Search in sources :

Example 6 with IContentProvider

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

the class ActivityThread method acquireExistingProvider.

public final IContentProvider acquireExistingProvider(Context c, String name) {
    IContentProvider provider = getExistingProvider(c, name);
    if (provider == null)
        return null;
    IBinder jBinder = provider.asBinder();
    synchronized (mProviderMap) {
        ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
        if (prc == null) {
            mProviderRefCountMap.put(jBinder, new ProviderRefCount(1));
        } else {
            prc.count++;
        }
    //end else
    }
    //end synchronized
    return provider;
}
Also used : IBinder(android.os.IBinder) IContentProvider(android.content.IContentProvider)

Example 7 with IContentProvider

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

the class ActivityThread method installContentProviders.

private void installContentProviders(Context context, List<ProviderInfo> providers) {
    final ArrayList<IActivityManager.ContentProviderHolder> results = new ArrayList<IActivityManager.ContentProviderHolder>();
    Iterator<ProviderInfo> i = providers.iterator();
    while (i.hasNext()) {
        ProviderInfo cpi = i.next();
        StringBuilder buf = new StringBuilder(128);
        buf.append("Pub ");
        buf.append(cpi.authority);
        buf.append(": ");
        buf.append(cpi.name);
        Log.i(TAG, buf.toString());
        IContentProvider cp = installProvider(context, null, cpi, false);
        if (cp != null) {
            IActivityManager.ContentProviderHolder cph = new IActivityManager.ContentProviderHolder(cpi);
            cph.provider = cp;
            results.add(cph);
            // Don't ever unload this provider from the process.
            synchronized (mProviderMap) {
                mProviderRefCountMap.put(cp.asBinder(), new ProviderRefCount(10000));
            }
        }
    }
    try {
        ActivityManagerNative.getDefault().publishContentProviders(getApplicationThread(), results);
    } catch (RemoteException ex) {
    }
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) IContentProvider(android.content.IContentProvider) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException)

Example 8 with IContentProvider

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

the class ActivityThread method getProvider.

private IContentProvider getProvider(Context context, String name) {
    IContentProvider existing = getExistingProvider(context, name);
    if (existing != null) {
        return existing;
    }
    IActivityManager.ContentProviderHolder holder = null;
    try {
        holder = ActivityManagerNative.getDefault().getContentProvider(getApplicationThread(), name);
    } catch (RemoteException ex) {
    }
    if (holder == null) {
        Slog.e(TAG, "Failed to find provider info for " + name);
        return null;
    }
    IContentProvider prov = installProvider(context, holder.provider, holder.info, true);
    //Slog.i(TAG, "noReleaseNeeded=" + holder.noReleaseNeeded);
    if (holder.noReleaseNeeded || holder.provider == null) {
        //Slog.i(TAG, "*** NO RELEASE NEEDED");
        synchronized (mProviderMap) {
            mProviderRefCountMap.put(prov.asBinder(), new ProviderRefCount(10000));
        }
    }
    return prov;
}
Also used : IContentProvider(android.content.IContentProvider) RemoteException(android.os.RemoteException)

Example 9 with IContentProvider

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

the class ShellUiAutomatorBridge method getSystemLongPressTime.

public long getSystemLongPressTime() {
    // Read the long press timeout setting.
    long longPressTimeout = 0;
    try {
        IContentProvider provider = null;
        Cursor cursor = null;
        IActivityManager activityManager = ActivityManagerNative.getDefault();
        String providerName = Settings.Secure.CONTENT_URI.getAuthority();
        IBinder token = new Binder();
        try {
            ContentProviderHolder holder = activityManager.getContentProviderExternal(providerName, UserHandle.USER_SYSTEM, token);
            if (holder == null) {
                throw new IllegalStateException("Could not find provider: " + providerName);
            }
            provider = holder.provider;
            cursor = provider.query(null, Settings.Secure.CONTENT_URI, new String[] { Settings.Secure.VALUE }, "name=?", new String[] { Settings.Secure.LONG_PRESS_TIMEOUT }, null, null);
            if (cursor.moveToFirst()) {
                longPressTimeout = cursor.getInt(0);
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (provider != null) {
                activityManager.removeContentProviderExternal(providerName, token);
            }
        }
    } catch (RemoteException e) {
        String message = "Error reading long press timeout setting.";
        Log.e(LOG_TAG, message, e);
        throw new RuntimeException(message, e);
    }
    return longPressTimeout;
}
Also used : IBinder(android.os.IBinder) Binder(android.os.Binder) IBinder(android.os.IBinder) IContentProvider(android.content.IContentProvider) ContentProviderHolder(android.app.IActivityManager.ContentProviderHolder) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 10 with IContentProvider

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

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);
        } finally {
            Binder.restoreCallingIdentity(ident);
        }
    }
}
Also used : IContentProvider(android.content.IContentProvider)

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