Merge change 6797

* changes:
  rename libsgl/libcorecg to libskia
diff --git a/core/java/android/backup/BackupManager.java b/core/java/android/backup/BackupManager.java
index 37a58a9..86d8921 100644
--- a/core/java/android/backup/BackupManager.java
+++ b/core/java/android/backup/BackupManager.java
@@ -43,7 +43,7 @@
     private static final String TAG = "BackupManager";
 
     /** @hide TODO: REMOVE THIS */
-    public static final boolean EVEN_THINK_ABOUT_DOING_RESTORE = false;
+    public static final boolean EVEN_THINK_ABOUT_DOING_RESTORE = true;
 
     private Context mContext;
     private static IBackupManager sService;
diff --git a/core/java/android/speech/tts/ITts.aidl b/core/java/android/speech/tts/ITts.aidl
index c9a6180..5b18b5d 100755
--- a/core/java/android/speech/tts/ITts.aidl
+++ b/core/java/android/speech/tts/ITts.aidl
@@ -27,37 +27,37 @@
  * {@hide}

  */

 interface ITts {

-    int setSpeechRate(in int speechRate);

+    int setSpeechRate(in String callingApp, in int speechRate);

 

-    int setPitch(in int pitch);

+    int setPitch(in String callingApp, in int pitch);

 

-    int speak(in String text, in int queueMode, in String[] params);

+    int speak(in String callingApp, in String text, in int queueMode, in String[] params);

 

     boolean isSpeaking();

 

-    int stop();

+    int stop(in String callingApp);

 

-    void addSpeech(in String text, in String packageName, in int resId);

+    void addSpeech(in String callingApp, in String text, in String packageName, in int resId);

 

-    void addSpeechFile(in String text, in String filename);

+    void addSpeechFile(in String callingApp, in String text, in String filename);

 

     String[] getLanguage();

 

     int isLanguageAvailable(in String language, in String country, in String variant);

 

-    int setLanguage(in String language, in String country, in String variant);

+    int setLanguage(in String callingApp, in String language, in String country, in String variant);

 

-    boolean synthesizeToFile(in String text, in String[] params, in String outputDirectory);

+    boolean synthesizeToFile(in String callingApp, in String text, in String[] params, in String outputDirectory);

 

-    int playEarcon(in String earcon, in int queueMode, in String[] params);

+    int playEarcon(in String callingApp, in String earcon, in int queueMode, in String[] params);

 

-    void addEarcon(in String earcon, in String packageName, in int resId);

+    void addEarcon(in String callingApp, in String earcon, in String packageName, in int resId);

 

-    void addEarconFile(in String earcon, in String filename);

+    void addEarconFile(in String callingApp, in String earcon, in String filename);

 

     void registerCallback(ITtsCallback cb);

 

     void unregisterCallback(ITtsCallback cb);

 

-    int playSilence(in long duration, in int queueMode, in String[] params);

+    int playSilence(in String callingApp, in long duration, in int queueMode, in String[] params);

 }

diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java
index ed1e4ff6..e09eb04 100644
--- a/core/java/android/speech/tts/TextToSpeech.java
+++ b/core/java/android/speech/tts/TextToSpeech.java
@@ -139,6 +139,7 @@
 
     private ITts mITts = null;
     private Context mContext = null;
+    private String mPackageName = "";
     private OnInitListener mInitListener = null;
     private boolean mStarted = false;
     private final Object mStartLock = new Object();
