Merge change Iac196e17 into eclair

* changes:
  Fix issue 2292062: Audio freezes for three seconds when choosing ringtones with a headset connected and music playing.
diff --git a/api/current.xml b/api/current.xml
index a60c3a1..1dbe58f 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -976,7 +976,7 @@
  value=""android.permission.SET_PREFERRED_APPLICATIONS""
  static="true"
  final="true"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 </field>
@@ -41097,7 +41097,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="packageName" type="java.lang.String">
@@ -41850,7 +41850,7 @@
  synchronized="false"
  static="false"
  final="false"
- deprecated="not deprecated"
+ deprecated="deprecated"
  visibility="public"
 >
 <parameter name="packageName" type="java.lang.String">
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index e2030be..03d2a6d 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -1656,21 +1656,19 @@
             IPackageStatsObserver observer);
 
     /**
-     * Add a new package to the list of preferred packages.  This new package
-     * will be added to the front of the list (removed from its current location
-     * if already listed), meaning it will now be preferred over all other
-     * packages when resolving conflicts.
-     *
-     * @param packageName The package name of the new package to make preferred.
+     * @deprecated This function no longer does anything; it was an old
+     * approach to managing preferred activities, which has been superceeded
+     * (and conflicts with) the modern activity-based preferences.
      */
+    @Deprecated
     public abstract void addPackageToPreferred(String packageName);
 
     /**
-     * Remove a package from the list of preferred packages.  If it was on
-     * the list, it will no longer be preferred over other packages.
-     *
-     * @param packageName The package name to remove.
+     * @deprecated This function no longer does anything; it was an old
+     * approach to managing preferred activities, which has been superceeded
+     * (and conflicts with) the modern activity-based preferences.
      */
