Search in sources :

Example 1 with IContentProvider

use of android.content.IContentProvider in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method acquireProvider.

public final IContentProvider acquireProvider(Context c, String auth, int userId, boolean stable) {
    final IContentProvider provider = acquireExistingProvider(c, auth, userId, stable);
    if (provider != null) {
        return provider;
    }
    // There is a possible race here.  Another thread may try to acquire
    // the same provider at the same time.  When this happens, we want to ensure
    // that the first one wins.
    // Note that we cannot hold the lock while acquiring and installing the
    // provider since it might take a long time to run and it could also potentially
    // be re-entrant in the case where the provider is in the same process.
    IActivityManager.ContentProviderHolder holder = null;
    try {
        holder = ActivityManagerNative.getDefault().getContentProvider(getApplicationThread(), auth, userId, stable);
    } catch (RemoteException ex) {
    }
    if (holder == null) {
        Slog.e(TAG, "Failed to find provider info for " + auth);
        return null;
    }
    // Install provider will increment the reference count for us, and break
    // any ties in the race.
    holder = installProvider(c, holder, holder.info, true, /*noisy*/
    holder.noReleaseNeeded, stable);
    return holder.provider;
}
Also used : IContentProvider(android.content.IContentProvider) RemoteException(android.os.RemoteException)

Example 2 with IContentProvider

use of android.content.IContentProvider in project android_frameworks_base by ParanoidAndroid.

the class ActivityManagerService method unstableProviderDied.

