Merge "Fix NPE crash when mPhone is null" into lmp-dev
diff --git a/api/current.txt b/api/current.txt
index 2cd1708..047f8d5 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -14832,7 +14832,6 @@
   }
 
   public static final class MediaDrm.MediaDrmStateException extends java.lang.IllegalStateException {
-    ctor public MediaDrm.MediaDrmStateException(int, java.lang.String);
     method public java.lang.String getDiagnosticInfo();
   }
 
@@ -28046,328 +28045,16 @@
 
 package android.telecom {
 
-  public final class AudioState implements android.os.Parcelable {
-    ctor public AudioState(boolean, int, int);
-    ctor public AudioState(android.telecom.AudioState);
-    method public int describeContents();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator CREATOR;
-    field public static final int ROUTE_BLUETOOTH = 2; // 0x2
-    field public static final int ROUTE_EARPIECE = 1; // 0x1
-    field public static final int ROUTE_SPEAKER = 8; // 0x8
-    field public static final int ROUTE_WIRED_HEADSET = 4; // 0x4
-    field public static final int ROUTE_WIRED_OR_EARPIECE = 5; // 0x5
-    field public final boolean isMuted;
-    field public final int route;
-    field public final int supportedRouteMask;
-  }
-
-  public abstract class Conference {
-    ctor public Conference(android.telecom.PhoneAccountHandle);
-    method public final boolean addConnection(android.telecom.Connection);
-    method public final void destroy();
-    method public final android.telecom.AudioState getAudioState();
-    method public final int getCapabilities();
-    method public final java.util.List<android.telecom.Connection> getConnections();
-    method public final android.telecom.PhoneAccountHandle getPhoneAccountHandle();
-    method public final int getState();
-    method public void onAudioStateChanged(android.telecom.AudioState);
-    method public void onDisconnect();
-    method public void onHold();
-    method public void onMerge();
-    method public void onPlayDtmfTone(char);
-    method public void onSeparate(android.telecom.Connection);
-    method public void onStopDtmfTone();
-    method public void onSwap();
-    method public void onUnhold();
-    method public final void removeConnection(android.telecom.Connection);
-    method public final void setActive();
-    method public final void setCapabilities(int);
-    method public final void setDisconnected(android.telecom.DisconnectCause);
-    method public final void setOnHold();
-  }
-
-  public abstract class Connection {
-    ctor public Connection();
-    method public static android.telecom.Connection createCanceledConnection();
-    method public static android.telecom.Connection createFailedConnection(android.telecom.DisconnectCause);
-    method public final void destroy();
-    method public final android.net.Uri getAddress();
-    method public final int getAddressPresentation();
-    method public final boolean getAudioModeIsVoip();
-    method public final android.telecom.AudioState getAudioState();
-    method public final int getCallCapabilities();
-    method public final java.lang.String getCallerDisplayName();
-    method public final int getCallerDisplayNamePresentation();
-    method public final android.telecom.Conference getConference();
-    method public final java.util.List<android.telecom.Connection> getConferenceableConnections();
-    method public final android.telecom.DisconnectCause getDisconnectCause();
-    method public final int getState();
-    method public final android.telecom.StatusHints getStatusHints();
-    method public final boolean isRingbackRequested();
-    method public void onAbort();
-    method public void onAnswer();
-    method public void onAudioStateChanged(android.telecom.AudioState);
-    method public void onConferenceWith(android.telecom.Connection);
-    method public void onDisconnect();
-    method public void onHold();
-    method public void onPlayDtmfTone(char);
-    method public void onPostDialContinue(boolean);
-    method public void onReject();
-    method public void onSeparate();
-    method public void onStateChanged(int);
-    method public void onStopDtmfTone();
-    method public void onUnhold();
-    method public final void setActive();
-    method public final void setAddress(android.net.Uri, int);
-    method public final void setAudioModeIsVoip(boolean);
-    method public final void setCallCapabilities(int);
-    method public final void setCallerDisplayName(java.lang.String, int);
-    method public final void setConferenceableConnections(java.util.List<android.telecom.Connection>);
-    method public final void setConnectionService(android.telecom.ConnectionService);
-    method public final void setDialing();
-    method public final void setDisconnected(android.telecom.DisconnectCause);
-    method public final void setInitialized();
-    method public final void setInitializing();
-    method public final void setOnHold();
-    method public final void setPostDialWait(java.lang.String);
-    method public final void setRingbackRequested(boolean);
-    method public final void setRinging();
-    method public final void setStatusHints(android.telecom.StatusHints);
-    method public static java.lang.String stateToString(int);
-    field public static final int STATE_ACTIVE = 4; // 0x4
-    field public static final int STATE_DIALING = 3; // 0x3
-    field public static final int STATE_DISCONNECTED = 6; // 0x6
-    field public static final int STATE_HOLDING = 5; // 0x5
-    field public static final int STATE_INITIALIZING = 0; // 0x0
-    field public static final int STATE_NEW = 1; // 0x1
-    field public static final int STATE_RINGING = 2; // 0x2
-  }
-
-  public final class ConnectionRequest implements android.os.Parcelable {
-    ctor public ConnectionRequest(android.telecom.PhoneAccountHandle, android.net.Uri, android.os.Bundle);
-    method public int describeContents();
-    method public android.telecom.PhoneAccountHandle getAccountHandle();
-    method public android.net.Uri getAddress();
-    method public android.os.Bundle getExtras();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator CREATOR;
-  }
-
-  public abstract class ConnectionService extends android.app.Service {
-    ctor public ConnectionService();
-    method public final void addConference(android.telecom.Conference);
-    method public final void conferenceRemoteConnections(android.telecom.RemoteConnection, android.telecom.RemoteConnection);
-    method public final android.telecom.RemoteConnection createRemoteIncomingConnection(android.telecom.PhoneAccountHandle, android.telecom.ConnectionRequest);
-    method public final android.telecom.RemoteConnection createRemoteOutgoingConnection(android.telecom.PhoneAccountHandle, android.telecom.ConnectionRequest);
-    method public final java.util.Collection<android.telecom.Connection> getAllConnections();
-    method public final android.os.IBinder onBind(android.content.Intent);
-    method public void onConference(android.telecom.Connection, android.telecom.Connection);
-    method public android.telecom.Connection onCreateIncomingConnection(android.telecom.PhoneAccountHandle, android.telecom.ConnectionRequest);
-    method public android.telecom.Connection onCreateOutgoingConnection(android.telecom.PhoneAccountHandle, android.telecom.ConnectionRequest);
-    method public void onRemoteConferenceAdded(android.telecom.RemoteConference);
-    field public static final java.lang.String SERVICE_INTERFACE = "android.telecom.ConnectionService";
-  }
-
-  public final class DisconnectCause implements android.os.Parcelable {
-    ctor public DisconnectCause(int);
-    ctor public DisconnectCause(int, java.lang.String);
-    ctor public DisconnectCause(int, java.lang.CharSequence, java.lang.CharSequence, java.lang.String);
-    ctor public DisconnectCause(int, java.lang.CharSequence, java.lang.CharSequence, java.lang.String, int);
-    method public int describeContents();
-    method public int getCode();
-    method public java.lang.CharSequence getDescription();
-    method public java.lang.CharSequence getLabel();
-    method public java.lang.String getReason();
-    method public int getTone();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final int BUSY = 7; // 0x7
-    field public static final int CANCELED = 4; // 0x4
-    field public static final android.os.Parcelable.Creator CREATOR;
-    field public static final int ERROR = 1; // 0x1
-    field public static final int LOCAL = 2; // 0x2
-    field public static final int MISSED = 5; // 0x5
-    field public static final int OTHER = 9; // 0x9
-    field public static final int REJECTED = 6; // 0x6
-    field public static final int REMOTE = 3; // 0x3
-    field public static final int RESTRICTED = 8; // 0x8
-    field public static final int UNKNOWN = 0; // 0x0
-  }
-
-  public class GatewayInfo implements android.os.Parcelable {
-    method public int describeContents();
-    method public android.net.Uri getGatewayAddress();
-    method public java.lang.String getGatewayProviderPackageName();
-    method public android.net.Uri getOriginalAddress();
-    method public boolean isEmpty();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator CREATOR;
-  }
-
-  public class PhoneAccount implements android.os.Parcelable {
-    method public static android.telecom.PhoneAccount.Builder builder(android.telecom.PhoneAccountHandle, java.lang.CharSequence);
-    method public int describeContents();
-    method public android.telecom.PhoneAccountHandle getAccountHandle();
-    method public android.net.Uri getAddress();
-    method public int getCapabilities();
-    method public android.graphics.drawable.Drawable getIcon(android.content.Context);
-    method public int getIconResId();
-    method public java.lang.CharSequence getLabel();
-    method public java.lang.CharSequence getShortDescription();
-    method public android.net.Uri getSubscriptionAddress();
-    method public java.util.List<java.lang.String> getSupportedUriSchemes();
-    method public boolean hasCapabilities(int);
-    method public boolean supportsUriScheme(java.lang.String);
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final int CAPABILITY_CONNECTION_MANAGER = 1; // 0x1
-    field public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 16; // 0x10
-    field public static final int CAPABILITY_SIM_SUBSCRIPTION = 4; // 0x4
-    field public static final android.os.Parcelable.Creator CREATOR;
-    field public static final java.lang.String SCHEME_SIP = "sip";
-    field public static final java.lang.String SCHEME_TEL = "tel";
-    field public static final java.lang.String SCHEME_VOICEMAIL = "voicemail";
-  }
-
-  public static class PhoneAccount.Builder {
-    ctor public PhoneAccount.Builder(android.telecom.PhoneAccountHandle, java.lang.CharSequence);
-    ctor public PhoneAccount.Builder(android.telecom.PhoneAccount);
-    method public android.telecom.PhoneAccount build();
-    method public android.telecom.PhoneAccount.Builder setAddress(android.net.Uri);
-    method public android.telecom.PhoneAccount.Builder setCapabilities(int);
-    method public android.telecom.PhoneAccount.Builder setIconResId(int);
-    method public android.telecom.PhoneAccount.Builder setShortDescription(java.lang.CharSequence);
-    method public android.telecom.PhoneAccount.Builder setSubscriptionAddress(android.net.Uri);
-    method public android.telecom.PhoneAccount.Builder setSupportedUriSchemes(java.util.List<java.lang.String>);
-  }
-
-  public class PhoneAccountHandle implements android.os.Parcelable {
-    ctor public PhoneAccountHandle(android.content.ComponentName, java.lang.String);
-    method public int describeContents();
-    method public android.content.ComponentName getComponentName();
-    method public java.lang.String getId();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator CREATOR;
-  }
-
-  public final class PhoneCapabilities {
-    method public static java.lang.String toString(int);
-    field public static final int ADD_CALL = 16; // 0x10
-    field public static final int ALL = 12543; // 0x30ff
-    field public static final int DISCONNECT_FROM_CONFERENCE = 8192; // 0x2000
-    field public static final int HOLD = 1; // 0x1
-    field public static final int MANAGE_CONFERENCE = 128; // 0x80
-    field public static final int MERGE_CONFERENCE = 4; // 0x4
-    field public static final int MUTE = 64; // 0x40
-    field public static final int RESPOND_VIA_TEXT = 32; // 0x20
-    field public static final int SEPARATE_FROM_CONFERENCE = 4096; // 0x1000
-    field public static final int SUPPORT_HOLD = 2; // 0x2
-    field public static final int SWAP_CONFERENCE = 8; // 0x8
-  }
-
-  public final class RemoteConference {
-    method public void disconnect();
-    method public final int getCallCapabilities();
-    method public final java.util.List<android.telecom.RemoteConnection> getConnections();
-    method public android.telecom.DisconnectCause getDisconnectCause();
-    method public final int getState();
-    method public void hold();
-    method public void playDtmfTone(char);
-    method public final void registerCallback(android.telecom.RemoteConference.Callback);
-    method public void separate(android.telecom.RemoteConnection);
-    method public void setAudioState(android.telecom.AudioState);
-    method public void stopDtmfTone();
-    method public void unhold();
-    method public final void unregisterCallback(android.telecom.RemoteConference.Callback);
-  }
-
-  public static abstract class RemoteConference.Callback {
-    ctor public RemoteConference.Callback();
-    method public void onCapabilitiesChanged(android.telecom.RemoteConference, int);
-    method public void onConnectionAdded(android.telecom.RemoteConference, android.telecom.RemoteConnection);
-    method public void onConnectionRemoved(android.telecom.RemoteConference, android.telecom.RemoteConnection);
-    method public void onDestroyed(android.telecom.RemoteConference);
-    method public void onDisconnected(android.telecom.RemoteConference, android.telecom.DisconnectCause);
-    method public void onStateChanged(android.telecom.RemoteConference, int, int);
-  }
-
-  public final class RemoteConnection {
-    method public void abort();
-    method public void answer();
-    method public void disconnect();
-    method public android.net.Uri getAddress();
-    method public int getAddressPresentation();
-    method public int getCallCapabilities();
-    method public java.lang.CharSequence getCallerDisplayName();
-    method public int getCallerDisplayNamePresentation();
-    method public android.telecom.RemoteConference getConference();
-    method public java.util.List<android.telecom.RemoteConnection> getConferenceableConnections();
-    method public android.telecom.DisconnectCause getDisconnectCause();
-    method public int getState();
-    method public android.telecom.StatusHints getStatusHints();
-    method public void hold();
-    method public boolean isRingbackRequested();
-    method public boolean isVoipAudioMode();
-    method public void playDtmfTone(char);
-    method public void postDialContinue(boolean);
-    method public void registerCallback(android.telecom.RemoteConnection.Callback);
-    method public void reject();
-    method public void setAudioState(android.telecom.AudioState);
-    method public void stopDtmfTone();
-    method public void unhold();
-    method public void unregisterCallback(android.telecom.RemoteConnection.Callback);
-  }
-
-  public static abstract class RemoteConnection.Callback {
-    ctor public RemoteConnection.Callback();
-    method public void onAddressChanged(android.telecom.RemoteConnection, android.net.Uri, int);
-    method public void onCallCapabilitiesChanged(android.telecom.RemoteConnection, int);
-    method public void onCallerDisplayNameChanged(android.telecom.RemoteConnection, java.lang.String, int);
-    method public void onConferenceChanged(android.telecom.RemoteConnection, android.telecom.RemoteConference);
-    method public void onConferenceableConnectionsChanged(android.telecom.RemoteConnection, java.util.List<android.telecom.RemoteConnection>);
-    method public void onDestroyed(android.telecom.RemoteConnection);
-    method public void onDisconnected(android.telecom.RemoteConnection, android.telecom.DisconnectCause);
-    method public void onPostDialWait(android.telecom.RemoteConnection, java.lang.String);
-    method public void onRingbackRequested(android.telecom.RemoteConnection, boolean);
-    method public void onStateChanged(android.telecom.RemoteConnection, int);
-    method public void onStatusHintsChanged(android.telecom.RemoteConnection, android.telecom.StatusHints);
-    method public void onVoipAudioChanged(android.telecom.RemoteConnection, boolean);
-  }
-
-  public final class StatusHints implements android.os.Parcelable {
-    ctor public StatusHints(android.content.ComponentName, java.lang.CharSequence, int, android.os.Bundle);
-    method public int describeContents();
-    method public android.os.Bundle getExtras();
-    method public android.graphics.drawable.Drawable getIcon(android.content.Context);
-    method public int getIconResId();
-    method public java.lang.CharSequence getLabel();
-    method public android.content.ComponentName getPackageName();
-    method public void writeToParcel(android.os.Parcel, int);
-    field public static final android.os.Parcelable.Creator CREATOR;
-  }
-
   public class TelecomManager {
-    method public void addNewIncomingCall(android.telecom.PhoneAccountHandle, android.os.Bundle);
     method public void cancelMissedCallsNotification();
-    method public void clearAccounts();
-    method public android.telecom.PhoneAccountHandle getConnectionManager();
-    method public android.telecom.PhoneAccount getPhoneAccount(android.telecom.PhoneAccountHandle);
-    method public java.util.List<android.telecom.PhoneAccountHandle> getPhoneAccountsForPackage();
     method public boolean handleMmi(java.lang.String);
-    method public boolean hasMultipleCallCapableAccounts();
     method public boolean isInCall();
-    method public void registerPhoneAccount(android.telecom.PhoneAccount);
     method public void showInCallScreen(boolean);
-    method public void unregisterPhoneAccount(android.telecom.PhoneAccountHandle);
-    field public static final java.lang.String ACTION_CHANGE_PHONE_ACCOUNTS = "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
-    field public static final java.lang.String ACTION_CONNECTION_SERVICE_CONFIGURE = "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
     field public static final java.lang.String ACTION_SHOW_CALL_SETTINGS = "android.telecom.action.SHOW_CALL_SETTINGS";
     field public static final char DTMF_CHARACTER_PAUSE = 44; // 0x002c ','
     field public static final char DTMF_CHARACTER_WAIT = 59; // 0x003b ';'
-    field public static final java.lang.String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
     field public static final java.lang.String EXTRA_CALL_DISCONNECT_CAUSE = "android.telecom.extra.CALL_DISCONNECT_CAUSE";
     field public static final java.lang.String EXTRA_CALL_DISCONNECT_MESSAGE = "android.telecom.extra.CALL_DISCONNECT_MESSAGE";
-    field public static final java.lang.String EXTRA_CONNECTION_SERVICE = "android.telecom.extra.CONNECTION_SERVICE";
-    field public static final java.lang.String EXTRA_PHONE_ACCOUNT_HANDLE = "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
     field public static final java.lang.String EXTRA_START_CALL_WITH_SPEAKERPHONE = "android.telecom.extra.START_CALL_WITH_SPEAKERPHONE";
     field public static final java.lang.String GATEWAY_ORIGINAL_ADDRESS = "android.telecom.extra.GATEWAY_ORIGINAL_ADDRESS";
     field public static final java.lang.String GATEWAY_PROVIDER_PACKAGE = "android.telecom.extra.GATEWAY_PROVIDER_PACKAGE";
diff --git a/core/java/android/app/ActivityTransitionState.java b/core/java/android/app/ActivityTransitionState.java
index bc2e6ca..555d20b 100644
--- a/core/java/android/app/ActivityTransitionState.java
+++ b/core/java/android/app/ActivityTransitionState.java
@@ -67,6 +67,12 @@
     private ExitTransitionCoordinator mCalledExitCoordinator;
 
     /**
+     * The ExitTransitionCoordinator used to return to a previous Activity when called with
+     * {@link android.app.Activity#finishAfterTransition()}.
+     */
+    private ExitTransitionCoordinator mReturnExitCoordinator;
+
+    /**
      * We must be able to cancel entering transitions to stop changing the Window to
      * opaque when we exit before making the Window opaque.
      */
@@ -218,6 +224,10 @@
             mEnterTransitionCoordinator.stop();
             mEnterTransitionCoordinator = null;
         }
+        if (mReturnExitCoordinator != null) {
+            mReturnExitCoordinator.stop();
+            mReturnExitCoordinator = null;
+        }
     }
 
     public void onResume() {
@@ -260,12 +270,12 @@
                     }
                 }
 
