Merge "Per requested by API council, rename MediaScannerConneciton.ScanResultListener to .OnScanCompletedListener http://2553871" into froyo
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java
index 984c070..98a4993 100644
--- a/core/java/android/content/SyncStorageEngine.java
+++ b/core/java/android/content/SyncStorageEngine.java
@@ -330,11 +330,11 @@
 
     @Override public void handleMessage(Message msg) {
         if (msg.what == MSG_WRITE_STATUS) {
-            synchronized (mAccounts) {
+            synchronized (mAuthorities) {
                 writeStatusLocked();
             }
         } else if (msg.what == MSG_WRITE_STATISTICS) {
-            synchronized (mAccounts) {
+            synchronized (mAuthorities) {
                 writeStatisticsLocked();
             }
         }
diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java
index bf94707..e56a6fe 100644
--- a/core/java/android/view/ViewRoot.java
+++ b/core/java/android/view/ViewRoot.java
@@ -766,7 +766,7 @@
                 // make sure touch mode code executes by setting cached value
                 // to opposite of the added touch mode.
                 mAttachInfo.mInTouchMode = !mAddedTouchMode;
-                ensureTouchModeLocally(mAddedTouchMode);
+                ensureTouchModeLocally(mAddedTouchMode, false);
             } else {
                 if (!mAttachInfo.mContentInsets.equals(mPendingContentInsets)) {
                     mAttachInfo.mContentInsets.set(mPendingContentInsets);
@@ -983,7 +983,7 @@
             }
 
             boolean focusChangedDueToTouchMode = ensureTouchModeLocally(
-                    (relayoutResult&WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE) != 0);
+                    (relayoutResult&WindowManagerImpl.RELAYOUT_IN_TOUCH_MODE) != 0, true);
             if (focusChangedDueToTouchMode || mWidth != host.mMeasuredWidth
                     || mHeight != host.mMeasuredHeight || contentInsetsChanged) {
                 childWidthMeasureSpec = getRootMeasureSpec(mWidth, lp.width);
@@ -1043,6 +1043,13 @@
                 startTime = SystemClock.elapsedRealtime();
             }
             host.layout(0, 0, host.mMeasuredWidth, host.mMeasuredHeight);
+            if (mFirst) {
+                if (mAddedTouchMode) {
+                    enterTouchMode();
+                } else {
+                    leaveTouchMode();
+                }
+            }
 
             if (Config.DEBUG && ViewDebug.consistencyCheckEnabled) {
                 if (!host.dispatchConsistencyCheck(ViewDebug.CONSISTENCY_LAYOUT)) {
@@ -1892,7 +1899,7 @@
                 mAttachInfo.mHasWindowFocus = hasWindowFocus;
                 if (hasWindowFocus) {
                     boolean inTouchMode = msg.arg2 != 0;
-                    ensureTouchModeLocally(inTouchMode);
+                    ensureTouchModeLocally(inTouchMode, true);
 
                     if (mGlWanted) {
                         checkEglErrors();
@@ -2002,16 +2009,17 @@
         }
 
         // handle the change
-        return ensureTouchModeLocally(inTouchMode);
+        return ensureTouchModeLocally(inTouchMode, true);
     }
 
     /**
      * Ensure that the touch mode for this window is set, and if it is changing,
      * take the appropriate action.
      * @param inTouchMode Whether we want to be in touch mode.
+     * @param dispatchFocus
      * @return True if the touch mode changed and focus changed was changed as a result
      */
-    private boolean ensureTouchModeLocally(boolean inTouchMode) {
+    private boolean ensureTouchModeLocally(boolean inTouchMode, boolean dispatchFocus) {
         if (DBG) Log.d("touchmode", "ensureTouchModeLocally(" + inTouchMode + "), current "
                 + "touch mode is " + mAttachInfo.mInTouchMode);
 
@@ -2020,7 +2028,7 @@
         mAttachInfo.mInTouchMode = inTouchMode;
         mAttachInfo.mTreeObserver.dispatchOnTouchModeChanged(inTouchMode);
 
-        return (inTouchMode) ? enterTouchMode() : leaveTouchMode();
+        return dispatchFocus && (inTouchMode) ? enterTouchMode() : leaveTouchMode();
     }
 
     private boolean enterTouchMode() {
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index 959a9db..3585bf1 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -527,6 +527,9 @@
         <!-- The screen layout has changed.  This might be caused by a
              different display being activated. -->
         <flag name="screenLayout" value="0x0100" />
+        <!-- The global user interface mode has changed.  For example,
+             going in or out of car mode, night mode changing, etc. -->
+        <flag name="uiMode" value="0x0200" />
         <!-- The font scaling factor has changed, that is the user has
              selected a new global font size. -->
         <flag name="fontScale" value="0x40000000" />
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
index 7641afe..ae3daad 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/ConnectivityManagerMobileTest.java
@@ -470,10 +470,7 @@
         }
 
         // Prepare for state validation
-        NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
-        cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_MOBILE,
-                networkInfo.getState(),NetworkState.DO_NOTHING,State.DISCONNECTED);
-        networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
+        NetworkInfo networkInfo = cmActivity.mCM.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
         assertEquals(State.DISCONNECTED, networkInfo.getState());
         cmActivity.setStateTransitionCriteria(ConnectivityManager.TYPE_WIFI,
                 networkInfo.getState(), NetworkState.TO_CONNECTION, State.CONNECTED);
@@ -482,7 +479,9 @@
         cmActivity.setAirplaneMode(getInstrumentation().getContext(), false);
 
         waitForNetworkState(ConnectivityManager.TYPE_WIFI, State.CONNECTED,
-            STATE_TRANSITION_LONG_TIMEOUT);
+                            STATE_TRANSITION_LONG_TIMEOUT);
+        waitForNetworkState(ConnectivityManager.TYPE_MOBILE, State.DISCONNECTED,
+                            STATE_TRANSITION_LONG_TIMEOUT);
 
         // validate the state transition
         if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_WIFI)) {
@@ -491,12 +490,6 @@
                     cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_WIFI));
             assertTrue(false);
         }
-        if (!cmActivity.validateNetworkStates(ConnectivityManager.TYPE_MOBILE)) {
-            Log.v(LOG_TAG, "Mobile state transition validation failed.");
-            Log.v(LOG_TAG, "reason: " +
-                    cmActivity.getTransitionFailureReason(ConnectivityManager.TYPE_MOBILE));
-            assertTrue(false);
-        }
     }
 
     // Test case 8: test wifi state change while connecting/disconnecting to/from an AP
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 27add0a..e7022f4 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -668,7 +668,9 @@
 }
 
 status_t AwesomePlayer::getPosition(int64_t *positionUs) {
-    if (mVideoSource != NULL) {
+    if (mSeeking) {
+        *positionUs = mSeekTimeUs;
+    } else if (mVideoSource != NULL) {
         Mutex::Autolock autoLock(mMiscStateLock);
         *positionUs = mVideoTimeUs;
     } else if (mAudioPlayer != NULL) {
@@ -710,7 +712,6 @@
 
         mWatchForAudioSeekComplete = true;
         mWatchForAudioEOS = true;
-        mSeeking = false;
         mSeekNotificationSent = false;
     }
 }
@@ -1001,6 +1002,8 @@
             notifyListener_l(MEDIA_SEEK_COMPLETE);
             mSeekNotificationSent = true;
         }
+
+        mSeeking = false;
     }
 
     status_t finalStatus;