Merge "Fix holo tabs to work on phone screens."
diff --git a/api/current.xml b/api/current.xml
index 16ba6be..3305a32 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -22045,6 +22045,32 @@
 <parameter name="useLogo" type="boolean">
 </parameter>
 </method>
+<method name="setIcon"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="resId" type="int">
+</parameter>
+</method>
+<method name="setIcon"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="icon" type="android.graphics.drawable.Drawable">
+</parameter>
+</method>
 <method name="setListNavigationCallbacks"
  return="void"
  abstract="true"
@@ -22060,6 +22086,32 @@
 <parameter name="callback" type="android.app.ActionBar.OnNavigationListener">
 </parameter>
 </method>
+<method name="setLogo"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="resId" type="int">
+</parameter>
+</method>
+<method name="setLogo"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="logo" type="android.graphics.drawable.Drawable">
+</parameter>
+</method>
 <method name="setNavigationMode"
  return="void"
  abstract="true"
diff --git a/core/java/android/app/ActionBar.java b/core/java/android/app/ActionBar.java
index fc5fac6..a9e84d7 100644
--- a/core/java/android/app/ActionBar.java
+++ b/core/java/android/app/ActionBar.java
@@ -160,6 +160,66 @@
     public abstract void setCustomView(int resId);
 
     /**
+     * Set the icon to display in the 'home' section of the action bar.
+     * The action bar will use an icon specified by its style or the
+     * activity icon by default.
+     *
+     * Whether the home section shows an icon or logo is controlled
+     * by the display option {@link #DISPLAY_USE_LOGO}.
+     *
+     * @param resId Resource ID of a drawable to show as an icon.
+     *
+     * @see #setDisplayUseLogoEnabled(boolean)
+     * @see #setDisplayShowHomeEnabled(boolean)
+     */
+    public abstract void setIcon(int resId);
+
+    /**
+     * Set the icon to display in the 'home' section of the action bar.
+     * The action bar will use an icon specified by its style or the
+     * activity icon by default.
+     *
+     * Whether the home section shows an icon or logo is controlled
+     * by the display option {@link #DISPLAY_USE_LOGO}.
+     *
+     * @param icon Drawable to show as an icon.
+     *
+     * @see #setDisplayUseLogoEnabled(boolean)
+     * @see #setDisplayShowHomeEnabled(boolean)
+     */
+    public abstract void setIcon(Drawable icon);
+
+    /**
+     * Set the logo to display in the 'home' section of the action bar.
+     * The action bar will use a logo specified by its style or the
+     * activity logo by default.
+     *
+     * Whether the home section shows an icon or logo is controlled
+     * by the display option {@link #DISPLAY_USE_LOGO}.
+     *
+     * @param resId Resource ID of a drawable to show as a logo.
+     *
+     * @see #setDisplayUseLogoEnabled(boolean)
+     * @see #setDisplayShowHomeEnabled(boolean)
+     */
+    public abstract void setLogo(int resId);
+
+    /**
+     * Set the logo to display in the 'home' section of the action bar.
+     * The action bar will use a logo specified by its style or the
+     * activity logo by default.
+     *
+     * Whether the home section shows an icon or logo is controlled
+     * by the display option {@link #DISPLAY_USE_LOGO}.
+     *
+     * @param logo Drawable to show as a logo.
+     *
+     * @see #setDisplayUseLogoEnabled(boolean)
+     * @see #setDisplayShowHomeEnabled(boolean)
+     */
+    public abstract void setLogo(Drawable logo);
+
+    /**
      * Set the adapter and navigation callback for list navigation mode.
      *
      * The supplied adapter will provide views for the expanded list as well as
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index c6051e1..2f2b4eb 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -1885,10 +1885,6 @@
      * @throws SQLException if the SQL string is invalid
      */
     public void execSQL(String sql) throws SQLException {
-        if (DatabaseUtils.getSqlStatementType(sql) == DatabaseUtils.STATEMENT_ATTACH) {
-            disableWriteAheadLogging();
-            mHasAttachedDbs = true;
-        }
         executeSql(sql, null);
     }
 