-                ExitTransitionCoordinator exitCoordinator =
+                mReturnExitCoordinator =
                         new ExitTransitionCoordinator(activity, mEnteringNames, null, null, true);
                 if (enterViewsTransition != null && decor != null) {
                     enterViewsTransition.resume(decor);
                 }
-                exitCoordinator.startExit(activity.mResultCode, activity.mResultData);
+                mReturnExitCoordinator.startExit(activity.mResultCode, activity.mResultData);
             }
             return true;
         }
diff --git a/core/java/android/app/EnterTransitionCoordinator.java b/core/java/android/app/EnterTransitionCoordinator.java
index 216d6ba..add67f2 100644
--- a/core/java/android/app/EnterTransitionCoordinator.java
+++ b/core/java/android/app/EnterTransitionCoordinator.java
@@ -30,6 +30,7 @@
 import android.view.ViewGroup;
 import android.view.ViewGroupOverlay;
 import android.view.ViewTreeObserver;
+import android.view.Window;
 
 import java.util.ArrayList;
 
@@ -265,10 +266,14 @@
     }
 
     protected void prepareEnter() {
+        ViewGroup decorView = getDecor();
+        if (mActivity == null || decorView == null) {
+            return;
+        }
         mActivity.overridePendingTransition(0, 0);
         if (!mIsReturning) {
             mWasOpaque = mActivity.convertToTranslucent(null, null);
-            Drawable background = getDecor().getBackground();
+            Drawable background = decorView.getBackground();
             if (background != null) {
                 getWindow().setBackgroundDrawable(null);
                 background = background.mutate();
@@ -282,18 +287,26 @@
 
     @Override
     protected Transition getViewsTransition() {
+        Window window = getWindow();
+        if (window == null) {
+            return null;
+        }
         if (mIsReturning) {
-            return getWindow().getReenterTransition();
+            return window.getReenterTransition();
         } else {
-            return getWindow().getEnterTransition();
+            return window.getEnterTransition();
         }
     }
 
     protected Transition getSharedElementTransition() {
+        Window window = getWindow();
+        if (window == null) {
+            return null;
+        }
         if (mIsReturning) {
-            return getWindow().getSharedElementReenterTransition();
+            return window.getSharedElementReenterTransition();
         } else {
-            return getWindow().getSharedElementEnterTransition();
+            return window.getSharedElementEnterTransition();
         }
     }
 
@@ -518,15 +531,29 @@
     }
 
     public void stop() {
-        makeOpaque();
-        mIsCanceled = true;
-        mResultReceiver = null;
+        // Restore the background to its previous state since the
+        // Activity is stopping.
         if (mBackgroundAnimator != null) {
             mBackgroundAnimator.end();
             mBackgroundAnimator = null;
+        } else if (mWasOpaque) {
+            ViewGroup decorView = getDecor();
+            if (decorView != null) {
+                Drawable drawable = decorView.getBackground();
+                if (drawable != null) {
+                    drawable.setAlpha(1);
+                }
+            }
         }
+        makeOpaque();
+        mIsCanceled = true;
+        mResultReceiver = null;
         mActivity = null;
         moveSharedElementsFromOverlay();
+        if (mTransitioningViews != null) {
+            showViews(mTransitioningViews, true);
+        }
+        showViews(mSharedElements, true);
         clearState();
     }
 
diff --git a/core/java/android/app/ExitTransitionCoordinator.java b/core/java/android/app/ExitTransitionCoordinator.java
index d4d3eda..dd3df47 100644
--- a/core/java/android/app/ExitTransitionCoordinator.java
+++ b/core/java/android/app/ExitTransitionCoordinator.java
@@ -255,6 +255,16 @@
         }
     }
 
