Merge "optional flag to enable tracker debugging"
diff --git a/camera/libcameraservice/CameraService.cpp b/camera/libcameraservice/CameraService.cpp
index 9980c9d..fae1f26 100644
--- a/camera/libcameraservice/CameraService.cpp
+++ b/camera/libcameraservice/CameraService.cpp
@@ -16,7 +16,6 @@
 ** limitations under the License.
 */
 
-//#define LOG_NDEBUG 0
 #define LOG_TAG "CameraService"
 #include <utils/Log.h>
 
@@ -95,7 +94,7 @@
 sp<ICamera> CameraService::connect(const sp<ICameraClient>& cameraClient)
 {
     int callingPid = getCallingPid();
-    LOGD("CameraService::connect E (pid %d, client %p)", callingPid,
+    LOGV("CameraService::connect E (pid %d, client %p)", callingPid,
             cameraClient->asBinder().get());
 
     Mutex::Autolock lock(mServiceLock);
@@ -106,30 +105,30 @@
             sp<ICameraClient> currentCameraClient(currentClient->getCameraClient());
             if (cameraClient->asBinder() == currentCameraClient->asBinder()) {
                 // This is the same client reconnecting...
-                LOGD("CameraService::connect X (pid %d, same client %p) is reconnecting...",
+                LOGV("CameraService::connect X (pid %d, same client %p) is reconnecting...",
                     callingPid, cameraClient->asBinder().get());
                 return currentClient;
             } else {
                 // It's another client... reject it
-                LOGD("CameraService::connect X (pid %d, new client %p) rejected. "
+                LOGV("CameraService::connect X (pid %d, new client %p) rejected. "
                     "(old pid %d, old client %p)",
                     callingPid, cameraClient->asBinder().get(),
                     currentClient->mClientPid, currentCameraClient->asBinder().get());
                 if (kill(currentClient->mClientPid, 0) == -1 && errno == ESRCH) {
-                    LOGD("The old client is dead!");
+                    LOGV("The old client is dead!");
                 }
                 return client;
             }
         } else {
             // can't promote, the previous client has died...
-            LOGD("New client (pid %d) connecting, old reference was dangling...",
+            LOGV("New client (pid %d) connecting, old reference was dangling...",
                     callingPid);
             mClient.clear();
         }
     }
 
     if (mUsers > 0) {
-        LOGD("Still have client, rejected");
+        LOGV("Still have client, rejected");
         return client;
     }
 
@@ -141,7 +140,7 @@
     // the refcount.
     client->trackMe(true, true);
 #endif
-    LOGD("CameraService::connect X");
+    LOGV("CameraService::connect X");
     return client;
 }
 
@@ -157,7 +156,7 @@
 
     if (mClient == 0) {
         // This happens when we have already disconnected.
-        LOGD("removeClient (pid %d): already disconnected", callingPid);
+        LOGV("removeClient (pid %d): already disconnected", callingPid);
         return;
     }
 
@@ -165,7 +164,7 @@
     // Client::~Client() -> disconnect() -> removeClient().
     client = mClient.promote();
     if (client == 0) {
-        LOGD("removeClient (pid %d): no more strong reference", callingPid);
+        LOGV("removeClient (pid %d): no more strong reference", callingPid);
         mClient.clear();
         return;
     }
@@ -178,7 +177,7 @@
         mClient.clear();
     }
 
-    LOGD("removeClient (pid %d) done", callingPid);
+    LOGV("removeClient (pid %d) done", callingPid);
 }
 
 // The reason we need this count is a new CameraService::connect() request may
@@ -212,7 +211,7 @@
         const sp<ICameraClient>& cameraClient, pid_t clientPid)
 {
     int callingPid = getCallingPid();
-    LOGD("Client::Client E (pid %d)", callingPid);
+    LOGV("Client::Client E (pid %d)", callingPid);
     mCameraService = cameraService;
     mCameraClient = cameraClient;
     mClientPid = clientPid;
@@ -237,7 +236,7 @@
     // Callback is disabled by default
     mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
     cameraService->incUsers();
-    LOGD("Client::Client X (pid %d)", callingPid);
+    LOGV("Client::Client X (pid %d)", callingPid);
 }
 
 status_t CameraService::Client::checkPid()