public void unstableProviderDied(IBinder connection) {
    ContentProviderConnection conn;
    try {
        conn = (ContentProviderConnection) connection;
    } catch (ClassCastException e) {
        String msg = "refContentProvider: " + connection + " not a ContentProviderConnection";
        Slog.w(TAG, msg);
        throw new IllegalArgumentException(msg);
    }
    if (conn == null) {
        throw new NullPointerException("connection is null");
    }
    // Safely retrieve the content provider associated with the connection.
    IContentProvider provider;
    synchronized (this) {
        provider = conn.provider.provider;
    }
    if (provider == null) {
        // Um, yeah, we're way ahead of you.
        return;
    }
    // Make sure the caller is being honest with us.
    if (provider.asBinder().pingBinder()) {
        // Er, no, still looks good to us.
        synchronized (this) {
            Slog.w(TAG, "unstableProviderDied: caller " + Binder.getCallingUid() + " says " + conn + " died, but we don't agree");
            return;
        }
    }
    // Well look at that!  It's dead!
    synchronized (this) {
        if (conn.provider.provider != provider) {
            // But something changed...  good enough.
            return;
        }
        ProcessRecord proc = conn.provider.proc;
        if (proc == null || proc.thread == null) {
            // Seems like the process is already cleaned up.
            return;
        }
        // As far as we're concerned, this is just like receiving a
        // death notification...  just a bit prematurely.
        Slog.i(TAG, "Process " + proc.processName + " (pid " + proc.pid + ") early provider death");
        final long ident = Binder.clearCallingIdentity();
        try {
            appDiedLocked(proc, proc.pid, proc.thread);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
}
Also used : IContentProvider(android.content.IContentProvider)

Example 3 with IContentProvider

use of android.content.IContentProvider in project cornerstone by Onskreen.

the class ActivityManagerService method unstableProviderDied.

public void unstableProviderDied(IBinder connection) {
    ContentProviderConnection conn;
    try {
        conn = (ContentProviderConnection) connection;
    } catch (ClassCastException e) {
        String msg = "refContentProvider: " + connection + " not a ContentProviderConnection";
        Slog.w(TAG, msg);
        throw new IllegalArgumentException(msg);
    }
    if (conn == null) {
        throw new NullPointerException("connection is null");
    }
    // Safely retrieve the content provider associated with the connection.
    IContentProvider provider;
    synchronized (this) {
        provider = conn.provider.provider;
    }
    if (provider == null) {
        // Um, yeah, we're way ahead of you.
        return;
    }
    // Make sure the caller is being honest with us.
    if (provider.asBinder().pingBinder()) {
        // Er, no, still looks good to us.
        synchronized (this) {
            Slog.w(TAG, "unstableProviderDied: caller " + Binder.getCallingUid() + " says " + conn + " died, but we don't agree");
            return;
        }
    }
    // Well look at that!  It's dead!
    synchronized (this) {
        if (conn.provider.provider != provider) {
            // But something changed...  good enough.
            return;
        }
        ProcessRecord proc = conn.provider.proc;
        if (proc == null || proc.thread == null) {
            // Seems like the process is already cleaned up.
            return;
        }
        // As far as we're concerned, this is just like receiving a
        // death notification...  just a bit prematurely.
        Slog.i(TAG, "Process " + proc.processName + " (pid " + proc.pid + ") early provider death");
        final long ident = Binder.clearCallingIdentity();
        try {
            appDiedLocked(proc, proc.pid, proc.thread);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
}
Also used : IContentProvider(android.content.IContentProvider)

Example 4 with IContentProvider

use of android.content.IContentProvider in project platform_frameworks_base by android.

the class ActivityThread method acquireExistingProvider.

public final IContentProvider acquireExistingProvider(Context c, String auth, int userId, boolean stable) {
    synchronized (mProviderMap) {
        final ProviderKey key = new ProviderKey(auth, userId);
        final ProviderClientRecord pr = mProviderMap.get(key);
        if (pr == null) {
            return null;
        }
        IContentProvider provider = pr.mProvider;
        IBinder jBinder = provider.asBinder();
        if (!jBinder.isBinderAlive()) {
            // The hosting process of the provider has died; we can't
            // use this one.
            Log.i(TAG, "Acquiring provider " + auth + " for user " + userId + ": existing object's process dead");
            handleUnstableProviderDiedLocked(jBinder, true);
            return null;
        }
        // Only increment the ref count if we have one.  If we don't then the
        // provider is not reference counted and never needs to be released.
        ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
        if (prc != null) {
            incProviderRefLocked(prc, stable);
        }
        return provider;
    }
}
Also used : IBinder(android.os.IBinder) IContentProvider(android.content.IContentProvider)

Example 5 with IContentProvider

use of android.content.IContentProvider in project XobotOS by xamarin.

the class ActivityThread method installProvider.

private IContentProvider installProvider(Context context, IContentProvider provider, ProviderInfo info, boolean noisy) {
    ContentProvider localProvider = null;
    if (provider == null) {
        if (noisy) {
            Slog.d(TAG, "Loading provider " + info.authority + ": " + info.name);
        }
        Context c = null;
        ApplicationInfo ai = info.applicationInfo;
        if (context.getPackageName().equals(ai.packageName)) {
            c = context;
        } else if (mInitialApplication != null && mInitialApplication.getPackageName().equals(ai.packageName)) {
            c = mInitialApplication;
        } else {
            try {
                c = context.createPackageContext(ai.packageName, Context.CONTEXT_INCLUDE_CODE);
            } catch (PackageManager.NameNotFoundException e) {
            // Ignore
            }
        }
        if (c == null) {
            Slog.w(TAG, "Unable to get context for package " + ai.packageName + " while loading content provider " + info.name);
            return null;
        }
        try {
            final java.lang.ClassLoader cl = c.getClassLoader();
            localProvider = (ContentProvider) cl.loadClass(info.name).newInstance();
            provider = localProvider.getIContentProvider();
            if (provider == null) {
                Slog.e(TAG, "Failed to instantiate class " + info.name + " from sourceDir " + info.applicationInfo.sourceDir);
                return null;
            }
            if (false)
                Slog.v(TAG, "Instantiating local provider " + info.name);
            // XXX Need to create the correct context for this provider.
            localProvider.attachInfo(c, info);
        } catch (java.lang.Exception e) {
            if (!mInstrumentation.onException(null, e)) {
                throw new RuntimeException("Unable to get provider " + info.name + ": " + e.toString(), e);
            }
            return null;
        }
    } else if (localLOGV) {
        Slog.v(TAG, "Installing external provider " + info.authority + ": " + info.name);
    }
    synchronized (mProviderMap) {
        // Cache the pointer for the remote provider.
        String[] names = PATTERN_SEMICOLON.split(info.authority);
        for (int i = 0; i < names.length; i++) {
            ProviderClientRecord pr = new ProviderClientRecord(names[i], provider, localProvider);
            try {
                provider.asBinder().linkToDeath(pr, 0);
                mProviderMap.put(names[i], pr);
            } catch (RemoteException e) {
                return null;
            }
        }
        if (localProvider != null) {
            mLocalProviders.put(provider.asBinder(), new ProviderClientRecord(null, provider, localProvider));
        }
    }
    return provider;
}
Also used : Context(android.content.Context) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) ApplicationInfo(android.content.pm.ApplicationInfo) AndroidRuntimeException(android.util.AndroidRuntimeException) RemoteException(android.os.RemoteException)

Aggregations

IContentProvider (android.content.IContentProvider)38 RemoteException (android.os.RemoteException)26 IBinder (android.os.IBinder)25 IActivityManager (android.app.IActivityManager)11 ContentProviderHolder (android.app.IActivityManager.ContentProviderHolder)11 Binder (android.os.Binder)11 ContentProvider (android.content.ContentProvider)7 Context (android.content.Context)7 ApplicationInfo (android.content.pm.ApplicationInfo)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 AndroidRuntimeException (android.util.AndroidRuntimeException)7 ComponentName (android.content.ComponentName)6 Cursor (android.database.Cursor)5 ProviderInfo (android.content.pm.ProviderInfo)1 java.lang (java.lang)1 ArrayList (java.util.ArrayList)1