+    public void stop() {
+        if (mIsReturning && mActivity != null) {
+            // Override the previous ActivityOptions. We don't want the
+            // activity to have options since we're essentially canceling the
+            // transition and finishing right now.
+            mActivity.convertToTranslucent(null, null);
+            finish();
+        }
+    }
+
     private void startExitTransition() {
         Transition transition = getExitTransition();
         ViewGroup decorView = getDecor();
@@ -425,13 +435,14 @@
 
     private void finish() {
         stopCancel();
-        mActivity.mActivityTransitionState.clear();
+        if (mActivity != null) {
+            mActivity.mActivityTransitionState.clear();
+            mActivity.finish();
+            mActivity.overridePendingTransition(0, 0);
+            mActivity = null;
+        }
         // Clear the state so that we can't hold any references accidentally and leak memory.
-        mHandler.removeMessages(MSG_CANCEL);
         mHandler = null;
-        mActivity.finish();
-        mActivity.overridePendingTransition(0, 0);
-        mActivity = null;
         mSharedElementBundle = null;
         if (mBackgroundAnimator != null) {
             mBackgroundAnimator.cancel();
diff --git a/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java b/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
index 4aa330d..e19f587 100644
--- a/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
+++ b/core/java/android/hardware/camera2/legacy/CameraDeviceUserShim.java
@@ -87,6 +87,15 @@
         mSurfaceIdCounter = 0;
     }
 
+    private static int translateErrorsFromCamera1(int errorCode) {
+        switch (errorCode) {
+            case CameraBinderDecorator.EACCES:
+                return CameraBinderDecorator.PERMISSION_DENIED;
+            default:
+                return errorCode;
+        }
+    }
+
     /**
      * Create a separate looper/thread for the camera to run on; open the camera.
      *
@@ -130,8 +139,7 @@
             // Save the looper so that we can terminate this thread
             // after we are done with it.
             mLooper = Looper.myLooper();
-            mInitErrors = mCamera.cameraInitUnspecified(mCameraId);
-
+            mInitErrors = translateErrorsFromCamera1(mCamera.cameraInitUnspecified(mCameraId));
             mStartDone.open();
             Looper.loop();  // Blocks forever until #close is called.
         }
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index d458ee4..673f075 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -955,14 +955,19 @@
      */
     public void screenTurningOn(ScreenOnListener screenOnListener);
 
+    /**
+     * Called when the device has turned the screen off.
+     */
+    public void screenTurnedOff();
+
     public interface ScreenOnListener {
         void onScreenOn();
     }
 
     /**
-     * Return whether the system is awake.
+     * Return whether the default display is on and not blocked by a black surface.
      */
-    public boolean isAwake();
+    public boolean isScreenOn();
 
     /**
      * Tell the policy that the lid switch has changed state.
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index af53ec8..2b8b4dc 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -611,6 +611,12 @@
     private final int[] mScrollOffset = new int[2];
     private final int[] mScrollConsumed = new int[2];
 
+    // Used for offsetting MotionEvents that we feed to the VelocityTracker.
+    // In the future it would be nice to be able to give this to the VelocityTracker
+    // directly, or alternatively put a VT into absolute-positioning mode that only
+    // reads the raw screen-coordinate x/y values.
+    private int mNestedYOffset = 0;
+
     // True when the popup should be hidden because of a call to
     // dispatchDisplayHint()
     private boolean mPopupHidden;
@@ -3330,6 +3336,7 @@
             scrollConsumedCorrection = mScrollConsumed[1];
             if (vtev != null) {
                 vtev.offsetLocation(0, mScrollOffset[1]);
+                mNestedYOffset += mScrollOffset[1];
             }
         }
         final int deltaY = rawDeltaY;
@@ -3399,6 +3406,7 @@
                             lastYCorrection -= mScrollOffset[1];
                             if (vtev != null) {
                                 vtev.offsetLocation(0, mScrollOffset[1]);
+                                mNestedYOffset += mScrollOffset[1];
                             }
                         } else {
                             final boolean atOverscrollEdge = overScrollBy(0, overscroll,
@@ -3582,6 +3590,10 @@
         final MotionEvent vtev = MotionEvent.obtain(ev);
 
         final int actionMasked = ev.getActionMasked();
+        if (actionMasked == MotionEvent.ACTION_DOWN) {
+            mNestedYOffset = 0;
+        }
+        vtev.offsetLocation(0, mNestedYOffset);
         switch (actionMasked) {
             case MotionEvent.ACTION_DOWN: {
                 onTouchDown(ev);
@@ -4144,7 +4156,7 @@
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent ev) {
-        int action = ev.getAction();
+        final int actionMasked = ev.getActionMasked();
         View v;
 
         if (mPositionScroller != null) {
@@ -4163,7 +4175,7 @@
             return true;
         }
 
-        switch (action & MotionEvent.ACTION_MASK) {
+        switch (actionMasked) {
         case MotionEvent.ACTION_DOWN: {
             int touchMode = mTouchMode;
             if (touchMode == TOUCH_MODE_OVERFLING || touchMode == TOUCH_MODE_OVERSCROLL) {
@@ -4190,6 +4202,7 @@
             mLastY = Integer.MIN_VALUE;
             initOrResetVelocityTracker();
             mVelocityTracker.addMovement(ev);
+            mNestedYOffset = 0;
             startNestedScroll(SCROLL_AXIS_VERTICAL);
             if (touchMode == TOUCH_MODE_FLING) {
                 return true;
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index dd312a6..a90b392 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -142,6 +142,7 @@
      */
     private final int[] mScrollOffset = new int[2];
     private final int[] mScrollConsumed = new int[2];
+    private int mNestedYOffset;
 
     /**
      * The StrictMode "critical time span" objects to catch animation
@@ -516,6 +517,7 @@
                     mLastMotionY = y;
                     initVelocityTrackerIfNotExists();
                     mVelocityTracker.addMovement(ev);
+                    mNestedYOffset = 0;
                     if (mScrollStrictSpan == null) {
                         mScrollStrictSpan = StrictMode.enterCriticalSpan("ScrollView-scroll");
                     }
@@ -586,9 +588,14 @@
 
         MotionEvent vtev = MotionEvent.obtain(ev);
 
-        final int action = ev.getAction();
+        final int actionMasked = ev.getActionMasked();
 
-        switch (action & MotionEvent.ACTION_MASK) {
+        if (actionMasked == MotionEvent.ACTION_DOWN) {
+            mNestedYOffset = 0;
+        }
+        vtev.offsetLocation(0, mNestedYOffset);
+
+        switch (actionMasked) {
             case MotionEvent.ACTION_DOWN: {
                 if (getChildCount() == 0) {
                     return false;
@@ -630,6 +637,7 @@
                 if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
                     deltaY -= mScrollConsumed[1];
                     vtev.offsetLocation(0, mScrollOffset[1]);
+                    mNestedYOffset += mScrollOffset[1];
                 }
                 if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) {
                     final ViewParent parent = getParent();
@@ -666,6 +674,7 @@
                     if (dispatchNestedScroll(0, scrolledDeltaY, 0, unconsumedY, mScrollOffset)) {
                         mLastMotionY -= mScrollOffset[1];
                         vtev.offsetLocation(0, mScrollOffset[1]);
+                        mNestedYOffset += mScrollOffset[1];
                     } else if (canOverscroll) {
                         final int pulledToY = oldY + deltaY;
                         if (pulledToY < 0) {
diff --git a/core/java/com/android/internal/app/ProcessStats.java b/core/java/com/android/internal/app/ProcessStats.java
index 4995ea1..a92cb74 100644
--- a/core/java/com/android/internal/app/ProcessStats.java
+++ b/core/java/com/android/internal/app/ProcessStats.java
@@ -3570,6 +3570,10 @@
             return mOwner != null || mRestarting;
         }
 
+        public boolean isRestarting() {
+            return mRestarting;
+        }
+
         void add(ServiceState other) {
             addDurations(other);
             mRunCount += other.mRunCount;
diff --git a/core/res/res/drawable-hdpi/ic_menu_refresh.png b/core/res/res/drawable-hdpi/ic_menu_refresh.png
deleted file mode 100644
index e13315f..0000000
--- a/core/res/res/drawable-hdpi/ic_menu_refresh.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-hdpi/ic_notification_cast_on.png b/core/res/res/drawable-hdpi/ic_notification_cast_on.png
deleted file mode 100644
index 3eaf13a..0000000
--- a/core/res/res/drawable-hdpi/ic_notification_cast_on.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-ldpi/ic_menu_refresh.png b/core/res/res/drawable-ldpi/ic_menu_refresh.png
deleted file mode 100644
index b25dc06..0000000
--- a/core/res/res/drawable-ldpi/ic_menu_refresh.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_menu_refresh.png b/core/res/res/drawable-mdpi/ic_menu_refresh.png
deleted file mode 100644
index 30b660f..0000000
--- a/core/res/res/drawable-mdpi/ic_menu_refresh.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-mdpi/ic_notification_cast_on.png b/core/res/res/drawable-mdpi/ic_notification_cast_on.png
deleted file mode 100644
index 42de8c4..0000000
--- a/core/res/res/drawable-mdpi/ic_notification_cast_on.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_menu_refresh.png b/core/res/res/drawable-xhdpi/ic_menu_refresh.png
deleted file mode 100644
index 9e9f10e..0000000
--- a/core/res/res/drawable-xhdpi/ic_menu_refresh.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xhdpi/ic_notification_cast_on.png b/core/res/res/drawable-xhdpi/ic_notification_cast_on.png
deleted file mode 100644
index 142065b..0000000
--- a/core/res/res/drawable-xhdpi/ic_notification_cast_on.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xxhdpi/ic_menu_refresh.png b/core/res/res/drawable-xxhdpi/ic_menu_refresh.png
deleted file mode 100644
index 580f4cf..0000000
--- a/core/res/res/drawable-xxhdpi/ic_menu_refresh.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-xxhdpi/ic_notification_cast_on.png b/core/res/res/drawable-xxhdpi/ic_notification_cast_on.png
deleted file mode 100644
index d562602..0000000
--- a/core/res/res/drawable-xxhdpi/ic_notification_cast_on.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable/ic_menu_refresh.xml b/core/res/res/drawable/ic_menu_refresh.xml
new file mode 100644
index 0000000..e0fbccb
--- /dev/null
+++ b/core/res/res/drawable/ic_menu_refresh.xml
@@ -0,0 +1,25 @@
+<!--
+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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24"
+        android:tint="?attr/colorControlNormal">
+    <path
+        android:pathData="M17.6,6.4C16.2,4.9 14.2,4 12,4c-4.4,0 -8,3.6 -8,8s3.6,8 8,8c3.7,0 6.8,-2.6 7.7,-6l-2.1,0c-0.8,2.3 -3,4 -5.6,4c-3.3,0 -6,-2.7 -6,-6s2.7,-6 6,-6c1.7,0 3.1,0.7 4.2,1.8L13,11l7,0L20,4L17.6,6.4z"
+        android:fillColor="@color/white"/>
+</vector>
diff --git a/core/res/res/drawable/ic_notification_cast_connecting.xml b/core/res/res/drawable/ic_notification_cast_connecting.xml
deleted file mode 100644
index a390bce..0000000
--- a/core/res/res/drawable/ic_notification_cast_connecting.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/*
- * Copyright 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.
- */
--->
-<animation-list
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        android:oneshot="false">
-    <item android:drawable="@drawable/ic_notification_cast_0" android:duration="500" />
-    <item android:drawable="@drawable/ic_notification_cast_1" android:duration="500" />
-    <item android:drawable="@drawable/ic_notification_cast_2" android:duration="500" />
-    <item android:drawable="@drawable/ic_notification_cast_1" android:duration="500" />
-</animation-list>
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index e9c5152..b49fc90 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -992,9 +992,11 @@
     <!-- 2 means give warning -->
     <integer name="config_datause_notification_type">2</integer>
 
-    <!-- If Voice Radio Technology is RIL_RADIO_TECHNOLOGY_LTE:14 this is the value
-         that should be used instead. A value of RIL_RADIO_TECHNOLOGY_UNKNOWN:0 means
-         there is no replacement value and VoLTE is assumed to be supported -->
+    <!-- If Voice Radio Technology is RIL_RADIO_TECHNOLOGY_LTE:14 or
+         RIL_RADIO_TECHNOLOGY_UNKNOWN:0 this is the value that should be used instead.
+         A configuration value of RIL_RADIO_TECHNOLOGY_UNKNOWN:0 means
+         there is no replacement value and that the default assumption
+         for phone type (GSM) should be used. -->
     <integer name="config_volte_replacement_rat">0</integer>
 
     <!-- Flag indicating whether the current device is "voice capable".
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 50da1fa..fd4b40f 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -4409,17 +4409,6 @@
     <!-- Title text to append when the display is secure.  [CHAR LIMIT=30] -->
     <string name="display_manager_overlay_display_secure_suffix">, secure</string>
 
-    <!-- Title of the notification to indicate the process of connecting to a wifi display.  [CHAR LIMIT=50] -->
-    <string name="wifi_display_notification_connecting_title">Casting screen</string>
-    <!-- Message of the notification to indicate the process of connecting to a wifi display.  [CHAR LIMIT=80] -->
-    <string name="wifi_display_notification_connecting_message">Connecting to <xliff:g id="name">%1$s</xliff:g></string>
-    <!-- Title of the notification to indicate an active wifi display connection.  [CHAR LIMIT=50] -->
-    <string name="wifi_display_notification_connected_title">Casting screen</string>
-    <!-- Message of the notification to indicate an active wifi display connection.  [CHAR LIMIT=80] -->
-    <string name="wifi_display_notification_connected_message">Connected to <xliff:g id="name">%1$s</xliff:g></string>
-    <!-- Label of a button to disconnect an active wifi display connection.  [CHAR LIMIT=25] -->
-    <string name="wifi_display_notification_disconnect">Disconnect</string>
-
     <!-- Keyguard strings -->
     <!-- Label shown on emergency call button in keyguard -->
     <string name="kg_emergency_call_label">Emergency call</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index c580d26..66afffb 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -1185,8 +1185,6 @@
   <java-symbol type="drawable" name="ic_media_route_off_holo_dark" />
   <java-symbol type="drawable" name="ic_media_route_connecting_holo_dark" />
   <java-symbol type="drawable" name="ic_media_route_disabled_holo_dark" />
-  <java-symbol type="drawable" name="ic_notification_cast_connecting" />
-  <java-symbol type="drawable" name="ic_notification_cast_on" />
   <java-symbol type="drawable" name="cling_button" />
   <java-symbol type="drawable" name="cling_arrow_up" />
   <java-symbol type="drawable" name="cling_bg" />
@@ -1723,11 +1721,6 @@
   <java-symbol type="string" name="vpn_lockdown_error" />
   <java-symbol type="string" name="vpn_lockdown_config" />
   <java-symbol type="string" name="wallpaper_binding_label" />
-  <java-symbol type="string" name="wifi_display_notification_connecting_title" />
-  <java-symbol type="string" name="wifi_display_notification_connecting_message" />
-  <java-symbol type="string" name="wifi_display_notification_connected_title" />
-  <java-symbol type="string" name="wifi_display_notification_connected_message" />
-  <java-symbol type="string" name="wifi_display_notification_disconnect" />
   <java-symbol type="style" name="Theme.Dialog.AppError" />
   <java-symbol type="style" name="Theme.Micro.Dialog.Alert" />
   <java-symbol type="style" name="Theme.Leanback.Dialog.Alert" />
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index ace5eab..bbb0b50 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -1456,12 +1456,12 @@
 
         /* Setters and Getters, used by animator from AnimatedVectorDrawable. */
         @SuppressWarnings("unused")
-        int getStroke() {
+        int getStrokeColor() {
             return mStrokeColor;
         }
 
         @SuppressWarnings("unused")
-        void setStroke(int strokeColor) {
+        void setStrokeColor(int strokeColor) {
             mStrokeColor = strokeColor;
         }
 
@@ -1476,32 +1476,32 @@
         }
 
         @SuppressWarnings("unused")
-        float getstrokeAlpha() {
+        float getStrokeAlpha() {
             return mStrokeAlpha;
         }
 
         @SuppressWarnings("unused")
-        void setstrokeAlpha(float strokeAlpha) {
+        void setStrokeAlpha(float strokeAlpha) {
             mStrokeAlpha = strokeAlpha;
         }
 
         @SuppressWarnings("unused")
-        int getFill() {
+        int getFillColor() {
             return mFillColor;
         }
 
         @SuppressWarnings("unused")
-        void setFill(int fillColor) {
+        void setFillColor(int fillColor) {
             mFillColor = fillColor;
         }
 
         @SuppressWarnings("unused")
-        float getfillAlpha() {
+        float getFillAlpha() {
             return mFillAlpha;
         }
 
         @SuppressWarnings("unused")
-        void setfillAlpha(float fillAlpha) {
+        void setFillAlpha(float fillAlpha) {
             mFillAlpha = fillAlpha;
         }
 
diff --git a/media/java/android/media/MediaCodec.java b/media/java/android/media/MediaCodec.java
index 2ef9289..5fb4f12 100644
--- a/media/java/android/media/MediaCodec.java
+++ b/media/java/android/media/MediaCodec.java
@@ -709,10 +709,10 @@
         }
 
         /**
-         * Retrieve a human readable diagnostic information string
-         * associated with the exception. DO NOT SHOW THIS TO END-USERS!
-         * This string will not be localized or generally comprehensible
-         * to end-users.
+         * Retrieve a developer-readable diagnostic information string
+         * associated with the exception. Do not show this to end-users,
+         * since this string will not be localized or generally
+         * comprehensible to end-users.
          */
         public String getDiagnosticInfo() {
             return mDiagnosticInfo;
diff --git a/media/java/android/media/MediaDrm.java b/media/java/android/media/MediaDrm.java
index 1490732..3b8cb19 100644
--- a/media/java/android/media/MediaDrm.java
+++ b/media/java/android/media/MediaDrm.java
@@ -190,6 +190,9 @@
         private final int mErrorCode;
         private final String mDiagnosticInfo;
 
+        /**
+         * @hide
+         */
         public MediaDrmStateException(int errorCode, String detailMessage) {
             super(detailMessage);
             mErrorCode = errorCode;
@@ -211,9 +214,9 @@
         }
 
         /**
-         * Retrieve a human readable diagnostic information string
-         * associated with the exception. DO NOT SHOW THIS TO END-USERS!
-         * This string will not be localized or generally comprehensible
+         * Retrieve a developer-readable diagnostic information string
+         * associated with the exception. Do not show this to end-users,
+         * since this string will not be localized or generally comprehensible
          * to end-users.
          */
         public String getDiagnosticInfo() {
diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java
index be86741..cfbf3af 100644
--- a/media/java/android/media/session/MediaController.java
+++ b/media/java/android/media/session/MediaController.java
@@ -434,6 +434,14 @@
         return mSessionBinder;
     }
 
+    /**
+     * @hide
+     */
+    public boolean controlsSameSession(MediaController other) {
+        if (other == null) return false;
+        return mSessionBinder.asBinder() == other.getSessionBinder().asBinder();
+    }
+
     private void addCallbackLocked(Callback cb, Handler handler) {
         if (getHandlerForCallbackLocked(cb) != null) {
             Log.w(TAG, "Callback is already added, ignoring");
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index bddd691..1d629fd 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -48,6 +48,7 @@
     <uses-permission android:name="android.permission.BLUETOOTH" />
     <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
     <uses-permission android:name="android.permission.READ_PHONE_STATE" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
     <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java
index b07e993..6cc890b 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeService.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeService.java
@@ -199,8 +199,8 @@
                     if (mPulsing && mDreaming) {
                         mPulsing = false;
                         turnDisplayOff();
-                        mWakeLock.release();
                     }
+                    mWakeLock.release(); // needs to be unconditional to balance acquire
                 }
             });
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java
index a4161f9..e2464c2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java
@@ -497,4 +497,13 @@
     public void setIsLeft(boolean left) {
         mIsLeft = left;
     }
+
+    @Override
+    public boolean performClick() {
+        if (isClickable()) {
+            return super.performClick();
+        } else {
+            return false;
+        }
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
index 754fade..fceed2f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
@@ -284,10 +284,13 @@
         if (mAccessibilityController == null) {
             return;
         }
-        mLockIcon.setClickable(mUnlockMethodCache.isTrustManaged()
-                || mAccessibilityController.isTouchExplorationEnabled());
-        mLockIcon.setLongClickable(mAccessibilityController.isTouchExplorationEnabled()
-                && mUnlockMethodCache.isTrustManaged());
+        boolean clickToUnlock = mAccessibilityController.isTouchExplorationEnabled();
+        boolean clickToForceLock = mUnlockMethodCache.isTrustManaged()
+                && !mAccessibilityController.isAccessibilityEnabled();
+        boolean longClickToForceLock = mUnlockMethodCache.isTrustManaged()
+                && !clickToForceLock;
+        mLockIcon.setClickable(clickToForceLock || clickToUnlock);
+        mLockIcon.setLongClickable(longClickToForceLock);
         mLockIcon.setFocusable(mAccessibilityController.isAccessibilityEnabled());
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
index 67c7723..95c5020 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelView.java
@@ -317,7 +317,7 @@
                     }
                     mJustPeeked = false;
                 }
-                if (-h >= mUnlockFalsingThreshold) {
+                if (-h >= getFalsingThreshold()) {
                     mTouchAboveFalsingThreshold = true;
                 }
                 if (!mJustPeeked && (!waitForTouchSlop || mTracking) && !isTrackingBlocked()) {
@@ -370,6 +370,11 @@
         return !waitForTouchSlop || mTracking;
     }
 
+    private int getFalsingThreshold() {
+        float factor = mStatusBar.isScreenOnComingFromTouch() ? 1.5f : 1.0f;
+        return (int) (mUnlockFalsingThreshold * factor);
+    }
+
     protected abstract boolean hasConflictingGestures();
 
     protected void onTrackingStopped(boolean expand) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index 90f9cdd..71fef65 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -262,6 +262,7 @@
     private StatusBarWindowManager mStatusBarWindowManager;
     private UnlockMethodCache mUnlockMethodCache;
     private DozeServiceHost mDozeServiceHost;
+    private boolean mScreenOnComingFromTouch;
 
     int mPixelFormat;
     Object mQueueLock = new Object();
@@ -1758,7 +1759,7 @@
                 }
             }
 
-            if (controller != mMediaController) {
+            if (!sameSessions(mMediaController, controller)) {
                 // We have a new media session
 
                 if (mMediaController != null) {
@@ -1807,6 +1808,12 @@
         updateMediaMetaData(metaDataChanged);
     }
 
+    private boolean sameSessions(MediaController a, MediaController b) {
+        if (a == b) return true;
+        if (a == null) return false;
+        return a.controlsSameSession(b);
+    }
+
     /**
      * Hide the album artwork that is fading out and release its bitmap.
      */
@@ -2112,10 +2119,14 @@
         return mNotificationPanel.isQsExpanded();
     }
 
+    public boolean isScreenOnComingFromTouch() {
+        return mScreenOnComingFromTouch;
+    }
+
     public boolean isFalsingThresholdNeeded() {
         boolean onKeyguard = getBarState() == StatusBarState.KEYGUARD;
         boolean isMethodInsecure = mUnlockMethodCache.isMethodInsecure();
-        return onKeyguard && (isMethodInsecure || mDozing);
+        return onKeyguard && (isMethodInsecure || mDozing || mScreenOnComingFromTouch);
     }
 
     @Override  // NotificationData.Environment
@@ -3903,6 +3914,7 @@
 
     public void onScreenTurnedOff() {
         mScreenOnFromKeyguard = false;
+        mScreenOnComingFromTouch = false;
         mStackScroller.setAnimationsEnabled(false);
     }
 
@@ -4005,10 +4017,13 @@
         return !mNotificationData.getActiveNotifications().isEmpty();
     }
 
-    public void wakeUpIfDozing(long time) {
+    public void wakeUpIfDozing(long time, boolean fromTouch) {
         if (mDozing && mScrimController.isPulsing()) {
             PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
             pm.wakeUp(time);
+            if (fromTouch) {
+                mScreenOnComingFromTouch = true;
+            }
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
index 072fb29..2cd2787 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
@@ -623,7 +623,10 @@
         mSettingsButton.setTranslationX(values.settingsTranslation);
         mSettingsButton.setRotation(values.settingsRotation);
         applyAlpha(mEmergencyCallsOnly, values.emergencyCallsOnlyAlpha);
-        applyAlpha(mAlarmStatus, values.alarmStatusAlpha);
+        if (!mShowingDetail) {
+            // Otherwise it needs to stay invisible
+            applyAlpha(mAlarmStatus, values.alarmStatusAlpha);
+        }
         applyAlpha(mDateCollapsed, values.dateCollapsedAlpha);
         applyAlpha(mDateExpanded, values.dateExpandedAlpha);
         applyAlpha(mBatteryLevel, values.batteryLevelAlpha);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java
index 89ce257..4c86990 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java
@@ -132,7 +132,7 @@
             case KeyEvent.KEYCODE_VOLUME_DOWN:
             case KeyEvent.KEYCODE_VOLUME_UP:
                 if (down) {
-                    mService.wakeUpIfDozing(event.getEventTime());
+                    mService.wakeUpIfDozing(event.getEventTime(), false);
                 }
         }
         if (mService.interceptMediaKey(event)) {
@@ -164,7 +164,7 @@
             intercept = mDragDownHelper.onInterceptTouchEvent(ev);
             // wake up on a touch down event, if dozing
             if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
-                mService.wakeUpIfDozing(ev.getEventTime());
+                mService.wakeUpIfDozing(ev.getEventTime(), true);
             }
         }
         if (!intercept) {
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index aa49d37..006f5db 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -199,7 +199,7 @@
      */
     private WindowState mKeyguardScrim;
     private boolean mKeyguardHidden;
-    private boolean mKeyguardDrawn;
+    private boolean mKeyguardDrawnOnce;
 
     /* Table of Application Launch keys.  Maps from key codes to intent categories.
      *
@@ -284,10 +284,6 @@
 
     boolean mBootMessageNeedsHiding;
     KeyguardServiceDelegate mKeyguardDelegate;
-    // The following are only accessed on the mHandler thread.
-    boolean mKeyguardDrawComplete;
-    boolean mWindowManagerDrawComplete;
-    ScreenOnListener mScreenOnListener;
     final Runnable mWindowManagerDrawCallback = new Runnable() {
         @Override
         public void run() {
@@ -351,8 +347,12 @@
     boolean mLidControlsSleep;
     int mShortPressOnPowerBehavior = -1;
     int mLongPressOnPowerBehavior = -1;
-    boolean mAwakeEarly = false;
-    boolean mAwakeFully = false;
+    boolean mAwake;
+    boolean mScreenOnEarly;
+    boolean mScreenOnFully;
+    ScreenOnListener mScreenOnListener;
+    boolean mKeyguardDrawComplete;
+    boolean mWindowManagerDrawComplete;
     boolean mOrientationSensorEnabled = false;
     int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
     boolean mHasSoftInput = false;
@@ -543,12 +543,10 @@
     private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
     private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
     private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
-    private static final int MSG_WAKING_UP = 8;
     private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
     private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
     private static final int MSG_HIDE_BOOT_MESSAGE = 11;
     private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
-    private static final int MSG_SCREEN_TURNING_ON = 13;
 
     private class PolicyHandler extends Handler {
         @Override
@@ -584,18 +582,12 @@
                     if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
                     finishWindowsDrawn();
                     break;
-                case MSG_WAKING_UP:
-                    handleWakingUp();
-                    break;
                 case MSG_HIDE_BOOT_MESSAGE:
                     handleHideBootMessage();
                     break;
                 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
                     launchVoiceAssistWithWakeLock(msg.arg1 != 0);
                     break;
-                case MSG_SCREEN_TURNING_ON:
-                    handleScreenTurningOn((ScreenOnListener)msg.obj);
-                    break;
             }
         }
     }
@@ -766,11 +758,11 @@
         }
         //Could have been invoked due to screen turning on or off or
         //change of the currently visible window's orientation
-        if (localLOGV) Slog.v(TAG, "Screen status="+mAwakeEarly+
-                ", current orientation="+mCurrentAppOrientation+
-                ", SensorEnabled="+mOrientationSensorEnabled);
+        if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
+                + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
+                + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled);
         boolean disable = true;
-        if (mAwakeEarly) {
+        if (mScreenOnEarly && mAwake) {
             if (needSensorRunningLp()) {
                 disable = false;
                 //enable listener if not already enabled
@@ -1332,7 +1324,7 @@
     }
 
     private boolean shouldEnableWakeGestureLp() {
-        return mWakeGestureEnabledSetting && !mAwakeEarly
+        return mWakeGestureEnabledSetting && !mAwake
                 && (!mLidControlsSleep || mLidState != LID_CLOSED)
                 && mWakeGestureListener.isSupported();
     }
@@ -4728,45 +4720,51 @@
         }
     }
 
+    // Called on the PowerManager's Notifier thread.
     @Override
     public void goingToSleep(int why) {
         EventLog.writeEvent(70000, 0);
         if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep...");
+
+        // We must get this work done here because the power manager will drop
+        // the wake lock and let the system suspend once this function returns.
         synchronized (mLock) {
-            mAwakeEarly = false;
-            mAwakeFully = false;
-        }
-        if (mKeyguardDelegate != null) {
-            mKeyguardDelegate.onScreenTurnedOff(why);
-        }
-        synchronized (mLock) {
+            mAwake = false;
+            mKeyguardDrawComplete = false;
             updateWakeGestureListenerLp();
             updateOrientationListenerLp();
             updateLockScreenTimeout();
         }
+
+        if (mKeyguardDelegate != null) {
+            mKeyguardDelegate.onScreenTurnedOff(why);
+        }
     }
 
+    // Called on the PowerManager's Notifier thread.
     @Override
     public void wakingUp() {
         EventLog.writeEvent(70000, 1);
         if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up...");
-        mHandler.obtainMessage(MSG_WAKING_UP).sendToTarget();
-    }
 
-    // Called on the mHandler thread.
-    private void handleWakingUp() {
+        // Since goToSleep performs these functions synchronously, we must
+        // do the same here.  We cannot post this work to a handler because
+        // that might cause it to become reordered with respect to what
+        // may happen in a future call to goToSleep.
         synchronized (mLock) {
-            mAwakeEarly = true;
+            mAwake = true;
+            mKeyguardDrawComplete = false;
+            if (mKeyguardDelegate != null) {
+                mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
+                mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
+            }
+
             updateWakeGestureListenerLp();
             updateOrientationListenerLp();
             updateLockScreenTimeout();
         }
 
-        mKeyguardDrawComplete = false;
-        mWindowManagerDrawComplete = false; // wait for later call to screenTurningOn
         if (mKeyguardDelegate != null) {
-            mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
-            mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
             mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback);
             // ... eventually calls finishKeyguardDrawn
         } else {
@@ -4775,94 +4773,130 @@
         }
     }
 
-    // Called on the mHandler thread.
     private void finishKeyguardDrawn() {
-        if (!mKeyguardDrawComplete) {
+        synchronized (mLock) {
+            if (!mAwake || mKeyguardDrawComplete) {
+                return; // spurious
+            }
+
             mKeyguardDrawComplete = true;
-            mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
-            finishScreenTurningOn();
+            if (mKeyguardDelegate != null) {
+                mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
+            }
+        }
+
+        finishScreenTurningOn();
+    }
+
+    // Called on the DisplayManager's DisplayPowerController thread.
+    @Override
+    public void screenTurnedOff() {
+        if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
+
+        synchronized (mLock) {
+            mScreenOnEarly = false;
+            mScreenOnFully = false;
+            mWindowManagerDrawComplete = false;
+            mScreenOnListener = null;
+            updateOrientationListenerLp();
         }
     }
 
+    // Called on the DisplayManager's DisplayPowerController thread.
     @Override
     public void screenTurningOn(final ScreenOnListener screenOnListener) {
-        EventLog.writeEvent(70000, 1);
         if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
-        mHandler.obtainMessage(MSG_SCREEN_TURNING_ON, screenOnListener).sendToTarget();
-    }
 
-    // Called on the mHandler thread.
-    private void handleScreenTurningOn(ScreenOnListener screenOnListener) {
-        mScreenOnListener = screenOnListener;
+        synchronized (mLock) {
+            mScreenOnEarly = true;
+            mScreenOnFully = false;
+            mWindowManagerDrawComplete = false;
+            mScreenOnListener = screenOnListener;
+            updateOrientationListenerLp();
+        }
 
-        mWindowManagerDrawComplete = false;
         mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
                 WAITING_FOR_DRAWN_TIMEOUT);
         // ... eventually calls finishWindowsDrawn
     }
 
-    // Called on the mHandler thread.
     private void finishWindowsDrawn() {
-        if (!mWindowManagerDrawComplete) {
+        synchronized (mLock) {
+            if (!mScreenOnEarly || mWindowManagerDrawComplete) {
+                return; // spurious
+            }
+
             mWindowManagerDrawComplete = true;
-            finishScreenTurningOn();
         }
+
+        finishScreenTurningOn();
     }
 
-    // Called on the mHandler thread.
     private void finishScreenTurningOn() {
-        if (DEBUG_WAKEUP) Slog.d(TAG,
-                "finishScreenTurningOn: mAwakeEarly=" + mAwakeEarly
-                        + " mKeyguardDrawComplete=" + mKeyguardDrawComplete
-                        + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
-        boolean awake;
+        final ScreenOnListener listener;
+        final boolean enableScreen;
         synchronized (mLock) {
-            if ((mAwakeEarly && !mKeyguardDrawComplete)
-                    || !mWindowManagerDrawComplete) {
-                return;
+            if (DEBUG_WAKEUP) Slog.d(TAG,
+                    "finishScreenTurningOn: mAwake=" + mAwake
+                            + ", mScreenOnEarly=" + mScreenOnEarly
+                            + ", mScreenOnFully=" + mScreenOnFully
+                            + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
+                            + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
+
+            if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
+                    || (mAwake && !mKeyguardDrawComplete)) {
+                return; // spurious or not ready yet
             }
 
-            if (mAwakeEarly) {
-                mAwakeFully = true;
-            }
-            awake = mAwakeFully;
-        }
-
-        if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
-
-        if (mScreenOnListener != null) {
-            mScreenOnListener.onScreenOn();
+            if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
+            listener = mScreenOnListener;
             mScreenOnListener = null;
+            mScreenOnFully = true;
+
+            // Remember the first time we draw the keyguard so we know when we're done with
+            // the main part of booting and can enable the screen and hide boot messages.
+            if (!mKeyguardDrawnOnce && mAwake) {
+                mKeyguardDrawnOnce = true;
+                enableScreen = true;
+                if (mBootMessageNeedsHiding) {
+                    mBootMessageNeedsHiding = false;
+                    hideBootMessages();
+                }
+            } else {
+                enableScreen = false;
+            }
         }
 
-        if (awake) {
-            setKeyguardDrawnFirstTime();
+        if (listener != null) {
+            listener.onScreenOn();
+        }
 
-            if (mBootMessageNeedsHiding) {
-                handleHideBootMessage();
-                mBootMessageNeedsHiding = false;
+        if (enableScreen) {
+            try {
+                mWindowManager.enableScreenIfNeeded();
+            } catch (RemoteException unhandled) {
             }
         }
     }
 
     private void handleHideBootMessage() {
-        if (mBootMsgDialog == null) {
-            if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up");
-            return;
+        synchronized (mLock) {
+            if (!mKeyguardDrawnOnce) {
+                mBootMessageNeedsHiding = true;
+                return; // keyguard hasn't drawn the first time yet, not done booting
+            }
         }
-        if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) {
-            if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready");
-            mBootMessageNeedsHiding = true;
-            return;
+
+        if (mBootMsgDialog != null) {
+            if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
+            mBootMsgDialog.dismiss();
+            mBootMsgDialog = null;
         }
-        if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
-        mBootMsgDialog.dismiss();
-        mBootMsgDialog = null;
     }
 
     @Override
-    public boolean isAwake() {
-        return mAwakeFully;
+    public boolean isScreenOn() {
+        return mScreenOnFully;
     }
 
     /** {@inheritDoc} */
@@ -4936,20 +4970,10 @@
         }
     }
 
-    private void setKeyguardDrawnFirstTime() {
-        synchronized (mLock) {
-            mKeyguardDrawn = true;
-        }
-        try {
-            mWindowManager.enableScreenIfNeeded();
-        } catch (RemoteException unhandled) {
-        }
-    }
-
     @Override
     public boolean isKeyguardDrawnLw() {
         synchronized (mLock) {
-            return mKeyguardDrawn;
+            return mKeyguardDrawnOnce;
         }
     }
 
@@ -5380,7 +5404,7 @@
 
     private void updateLockScreenTimeout() {
         synchronized (mScreenLockTimeout) {
-            boolean enable = (mAllowLockscreenWhenOn && mAwakeEarly &&
+            boolean enable = (mAllowLockscreenWhenOn && mAwake &&
                     mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
             if (mLockScreenTimerActive != enable) {
                 if (enable) {
@@ -5918,9 +5942,13 @@
                 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
                 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
         pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
-        pw.print(prefix); pw.print("mAwakeEarly="); pw.print(mAwakeEarly);
-                pw.print(" mAwakeFully="); pw.print(mAwakeFully);
-                pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
+        pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
+        pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
+                pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
+        pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
+                pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
+        pw.print(prefix); pw.print("mOrientationSensorEnabled=");
+                pw.println(mOrientationSensorEnabled);
         pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
                 pw.print(","); pw.print(mOverscanScreenTop);
                 pw.print(") "); pw.print(mOverscanScreenWidth);
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 967681b..5c43f6b 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -979,12 +979,10 @@
         enforceAccessPermission();
         final int uid = Binder.getCallingUid();
         final ArrayList<NetworkInfo> result = Lists.newArrayList();
-        synchronized (mRulesLock) {
-            for (int networkType = 0; networkType <= ConnectivityManager.MAX_NETWORK_TYPE;
-                    networkType++) {
-                if (getNetworkInfoForType(networkType) != null) {
-                    result.add(getFilteredNetworkInfo(networkType, uid));
-                }
+        for (int networkType = 0; networkType <= ConnectivityManager.MAX_NETWORK_TYPE;
+                networkType++) {
+            if (getNetworkInfoForType(networkType) != null) {
+                result.add(getFilteredNetworkInfo(networkType, uid));
             }
         }
         return result.toArray(new NetworkInfo[result.size()]);
@@ -1078,15 +1076,13 @@
         enforceAccessPermission();
         final int uid = Binder.getCallingUid();
         final ArrayList<NetworkState> result = Lists.newArrayList();
-        synchronized (mRulesLock) {
-            for (int networkType = 0; networkType <= ConnectivityManager.MAX_NETWORK_TYPE;
-                    networkType++) {
-                if (getNetworkInfoForType(networkType) != null) {
-                    final NetworkInfo info = getFilteredNetworkInfo(networkType, uid);
-                    final LinkProperties lp = getLinkPropertiesForTypeInternal(networkType);
-                    final NetworkCapabilities netcap = getNetworkCapabilitiesForType(networkType);
-                    result.add(new NetworkState(info, lp, netcap));
-                }
+        for (int networkType = 0; networkType <= ConnectivityManager.MAX_NETWORK_TYPE;
+                networkType++) {
+            if (getNetworkInfoForType(networkType) != null) {
+                final NetworkInfo info = getFilteredNetworkInfo(networkType, uid);
+                final LinkProperties lp = getLinkPropertiesForTypeInternal(networkType);
+                final NetworkCapabilities netcap = getNetworkCapabilitiesForType(networkType);
+                result.add(new NetworkState(info, lp, netcap));
             }
         }
         return result.toArray(new NetworkState[result.size()]);
@@ -4132,8 +4128,9 @@
         if (networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED)
                 == false) {
             final int uidRules;
+            final int uid = Binder.getCallingUid();
             synchronized(mRulesLock) {
-                uidRules = mUidRules.get(Binder.getCallingUid(), RULE_ALLOW_ALL);
+                uidRules = mUidRules.get(uid, RULE_ALLOW_ALL);
             }
             if ((uidRules & RULE_REJECT_METERED) != 0) {
                 // we could silently fail or we can filter the available nets to only give
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 34d7cb3..1b49029 100755
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -895,6 +895,11 @@
             while (clist.size() > 0) {
                 ConnectionRecord r = clist.get(0);
                 removeConnectionLocked(r, null, null);
+                if (clist.size() > 0 && clist.get(0) == r) {
+                    // In case it didn't get removed above, do it now.
+                    Slog.wtf(TAG, "Connection " + r + " not removed for binder " + binder);
+                    clist.remove(0);
+                }
 
                 if (r.binding.service.app != null) {
                     // This could have made the service less important.
diff --git a/services/core/java/com/android/server/am/ProcessStatsService.java b/services/core/java/com/android/server/am/ProcessStatsService.java
index 7ec14c2..28e46a4 100644
--- a/services/core/java/com/android/server/am/ProcessStatsService.java
+++ b/services/core/java/com/android/server/am/ProcessStatsService.java
@@ -146,7 +146,9 @@
                         final ArrayMap<String, ProcessStats.ServiceState> services = pkg.mServices;
                         for (int isvc=services.size()-1; isvc>=0; isvc--) {
                             final ProcessStats.ServiceState service = services.valueAt(isvc);
-                            if (service.isInUse()) {
+                            if (service.isRestarting()) {
+                                service.setRestarting(true, memFactor, now);
+                            } else if (service.isInUse()) {
                                 if (service.mStartedState != ProcessStats.STATE_NOTHING) {
                                     service.setStarted(true, memFactor, now);
                                 }
@@ -157,7 +159,6 @@
                                     service.setExecuting(true, memFactor, now);
                                 }
                             }
-
                         }
                     }
                 }
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 73c9783..4dfd23b 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -783,7 +783,7 @@
     int findEffectiveRootIndex() {
         int effectiveNdx = 0;
         final int topActivityNdx = mActivities.size() - 1;
-        for (int activityNdx = 0; activityNdx < topActivityNdx; ++activityNdx) {
+        for (int activityNdx = 0; activityNdx <= topActivityNdx; ++activityNdx) {
             final ActivityRecord r = mActivities.get(activityNdx);
             if (r.finishing) {
                 continue;
diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java
index 67d9776..e2a548a 100644
--- a/services/core/java/com/android/server/display/DisplayPowerController.java
+++ b/services/core/java/com/android/server/display/DisplayPowerController.java
@@ -43,6 +43,7 @@
 import android.util.Spline;
 import android.util.TimeUtils;
 import android.view.Display;
+import android.view.WindowManagerPolicy;
 
 import java.io.PrintWriter;
 
@@ -65,7 +66,7 @@
  * 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
+ * For debugging, you can make the color fade and brightness animations run
  * slower by changing the "animator duration scale" option in Development Settings.
  */
 final class DisplayPowerController implements AutomaticBrightnessController.Callbacks {
@@ -76,13 +77,12 @@
 
     private static final String SCREEN_ON_BLOCKED_TRACE_NAME = "Screen on blocked";
 
-    // If true, uses the electron beam on animation.
+    // If true, uses the color fade 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_COLOR_FADE_ON_ANIMATION = false;
 
-
     // The minimum reduction in brightness when dimmed.
     private static final int SCREEN_DIM_MINIMUM_REDUCTION = 10;
 
@@ -91,6 +91,7 @@
 
     private static final int MSG_UPDATE_POWER_STATE = 1;
     private static final int MSG_PROXIMITY_SENSOR_DEBOUNCED = 2;
+    private static final int MSG_SCREEN_ON_UNBLOCKED = 3;
 
     private static final int PROXIMITY_UNKNOWN = -1;
     private static final int PROXIMITY_NEGATIVE = 0;
@@ -127,6 +128,9 @@
     // The sensor manager.
     private final SensorManager mSensorManager;
 
+    // The window manager policy.
+    private final WindowManagerPolicy mWindowManagerPolicy;
+
     // The display blanker.
     private final DisplayBlanker mBlanker;
 
@@ -152,7 +156,7 @@
     private boolean mUseSoftwareAutoBrightnessConfig;
 
     // True if we should fade the screen while turning it off, false if we should play
-    // a stylish electron beam animation instead.
+    // a stylish color fade animation instead.
     private boolean mColorFadeFadesConfig;
 
     // The pending power request.
@@ -214,8 +218,14 @@
     // 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 currently active screen on unblocker.  This field is non-null whenever
+    // we are waiting for a callback to release it and unblock the screen.
+    private ScreenOnUnblocker mPendingScreenOnUnblocker;
+
+    // True if we were in the process of turning off the screen.
+    // This allows us to recover more gracefully from situations where we abort
+    // turning off the screen.
+    private boolean mPendingScreenOff;
 
     // The elapsed real time when the screen on was blocked.
     private long mScreenOnBlockStartRealTime;
@@ -246,6 +256,7 @@
         mBatteryStats = BatteryStatsService.getService();
         mLights = LocalServices.getService(LightsManager.class);
         mSensorManager = sensorManager;
+        mWindowManagerPolicy = LocalServices.getService(WindowManagerPolicy.class);
         mBlanker = blanker;
         mContext = context;
 
@@ -633,7 +644,7 @@
 
         // Report whether the display is ready for use and all changes have been applied.
         if (mustNotify
-                && !mScreenOnWasBlocked
+                && mPendingScreenOnUnblocker == null
                 && !mColorFadeOnAnimator.isStarted()
                 && !mColorFadeOffAnimator.isStarted()
                 && !mScreenBrightnessRampAnimator.isAnimating()
@@ -657,32 +668,53 @@
     }
 
     private void blockScreenOn() {
-        if (!mScreenOnWasBlocked) {
+        if (mPendingScreenOnUnblocker == null) {
             Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, SCREEN_ON_BLOCKED_TRACE_NAME, 0);
-            mScreenOnWasBlocked = true;
+            mPendingScreenOnUnblocker = new ScreenOnUnblocker();
             mScreenOnBlockStartRealTime = SystemClock.elapsedRealtime();
             Slog.i(TAG, "Blocking screen on until initial contents have been drawn.");
         }
     }
 
     private void unblockScreenOn() {
-        if (mScreenOnWasBlocked) {
-            mScreenOnWasBlocked = false;
+        if (mPendingScreenOnUnblocker != null) {
+            mPendingScreenOnUnblocker = null;
             long delay = SystemClock.elapsedRealtime() - mScreenOnBlockStartRealTime;
             Slog.i(TAG, "Unblocked screen on after " + delay + " ms");
             Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, SCREEN_ON_BLOCKED_TRACE_NAME, 0);
         }
     }
 
-    private void setScreenState(int state) {
+    private boolean setScreenState(int state) {
         if (mPowerState.getScreenState() != state) {
+            final boolean wasOn = (mPowerState.getScreenState() != Display.STATE_OFF);
             mPowerState.setScreenState(state);
+
+            // Tell battery stats about the transition.
             try {
                 mBatteryStats.noteScreenState(state);
             } catch (RemoteException ex) {
                 // same process
             }
+
+            // Tell the window manager what's happening.
+            // Temporarily block turning the screen on until the window manager is ready
+            // by leaving a black surface covering the screen.  This surface is essentially
+            // the final state of the color fade animation.
+            boolean isOn = (state != Display.STATE_OFF);
+            if (wasOn && !isOn) {
+                unblockScreenOn();
+                mWindowManagerPolicy.screenTurnedOff();
+            } else if (!wasOn && isOn) {
+                if (mPowerState.getColorFadeLevel() == 0.0f) {
+                    blockScreenOn();
+                } else {
+                    unblockScreenOn();
+                }
+                mWindowManagerPolicy.screenTurningOn(mPendingScreenOnUnblocker);
+            }
         }
+        return mPendingScreenOnUnblocker == null;
     }
 
     private int clampScreenBrightness(int value) {
@@ -707,21 +739,21 @@
             return;
         }
 
-        // Temporarily block turning the screen on if requested and there is already a
-        // black surface covering the screen.
-        if (mPowerRequest.blockScreenOn
-                && mPowerState.getColorFadeLevel() == 0.0f
-                && target != Display.STATE_OFF) {
-            blockScreenOn();
-            return;
+        // If we were in the process of turning off the screen but didn't quite
+        // finish.  Then finish up now to prevent a jarring transition back
+        // to screen on if we skipped blocking screen on as usual.
+        if (mPendingScreenOff && target != Display.STATE_OFF) {
+            setScreenState(Display.STATE_OFF);
+            mPendingScreenOff = false;
         }
 
         if (target == Display.STATE_ON) {
             // Want screen on.  The contents of the screen may not yet
-            // be visible if the electron beam has not been dismissed because
+            // be visible if the color fade has not been dismissed because
             // its last frame of animation is solid black.
-            unblockScreenOn();
-            setScreenState(Display.STATE_ON);
+            if (!setScreenState(Display.STATE_ON)) {
+                return; // screen on blocked
+            }
             if (USE_COLOR_FADE_ON_ANIMATION && mPowerRequest.isBrightOrDim()) {
                 // Perform screen on animation.
                 if (mPowerState.getColorFadeLevel() == 1.0f) {
@@ -749,9 +781,12 @@
                 return;
             }
 
-            // Set screen state and dismiss the black surface without fanfare.
-            unblockScreenOn();
-            setScreenState(Display.STATE_DOZE);
+            // Set screen state.
+            if (!setScreenState(Display.STATE_DOZE)) {
+                return; // screen on blocked
+            }
+
+            // Dismiss the black surface without fanfare.
             mPowerState.setColorFadeLevel(1.0f);
             mPowerState.dismissColorFade();
         } else if (target == Display.STATE_DOZE_SUSPEND) {
@@ -763,18 +798,26 @@
                 return;
             }
 
-            // Set screen state and dismiss the black surface without fanfare.
-            unblockScreenOn();
-            setScreenState(Display.STATE_DOZE_SUSPEND);
+            // If not already suspending, temporarily set the state to doze until the
+            // screen on is unblocked, then suspend.
+            if (mPowerState.getScreenState() != Display.STATE_DOZE_SUSPEND) {
+                if (!setScreenState(Display.STATE_DOZE)) {
+                    return; // screen on blocked
+                }
+                setScreenState(Display.STATE_DOZE_SUSPEND); // already on so can't block
+            }
+
+            // Dismiss the black surface without fanfare.
             mPowerState.setColorFadeLevel(1.0f);
             mPowerState.dismissColorFade();
         } else {
             // Want screen off.
-            unblockScreenOn();
+            mPendingScreenOff = true;
             if (mPowerState.getColorFadeLevel() == 0.0f) {
                 // Turn the screen off.
                 // A black surface is already hiding the contents of the screen.
                 setScreenState(Display.STATE_OFF);
+                mPendingScreenOff = false;
             } else if (performScreenOffTransition
                     && mPowerState.prepareColorFade(mContext,
                             mColorFadeFadesConfig ?
@@ -968,6 +1011,8 @@
         pw.println("  mAppliedAutoBrightness=" + mAppliedAutoBrightness);
         pw.println("  mAppliedDimming=" + mAppliedDimming);
         pw.println("  mAppliedLowPower=" + mAppliedLowPower);
+        pw.println("  mPendingScreenOnUnblocker=" + mPendingScreenOnUnblocker);
+        pw.println("  mPendingScreenOff=" + mPendingScreenOff);
 
         pw.println("  mScreenBrightnessRampAnimator.isAnimating()=" +
                 mScreenBrightnessRampAnimator.isAnimating());
@@ -1052,6 +1097,13 @@
                 case MSG_PROXIMITY_SENSOR_DEBOUNCED:
                     debounceProximitySensor();
                     break;
+
+                case MSG_SCREEN_ON_UNBLOCKED:
+                    if (mPendingScreenOnUnblocker == msg.obj) {
+                        unblockScreenOn();
+                        updatePowerState();
+                    }
+                    break;
             }
         }
     }
@@ -1072,4 +1124,13 @@
             // Not used.
         }
     };
+
+    private final class ScreenOnUnblocker implements WindowManagerPolicy.ScreenOnListener {
+        @Override
+        public void onScreenOn() {
+            Message msg = mHandler.obtainMessage(MSG_SCREEN_ON_UNBLOCKED, this);
+            msg.setAsynchronous(true);
+            mHandler.sendMessage(msg);
+        }
+    }
 }
diff --git a/services/core/java/com/android/server/display/WifiDisplayAdapter.java b/services/core/java/com/android/server/display/WifiDisplayAdapter.java
index 9d008b9..a17d731 100644
--- a/services/core/java/com/android/server/display/WifiDisplayAdapter.java
+++ b/services/core/java/com/android/server/display/WifiDisplayAdapter.java
@@ -16,18 +16,13 @@
 
 package com.android.server.display;
 
-import com.android.internal.R;
 import com.android.internal.util.DumpUtils;
 import com.android.internal.util.IndentingPrintWriter;
 
-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.res.Resources;
 import android.hardware.display.DisplayManager;
 import android.hardware.display.WifiDisplay;
 import android.hardware.display.WifiDisplaySessionInfo;
@@ -38,7 +33,6 @@
 import android.os.Looper;
 import android.os.Message;
 import android.os.UserHandle;
-import android.provider.Settings;
 import android.util.Slog;
 import android.view.Display;
 import android.view.Surface;
@@ -71,17 +65,12 @@
     private static final boolean DEBUG = false;
 
     private static final int MSG_SEND_STATUS_CHANGE_BROADCAST = 1;
-    private static final int MSG_UPDATE_NOTIFICATION = 2;
 
     private static final String ACTION_DISCONNECT = "android.server.display.wfd.DISCONNECT";
 
     private final WifiDisplayHandler mHandler;
     private final PersistentDataStore mPersistentDataStore;
     private final boolean mSupportsProtectedBuffers;
-    private final NotificationManager mNotificationManager;
-
-    private PendingIntent mSettingsPendingIntent;
-    private PendingIntent mDisconnectPendingIntent;
 
     private WifiDisplayController mDisplayController;
     private WifiDisplayDevice mDisplayDevice;
@@ -97,7 +86,6 @@
     private WifiDisplaySessionInfo mSessionInfo;
 
     private boolean mPendingStatusChangeBroadcast;
-    private boolean mPendingNotificationUpdate;
 
     // Called with SyncRoot lock held.
     public WifiDisplayAdapter(DisplayManagerService.SyncRoot syncRoot,
@@ -108,8 +96,6 @@
         mPersistentDataStore = persistentDataStore;
         mSupportsProtectedBuffers = context.getResources().getBoolean(
                 com.android.internal.R.bool.config_wifiDisplaySupportsProtectedBuffers);
-        mNotificationManager = (NotificationManager)context.getSystemService(
-                Context.NOTIFICATION_SERVICE);
     }
 
     @Override
@@ -125,7 +111,6 @@
         pw.println("mAvailableDisplays=" + Arrays.toString(mAvailableDisplays));
         pw.println("mRememberedDisplays=" + Arrays.toString(mRememberedDisplays));
         pw.println("mPendingStatusChangeBroadcast=" + mPendingStatusChangeBroadcast);
-        pw.println("mPendingNotificationUpdate=" + mPendingNotificationUpdate);
         pw.println("mSupportsProtectedBuffers=" + mSupportsProtectedBuffers);
 
         // Try to dump the controller state.
@@ -421,13 +406,6 @@
         }
     }
 
-    private void scheduleUpdateNotificationLocked() {
-        if (!mPendingNotificationUpdate) {
-            mPendingNotificationUpdate = true;
-            mHandler.sendEmptyMessage(MSG_UPDATE_NOTIFICATION);
-        }
-    }
-
     // Runs on the handler.
     private void handleSendStatusChangeBroadcast() {
         final Intent intent;
@@ -447,87 +425,6 @@
         getContext().sendBroadcastAsUser(intent, UserHandle.ALL);
     }
 
-    // Runs on the handler.
-    private void handleUpdateNotification() {
-        final int state;
-        final WifiDisplay display;
-        synchronized (getSyncRoot()) {
-            if (!mPendingNotificationUpdate) {
-                return;
-            }
-
-            mPendingNotificationUpdate = false;
-            state = mActiveDisplayState;
-            display = mActiveDisplay;
-        }
-
-        // Cancel the old notification if there is one.
-        mNotificationManager.cancelAsUser(null,
-                R.string.wifi_display_notification_disconnect, UserHandle.ALL);
-
-        if (state == WifiDisplayStatus.DISPLAY_STATE_CONNECTING
-                || state == WifiDisplayStatus.DISPLAY_STATE_CONNECTED) {
-            Context context = getContext();
-
-            // Initialize pending intents for the notification outside of the lock because
-            // creating a pending intent requires a call into the activity manager.
-            if (mSettingsPendingIntent == null) {
-                Intent settingsIntent = new Intent(Settings.ACTION_WIFI_DISPLAY_SETTINGS);
-                settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
-                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
-                        | Intent.FLAG_ACTIVITY_CLEAR_TOP);
-                mSettingsPendingIntent = PendingIntent.getActivityAsUser(
-                        context, 0, settingsIntent, 0, null, UserHandle.CURRENT);
-            }
-
-            if (mDisconnectPendingIntent == null) {
-                Intent disconnectIntent = new Intent(ACTION_DISCONNECT);
-                mDisconnectPendingIntent = PendingIntent.getBroadcastAsUser(
-                        context, 0, disconnectIntent, 0, UserHandle.CURRENT);
-            }
-
-            // Post the notification.
-            Resources r = context.getResources();
-            Notification notification;
-            if (state == WifiDisplayStatus.DISPLAY_STATE_CONNECTING) {
-                notification = new Notification.Builder(context)
-                        .setContentTitle(r.getString(
-                                R.string.wifi_display_notification_connecting_title))
-                        .setContentText(r.getString(
-                                R.string.wifi_display_notification_connecting_message,
-                                display.getFriendlyDisplayName()))
-                        .setContentIntent(mSettingsPendingIntent)
-                        .setSmallIcon(R.drawable.ic_notification_cast_connecting)
-                        .setOngoing(true)
-                        .addAction(android.R.drawable.ic_menu_close_clear_cancel,
-                                r.getString(R.string.wifi_display_notification_disconnect),
-                                mDisconnectPendingIntent)
-                        .setColor(r.getColor(
-                                com.android.internal.R.color.system_notification_accent_color))
-                        .build();
-            } else {
-                notification = new Notification.Builder(context)
-                        .setContentTitle(r.getString(
-                                R.string.wifi_display_notification_connected_title))
-                        .setContentText(r.getString(
-                                R.string.wifi_display_notification_connected_message,
-                                display.getFriendlyDisplayName()))
-                        .setContentIntent(mSettingsPendingIntent)
-                        .setSmallIcon(R.drawable.ic_notification_cast_on)
-                        .setOngoing(true)
-                        .addAction(android.R.drawable.ic_menu_close_clear_cancel,
-                                r.getString(R.string.wifi_display_notification_disconnect),
-                                mDisconnectPendingIntent)
-                        .setColor(r.getColor(
-                                com.android.internal.R.color.system_notification_accent_color))
-                        .build();
-            }
-            mNotificationManager.notifyAsUser(null,
-                    R.string.wifi_display_notification_disconnect,
-                    notification, UserHandle.ALL);
-        }
-    }
-
     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -605,7 +502,6 @@
                     mActiveDisplayState = WifiDisplayStatus.DISPLAY_STATE_CONNECTING;
                     mActiveDisplay = display;
                     scheduleStatusChangedBroadcastLocked();
-                    scheduleUpdateNotificationLocked();
                 }
             }
         }
@@ -618,7 +514,6 @@
                     mActiveDisplayState = WifiDisplayStatus.DISPLAY_STATE_NOT_CONNECTED;
                     mActiveDisplay = null;
                     scheduleStatusChangedBroadcastLocked();
-                    scheduleUpdateNotificationLocked();
                 }
             }
         }
@@ -636,7 +531,6 @@
                     mActiveDisplayState = WifiDisplayStatus.DISPLAY_STATE_CONNECTED;
                     mActiveDisplay = display;
                     scheduleStatusChangedBroadcastLocked();
-                    scheduleUpdateNotificationLocked();
                 }
             }
         }
@@ -659,7 +553,6 @@
                     mActiveDisplay = display;
                     renameDisplayDeviceLocked(display.getFriendlyDisplayName());
                     scheduleStatusChangedBroadcastLocked();
-                    scheduleUpdateNotificationLocked();
                 }
             }
         }
@@ -675,7 +568,6 @@
                     mActiveDisplayState = WifiDisplayStatus.DISPLAY_STATE_NOT_CONNECTED;
                     mActiveDisplay = null;
                     scheduleStatusChangedBroadcastLocked();
-                    scheduleUpdateNotificationLocked();
                 }
             }
         }
@@ -755,10 +647,6 @@
                 case MSG_SEND_STATUS_CHANGE_BROADCAST:
                     handleSendStatusChangeBroadcast();
                     break;
-
-                case MSG_UPDATE_NOTIFICATION:
-                    handleUpdateNotification();
-                    break;
             }
         }
     }