@@ -159,6 +160,7 @@
      */
     public TextToSpeech(Context context, OnInitListener listener) {
         mContext = context;
+        mPackageName = mContext.getPackageName();
         mInitListener = listener;
 
         mCachedParams = new String[2*4]; // 4 parameters, store key and value
@@ -261,7 +263,7 @@
                 return TTS_ERROR;
             }
             try {
-                mITts.addSpeech(text, packagename, resourceId);
+                mITts.addSpeech(mPackageName, text, packagename, resourceId);
                 return TTS_SUCCESS;
             } catch (RemoteException e) {
                 // TTS died; restart it.
@@ -299,7 +301,7 @@
                 return TTS_ERROR;
             }
             try {
-                mITts.addSpeechFile(text, filename);
+                mITts.addSpeechFile(mPackageName, text, filename);
                 return TTS_SUCCESS;
             } catch (RemoteException e) {
                 // TTS died; restart it.
@@ -346,7 +348,7 @@
             }
             try {
                 // TODO support extra parameters, passing cache of current parameters for the moment
-                result = mITts.speak(text, queueMode, mCachedParams);
+                result = mITts.speak(mPackageName, text, queueMode, mCachedParams);
             } catch (RemoteException e) {
                 // TTS died; restart it.
                 mStarted = false;
@@ -387,7 +389,7 @@
             }
             try {
                 // TODO support extra parameters, passing null for the moment
-                result = mITts.playEarcon(earcon, queueMode, null);
+                result = mITts.playEarcon(mPackageName, earcon, queueMode, null);
             } catch (RemoteException e) {
                 // TTS died; restart it.
                 mStarted = false;
@@ -425,7 +427,7 @@
             }
             try {
                 // TODO support extra parameters, passing cache of current parameters for the moment
-                result = mITts.playSilence(durationInMs, queueMode, mCachedParams);
+                result = mITts.playSilence(mPackageName, durationInMs, queueMode, mCachedParams);
             } catch (RemoteException e) {
                 // TTS died; restart it.
                 mStarted = false;
@@ -487,7 +489,7 @@
                 return result;
             }
             try {
-                result = mITts.stop();
+                result = mITts.stop(mPackageName);
             } catch (RemoteException e) {
                 // TTS died; restart it.
                 mStarted = false;
@@ -532,7 +534,7 @@
                 if (speechRate > 0) {
                     int rate = (int)(speechRate*100);
                     mCachedParams[Engine.TTS_PARAM_POSITION_RATE + 1] = String.valueOf(rate);
-                    result = mITts.setSpeechRate(rate);
+                    result = mITts.setSpeechRate(mPackageName, rate);
                 }
             } catch (RemoteException e) {
                 // TTS died; restart it.
@@ -568,7 +570,7 @@
             }
             try {
                 if (pitch > 0) {
-                    result = mITts.setPitch((int)(pitch*100));
+                    result = mITts.setPitch(mPackageName, (int)(pitch*100));
                 }
             } catch (RemoteException e) {
                 // TTS died; restart it.
@@ -603,7 +605,8 @@
                 mCachedParams[Engine.TTS_PARAM_POSITION_LANGUAGE + 1] = loc.getISO3Language();
                 mCachedParams[Engine.TTS_PARAM_POSITION_COUNTRY + 1] = loc.getISO3Country();
                 mCachedParams[Engine.TTS_PARAM_POSITION_VARIANT + 1] = loc.getVariant();
-                result = mITts.setLanguage(mCachedParams[Engine.TTS_PARAM_POSITION_LANGUAGE + 1],
+                result = mITts.setLanguage(mPackageName,
+                        mCachedParams[Engine.TTS_PARAM_POSITION_LANGUAGE + 1],
                         mCachedParams[Engine.TTS_PARAM_POSITION_COUNTRY + 1],
                         mCachedParams[Engine.TTS_PARAM_POSITION_VARIANT + 1] );
             } catch (RemoteException e) {
@@ -694,7 +697,7 @@
             }
             try {
                 // TODO support extra parameters, passing null for the moment
-                if (mITts.synthesizeToFile(text, null, filename)){
+                if (mITts.synthesizeToFile(mPackageName, text, null, filename)){
                     result = TTS_SUCCESS;
                 }
             } catch (RemoteException e) {
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index f02d43c..8f3d55f 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -16,27 +16,13 @@
 
 package android.webkit;
 
-import android.content.ContentValues;
 import android.content.Context;
-import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
 import android.os.Build;
 import android.os.Handler;
 import android.os.Message;
-import android.preference.PreferenceManager;
 import android.provider.Checkin;
-import android.provider.Settings;
-import android.util.Log;
-
-import java.io.File;
 import java.lang.SecurityException;
-
-import android.content.SharedPreferences.Editor;
-import android.content.pm.PackageManager;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteException;
-import android.database.sqlite.SQLiteStatement;
-
-import java.util.HashSet;
 import java.util.Locale;
 
 /**
@@ -197,43 +183,6 @@
     private boolean         mAppCacheEnabled = false;
     private boolean         mDomStorageEnabled = false;
 
-    // Donut-specific hack to keep Gears permissions in sync with the
-    // system location setting.
-    // TODO: Make sure this hack is removed in  Eclair, when Gears
-    // is also removed.
-    // Used to remember if we checked the Gears permissions already.
-    static boolean mCheckedGearsPermissions = false;
-    // The Gears permissions database directory.
-    private final static String GEARS_DATABASE_DIR = "gears";
-    // The Gears permissions database file name.
-    private final static String GEARS_DATABASE_FILE = "permissions.db";
-    // The Gears location permissions table.
-    private final static String GEARS_LOCATION_ACCESS_TABLE_NAME = 
-        "LocationAccess";
-    // The Gears storage access permissions table.
-    private final static String GEARS_STORAGE_ACCESS_TABLE_NAME = "Access";
-    // The Gears permissions db schema version table.
-    private final static String GEARS_SCHEMA_VERSION_TABLE_NAME =
-        "VersionInfo";
-    // The shared pref name.
-    private static final String LAST_KNOWN_LOCATION_SETTING =
-        "lastKnownLocationSystemSetting";
-    // The Browser package name.
-    private static final String BROWSER_PACKAGE_NAME = "com.android.browser";
-    // The Google URLs whitelisted for Gears location access.
-    private static HashSet<String> sGearsWhiteList;
-
-    static {
-        sGearsWhiteList = new HashSet<String>();
-        // NOTE: DO NOT ADD A "/" AT THE END!
-        sGearsWhiteList.add("http://www.google.com");
-        sGearsWhiteList.add("http://www.google.co.uk");
-    }
-
-    private static final String LOGTAG = "webcore";
-    static final boolean DEBUG = false;
-    static final boolean LOGV_ENABLED = DEBUG;
-
     // Class to handle messages before WebCore is ready.
     private class EventHandler {
         // Message id for syncing
@@ -254,7 +203,6 @@
                     switch (msg.what) {
                         case SYNC:
                             synchronized (WebSettings.this) {
-                                checkGearsPermissions();
                                 if (mBrowserFrame.mNativeFrame != 0) {
                                     nativeSync(mBrowserFrame.mNativeFrame);
                                 }
@@ -1327,123 +1275,6 @@
         return size;
     }
 
-    private void checkGearsPermissions() {
-        // Did we already check the permissions?
-        if (mCheckedGearsPermissions) {
-            return;
-        }
-        // Are we running in the browser?
-        if (!BROWSER_PACKAGE_NAME.equals(mContext.getPackageName())) {
-            return;
-        }
-
-        // Remember we checked the Gears permissions.
-        mCheckedGearsPermissions = true;
-        // Get the current system settings.
-        int setting = Settings.Secure.getInt(mContext.getContentResolver(),
-                Settings.Secure.USE_LOCATION_FOR_SERVICES, -1);
-        // Check if we need to set the Gears permissions.
-        if (setting != -1 && locationSystemSettingChanged(setting)) {
-            setGearsPermissionForGoogleDomains(setting);
-        }
-    }
-
-    private boolean locationSystemSettingChanged(int newSetting) {
-        SharedPreferences prefs =
-            PreferenceManager.getDefaultSharedPreferences(mContext);
-        int oldSetting = 0;
-        oldSetting = prefs.getInt(LAST_KNOWN_LOCATION_SETTING, oldSetting);
-        if (oldSetting == newSetting) {
-            return false;
-        }
-        Editor ed = prefs.edit();
-        ed.putInt(LAST_KNOWN_LOCATION_SETTING, newSetting);
-        ed.commit();
-        return true;
-    }
-
-    private void setGearsPermissionForGoogleDomains(int systemPermission) {
-        // Transform the system permission into a Gears permission
-        int gearsPermission = (systemPermission == 1 ? 1 : 2);
-        // Build the path to the Gears library.
-
-        // hack for now
-        File file = mContext.getDir("plugins", 0);
-        if (file == null) {
-            return;
-        }
-        file = file.getParentFile();
-        // Build the Gears database file name.
-        file = new File(file.getAbsolutePath() + File.separator 
-                + GEARS_DATABASE_DIR + File.separator + GEARS_DATABASE_FILE);
-        // Remember whether or not we need to create the LocationAccess table.
-        boolean needToCreateTables = !file.exists();
-        // Try opening the Gears database.
-        SQLiteDatabase permissions;
-        try {
-            permissions = SQLiteDatabase.openOrCreateDatabase(file, null);
-        } catch (SQLiteException e) {
-            if (LOGV_ENABLED) {
-                Log.v(LOGTAG, "Could not open Gears permission DB: " +
-                        e.getMessage());
-            }
-            // Just bail out.
-            return;
-        }
-        // We now have a database open. Begin a transaction.
-        permissions.beginTransaction();
-        try {
-            if (needToCreateTables) {
-                // Create the tables. Note that this creates the
-                // Gears tables for the permissions DB schema version 2.
-                // The Gears schema upgrade process will take care of the rest.
-                // First, the storage access table.
-                SQLiteStatement statement = permissions.compileStatement(
-                        "CREATE TABLE IF NOT EXISTS " +
-                        GEARS_STORAGE_ACCESS_TABLE_NAME +
-                        " (Name TEXT UNIQUE, Value)");
-                statement.execute();
-                // Next the location access table.
-                statement = permissions.compileStatement(
-                        "CREATE TABLE IF NOT EXISTS " +
-                        GEARS_LOCATION_ACCESS_TABLE_NAME +
-                        " (Name TEXT UNIQUE, Value)");
-                statement.execute();
-                // Finally, the schema version table.
-                statement = permissions.compileStatement(
-                        "CREATE TABLE IF NOT EXISTS " +
-                        GEARS_SCHEMA_VERSION_TABLE_NAME +
-                        " (Name TEXT UNIQUE, Value)");
-                statement.execute();
-                // Set the schema version to 2.
-                ContentValues schema = new ContentValues();
-                schema.put("Name", "Version");
-                schema.put("Value", 2);
-                permissions.insert(GEARS_SCHEMA_VERSION_TABLE_NAME, null,
-                        schema);
-            }
-
-            ContentValues permissionValues = new ContentValues();
-
-            for (String url : sGearsWhiteList) {
-                permissionValues.put("Name", url);
-                permissionValues.put("Value", gearsPermission);
-                permissions.replace(GEARS_LOCATION_ACCESS_TABLE_NAME, null,
-                        permissionValues);
-                permissionValues.clear();
-            }
-            // Commit the transaction.
-            permissions.setTransactionSuccessful();
-        } catch (SQLiteException e) {
-            if (LOGV_ENABLED) {
-                Log.v(LOGTAG, "Could not set the Gears permissions: " +
-                        e.getMessage());
-            }
-        } finally {
-            permissions.endTransaction();
-            permissions.close();
-        }
-    }
     /* Post a SYNC message to handle syncing the native settings. */
     private synchronized void postSync() {
         // Only post if a sync is not pending
diff --git a/include/media/IMediaPlayer.h b/include/media/IMediaPlayer.h
index 074125f..b6f654f 100644
--- a/include/media/IMediaPlayer.h
+++ b/include/media/IMediaPlayer.h
@@ -59,6 +59,23 @@
     // @param filter A set of allow and drop rules serialized in a Parcel.
     // @return OK if the invocation was made successfully.
     virtual status_t        setMetadataFilter(const Parcel& filter) = 0;
+
+    // Retrieve a set of metadata.
+    // @param update_only Include only the metadata that have changed
+    //                    since the last invocation of getMetadata.
+    //                    The set is built using the unfiltered
+    //                    notifications the native player sent to the
+    //                    MediaPlayerService during that period of
+    //                    time. If false, all the metadatas are considered.
+    // @param apply_filter If true, once the metadata set has been built based
+    //                     on the value update_only, the current filter is
+    //                     applied.
+    // @param[out] metadata On exit contains a set (possibly empty) of metadata.
+    //                      Valid only if the call returned OK.
+    // @return OK if the invocation was made successfully.
+    virtual status_t        getMetadata(bool update_only,
+                                        bool apply_filter,
+                                        Parcel *metadata) = 0;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h
index 8326a21..26b054bd 100644
--- a/include/media/mediaplayer.h
+++ b/include/media/mediaplayer.h
@@ -155,6 +155,7 @@
     static  sp<IMemory>     decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
             status_t        invoke(const Parcel& request, Parcel *reply);
             status_t        setMetadataFilter(const Parcel& filter);
+            status_t        getMetadata(bool update_only, bool apply_filter, Parcel *metadata);
 private:
             void            clear_l();
             status_t        seekTo_l(int msec);
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index 306ea81..a23f535 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -930,8 +930,21 @@
      */
     public Metadata getMetadata(final boolean update_only,
                                 final boolean apply_filter) {
-        // FIXME: Implement.
-        return new Metadata();
+        Parcel reply = Parcel.obtain();
+        Metadata data = new Metadata();
+
+        if (!native_getMetadata(update_only, apply_filter, reply)) {
+            reply.recycle();
+            return null;
+        }
+
+        // Metadata takes over the parcel, don't recycle it unless
+        // there is an error.
+        if (!data.parse(reply)) {
+            reply.recycle();
+            return null;
+        }
+        return data;
     }
 
     /**
@@ -1064,11 +1077,29 @@
      * @param request Parcel destinated to the media player. The
      *                Interface token must be set to the IMediaPlayer
      *                one to be routed correctly through the system.
-     * @param reply Parcel that will contain the reply.
+     * @param reply[out] Parcel that will contain the reply.
      * @return The status code.
      */
     private native final int native_invoke(Parcel request, Parcel reply);
 
+
+    /**
+     * @param update_only If true fetch only the set of metadata that have
+     *                    changed since the last invocation of getMetadata.
+     *                    The set is built using the unfiltered
+     *                    notifications the native player sent to the
+     *                    MediaPlayerService during that period of
+     *                    time. If false, all the metadatas are considered.
+     * @param apply_filter  If true, once the metadata set has been built based on
+     *                     the value update_only, the current filter is applied.
+     * @param reply[out] On return contains the serialized
+     *                   metadata. Valid only if the call was successful.
+     * @return The status code.
+     */
+    private native final boolean native_getMetadata(boolean update_only,
+                                                    boolean apply_filter,
+                                                    Parcel reply);
+
     /**
      * @param request Parcel with the 2 serialized lists of allowed
      *                metadata types followed by the one to be
diff --git a/media/java/android/media/Metadata.java b/media/java/android/media/Metadata.java
index 7bc4e9c..6525109 100644
--- a/media/java/android/media/Metadata.java
+++ b/media/java/android/media/Metadata.java
@@ -17,6 +17,7 @@
 package android.media;
 
 import android.graphics.Bitmap;
+import android.os.Parcel;
 import android.util.Log;
 
 import java.util.Collections;
@@ -24,6 +25,7 @@
 import java.util.Iterator;
 import java.util.Set;
 
+
 /**
    Class to hold the media's metadata.  Metadata are used
    for human consumption and can be embedded in the media (e.g
@@ -100,6 +102,12 @@
     public static final Set<Integer> MATCH_NONE = Collections.EMPTY_SET;
     public static final Set<Integer> MATCH_ALL = Collections.singleton(ANY);
 
+    private static final int STRING_VAL = 1;
+    private static final int INTEGER_VAL = 2;
+    private static final int LONG_VAL = 3;
+    private static final int DOUBLE_VAL = 4;
+    private static final int TIMED_TEXT_VAL = 2;
+
     /**
      * Helper class to hold a pair (time, text). Can be used to implement caption.
      */
@@ -119,6 +127,11 @@
 
     /* package */ Metadata() {}
 
+    /* package */ boolean parse(Parcel data) {
+        // FIXME: Implement.
+        return true;
+    }
+
     /**
      * @return the number of element in this metadata set.
      */
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index 19a2a41..b173129 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -479,9 +479,39 @@
 
     Parcel *filter = parcelForJavaObject(env, request);
 
+    if (filter == NULL ) {
+        jniThrowException(env, "java/lang/RuntimeException", "Filter is null");
+        return UNKNOWN_ERROR;
+    }
+
     return media_player->setMetadataFilter(*filter);
 }
 
+static jboolean
+android_media_MediaPlayer_getMetadata(JNIEnv *env, jobject thiz, jboolean update_only,
+                                      jboolean apply_filter, jobject reply)
+{
+    sp<MediaPlayer> media_player = getMediaPlayer(env, thiz);
+    if (media_player == NULL ) {
+        jniThrowException(env, "java/lang/IllegalStateException", NULL);
+        return false;
+    }
+
+    Parcel *metadata = parcelForJavaObject(env, reply);
+
+    if (metadata == NULL ) {
+        jniThrowException(env, "java/lang/RuntimeException", "Reply parcel is null");
+        return false;
+    }
+
+    metadata->freeData();
+    // On return metadata is positioned at the beginning of the
+    // metadata. Note however that the parcel actually starts with the
+    // return code so you should not rewind the parcel using
+    // setDataPosition(0).
+    return media_player->getMetadata(update_only, apply_filter, metadata) == OK;
+}
+
 
 static void
 android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this)
@@ -546,6 +576,7 @@
     {"getFrameAt",          "(I)Landroid/graphics/Bitmap;",     (void *)android_media_MediaPlayer_getFrameAt},
     {"native_invoke",       "(Landroid/os/Parcel;Landroid/os/Parcel;)I",(void *)android_media_MediaPlayer_invoke},
     {"native_setMetadataFilter", "(Landroid/os/Parcel;)I",      (void *)android_media_MediaPlayer_setMetadataFilter},
+    {"native_getMetadata", "(ZZLandroid/os/Parcel;)Z",          (void *)android_media_MediaPlayer_getMetadata},
     {"native_setup",        "(Ljava/lang/Object;)V",            (void *)android_media_MediaPlayer_native_setup},
     {"native_finalize",     "()V",                              (void *)android_media_MediaPlayer_native_finalize},
 };
diff --git a/media/libmedia/IMediaPlayer.cpp b/media/libmedia/IMediaPlayer.cpp
index 131e510..5d9db10 100644
--- a/media/libmedia/IMediaPlayer.cpp
+++ b/media/libmedia/IMediaPlayer.cpp
@@ -42,6 +42,7 @@
     SET_VOLUME,
     INVOKE,
     SET_METADATA_FILTER,
+    GET_METADATA,
 };
 
 class BpMediaPlayer: public BpInterface<IMediaPlayer>
