Merge "Replace osd message for record status with IHdmiRecordCallback." into lmp-dev
diff --git a/api/current.txt b/api/current.txt
index 0361c7d..4e0d311 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -3392,6 +3392,7 @@
     method public android.view.View onCreateView(android.view.View, java.lang.String, android.content.Context, android.util.AttributeSet);
     method protected void onDestroy();
     method public void onDetachedFromWindow();
+    method public void onEnterAnimationComplete();
     method public boolean onGenericMotionEvent(android.view.MotionEvent);
     method public boolean onKeyDown(int, android.view.KeyEvent);
     method public boolean onKeyLongPress(int, android.view.KeyEvent);
@@ -14991,6 +14992,7 @@
     field public static final java.lang.String KEY_AAC_SBR_MODE = "aac-sbr-mode";
     field public static final java.lang.String KEY_BITRATE_MODE = "bitrate-mode";
     field public static final java.lang.String KEY_BIT_RATE = "bitrate";
+    field public static final java.lang.String KEY_CAPTURE_RATE = "capture-rate";
     field public static final java.lang.String KEY_CHANNEL_COUNT = "channel-count";
     field public static final java.lang.String KEY_CHANNEL_MASK = "channel-mask";
     field public static final java.lang.String KEY_COLOR_FORMAT = "color-format";
@@ -16819,7 +16821,6 @@
 
   public static final class TvContract.Channels implements android.media.tv.TvContract.BaseTvColumns {
     method public static final java.lang.String getVideoResolution(java.lang.String);
-    field public static final java.lang.String COLUMN_CONDITIONAL_ACCESS = "conditional_access";
     field public static final java.lang.String COLUMN_DESCRIPTION = "description";
     field public static final java.lang.String COLUMN_DISPLAY_NAME = "display_name";
     field public static final java.lang.String COLUMN_DISPLAY_NUMBER = "display_number";
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 127b0fc..fa59e4b 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -1465,7 +1465,7 @@
 
         System.out.println("Performing idle maintenance...");
         Intent intent = new Intent(
-                "com.android.server.IdleMaintenanceService.action.FORCE_IDLE_MAINTENANCE");
+                "com.android.server.task.controllers.IdleController.ACTION_TRIGGER_IDLE");
         mAm.broadcastIntent(null, intent, null, null, 0, null, null, null,
                 android.app.AppOpsManager.OP_NONE, true, false, UserHandle.USER_ALL);
     }
diff --git a/core/java/android/accessibilityservice/AccessibilityService.java b/core/java/android/accessibilityservice/AccessibilityService.java
index 19a91a6..13ceb4a 100644
--- a/core/java/android/accessibilityservice/AccessibilityService.java
+++ b/core/java/android/accessibilityservice/AccessibilityService.java
@@ -23,7 +23,6 @@
 import android.os.Looper;
 import android.os.Message;
 import android.os.RemoteException;
-import android.os.SystemClock;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.accessibility.AccessibilityEvent;
@@ -659,16 +658,12 @@
      */
     public static class IAccessibilityServiceClientWrapper extends IAccessibilityServiceClient.Stub
             implements HandlerCaller.Callback {
-
-        static final int NO_ID = -1;
-
         private static final int DO_SET_SET_CONNECTION = 1;
         private static final int DO_ON_INTERRUPT = 2;
         private static final int DO_ON_ACCESSIBILITY_EVENT = 3;
         private static final int DO_ON_GESTURE = 4;
         private static final int DO_CLEAR_ACCESSIBILITY_CACHE = 5;
         private static final int DO_ON_KEY_EVENT = 6;
-        private static final int DO_ON_WINDOWS_CHANGED = 7;
 
         private final HandlerCaller mCaller;
 
@@ -715,12 +710,6 @@
         }
 
         @Override
-        public void onWindowsChanged(int[] windowIds) {
-            Message message = mCaller.obtainMessageO(DO_ON_WINDOWS_CHANGED, windowIds);
-            mCaller.sendMessage(message);
-        }
-
-        @Override
         public void executeMessage(Message message) {
             switch (message.what) {
                 case DO_ON_ACCESSIBILITY_EVENT: {
@@ -791,31 +780,6 @@
                     }
                 } return;
 
-                case DO_ON_WINDOWS_CHANGED: {
-                    final int[] windowIds = (int[]) message.obj;
-
-                    // Update the cached windows first.
-                    // NOTE: The cache will hold on to the windows so do not recycle.
-                    if (windowIds != null) {
-                        AccessibilityInteractionClient.getInstance().removeWindows(windowIds);
-                    }
-
-                    // Let the client know the windows changed.
-                    AccessibilityEvent event = AccessibilityEvent.obtain(
-                            AccessibilityEvent.TYPE_WINDOWS_CHANGED);
-                    event.setEventTime(SystemClock.uptimeMillis());
-                    event.setSealed(true);
-
-                    mCallback.onAccessibilityEvent(event);
-
-                    // Make sure the event is recycled.
-                    try {
-                        event.recycle();
-                    } catch (IllegalStateException ise) {
-                        /* ignore - best effort */
-                    }
-                } break;
-
                 default :
                     Log.w(LOG_TAG, "Unknown message type " + message.what);
             }
diff --git a/core/java/android/accessibilityservice/IAccessibilityServiceClient.aidl b/core/java/android/accessibilityservice/IAccessibilityServiceClient.aidl
index edd8727..6ce0219 100644
--- a/core/java/android/accessibilityservice/IAccessibilityServiceClient.aidl
+++ b/core/java/android/accessibilityservice/IAccessibilityServiceClient.aidl
@@ -39,6 +39,4 @@
     void clearAccessibilityCache();
 
     void onKeyEvent(in KeyEvent event, int sequence);