diff --git a/services/core/java/com/android/server/location/GpsLocationProvider.java b/services/core/java/com/android/server/location/GpsLocationProvider.java
index f1c5a6c..0198e46 100644
--- a/services/core/java/com/android/server/location/GpsLocationProvider.java
+++ b/services/core/java/com/android/server/location/GpsLocationProvider.java
@@ -25,6 +25,7 @@
 import com.android.internal.R;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
+import com.android.internal.telephony.TelephonyIntents;
 
 import android.app.AlarmManager;
 import android.app.AppOpsManager;
@@ -227,6 +228,11 @@
     private static final int GPS_GEOFENCE_ERROR_INVALID_TRANSITION = -103;
     private static final int GPS_GEOFENCE_ERROR_GENERIC = -149;
 
+    // TCP/IP constants.
+    // Valid TCP/UDP port range is (0, 65535].
+    private static final int TCP_MIN_PORT = 0;
+    private static final int TCP_MAX_PORT = 0xffff;
+
     // Value of batterySaverGpsMode such that GPS isn't affected by battery saver mode.
     private static final int BATTERY_SAVER_MODE_NO_CHANGE = 0;
     // Value of batterySaverGpsMode such that GPS is disabled when battery saver mode
@@ -332,7 +338,7 @@
     // properties loaded from PROPERTIES_FILE
     private Properties mProperties;
     private String mSuplServerHost;
