Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66a017b6 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Always give ContentResolver a valid Context.

Also add MockContentResolver constructor to provide a Context, and
move to singleton ActivityThread, since there is only one inside
each process.  This makes ActivityThread accessible from threads like
InstrumentationThread.

Change-Id: Ib8b18f1b9bba8820ff412d782a43511066eabf24
parent 54781207
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21512,6 +21512,7 @@ package android.test.mock {
  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);
  }
+4 −3
Original line number Diff line number Diff line
@@ -187,7 +187,8 @@ public final class ActivityThread {
            = 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 final class ActivityThread {
    }

    public static ActivityThread currentActivityThread() {
        return sThreadLocal.get();
        return sCurrentActivityThread;
    }

    public static String currentPackageName() {
@@ -4894,7 +4895,7 @@ public final class ActivityThread {
    }

    private void attach(boolean system) {
        sThreadLocal.set(this);
        sCurrentActivityThread = this;
        mSystemThread = system;
        if (!system) {
            ViewRootImpl.addFirstDrawHandler(new Runnable() {
+3 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import dalvik.system.CloseGuard;

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 @@ public abstract class ContentResolver {
    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 */
+12 −4
Original line number Diff line number Diff line
@@ -54,12 +54,20 @@ import java.util.Map;
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();
    }