-
-    void onWindowsChanged(in int[] changedWindowIds);
 }
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index cac646d..2ebfa1d 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -5501,6 +5501,14 @@
     }
 
     /**
+     * Activities cannot draw during the period that their windows are animating in. In order
+     * to know when it is safe to begin drawing they can override this method which will be
+     * called when the entering animation has completed.
+     */
+    public void onEnterAnimationComplete() {
+    }
+
+    /**
      * Adjust the current immersive mode setting.
      *
      * Note that changing this value will have no effect on the activity's
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 318a520..311a8f55 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -2231,6 +2231,14 @@
             reply.writeNoException();
             return true;
         }
+
+        case NOTIFY_ENTER_ANIMATION_COMPLETE_TRANSACTION: {
+            data.enforceInterface(IActivityManager.descriptor);
+            IBinder token = data.readStrongBinder();
+            notifyEnterAnimationComplete(token);
+            reply.writeNoException();
+            return true;
+        }
         }
 
         return super.onTransact(code, data, reply, flags);
@@ -5146,5 +5154,18 @@
         reply.recycle();
     }
 
+    @Override
+    public void notifyEnterAnimationComplete(IBinder token) throws RemoteException {
+        Parcel data = Parcel.obtain();
+        Parcel reply = Parcel.obtain();
+        data.writeInterfaceToken(IActivityManager.descriptor);
+        data.writeStrongBinder(token);
+        mRemote.transact(NOTIFY_ENTER_ANIMATION_COMPLETE_TRANSACTION, data, reply,
+                IBinder.FLAG_ONEWAY);
+        reply.readException();
+        data.recycle();
+        reply.recycle();
+    }
+
     private IBinder mRemote;
 }
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 48954f4..0bab7b2 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -1163,6 +1163,10 @@
         public void scheduleBackgroundMediaPlayingChanged(IBinder token, boolean playing) {
             sendMessage(H.BACKGROUND_MEDIA_PLAYING_CHANGED, token, playing ? 1 : 0);
         }
+
+        public void scheduleEnterAnimationComplete(IBinder token) {
+            sendMessage(H.ENTER_ANIMATION_COMPLETE, token);
+        }
     }
 
     private class H extends Handler {
@@ -1215,6 +1219,7 @@
         public static final int ON_NEW_ACTIVITY_OPTIONS = 146;
         public static final int STOP_MEDIA_PLAYING = 147;
         public static final int BACKGROUND_MEDIA_PLAYING_CHANGED = 148;
+        public static final int ENTER_ANIMATION_COMPLETE = 149;
 
         String codeToString(int code) {
             if (DEBUG_MESSAGES) {
@@ -1267,6 +1272,7 @@
                     case ON_NEW_ACTIVITY_OPTIONS: return "ON_NEW_ACTIVITY_OPTIONS";
                     case STOP_MEDIA_PLAYING: return "STOP_MEDIA_PLAYING";
                     case BACKGROUND_MEDIA_PLAYING_CHANGED: return "BACKGROUND_MEDIA_PLAYING_CHANGED";
+                    case ENTER_ANIMATION_COMPLETE: return "ENTER_ANIMATION_COMPLETE";
                 }
             }
             return Integer.toString(code);
@@ -1491,6 +1497,9 @@
                 case BACKGROUND_MEDIA_PLAYING_CHANGED:
                     handleOnBackgroundMediaPlayingChanged((IBinder) msg.obj, msg.arg1 > 0);
                     break;
+                case ENTER_ANIMATION_COMPLETE:
+                    handleEnterAnimationComplete((IBinder) msg.obj);
+                    break;
             }
             if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + codeToString(msg.what));
         }
@@ -2509,6 +2518,13 @@
         installContentProviders(mInitialApplication, Lists.newArrayList(info));
     }
 
+    private void handleEnterAnimationComplete(IBinder token) {
+        ActivityClientRecord r = mActivities.get(token);
+        if (r != null) {
+            r.activity.onEnterAnimationComplete();
+        }
+    }
+
     private static final ThreadLocal<Intent> sCurrentBroadcastIntent = new ThreadLocal<Intent>();
 
     /**
diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java
index 0b4510fe..e9d4bd9 100644
--- a/core/java/android/app/ApplicationThreadNative.java
+++ b/core/java/android/app/ApplicationThreadNative.java
@@ -666,6 +666,15 @@
             reply.writeNoException();
             return true;
         }
+
+        case ENTER_ANIMATION_COMPLETE_TRANSACTION:
+        {
+            data.enforceInterface(IApplicationThread.descriptor);
+            IBinder token = data.readStrongBinder();
+            scheduleEnterAnimationComplete(token);
+            reply.writeNoException();
+            return true;
+        }
         }
 
         return super.onTransact(code, data, reply, flags);
@@ -1342,4 +1351,13 @@
         mRemote.transact(BACKGROUND_MEDIA_PLAYING_CHANGED_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
         data.recycle();
     }
+
+    @Override
+    public void scheduleEnterAnimationComplete(IBinder token) throws RemoteException {
+        Parcel data = Parcel.obtain();
+        data.writeInterfaceToken(IApplicationThread.descriptor);
+        data.writeStrongBinder(token);
+        mRemote.transact(ENTER_ANIMATION_COMPLETE_TRANSACTION, data, null, IBinder.FLAG_ONEWAY);
+        data.recycle();
+    }
 }
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 53c1408..5347f03 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -448,6 +448,7 @@
     public void mediaResourcesReleased(IBinder token) throws RemoteException;
 
     public void notifyLaunchTaskBehindComplete(IBinder token) throws RemoteException;
+    public void notifyEnterAnimationComplete(IBinder token) throws RemoteException;
 
     /*
      * Private non-Binder interfaces
@@ -758,4 +759,5 @@
     int MEDIA_RESOURCES_RELEASED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+227;
     int NOTIFY_LAUNCH_TASK_BEHIND_COMPLETE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+228;
     int START_ACTIVITY_FROM_RECENTS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION + 229;
+    int NOTIFY_ENTER_ANIMATION_COMPLETE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+230;
 }
diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java
index 18faf0e..4a1fda4 100644
--- a/core/java/android/app/IApplicationThread.java
+++ b/core/java/android/app/IApplicationThread.java
@@ -147,6 +147,7 @@
     void updateTimePrefs(boolean is24Hour) throws RemoteException;
     void scheduleStopMediaPlaying(IBinder token) throws RemoteException;
     void scheduleBackgroundMediaPlayingChanged(IBinder token, boolean enabled) throws RemoteException;
+    void scheduleEnterAnimationComplete(IBinder token) throws RemoteException;
 
     String descriptor = "android.app.IApplicationThread";
 
@@ -203,4 +204,5 @@
     int UPDATE_TIME_PREFS_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+51;
     int STOP_MEDIA_PLAYING_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+52;
     int BACKGROUND_MEDIA_PLAYING_CHANGED_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+53;
+    int ENTER_ANIMATION_COMPLETE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+54;
 }
diff --git a/core/java/android/hardware/Sensor.java b/core/java/android/hardware/Sensor.java
index a5c2f63..b6d2a13 100644
--- a/core/java/android/hardware/Sensor.java
+++ b/core/java/android/hardware/Sensor.java
@@ -781,6 +781,25 @@
      */
     public static final String STRING_TYPE_GLANCE_GESTURE = "android.sensor.glance_gesture";
 