-    private int mSuplServerPort;
+    private int mSuplServerPort = TCP_MIN_PORT;
     private String mC2KServerHost;
     private int mC2KServerPort;
     private boolean mSuplEsEnabled = false;
@@ -487,7 +493,10 @@
                     || Intent.ACTION_SCREEN_OFF.equals(action)
                     || Intent.ACTION_SCREEN_ON.equals(action)) {
                 updateLowPowerMode();
-            } else if (action.equals(SIM_STATE_CHANGED)) {
+            } else if (action.equals(SIM_STATE_CHANGED)
+                    || action.equals(TelephonyIntents.ACTION_SUBINFO_CONTENT_CHANGE)
+                    || action.equals(TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED)) {
+                Log.d(TAG, "received SIM realted action: " + action);
                 TelephonyManager phone = (TelephonyManager)
                         mContext.getSystemService(Context.TELEPHONY_SERVICE);
                 String mccMnc = phone.getSimOperator();
@@ -497,6 +506,8 @@
                         reloadGpsProperties(context, mProperties);
                         mNIHandler.setSuplEsEnabled(mSuplEsEnabled);
                     }
+                } else {
+                    Log.d(TAG, "SIM MCC/MNC is still not available");
                 }
             }
         }
@@ -709,6 +720,10 @@
         intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
         intentFilter.addAction(Intent.ACTION_SCREEN_ON);
         intentFilter.addAction(SIM_STATE_CHANGED);