@@ -176,8 +177,7 @@
     status_t invoke(const Parcel& request, Parcel *reply)
     { // Avoid doing any extra copy. The interface descriptor should
       // have been set by MediaPlayer.java.
-        status_t retcode = remote()->transact(INVOKE, request, reply);
-        return retcode;
+        return remote()->transact(INVOKE, request, reply);
     }
 
     status_t setMetadataFilter(const Parcel& request)
@@ -188,6 +188,17 @@
         remote()->transact(SET_METADATA_FILTER, request, &reply);
         return reply.readInt32();
     }
+
+    status_t getMetadata(bool update_only, bool apply_filter, Parcel *reply)
+    {
+        Parcel request;
+        request.writeInterfaceToken(IMediaPlayer::getInterfaceDescriptor());
+        // TODO: Burning 2 ints for 2 boolean. Should probably use flags in an int here.
+        request.writeInt32(update_only);
+        request.writeInt32(apply_filter);
+        remote()->transact(GET_METADATA, request, reply);
+        return reply->readInt32();
+    }
 };
 
 IMPLEMENT_META_INTERFACE(MediaPlayer, "android.media.IMediaPlayer");
@@ -288,6 +299,14 @@
             reply->writeInt32(setMetadataFilter(data));
             return NO_ERROR;
         } break;