+    @Deprecated
     public abstract void removePackageFromPreferred(String packageName);
 
     /**
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 691fa77..ed1a98a 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -4621,6 +4621,7 @@
             View v = mWebTextView;
             int x = viewToContentX((v.getLeft() + v.getRight()) >> 1);
             int y = viewToContentY((v.getTop() + v.getBottom()) >> 1);
+            displaySoftKeyboard(true);
             nativeTextInputMotionUp(x, y);
         }
     }
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 1c3cf3c..0d03ff2 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -597,11 +597,9 @@
         android:label="@string/permlab_getPackageSize"
         android:description="@string/permdesc_getPackageSize" />
 
-    <!-- Allows an application to modify the list of preferred applications
-         with the {@link android.content.pm.PackageManager#addPackageToPreferred
-         PackageManager.addPackageToPreferred()} and
-         {@link android.content.pm.PackageManager#removePackageFromPreferred
-         PackageManager.removePackageFromPreferred()} methods. -->
+    <!-- @deprecated No longer useful, see
+         {@link android.content.pm.PackageManager#addPackageToPreferred}
+         for details. -->
     <permission android:name="android.permission.SET_PREFERRED_APPLICATIONS"
         android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
         android:protectionLevel="dangerous"
diff --git a/libs/surfaceflinger/SurfaceFlinger.cpp b/libs/surfaceflinger/SurfaceFlinger.cpp
index 9694cf1..965b7dd 100644
--- a/libs/surfaceflinger/SurfaceFlinger.cpp
+++ b/libs/surfaceflinger/SurfaceFlinger.cpp
@@ -417,9 +417,9 @@
 {
     while (true) {
         nsecs_t timeout = -1;
+        const nsecs_t freezeDisplayTimeout = ms2ns(5000);
         if (UNLIKELY(isFrozen())) {
             // wait 5 seconds
-            const nsecs_t freezeDisplayTimeout = ms2ns(5000);
             const nsecs_t now = systemTime();
             if (mFreezeDisplayTime == 0) {
                 mFreezeDisplayTime = now;
@@ -429,23 +429,27 @@
         }
 
         MessageList::value_type msg = mEventQueue.waitMessage(timeout);
+
+        // see if we timed out
+        if (isFrozen()) {
+            const nsecs_t now = systemTime();
+            nsecs_t frozenTime = (now - mFreezeDisplayTime);
+            if (frozenTime >= freezeDisplayTimeout) {
+                // we timed out and are still frozen
+                LOGW("timeout expired mFreezeDisplay=%d, mFreezeCount=%d",
+                        mFreezeDisplay, mFreezeCount);
+                mFreezeDisplayTime = 0;
+                mFreezeCount = 0;
+                mFreezeDisplay = false;
+            }
+        }
+
         if (msg != 0) {
-            mFreezeDisplayTime = 0;
             switch (msg->what) {
                 case MessageQueue::INVALIDATE:
                     // invalidate message, just return to the main loop
                     return;
             }
-        } else {
-            // we timed out
-            if (isFrozen()) {
-                // we timed out and are still frozen
-                LOGW("timeout expired mFreezeDisplay=%d, mFreezeCount=%d",
-                        mFreezeDisplay, mFreezeCount);
-                mFreezeCount = 0;
-                mFreezeDisplay = false;
-                return;
-            }
         }
     }
 }
@@ -1646,6 +1650,7 @@
             }
             case 1007: // set mFreezeCount
                 mFreezeCount = data.readInt32();
+                mFreezeDisplayTime = 0;
                 return NO_ERROR;
             case 1010:  // interrogate.
                 reply->writeInt32(0);
diff --git a/libs/surfaceflinger/SurfaceFlinger.h b/libs/surfaceflinger/SurfaceFlinger.h
index f9bfe6c..c0ab73d 100644
--- a/libs/surfaceflinger/SurfaceFlinger.h
+++ b/libs/surfaceflinger/SurfaceFlinger.h
@@ -291,7 +291,11 @@
 
             friend class FreezeLock;
             sp<FreezeLock> getFreezeLock() const;
-            inline void incFreezeCount() { mFreezeCount++; }
+            inline void incFreezeCount() {
+                if (mFreezeCount == 0)
+                    mFreezeDisplayTime = 0;
+                mFreezeCount++;
+            }
             inline void decFreezeCount() { if (mFreezeCount > 0) mFreezeCount--; }
             inline bool hasFreezeRequest() const { return mFreezeDisplay; }
             inline bool isFrozen() const { 
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index da25f97..079b4c3 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -640,13 +640,13 @@
                 map.put(Video.Media.ARTIST, (mArtist != null && mArtist.length() > 0 ? mArtist : MediaFile.UNKNOWN_STRING));
                 map.put(Video.Media.ALBUM, (mAlbum != null && mAlbum.length() > 0 ? mAlbum : MediaFile.UNKNOWN_STRING));
                 map.put(Video.Media.DURATION, mDuration);
-                map.put(Video.Media.DATE_TAKEN, mLastModified);
+                map.put(Video.Media.DATE_TAKEN, mLastModified * 1000);
                 // FIXME - add RESOLUTION
             } else if (MediaFile.isImageFileType(mFileType)) {
                 // FIXME - add DESCRIPTION
                 // DATE_TAKEN will be overridden later if this is a JPEG image whose EXIF data
                 // contains date time information.
-                map.put(Images.Media.DATE_TAKEN, mLastModified);
+                map.put(Images.Media.DATE_TAKEN, mLastModified * 1000);
             } else if (MediaFile.isAudioFileType(mFileType)) {
                 map.put(Audio.Media.ARTIST, (mArtist != null && mArtist.length() > 0 ? mArtist : MediaFile.UNKNOWN_STRING));
                 map.put(Audio.Media.ALBUM, (mAlbum != null && mAlbum.length() > 0 ? mAlbum : MediaFile.UNKNOWN_STRING));
@@ -746,7 +746,7 @@
 
                     long time = exif.getDateTime();
                     if (time != -1) {
-                        values.put(Images.Media.DATE_TAKEN, time);
+                        values.put(Images.Media.DATE_TAKEN, time * 1000);
                     }
 
                     int orientation = exif.getAttributeInt(
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 5ed2d35..9382146 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -2966,12 +2966,6 @@
             TAG, "Removing package " + pkg.applicationInfo.packageName );
 
         synchronized (mPackages) {
-            if (pkg.mPreferredOrder > 0) {
-                mSettings.mPreferredPackages.remove(pkg);
-                pkg.mPreferredOrder = 0;
-                updatePreferredIndicesLP();
-            }
-    
             clearPackagePreferredActivitiesLP(pkg.packageName);
     
             mPackages.remove(pkg.applicationInfo.packageName);
@@ -4938,62 +4932,17 @@
     public void addPackageToPreferred(String packageName) {
         mContext.enforceCallingOrSelfPermission(
                 android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
-
-        synchronized (mPackages) {
-            PackageParser.Package p = mPackages.get(packageName);
-            if (p == null) {
-                return;
-            }
-            PackageSetting ps = (PackageSetting)p.mExtras;
-            if (ps != null) {
-                mSettings.mPreferredPackages.remove(ps);
-                mSettings.mPreferredPackages.add(0, ps);
-                updatePreferredIndicesLP();
-                mSettings.writeLP();
-            }
-        }
+        Log.w(TAG, "addPackageToPreferred: no longer implemented");
     }
 
     public void removePackageFromPreferred(String packageName) {
         mContext.enforceCallingOrSelfPermission(
                 android.Manifest.permission.SET_PREFERRED_APPLICATIONS, null);
-
-        synchronized (mPackages) {
-            PackageParser.Package p = mPackages.get(packageName);
-            if (p == null) {
-                return;
-            }
-            if (p.mPreferredOrder > 0) {
-                PackageSetting ps = (PackageSetting)p.mExtras;
-                if (ps != null) {
-                    mSettings.mPreferredPackages.remove(ps);
-                    p.mPreferredOrder = 0;
-                    updatePreferredIndicesLP();
-                    mSettings.writeLP();
-                }
-            }
-        }
-    }
-
-    private void updatePreferredIndicesLP() {
-        final ArrayList<PackageSetting> pkgs
-                = mSettings.mPreferredPackages;
-        final int N = pkgs.size();
-        for (int i=0; i<N; i++) {
-            pkgs.get(i).pkg.mPreferredOrder = N - i;
-        }
+        Log.w(TAG, "removePackageFromPreferred: no longer implemented");
     }
 
     public List<PackageInfo> getPreferredPackages(int flags) {
-        synchronized (mPackages) {
-            final ArrayList<PackageInfo> res = new ArrayList<PackageInfo>();
-            final ArrayList<PackageSetting> pref = mSettings.mPreferredPackages;
-            final int N = pref.size();
-            for (int i=0; i<N; i++) {
-                res.add(generatePackageInfo(pref.get(i).pkg, flags));
-            }
-            return res;
-        }
+        return new ArrayList<PackageInfo>();
     }
 
     public void addPreferredActivity(IntentFilter filter, int match,
@@ -5307,13 +5256,6 @@
             pw.println("Preferred Activities:");
             mSettings.mPreferredActivities.dump(pw, "  ");
             pw.println(" ");
-            pw.println("Preferred Packages:");
-            {
-                for (PackageSetting ps : mSettings.mPreferredPackages) {
-                    pw.print("  "); pw.println(ps.name);
-                }
-            }
-            pw.println(" ");
             pw.println("Permissions:");
             {
                 for (BasePermission p : mSettings.mPermissions.values()) {
@@ -6064,10 +6006,6 @@
         private final File mBackupSettingsFilename;
         private final HashMap<String, PackageSetting> mPackages =
                 new HashMap<String, PackageSetting>();
-        // The user's preferred packages/applications, in order of preference.
-        // First is the most preferred.
-        private final ArrayList<PackageSetting> mPreferredPackages =
-                new ArrayList<PackageSetting>();
         // List of replaced system applications
         final HashMap<String, PackageSetting> mDisabledSysPackages =
             new HashMap<String, PackageSetting>();
@@ -6112,9 +6050,6 @@
         final HashMap<String, BasePermission> mPermissionTrees =
                 new HashMap<String, BasePermission>();
 
-        private final ArrayList<String> mPendingPreferredPackages
-                = new ArrayList<String>();
-
         private final StringBuilder mReadMessages = new StringBuilder();
 
         private static final class PendingPackage extends PackageSettingBase {
@@ -6598,16 +6533,6 @@
                     writeDisabledSysPackage(serializer, pkg);
                 }
 
-                serializer.startTag(null, "preferred-packages");
-                int N = mPreferredPackages.size();
-                for (int i=0; i<N; i++) {
-                    PackageSetting pkg = mPreferredPackages.get(i);
-                    serializer.startTag(null, "item");
-                    serializer.attribute(null, "name", pkg.name);
-                    serializer.endTag(null, "item");
-                }
-                serializer.endTag(null, "preferred-packages");
-
                 serializer.startTag(null, "preferred-activities");
                 for (PreferredActivity pa : mPreferredActivities.filterSet()) {
                     serializer.startTag(null, "item");
@@ -6885,7 +6810,7 @@
                     } else if (tagName.equals("shared-user")) {
                         readSharedUserLP(parser);
                     } else if (tagName.equals("preferred-packages")) {
-                        readPreferredPackagesLP(parser);
+                        // no longer used.
                     } else if (tagName.equals("preferred-activities")) {
                         readPreferredActivitiesLP(parser);
                     } else if(tagName.equals("updated-package")) {
@@ -6939,19 +6864,6 @@
             }
             mPendingPackages.clear();
 
-            N = mPendingPreferredPackages.size();
-            mPreferredPackages.clear();
-            for (int i=0; i<N; i++) {
-                final String name = mPendingPreferredPackages.get(i);
-                final PackageSetting p = mPackages.get(name);
-                if (p != null) {
-                    mPreferredPackages.add(p);
-                } else {
-                    Log.w(TAG, "Unknown preferred package: " + name);
-                }
-            }
-            mPendingPreferredPackages.clear();
-
             mReadMessages.append("Read completed successfully: "
                     + mPackages.size() + " packages, "
                     + mSharedUsers.size() + " shared uids\n");
@@ -7410,37 +7322,6 @@
             }
         }
 
-        private void readPreferredPackagesLP(XmlPullParser parser)
-                throws XmlPullParserException, IOException {
-            int outerDepth = parser.getDepth();
-            int type;
-            while ((type=parser.next()) != XmlPullParser.END_DOCUMENT
-                   && (type != XmlPullParser.END_TAG
-                           || parser.getDepth() > outerDepth)) {
-                if (type == XmlPullParser.END_TAG
-                        || type == XmlPullParser.TEXT) {
-                    continue;
-                }
-
-                String tagName = parser.getName();
-                if (tagName.equals("item")) {
-                    String name = parser.getAttributeValue(null, "name");
-                    if (name != null) {
-                        mPendingPreferredPackages.add(name);
-                    } else {
-                        reportSettingsProblem(Log.WARN,
-                                "Error in package manager settings: <preferred-package> has no name at "
-                                + parser.getPositionDescription());
-                    }
-                } else {
-                    reportSettingsProblem(Log.WARN,
-                            "Unknown element under <preferred-packages>: "
-                            + parser.getName());
-                }
-                XmlUtils.skipCurrentTag(parser);
-            }
-        }
-
         private void readPreferredActivitiesLP(XmlPullParser parser)
                 throws XmlPullParserException, IOException {
             int outerDepth = parser.getDepth();