+        // TODO: remove the use TelephonyIntents. We are using it because SIM_STATE_CHANGED
+        // is not reliable at the moment.
+        intentFilter.addAction(TelephonyIntents.ACTION_SUBINFO_CONTENT_CHANGE);
+        intentFilter.addAction(TelephonyIntents.ACTION_SUBINFO_RECORD_UPDATED);
         mContext.registerReceiver(mBroadcastReceiver, intentFilter, null, mHandler);
     }
 
@@ -921,6 +936,11 @@
                 Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
             }
         }
+        if (mSuplServerHost != null
+                && mSuplServerPort > TCP_MIN_PORT
+                && mSuplServerPort <= TCP_MAX_PORT) {
+            native_set_agps_server(AGPS_TYPE_SUPL, mSuplServerHost, mSuplServerPort);
+        }
     }
 
     /**
@@ -963,6 +983,8 @@
 
         if (enabled) {
             mSupportsXtra = native_supports_xtra();
+
+            // TODO: remove the following native calls if we can make sure they are redundant.
             if (mSuplServerHost != null) {
                 native_set_agps_server(AGPS_TYPE_SUPL, mSuplServerHost, mSuplServerPort);
             }
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 5a94f23..a61d621 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -5589,9 +5589,11 @@
         // update the package settings accordingly.
         pkg.cpuAbiOverride = cpuAbiOverride;
 
-        Slog.d(TAG, "Resolved nativeLibraryRoot for " + pkg.applicationInfo.packageName
-                + " to root=" + pkg.applicationInfo.nativeLibraryRootDir + ", isa="
-                + pkg.applicationInfo.nativeLibraryRootRequiresIsa);
+        if (DEBUG_ABI_SELECTION) {
+            Slog.d(TAG, "Resolved nativeLibraryRoot for " + pkg.applicationInfo.packageName
+                    + " to root=" + pkg.applicationInfo.nativeLibraryRootDir + ", isa="
+                    + pkg.applicationInfo.nativeLibraryRootRequiresIsa);
+        }
 
         // Push the derived path down into PackageSettings so we know what to
         // clean up at uninstall time.
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java
index c720668..94a628d 100644
--- a/services/core/java/com/android/server/power/Notifier.java
+++ b/services/core/java/com/android/server/power/Notifier.java
@@ -84,7 +84,6 @@
     private final IBatteryStats mBatteryStats;
     private final IAppOpsService mAppOps;
     private final SuspendBlocker mSuspendBlocker;
-    private final ScreenOnBlocker mScreenOnBlocker;
     private final WindowManagerPolicy mPolicy;
     private final ActivityManagerInternal mActivityManagerInternal;
     private final InputManagerInternal mInputManagerInternal;
@@ -110,18 +109,13 @@
     // True if a user activity message should be sent.
     private boolean mUserActivityPending;
 
-    // The currently active screen on listener. This field is non-null whenever the
-    // ScreenOnBlocker has been acquired and we are awaiting a callback to release it.
-    private ScreenOnUnblocker mPendingScreenOnUnblocker;
-
     public Notifier(Looper looper, Context context, IBatteryStats batteryStats,
-            IAppOpsService appOps, SuspendBlocker suspendBlocker, ScreenOnBlocker screenOnBlocker,
+            IAppOpsService appOps, SuspendBlocker suspendBlocker,
             WindowManagerPolicy policy) {
         mContext = context;
         mBatteryStats = batteryStats;
         mAppOps = appOps;
         mSuspendBlocker = suspendBlocker;
-        mScreenOnBlocker = screenOnBlocker;
         mPolicy = policy;
         mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
         mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
@@ -333,21 +327,6 @@
     }
 
     /**
-     * Notifies that screen is about to be turned on (any state other than off).
-     */
-    public void onScreenTurningOn() {
-        synchronized (mLock) {
-            final ScreenOnUnblocker unblocker = blockScreenOnLocked();
-            mHandler.post(new Runnable() {
-                @Override
-                public void run() {
-                    mPolicy.screenTurningOn(unblocker);
-                }
-            });
-        }
-    }
-
-    /**
      * Called when there has been user activity.
      */
     public void onUserActivity(int event, int uid) {
@@ -470,26 +449,6 @@
         }
     }
 