@@ -253,7 +252,7 @@
 status_t CameraService::Client::lock()
 {
     int callingPid = getCallingPid();
-    LOGD("lock from pid %d (mClientPid %d)", callingPid, mClientPid);
+    LOGV("lock from pid %d (mClientPid %d)", callingPid, mClientPid);
     Mutex::Autolock _l(mLock);
     // lock camera to this client if the the camera is unlocked
     if (mClientPid == 0) {
@@ -267,13 +266,13 @@
 status_t CameraService::Client::unlock()
 {
     int callingPid = getCallingPid();
-    LOGD("unlock from pid %d (mClientPid %d)", callingPid, mClientPid);
+    LOGV("unlock from pid %d (mClientPid %d)", callingPid, mClientPid);
     Mutex::Autolock _l(mLock);
     // allow anyone to use camera
     status_t result = checkPid();
     if (result == NO_ERROR) {
         mClientPid = 0;
-        LOGD("clear mCameraClient (pid %d)", callingPid);
+        LOGV("clear mCameraClient (pid %d)", callingPid);
         // we need to remove the reference so that when app goes
         // away, the reference count goes to 0.
         mCameraClient.clear();
@@ -286,7 +285,7 @@
     int callingPid = getCallingPid();
 
     // connect a new process to the camera
-    LOGD("Client::connect E (pid %d, client %p)", callingPid, client->asBinder().get());
+    LOGV("Client::connect E (pid %d, client %p)", callingPid, client->asBinder().get());
 
     // I hate this hack, but things get really ugly when the media recorder
     // service is handing back the camera to the app. The ICameraClient
@@ -310,14 +309,14 @@
 
             // did the client actually change?
             if ((mCameraClient != NULL) && (client->asBinder() == mCameraClient->asBinder())) {
-                LOGD("Connect to the same client");
+                LOGV("Connect to the same client");
                 return NO_ERROR;
             }
 
             mCameraClient = client;
             mClientPid = -1;
             mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
-            LOGD("Connect to the new client (pid %d, client %p)",
+            LOGV("Connect to the new client (pid %d, client %p)",
                 callingPid, mCameraClient->asBinder().get());
         }
 
@@ -344,7 +343,7 @@
     int callingPid = getCallingPid();
 
     // tear down client
-    LOGD("Client::~Client E (pid %d, client %p)",
+    LOGV("Client::~Client E (pid %d, client %p)",
             callingPid, getCameraClient()->asBinder().get());
     if (mSurface != 0 && !mUseOverlay) {
 #if HAVE_ANDROID_OS
@@ -373,23 +372,23 @@
     // make sure we tear down the hardware
     mClientPid = callingPid;
     disconnect();
-    LOGD("Client::~Client X (pid %d)", mClientPid);
+    LOGV("Client::~Client X (pid %d)", mClientPid);
 }
 
 void CameraService::Client::disconnect()
 {
     int callingPid = getCallingPid();
 
-    LOGD("Client::disconnect() E (pid %d client %p)",
+    LOGV("Client::disconnect() E (pid %d client %p)",
             callingPid, getCameraClient()->asBinder().get());
 
     Mutex::Autolock lock(mLock);
     if (mClientPid <= 0) {
-        LOGD("camera is unlocked (mClientPid = %d), don't tear down hardware", mClientPid);
+        LOGV("camera is unlocked (mClientPid = %d), don't tear down hardware", mClientPid);
         return;
     }
     if (checkPid() != NO_ERROR) {
-        LOGD("Different client - don't disconnect");
+        LOGV("Different client - don't disconnect");
         return;
     }
 
@@ -397,7 +396,7 @@
     // from the user directly, or called by the destructor.
     if (mHardware == 0) return;
 
-    LOGD("hardware teardown");
+    LOGV("hardware teardown");
     // Before destroying mHardware, we must make sure it's in the
     // idle state.
     mHardware->stopPreview();
@@ -421,7 +420,7 @@
     mCameraService->removeClient(mCameraClient);
     mCameraService->decUsers();
 
-    LOGD("Client::disconnect() X (pid %d)", callingPid);
+    LOGV("Client::disconnect() X (pid %d)", callingPid);
 }
 
 // pass the buffered ISurface to the camera service
@@ -805,14 +804,14 @@
     int nw, cnt = 0;
     uint32_t written = 0;
 
-    LOGD("opening file [%s]\n", fname);
+    LOGV("opening file [%s]\n", fname);
     int fd = open(fname, O_RDWR | O_CREAT);
     if (fd < 0) {
         LOGE("failed to create file [%s]: %s", fname, strerror(errno));
         return;
     }
 
-    LOGD("writing %d bytes to file [%s]\n", size, fname);
+    LOGV("writing %d bytes to file [%s]\n", size, fname);
     while (written < size) {
         nw = ::write(fd,
                      buf + written,
@@ -825,7 +824,7 @@
         written += nw;
         cnt++;
     }
-    LOGD("done writing %d bytes to file [%s] in %d passes\n",
+    LOGV("done writing %d bytes to file [%s] in %d passes\n",
          size, fname, cnt);
     ::close(fd);
 }
@@ -1189,7 +1188,7 @@
 // set preview/capture parameters - key/value pairs
 status_t CameraService::Client::setParameters(const String8& params)
 {
-    LOGD("setParameters(%s)", params.string());
+    LOGV("setParameters(%s)", params.string());
 
     Mutex::Autolock lock(mLock);
     status_t result = checkPid();
@@ -1215,7 +1214,7 @@
     }
 
     String8 params(mHardware->getParameters().flatten());
-    LOGD("getParameters(%s)", params.string());
+    LOGV("getParameters(%s)", params.string());
     return params;
 }
 
@@ -1327,7 +1326,7 @@
     status_t err = BnCameraService::onTransact(code, data, reply, flags);
 
 #if DEBUG_HEAP_LEAKS
-    LOGD("+++ onTransact err %d code %d", err, code);
+    LOGV("+++ onTransact err %d code %d", err, code);
 
     if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) {
         // the 'service' command interrogates this binder for its name, and then supplies it
@@ -1335,7 +1334,7 @@
         // ISurfaceComposer (since we delegated the INTERFACE_TRANSACTION handling to
         // BnSurfaceComposer before falling through to this code).
 
-        LOGD("+++ onTransact code %d", code);
+        LOGV("+++ onTransact code %d", code);
 
         CHECK_INTERFACE(ICameraService, data, reply);
 
@@ -1345,13 +1344,13 @@
             if (gWeakHeap != 0) {
                 sp<IMemoryHeap> h = gWeakHeap.promote();
                 IMemoryHeap *p = gWeakHeap.unsafe_get();
-                LOGD("CHECKING WEAK REFERENCE %p (%p)", h.get(), p);
+                LOGV("CHECKING WEAK REFERENCE %p (%p)", h.get(), p);
                 if (h != 0)
                     h->printRefs();
                 bool attempt_to_delete = data.readInt32() == 1;
                 if (attempt_to_delete) {
                     // NOT SAFE!
-                    LOGD("DELETING WEAK REFERENCE %p (%p)", h.get(), p);
+                    LOGV("DELETING WEAK REFERENCE %p (%p)", h.get(), p);
                     if (p) delete p;
                 }
                 return NO_ERROR;
diff --git a/cmds/dumpstate/dumpstate.c b/cmds/dumpstate/dumpstate.c
index 236c0fe..a2b5d8d 100644
--- a/cmds/dumpstate/dumpstate.c
+++ b/cmds/dumpstate/dumpstate.c
@@ -28,7 +28,7 @@
 #include <cutils/sockets.h>
 #include "private/android_filesystem_config.h"
 
-#define LOG_NDEBUG 0
+
 #define LOG_TAG "dumpstate"
 #include <utils/Log.h>
 
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index 6e7e6d7f..eb2d7b1 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -88,11 +88,11 @@
      * <code>content://com.company.provider.imap/inbox/1</code> for a particular
      * message in the inbox, whose MIME type would be reported as
      * <code>CURSOR_ITEM_BASE_TYPE + "/vnd.company.imap-msg"</code>
-     * 
+     *
      * <p>Compare with {@link #CURSOR_DIR_BASE_TYPE}.
      */
     public static final String CURSOR_ITEM_BASE_TYPE = "vnd.android.cursor.item";
-    
+
     /**
      * This is the Android platform's base MIME type for a content: URI
      * containing a Cursor of zero or more items.  Applications should use this
@@ -102,7 +102,7 @@
      * <code>content://com.company.provider.imap/inbox</code> for all of the
      * messages in its inbox, whose MIME type would be reported as
      * <code>CURSOR_DIR_BASE_TYPE + "/vnd.company.imap-msg"</code>
-     * 
+     *
      * <p>Note how the base MIME type varies between this and
      * {@link #CURSOR_ITEM_BASE_TYPE} depending on whether there is
      * one single item or multiple items in the data set, while the sub-type
@@ -173,13 +173,25 @@
     }
 
     /**
+     * <p>
      * Query the given URI, returning a {@link Cursor} over the result set.
+     * </p>
+     * <p>
+     * For best performance, the caller should follow these guidelines:
+     * <ul>
+     * <li>Provide an explicit projection, to prevent
+     * reading data from storage that aren't going to be used.</li>
+     * <li>Use question mark parameter markers such as 'phone=?' instead of
+     * explicit values in the {@code selection} parameter, so that queries
+     * that differ only by those values will be recognized as the same
+     * for caching purposes.</li>
+     * </ul>
+     * </p>
      *
      * @param uri The URI, using the content:// scheme, for the content to
      *         retrieve.
      * @param projection A list of which columns to return. Passing null will
-     *         return all columns, which is discouraged to prevent reading data
-     *         from storage that isn't going to be used.
+     *         return all columns, which is inefficient.
      * @param selection A filter declaring which rows to return, formatted as an
      *         SQL WHERE clause (excluding the WHERE itself). Passing null will
      *         return all rows for the given URI.
@@ -225,10 +237,10 @@
      * <li>android.resource ({@link #SCHEME_ANDROID_RESOURCE})</li>
      * <li>file ({@link #SCHEME_FILE})</li>
      * </ul>
-     * 
+     *
      * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information
      * on these schemes.
-     * 
+     *
      * @param uri The desired URI.
      * @return InputStream
      * @throws FileNotFoundException if the provided URI could not be opened.
@@ -283,7 +295,7 @@
      *
      * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information
      * on these schemes.
-     * 
+     *
      * @param uri The desired URI.
      * @param mode May be "w", "wa", "rw", or "rwt".
      * @return OutputStream
@@ -318,7 +330,7 @@
      *
      * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information
      * on these schemes.
-     * 
+     *
      * @param uri The desired URI to open.
      * @param mode The file mode to use, as per {@link ContentProvider#openFile
      * ContentProvider.openFile}.
@@ -334,19 +346,19 @@
         if (afd == null) {
             return null;
         }
-        
+
         if (afd.getDeclaredLength() < 0) {
             // This is a full file!
             return afd.getParcelFileDescriptor();
         }
-        
+
         // Client can't handle a sub-section of a file, so close what
         // we got and bail with an exception.
         try {
             afd.close();
         } catch (IOException e) {
         }
-        
+
         throw new FileNotFoundException("Not a whole file");
     }
 
@@ -491,7 +503,7 @@
         res.id = id;
         return res;
     }
-    
+
     /** @hide */
     static public int modeToMode(Uri uri, String mode) throws FileNotFoundException {
         int modeBits;
@@ -518,7 +530,7 @@
         }
         return modeBits;
     }
-    
+
     /**
      * Inserts a row into a table at the given URL.
      *
@@ -1146,7 +1158,7 @@
 
     /** @hide */
     public static final String CONTENT_SERVICE_NAME = "content";
-    
+
     /** @hide */
     public static IContentService getContentService() {
         if (sContentService != null) {
@@ -1158,7 +1170,7 @@
         if (Config.LOGV) Log.v("ContentService", "default service = " + sContentService);
         return sContentService;
     }
-    
+
     private static IContentService sContentService;
     private final Context mContext;
     private static final String TAG = "ContentResolver";
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java
index 01c67cf..0c6bb1a 100644
--- a/core/java/android/hardware/SensorManager.java
+++ b/core/java/android/hardware/SensorManager.java
@@ -545,8 +545,8 @@
                     i = sensors_module_get_next_sensor(sensor, i);
 
                     if (i>=0) {
-                        Log.d(TAG, "found sensor: " + sensor.getName() +
-                                ", handle=" + sensor.getHandle());
+                        //Log.d(TAG, "found sensor: " + sensor.getName() +
+                        //        ", handle=" + sensor.getHandle());
                         sensor.setLegacyType(getLegacySensorType(sensor.getType()));
                         fullList.add(sensor);
                         sHandleToSensor.append(sensor.getHandle(), sensor);
diff --git a/core/jni/android_hardware_Camera.cpp b/core/jni/android_hardware_Camera.cpp
index 11463a2..64ee4f0 100644
--- a/core/jni/android_hardware_Camera.cpp
+++ b/core/jni/android_hardware_Camera.cpp
@@ -328,7 +328,7 @@
 static void android_hardware_Camera_release(JNIEnv *env, jobject thiz)
 {
     // TODO: Change to LOGV
-    LOGD("release camera");
+    LOGV("release camera");
     JNICameraContext* context = NULL;
     sp<Camera> camera;
     {
@@ -526,7 +526,7 @@
 
 static void android_hardware_Camera_startSmoothZoom(JNIEnv *env, jobject thiz, jint value)
 {
-    LOGD("startSmoothZoom");
+    LOGV("startSmoothZoom");
     sp<Camera> camera = get_native_camera(env, thiz, NULL);
     if (camera == 0) return;
 
@@ -537,7 +537,7 @@
 
 static void android_hardware_Camera_stopSmoothZoom(JNIEnv *env, jobject thiz)
 {
-    LOGD("stopSmoothZoom");
+    LOGV("stopSmoothZoom");
     sp<Camera> camera = get_native_camera(env, thiz, NULL);
     if (camera == 0) return;
 
diff --git a/core/jni/android_hardware_SensorManager.cpp b/core/jni/android_hardware_SensorManager.cpp
index 3e27978..9a90b72 100644
--- a/core/jni/android_hardware_SensorManager.cpp
+++ b/core/jni/android_hardware_SensorManager.cpp
@@ -16,7 +16,6 @@
 
 #define LOG_TAG "SensorManager"
 
-#define LOG_NDEBUG 0
 #include "utils/Log.h"
 
 #include <hardware/sensors.h>
diff --git a/libs/rs/rsUtils.h b/libs/rs/rsUtils.h
index 07f8933..3c6da68 100644
--- a/libs/rs/rsUtils.h
+++ b/libs/rs/rsUtils.h
@@ -17,7 +17,6 @@
 #ifndef ANDROID_RS_UTILS_H
 #define ANDROID_RS_UTILS_H
 
-#define LOG_NDEBUG 0
 #define LOG_TAG "RenderScript"
 #include <utils/Log.h>
 #include <utils/Vector.h>
diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java
index 5c0b7a5..74af9b6 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -23,7 +23,6 @@
 import android.os.RemoteException;
 import android.os.Handler;
 import android.os.Message;
-import android.util.Config;
 import android.util.Log;
 
 import com.android.internal.location.DummyLocationProvider;
@@ -248,7 +247,7 @@
      * factory Context.getSystemService.
      */
     public LocationManager(ILocationManager service) {
-        if (Config.LOGD) {
+        if (false) {
             Log.d(TAG, "Constructor: service = " + service);
         }
         mService = service;
@@ -277,7 +276,7 @@
      * @return list of Strings containing names of the providers
      */
     public List<String> getAllProviders() {
-        if (Config.LOGD) {
+        if (false) {
             Log.d(TAG, "getAllProviders");
         }
         try {
@@ -829,7 +828,7 @@
         if (listener == null) {
             throw new IllegalArgumentException("listener==null");
         }
-        if (Config.LOGD) {
+        if (false) {
             Log.d(TAG, "removeUpdates: listener = " + listener);
         }
         try {
@@ -854,7 +853,7 @@
         if (intent == null) {
             throw new IllegalArgumentException("intent==null");
         }
-        if (Config.LOGD) {
+        if (false) {
             Log.d(TAG, "removeUpdates: intent = " + intent);
         }
         try {
@@ -909,7 +908,7 @@
      */
     public void addProximityAlert(double latitude, double longitude,
         float radius, long expiration, PendingIntent intent) {
-        if (Config.LOGD) {
+        if (false) {
             Log.d(TAG, "addProximityAlert: latitude = " + latitude +
                 ", longitude = " + longitude + ", radius = " + radius +
                 ", expiration = " + expiration +
@@ -930,7 +929,7 @@
      * proximity alerts
      */
     public void removeProximityAlert(PendingIntent intent) {
-        if (Config.LOGD) {
+        if (false) {
             Log.d(TAG, "removeProximityAlert: intent = " + intent);
         }
         try {
diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java
index 7763549..ee56621 100755
--- a/location/java/com/android/internal/location/GpsLocationProvider.java
+++ b/location/java/com/android/internal/location/GpsLocationProvider.java
@@ -41,7 +41,6 @@
 import android.os.ServiceManager;
 import android.os.SystemClock;
 import android.provider.Settings;
-import android.util.Config;
 import android.util.Log;
 import android.util.SparseIntArray;
 
@@ -69,7 +68,7 @@
 
     private static final String TAG = "GpsLocationProvider";
 
-    private static final boolean DEBUG = true;
+    private static final boolean DEBUG = false;
     private static final boolean VERBOSE = false;
     
     /**
@@ -377,7 +376,7 @@
     public void updateNetworkState(int state, NetworkInfo info) {
         mNetworkAvailable = (state == LocationProvider.AVAILABLE);
 
-        if (Config.LOGD) {
+        if (DEBUG) {
             Log.d(TAG, "updateNetworkState " + (mNetworkAvailable ? "available" : "unavailable")
                 + " info: " + info);
         }
@@ -498,7 +497,7 @@
      * when the provider is enabled.
      */
     public synchronized void enable() {
-        if (Config.LOGD) Log.d(TAG, "enable");
+        if (DEBUG) Log.d(TAG, "enable");
         if (mEnabled) return;
         mEnabled = native_init();
 
@@ -534,7 +533,7 @@
      * down while the provider is disabled.
      */
     public synchronized void disable() {
-        if (Config.LOGD) Log.d(TAG, "disable");
+        if (DEBUG) Log.d(TAG, "disable");
         if (!mEnabled) return;
 
         mEnabled = false;
@@ -602,7 +601,7 @@
     }
 
     public void setMinTime(long minTime) {
-        if (Config.LOGD) Log.d(TAG, "setMinTime " + minTime);
+        if (DEBUG) Log.d(TAG, "setMinTime " + minTime);
         
         if (minTime >= 0) {
             int interval = (int)(minTime/1000);
@@ -623,7 +622,7 @@
         }
         
         public void binderDied() {
-            if (Config.LOGD) Log.d(TAG, "GPS status listener died");
+            if (DEBUG) Log.d(TAG, "GPS status listener died");
 
             synchronized(mListeners) {
                 mListeners.remove(this);
@@ -721,7 +720,7 @@
     }
 
     private boolean forceTimeInjection() {
-        if (Config.LOGD) Log.d(TAG, "forceTimeInjection");
+        if (DEBUG) Log.d(TAG, "forceTimeInjection");
         if (mNetworkThread != null) {
             mNetworkThread.timeInjectRequest();
             return true;
@@ -797,7 +796,7 @@
         // report time to first fix
         if (mTTFF == 0 && (flags & LOCATION_HAS_LAT_LONG) == LOCATION_HAS_LAT_LONG) {
             mTTFF = (int)(mLastFixTime - mFixRequestTime);
-            if (Config.LOGD) Log.d(TAG, "TTFF: " + mTTFF);
+            if (DEBUG) Log.d(TAG, "TTFF: " + mTTFF);
 
             // notify status listeners
             synchronized(mListeners) {
@@ -1046,7 +1045,7 @@
     }
 
     private void xtraDownloadRequest() {
-        if (Config.LOGD) Log.d(TAG, "xtraDownloadRequest");
+        if (DEBUG) Log.d(TAG, "xtraDownloadRequest");
         if (mNetworkThread != null) {
             mNetworkThread.xtraDownloadRequest();
         }
@@ -1063,7 +1062,7 @@
     		
     		StringBuilder extrasBuf = new StringBuilder();
 
-    		if (Config.LOGD) Log.d(TAG, "sendNiResponse, notifId: " + notificationId +
+    		if (DEBUG) Log.d(TAG, "sendNiResponse, notifId: " + notificationId +
     				", response: " + userResponse);
     		
     		native_send_ni_response(notificationId, userResponse);
@@ -1149,14 +1148,14 @@
         }
 
         public void run() {
-            if (Config.LOGD) Log.d(TAG, "GpsEventThread starting");
+            if (DEBUG) Log.d(TAG, "GpsEventThread starting");
             // Exit as soon as disable() is called instead of waiting for the GPS to stop.
             while (mEnabled) {
                 // this will wait for an event from the GPS,
                 // which will be reported via reportLocation or reportStatus
                 native_wait_for_event();
             }
-            if (Config.LOGD) Log.d(TAG, "GpsEventThread exiting");
+            if (DEBUG) Log.d(TAG, "GpsEventThread exiting");
         }
     }
 
@@ -1181,7 +1180,7 @@
         }
 
         public void runLocked() {
-            if (Config.LOGD) Log.d(TAG, "NetworkThread starting");
+            if (DEBUG) Log.d(TAG, "NetworkThread starting");
             
             SntpClient client = new SntpClient();
             GpsXtraDownloader xtraDownloader = null;
@@ -1197,18 +1196,17 @@
                     synchronized (this) {
                         try {
                             if (!mNetworkAvailable) {
-                                if (Config.LOGD) Log.d(TAG, 
-                                        "NetworkThread wait for network");
+                                if (DEBUG) Log.d(TAG, "NetworkThread wait for network");
                                 wait();
                             } else if (waitTime > 0) {
-                                if (Config.LOGD) {
+                                if (DEBUG) {
                                     Log.d(TAG, "NetworkThread wait for " +
                                             waitTime + "ms");
                                 }
                                 wait(waitTime);
                             }
                         } catch (InterruptedException e) {
-                            if (Config.LOGD) {
+                            if (DEBUG) {
                                 Log.d(TAG, "InterruptedException in GpsNetworkThread");
                             }
                         }
@@ -1217,12 +1215,11 @@
                 } while (!mDone && ((!mXtraDownloadRequested &&
                         !mTimeInjectRequested && waitTime > 0)
                         || !mNetworkAvailable));
-                if (Config.LOGD) Log.d(TAG, "NetworkThread out of wake loop");
-                
+                if (DEBUG) Log.d(TAG, "NetworkThread out of wake loop"); 
                 if (!mDone) {
                     if (mNtpServer != null && 
                             (mTimeInjectRequested || mNextNtpTime <= System.currentTimeMillis())) {
-                        if (Config.LOGD) {
+                        if (DEBUG) {
                             Log.d(TAG, "Requesting time from NTP server " + mNtpServer);
                         }
                         mTimeInjectRequested = false;
@@ -1231,14 +1228,14 @@
                             long timeReference = client.getNtpTimeReference();
                             int certainty = (int)(client.getRoundTripTime()/2);
         
-                            if (Config.LOGD) Log.d(TAG, "calling native_inject_time: " + 
+                            if (DEBUG) Log.d(TAG, "calling native_inject_time: " + 
                                     time + " reference: " + timeReference 
                                     + " certainty: " + certainty);
         
                             native_inject_time(time, timeReference, certainty);
                             mNextNtpTime = System.currentTimeMillis() + NTP_INTERVAL;
                         } else {
-                            if (Config.LOGD) Log.d(TAG, "requestTime failed");
+                            if (DEBUG) Log.d(TAG, "requestTime failed");
                             mNextNtpTime = System.currentTimeMillis() + RETRY_INTERVAL;
                         }
                     }
@@ -1249,7 +1246,7 @@
                         mXtraDownloadRequested = false;
                         byte[] data = xtraDownloader.downloadXtraData();
                         if (data != null) {
-                            if (Config.LOGD) {
+                            if (DEBUG) {
                                 Log.d(TAG, "calling native_inject_xtra_data");
                             }
                             native_inject_xtra_data(data, data.length);
@@ -1260,7 +1257,7 @@
                     }
                 }
             }
-            if (Config.LOGD) Log.d(TAG, "NetworkThread exiting");
+            if (DEBUG) Log.d(TAG, "NetworkThread exiting");
         }
         
         synchronized void xtraDownloadRequest() {
@@ -1278,7 +1275,7 @@
         }
 
         synchronized void setDone() {
-            if (Config.LOGD) Log.d(TAG, "stopping NetworkThread");
+            if (DEBUG) Log.d(TAG, "stopping NetworkThread");
             mDone = true;
             notify();
         }
diff --git a/packages/TtsService/jni/android_tts_SynthProxy.cpp b/packages/TtsService/jni/android_tts_SynthProxy.cpp
index 0ec8dab..17ece04 100644
--- a/packages/TtsService/jni/android_tts_SynthProxy.cpp
+++ b/packages/TtsService/jni/android_tts_SynthProxy.cpp
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#define LOG_NDEBUG 0
 
 #include <stdio.h>
 #include <unistd.h>
diff --git a/services/java/com/android/server/MountListener.java b/services/java/com/android/server/MountListener.java
index 5eea335..f35556d 100644
--- a/services/java/com/android/server/MountListener.java
+++ b/services/java/com/android/server/MountListener.java
@@ -364,7 +364,7 @@
         for (String line : rsp) {
             String []tok = line.split(" ");
             int code = Integer.parseInt(tok[0]);
-            if (code == ResponseCode.AsecPathResult) {
+            if (code == ResponseCode.AsecListResult) {
                 rdata[idx++] = tok[1];
             } else if (code == ResponseCode.CommandOkay) {
                 return rdata;
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 6fab96b..de3dcb0 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -333,16 +333,18 @@
         setWifiEnabledState(enable ? WIFI_STATE_ENABLING : WIFI_STATE_DISABLING, uid);
 
         if (enable) {
-            if (!WifiNative.loadDriver()) {
-                Log.e(TAG, "Failed to load Wi-Fi driver.");
-                setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
-                return false;
-            }
-            if (!WifiNative.startSupplicant()) {
-                WifiNative.unloadDriver();
-                Log.e(TAG, "Failed to start supplicant daemon.");
-                setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
-                return false;
+            synchronized (mWifiStateTracker) {
+                if (!WifiNative.loadDriver()) {
+                    Log.e(TAG, "Failed to load Wi-Fi driver.");
+                    setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
+                    return false;
+                }
+                if (!WifiNative.startSupplicant()) {
+                    WifiNative.unloadDriver();
+                    Log.e(TAG, "Failed to start supplicant daemon.");
+                    setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
+                    return false;
+                }
             }
             registerForBroadcasts();
             mWifiStateTracker.startEventLoop();
@@ -353,21 +355,23 @@
             mWifiStateTracker.setNotificationVisible(false, 0, false, 0);
 
             boolean failedToStopSupplicantOrUnloadDriver = false;
-            if (!WifiNative.stopSupplicant()) {
-                Log.e(TAG, "Failed to stop supplicant daemon.");
-                setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
-                failedToStopSupplicantOrUnloadDriver = true;
-            }
-
-            // We must reset the interface before we unload the driver
-            mWifiStateTracker.resetInterface(false);
-
-            if (!WifiNative.unloadDriver()) {
-                Log.e(TAG, "Failed to unload Wi-Fi driver.");
-                if (!failedToStopSupplicantOrUnloadDriver) {
+            synchronized (mWifiStateTracker) {
+                if (!WifiNative.stopSupplicant()) {
+                    Log.e(TAG, "Failed to stop supplicant daemon.");
                     setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
                     failedToStopSupplicantOrUnloadDriver = true;
                 }
+
+                // We must reset the interface before we unload the driver
+                mWifiStateTracker.resetInterface(false);
+
+                if (!WifiNative.unloadDriver()) {
+                    Log.e(TAG, "Failed to unload Wi-Fi driver.");
+                    if (!failedToStopSupplicantOrUnloadDriver) {
+                        setWifiEnabledState(WIFI_STATE_UNKNOWN, uid);
+                        failedToStopSupplicantOrUnloadDriver = true;
+                    }
+                }
             }
             if (failedToStopSupplicantOrUnloadDriver) {
                 return false;
@@ -380,7 +384,6 @@
             persistWifiEnabled(enable);
         }
         setWifiEnabledState(eventualWifiState, uid);
-
         return true;
     }
 
@@ -698,7 +701,7 @@
      * @return the supplicant-assigned identifier for the new or updated
      * network if the operation succeeds, or {@code -1} if it fails
      */
-    public synchronized int addOrUpdateNetwork(WifiConfiguration config) {
+    public int addOrUpdateNetwork(WifiConfiguration config) {
         enforceChangePermission();
         /*
          * If the supplied networkId is -1, we create a new empty
@@ -710,41 +713,41 @@
         boolean doReconfig;
         int currentPriority;
         // networkId of -1 means we want to create a new network
-        if (newNetwork) {
-            netId = WifiNative.addNetworkCommand();
-            if (netId < 0) {
-                if (DBG) {
-                    Log.d(TAG, "Failed to add a network!");
+        synchronized (mWifiStateTracker) {
+            if (newNetwork) {
+                netId = WifiNative.addNetworkCommand();
+                if (netId < 0) {
+                    if (DBG) {
+                        Log.d(TAG, "Failed to add a network!");
+                    }
+                    return -1;
                 }
-                return -1;
-            }
-            doReconfig = true;
-        } else {
-            String priorityVal = WifiNative.getNetworkVariableCommand(netId, WifiConfiguration.priorityVarName);
-            currentPriority = -1;
-            if (!TextUtils.isEmpty(priorityVal)) {
-                try {
-                    currentPriority = Integer.parseInt(priorityVal);
-                } catch (NumberFormatException ignore) {
+                doReconfig = true;
+            } else {
+                String priorityVal = WifiNative.getNetworkVariableCommand(netId, WifiConfiguration.priorityVarName);
+                currentPriority = -1;
+                if (!TextUtils.isEmpty(priorityVal)) {
+                    try {
+                        currentPriority = Integer.parseInt(priorityVal);
+                    } catch (NumberFormatException ignore) {
+                    }
                 }
+                doReconfig = currentPriority != config.priority;
             }
-            doReconfig = currentPriority != config.priority;
-        }
-        mNeedReconfig = mNeedReconfig || doReconfig;
+            mNeedReconfig = mNeedReconfig || doReconfig;
 
-        setVariables: {
+            setVariables: {
             /*
              * Note that if a networkId for a non-existent network
              * was supplied, then the first setNetworkVariableCommand()
              * will fail, so we don't bother to make a separate check
              * for the validity of the ID up front.
              */
-
             if (config.SSID != null &&
-                !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.ssidVarName,
-                    convertToQuotedString(config.SSID))) {
+                    !WifiNative.setNetworkVariableCommand(
+                        netId,
+                        WifiConfiguration.ssidVarName,
+                        convertToQuotedString(config.SSID))) {
                 if (DBG) {
                     Log.d(TAG, "failed to set SSID: "+config.SSID);
                 }
@@ -752,10 +755,10 @@
             }
 
             if (config.BSSID != null &&
-                !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.bssidVarName,
-                    config.BSSID)) {
+                    !WifiNative.setNetworkVariableCommand(
+                        netId,
+                        WifiConfiguration.bssidVarName,
+                        config.BSSID)) {
                 if (DBG) {
                     Log.d(TAG, "failed to set BSSID: "+config.BSSID);
                 }
@@ -765,13 +768,13 @@
             String allowedKeyManagementString =
                 makeString(config.allowedKeyManagement, WifiConfiguration.KeyMgmt.strings);
             if (config.allowedKeyManagement.cardinality() != 0 &&
-                !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.KeyMgmt.varName,
-                    allowedKeyManagementString)) {
+                    !WifiNative.setNetworkVariableCommand(
+                        netId,
+                        WifiConfiguration.KeyMgmt.varName,
+                        allowedKeyManagementString)) {
                 if (DBG) {
                     Log.d(TAG, "failed to set key_mgmt: "+
-                          allowedKeyManagementString);
+                            allowedKeyManagementString);
                 }
                 break setVariables;
             }
@@ -779,13 +782,13 @@
             String allowedProtocolsString =
                 makeString(config.allowedProtocols, WifiConfiguration.Protocol.strings);
             if (config.allowedProtocols.cardinality() != 0 &&
-                !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.Protocol.varName,
-                    allowedProtocolsString)) {
+                    !WifiNative.setNetworkVariableCommand(
+                        netId,
+                        WifiConfiguration.Protocol.varName,
+                        allowedProtocolsString)) {
                 if (DBG) {
                     Log.d(TAG, "failed to set proto: "+
-                          allowedProtocolsString);
+                            allowedProtocolsString);
                 }
                 break setVariables;
             }
@@ -793,13 +796,13 @@
             String allowedAuthAlgorithmsString =
                 makeString(config.allowedAuthAlgorithms, WifiConfiguration.AuthAlgorithm.strings);
             if (config.allowedAuthAlgorithms.cardinality() != 0 &&
-                !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.AuthAlgorithm.varName,
-                    allowedAuthAlgorithmsString)) {
+                    !WifiNative.setNetworkVariableCommand(
+                        netId,
+                        WifiConfiguration.AuthAlgorithm.varName,
+                        allowedAuthAlgorithmsString)) {
                 if (DBG) {
                     Log.d(TAG, "failed to set auth_alg: "+
-                          allowedAuthAlgorithmsString);
+                            allowedAuthAlgorithmsString);
                 }
                 break setVariables;
             }
@@ -807,13 +810,13 @@
             String allowedPairwiseCiphersString =
                 makeString(config.allowedPairwiseCiphers, WifiConfiguration.PairwiseCipher.strings);
             if (config.allowedPairwiseCiphers.cardinality() != 0 &&
-                !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.PairwiseCipher.varName,
-                    allowedPairwiseCiphersString)) {
+                    !WifiNative.setNetworkVariableCommand(
+                        netId,
+                        WifiConfiguration.PairwiseCipher.varName,
+                        allowedPairwiseCiphersString)) {
                 if (DBG) {
                     Log.d(TAG, "failed to set pairwise: "+
-                          allowedPairwiseCiphersString);
+                            allowedPairwiseCiphersString);
                 }
                 break setVariables;
             }
@@ -821,13 +824,13 @@
             String allowedGroupCiphersString =
                 makeString(config.allowedGroupCiphers, WifiConfiguration.GroupCipher.strings);
             if (config.allowedGroupCiphers.cardinality() != 0 &&
-                !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.GroupCipher.varName,
-                    allowedGroupCiphersString)) {
+                    !WifiNative.setNetworkVariableCommand(
+                        netId,
+                        WifiConfiguration.GroupCipher.varName,
+                        allowedGroupCiphersString)) {
                 if (DBG) {
                     Log.d(TAG, "failed to set group: "+
-                          allowedGroupCiphersString);
+                            allowedGroupCiphersString);
                 }
                 break setVariables;
             }
@@ -835,10 +838,10 @@
             // Prevent client screw-up by passing in a WifiConfiguration we gave it
             // by preventing "*" as a key.
             if (config.preSharedKey != null && !config.preSharedKey.equals("*") &&
-                !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.pskVarName,
-                    config.preSharedKey)) {
+                    !WifiNative.setNetworkVariableCommand(
+                        netId,
+                        WifiConfiguration.pskVarName,
+                        config.preSharedKey)) {
                 if (DBG) {
                     Log.d(TAG, "failed to set psk: "+config.preSharedKey);
                 }
@@ -852,13 +855,13 @@
                     // by preventing "*" as a key.
                     if (config.wepKeys[i] != null && !config.wepKeys[i].equals("*")) {
                         if (!WifiNative.setNetworkVariableCommand(
-                                netId,
-                                WifiConfiguration.wepKeyVarNames[i],
-                                config.wepKeys[i])) {
+                                    netId,
+                                    WifiConfiguration.wepKeyVarNames[i],
+                                    config.wepKeys[i])) {
                             if (DBG) {
                                 Log.d(TAG,
-                                      "failed to set wep_key"+i+": " +
-                                      config.wepKeys[i]);
+                                        "failed to set wep_key"+i+": " +
+                                        config.wepKeys[i]);
                             }
                             break setVariables;
                         }
@@ -869,36 +872,36 @@
 
             if (hasSetKey) {
                 if (!WifiNative.setNetworkVariableCommand(
-                        netId,
-                        WifiConfiguration.wepTxKeyIdxVarName,
-                        Integer.toString(config.wepTxKeyIndex))) {
+                            netId,
+                            WifiConfiguration.wepTxKeyIdxVarName,
+                            Integer.toString(config.wepTxKeyIndex))) {
                     if (DBG) {
                         Log.d(TAG,
-                              "failed to set wep_tx_keyidx: "+
-                              config.wepTxKeyIndex);
+                                "failed to set wep_tx_keyidx: "+
+                                config.wepTxKeyIndex);
                     }
                     break setVariables;
                 }
             }
 
             if (!WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.priorityVarName,
-                    Integer.toString(config.priority))) {
+                        netId,
+                        WifiConfiguration.priorityVarName,
+                        Integer.toString(config.priority))) {
                 if (DBG) {
                     Log.d(TAG, config.SSID + ": failed to set priority: "
-                          +config.priority);
+                            +config.priority);
                 }
                 break setVariables;
             }
 
             if (config.hiddenSSID && !WifiNative.setNetworkVariableCommand(
-                    netId,
-                    WifiConfiguration.hiddenSSIDVarName,
-                    Integer.toString(config.hiddenSSID ? 1 : 0))) {
+                        netId,
+                        WifiConfiguration.hiddenSSIDVarName,
+                        Integer.toString(config.hiddenSSID ? 1 : 0))) {
                 if (DBG) {
                     Log.d(TAG, config.SSID + ": failed to set hiddenSSID: "+
-                          config.hiddenSSID);
+                            config.hiddenSSID);
                 }
                 break setVariables;
             }
@@ -912,32 +915,33 @@
                         value = convertToQuotedString(value);
                     }
                     if (!WifiNative.setNetworkVariableCommand(
-                            netId,
-                            varName,
-                            value)) {
+                                netId,
+                                varName,
+                                value)) {
                         if (DBG) {
                             Log.d(TAG, config.SSID + ": failed to set " + varName +
-                                  ": " + value);
+                                    ": " + value);
                         }
                         break setVariables;
                     }
                 }
             }
             return netId;
-        }
+            }
 
-        /*
-         * For an update, if one of the setNetworkVariable operations fails,
-         * we might want to roll back all the changes already made. But the
-         * chances are that if anything is going to go wrong, it'll happen
-         * the first time we try to set one of the variables.
-         */
-        if (newNetwork) {
-            removeNetwork(netId);
-            if (DBG) {
-                Log.d(TAG,
-                      "Failed to set a network variable, removed network: "
-                      + netId);
+            /*
+             * For an update, if one of the setNetworkVariable operations fails,
+             * we might want to roll back all the changes already made. But the
+             * chances are that if anything is going to go wrong, it'll happen
+             * the first time we try to set one of the variables.
+             */
+            if (newNetwork) {
+                removeNetwork(netId);
+                if (DBG) {
+                    Log.d(TAG,
+                            "Failed to set a network variable, removed network: "
+                            + netId);
+                }
             }
         }
         return -1;
@@ -1849,13 +1853,14 @@
 
     public void initializeMulticastFiltering() {
         enforceMulticastChangePermission();
-
         synchronized (mMulticasters) {
             // if anybody had requested filters be off, leave off
             if (mMulticasters.size() != 0) {
                 return;
             } else {
-                WifiNative.startPacketFiltering();
+                synchronized (mWifiStateTracker) {
+                    WifiNative.startPacketFiltering();
+                }
             }
         }
     }
diff --git a/services/jni/com_android_server_SensorService.cpp b/services/jni/com_android_server_SensorService.cpp
index 3911d1f..77db6da 100644
--- a/services/jni/com_android_server_SensorService.cpp
+++ b/services/jni/com_android_server_SensorService.cpp
@@ -16,7 +16,6 @@
 
 #define LOG_TAG "SensorService"
 
-#define LOG_NDEBUG 0
 #include "utils/Log.h"
 
 #include <hardware/sensors.h>
diff --git a/wifi/java/android/net/wifi/WifiStateTracker.java b/wifi/java/android/net/wifi/WifiStateTracker.java
index 9d8f730..2668fe0 100644
--- a/wifi/java/android/net/wifi/WifiStateTracker.java
+++ b/wifi/java/android/net/wifi/WifiStateTracker.java
@@ -616,7 +616,7 @@
      * @return {@code true} if the operation succeeds, {@code false} otherwise, e.g.,
      * the number of channels is invalid.
      */
-    public boolean setNumAllowedChannels() {
+    public synchronized boolean setNumAllowedChannels() {
         try {
             return setNumAllowedChannels(
                     Settings.Secure.getInt(mContext.getContentResolver(),
@@ -859,7 +859,9 @@
                 // Only do this if we haven't gotten a new supplicant status since the timer
                 // started
                 if (mNumSupplicantStateChanges == msg.arg1) {
-                    WifiNative.scanCommand(false); // do a passive scan
+                    synchronized (this) {
+                        WifiNative.scanCommand(false); // do a passive scan
+                    }
                 }
                 break;
 
@@ -1154,7 +1156,6 @@
                     // [31- 1] Reserved for future use
                     // [ 0- 0] Interface configuration succeeded (1) or failed (0)
                     EventLog.writeEvent(EVENTLOG_INTERFACE_CONFIGURATION_STATE_CHANGED, 0);
-                
                     mHaveIpAddress = false;
                     mWifiInfo.setIpAddress(0);
                     mObtainingIpAddress = false;