resolved conflicts for merge of 2ecce34f to master

Change-Id: Ic4e38199beaf8c16f9d28ac5296e8aaa61788b36
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index b6064e8..a437d95 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -3516,7 +3516,7 @@
             if (DEBUG_TASKS) Slog.v(TAG, "Starting new activity " + r
                     + " in new task " + r.task);
             newTask = true;
-            addRecentTask(r.task);
+            addRecentTaskLocked(r.task);
             
         } else if (sourceRecord != null) {
             if (!addingToTask &&
@@ -3891,7 +3891,7 @@
         }
     }
 
-    private final void addRecentTask(TaskRecord task) {
+    private final void addRecentTaskLocked(TaskRecord task) {
         // Remove any existing entries that are the same kind of task.
         int N = mRecentTasks.size();
         for (int i=0; i<N; i++) {
@@ -4939,9 +4939,11 @@
                 Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED,
                         Uri.fromParts("package", packageName, null));
                 intent.putExtra(Intent.EXTRA_UID, pkgUid);
-                broadcastIntentLocked(null, null, intent,
-                        null, null, 0, null, null, null,
-                        false, false, MY_PID, Process.SYSTEM_UID);
+                synchronized (this) {
+                    broadcastIntentLocked(null, null, intent,
+                            null, null, 0, null, null, null,
+                            false, false, MY_PID, Process.SYSTEM_UID);
+                }
             } catch (RemoteException e) {
             }
         } finally {
@@ -7001,7 +7003,7 @@
                             taskTopI = -1;
                         }
                         replyChainEnd = -1;
-                        addRecentTask(target.task);
+                        addRecentTaskLocked(target.task);
                     } else if (forceReset || finishOnTaskLaunch
                             || clearWhenTaskReset) {
                         // If the activity should just be removed -- either
@@ -7223,7 +7225,7 @@
                 moved.add(0, r);
                 top--;
                 if (first) {
-                    addRecentTask(r.task);
+                    addRecentTaskLocked(r.task);
                     first = false;
                 }
             }
@@ -7248,11 +7250,11 @@
             mWindowManager.validateAppTokens(mHistory);
         }
 
-        finishTaskMove(task);
+        finishTaskMoveLocked(task);
         EventLog.writeEvent(EventLogTags.AM_TASK_TO_FRONT, task);
     }
 
-    private final void finishTaskMove(int task) {
+    private final void finishTaskMoveLocked(int task) {
         resumeTopActivityLocked(null);
     }
 
@@ -7370,7 +7372,7 @@
             mWindowManager.validateAppTokens(mHistory);
         }
 
-        finishTaskMove(task);
+        finishTaskMoveLocked(task);
         return true;
     }
 
@@ -8002,19 +8004,24 @@
     }
 
     public static final void installSystemProviders() {
-        ProcessRecord app = mSelf.mProcessNames.get("system", Process.SYSTEM_UID);
-        List providers = mSelf.generateApplicationProvidersLocked(app);
-        if (providers != null) {
-            for (int i=providers.size()-1; i>=0; i--) {
-                ProviderInfo pi = (ProviderInfo)providers.get(i);
-                if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
-                    Slog.w(TAG, "Not installing system proc provider " + pi.name
-                            + ": not system .apk");
-                    providers.remove(i);
+        List providers;
+        synchronized (mSelf) {
+            ProcessRecord app = mSelf.mProcessNames.get("system", Process.SYSTEM_UID);
+            providers = mSelf.generateApplicationProvidersLocked(app);
+            if (providers != null) {
+                for (int i=providers.size()-1; i>=0; i--) {
+                    ProviderInfo pi = (ProviderInfo)providers.get(i);
+                    if ((pi.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
+                        Slog.w(TAG, "Not installing system proc provider " + pi.name
+                                + ": not system .apk");
+                        providers.remove(i);
+                    }
                 }
             }
         }
-        mSystemThread.installSystemProviders(providers);
+        if (providers != null) {
+            mSystemThread.installSystemProviders(providers);
+        }
     }
 
     // =========================================================
@@ -8297,11 +8304,15 @@
     }
     
     public void registerActivityWatcher(IActivityWatcher watcher) {
-        mWatchers.register(watcher);
+        synchronized (this) {
+            mWatchers.register(watcher);
+        }
     }
 
     public void unregisterActivityWatcher(IActivityWatcher watcher) {
-        mWatchers.unregister(watcher);
+        synchronized (this) {
+            mWatchers.unregister(watcher);
+        }
     }
 
     public final void enterSafeMode() {
@@ -11937,7 +11948,7 @@
     // BROADCASTS
     // =========================================================
 
-    private final List getStickies(String action, IntentFilter filter,
+    private final List getStickiesLocked(String action, IntentFilter filter,
             List cur) {
         final ContentResolver resolver = mContext.getContentResolver();
         final ArrayList<Intent> list = mStickyBroadcasts.get(action);
@@ -11989,10 +12000,10 @@
             if (actions != null) {
                 while (actions.hasNext()) {
                     String action = (String)actions.next();
-                    allSticky = getStickies(action, filter, allSticky);
+                    allSticky = getStickiesLocked(action, filter, allSticky);
                 }
             } else {
-                allSticky = getStickies(null, filter, allSticky);
+                allSticky = getStickiesLocked(null, filter, allSticky);
             }
 
             // The first sticky in the list is returned directly back to
@@ -13840,7 +13851,7 @@
     /**
      * Returns true if things are idle enough to perform GCs.
      */
-    private final boolean canGcNow() {
+    private final boolean canGcNowLocked() {
         return mParallelBroadcasts.size() == 0
                 && mOrderedBroadcasts.size() == 0
                 && (mSleeping || (mResumedActivity != null &&
@@ -13856,7 +13867,7 @@
         if (N <= 0) {
             return;
         }
-        if (canGcNow()) {
+        if (canGcNowLocked()) {
             while (mProcessesToGc.size() > 0) {
                 ProcessRecord proc = mProcessesToGc.remove(0);
                 if (proc.curRawAdj > VISIBLE_APP_ADJ || proc.reportLowMemory) {
@@ -13884,7 +13895,7 @@
      * If all looks good, perform GCs on all processes waiting for them.
      */
     final void performAppGcsIfAppropriateLocked() {
-        if (canGcNow()) {
+        if (canGcNowLocked()) {
             performAppGcsLocked();
             return;
         }