-    private ScreenOnUnblocker blockScreenOnLocked() {
-        if (mPendingScreenOnUnblocker == null) {
-            mScreenOnBlocker.acquire();
-        }
-        mPendingScreenOnUnblocker = new ScreenOnUnblocker();
-        return mPendingScreenOnUnblocker;
-    }
-
-    private final class ScreenOnUnblocker implements WindowManagerPolicy.ScreenOnListener {
-        @Override
-        public void onScreenOn() {
-            synchronized (mLock) {
-                if (mPendingScreenOnUnblocker == this) {
-                    mPendingScreenOnUnblocker = null;
-                    mScreenOnBlocker.release();
-                }
-            }
-        }
-    }
-
     private final BroadcastReceiver mWakeUpBroadcastDone = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 71e059a..4f41bee 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -88,8 +88,6 @@
     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;
 
     // Dirty bit: mWakeLocks changed
     private static final int DIRTY_WAKE_LOCKS = 1 << 0;
@@ -111,10 +109,8 @@
     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;
+    private static final int DIRTY_DOCK_STATE = 1 << 10;
 
     // 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.
@@ -244,10 +240,6 @@
     // 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;
-
     // True if systemReady() has been called.
     private boolean mSystemReady;
 
@@ -451,7 +443,6 @@
             mHalAutoSuspendModeEnabled = false;
             mHalInteractiveModeEnabled = true;
 
-            mScreenOnBlocker = new ScreenOnBlockerImpl();
             mWakefulness = WAKEFULNESS_AWAKE;
             mInteractive = true;
 
@@ -505,7 +496,7 @@
             mBatteryStats = BatteryStatsService.getService();
             mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats,
                     mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"),
-                    mScreenOnBlocker, mPolicy);
+                    mPolicy);
 
             mWirelessChargerDetector = new WirelessChargerDetector(sensorManager,
                     createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"),
@@ -1745,13 +1736,6 @@
         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
@@ -1766,8 +1750,7 @@
         final boolean oldDisplayReady = mDisplayReady;
         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) {
-            boolean wasBlockerNeeded = isScreenOnBlockerNeededLocked(mDisplayPowerRequest);
+                | DIRTY_SETTINGS)) != 0) {
             mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked();
 
             int screenBrightness = mScreenBrightnessSettingDefault;
@@ -1815,12 +1798,6 @@
                 mDisplayPowerRequest.dozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;
             }
 
-            if (!wasBlockerNeeded && isScreenOnBlockerNeededLocked(mDisplayPowerRequest)
-                    && !mScreenOnBlocker.isHeld()) {
-                mNotifier.onScreenTurningOn();
-            }
-            mDisplayPowerRequest.blockScreenOn = mScreenOnBlocker.isHeld();
-
             mDisplayReady = mDisplayManagerInternal.requestPowerState(mDisplayPowerRequest,
                     mRequestWaitForNegativeProximity);
             mRequestWaitForNegativeProximity = false;
@@ -1837,17 +1814,6 @@
         return mDisplayReady && !oldDisplayReady;
     }
 
-    private static boolean isScreenOnBlockerNeededLocked(DisplayPowerRequest req) {
-        switch (req.policy) {
-            case DisplayPowerRequest.POLICY_OFF:
-                return false;
-            case DisplayPowerRequest.POLICY_DOZE:
-                return req.dozeScreenState != Display.STATE_OFF;
-            default:
-                return true;
-        }
-    }
-
     private static boolean isValidBrightness(int value) {
         return value >= 0 && value <= 255;
     }
@@ -2420,9 +2386,6 @@
             }
 
             pw.println();
-            pw.println("Screen On Blocker: " + mScreenOnBlocker);
-
-            pw.println();
             pw.println("Display Power: " + mDisplayPowerCallbacks);
 
             wcd = mWirelessChargerDetector;
@@ -2530,9 +2493,6 @@
                 case MSG_SANDMAN:
                     handleSandman();
                     break;
-                case MSG_SCREEN_ON_BLOCKER_RELEASED:
-                    handleScreenOnBlockerReleased();
-                    break;
             }
         }
     }
@@ -2709,56 +2669,6 @@
         }
     }
 