+     /**
+     * A constant describing a pick up sensor.
+     *
+     * A sensor of this type triggers when the device is picked up regardless of wherever it was
+     * before (desk, pocket, bag). The only allowed return value is 1.0. This sensor deactivates
+     * itself immediately after it triggers.
+     *
+     * @hide Expected to be used internally for always on display.
+     */
+    public static final int TYPE_PICK_UP_GESTURE = 44;
+
+    /**
+     * A constant string describing a pick up sensor.
+     *
+     * @hide This sensor is expected to be used internally for always on display.
+     * @see #TYPE_PICK_UP_GESTURE
+     */
+    public static final String STRING_TYPE_PICK_UP_GESTURE = "android.sensor.pick_up_gesture";
+
     /**
      * A constant describing all sensor types.
      */
@@ -880,6 +899,7 @@
             1, // SENSOR_TYPE_WAKE_UP_TILT_DETECTOR
             1, // SENSOR_TYPE_WAKE_GESTURE
             1, // SENSOR_TYPE_GLANCE_GESTURE
+            1, // SENSOR_TYPE_PICK_UP_GESTURE
     };
 
     /**
diff --git a/core/java/android/view/accessibility/AccessibilityCache.java b/core/java/android/view/accessibility/AccessibilityCache.java
index f796587..4f34231 100644
--- a/core/java/android/view/accessibility/AccessibilityCache.java
+++ b/core/java/android/view/accessibility/AccessibilityCache.java
@@ -58,20 +58,18 @@
         }
     }
 
-    public void removeWindows(int[] windowIds) {
+    public void clearWindows() {
         synchronized (mLock) {
-            final int windowCount = windowIds.length;
-            for (int i = 0; i < windowCount; i++) {
-                final int windowId = windowIds[i];
-                AccessibilityWindowInfo window = mWindowCache.get(windowId);
+            final int windowCount = mWindowCache.size();
+            for (int i = windowCount - 1; i >= 0; i--) {
+                AccessibilityWindowInfo window = mWindowCache.valueAt(i);
                 if (window != null) {
                     if (DEBUG) {
-                        Log.i(LOG_TAG, "Removing window: " + windowId);
+                        Log.i(LOG_TAG, "Removing window: " + window.getId());
                     }
                     window.recycle();
-                    mWindowCache.remove(windowId);
+                    mWindowCache.removeAt(i);
                 }
-                clearNodesForWindowLocked(windowIds[i]);
             }
         }
     }
@@ -111,6 +109,10 @@
                 case AccessibilityEvent.TYPE_VIEW_SCROLLED: {
                     clearSubTreeLocked(event.getWindowId(), event.getSourceNodeId());
                 } break;
+
+                case AccessibilityEvent.TYPE_WINDOWS_CHANGED: {
+                    clearWindows();
+                } break;
             }
         }
 
diff --git a/core/java/android/view/accessibility/AccessibilityInteractionClient.java b/core/java/android/view/accessibility/AccessibilityInteractionClient.java
index 4748402..db78ec5 100644
--- a/core/java/android/view/accessibility/AccessibilityInteractionClient.java
+++ b/core/java/android/view/accessibility/AccessibilityInteractionClient.java
@@ -84,7 +84,7 @@
     private static final Object sStaticLock = new Object();
 
     private static final LongSparseArray<AccessibilityInteractionClient> sClients =
-        new LongSparseArray<AccessibilityInteractionClient>();
+        new LongSparseArray<>();
 
     private final AtomicInteger mInteractionIdCounter = new AtomicInteger();
 
@@ -101,7 +101,7 @@
     private Message mSameThreadMessage;
 
     private static final SparseArray<IAccessibilityServiceConnection> sConnectionCache =
-        new SparseArray<IAccessibilityServiceConnection>();
+        new SparseArray<>();
 
     private static final AccessibilityCache sAccessibilityCache =
         new AccessibilityCache();
@@ -163,19 +163,6 @@
     }
 
     /**
-     * Gets the root {@link AccessibilityNodeInfo} in a given window.
-     *
-     * @param connectionId The id of a connection for interacting with the system.
-     * @param windowId The window id.
-     * @return The root {@link AccessibilityNodeInfo} if found, null otherwise.
-     */
-    public AccessibilityNodeInfo getRootInWindow(int connectionId, int windowId) {
-        return findAccessibilityNodeInfoByAccessibilityId(connectionId, windowId,
-                AccessibilityNodeInfo.ROOT_NODE_ID, false,
-                AccessibilityNodeInfo.FLAG_PREFETCH_DESCENDANTS);
-    }
-
-    /**
      * Gets the info for a window.
      *
      * @param connectionId The id of a connection for interacting with the system.
@@ -225,11 +212,17 @@
         try {
             IAccessibilityServiceConnection connection = getConnection(connectionId);
             if (connection != null) {
-                // The system is just sending data for windows that we introspected
-                // and changed but not ones that appeared, so we have to always call
-                // into the system process. This is less expensice as opposed to
-                // sending all windows on every window change.
-                List<AccessibilityWindowInfo> windows = connection.getWindows();
+                List<AccessibilityWindowInfo> windows = sAccessibilityCache.getWindows();
+                if (windows != null) {
+                    if (DEBUG) {
+                        Log.i(LOG_TAG, "Windows cache hit");
+                    }
+                    return windows;
+                }
+                if (DEBUG) {
+                    Log.i(LOG_TAG, "Windows cache miss");
+                }
+                windows = connection.getWindows();
                 if (windows != null) {
                     final int windowCount = windows.size();
                     for (int i = 0; i < windowCount; i++) {
@@ -534,10 +527,6 @@
         sAccessibilityCache.onAccessibilityEvent(event);
     }
 
-    public void removeWindows(int[] windowIds) {
-        sAccessibilityCache.removeWindows(windowIds);
-    }
-
     /**
      * Gets the the result of an async request that returns an {@link AccessibilityNodeInfo}.
      *
@@ -603,8 +592,7 @@
                     // instantiate new result list to avoid passing internal instances to clients.
                     final boolean isIpcCall = (Binder.getCallingPid() != Process.myPid());
                     if (!isIpcCall) {
-                        mFindAccessibilityNodeInfosResult =
-                            new ArrayList<AccessibilityNodeInfo>(infos);
+                        mFindAccessibilityNodeInfosResult = new ArrayList<>(infos);
                     } else {
                         mFindAccessibilityNodeInfosResult = infos;
                     }
@@ -795,8 +783,8 @@
             Log.e(LOG_TAG, "No root.");
         }
         // Check for duplicates.
-        HashSet<AccessibilityNodeInfo> seen = new HashSet<AccessibilityNodeInfo>();
-        Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>();
+        HashSet<AccessibilityNodeInfo> seen = new HashSet<>();
+        Queue<AccessibilityNodeInfo> fringe = new LinkedList<>();
         fringe.add(root);
         while (!fringe.isEmpty()) {
             AccessibilityNodeInfo current = fringe.poll();
diff --git a/core/res/res/values-large/themes_material.xml b/core/res/res/values-large/themes_material.xml
index 2781608..05fee6b 100644
--- a/core/res/res/values-large/themes_material.xml
+++ b/core/res/res/values-large/themes_material.xml
@@ -35,6 +35,10 @@
     <style name="Theme.Material.DialogWhenLarge.NoActionBar" parent="@style/Theme.Material.Dialog.NoActionBar.FixedSize">
         <item name="preferencePanelStyle">@style/PreferencePanel.Dialog</item>
     </style>
-    <style name="Theme.Material.Light.DialogWhenLarge" parent="@style/Theme.Material.Light.Dialog.FixedSize" />
-    <style name="Theme.Material.Light.DialogWhenLarge.NoActionBar" parent="@style/Theme.Material.Light.Dialog.NoActionBar.FixedSize" />
+    <style name="Theme.Material.Light.DialogWhenLarge" parent="@style/Theme.Material.Light.Dialog.FixedSize">
+        <item name="preferencePanelStyle">@style/PreferencePanel.Dialog</item>
+    </style>
+    <style name="Theme.Material.Light.DialogWhenLarge.NoActionBar" parent="@style/Theme.Material.Light.Dialog.NoActionBar.FixedSize">
+        <item name="preferencePanelStyle">@style/PreferencePanel.Dialog</item>
+    </style>
 </resources>
diff --git a/media/java/android/media/MediaFormat.java b/media/java/android/media/MediaFormat.java
index a95348f..a1ccf60 100644
--- a/media/java/android/media/MediaFormat.java
+++ b/media/java/android/media/MediaFormat.java
@@ -43,7 +43,8 @@
  * <tr><td>{@link #KEY_COLOR_FORMAT}</td><td>Integer</td><td>set by the user
  *         for encoders, readable in the output format of decoders</b></td></tr>
  * <tr><td>{@link #KEY_FRAME_RATE}</td><td>Integer or Float</td><td><b>encoder-only</b></td></tr>
- * <tr><td>{@link #KEY_I_FRAME_INTERVAL}</td><td>Integer</td><td><b>encoder-only</b></td></tr>
+ * <tr><td>{@link #KEY_CAPTURE_RATE}</td><td>Integer</td><td></td></tr>
+* <tr><td>{@link #KEY_I_FRAME_INTERVAL}</td><td>Integer</td><td><b>encoder-only</b></td></tr>
  * <tr><td>{@link #KEY_MAX_WIDTH}</td><td>Integer</td><td><b>decoder-only</b>, optional, max-resolution width</td></tr>
  * <tr><td>{@link #KEY_MAX_HEIGHT}</td><td>Integer</td><td><b>decoder-only</b>, optional, max-resolution height</td></tr>
  * <tr><td>{@link #KEY_REPEAT_PREVIOUS_FRAME_AFTER}</td><td>Long</td><td><b>video encoder in surface-mode only</b></td></tr>
@@ -206,6 +207,21 @@
     public static final String KEY_FRAME_RATE = "frame-rate";
 
     /**
+     * A key describing the capture rate of a video format in frames/sec.
+     * <p>
+     * When capture rate is different than the frame rate, it means that the
+     * video is acquired at a different rate than the playback, which produces
+     * slow motion or timelapse effect during playback. Application can use the
+     * value of this key to tell the relative speed ratio between capture and
+     * playback rates when the video was recorded.
+     * </p>
+     * <p>
+     * The associated value is an integer or a float.
+     * </p>
+     */
+    public static final String KEY_CAPTURE_RATE = "capture-rate";
+
+    /**
      * A key describing the frequency of I frames expressed in secs
      * between I frames.
      * The associated value is an integer.
diff --git a/media/java/android/media/tv/TvContract.java b/media/java/android/media/tv/TvContract.java
index d2071ef..1a43051 100644
--- a/media/java/android/media/tv/TvContract.java
+++ b/media/java/android/media/tv/TvContract.java
@@ -696,19 +696,6 @@
         public static final String COLUMN_SEARCHABLE = "searchable";
 
         /**
-         * The flag indicating whether this TV channel is scrambled by conditional access or not.
-         * <p>
-         * This is used for indicating that this channel is protected by a conditional access
-         * system. A value of 1 indicates the channel is scrambled and the user is required
-         * to contact the service provider to watch this channel. A value of 0 indicates the channel
-         * is not scrambled. If not specified, this value is set to 0 (not scrambled) by default.
-         * </p><p>
-         * Type: INTEGER (boolean)
-         * </p>
-         */
-        public static final String COLUMN_CONDITIONAL_ACCESS = "conditional_access";
-
-        /**
          * The flag indicating whether this TV channel is locked or not.
          * <p>
          * This is primarily used for alternative parental control to prevent unauthorized users
diff --git a/media/java/android/media/tv/TvStreamConfig.java b/media/java/android/media/tv/TvStreamConfig.java
index 7f0c92f..243f864 100644
--- a/media/java/android/media/tv/TvStreamConfig.java
+++ b/media/java/android/media/tv/TvStreamConfig.java
@@ -16,6 +16,7 @@
 
 package android.media.tv;
 
+import android.annotation.SystemApi;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.util.Log;
@@ -23,6 +24,7 @@
 /**
  * @hide
  */