+        case GET_METADATA: {
+            CHECK_INTERFACE(IMediaPlayer, data, reply);
+            const status_t retcode = getMetadata(data.readInt32(), data.readInt32(), reply);
+            reply->setDataPosition(0);
+            reply->writeInt32(retcode);
+            reply->setDataPosition(0);
+            return NO_ERROR;
+        } break;
         default:
             return BBinder::onTransact(code, data, reply, flags);
     }
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index d8c622f..6b35fa7 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -211,14 +211,23 @@
 status_t MediaPlayer::setMetadataFilter(const Parcel& filter)
 {
     LOGD("setMetadataFilter");
-    Mutex::Autolock _l(mLock);
-    if (mPlayer == NULL)
-    {
+    Mutex::Autolock lock(mLock);
+    if (mPlayer == NULL) {
         return NO_INIT;
     }
     return mPlayer->setMetadataFilter(filter);
 }
 
+status_t MediaPlayer::getMetadata(bool update_only, bool apply_filter, Parcel *metadata)
+{
+    LOGD("getMetadata");
+    Mutex::Autolock lock(mLock);
+    if (mPlayer == NULL) {
+        return NO_INIT;
+    }
+    return mPlayer->getMetadata(update_only, apply_filter, metadata);
+}
+
 status_t MediaPlayer::setVideoSurface(const sp<Surface>& surface)
 {
     LOGV("setVideoSurface");
diff --git a/media/libmediaplayerservice/MediaPlayerService.cpp b/media/libmediaplayerservice/MediaPlayerService.cpp
index 3adbfac..04aab81 100644
--- a/media/libmediaplayerservice/MediaPlayerService.cpp
+++ b/media/libmediaplayerservice/MediaPlayerService.cpp
@@ -846,6 +846,16 @@
     return status;
 }
 
+status_t MediaPlayerService::Client::getMetadata(bool update_only, bool apply_filter, Parcel *metadata)
+{
+    status_t status;
+    metadata->writeInt32(-1);  // Placeholder for the return code
+
+    // FIXME: Implement, query the native player and do the optional filtering, etc...
+    status = OK;
+    return status;
+}
+
 status_t MediaPlayerService::Client::prepareAsync()
 {
     LOGV("[%d] prepareAsync", mConnId);
diff --git a/media/libmediaplayerservice/MediaPlayerService.h b/media/libmediaplayerservice/MediaPlayerService.h
index b915e86..7920559 100644
--- a/media/libmediaplayerservice/MediaPlayerService.h
+++ b/media/libmediaplayerservice/MediaPlayerService.h
@@ -191,6 +191,7 @@
         virtual status_t        setVolume(float leftVolume, float rightVolume);
         virtual status_t        invoke(const Parcel& request, Parcel *reply);
         virtual status_t        setMetadataFilter(const Parcel& filter);
+        virtual status_t        getMetadata(bool update_only, bool apply_filter, Parcel *metadata);
 
         sp<MediaPlayerBase>     createPlayer(player_type playerType);
                 status_t        setDataSource(const char *url);
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java
index 1eba469..ea22410 100755
--- a/packages/TtsService/src/android/tts/TtsService.java
+++ b/packages/TtsService/src/android/tts/TtsService.java
@@ -59,23 +59,27 @@
         public int mType = TEXT;
         public long mDuration = 0;
         public String mFilename = null;
+        public String callingApp = "";
 
-        public SpeechItem(String text, ArrayList<String> params, int itemType) {
+        public SpeechItem(String source, String text, ArrayList<String> params, int itemType) {
             mText = text;
             mParams = params;
             mType = itemType;
+            callingApp = source;
         }
 
-        public SpeechItem(long silenceTime) {
+        public SpeechItem(String source, long silenceTime) {
             mDuration = silenceTime;
             mType = SILENCE;
+            callingApp = source;
         }
 
-        public SpeechItem(String text, ArrayList<String> params, int itemType, String filename) {
+        public SpeechItem(String source, String text, ArrayList<String> params, int itemType, String filename) {
             mText = text;
             mParams = params;
             mType = itemType;
             mFilename = filename;
+            callingApp = source;
         }
 
     }
@@ -161,10 +165,10 @@
 
 
     private void setDefaultSettings() {
-        setLanguage(this.getDefaultLanguage(), getDefaultCountry(), getDefaultLocVariant());
+        setLanguage("", this.getDefaultLanguage(), getDefaultCountry(), getDefaultLocVariant());
 
         // speech rate
-        setSpeechRate(getDefaultRate());
+        setSpeechRate("", getDefaultRate());
     }
 
 
@@ -219,7 +223,7 @@
     }
 
 
-    private int setSpeechRate(int rate) {
+    private int setSpeechRate(String callingApp, int rate) {
         if (isDefaultEnforced()) {
             return nativeSynth.setSpeechRate(getDefaultRate());
         } else {
@@ -228,7 +232,7 @@
     }
 
 
-    private int setPitch(int pitch) {
+    private int setPitch(String callingApp, int pitch) {
         return nativeSynth.setPitch(pitch);
     }
 
@@ -244,7 +248,7 @@
     }
 
 
-    private int setLanguage(String lang, String country, String variant) {
+    private int setLanguage(String callingApp, String lang, String country, String variant) {
         //Log.v("TTS", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")");
         if (isDefaultEnforced()) {
             return nativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(),
@@ -265,7 +269,7 @@
      * @param resId
      *            The resource ID of the sound within its package
      */
-    private void addSpeech(String text, String packageName, int resId) {
+    private void addSpeech(String callingApp, String text, String packageName, int resId) {
         mUtterances.put(text, new SoundResource(packageName, resId));
     }
 
@@ -278,7 +282,7 @@
      *            The filename of the sound resource. This must be a complete
      *            path like: (/sdcard/mysounds/mysoundbite.mp3).
      */
-    private void addSpeech(String text, String filename) {
+    private void addSpeech(String callingApp, String text, String filename) {
         mUtterances.put(text, new SoundResource(filename));
     }
 
@@ -292,7 +296,7 @@
      * @param resId
      *            The resource ID of the sound within its package
      */
-    private void addEarcon(String earcon, String packageName, int resId) {
+    private void addEarcon(String callingApp, String earcon, String packageName, int resId) {
         mEarcons.put(earcon, new SoundResource(packageName, resId));
     }
 
@@ -305,7 +309,7 @@
      *            The filename of the sound resource. This must be a complete
      *            path like: (/sdcard/mysounds/mysoundbite.mp3).
      */
-    private void addEarcon(String earcon, String filename) {
+    private void addEarcon(String callingApp, String earcon, String filename) {
         mEarcons.put(earcon, new SoundResource(filename));
     }
 
@@ -315,17 +319,17 @@
      * @param text
      *            The text that should be spoken
      * @param queueMode
-     *            0 for no queue (interrupts all previous utterances), 1 for
-     *            queued
+     *            TextToSpeech.TTS_QUEUE_FLUSH for no queue (interrupts all previous utterances),
+     *            TextToSpeech.TTS_QUEUE_ADD for queued
      * @param params
      *            An ArrayList of parameters. This is not implemented for all
      *            engines.
      */
-    private int speak(String text, int queueMode, ArrayList<String> params) {
-        if (queueMode == 0) {
-            stop();
+    private int speak(String callingApp, String text, int queueMode, ArrayList<String> params) {
+        if (queueMode == TextToSpeech.TTS_QUEUE_FLUSH) {
+            stop(callingApp);
         }
-        mSpeechQueue.add(new SpeechItem(text, params, SpeechItem.TEXT));
+        mSpeechQueue.add(new SpeechItem(callingApp, text, params, SpeechItem.TEXT));
         if (!mIsSpeaking) {
             processSpeechQueue();
         }
@@ -338,18 +342,18 @@
      * @param earcon
      *            The earcon that should be played
      * @param queueMode
-     *            0 for no queue (interrupts all previous utterances), 1 for
-     *            queued
+     *            TextToSpeech.TTS_QUEUE_FLUSH for no queue (interrupts all previous utterances),
+     *            TextToSpeech.TTS_QUEUE_ADD for queued
      * @param params
      *            An ArrayList of parameters. This is not implemented for all
      *            engines.
      */
-    private int playEarcon(String earcon, int queueMode,
+    private int playEarcon(String callingApp, String earcon, int queueMode,
             ArrayList<String> params) {
-        if (queueMode == 0) {
-            stop();
+        if (queueMode == TextToSpeech.TTS_QUEUE_FLUSH) {
+            stop(callingApp);
         }
-        mSpeechQueue.add(new SpeechItem(earcon, params, SpeechItem.EARCON));
+        mSpeechQueue.add(new SpeechItem(callingApp, earcon, params, SpeechItem.EARCON));
         if (!mIsSpeaking) {
             processSpeechQueue();
         }
@@ -359,7 +363,7 @@
     /**
      * Stops all speech output and removes any utterances still in the queue.
      */
-    private int stop() {
+    private int stop(String callingApp) {
         int result = TextToSpeech.TTS_ERROR;
         boolean speechQueueAvailable = false;
         try{
@@ -368,7 +372,11 @@
             speechQueueAvailable = speechQueueLock.tryLock(1000, TimeUnit.MILLISECONDS);
             if (speechQueueAvailable) {
                 Log.i("TTS", "Stopping");
-                mSpeechQueue.clear();
+                for (int i = mSpeechQueue.size() - 1; i > -1; i--){
+                    if (mSpeechQueue.get(i).callingApp.equals(callingApp)){
+                        mSpeechQueue.remove(i);
+                    }
+                }
 
                 result = nativeSynth.stop();
                 mIsSpeaking = false;
@@ -398,12 +406,12 @@
         processSpeechQueue();
     }
 
-    private int playSilence(long duration, int queueMode,
+    private int playSilence(String callingApp, long duration, int queueMode,
             ArrayList<String> params) {
-        if (queueMode == 0) {
-            stop();
+        if (queueMode == TextToSpeech.TTS_QUEUE_FLUSH) {
+            stop(callingApp);
         }
-        mSpeechQueue.add(new SpeechItem(duration));
+        mSpeechQueue.add(new SpeechItem(callingApp, duration));
         if (!mIsSpeaking) {
             processSpeechQueue();
         }
@@ -448,7 +456,7 @@
                         for (int i = 0; i < params.size() - 1; i = i + 2){
                             String param = params.get(i);
                             if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_RATE)){
-                                setSpeechRate(Integer.parseInt(params.get(i+1)));
+                                setSpeechRate("", Integer.parseInt(params.get(i+1)));
                             } else if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_LANGUAGE)){
                                 language = params.get(i+1);
                             } else if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_COUNTRY)){
@@ -458,7 +466,7 @@
                             }
                         }
                         if (language.length() > 0){
-                            setLanguage(language, country, variant);
+                            setLanguage("", language, country, variant);
                         }
                     }
                     nativeSynth.speak(text);
@@ -503,7 +511,7 @@
                         for (int i = 0; i < params.size() - 1; i = i + 2){
                             String param = params.get(i);
                             if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_RATE)){
-                                setSpeechRate(Integer.parseInt(params.get(i+1)));
+                                setSpeechRate("", Integer.parseInt(params.get(i+1)));
                             } else if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_LANGUAGE)){
                                 language = params.get(i+1);
                             } else if (param.equals(TextToSpeech.Engine.TTS_KEY_PARAM_COUNTRY)){
@@ -513,7 +521,7 @@
                             }
                         }
                         if (language.length() > 0){
-                            setLanguage(language, country, variant);
+                            setLanguage("", language, country, variant);
                         }
                     }
                     nativeSynth.synthesizeToFile(text, filename);
@@ -574,6 +582,7 @@
         if (currentSpeechItem.mText.length() < MAX_SPEECH_ITEM_CHAR_LENGTH){
             return currentSpeechItem;
         } else {
+            String callingApp = currentSpeechItem.callingApp;
             ArrayList<SpeechItem> splitItems = new ArrayList<SpeechItem>();
             int start = 0;
             int end = start + MAX_SPEECH_ITEM_CHAR_LENGTH - 1;
@@ -581,13 +590,13 @@
             SpeechItem splitItem;
             while (end < currentSpeechItem.mText.length()){
                 splitText = currentSpeechItem.mText.substring(start, end);
-                splitItem = new SpeechItem(splitText, null, SpeechItem.TEXT);
+                splitItem = new SpeechItem(callingApp, splitText, null, SpeechItem.TEXT);
                 splitItems.add(splitItem);
                 start = end;
                 end = start + MAX_SPEECH_ITEM_CHAR_LENGTH - 1;
             }
             splitText = currentSpeechItem.mText.substring(start);
-            splitItem = new SpeechItem(splitText, null, SpeechItem.TEXT);
+            splitItem = new SpeechItem(callingApp, splitText, null, SpeechItem.TEXT);
             splitItems.add(splitItem);
             mSpeechQueue.remove(0);
             for (int i = splitItems.size() - 1; i >= 0; i--){
@@ -701,7 +710,7 @@
      *            something like "/sdcard/myappsounds/mysound.wav".
      * @return A boolean that indicates if the synthesis succeeded
      */
-    private boolean synthesizeToFile(String text, ArrayList<String> params,
+    private boolean synthesizeToFile(String callingApp, String text, ArrayList<String> params,
             String filename) {
         // Don't allow a filename that is too long
         if (filename.length() > MAX_FILENAME_LENGTH) {
@@ -712,7 +721,7 @@
         if (text.length() >= MAX_SPEECH_ITEM_CHAR_LENGTH){
             return false;
         }
-        mSpeechQueue.add(new SpeechItem(text, params, SpeechItem.TEXT_TO_FILE, filename));
+        mSpeechQueue.add(new SpeechItem(callingApp, text, params, SpeechItem.TEXT_TO_FILE, filename));
         if (!mIsSpeaking) {
             processSpeechQueue();
         }
@@ -750,18 +759,18 @@
          * @param text
          *            The text that should be spoken
          * @param queueMode
-         *            0 for no queue (interrupts all previous utterances), 1 for
-         *            queued
+         *            TextToSpeech.TTS_QUEUE_FLUSH for no queue (interrupts all previous utterances)
+         *            TextToSpeech.TTS_QUEUE_ADD for queued
          * @param params
          *            An ArrayList of parameters. The first element of this
          *            array controls the type of voice to use.
          */
-        public int speak(String text, int queueMode, String[] params) {
+        public int speak(String callingApp, String text, int queueMode, String[] params) {
             ArrayList<String> speakingParams = new ArrayList<String>();
             if (params != null) {
                 speakingParams = new ArrayList<String>(Arrays.asList(params));
             }
-            return mSelf.speak(text, queueMode, speakingParams);
+            return mSelf.speak(callingApp, text, queueMode, speakingParams);
         }
 
         /**
@@ -770,17 +779,17 @@
          * @param earcon
          *            The earcon that should be played
          * @param queueMode
-         *            0 for no queue (interrupts all previous utterances), 1 for
-         *            queued
+         *            TextToSpeech.TTS_QUEUE_FLUSH for no queue (interrupts all previous utterances)
+         *            TextToSpeech.TTS_QUEUE_ADD for queued
          * @param params
          *            An ArrayList of parameters.
          */
-        public int playEarcon(String earcon, int queueMode, String[] params) {
+        public int playEarcon(String callingApp, String earcon, int queueMode, String[] params) {
             ArrayList<String> speakingParams = new ArrayList<String>();
             if (params != null) {
                 speakingParams = new ArrayList<String>(Arrays.asList(params));
             }
-            return mSelf.playEarcon(earcon, queueMode, speakingParams);
+            return mSelf.playEarcon(callingApp, earcon, queueMode, speakingParams);
         }
 
         /**
@@ -789,25 +798,25 @@
          * @param duration
          *            The duration of the silence that should be played
          * @param queueMode
-         *            0 for no queue (interrupts all previous utterances), 1 for
-         *            queued
+         *            TextToSpeech.TTS_QUEUE_FLUSH for no queue (interrupts all previous utterances)
+         *            TextToSpeech.TTS_QUEUE_ADD for queued
          * @param params
          *            An ArrayList of parameters.
          */
-        public int playSilence(long duration, int queueMode, String[] params) {
+        public int playSilence(String callingApp, long duration, int queueMode, String[] params) {
             ArrayList<String> speakingParams = new ArrayList<String>();
             if (params != null) {
                 speakingParams = new ArrayList<String>(Arrays.asList(params));
             }
-            return mSelf.playSilence(duration, queueMode, speakingParams);
+            return mSelf.playSilence(callingApp, duration, queueMode, speakingParams);
         }
 
         /**
          * Stops all speech output and removes any utterances still in the
          * queue.
          */
-        public int stop() {
-            return mSelf.stop();
+        public int stop(String callingApp) {
+            return mSelf.stop(callingApp);
         }
 
         /**
@@ -829,8 +838,8 @@
          * @param resId
          *            The resource ID of the sound within its package
          */
-        public void addSpeech(String text, String packageName, int resId) {
-            mSelf.addSpeech(text, packageName, resId);
+        public void addSpeech(String callingApp, String text, String packageName, int resId) {
+            mSelf.addSpeech(callingApp, text, packageName, resId);
         }
 
         /**
@@ -842,8 +851,8 @@
          *            The filename of the sound resource. This must be a
          *            complete path like: (/sdcard/mysounds/mysoundbite.mp3).
          */
-        public void addSpeechFile(String text, String filename) {
-            mSelf.addSpeech(text, filename);
+        public void addSpeechFile(String callingApp, String text, String filename) {
+            mSelf.addSpeech(callingApp, text, filename);
         }
 
         /**
@@ -856,8 +865,8 @@
          * @param resId
          *            The resource ID of the sound within its package
          */
-        public void addEarcon(String earcon, String packageName, int resId) {
-            mSelf.addEarcon(earcon, packageName, resId);
+        public void addEarcon(String callingApp, String earcon, String packageName, int resId) {
+            mSelf.addEarcon(callingApp, earcon, packageName, resId);
         }
 
         /**
@@ -869,8 +878,8 @@
          *            The filename of the sound resource. This must be a
          *            complete path like: (/sdcard/mysounds/mysoundbite.mp3).
          */
-        public void addEarconFile(String earcon, String filename) {
-            mSelf.addEarcon(earcon, filename);
+        public void addEarconFile(String callingApp, String earcon, String filename) {
+            mSelf.addEarcon(callingApp, earcon, filename);
         }
 
         /**
@@ -880,8 +889,8 @@
          * @param speechRate
          *            The speech rate that should be used
          */
-        public int setSpeechRate(int speechRate) {
-            return mSelf.setSpeechRate(speechRate);
+        public int setSpeechRate(String callingApp, int speechRate) {
+            return mSelf.setSpeechRate(callingApp, speechRate);
         }
 
         /**
@@ -891,8 +900,8 @@
          * @param pitch
          *            The pitch that should be used for the synthesized voice
          */
-        public int setPitch(int pitch) {
-            return mSelf.setPitch(pitch);
+        public int setPitch(String callingApp, int pitch) {
+            return mSelf.setPitch(callingApp, pitch);
         }
 
         /**
@@ -926,8 +935,8 @@
          * @param country  the three letter ISO country code.
          * @param variant  the variant code associated with the country and language pair.
          */
-        public int setLanguage(String lang, String country, String variant) {
-            return mSelf.setLanguage(lang, country, variant);
+        public int setLanguage(String callingApp, String lang, String country, String variant) {
+            return mSelf.setLanguage(callingApp, lang, country, variant);
         }
 
         /**
@@ -944,13 +953,13 @@
          *            be something like "/sdcard/myappsounds/mysound.wav".
          * @return A boolean that indicates if the synthesis succeeded
          */
-        public boolean synthesizeToFile(String text, String[] params,
+        public boolean synthesizeToFile(String callingApp, String text, String[] params,
                 String filename) {
             ArrayList<String> speakingParams = new ArrayList<String>();
             if (params != null) {
                 speakingParams = new ArrayList<String>(Arrays.asList(params));
             }
-            return mSelf.synthesizeToFile(text, speakingParams, filename);
+            return mSelf.synthesizeToFile(callingApp, text, speakingParams, filename);
         }
 
     };
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index e612a04e..55b7a30 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -142,28 +142,6 @@
     private final  WifiHandler mWifiHandler;
 
     /*
-     * Map used to keep track of hidden networks presence, which
-     * is needed to switch between active and passive scan modes.
-     * If there is at least one hidden network that is currently
-     * present (enabled), we want to do active scans instead of
-     * passive.
-     */
-    private final Map<Integer, Boolean> mIsHiddenNetworkPresent;
-    /*
-     * The number of currently present hidden networks. When this
-     * counter goes from 0 to 1 or from 1 to 0, we change the
-     * scan mode to active or passive respectively. Initially, we
-     * set the counter to 0 and we increment it every time we add
-     * a new present (enabled) hidden network.
-     */
-    private int mNumHiddenNetworkPresent;
-    /*
-     * Whether we change the scan mode is due to a hidden network
-     * (in this class, this is always the case)
-     */
-    private final static boolean SET_DUE_TO_A_HIDDEN_NETWORK = true;
-
-    /*
      * Cache of scan results objects (size is somewhat arbitrary)
      */
     private static final int SCAN_RESULT_CACHE_SIZE = 80;
@@ -194,12 +172,6 @@
         mWifiStateTracker = tracker;
         mBatteryStats = BatteryStatsService.getService();
         
-        /*
-         * Initialize the hidden-networks state
-         */
-        mIsHiddenNetworkPresent = new HashMap<Integer, Boolean>();
-        mNumHiddenNetworkPresent = 0;
-
         mScanResultCache = new LinkedHashMap<String, ScanResult>(
             SCAN_RESULT_CACHE_SIZE, 0.75f, true) {
                 /*
@@ -253,155 +225,6 @@
         setWifiEnabledBlocking(wifiEnabled, false, Process.myUid());
     }
 
-    /**
-     * Initializes the hidden networks state. Must be called when we
-     * enable Wi-Fi.
-     */
-    private synchronized void initializeHiddenNetworksState() {
-        // First, reset the state
-        resetHiddenNetworksState();
-
-        // ... then add networks that are marked as hidden
-        List<WifiConfiguration> networks = getConfiguredNetworks();
-        if (!networks.isEmpty()) {
-            for (WifiConfiguration config : networks) {
-                if (config != null && config.hiddenSSID) {
-                    addOrUpdateHiddenNetwork(
-                        config.networkId,
-                        config.status != WifiConfiguration.Status.DISABLED);
-                }
-            }
-
-        }
-    }
-
-    /**
-     * Resets the hidden networks state.
-     */
-    private synchronized void resetHiddenNetworksState() {
-        mNumHiddenNetworkPresent = 0;
-        mIsHiddenNetworkPresent.clear();
-    }
-
-    /**
-     * Marks all but netId network as not present.
-     */
-    private synchronized void markAllHiddenNetworksButOneAsNotPresent(int netId) {
-        for (Map.Entry<Integer, Boolean> entry : mIsHiddenNetworkPresent.entrySet()) {
-            if (entry != null) {
-                Integer networkId = entry.getKey();
-                if (networkId != netId) {
-                    updateNetworkIfHidden(
-                        networkId, false);
-                }
-            }
-        }
-    }
-
-    /**
-     * Updates the netId network presence status if netId is an existing
-     * hidden network.
-     */
-    private synchronized void updateNetworkIfHidden(int netId, boolean present) {
-        if (isHiddenNetwork(netId)) {
-            addOrUpdateHiddenNetwork(netId, present);
-        }
-    }
-
-    /**
-     * Updates the netId network presence status if netId is an existing
-     * hidden network. If the network does not exist, adds the network.
-     */
-    private synchronized void addOrUpdateHiddenNetwork(int netId, boolean present) {
-        if (0 <= netId) {
-
-            // If we are adding a new entry or modifying an existing one
-            Boolean isPresent = mIsHiddenNetworkPresent.get(netId);
-            if (isPresent == null || isPresent != present) {
-                if (present) {
-                    incrementHiddentNetworkPresentCounter();
-                } else {
-                    // If we add a new hidden network, no need to change
-                    // the counter (it must be 0)
-                    if (isPresent != null) {
-                        decrementHiddentNetworkPresentCounter();
-                    }
-                }
-                mIsHiddenNetworkPresent.put(netId, present);
-            }
-        } else {
-            Log.e(TAG, "addOrUpdateHiddenNetwork(): Invalid (negative) network id!");
-        }
-    }
-
-    /**
-     * Removes the netId network if it is hidden (being kept track of).
-     */
-    private synchronized void removeNetworkIfHidden(int netId) {
-        if (isHiddenNetwork(netId)) {
-            removeHiddenNetwork(netId);
-        }
-    }
-
-    /**
-     * Removes the netId network. For the call to be successful, the network
-     * must be hidden.
-     */
-    private synchronized void removeHiddenNetwork(int netId) {
-        if (0 <= netId) {
-            Boolean isPresent =
-                mIsHiddenNetworkPresent.remove(netId);
-            if (isPresent != null) {
-                // If we remove an existing hidden network that is not
-                // present, no need to change the counter
-                if (isPresent) {
-                    decrementHiddentNetworkPresentCounter();
-                }
-            } else {
-                if (DBG) {
-                    Log.d(TAG, "removeHiddenNetwork(): Removing a non-existent network!");
-                }
-            }
-        } else {
-            Log.e(TAG, "removeHiddenNetwork(): Invalid (negative) network id!");
-        }
-    }
-
-    /**
-     * Returns true if netId is an existing hidden network.
-     */
-    private synchronized boolean isHiddenNetwork(int netId) {
-        return mIsHiddenNetworkPresent.containsKey(netId);
-    }
-
-    /**
-     * Increments the present (enabled) hidden networks counter. If the
-     * counter value goes from 0 to 1, changes the scan mode to active.
-     */
-    private void incrementHiddentNetworkPresentCounter() {
-        ++mNumHiddenNetworkPresent;
-        if (1 == mNumHiddenNetworkPresent) {
-            // Switch the scan mode to "active"
-            mWifiStateTracker.setScanMode(true, SET_DUE_TO_A_HIDDEN_NETWORK);
-        }
-    }
-
-    /**
-     * Decrements the present (enabled) hidden networks counter. If the
-     * counter goes from 1 to 0, changes the scan mode back to passive.
-     */
-    private void decrementHiddentNetworkPresentCounter() {
-        if (0 < mNumHiddenNetworkPresent) {
-            --mNumHiddenNetworkPresent;
-            if (0 == mNumHiddenNetworkPresent) {
-                // Switch the scan mode to "passive"
-                mWifiStateTracker.setScanMode(false, SET_DUE_TO_A_HIDDEN_NETWORK);
-            }
-        } else {
-            Log.e(TAG, "Hidden-network counter invariant violation!");
-        }
-    }
-
     private boolean getPersistedWifiEnabled() {
         final ContentResolver cr = mContext.getContentResolver();
         try {
@@ -543,12 +366,10 @@
         setWifiEnabledState(eventualWifiState, uid);
 
         /*
-         * Initialize the hidden networks state and the number of allowed
-         * radio channels if Wi-Fi is being turned on.
+         * Initialize the number of allowed radio channels if Wi-Fi is being turned on.
          */
         if (enable) {
             mWifiStateTracker.setNumAllowedChannels();
-            initializeHiddenNetworksState();
         }
 
         return true;
@@ -883,15 +704,6 @@
         }
         mNeedReconfig = mNeedReconfig || doReconfig;
 
-        /*
-         * If we have hidden networks, we may have to change the scan mode
-         */
-        if (config.hiddenSSID) {
-            // Mark the network as present unless it is disabled
-            addOrUpdateHiddenNetwork(
-                netId, config.status != WifiConfiguration.Status.DISABLED);
-        }
-
         setVariables: {
             /*
              * Note that if a networkId for a non-existent network
@@ -1219,11 +1031,6 @@
     public boolean removeNetwork(int netId) {
         enforceChangePermission();
 
-        /*
-         * If we have hidden networks, we may have to change the scan mode
-         */
-        removeNetworkIfHidden(netId);
-
         return mWifiStateTracker.removeNetwork(netId);
     }
 
@@ -1237,16 +1044,6 @@
     public boolean enableNetwork(int netId, boolean disableOthers) {
         enforceChangePermission();
 
-        /*
-         * If we have hidden networks, we may have to change the scan mode
-         */
-         synchronized(this) {
-             if (disableOthers) {
-                 markAllHiddenNetworksButOneAsNotPresent(netId);
-             }
-             updateNetworkIfHidden(netId, true);
-         }
-
         synchronized (mWifiStateTracker) {
             return WifiNative.enableNetworkCommand(netId, disableOthers);
         }
@@ -1261,11 +1058,6 @@
     public boolean disableNetwork(int netId) {
         enforceChangePermission();
 
-        /*
-         * If we have hidden networks, we may have to change the scan mode
-         */
-        updateNetworkIfHidden(netId, false);
-
         synchronized (mWifiStateTracker) {
             return WifiNative.disableNetworkCommand(netId);
         }
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java
index afbb19b..0e2eb38 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -242,7 +242,6 @@
     private SettingsObserver mSettingsObserver;
     
     private boolean mIsScanModeActive;
-    private boolean mIsScanModeSetDueToAHiddenNetwork;
 
     // Wi-Fi run states:
     private static final int RUN_STATE_STARTING = 1;
@@ -314,7 +313,6 @@
         mScanResults = new ArrayList<ScanResult>();
         // Allocate DHCP info object once, and fill it in on each request
         mDhcpInfo = new DhcpInfo();
-        mIsScanModeSetDueToAHiddenNetwork = false;
         mRunState = RUN_STATE_STARTING;
 
         // Setting is in seconds
@@ -1019,12 +1017,7 @@
                  * On receiving the first scan results after connecting to
                  * the supplicant, switch scan mode over to passive.
                  */
-                if (!mIsScanModeSetDueToAHiddenNetwork) {
-                    // This is the only place at the moment where we set
-                    // the scan mode NOT due to a hidden network. This is
-                    // what the second parameter value (false) stands for.
-                    setScanMode(false, false);
-                }
+                setScanMode(false);
                 break;
 
             case EVENT_POLL_INTERVAL:
@@ -1162,9 +1155,7 @@
         return disabledNetwork;
     }
 
-    public synchronized void setScanMode(
-        boolean isScanModeActive, boolean setDueToAHiddenNetwork) {
-        mIsScanModeSetDueToAHiddenNetwork = setDueToAHiddenNetwork;
+    public synchronized void setScanMode(boolean isScanModeActive) {
         if (mIsScanModeActive != isScanModeActive) {
             WifiNative.setScanModeCommand(mIsScanModeActive = isScanModeActive);
         }