Merge changes Ib8b18f1b,I0d799d82,Ia6222322

* changes:
  Always give ContentResolver a valid Context.
  Define failed connections column, and reset.
  Add method to get process group.
diff --git a/api/current.txt b/api/current.txt
index ac367f6..d367a00 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -21512,6 +21512,7 @@
 
   public class MockContentResolver extends android.content.ContentResolver {
     ctor public MockContentResolver();
+    ctor public MockContentResolver(android.content.Context);
     method public void addProvider(java.lang.String, android.content.ContentProvider);
   }
 
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 60d4363..12716456 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -187,7 +187,8 @@
             = new ArrayList<Application>();
     // set of instantiated backup agents, keyed by package name
     final HashMap<String, BackupAgent> mBackupAgents = new HashMap<String, BackupAgent>();
-    static final ThreadLocal<ActivityThread> sThreadLocal = new ThreadLocal<ActivityThread>();
+    /** Reference to singleton {@link ActivityThread} */
+    private static ActivityThread sCurrentActivityThread;
     Instrumentation mInstrumentation;
     String mInstrumentationAppDir = null;
     String mInstrumentationAppLibraryDir = null;
@@ -1564,7 +1565,7 @@
     }
 
     public static ActivityThread currentActivityThread() {
-        return sThreadLocal.get();
+        return sCurrentActivityThread;
     }
 
     public static String currentPackageName() {
@@ -4894,7 +4895,7 @@
     }
 
     private void attach(boolean system) {
-        sThreadLocal.set(this);
+        sCurrentActivityThread = this;
         mSystemThread = system;
         if (!system) {
             ViewRootImpl.addFirstDrawHandler(new Runnable() {
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
index 32e40ee..26dc60d 100644
--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -1085,6 +1085,7 @@
         values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, -1);
         values.putNull(Downloads.Impl._DATA);
         values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_PENDING);
+        values.put(Downloads.Impl.COLUMN_FAILED_CONNECTIONS, 0);
         mResolver.update(mBaseUri, values, getWhereClauseForIds(ids), getWhereArgsForIds(ids));
     }
 
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index 51c9aa5..fb73529 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -20,6 +20,7 @@
 
 import android.accounts.Account;
 import android.app.ActivityManagerNative;
+import android.app.ActivityThread;
 import android.app.AppGlobals;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.AssetFileDescriptor;
@@ -206,8 +207,8 @@
     private final Random mRandom = new Random();  // guarded by itself
 
     public ContentResolver(Context context) {
-        mContext = context;
-        mPackageName = context.getPackageName();
+        mContext = context != null ? context : ActivityThread.currentApplication();
+        mPackageName = mContext.getPackageName();
     }
 
     /** @hide */
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 05099fb..facab4c 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -806,7 +806,15 @@
      */
     public static final native void setProcessGroup(int pid, int group)
             throws IllegalArgumentException, SecurityException;
-    
+
+    /**
+     * Return the scheduling group of requested process.
+     *
+     * @hide
+     */
+    public static final native int getProcessGroup(int pid)
+            throws IllegalArgumentException, SecurityException;
+
     /**
      * Set the priority of the calling thread, based on Linux priorities.  See
      * {@link #setThreadPriority(int, int)} for more information.
diff --git a/core/java/android/provider/Downloads.java b/core/java/android/provider/Downloads.java
index 31ad12b..9999760 100644
--- a/core/java/android/provider/Downloads.java
+++ b/core/java/android/provider/Downloads.java
@@ -407,6 +407,9 @@
          */
         public static final String COLUMN_LAST_UPDATESRC = "lastUpdateSrc";
 
+        /** The column that is used to count retries */
+        public static final String COLUMN_FAILED_CONNECTIONS = "numfailed";
+
         /**
          * default value for {@link #COLUMN_LAST_UPDATESRC}.
          * This value is used when this column's value is not relevant.
diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp
index 0290857..5d32328 100644
--- a/core/jni/android_util_Process.cpp
+++ b/core/jni/android_util_Process.cpp
@@ -268,6 +268,15 @@
     closedir(d);
 }
 
+jint android_os_Process_getProcessGroup(JNIEnv* env, jobject clazz, jint pid)
+{
+    SchedPolicy sp;
+    if (get_sched_policy(pid, &sp) != 0) {
+        signalExceptionForGroupError(env, errno);
+    }
+    return (int) sp;
+}
+
 static void android_os_Process_setCanSelfBackground(JNIEnv* env, jobject clazz, jboolean bgOk) {
     // Establishes the calling thread as illegal to put into the background.
     // Typically used only for the system process's main looper.
@@ -991,7 +1000,8 @@
     {"setThreadPriority",   "(I)V", (void*)android_os_Process_setCallingThreadPriority},
     {"getThreadPriority",   "(I)I", (void*)android_os_Process_getThreadPriority},
     {"setThreadGroup",      "(II)V", (void*)android_os_Process_setThreadGroup},
-    {"setProcessGroup",      "(II)V", (void*)android_os_Process_setProcessGroup},
+    {"setProcessGroup",     "(II)V", (void*)android_os_Process_setProcessGroup},
+    {"getProcessGroup",     "(I)I", (void*)android_os_Process_getProcessGroup},
     {"setOomAdj",   "(II)Z", (void*)android_os_Process_setOomAdj},
     {"setArgV0",    "(Ljava/lang/String;)V", (void*)android_os_Process_setArgV0},
     {"setUid", "(I)I", (void*)android_os_Process_setUid},
diff --git a/test-runner/src/android/test/mock/MockContentResolver.java b/test-runner/src/android/test/mock/MockContentResolver.java
index 715da0f..aec6c77 100644
--- a/test-runner/src/android/test/mock/MockContentResolver.java
+++ b/test-runner/src/android/test/mock/MockContentResolver.java
@@ -54,12 +54,20 @@
 public class MockContentResolver extends ContentResolver {
     Map<String, ContentProvider> mProviders;
 
-    /*
-     * Creates a local map of providers. This map is used instead of the global map when an
-     * API call tries to acquire a provider.
+    /**
+     * Creates a local map of providers. This map is used instead of the global
+     * map when an API call tries to acquire a provider.
      */
     public MockContentResolver() {
-        super(null);
+        this(null);
+    }
+
+    /**
+     * Creates a local map of providers. This map is used instead of the global
+     * map when an API call tries to acquire a provider.
+     */
+    public MockContentResolver(Context context) {
+        super(context);
         mProviders = Maps.newHashMap();
     }