+@SystemApi
 public class TvStreamConfig implements Parcelable {
     static final String TAG = TvStreamConfig.class.getSimpleName();
 
@@ -154,4 +156,4 @@
             return config;
         }
     }
-}
\ No newline at end of file
+}
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index e3c2203..392c280 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -3379,6 +3379,9 @@
             }
             mDecor.setWindowBackground(background);
 
+            // By default, clip content to the background outline.
+            mDecor.setClipToOutline(true);
+
             final Drawable frame;
             if (mFrameResource != 0) {
                 frame = getContext().getDrawable(mFrameResource);
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index 07bb713..b1f1954 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -62,7 +62,6 @@
 import android.provider.Settings;
 import android.text.TextUtils;
 import android.text.TextUtils.SimpleStringSplitter;
-import android.util.LongArray;
 import android.util.Pools.Pool;
 import android.util.Pools.SimplePool;
 import android.util.Slog;
@@ -114,8 +113,6 @@
  * accessed only by the system. The task of this service is to be a centralized
  * event dispatch for {@link AccessibilityEvent}s generated across all processes
  * on the device. Events are dispatched to {@link AccessibilityService}s.
- *
- * @hide
  */
 public class AccessibilityManagerService extends IAccessibilityManager.Stub {
 
@@ -155,13 +152,13 @@
     private final Object mLock = new Object();
 
     private final Pool<PendingEvent> mPendingEventPool =
-            new SimplePool<PendingEvent>(MAX_POOL_SIZE);
+            new SimplePool<>(MAX_POOL_SIZE);
 
     private final SimpleStringSplitter mStringColonSplitter =
             new SimpleStringSplitter(COMPONENT_NAME_SEPARATOR);
 
     private final List<AccessibilityServiceInfo> mEnabledServicesForFeedbackTempList =
-            new ArrayList<AccessibilityServiceInfo>();
+            new ArrayList<>();
 
     private final Rect mTempRect = new Rect();
 
@@ -183,27 +180,25 @@
 
     private boolean mHasInputFilter;
 
-    private final Set<ComponentName> mTempComponentNameSet = new HashSet<ComponentName>();
+    private final Set<ComponentName> mTempComponentNameSet = new HashSet<>();
 
     private final List<AccessibilityServiceInfo> mTempAccessibilityServiceInfoList =
-            new ArrayList<AccessibilityServiceInfo>();
+            new ArrayList<>();
 
     private final RemoteCallbackList<IAccessibilityManagerClient> mGlobalClients =
-            new RemoteCallbackList<IAccessibilityManagerClient>();
+            new RemoteCallbackList<>();
 
     private final SparseArray<AccessibilityConnectionWrapper> mGlobalInteractionConnections =
-            new SparseArray<AccessibilityConnectionWrapper>();
+            new SparseArray<>();
 
-    private final SparseArray<IBinder> mGlobalWindowTokens = new SparseArray<IBinder>();
+    private final SparseArray<IBinder> mGlobalWindowTokens = new SparseArray<>();
 
-    private final SparseArray<UserState> mUserStates = new SparseArray<UserState>();
+    private final SparseArray<UserState> mUserStates = new SparseArray<>();
 
     private final UserManager mUserManager;
 
     private int mCurrentUserId = UserHandle.USER_OWNER;
 
-    private final LongArray mTempLongArray = new LongArray();
-
     //TODO: Remove this hack
     private boolean mInitialized;
 
@@ -439,10 +434,9 @@
             // to clients as being installed - it really is not.
             UserState userState = getUserStateLocked(resolvedUserId);
             if (userState.mUiAutomationService != null) {
-                List<AccessibilityServiceInfo> installedServices =
-                        new ArrayList<AccessibilityServiceInfo>();
+                List<AccessibilityServiceInfo> installedServices = new ArrayList<>();
                 installedServices.addAll(userState.mInstalledServices);
-                installedServices.remove(userState.mUiAutomationService);
+                installedServices.remove(userState.mUiAutomationService.mAccessibilityServiceInfo);
                 return installedServices;
             }
             return userState.mInstalledServices;
@@ -655,7 +649,6 @@
             // Automation service is not bound, so pretend it died to perform clean up.
             if (userState.mUiAutomationService != null
                     && serviceClient != null
-                    && userState.mUiAutomationService != null
                     && userState.mUiAutomationService.mServiceInterface != null
                     && userState.mUiAutomationService.mServiceInterface.asBinder()
                     == serviceClient.asBinder()) {
@@ -907,16 +900,6 @@
         }
     }
 
-    private void notifyWindowsChangedLocked(List<AccessibilityWindowInfo> windows) {
-        UserState state = getCurrentUserStateLocked();
-        for (int i = state.mBoundServices.size() - 1; i >= 0; i--) {
-            Service service = state.mBoundServices.get(i);
-            if (mSecurityPolicy.canRetrieveWindowsLocked(service)) {
-                service.notifyWindowsChangedLocked(windows);
-            }
-        }
-    }
-
     /**
      * Removes an AccessibilityInteractionConnection.
      *
@@ -961,10 +944,8 @@
             try {
                 accessibilityServiceInfo = new AccessibilityServiceInfo(resolveInfo, mContext);
                 mTempAccessibilityServiceInfoList.add(accessibilityServiceInfo);
-            } catch (XmlPullParserException xppe) {
+            } catch (XmlPullParserException | IOException xppe) {
                 Slog.e(LOG_TAG, "Error while initializing AccessibilityServiceInfo", xppe);
-            } catch (IOException ioe) {
-                Slog.e(LOG_TAG, "Error while initializing AccessibilityServiceInfo", ioe);
             }
         }
 
@@ -1035,7 +1016,6 @@
             // An out of bounds exception can happen if services are going away
             // as the for loop is running. If that happens, just bail because
             // there are no more services to notify.
-            return;
         }
     }
 
@@ -1053,7 +1033,6 @@
      * Removes a service.
      *
      * @param service The service.
-     * @return True if the service was removed, false otherwise.
      */
     private void removeServiceLocked(Service service, UserState userState) {
         userState.mBoundServices.remove(service);
@@ -1093,7 +1072,8 @@
         }
 
         Set<String> packageNames = service.mPackageNames;
-        CharSequence packageName = event.getPackageName();
+        String packageName = (event.getPackageName() != null)
+                ? event.getPackageName().toString() : null;
 
         if (packageNames.isEmpty() || packageNames.contains(packageName)) {
             int feedbackType = service.mFeedbackType;
@@ -1386,8 +1366,7 @@
 
         if (mWindowsForAccessibilityCallback != null) {
             mWindowsForAccessibilityCallback = null;
-            mWindowManagerService.setWindowsForAccessibilityCallback(
-                    mWindowsForAccessibilityCallback);
+            mWindowManagerService.setWindowsForAccessibilityCallback(null);
         }
     }
 
@@ -1437,8 +1416,7 @@
     }
 
     private boolean readConfigurationForUserStateLocked(UserState userState) {
-        boolean somthingChanged = false;
-        somthingChanged |= readAccessibilityEnabledSettingLocked(userState);
+        boolean somthingChanged = readAccessibilityEnabledSettingLocked(userState);
         somthingChanged |= readInstalledAccessibilityServiceLocked(userState);
         somthingChanged |= readEnabledAccessibilityServicesLocked(userState);
         somthingChanged |= readTouchExplorationGrantedAccessibilityServicesLocked(userState);
@@ -1868,7 +1846,7 @@
 
         int mFeedbackType;
 
-        Set<String> mPackageNames = new HashSet<String>();
+        Set<String> mPackageNames = new HashSet<>();
 
         boolean mIsDefault;
 
@@ -1890,20 +1868,16 @@
 
         boolean mIsAutomation;
 
-        final Rect mTempBounds1 = new Rect();
-
-        final Rect mTempBounds2 = new Rect();
-
         final ResolveInfo mResolveInfo;
 
         // the events pending events to be dispatched to this service
         final SparseArray<AccessibilityEvent> mPendingEvents =
-            new SparseArray<AccessibilityEvent>();
+            new SparseArray<>();
 
         final KeyEventDispatcher mKeyEventDispatcher = new KeyEventDispatcher();
 
         final SparseArray<AccessibilityWindowInfo> mIntrospectedWindows =
-                new SparseArray<AccessibilityWindowInfo>();
+                new SparseArray<>();
 
         boolean mWasConnectedAndDied;
 
@@ -2106,7 +2080,7 @@
                 if (!permissionGranted) {
                     return null;
                 }
-                List<AccessibilityWindowInfo> windows = new ArrayList<AccessibilityWindowInfo>();
+                List<AccessibilityWindowInfo> windows = new ArrayList<>();
                 final int windowCount = mSecurityPolicy.mWindows.size();
                 for (int i = 0; i < windowCount; i++) {
                     AccessibilityWindowInfo window = mSecurityPolicy.mWindows.get(i);
@@ -2646,51 +2620,6 @@
             }
         }
 