-    private final class ScreenOnBlockerImpl implements ScreenOnBlocker {
-        private static final String TRACE_NAME = "ScreenOnBlocker";
-
-        private int mNestCount;
-
-        public boolean isHeld() {
-            synchronized (this) {
-                return mNestCount != 0;
-            }
-        }
-
-        @Override
-        public void acquire() {
-            synchronized (this) {
-                mNestCount += 1;
-                if (DEBUG || true) {
-                    Slog.d(TAG, "Screen on blocked: mNestCount=" + mNestCount);
-                }
-                if (mNestCount == 1) {
-                    Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, TRACE_NAME, 0);
-                }
-            }
-        }
-
-        @Override
-        public void release() {
-            synchronized (this) {
-                mNestCount -= 1;
-                if (mNestCount == 0) {
-                    if (DEBUG || true) {
-                        Slog.d(TAG, "Screen on unblocked: mNestCount=" + mNestCount);
-                    }
-                    mHandler.sendEmptyMessage(MSG_SCREEN_ON_BLOCKER_RELEASED);
-                    Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, TRACE_NAME, 0);
-                } else if (mNestCount < 0) {
-                    Slog.wtf(TAG, "Screen on blocker was released without being acquired!",
-                            new Throwable());
-                    mNestCount = 0;
-                }
-            }
-        }
-
-        @Override
-        public String toString() {
-            synchronized (this) {
-                return "held=" + (mNestCount != 0) + ", mNestCount=" + mNestCount;
-            }
-        }
-    }
-
     private final class BinderService extends IPowerManager.Stub {
         @Override // Binder call
         public void acquireWakeLockWithUid(IBinder lock, int flags, String tag,
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index a4edc86..bc35330 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -3474,7 +3474,7 @@
     }
 
     boolean okToDisplay() {
-        return !mDisplayFrozen && mDisplayEnabled && mPolicy.isAwake();
+        return !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOn();
     }
 
     AppWindowToken findAppWindowToken(IBinder token) {
@@ -10397,7 +10397,7 @@
             return;
         }
 
-        if (!mDisplayReady || !mPolicy.isAwake()) {
+        if (!mDisplayReady || !mPolicy.isScreenOn()) {
             // No need to freeze the screen before the system is ready or if
             // the screen is off.
             return;
@@ -11576,7 +11576,7 @@
                 final WindowList windows = getDefaultWindowListLocked();
                 for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
                     final WindowState win = windows.get(winNdx);
-                    if (win.mHasSurface
+                    if (win.isVisibleLw()
                             && (win.mAppToken != null || mPolicy.isForceHiding(win.mAttrs))) {
                         win.mWinAnimator.mDrawState = WindowStateAnimator.DRAW_PENDING;
                         // Force add to mResizingWindows.
diff --git a/telecomm/java/android/telecom/AudioState.java b/telecomm/java/android/telecom/AudioState.java
index d0e2860..fc2fff4 100644
--- a/telecomm/java/android/telecom/AudioState.java
+++ b/telecomm/java/android/telecom/AudioState.java
@@ -16,6 +16,7 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
 import android.os.Parcel;
 import android.os.Parcelable;
 
@@ -23,7 +24,9 @@
 
 /**
  *  Encapsulates all audio states during a call.
+ *  @hide
  */
+@SystemApi
 public final class AudioState implements Parcelable {
     /** Direct the audio stream through the device's earpiece. */
     public static final int ROUTE_EARPIECE      = 0x00000001;
diff --git a/telecomm/java/android/telecom/Conference.java b/telecomm/java/android/telecom/Conference.java
index 9b350c1..e47d9d1 100644
--- a/telecomm/java/android/telecom/Conference.java
+++ b/telecomm/java/android/telecom/Conference.java
@@ -16,6 +16,8 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
+
 import java.util.Collections;
 import java.util.List;
 import java.util.Set;
@@ -24,7 +26,9 @@
 
 /**
  * Represents a conference call which can contain any number of {@link Connection} objects.
+ * @hide
  */
+@SystemApi
 public abstract class Conference {
 
     /** @hide */
diff --git a/telecomm/java/android/telecom/Connection.java b/telecomm/java/android/telecom/Connection.java
index 7979e44..13acc59 100644
--- a/telecomm/java/android/telecom/Connection.java
+++ b/telecomm/java/android/telecom/Connection.java
@@ -19,6 +19,7 @@
 import com.android.internal.telecom.IVideoCallback;
 import com.android.internal.telecom.IVideoProvider;
 
+import android.annotation.SystemApi;
 import android.net.Uri;
 import android.os.Handler;
 import android.os.IBinder;
@@ -43,7 +44,9 @@
  * Implementations are then responsible for updating the state of the {@code Connection}, and
  * must call {@link #destroy()} to signal to the framework that the {@code Connection} is no
  * longer used and associated resources may be recovered.
+ * @hide
  */
+@SystemApi
 public abstract class Connection {
 
     public static final int STATE_INITIALIZING = 0;
@@ -873,7 +876,7 @@
         return mUnmodifiableConferenceableConnections;
     }
 
-    /*
+    /**
      * @hide
      */
     public final void setConnectionService(ConnectionService connectionService) {
diff --git a/telecomm/java/android/telecom/ConnectionRequest.java b/telecomm/java/android/telecom/ConnectionRequest.java
index 71b481b..f691c17 100644
--- a/telecomm/java/android/telecom/ConnectionRequest.java
+++ b/telecomm/java/android/telecom/ConnectionRequest.java
@@ -16,6 +16,7 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Parcel;
@@ -24,7 +25,9 @@
 /**
  * Simple data container encapsulating a request to some entity to
  * create a new {@link Connection}.
+ * @hide
  */
+@SystemApi
 public final class ConnectionRequest implements Parcelable {
 
     // TODO: Token to limit recursive invocations
diff --git a/telecomm/java/android/telecom/ConnectionService.java b/telecomm/java/android/telecom/ConnectionService.java
index 3e18bac..ed9251b7 100644
--- a/telecomm/java/android/telecom/ConnectionService.java
+++ b/telecomm/java/android/telecom/ConnectionService.java
@@ -16,6 +16,7 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
 import android.annotation.SdkConstant;
 import android.app.Service;
 import android.content.ComponentName;
@@ -34,15 +35,17 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * A {@link android.app.Service} that provides telephone connections to processes running on an
  * Android device.
+ * @hide
  */
+@SystemApi
 public abstract class ConnectionService extends Service {
     /**
      * The {@link Intent} that must be declared as handled by the service.
@@ -74,10 +77,10 @@
 
     private static Connection sNullConnection;
 
-    private final Map<String, Connection> mConnectionById = new HashMap<>();
-    private final Map<Connection, String> mIdByConnection = new HashMap<>();
-    private final Map<String, Conference> mConferenceById = new HashMap<>();
-    private final Map<Conference, String> mIdByConference = new HashMap<>();
+    private final Map<String, Connection> mConnectionById = new ConcurrentHashMap<>();
+    private final Map<Connection, String> mIdByConnection = new ConcurrentHashMap<>();
+    private final Map<String, Conference> mConferenceById = new ConcurrentHashMap<>();
+    private final Map<Conference, String> mIdByConference = new ConcurrentHashMap<>();
     private final RemoteConnectionManager mRemoteConnectionManager =
             new RemoteConnectionManager(this);
     private final List<Runnable> mPreInitializationConnectionRequests = new ArrayList<>();
diff --git a/telecomm/java/android/telecom/DisconnectCause.java b/telecomm/java/android/telecom/DisconnectCause.java
index 9be0138..52c1284 100644
--- a/telecomm/java/android/telecom/DisconnectCause.java
+++ b/telecomm/java/android/telecom/DisconnectCause.java
@@ -16,6 +16,7 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.media.ToneGenerator;
@@ -28,7 +29,9 @@
  * cause of the disconnect. Optionally, it may include a localized label and/or localized description
  * to display to the user which is provided by the {@link ConnectionService}. It also may contain a
  * reason for the the disconnect, which is intended for logging and not for display to the user.
+ * @hide
  */
+@SystemApi
 public final class DisconnectCause implements Parcelable {
 
     /** Disconnected because of an unknown or unspecified reason. */
diff --git a/telecomm/java/android/telecom/GatewayInfo.java b/telecomm/java/android/telecom/GatewayInfo.java
index 583c3e2..3efab0f 100644
--- a/telecomm/java/android/telecom/GatewayInfo.java
+++ b/telecomm/java/android/telecom/GatewayInfo.java
@@ -30,7 +30,9 @@
  * <li> Call the appropriate routing number
  * <li> Display information about how the call is being routed to the user
  * </ol>
+ * @hide
  */
+@SystemApi
 public class GatewayInfo implements Parcelable {
 
     private final String mGatewayProviderPackageName;
diff --git a/telecomm/java/android/telecom/PhoneAccount.java b/telecomm/java/android/telecom/PhoneAccount.java
index 4b059b2..ffe787a 100644
--- a/telecomm/java/android/telecom/PhoneAccount.java
+++ b/telecomm/java/android/telecom/PhoneAccount.java
@@ -16,6 +16,7 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.res.Resources.NotFoundException;
@@ -34,7 +35,9 @@
 /**
  * Describes a distinct account, line of service or call placement method that the system
  * can use to place phone calls.
+ * @hide
  */
+@SystemApi
 public class PhoneAccount implements Parcelable {
 
     /**
diff --git a/telecomm/java/android/telecom/PhoneAccountHandle.java b/telecomm/java/android/telecom/PhoneAccountHandle.java
index e13df76..652befe5 100644
--- a/telecomm/java/android/telecom/PhoneAccountHandle.java
+++ b/telecomm/java/android/telecom/PhoneAccountHandle.java
@@ -16,6 +16,7 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
 import android.content.ComponentName;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -24,7 +25,9 @@
 
 /**
  * The unique identifier for a {@link PhoneAccount}.
+ * @hide
  */
+@SystemApi
 public class PhoneAccountHandle implements Parcelable {
     private ComponentName mComponentName;
     private String mId;
diff --git a/telecomm/java/android/telecom/PhoneCapabilities.java b/telecomm/java/android/telecom/PhoneCapabilities.java
index e73dfe2..de2abcb 100644
--- a/telecomm/java/android/telecom/PhoneCapabilities.java
+++ b/telecomm/java/android/telecom/PhoneCapabilities.java
@@ -16,10 +16,14 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
+
 /**
  * Defines capabilities a phone call can support, such as conference calling and video telephony.
  * Also defines properties of a phone call, such as whether it is using VoLTE technology.
+ * @hide
  */
+@SystemApi
 public final class PhoneCapabilities {
     /** Call can currently be put on hold or unheld. */
     public static final int HOLD               = 0x00000001;
diff --git a/telecomm/java/android/telecom/RemoteConference.java b/telecomm/java/android/telecom/RemoteConference.java
index f931bc5..796725b 100644
--- a/telecomm/java/android/telecom/RemoteConference.java
+++ b/telecomm/java/android/telecom/RemoteConference.java
@@ -18,6 +18,7 @@
 
 import com.android.internal.telecom.IConnectionService;
 
+import android.annotation.SystemApi;
 import android.os.RemoteException;
 
 import java.util.Collections;
@@ -28,7 +29,9 @@
 
 /**
  * Represents a conference call which can contain any number of {@link Connection} objects.
+ * @hide
  */
+@SystemApi
 public final class RemoteConference {
 
     public abstract static class Callback {
diff --git a/telecomm/java/android/telecom/RemoteConnection.java b/telecomm/java/android/telecom/RemoteConnection.java
index 9a094df..4a89692 100644
--- a/telecomm/java/android/telecom/RemoteConnection.java
+++ b/telecomm/java/android/telecom/RemoteConnection.java
@@ -20,6 +20,7 @@
 import com.android.internal.telecom.IVideoCallback;
 import com.android.internal.telecom.IVideoProvider;
 
+import android.annotation.SystemApi;
 import android.net.Uri;
 import android.os.IBinder;
 import android.os.RemoteException;
@@ -37,7 +38,9 @@
  *
  * @see ConnectionService#createRemoteOutgoingConnection(PhoneAccountHandle, ConnectionRequest)
  * @see ConnectionService#createRemoteIncomingConnection(PhoneAccountHandle, ConnectionRequest)
+ * @hide
  */
+@SystemApi
 public final class RemoteConnection {
 
     public static abstract class Callback {
diff --git a/telecomm/java/android/telecom/StatusHints.java b/telecomm/java/android/telecom/StatusHints.java
index a32eae7..dd3a639 100644
--- a/telecomm/java/android/telecom/StatusHints.java
+++ b/telecomm/java/android/telecom/StatusHints.java
@@ -16,6 +16,7 @@
 
 package android.telecom;
 
+import android.annotation.SystemApi;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.PackageManager;
@@ -29,7 +30,9 @@
 
 /**
  * Contains status label and icon displayed in the in-call UI.
+ * @hide
  */
+@SystemApi
 public final class StatusHints implements Parcelable {
 
     private final ComponentName mPackageName;
diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java
index 481e483..89d2dc0 100644
--- a/telecomm/java/android/telecom/TelecomManager.java
+++ b/telecomm/java/android/telecom/TelecomManager.java
@@ -53,6 +53,7 @@
     /**
      * The {@link android.content.Intent} action used to configure a
      * {@link android.telecom.ConnectionService}.
+     * @hide
      */
     public static final String ACTION_CONNECTION_SERVICE_CONFIGURE =
             "android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
@@ -66,6 +67,7 @@
     /**
      * The {@link android.content.Intent} action used to show the settings page used to configure
      * {@link PhoneAccount} preferences.
+     * @hide
      */
     public static final String ACTION_CHANGE_PHONE_ACCOUNTS =
             "android.telecom.action.CHANGE_PHONE_ACCOUNTS";
@@ -96,6 +98,7 @@
      * {@link PhoneAccountHandle} to use when making the call.
      * <p class="note">
      * Retrieve with {@link android.content.Intent#getParcelableExtra(String)}.
+     * @hide
      */
     public static final String EXTRA_PHONE_ACCOUNT_HANDLE =
             "android.telecom.extra.PHONE_ACCOUNT_HANDLE";
@@ -138,6 +141,7 @@
     /**
      * Optional extra for {@link android.telephony.TelephonyManager#ACTION_PHONE_STATE_CHANGED}
      * containing the component name of the associated connection service.
+     * @hide
      */
     public static final String EXTRA_CONNECTION_SERVICE =
             "android.telecom.extra.CONNECTION_SERVICE";
@@ -173,6 +177,7 @@
      * {@link ConnectionService}s which interact with {@link RemoteConnection}s should only populate
      * this if the {@link android.telephony.TelephonyManager#getLine1Number()} value, as that is the
      * user's expected caller ID.
+     * @hide
      */
     public static final String EXTRA_CALL_BACK_NUMBER = "android.telecom.extra.CALL_BACK_NUMBER";
 
@@ -419,6 +424,7 @@
      * {@code PhoneAccount}.
      *
      * @return The phone account handle of the current connection manager.
+     * @hide
      */
     public PhoneAccountHandle getConnectionManager() {
         return getSimCallManager();
@@ -476,6 +482,7 @@
      *
      * @return {@code true} if the device has more than one account registered and {@code false}
      * otherwise.
+     * @hide
      */
     public boolean hasMultipleCallCapableAccounts() {
         return getCallCapablePhoneAccounts().size() > 1;
@@ -485,6 +492,7 @@
      *  Returns a list of all {@link PhoneAccount}s registered for the calling package.
      *
      * @return A list of {@code PhoneAccountHandle} objects.
+     * @hide
      */
     public List<PhoneAccountHandle> getPhoneAccountsForPackage() {
         try {
@@ -503,6 +511,7 @@
      *
      * @param account The {@link PhoneAccountHandle}.
      * @return The {@link PhoneAccount} object.
+     * @hide
      */
     public PhoneAccount getPhoneAccount(PhoneAccountHandle account) {
         try {
@@ -573,6 +582,7 @@
      * Register a {@link PhoneAccount} for use by the system.
      *
      * @param account The complete {@link PhoneAccount}.
+     * @hide
      */
     public void registerPhoneAccount(PhoneAccount account) {
         try {
@@ -588,6 +598,7 @@
      * Remove a {@link PhoneAccount} registration from the system.
      *
      * @param accountHandle A {@link PhoneAccountHandle} for the {@link PhoneAccount} to unregister.
+     * @hide
      */
     public void unregisterPhoneAccount(PhoneAccountHandle accountHandle) {
         try {
@@ -601,6 +612,7 @@
 
     /**
      * Remove all Accounts that belong to the calling package from the system.
+     * @hide
      */
     @SystemApi
     public void clearAccounts() {
@@ -786,6 +798,7 @@
      *            {@link #registerPhoneAccount}.
      * @param extras A bundle that will be passed through to
      *            {@link ConnectionService#onCreateIncomingConnection}.
+     * @hide
      */
     public void addNewIncomingCall(PhoneAccountHandle phoneAccount, Bundle extras) {
         try {
diff --git a/tests/VectorDrawableTest/res/anim/animation_favorite.xml b/tests/VectorDrawableTest/res/anim/animation_favorite.xml
index c81ba40..2e2d9bb 100644
--- a/tests/VectorDrawableTest/res/anim/animation_favorite.xml
+++ b/tests/VectorDrawableTest/res/anim/animation_favorite.xml
@@ -25,5 +25,35 @@
         android:valueFrom="@string/round_box"
         android:valueTo="@string/heart"
         android:valueType="pathType" />
+    <objectAnimator
+        android:duration="8000"
+        android:propertyName="fillAlpha"
+        android:repeatCount="-1"
+        android:valueFrom="1.0"
+        android:valueTo="0.0" />
+    <objectAnimator
+        android:duration="8000"
+        android:propertyName="strokeAlpha"
+        android:repeatCount="-1"
+        android:valueFrom="1.0"
+        android:valueTo="0.0" />
+    <objectAnimator
+        android:duration="8000"
+        android:propertyName="strokeColor"
+        android:repeatCount="-1"
+        android:valueFrom="#FF0000FF"
+        android:valueTo="#FF00FF00" />
+    <objectAnimator
+        android:duration="8000"
+        android:propertyName="strokeWidth"
+        android:repeatCount="-1"
+        android:valueFrom="5"
+        android:valueTo="20" />
+    <objectAnimator
+        android:duration="8000"
+        android:propertyName="fillColor"
+        android:repeatCount="-1"
+        android:valueFrom="#FFFF0000"
+        android:valueTo="#FF00FF00" />
 
 </set>
\ No newline at end of file
diff --git a/tests/VectorDrawableTest/res/anim/trim_path_animation02.xml b/tests/VectorDrawableTest/res/anim/trim_path_animation02.xml
index 3bf2865..5d688cf 100644
--- a/tests/VectorDrawableTest/res/anim/trim_path_animation02.xml
+++ b/tests/VectorDrawableTest/res/anim/trim_path_animation02.xml
@@ -19,7 +19,7 @@
 
     <objectAnimator
         android:duration="5000"
-        android:propertyName="fill"
+        android:propertyName="fillColor"
         android:valueFrom="#FF000000"
         android:valueTo="#FFFF0000"/>