@@ -1943,6 +1939,10 @@
     }
 
     private int executeSql(String sql, Object[] bindArgs) throws SQLException {
+        if (DatabaseUtils.getSqlStatementType(sql) == DatabaseUtils.STATEMENT_ATTACH) {
+            disableWriteAheadLogging();
+            mHasAttachedDbs = true;
+        }
         SQLiteStatement statement = new SQLiteStatement(this, sql, bindArgs);
         try {
             return statement.executeUpdateDelete();
diff --git a/core/java/android/database/sqlite/SQLiteProgram.java b/core/java/android/database/sqlite/SQLiteProgram.java
index 88246e8..89552dc 100644
--- a/core/java/android/database/sqlite/SQLiteProgram.java
+++ b/core/java/android/database/sqlite/SQLiteProgram.java
@@ -105,12 +105,9 @@
             case DatabaseUtils.STATEMENT_SELECT:
                 mStatementType = n | STATEMENT_CACHEABLE | STATEMENT_USE_POOLED_CONN;
                 break;
-            case DatabaseUtils.STATEMENT_ATTACH:
             case DatabaseUtils.STATEMENT_BEGIN:
             case DatabaseUtils.STATEMENT_COMMIT:
             case DatabaseUtils.STATEMENT_ABORT:
-            case DatabaseUtils.STATEMENT_DDL:
-            case DatabaseUtils.STATEMENT_UNPREPARED:
                 mStatementType = n | STATEMENT_DONT_PREPARE;
                 break;
             default:
@@ -353,13 +350,10 @@
 
     /* package */ void compileAndbindAllArgs() {
         if ((mStatementType & STATEMENT_DONT_PREPARE) > 0) {
-            // no need to prepare this SQL statement
-            if (SQLiteDebug.DEBUG_SQL_STATEMENTS) {
-                if (mBindArgs != null) {
-                    throw new IllegalArgumentException("no need to pass bindargs for this sql :" +
-                            mSql);
-                }
+            if (mBindArgs != null) {
+                throw new IllegalArgumentException("Can't pass bindargs for this sql :" + mSql);
             }
+            // no need to prepare this SQL statement
             return;
         }
         if (nStatement == 0) {
diff --git a/core/java/android/webkit/HTML5VideoFullScreen.java b/core/java/android/webkit/HTML5VideoFullScreen.java
index f52fa66..0510f8b 100644
--- a/core/java/android/webkit/HTML5VideoFullScreen.java
+++ b/core/java/android/webkit/HTML5VideoFullScreen.java
@@ -114,6 +114,13 @@
         return mVideoSurfaceView;
     }
 
+    @Override
+    public void start() {
+        if (getAutostart()) {
+            super.start();
+        }
+    }
+
     HTML5VideoFullScreen(Context context, int videoLayerId, int position,
             boolean autoStart) {
         mVideoSurfaceView = new VideoSurfaceView(context);
diff --git a/core/java/android/webkit/HTML5VideoInline.java b/core/java/android/webkit/HTML5VideoInline.java
index 4f042a6..25921bc 100644
--- a/core/java/android/webkit/HTML5VideoInline.java
+++ b/core/java/android/webkit/HTML5VideoInline.java
@@ -20,7 +20,9 @@
     // Video control FUNCTIONS:
     @Override
     public void start() {
-        super.start();
+        if (!getPauseDuringPreparing()) {
+            super.start();
+        }
     }
 
     HTML5VideoInline(int videoLayerId, int position,
diff --git a/core/java/android/webkit/HTML5VideoView.java b/core/java/android/webkit/HTML5VideoView.java
index cd2264c..8ea73b5 100644
--- a/core/java/android/webkit/HTML5VideoView.java
+++ b/core/java/android/webkit/HTML5VideoView.java
@@ -65,6 +65,7 @@
     // The spec says the timer should fire every 250 ms or less.
     private static final int TIMEUPDATE_PERIOD = 250;  // ms
 
+    protected boolean mPauseDuringPreparing;
     // common Video control FUNCTIONS:
     public void start() {
         if (mCurrentState == STATE_PREPARED) {
@@ -83,8 +84,9 @@
     public void pause() {
         if (mCurrentState == STATE_PREPARED && mPlayer.isPlaying()) {
             mPlayer.pause();
+        } else if (mCurrentState == STATE_NOTPREPARED) {
+            mPauseDuringPreparing = true;
         }
-
         // Delete the Timer to stop it since there is no stop call.
         if (mTimer != null) {
             mTimer.purge();
@@ -133,6 +135,10 @@
         return mAutostart;
     }
 
+    public boolean getPauseDuringPreparing() {
+        return mPauseDuringPreparing;
+    }
+
     // Every time we start a new Video, we create a VideoView and a MediaPlayer
     public void init(int videoLayerId, int position, boolean autoStart) {
         mPlayer = new MediaPlayer();
@@ -142,6 +148,7 @@
         mSaveSeekTime = position;
         mAutostart = autoStart;
         mTimer = null;
+        mPauseDuringPreparing = false;
     }
 
     protected HTML5VideoView() {
@@ -242,15 +249,17 @@
         if (mProxy != null) {
             mProxy.onPrepared(mp);
         }
+        if (mPauseDuringPreparing) {
+            pauseAndDispatch(mProxy);
+            mPauseDuringPreparing = false;
+        }
     }
 
     // Pause the play and update the play/pause button
     public void pauseAndDispatch(HTML5VideoViewProxy proxy) {
-        if (isPlaying()) {
-            pause();
-            if (proxy != null) {
-                proxy.dispatchOnPaused();
-            }
+        pause();
+        if (proxy != null) {
+            proxy.dispatchOnPaused();
         }
     }
 
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index d12b965..094566f 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -224,10 +224,8 @@
         }
 
         public static void onPrepared() {
-            if (!mHTML5VideoView.isFullScreenMode() ||
-                    mHTML5VideoView.isFullScreenMode() &&
-                    mHTML5VideoView.getAutostart() )
-                mHTML5VideoView.start();
+            // The VideoView will decide whether to really kick off to play.
+            mHTML5VideoView.start();
             if (mBaseLayer != 0) {
                 setBaseLayer(mBaseLayer);
             }
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 8f1354b..b712fdb 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -889,23 +889,24 @@
         return mTabs.get(index);
     }
 
-    /**
-     * This fragment is added when we're keeping a back stack in a tab switch
-     * transaction. We use it to change the selected tab in the action bar view
-     * when we back out.
-     */
-    private class SwitchSelectedTabViewFragment extends Fragment {
-        private int mSelectedTabIndex;
 
-        public SwitchSelectedTabViewFragment(int oldSelectedTab) {
-            mSelectedTabIndex = oldSelectedTab;
-        }
+    @Override
+    public void setIcon(int resId) {
+        mActionView.setIcon(mContext.getResources().getDrawable(resId));
+    }
 
-        @Override
-        public void onDetach() {
-            if (mSelectedTabIndex >= 0 && mSelectedTabIndex < getTabCount()) {
-                mActionView.setTabSelected(mSelectedTabIndex);
-            }
-        }
+    @Override
+    public void setIcon(Drawable icon) {
+        mActionView.setIcon(icon);
+    }
+
+    @Override
+    public void setLogo(int resId) {
+        mActionView.setLogo(mContext.getResources().getDrawable(resId));
+    }
+
+    @Override
+    public void setLogo(Drawable logo) {
+        mActionView.setLogo(logo);
     }
 }
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 81d02ee..2d9a9f2 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -416,6 +416,21 @@
         }
     }
 
+    public void setIcon(Drawable icon) {
+        mIcon = icon;
+        if (icon != null &&
+                ((mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) == 0 || mLogo == null)) {
+            mIconView.setImageDrawable(icon);
+        }
+    }
+
+    public void setLogo(Drawable logo) {
+        mLogo = logo;
+        if (logo != null && (mDisplayOptions & ActionBar.DISPLAY_USE_LOGO) != 0) {
+            mIconView.setImageDrawable(logo);
+        }
+    }
+
     public void setNavigationMode(int mode) {
         final int oldMode = mNavigationMode;
         if (mode != oldMode) {
diff --git a/core/tests/coretests/src/android/database/sqlite/SQLiteDatabaseTest.java b/core/tests/coretests/src/android/database/sqlite/SQLiteDatabaseTest.java
index 39258ae..5ef8d11 100644
--- a/core/tests/coretests/src/android/database/sqlite/SQLiteDatabaseTest.java
+++ b/core/tests/coretests/src/android/database/sqlite/SQLiteDatabaseTest.java
@@ -31,9 +31,11 @@
 import android.test.suitebuilder.annotation.SmallTest;
 import android.test.suitebuilder.annotation.Suppress;
 import android.util.Log;
+import android.util.Pair;
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.List;
 
 public class SQLiteDatabaseTest extends AndroidTestCase {
     private static final String TAG = "DatabaseGeneralTest";
@@ -892,6 +894,49 @@
         c.close();
     }
 
+    @SmallTest
+    public void testAttachDb() {
+        String newDb = "/sdcard/mydata.db";
+        File f = new File(newDb);
+        if (f.exists()) {
+            f.delete();
+        }
+        assertFalse(f.exists());
+        SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(newDb, null);
+        db.execSQL("create table test1 (i int);");
+        db.execSQL("insert into test1 values(1);");
+        db.execSQL("insert into test1 values(11);");
+        Cursor c = null;
+        try {
+            c = db.rawQuery("select * from test1", null);
+            int count = c.getCount();
+            Log.i(TAG, "count: " + count);
+            assertEquals(2, count);
+        } finally {
+            c.close();
+            db.close();
+            c = null;
+        }
+
+        mDatabase.execSQL("attach database ? as newDb" , new String[]{newDb});
+        Cursor c1 = null;
+        try {
+            c1 = mDatabase.rawQuery("select * from newDb.test1", null);
+            assertEquals(2, c1.getCount());
+        } catch (Exception e) {
+            fail("unexpected exception: " + e.getMessage());
+        } finally {
+            if (c1 != null) {
+                c1.close();
+            }
+        }
+        List<Pair<String, String>> dbs = mDatabase.getAttachedDbs();
+        for (Pair<String, String> p: dbs) {
+            Log.i(TAG, "attached dbs: " + p.first + " : " + p.second);
+        }
+        assertEquals(2, dbs.size());
+     }
+
     /**
      * http://b/issue?id=2943028
      * SQLiteOpenHelper maintains a Singleton even if it is in bad state.
diff --git a/drm/common/DrmSupportInfo.cpp b/drm/common/DrmSupportInfo.cpp
index c0bff0e..3dee435 100644
--- a/drm/common/DrmSupportInfo.cpp
+++ b/drm/common/DrmSupportInfo.cpp
@@ -15,6 +15,7 @@
  */
 
 #include <drm/DrmSupportInfo.h>
+#include <strings.h>
 
 using namespace android;
 
@@ -152,4 +153,3 @@
     mIndex++;
     return value;
 }
-
diff --git a/libs/utils/AssetManager.cpp b/libs/utils/AssetManager.cpp
index e09e755..6e57d93 100644
--- a/libs/utils/AssetManager.cpp
+++ b/libs/utils/AssetManager.cpp
@@ -36,6 +36,7 @@
 #include <dirent.h>
 #include <errno.h>
 #include <assert.h>
+#include <strings.h>
 
 using namespace android;
 
@@ -1764,4 +1765,3 @@
 
     return mZipPath.size()-1;
 }
-
diff --git a/services/java/com/android/server/PackageManagerService.java b/services/java/com/android/server/PackageManagerService.java
index 2b673fa..3d8dccb 100644
--- a/services/java/com/android/server/PackageManagerService.java
+++ b/services/java/com/android/server/PackageManagerService.java
@@ -16,6 +16,10 @@
 
 package com.android.server;
 
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
+import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
+
 import com.android.internal.app.IMediaContainerService;
 import com.android.internal.app.ResolverActivity;
 import com.android.internal.content.NativeLibraryHelper;
@@ -32,8 +36,8 @@
 import android.app.IActivityManager;
 import android.app.admin.IDevicePolicyManager;
 import android.app.backup.IBackupManager;
-import android.content.Context;
 import android.content.ComponentName;
+import android.content.Context;
 import android.content.IIntentReceiver;
 import android.content.Intent;
 import android.content.IntentFilter;
@@ -54,13 +58,10 @@
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageInfoLite;
 import android.content.pm.PackageManager;
-import android.content.pm.PackageStats;
-import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
-import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
-import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
 import android.content.pm.PackageParser;
-import android.content.pm.PermissionInfo;
+import android.content.pm.PackageStats;
 import android.content.pm.PermissionGroupInfo;
+import android.content.pm.PermissionInfo;
 import android.content.pm.ProviderInfo;
 import android.content.pm.ResolveInfo;
 import android.content.pm.ServiceInfo;
@@ -69,24 +70,29 @@
 import android.os.Binder;
 import android.os.Build;
 import android.os.Bundle;
-import android.os.Debug;
+import android.os.Environment;
+import android.os.FileObserver;
+import android.os.FileUtils;
+import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
 import android.os.Parcel;
-import android.os.RemoteException;
-import android.os.Environment;
-import android.os.FileObserver;
-import android.os.FileUtils;
-import android.os.Handler;
 import android.os.ParcelFileDescriptor;
 import android.os.Process;
+import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.security.SystemKeyStore;
-import android.util.*;
+import android.util.DisplayMetrics;
+import android.util.EventLog;
+import android.util.Log;
+import android.util.LogPrinter;
+import android.util.Slog;
+import android.util.SparseArray;
+import android.util.Xml;
 import android.view.Display;
 import android.view.WindowManager;
 
@@ -138,6 +144,12 @@
     private static final boolean DEBUG_UPGRADE = false;
     private static final boolean DEBUG_INSTALL = false;
     private static final boolean DEBUG_STOPPED = false;
+    private static final boolean DEBUG_REMOVE = false;
+    private static final boolean DEBUG_SHOW_INFO = false;
+    private static final boolean DEBUG_PACKAGE_INFO = false;
+    private static final boolean DEBUG_INTENT_MATCHING = false;
+    private static final boolean DEBUG_PACKAGE_SCANNING = false;
+    private static final boolean DEBUG_APP_DIR_OBSERVER = false;
 
     private static final boolean MULTIPLE_APPLICATION_UIDS = true;
     private static final int RADIO_UID = Process.PHONE_UID;
@@ -147,8 +159,6 @@
         Process.FIRST_APPLICATION_UID;
     private static final int MAX_APPLICATION_UIDS = 1000;
 
-    private static final boolean SHOW_INFO = false;
-
     private static final boolean GET_CERTIFICATES = true;
 
     private static final int REMOVE_EVENTS =
@@ -362,6 +372,7 @@
 
     // Delay time in millisecs
     static final int BROADCAST_DELAY = 10 * 1000;
+
     final private DefaultContainerConnection mDefContainerConn =
             new DefaultContainerConnection();
     class DefaultContainerConnection implements ServiceConnection {
@@ -526,12 +537,12 @@
                 }
                 case MCS_GIVE_UP: {
                     if (DEBUG_SD_INSTALL) Log.i(TAG, "mcs_giveup too many retries");
-                    HandlerParams params = mPendingInstalls.remove(0);
+                    mPendingInstalls.remove(0);
                     break;
                 }
                 case SEND_PENDING_BROADCAST : {
                     String packages[];
-                    ArrayList components[];
+                    ArrayList<String> components[];
                     int size = 0;
                     int uids[];
                     Process.setThreadPriority(Process.THREAD_PRIORITY_DEFAULT);
@@ -563,8 +574,7 @@
                     }
                     // Send broadcasts
                     for (int i = 0; i < size; i++) {
-                        sendPackageChangedBroadcast(packages[i], true,
-                                (ArrayList<String>)components[i], uids[i]);
+                        sendPackageChangedBroadcast(packages[i], true, components[i], uids[i]);
                     }
                     Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
                     break;
@@ -1347,9 +1357,8 @@
     public PackageInfo getPackageInfo(String packageName, int flags) {
         synchronized (mPackages) {
             PackageParser.Package p = mPackages.get(packageName);
-            if (Config.LOGV) Log.v(
-                TAG, "getPackageInfo " + packageName
-                + ": " + p);
+            if (DEBUG_PACKAGE_INFO)
+                Log.v(TAG, "getPackageInfo " + packageName + ": " + p);
             if (p != null) {
                 return generatePackageInfo(p, flags);
             }
@@ -1400,9 +1409,8 @@
     public int[] getPackageGids(String packageName) {
         synchronized (mPackages) {
             PackageParser.Package p = mPackages.get(packageName);
-            if (Config.LOGV) Log.v(
-                TAG, "getPackageGids" + packageName
-                + ": " + p);
+            if (DEBUG_PACKAGE_INFO)
+                Log.v(TAG, "getPackageGids" + packageName + ": " + p);
             if (p != null) {
                 final PackageSetting ps = (PackageSetting)p.mExtras;
                 final SharedUserSetting suid = ps.sharedUser;
@@ -1514,7 +1522,7 @@
     public ApplicationInfo getApplicationInfo(String packageName, int flags) {
         synchronized (mPackages) {
             PackageParser.Package p = mPackages.get(packageName);
-            if (Config.LOGV) Log.v(
+            if (DEBUG_PACKAGE_INFO) Log.v(
                     TAG, "getApplicationInfo " + packageName
                     + ": " + p);
             if (p != null) {
@@ -1589,7 +1597,7 @@
         synchronized (mPackages) {
             PackageParser.Activity a = mActivities.mActivities.get(component);
 
-            if (Config.LOGV) Log.v(TAG, "getActivityInfo " + component + ": " + a);
+            if (DEBUG_PACKAGE_INFO) Log.v(TAG, "getActivityInfo " + component + ": " + a);
             if (a != null && mSettings.isEnabledLP(a.info, flags)) {
                 return PackageParser.generateActivityInfo(a, flags);
             }
@@ -1603,7 +1611,7 @@
     public ActivityInfo getReceiverInfo(ComponentName component, int flags) {
         synchronized (mPackages) {
             PackageParser.Activity a = mReceivers.mActivities.get(component);
-            if (Config.LOGV) Log.v(
+            if (DEBUG_PACKAGE_INFO) Log.v(
                 TAG, "getReceiverInfo " + component + ": " + a);
             if (a != null && mSettings.isEnabledLP(a.info, flags)) {
                 return PackageParser.generateActivityInfo(a, flags);
@@ -1615,7 +1623,7 @@
     public ServiceInfo getServiceInfo(ComponentName component, int flags) {
         synchronized (mPackages) {
             PackageParser.Service s = mServices.mServices.get(component);
-            if (Config.LOGV) Log.v(
+            if (DEBUG_PACKAGE_INFO) Log.v(
                 TAG, "getServiceInfo " + component + ": " + s);
             if (s != null && mSettings.isEnabledLP(s.info, flags)) {
                 return PackageParser.generateServiceInfo(s, flags);
@@ -1627,7 +1635,7 @@
     public ProviderInfo getProviderInfo(ComponentName component, int flags) {
         synchronized (mPackages) {
             PackageParser.Provider p = mProvidersByComponent.get(component);
-            if (Config.LOGV) Log.v(
+            if (DEBUG_PACKAGE_INFO) Log.v(
                 TAG, "getProviderInfo " + component + ": " + p);
             if (p != null && mSettings.isEnabledLP(p.info, flags)) {
                 return PackageParser.generateProviderInfo(p, flags);
@@ -1973,11 +1981,9 @@
                 // then let the user decide between them.
                 ResolveInfo r0 = query.get(0);
                 ResolveInfo r1 = query.get(1);
-                if (false) {
-                    System.out.println(r0.activityInfo.name +
-                                       "=" + r0.priority + " vs " +
-                                       r1.activityInfo.name +
-                                       "=" + r1.priority);
+                if (DEBUG_INTENT_MATCHING) {
+                    Log.d(TAG, r0.activityInfo.name + "=" + r0.priority + " vs "
+                            + r1.activityInfo.name + "=" + r1.priority);
                 }
                 // If the first activity has a higher priority, or a different
                 // default, then it is always desireable to pick it.
@@ -2105,7 +2111,7 @@
 
         List<ResolveInfo> results = queryIntentActivities(
             intent, resolvedType, flags|PackageManager.GET_RESOLVED_FILTER);
-        if (Config.LOGV) Log.v(TAG, "Query " + intent + ": " + results);
+        if (DEBUG_INTENT_MATCHING) Log.v(TAG, "Query " + intent + ": " + results);
 
         int specificsPos = 0;
         int N;
@@ -2125,7 +2131,7 @@
                     continue;
                 }
 
-                if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + sintent);
+                if (DEBUG_INTENT_MATCHING) Log.v(TAG, "Specific #" + i + ": " + sintent);
                 String action = sintent.getAction();
                 if (resultsAction != null && resultsAction.equals(action)) {
                     // If this action was explicitly requested, then don't
@@ -2158,7 +2164,7 @@
 
                 // Look for any generic query activities that are duplicates
                 // of this specific one, and remove them from the results.
-                if (Config.LOGV) Log.v(TAG, "Specific #" + i + ": " + ai);
+                if (DEBUG_INTENT_MATCHING) Log.v(TAG, "Specific #" + i + ": " + ai);
                 N = results.size();
                 int j;
                 for (j=specificsPos; j<N; j++) {
@@ -2168,7 +2174,7 @@
                                     comp.getPackageName()))
                         || (action != null && sri.filter.matchAction(action))) {
                         results.remove(j);
-                        if (Config.LOGV) Log.v(
+                        if (DEBUG_INTENT_MATCHING) Log.v(
                             TAG, "Removing duplicate item from " + j
                             + " due to specific " + specificsPos);
                         if (ri == null) {
@@ -2216,7 +2222,7 @@
                     final ResolveInfo rij = results.get(j);
                     if (rij.filter != null && rij.filter.hasAction(action)) {
                         results.remove(j);
-                        if (Config.LOGV) Log.v(
+                        if (DEBUG_INTENT_MATCHING) Log.v(
                             TAG, "Removing duplicate item from " + j
                             + " due to action " + action + " at " + i);
                         j--;
@@ -2255,7 +2261,7 @@
             }
         }
 
-        if (Config.LOGV) Log.v(TAG, "Result: " + results);
+        if (DEBUG_INTENT_MATCHING) Log.v(TAG, "Result: " + results);
         return results;
     }
 
@@ -2423,7 +2429,8 @@
     /**
      * @deprecated
      */
-    public void querySyncProviders(List outNames, List outInfo) {
+    @Deprecated
+    public void querySyncProviders(List<String> outNames, List<ProviderInfo> outInfo) {
         synchronized (mPackages) {
             Iterator<Map.Entry<String, PackageParser.Provider>> i
                 = mProviders.entrySet().iterator();
@@ -2508,7 +2515,7 @@
             return;
         }
 
-        if (false) {
+        if (DEBUG_PACKAGE_SCANNING) {
             Log.d(TAG, "Scanning app dir " + dir);
         }
 
@@ -2861,8 +2868,11 @@
             }
         }
 
-        if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) Log.d(
-                TAG, "Scanning package " + pkg.packageName);
+        if (DEBUG_PACKAGE_SCANNING) {
+            if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
+                Log.d(TAG, "Scanning package " + pkg.packageName);
+        }
+
         if (mPackages.containsKey(pkg.packageName)
                 || mSharedLibraries.containsKey(pkg.packageName)) {
             Slog.w(TAG, "Application package " + pkg.packageName
@@ -2934,18 +2944,10 @@
                     mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
                     return null;
                 }
-                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD) {
-                    Log.d(TAG, "Shared UserID " + pkg.mSharedUserId + " (uid="
-                            + suid.userId + "): packages=" + suid.packages);
-                }
-            }
-
-            if (false) {
-                if (pkg.mOriginalPackages != null) {
-                    Log.w(TAG, "WAITING FOR DEBUGGER");
-                    Debug.waitForDebugger();
-                    Log.i(TAG, "Package " + pkg.packageName + " from original packages"
-                            + pkg.mOriginalPackages);
+                if (DEBUG_PACKAGE_SCANNING) {
+                    if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
+                        Log.d(TAG, "Shared UserID " + pkg.mSharedUserId + " (uid=" + suid.userId
+                                + "): packages=" + suid.packages);
                 }
             }
             
@@ -3077,7 +3079,7 @@
             // package isn't already installed, since we don't want to break
             // things that are installed.
             if ((scanMode&SCAN_NEW_INSTALL) != 0) {
-                int N = pkg.providers.size();
+                final int N = pkg.providers.size();
                 int i;
                 for (i=0; i<N; i++) {
                     PackageParser.Provider p = pkg.providers.get(i);
@@ -3120,7 +3122,6 @@
         
         final long scanFileTime = scanFile.lastModified();
         final boolean forceDex = (scanMode&SCAN_FORCE_DEX) != 0;
-        final boolean scanFileNewer = forceDex || scanFileTime != pkgSetting.timeStamp;
         pkg.applicationInfo.processName = fixProcessName(
                 pkg.applicationInfo.packageName,
                 pkg.applicationInfo.processName,
@@ -3197,8 +3198,10 @@
                 }
                 pkg.applicationInfo.dataDir = dataPath.getPath();
             } else {
-                if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGV)
-                    Log.v(TAG, "Want this data dir: " + dataPath);
+                if (DEBUG_PACKAGE_SCANNING) {
+                    if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
+                        Log.v(TAG, "Want this data dir: " + dataPath);
+                }
                 //invoke installer to do the actual installation
                 if (mInstaller != null) {
                     int ret = mInstaller.install(pkgName, pkg.applicationInfo.uid,
@@ -3378,10 +3381,12 @@
                             } else {
                                 p.info.authority = p.info.authority + ";" + names[j];
                             }
-                            if ((parseFlags&PackageParser.PARSE_CHATTY) != 0 && Config.LOGD)
-                                Log.d(TAG, "Registered content provider: " + names[j] +
-                                        ", className = " + p.info.name +
-                                        ", isSyncable = " + p.info.isSyncable);
+                            if (DEBUG_PACKAGE_SCANNING) {
+                                if ((parseFlags & PackageParser.PARSE_CHATTY) != 0)
+                                    Log.d(TAG, "Registered content provider: " + names[j]
+                                            + ", className = " + p.info.name + ", isSyncable = "
+                                            + p.info.isSyncable);
+                            }
                         } else {
                             PackageParser.Provider other = mProviders.get(names[j]);
                             Slog.w(TAG, "Skipping provider name " + names[j] +
@@ -3402,7 +3407,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Providers: " + r);
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Providers: " + r);
             }
 
             N = pkg.services.size();
@@ -3422,7 +3427,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Services: " + r);
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Services: " + r);
             }
 
             N = pkg.receivers.size();
@@ -3442,7 +3447,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Receivers: " + r);
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Receivers: " + r);
             }
 
             N = pkg.activities.size();
@@ -3462,7 +3467,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Activities: " + r);
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Activities: " + r);
             }
 
             N = pkg.permissionGroups.size();
@@ -3496,7 +3501,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Permission Groups: " + r);
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Permission Groups: " + r);
             }
 
             N = pkg.permissions.size();
@@ -3561,7 +3566,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Permissions: " + r);
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Permissions: " + r);
             }
 
             N = pkg.instrumentation.size();
@@ -3584,7 +3589,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Instrumentation: " + r);
+                if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, "  Instrumentation: " + r);
             }
 
             if (pkg.protectedBroadcasts != null) {
@@ -3613,22 +3618,11 @@
         }
     }
 
-    // Return the path of the directory that will contain the native binaries
-    // of a given installed package. This is relative to the data path.
-    //
-    private File getNativeBinaryDirForPackage(PackageParser.Package pkg) {
-        final String nativeLibraryDir = pkg.applicationInfo.nativeLibraryDir;
-        if (nativeLibraryDir != null) {
-            return new File(nativeLibraryDir);
-        } else {
-            // Fall back for old packages
-            return new File(pkg.applicationInfo.dataDir, LIB_DIR_NAME);
-        }
-    }
-
     void removePackageLI(PackageParser.Package pkg, boolean chatty) {
-        if (chatty && Config.LOGD) Log.d(
-            TAG, "Removing package " + pkg.applicationInfo.packageName );
+        if (DEBUG_INSTALL) {
+            if (chatty)
+                Log.d(TAG, "Removing package " + pkg.applicationInfo.packageName);
+        }
 
         synchronized (mPackages) {
             clearPackagePreferredActivitiesLP(pkg.packageName);
@@ -3657,10 +3651,12 @@
                 for (int j = 0; j < names.length; j++) {
                     if (mProviders.get(names[j]) == p) {
                         mProviders.remove(names[j]);
-                        if (chatty && Config.LOGD) Log.d(
-                            TAG, "Unregistered content provider: " + names[j] +
-                            ", className = " + p.info.name +
-                            ", isSyncable = " + p.info.isSyncable);
+                        if (DEBUG_REMOVE) {
+                            if (chatty)
+                                Log.d(TAG, "Unregistered content provider: " + names[j]
+                                        + ", className = " + p.info.name + ", isSyncable = "
+                                        + p.info.isSyncable);
+                        }
                     }
                 }
                 if (chatty) {
@@ -3673,7 +3669,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Providers: " + r);
+                if (DEBUG_REMOVE) Log.d(TAG, "  Providers: " + r);
             }
 
             N = pkg.services.size();
@@ -3691,7 +3687,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Services: " + r);
+                if (DEBUG_REMOVE) Log.d(TAG, "  Services: " + r);
             }
 
             N = pkg.receivers.size();
@@ -3709,7 +3705,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Receivers: " + r);
+                if (DEBUG_REMOVE) Log.d(TAG, "  Receivers: " + r);
             }
 
             N = pkg.activities.size();
@@ -3727,17 +3723,15 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Activities: " + r);
+                if (DEBUG_REMOVE) Log.d(TAG, "  Activities: " + r);
             }
 
             N = pkg.permissions.size();
             r = null;
             for (i=0; i<N; i++) {
                 PackageParser.Permission p = pkg.permissions.get(i);
-                boolean tree = false;
                 BasePermission bp = mSettings.mPermissions.get(p.info.name);
                 if (bp == null) {
-                    tree = true;
                     bp = mSettings.mPermissionTrees.get(p.info.name);
                 }
                 if (bp != null && bp.perm == p) {
@@ -3753,7 +3747,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Permissions: " + r);
+                if (DEBUG_REMOVE) Log.d(TAG, "  Permissions: " + r);
             }
 
             N = pkg.instrumentation.size();
@@ -3771,7 +3765,7 @@
                 }
             }
             if (r != null) {
-                if (Config.LOGD) Log.d(TAG, "  Instrumentation: " + r);
+                if (DEBUG_REMOVE) Log.d(TAG, "  Instrumentation: " + r);
             }
         }
     }
@@ -3895,10 +3889,9 @@
         for (int i=0; i<N; i++) {
             String name = pkg.requestedPermissions.get(i);
             BasePermission bp = mSettings.mPermissions.get(name);
-            if (false) {
+            if (DEBUG_INSTALL) {
                 if (gp != ps) {
-                    Log.i(TAG, "Package " + pkg.packageName + " checking " + name
-                            + ": " + bp);
+                    Log.i(TAG, "Package " + pkg.packageName + " checking " + name + ": " + bp);
                 }
             }
             if (bp != null && bp.packageSetting != null) {
@@ -3944,7 +3937,7 @@
                 } else {
                     allowed = false;
                 }
-                if (false) {
+                if (DEBUG_INSTALL) {
                     if (gp != ps) {
                         Log.i(TAG, "Package " + pkg.packageName + " granting " + perm);
                     }
@@ -4022,25 +4015,26 @@
     
     private final class ActivityIntentResolver
             extends IntentResolver<PackageParser.ActivityIntentInfo, ResolveInfo> {
-        public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) {
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
+                boolean defaultOnly) {
             mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
             return super.queryIntent(intent, resolvedType, defaultOnly);
         }
 
-        public List queryIntent(Intent intent, String resolvedType, int flags) {
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags) {
             mFlags = flags;
             return super.queryIntent(intent, resolvedType,
                 (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0);
         }
 
-        public List queryIntentForPackage(Intent intent, String resolvedType, int flags,
-                                          ArrayList<PackageParser.Activity> packageActivities) {
+        public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
+                int flags, ArrayList<PackageParser.Activity> packageActivities) {
             if (packageActivities == null) {
                 return null;
             }
             mFlags = flags;
             final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0;
-            int N = packageActivities.size();
+            final int N = packageActivities.size();
             ArrayList<ArrayList<PackageParser.ActivityIntentInfo>> listCut =
                 new ArrayList<ArrayList<PackageParser.ActivityIntentInfo>>(N);
 
@@ -4057,11 +4051,13 @@
         public final void addActivity(PackageParser.Activity a, String type) {
             final boolean systemApp = isSystemApp(a.info.applicationInfo);
             mActivities.put(a.getComponentName(), a);
-            if (SHOW_INFO || Config.LOGV) Log.v(
+            if (DEBUG_SHOW_INFO)
+                Log.v(
                 TAG, "  " + type + " " +
                 (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":");
-            if (SHOW_INFO || Config.LOGV) Log.v(TAG, "    Class=" + a.info.name);
-            int NI = a.intents.size();
+            if (DEBUG_SHOW_INFO)
+                Log.v(TAG, "    Class=" + a.info.name);
+            final int NI = a.intents.size();
             for (int j=0; j<NI; j++) {
                 PackageParser.ActivityIntentInfo intent = a.intents.get(j);
                 if (!systemApp && intent.getPriority() > 0 && "activity".equals(type)) {
@@ -4069,7 +4065,7 @@
                     Log.w(TAG, "Package " + a.info.applicationInfo.packageName + " has activity "
                             + a.className + " with priority > 0, forcing to 0");
                 }
-                if (SHOW_INFO || Config.LOGV) {
+                if (DEBUG_SHOW_INFO) {
                     Log.v(TAG, "    IntentFilter:");
                     intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
                 }
@@ -4082,14 +4078,16 @@
 
         public final void removeActivity(PackageParser.Activity a, String type) {
             mActivities.remove(a.getComponentName());
-            if (SHOW_INFO || Config.LOGV) Log.v(
-                TAG, "  " + type + " " +
-                (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel : a.info.name) + ":");
-            if (SHOW_INFO || Config.LOGV) Log.v(TAG, "    Class=" + a.info.name);
-            int NI = a.intents.size();
+            if (DEBUG_SHOW_INFO) {
+                Log.v(TAG, "  " + type + " "
+                        + (a.info.nonLocalizedLabel != null ? a.info.nonLocalizedLabel
+                                : a.info.name) + ":");
+                Log.v(TAG, "    Class=" + a.info.name);
+            }
+            final int NI = a.intents.size();
             for (int j=0; j<NI; j++) {
                 PackageParser.ActivityIntentInfo intent = a.intents.get(j);
-                if (SHOW_INFO || Config.LOGV) {
+                if (DEBUG_SHOW_INFO) {
                     Log.v(TAG, "    IntentFilter:");
                     intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
                 }
@@ -4193,25 +4191,26 @@
 
     private final class ServiceIntentResolver
             extends IntentResolver<PackageParser.ServiceIntentInfo, ResolveInfo> {
-        public List queryIntent(Intent intent, String resolvedType, boolean defaultOnly) {
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
+                boolean defaultOnly) {
             mFlags = defaultOnly ? PackageManager.MATCH_DEFAULT_ONLY : 0;
             return super.queryIntent(intent, resolvedType, defaultOnly);
         }
 
-        public List queryIntent(Intent intent, String resolvedType, int flags) {
+        public List<ResolveInfo> queryIntent(Intent intent, String resolvedType, int flags) {
             mFlags = flags;
             return super.queryIntent(intent, resolvedType,
                 (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0);
         }
 
-        public List queryIntentForPackage(Intent intent, String resolvedType, int flags,
-                                          ArrayList<PackageParser.Service> packageServices) {
+        public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType,
+                int flags, ArrayList<PackageParser.Service> packageServices) {
             if (packageServices == null) {
                 return null;
             }
             mFlags = flags;
             final boolean defaultOnly = (flags&PackageManager.MATCH_DEFAULT_ONLY) != 0;
-            int N = packageServices.size();
+            final int N = packageServices.size();
             ArrayList<ArrayList<PackageParser.ServiceIntentInfo>> listCut =
                 new ArrayList<ArrayList<PackageParser.ServiceIntentInfo>>(N);
 
@@ -4227,16 +4226,17 @@
 
         public final void addService(PackageParser.Service s) {
             mServices.put(s.getComponentName(), s);
-            if (SHOW_INFO || Config.LOGV) Log.v(
-                TAG, "  " + (s.info.nonLocalizedLabel != null
+            if (DEBUG_SHOW_INFO) {
+                Log.v(TAG, "  "
+                        + (s.info.nonLocalizedLabel != null
                         ? s.info.nonLocalizedLabel : s.info.name) + ":");
-            if (SHOW_INFO || Config.LOGV) Log.v(
-                    TAG, "    Class=" + s.info.name);
-            int NI = s.intents.size();
+                Log.v(TAG, "    Class=" + s.info.name);
+            }
+            final int NI = s.intents.size();
             int j;
             for (j=0; j<NI; j++) {
                 PackageParser.ServiceIntentInfo intent = s.intents.get(j);
-                if (SHOW_INFO || Config.LOGV) {
+                if (DEBUG_SHOW_INFO) {
                     Log.v(TAG, "    IntentFilter:");
                     intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
                 }
@@ -4249,16 +4249,16 @@
 
         public final void removeService(PackageParser.Service s) {
             mServices.remove(s.getComponentName());
-            if (SHOW_INFO || Config.LOGV) Log.v(
-                TAG, "  " + (s.info.nonLocalizedLabel != null
+            if (DEBUG_SHOW_INFO) {
+                Log.v(TAG, "  " + (s.info.nonLocalizedLabel != null
                         ? s.info.nonLocalizedLabel : s.info.name) + ":");
-            if (SHOW_INFO || Config.LOGV) Log.v(
-                    TAG, "    Class=" + s.info.name);
-            int NI = s.intents.size();
+                Log.v(TAG, "    Class=" + s.info.name);
+            }
+            final int NI = s.intents.size();
             int j;
             for (j=0; j<NI; j++) {
                 PackageParser.ServiceIntentInfo intent = s.intents.get(j);
-                if (SHOW_INFO || Config.LOGV) {
+                if (DEBUG_SHOW_INFO) {
                     Log.v(TAG, "    IntentFilter:");
                     intent.dump(new LogPrinter(Log.VERBOSE, TAG), "      ");
                 }
@@ -4485,13 +4485,12 @@
                     fullPathStr = fullPath.getPath();
                 }
 
-                if (Config.LOGV) Log.v(
-                    TAG, "File " + fullPathStr + " changed: "
-                    + Integer.toHexString(event));
+                if (DEBUG_APP_DIR_OBSERVER)
+                    Log.v(TAG, "File " + fullPathStr + " changed: " + Integer.toHexString(event));
 
                 if (!isPackageFilename(path)) {
-                    if (Config.LOGV) Log.v(
-                        TAG, "Ignoring change of non-package file: " + fullPathStr);
+                    if (DEBUG_APP_DIR_OBSERVER)
+                        Log.v(TAG, "Ignoring change of non-package file: " + fullPathStr);
                     return;
                 }
 
@@ -5743,11 +5742,6 @@
         boolean deletedPkg = true;
         boolean updatedSettings = false;
 
-        String oldInstallerPackageName = null;
-        synchronized (mPackages) {
-            oldInstallerPackageName = mSettings.getInstallerPackageName(pkgName);
-        }
-
         long origUpdateTime;
         if (pkg.mExtras != null) {
             origUpdateTime = ((PackageSetting)pkg.mExtras).lastUpdateTime;
@@ -6063,7 +6057,6 @@
     }
 
     private int setPermissionsLI(PackageParser.Package newPackage) {
-        String pkgName = newPackage.packageName;
         int retCode = 0;
         // TODO Gross hack but fix later. Ideally move this to be a post installation
         // check after alloting uid.
@@ -6093,9 +6086,8 @@
         }
 
         if (retCode != 0) {
-            Slog.e(TAG, "Couldn't set new package file permissions for " +
-                    newPackage.mPath
-                       + ". The return code was: " + retCode);
+            Slog.e(TAG, "Couldn't set new package file permissions for " + newPackage.mPath
+                    + ". The return code was: " + retCode);
             // TODO Define new internal error
             return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
         }
@@ -6740,14 +6732,12 @@
         return new ArrayList<PackageInfo>();
     }
 
-    int getUidTargetSdkVersionLockedLP(int uid) {
+    private int getUidTargetSdkVersionLockedLP(int uid) {
         Object obj = mSettings.getUserIdLP(uid);
         if (obj instanceof SharedUserSetting) {
-            SharedUserSetting sus = (SharedUserSetting)obj;
-            final int N = sus.packages.size();
+            final SharedUserSetting sus = (SharedUserSetting) obj;
             int vers = Build.VERSION_CODES.CUR_DEVELOPMENT;
-            Iterator<PackageSetting> it = sus.packages.iterator();
-            int i=0;
+            final Iterator<PackageSetting> it = sus.packages.iterator();
             while (it.hasNext()) {
                 PackageSetting ps = it.next();
                 if (ps.pkg != null) {
@@ -6757,7 +6747,7 @@
             }
             return vers;
         } else if (obj instanceof PackageSetting) {
-            PackageSetting ps = (PackageSetting)obj;
+            final PackageSetting ps = (PackageSetting) obj;
             if (ps.pkg != null) {
                 return ps.pkg.applicationInfo.targetSdkVersion;
             }
@@ -7013,8 +7003,9 @@
 
     private void sendPackageChangedBroadcast(String packageName,
             boolean killFlag, ArrayList<String> componentNames, int packageUid) {
-        if (false) Log.v(TAG, "Sending package changed: package=" + packageName
-                + " components=" + componentNames);
+        if (DEBUG_INSTALL)
+            Log.v(TAG, "Sending package changed: package=" + packageName + " components="
+                    + componentNames);
         Bundle extras = new Bundle(4);
         extras.putString(Intent.EXTRA_CHANGED_COMPONENT_NAME, componentNames.get(0));
         String nameList[] = new String[componentNames.size()];
@@ -8167,19 +8158,6 @@
             }
         }
 
-        String getInstallerPackageName(String pkgName) {
-            PackageSetting p = mPackages.get(pkgName);
-            return (p == null) ? null : p.getInstallerPackageName();
-        }
-
-        int getInstallStatus(String pkgName) {
-            PackageSetting p = mPackages.get(pkgName);
-            if(p != null) {
-                return p.getInstallStatus();
-            }
-            return -1;
-        }
-
         SharedUserSetting getSharedUserLP(String name,
                 int pkgFlags, boolean create) {
             SharedUserSetting s = mSharedUsers.get(name);
@@ -8617,7 +8595,7 @@
 
         public Object getUserIdLP(int uid) {
             if (uid >= FIRST_APPLICATION_UID) {
-                int N = mUserIds.size();
+                final int N = mUserIds.size();
                 final int index = uid - FIRST_APPLICATION_UID;
                 return index < N ? mUserIds.get(index) : null;
             } else {
@@ -8625,20 +8603,9 @@
             }
         }
 
-        private Set<String> findPackagesWithFlag(int flag) {
-            Set<String> ret = new HashSet<String>();
-            for (PackageSetting ps : mPackages.values()) {
-                // Has to match atleast all the flag bits set on flag
-                if ((ps.pkgFlags & flag) == flag) {
-                    ret.add(ps.name);
-                }
-            }
-            return ret;
-        }
-
         private void removeUserIdLP(int uid) {
             if (uid >= FIRST_APPLICATION_UID) {
-                int N = mUserIds.size();
+                final int N = mUserIds.size();
                 final int index = uid - FIRST_APPLICATION_UID;
                 if (index < N) mUserIds.set(index, null);
             } else {
@@ -8648,7 +8615,7 @@
 
         private void replaceUserIdLP(int uid, Object obj) {
             if (uid >= FIRST_APPLICATION_UID) {
-                int N = mUserIds.size();
+                final int N = mUserIds.size();
                 final int index = uid - FIRST_APPLICATION_UID;
                 if (index < N) mUserIds.set(index, obj);
             } else {
@@ -9183,10 +9150,6 @@
             }
         }
 
-        String getReadMessagesLP() {
-            return mReadMessages.toString();
-        }
-
         ArrayList<PackageSetting> getListOfIncompleteInstallPackages() {
             HashSet<String> kList = new HashSet<String>(mPackages.keySet());
             Iterator<String> its = kList.iterator();
@@ -9316,7 +9279,7 @@
 
             }
 
-            int N = mPendingPackages.size();
+            final int N = mPendingPackages.size();
             for (int i=0; i<N; i++) {
                 final PendingPackage pp = mPendingPackages.get(i);
                 Object idObj = getUserIdLP(pp.sharedId);
@@ -9943,7 +9906,7 @@
                 return true;
             }
             final PackageSetting packageSettings = mPackages.get(componentInfo.packageName);
-            if (Config.LOGV) {
+            if (DEBUG_SETTINGS) {
                 Log.v(TAG, "isEnabledLock - packageName = " + componentInfo.packageName
                            + " componentName = " + componentInfo.name);
                 Log.v(TAG, "enabledComponents: "
@@ -9952,11 +9915,6 @@
                            + Arrays.toString(packageSettings.disabledComponents.toArray()));
             }
             if (packageSettings == null) {
-                if (false) {
-                    Log.w(TAG, "WAITING FOR DEBUGGER");
-                    Debug.waitForDebugger();
-                    Log.i(TAG, "We will crash!");
-                }
                 return false;
             }
             if (packageSettings.enabled == COMPONENT_ENABLED_STATE_DISABLED
@@ -10283,7 +10241,6 @@
        ArrayList<SdInstallArgs> failedList = new ArrayList<SdInstallArgs>();
        final Set<SdInstallArgs> keys = processCids.keySet();
        for (SdInstallArgs args : keys) {
-           String cid = args.cid;
            String pkgName = args.getPackageName();
            if (DEBUG_SD_INSTALL) Log.i(TAG, "Trying to unload pkg : " + pkgName);
            // Delete package internally
diff --git a/telephony/java/com/android/internal/telephony/DataConnection.java b/telephony/java/com/android/internal/telephony/DataConnection.java
index 1f5fc05..b5578c3 100644
--- a/telephony/java/com/android/internal/telephony/DataConnection.java
+++ b/telephony/java/com/android/internal/telephony/DataConnection.java
@@ -219,6 +219,7 @@
     protected static final int EVENT_LOG_BAD_DNS_ADDRESS = 50100;
 
     //***** Member Variables
+    protected ApnSetting mApn;
     protected int mTag;
     protected PhoneBase phone;
     protected int cid;
@@ -429,11 +430,12 @@
     protected void clearSettings() {
         if (DBG) log("clearSettings");
 
-        this.createTime = -1;
-        this.lastFailTime = -1;
-        this.lastFailCause = FailCause.NONE;
+        createTime = -1;
+        lastFailTime = -1;
+        lastFailCause = FailCause.NONE;
 
         mLinkProperties = new LinkProperties();
+        mApn = null;
     }
 
     /**
@@ -1087,4 +1089,11 @@
     public FailCause getLastFailCause() {
         return lastFailCause;
     }
+
+    /**
+     * @return the current ApnSetting
+     */
+    public ApnSetting getApn() {
+        return mApn;
+    }
 }
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
index 7f0c7c7d8..d4a3c0a 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
@@ -441,7 +441,6 @@
     protected abstract void onRadioOffOrNotAvailable();
     protected abstract void onDataSetupComplete(AsyncResult ar);
     protected abstract void onDisconnectDone(int connId, AsyncResult ar);
-    protected abstract void onResetDone(AsyncResult ar);
     protected abstract void onVoiceCallStarted();
     protected abstract void onVoiceCallEnded();
     protected abstract void onCleanUpConnection(boolean tearDown, int apnId, String reason);
@@ -514,9 +513,10 @@
                 onSetInternalDataEnabled(enabled);
                 break;
             }
-            case EVENT_RESET_DONE:
+            case EVENT_RESET_DONE: {
                 onResetDone((AsyncResult) msg.obj);
                 break;
+            }
             case CMD_SET_DATA_ENABLE: {
                 log("CMD_SET_DATA_ENABLE msg=" + msg);
                 boolean enabled = (msg.arg1 == ENABLED) ? true : false;
@@ -602,6 +602,8 @@
 
     protected abstract void setState(State s);
 
+    protected abstract void gotoIdleAndNotifyDataConnection(String reason);
+
     protected LinkProperties getLinkProperties(String apnType) {
         int id = apnTypeToId(apnType);
         if (isApnIdEnabled(id)) {
@@ -873,6 +875,22 @@
     }
 
     /**
+     * Called when EVENT_RESET_DONE is received so goto
+     * IDLE state and send notifications to those interested.
+     *
+     * TODO - currently unused.  Needs to be hooked into DataConnection cleanup
+     * TODO - needs to pass some notion of which connection is reset..
+     */
+    protected void onResetDone(AsyncResult ar) {
+        if (DBG) log("EVENT_RESET_DONE");
+        String reason = null;
+        if (ar.userObj instanceof String) {
+            reason = (String) ar.userObj;
+        }
+        gotoIdleAndNotifyDataConnection(reason);
+    }
+
+    /**
      * Prevent mobile data connections from being established, or once again
      * allow mobile data connections. If the state toggles, then either tear
      * down or set up data, as appropriate to match the new state.
diff --git a/telephony/java/com/android/internal/telephony/RIL.java b/telephony/java/com/android/internal/telephony/RIL.java
index 88aed28..1d47405 100644
--- a/telephony/java/com/android/internal/telephony/RIL.java
+++ b/telephony/java/com/android/internal/telephony/RIL.java
@@ -207,9 +207,8 @@
  */
 public final class RIL extends BaseCommands implements CommandsInterface {
     static final String LOG_TAG = "RILJ";
-    private static final boolean DBG = false;
-    static final boolean RILJ_LOGD = Config.LOGD;
-    static final boolean RILJ_LOGV = DBG ? Config.LOGD : Config.LOGV;
+    static final boolean RILJ_LOGD = true;
+    static final boolean RILJ_LOGV = false; // STOP SHIP if true
 
     /**
      * Wake lock timeout should be longer than the longest timeout in
@@ -2069,7 +2068,7 @@
                 if (RILJ_LOGD) Log.d(LOG_TAG, "Radio ON @ init; reset to OFF");
                 setRadioPower(false, null);
             } else {
-                if (DBG) Log.d(LOG_TAG, "Radio OFF @ init");
+                if (RILJ_LOGD) Log.d(LOG_TAG, "Radio OFF @ init");
                 setRadioState(newState);
                 setPreferredNetworkType(mNetworkMode, null);
             }
@@ -2366,7 +2365,10 @@
             case RIL_REQUEST_GET_IMSI:
             case RIL_REQUEST_GET_IMEI:
             case RIL_REQUEST_GET_IMEISV:
-                return "";
+                if (!RILJ_LOGV) {
+                    // If not versbose logging just return and don't display IMSI and IMEI, IMEISV
+                    return "";
+                }
         }
 
         StringBuilder sb;
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnection.java b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnection.java
index 4f27e7f..cccc053 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnection.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnection.java
@@ -67,6 +67,7 @@
     protected void onConnect(ConnectionParams cp) {
         if (DBG) log("CdmaDataConnection Connecting...");
 
+        mApn = cp.apn;
         createTime = -1;
         lastFailTime = -1;
         lastFailCause = FailCause.NONE;
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
index 345d0d9..b244945 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaDataConnectionTracker.java
@@ -508,7 +508,7 @@
         notifyDataAvailability(null);
     }
 
-    private void gotoIdleAndNotifyDataConnection(String reason) {
+    protected void gotoIdleAndNotifyDataConnection(String reason) {
         if (DBG) log("gotoIdleAndNotifyDataConnection: reason=" + reason);
         setState(State.IDLE);
         notifyDataConnection(reason);
@@ -668,20 +668,6 @@
     }
 
     /**
-     * Called when EVENT_RESET_DONE is received so goto
-     * IDLE state and send notifications to those interested.
-     */
-    @Override
-    protected void onResetDone(AsyncResult ar) {
-      if (DBG) log("EVENT_RESET_DONE");
-      String reason = null;
-      if (ar.userObj instanceof String) {
-          reason = (String) ar.userObj;
-      }
-      gotoIdleAndNotifyDataConnection(reason);
-    }
-
-    /**
      * @override com.android.internal.telephony.DataConnectionTracker
      */
     @Override
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
index 344486a..b0b2ac5 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnection.java
@@ -36,8 +36,6 @@
     private static final String LOG_TAG = "GSM";
 
     //***** Instance Variables
-    private ApnSetting apn;
-
     protected int mProfileId = RILConstants.DATA_PROFILE_DEFAULT;
     protected String mActiveApnType = Phone.APN_TYPE_DEFAULT;
     //***** Constructor
@@ -74,13 +72,13 @@
     @Override
     protected
     void onConnect(ConnectionParams cp) {
-        apn = cp.apn;
+        mApn = cp.apn;
 
-        if (DBG) log("Connecting to carrier: '" + apn.carrier
-                + "' APN: '" + apn.apn
-                + "' proxy: '" + apn.proxy + "' port: '" + apn.port);
+        if (DBG) log("Connecting to carrier: '" + mApn.carrier
+                + "' APN: '" + mApn.apn
+                + "' proxy: '" + mApn.proxy + "' port: '" + mApn.port);
 
-        setHttpProxy (apn.proxy, apn.port);
+        setHttpProxy (mApn.proxy, mApn.port);
 
         createTime = -1;
         lastFailTime = -1;
@@ -90,23 +88,23 @@
         Message msg = obtainMessage(EVENT_SETUP_DATA_CONNECTION_DONE, cp);
         msg.obj = cp;
 
-        int authType = apn.authType;
+        int authType = mApn.authType;
         if (authType == -1) {
-            authType = (apn.user != null) ? RILConstants.SETUP_DATA_AUTH_PAP_CHAP :
+            authType = (mApn.user != null) ? RILConstants.SETUP_DATA_AUTH_PAP_CHAP :
                 RILConstants.SETUP_DATA_AUTH_NONE;
         }
 
         String protocol;
         if (phone.getServiceState().getRoaming()) {
-            protocol = apn.roamingProtocol;
+            protocol = mApn.roamingProtocol;
         } else {
-            protocol = apn.protocol;
+            protocol = mApn.protocol;
         }
 
         phone.mCM.setupDataCall(
                 Integer.toString(RILConstants.SETUP_DATA_TECH_GSM),
                 Integer.toString(mProfileId),
-                apn.apn, apn.user, apn.password,
+                mApn.apn, mApn.user, mApn.password,
                 Integer.toString(authType),
                 protocol, msg);
     }
@@ -129,14 +127,8 @@
     }
 
     @Override
-    protected void clearSettings() {
-        super.clearSettings();
-        apn = null;
-    }
-
-    @Override
     public String toString() {
-        return "State=" + getCurrentState().getName() + " Apn=" + apn +
+        return "State=" + getCurrentState().getName() + " Apn=" + mApn +
                " create=" + createTime + " lastFail=" + lastFailTime +
                " lastFailCause=" + lastFailCause;
     }
@@ -150,11 +142,12 @@
             // Do not apply the race condition workaround for MMS APN
             // if Proxy is an IP-address.
             // Otherwise, the default APN will not be restored anymore.
-            if (!apn.types[0].equals(Phone.APN_TYPE_MMS)
-                || !isIpAddress(apn.mmsProxy)) {
+            if (!mApn.types[0].equals(Phone.APN_TYPE_MMS)
+                || !isIpAddress(mApn.mmsProxy)) {
                 log(String.format(
                         "isDnsOk: return false apn.types[0]=%s APN_TYPE_MMS=%s isIpAddress(%s)=%s",
-                        apn.types[0], Phone.APN_TYPE_MMS, apn.mmsProxy, isIpAddress(apn.mmsProxy)));
+                        mApn.types[0], Phone.APN_TYPE_MMS, mApn.mmsProxy,
+                        isIpAddress(mApn.mmsProxy)));
                 return false;
             }
         }
@@ -166,15 +159,11 @@
         Log.d(LOG_TAG, "[" + getName() + "] " + s);
     }
 
-    public ApnSetting getApn() {
-        return this.apn;
-    }
-
     private void setHttpProxy(String httpProxy, String httpPort) {
 
         if (DBG) log("set http proxy for"
                 + "' APN: '" + mActiveApnType
-                + "' proxy: '" + apn.proxy + "' port: '" + apn.port);
+                + "' proxy: '" + mApn.proxy + "' port: '" + mApn.port);
         if(TextUtils.equals(mActiveApnType, Phone.APN_TYPE_DEFAULT)) {
             if (httpProxy == null || httpProxy.length() == 0) {
                 phone.setSystemProperty("net.gprs.http-proxy", null);
@@ -205,6 +194,6 @@
     private boolean isIpAddress(String address) {
         if (address == null) return false;
 
-        return Patterns.IP_ADDRESS.matcher(apn.mmsProxy).matches();
+        return Patterns.IP_ADDRESS.matcher(address).matches();
     }
 }
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
index 0f62907..d602c38 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
@@ -757,20 +757,19 @@
             return;
         }
 
-        GsmDataConnection pdp = apnContext.getDataConnection();
-        if (tearDown && pdp!=null) {
+        GsmDataConnection conn = apnContext.getDataConnection();
+        if (conn != null) {
             apnContext.setState(State.DISCONNECTING);
-            Message msg = obtainMessage(EVENT_DISCONNECT_DONE, apnContext);
-            pdp.disconnect(msg);
-            return;
-        } else if (pdp != null) {
-            pdp.clearSettings();
+            if (tearDown ) {
+                Message msg = obtainMessage(EVENT_DISCONNECT_DONE, apnContext);
+                conn.disconnect(msg);
+            } else {
+                conn.resetSynchronously();
+                apnContext.setState(State.IDLE);
+                mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
+            }
         }
 
-        if (!tearDown) {
-            apnContext.setState(State.IDLE);
-            mPhone.notifyDataConnection(apnContext.getReason(), apnContext.getApnType());
-        }
         if (apnContext.getPendingAction() == ApnContext.PENDING_ACTION_APN_DISABLE) {
            mApnContexts.remove(apnContext.getApnType());
         }
@@ -1036,7 +1035,7 @@
     }
 
     // TODO: For multiple Active APNs not exactly sure how to do this.
-    private void gotoIdleAndNotifyDataConnection(String reason) {
+    protected void gotoIdleAndNotifyDataConnection(String reason) {
         if (DBG) log("gotoIdleAndNotifyDataConnection: reason=" + reason);
         notifyDataConnection(reason);
         mActiveApn = null;
@@ -1528,19 +1527,6 @@
         }
     }
 
-    /**
-     * Called when EVENT_RESET_DONE is received.
-     */
-    @Override
-    protected void onResetDone(AsyncResult ar) {
-        if (DBG) log("EVENT_RESET_DONE");
-        String reason = null;
-        if (ar.userObj instanceof String) {
-            reason = (String) ar.userObj;
-        }
-        gotoIdleAndNotifyDataConnection(reason);
-    }
-
     protected void onPollPdp() {
         if (getOverallState() == State.CONNECTED) {
             // only poll when connected