-        public void notifyWindowsChangedLocked(List<AccessibilityWindowInfo> windows) {
-            LongArray changedWindows = mTempLongArray;
-            changedWindows.clear();
-
-            // Figure out which windows the service cares about changed.
-            final int windowCount = windows.size();
-            for (int i = 0; i < windowCount; i++) {
-                AccessibilityWindowInfo newState = windows.get(i);
-                final int windowId = newState.getId();
-                AccessibilityWindowInfo oldState = mIntrospectedWindows.get(windowId);
-                if (oldState != null && oldState.changed(newState)) {
-                    oldState.recycle();
-                    mIntrospectedWindows.put(newState.getId(),
-                            AccessibilityWindowInfo.obtain(newState));
-                    changedWindows.add(windowId);
-                }
-            }
-
-            // Figure out which windows the service cares about went away.
-            final int introspectedWindowCount = mIntrospectedWindows.size();
-            for (int i = introspectedWindowCount - 1; i >= 0; i--) {
-                AccessibilityWindowInfo window = mIntrospectedWindows.valueAt(i);
-                if (changedWindows.indexOf(window.getId()) < 0 && !windows.contains(window)) {
-                    changedWindows.add(window.getId());
-                    mIntrospectedWindows.removeAt(i);
-                    window.recycle();
-                }
-            }
-
-            int[] windowIds = null;
-
-            final int changedWindowCount = changedWindows.size();
-            if (changedWindowCount > 0) {
-                windowIds = new int[changedWindowCount];
-                for (int i = 0; i < changedWindowCount; i++) {
-                    // Cast is fine as we use long array to cache ints.
-                    windowIds[i] = (int) changedWindows.get(i);
-                }
-                changedWindows.clear();
-            }
-
-            mInvocationHandler.obtainMessage(InvocationHandler.MSG_ON_WINDOWS_CHANGED,
-                    windowIds).sendToTarget();
-        }
-
         private void notifyGestureInternal(int gestureId) {
             final IAccessibilityServiceClient listener;
             synchronized (mLock) {
@@ -2725,20 +2654,6 @@
             }
         }
 
-        private void notifyWindowsChangedInternal(int[] windowIds) {
-            final IAccessibilityServiceClient listener;
-            synchronized (mLock) {
-                listener = mServiceInterface;
-            }
-            if (listener != null) {
-                try {
-                    listener.onWindowsChanged(windowIds);
-                } catch (RemoteException re) {
-                    Slog.e(LOG_TAG, "Error during sending windows to: " + mService, re);
-                }
-            }
-        }
-
         private void sendDownAndUpKeyEvents(int keyCode) {
             final long token = Binder.clearCallingIdentity();
 
@@ -2844,7 +2759,6 @@
             public static final int MSG_ON_KEY_EVENT = 2;
             public static final int MSG_CLEAR_ACCESSIBILITY_CACHE = 3;
             public static final int MSG_ON_KEY_EVENT_TIMEOUT = 4;
-            public static final int MSG_ON_WINDOWS_CHANGED = 5;
 
             public InvocationHandler(Looper looper) {
                 super(looper, null, true);
@@ -2874,11 +2788,6 @@
                         setOnKeyEventResult(false, eventState.sequence);
                     } break;
 
-                    case MSG_ON_WINDOWS_CHANGED: {
-                        final int[] windowIds = (int[]) message.obj;
-                        notifyWindowsChangedInternal(windowIds);
-                    } break;
-
                     default: {
                         throw new IllegalArgumentException("Unknown message: " + type);
                     }
@@ -3028,14 +2937,11 @@
         @Override
         public void onWindowsForAccessibilityChanged(List<WindowInfo> windows) {
             synchronized (mLock) {
-                List<WindowInfo> receivedWindows = (List<WindowInfo>) windows;
-
                 // Populate the windows to report.
-                List<AccessibilityWindowInfo> reportedWindows =
-                        new ArrayList<AccessibilityWindowInfo>();
-                final int receivedWindowCount = receivedWindows.size();
+                List<AccessibilityWindowInfo> reportedWindows = new ArrayList<>();
+                final int receivedWindowCount = windows.size();
                 for (int i = 0; i < receivedWindowCount; i++) {
-                    WindowInfo receivedWindow = receivedWindows.get(i);
+                    WindowInfo receivedWindow = windows.get(i);
                     AccessibilityWindowInfo reportedWindow = populateReportedWindow(
                             receivedWindow);
                     if (reportedWindow != null) {
@@ -3224,8 +3130,7 @@
             | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED
             | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY;
 
-        public final List<AccessibilityWindowInfo> mWindows =
-                new ArrayList<AccessibilityWindowInfo>();
+        public final List<AccessibilityWindowInfo> mWindows = new ArrayList<>();
 
         public int mActiveWindowId = INVALID_WINDOW_ID;
         public int mFocusedWindowId = INVALID_WINDOW_ID;
@@ -3265,7 +3170,9 @@
                 case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START:
                 case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END:
                 case AccessibilityEvent.TYPE_VIEW_HOVER_ENTER:
-                case AccessibilityEvent.TYPE_VIEW_HOVER_EXIT: {
+                case AccessibilityEvent.TYPE_VIEW_HOVER_EXIT:
+                // Also windows changing should always be anounced.
+                case AccessibilityEvent.TYPE_WINDOWS_CHANGED: {
                     return true;
                 }
                 // All events for changes in window content should be
@@ -3327,7 +3234,7 @@
                 }
             }
 
-            notifyWindowsChangedLocked(mWindows);
+            notifyWindowsChanged();
 
             // If we are delaying a window state change event as the window
             // source was showing when it was fired, now is the time to send.
@@ -3452,10 +3359,18 @@
                     AccessibilityWindowInfo window = mWindows.get(i);
                     window.setActive(window.getId() == windowId);
                 }
-                notifyWindowsChangedLocked(mWindows);
+                notifyWindowsChanged();
             }
         }
 
+        private void notifyWindowsChanged() {
+            // Let the client know the windows changed.
+            AccessibilityEvent event = AccessibilityEvent.obtain(
+                    AccessibilityEvent.TYPE_WINDOWS_CHANGED);
+            event.setEventTime(SystemClock.uptimeMillis());
+            sendAccessibilityEvent(event, mCurrentUserId);
+        }
+
         public boolean canGetAccessibilityNodeInfoLocked(Service service, int windowId) {
             return canRetrieveWindowContentLocked(service) && isRetrievalAllowingWindow(windowId);
         }
@@ -3568,30 +3483,30 @@
         // Non-transient state.
 
         public final RemoteCallbackList<IAccessibilityManagerClient> mClients =
-            new RemoteCallbackList<IAccessibilityManagerClient>();
+            new RemoteCallbackList<>();
 
         public final SparseArray<AccessibilityConnectionWrapper> mInteractionConnections =
-                new SparseArray<AccessibilityConnectionWrapper>();
+                new SparseArray<>();
 
-        public final SparseArray<IBinder> mWindowTokens = new SparseArray<IBinder>();
+        public final SparseArray<IBinder> mWindowTokens = new SparseArray<>();
 
         // Transient state.
 
         public final CopyOnWriteArrayList<Service> mBoundServices =
-                new CopyOnWriteArrayList<Service>();
+                new CopyOnWriteArrayList<>();
 
         public final Map<ComponentName, Service> mComponentNameToServiceMap =
-                new HashMap<ComponentName, Service>();
+                new HashMap<>();
 
         public final List<AccessibilityServiceInfo> mInstalledServices =
-                new ArrayList<AccessibilityServiceInfo>();
+                new ArrayList<>();
 
-        public final Set<ComponentName> mBindingServices = new HashSet<ComponentName>();
+        public final Set<ComponentName> mBindingServices = new HashSet<>();
 
-        public final Set<ComponentName> mEnabledServices = new HashSet<ComponentName>();
+        public final Set<ComponentName> mEnabledServices = new HashSet<>();
 
         public final Set<ComponentName> mTouchExplorationGrantedServices =
-                new HashSet<ComponentName>();
+                new HashSet<>();
 
         public int mHandledFeedbackTypes = 0;
 
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
index 56b8c92..595e91e 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/BackupManagerService.java
@@ -6645,8 +6645,8 @@
             UnifiedRestoreState nextState = UnifiedRestoreState.FINAL;
             try {
                 mRestoreDescription = mTransport.nextRestorePackage();
-                final int type = mRestoreDescription.getDataType();
-                final String pkgName = mRestoreDescription.getPackageName();
+                final String pkgName = (mRestoreDescription != null)
+                        ? mRestoreDescription.getPackageName() : null;
                 if (pkgName == null) {
                     Slog.e(TAG, "Failure getting next package name");
                     EventLog.writeEvent(EventLogTags.RESTORE_TRANSPORT_FAILURE);
@@ -6717,6 +6717,7 @@
 
                 // Reset per-package preconditions and fire the appropriate next state
                 mWidgetData = null;
+                final int type = mRestoreDescription.getDataType();
                 if (type == RestoreDescription.TYPE_KEY_VALUE) {
                     nextState = UnifiedRestoreState.RESTORE_KEYVALUE;
                 } else if (type == RestoreDescription.TYPE_FULL_STREAM) {
@@ -8470,12 +8471,6 @@
                 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.
diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java
index 6c3a4b4..50f2ae9 100644
--- a/services/core/java/com/android/server/MountService.java
+++ b/services/core/java/com/android/server/MountService.java
@@ -775,7 +775,7 @@
                  */
                 try {
                     final String[] vols = NativeDaemonEvent.filterMessageList(
-                            mConnector.executeForList("volume", "list"),
+                            mConnector.executeForList("volume", "list", "broadcast"),
                             VoldResponseCode.VolumeListResult);
                     for (String volstr : vols) {
                         String[] tok = volstr.split(" ");
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index fed68f9..314e906 100755
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1158,6 +1158,7 @@
     static final int UPDATE_TIME = 41;
     static final int SYSTEM_USER_START_MSG = 42;
     static final int SYSTEM_USER_CURRENT_MSG = 43;
+    static final int ENTER_ANIMATION_COMPLETE_MSG = 44;
 
     static final int FIRST_ACTIVITY_STACK_MSG = 100;
     static final int FIRST_BROADCAST_QUEUE_MSG = 200;
@@ -1813,6 +1814,18 @@
                 mSystemServiceManager.switchUser(msg.arg1);
                 break;
             }
+            case ENTER_ANIMATION_COMPLETE_MSG: {
+                synchronized (ActivityManagerService.this) {
+                    ActivityRecord r = ActivityRecord.forToken((IBinder) msg.obj);
+                    if (r != null && r.app != null && r.app.thread != null) {
+                        try {
+                            r.app.thread.scheduleEnterAnimationComplete(r.appToken);
+                        } catch (RemoteException e) {
+                        }
+                    }
+                }
+                break;
+            }
             }
         }
     };
@@ -5699,6 +5712,11 @@
     }
 
     @Override
+    public final void notifyEnterAnimationComplete(IBinder token) {
+        mHandler.sendMessage(mHandler.obtainMessage(ENTER_ANIMATION_COMPLETE_MSG, token));
+    }
+
+    @Override
     public String getCallingPackage(IBinder token) {
         synchronized (this) {
             ActivityRecord r = getCallingRecordLocked(token);
diff --git a/services/core/java/com/android/server/display/DisplayManagerService.java b/services/core/java/com/android/server/display/DisplayManagerService.java
index 2737646..b9acea5 100644
--- a/services/core/java/com/android/server/display/DisplayManagerService.java
+++ b/services/core/java/com/android/server/display/DisplayManagerService.java
@@ -1367,7 +1367,7 @@
             }
             if (mContext.checkCallingPermission(
                     android.Manifest.permission.CAPTURE_VIDEO_OUTPUT)
-                    != PackageManager.PERMISSION_GRANTED) {
+                    == PackageManager.PERMISSION_GRANTED) {
                 return true;
             }
             return canProjectSecureVideo(projection);
@@ -1385,7 +1385,7 @@
             }
             return mContext.checkCallingPermission(
                     android.Manifest.permission.CAPTURE_SECURE_VIDEO_OUTPUT)
-                    != PackageManager.PERMISSION_GRANTED;
+                    == PackageManager.PERMISSION_GRANTED;
         }
     }
 
diff --git a/services/core/java/com/android/server/job/JobServiceContext.java b/services/core/java/com/android/server/job/JobServiceContext.java
index eaf5480..ee45833 100644
--- a/services/core/java/com/android/server/job/JobServiceContext.java
+++ b/services/core/java/com/android/server/job/JobServiceContext.java
@@ -285,7 +285,7 @@
                 case MSG_CALLBACK:
                     if (DEBUG) {
                         Slog.d(TAG, "MSG_CALLBACK of : " + mRunningJob + " v:" +
-                                VERB_STRINGS[mVerb]);
+                                (mVerb >= 0 ? VERB_STRINGS[mVerb] : "[invalid]"));
                     }
                     removeMessages(MSG_TIMEOUT);
 
@@ -518,7 +518,7 @@
                     EXECUTING_TIMESLICE_MILLIS : OP_TIMEOUT_MILLIS;
             if (DEBUG) {
                 Slog.d(TAG, "Scheduling time out for '" +
-                        mRunningJob.getServiceComponent().getShortClassName() + "' tId: " +
+                        mRunningJob.getServiceComponent().getShortClassName() + "' jId: " +
                         mParams.getJobId() + ", in " + (timeoutMillis / 1000) + " s");
             }
             Message m = mCallbackHandler.obtainMessage(MSG_TIMEOUT);
diff --git a/services/core/java/com/android/server/job/controllers/IdleController.java b/services/core/java/com/android/server/job/controllers/IdleController.java
index 07ffe4d..451960c 100644
--- a/services/core/java/com/android/server/job/controllers/IdleController.java
+++ b/services/core/java/com/android/server/job/controllers/IdleController.java
@@ -137,6 +137,9 @@
             filter.addAction(Intent.ACTION_DREAMING_STARTED);
             filter.addAction(Intent.ACTION_DREAMING_STOPPED);
 
+            // Debugging/instrumentation
+            filter.addAction(ACTION_TRIGGER_IDLE);
+
             mContext.registerReceiver(this, filter);
         }
 
diff --git a/services/core/java/com/android/server/wm/AppWindowAnimator.java b/services/core/java/com/android/server/wm/AppWindowAnimator.java
index 874e105..9b69ce2 100644
--- a/services/core/java/com/android/server/wm/AppWindowAnimator.java
+++ b/services/core/java/com/android/server/wm/AppWindowAnimator.java
@@ -297,6 +297,13 @@
             mAppToken.mLaunchTaskBehind = false;
         } else {
             mAppToken.updateReportedVisibilityLocked();
+            if (mAppToken.mEnteringAnimation) {
+                mAppToken.mEnteringAnimation = false;
+                try {
+                    mService.mActivityManager.notifyEnterAnimationComplete(mAppToken.token);
+                } catch (RemoteException e) {
+                }
+            }
         }
 
         return false;
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 312689b..3fcd067 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -110,6 +110,7 @@
     boolean mDeferRemoval;
 
     boolean mLaunchTaskBehind;
+    boolean mEnteringAnimation;
 
     AppWindowToken(WindowManagerService _service, IApplicationToken _token,
             boolean _voiceInteraction) {
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 170ecbd..670ba55 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -4450,6 +4450,7 @@
                 if (visible) {
                     mOpeningApps.add(wtoken);
                     wtoken.startingMoved = false;
+                    wtoken.mEnteringAnimation = true;
 
                     // If the token is currently hidden (should be the
                     // common case), then we need to set up to wait for
@@ -4472,6 +4473,7 @@
                     }
                 } else {
                     mClosingApps.add(wtoken);
+                    wtoken.mEnteringAnimation = false;
 
                     // If the token is currently visible (should be the
                     // common case), then set up to wait for it to be hidden.
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index bf2edc8..9e67908 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -930,7 +930,9 @@
                 mSystemServiceManager.startService(HdmiControlService.class);
             }
 
-            mSystemServiceManager.startService(TvInputManagerService.class);
+            if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
+                mSystemServiceManager.startService(TvInputManagerService.class);
+            }
 
             if (!disableNonCoreServices) {
                 try {