android.content.IContentProvider Java Examples

The following examples show how to use android.content.IContentProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ContentResolverProxy.java    From GPT with Apache License 2.0 6 votes vote down vote up
/**
 * acquireUnstableProvider
 *
 * @param context Context
 * @param name    name
 * @return IContentProvider
 */
protected IContentProvider acquireUnstableProvider(Context context, String name) {

    IContentProvider result = null;

    context = Util.getHostContext(context);
    ContentProviderHolder holder = ActivityManagerNativeWorker.getContentProviderHolder(context, name);
    if (holder != null && holder.provider != null) {
        result = holder.provider;
    }

    if (result == null) {
        result = JavaCalls.callMethod(mHostContentResolver, "acquireUnstableProvider", context, name);
    }
    return result;
}
 
Example #2
Source File: SettingsService.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
void resetForUser(IContentProvider provider, int userHandle,
        String table, String tag) {
    final String callResetCommand;
    if ("secure".equals(table)) callResetCommand = Settings.CALL_METHOD_RESET_SECURE;
    else if ("global".equals(table)) callResetCommand = Settings.CALL_METHOD_RESET_GLOBAL;
    else {
        getErrPrintWriter().println("Invalid table; no reset performed");
        return;
    }

    try {
        Bundle arg = new Bundle();
        arg.putInt(Settings.CALL_METHOD_USER_KEY, userHandle);
        arg.putInt(Settings.CALL_METHOD_RESET_MODE_KEY, mResetMode);
        if (tag != null) {
            arg.putString(Settings.CALL_METHOD_TAG_KEY, tag);
        }
        String packageName = mPackageName != null ? mPackageName : resolveCallingPackage();
        arg.putInt(Settings.CALL_METHOD_USER_KEY, userHandle);
        provider.call(packageName, callResetCommand, null, arg);
    } catch (RemoteException e) {
        throw new RuntimeException("Failed in IPC", e);
    }
}
 
Example #3
Source File: SettingsService.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
int deleteForUser(IContentProvider provider, int userHandle,
        final String table, final String key) {
    Uri targetUri;
    if ("system".equals(table)) targetUri = Settings.System.getUriFor(key);
    else if ("secure".equals(table)) targetUri = Settings.Secure.getUriFor(key);
    else if ("global".equals(table)) targetUri = Settings.Global.getUriFor(key);
    else {
        getErrPrintWriter().println("Invalid table; no delete performed");
        throw new IllegalArgumentException("Invalid table " + table);
    }

    int num = 0;
    try {
        num = provider.delete(resolveCallingPackage(), targetUri, null, null);
    } catch (RemoteException e) {
        throw new RuntimeException("Failed in IPC", e);
    }
    return num;
}
 
Example #4
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 6 votes vote down vote up
public final IContentProvider acquireExistingProvider(Context c, String name,
        boolean stable) {
    synchronized (mProviderMap) {
        ProviderClientRecord pr = mProviderMap.get(name);
        if (pr == null) {
            return null;
        }

        IContentProvider provider = pr.mProvider;
        IBinder jBinder = provider.asBinder();

        // 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;
    }
}
 
Example #5
Source File: SettingsService.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
String getForUser(IContentProvider provider, int userHandle,
        final String table, final String key) {
    final String callGetCommand;
    if ("system".equals(table)) callGetCommand = Settings.CALL_METHOD_GET_SYSTEM;
    else if ("secure".equals(table)) callGetCommand = Settings.CALL_METHOD_GET_SECURE;
    else if ("global".equals(table)) callGetCommand = Settings.CALL_METHOD_GET_GLOBAL;
    else {
        getErrPrintWriter().println("Invalid table; no put performed");
        throw new IllegalArgumentException("Invalid table " + table);
    }

    String result = null;
    try {
        Bundle arg = new Bundle();
        arg.putInt(Settings.CALL_METHOD_USER_KEY, userHandle);
        Bundle b = provider.call(resolveCallingPackage(), callGetCommand, key, arg);
        if (b != null) {
            result = b.getPairValue();
        }
    } catch (RemoteException e) {
        throw new RuntimeException("Failed in IPC", e);
    }
    return result;
}
 
Example #6
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
ProviderClientRecord(String[] names, IContentProvider provider,
        ContentProvider localProvider,
        IActivityManager.ContentProviderHolder holder) {
    mNames = names;
    mProvider = provider;
    mLocalProvider = localProvider;
    mHolder = holder;
}
 
Example #7
Source File: ContentResolverWrapper.java    From Neptune with Apache License 2.0 5 votes vote down vote up
/** @Override*/
protected IContentProvider acquireProvider(Context context, String name) {
    //return mBase.acquireProvider(context, name);
    Class<?>[] paramTypes = new Class[]{Context.class, String.class};
    return ReflectionUtils.on(mBase).call("acquireProvider", sMethods,
            paramTypes, context, name).get();
}
 
Example #8
Source File: PluginContentResolver.java    From VirtualAPK with Apache License 2.0 5 votes vote down vote up
@Override
protected IContentProvider acquireProvider(Context context, String auth) {
    if (mPluginManager.resolveContentProvider(auth, 0) != null) {
        return mPluginManager.getIContentProvider();
    }
    return super.acquireProvider(context, auth);
}
 
Example #9
Source File: SettingsService.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private List<String> listForUser(IContentProvider provider, int userHandle, String table) {
    final Uri uri = "system".equals(table) ? Settings.System.CONTENT_URI
            : "secure".equals(table) ? Settings.Secure.CONTENT_URI
            : "global".equals(table) ? Settings.Global.CONTENT_URI
            : null;
    final ArrayList<String> lines = new ArrayList<String>();
    if (uri == null) {
        return lines;
    }
    try {
        final Cursor cursor = provider.query(resolveCallingPackage(), uri, null, null,
                null);
        try {
            while (cursor != null && cursor.moveToNext()) {
                lines.add(cursor.getString(1) + "=" + cursor.getString(2));
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
        Collections.sort(lines);
    } catch (RemoteException e) {
        throw new RuntimeException("Failed in IPC", e);
    }
    return lines;
}
 
Example #10
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
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 /*noisy*/, true /*noReleaseNeeded*/);
        if (cp != null) {
            IActivityManager.ContentProviderHolder cph =
                    new IActivityManager.ContentProviderHolder(cpi);
            cph.provider = cp;
            cph.noReleaseNeeded = true;
            results.add(cph);
        }
    }

    try {
        ActivityManagerNative.getDefault().publishContentProviders(
            getApplicationThread(), results);
    } catch (RemoteException ex) {
    }
}
 
Example #11
Source File: PluginContentResolver.java    From VirtualAPK with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
protected IContentProvider acquireUnstableProvider(Context context, String auth) {
    if (mPluginManager.resolveContentProvider(auth, 0) != null) {
        return mPluginManager.getIContentProvider();
    }
    return super.acquireUnstableProvider(context, auth);
}
 
Example #12
Source File: PluginContentResolver.java    From Neptune with Apache License 2.0 5 votes vote down vote up
@Override
protected IContentProvider acquireExistingProvider(Context context, String name) {
    if (ComponentFinder.resolveProviderInfo(context, name) != null) {
        return getIContentProvider(context);
    }
    return super.acquireExistingProvider(context, name);
}
 
Example #13
Source File: PluginManager.java    From VirtualAPK with Apache License 2.0 5 votes vote down vote up
protected void hookIContentProviderAsNeeded() {
    Uri uri = Uri.parse(RemoteContentProvider.getUri(mContext));
    mContext.getContentResolver().call(uri, "wakeup", null, null);
    try {
        Field authority = null;
        Field provider = null;
        ActivityThread activityThread = ActivityThread.currentActivityThread();
        Map providerMap = Reflector.with(activityThread).field("mProviderMap").get();
        Iterator iter = providerMap.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            Object key = entry.getKey();
            Object val = entry.getValue();
            String auth;
            if (key instanceof String) {
                auth = (String) key;
            } else {
                if (authority == null) {
                    authority = key.getClass().getDeclaredField("authority");
                    authority.setAccessible(true);
                }
                auth = (String) authority.get(key);
            }
            if (auth.equals(RemoteContentProvider.getAuthority(mContext))) {
                if (provider == null) {
                    provider = val.getClass().getDeclaredField("mProvider");
                    provider.setAccessible(true);
                }
                IContentProvider rawProvider = (IContentProvider) provider.get(val);
                IContentProvider proxy = IContentProviderProxy.newInstance(mContext, rawProvider);
                mIContentProvider = proxy;
                Log.d(TAG, "hookIContentProvider succeed : " + mIContentProvider);
                break;
            }
        }
    } catch (Exception e) {
        Log.w(TAG, e);
    }
}
 
Example #14
Source File: ContentResolverWrapper.java    From Neptune with Apache License 2.0 5 votes vote down vote up
/** @Override*/
protected IContentProvider acquireExistingProvider(Context context, String name) {
    //return mBase.acquireExistingProvider(context, name);
    Class<?>[] paramTypes = new Class[]{Context.class, String.class};
    return ReflectionUtils.on(mBase).call("acquireExistingProvider", sMethods,
            paramTypes, context, name).get();
}
 
Example #15
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 5 votes vote down vote up
public final IContentProvider acquireProvider(Context c, String name, boolean stable) {
    IContentProvider provider = acquireExistingProvider(c, name, 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(), name, stable);
    } catch (RemoteException ex) {
    }
    if (holder == null) {
        Slog.e(TAG, "Failed to find provider info for " + name);
        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;
}
 
Example #16
Source File: PluginManager.java    From VirtualAPK with Apache License 2.0 5 votes vote down vote up
public synchronized IContentProvider getIContentProvider() {
    if (mIContentProvider == null) {
        hookIContentProviderAsNeeded();
    }

    return mIContentProvider;
}
 
Example #17
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
protected IContentProvider acquireUnstableProvider(Context c, String auth) {
    return mMainThread.acquireProvider(c,
            ContentProvider.getAuthorityWithoutUserId(auth),
            resolveUserIdFromAuthority(auth), false);
}
 
Example #18
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
protected IContentProvider acquireExistingProvider(Context context, String name) {
    return mMainThread.acquireExistingProvider(context, name);
}
 
Example #19
Source File: PluginContentResolver.java    From Neptune with Apache License 2.0 4 votes vote down vote up
private static synchronized IContentProvider getIContentProvider(Context context) {
    if (sIContentProvider == null) {
        hookIContentProviderAsNeeded(context);
    }
    return sIContentProvider;
}
 
Example #20
Source File: IContentProviderProxy.java    From Neptune with Apache License 2.0 4 votes vote down vote up
public static IContentProvider newInstance(Context context, IContentProvider rawProvider) {
    return (IContentProvider) Proxy.newProxyInstance(rawProvider.getClass().getClassLoader(),
            new Class[]{IContentProvider.class}, new IContentProviderProxy(context, rawProvider));
}
 
Example #21
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
protected IContentProvider acquireUnstableProvider(Context c, String auth) {
    return mMainThread.acquireProvider(c,
            ContentProvider.getAuthorityWithoutUserId(auth),
            resolveUserIdFromAuthority(auth), false);
}
 
Example #22
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean releaseProvider(IContentProvider provider) {
    return mMainThread.releaseProvider(provider, true);
}
 
Example #23
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
public void appNotRespondingViaProvider(IContentProvider icp) {
    mMainThread.appNotRespondingViaProvider(icp.asBinder());
}
 
Example #24
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
protected IContentProvider acquireExistingProvider(Context context, String auth) {
    return mMainThread.acquireExistingProvider(context, auth, mUser.getIdentifier(), true);
}
 
Example #25
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
protected IContentProvider acquireProvider(Context context, String auth) {
    return mMainThread.acquireProvider(context,
            ContentProvider.getAuthorityWithoutUserId(auth),
            resolveUserIdFromAuthority(auth), true);
}
 
Example #26
Source File: PluginContentResolver.java    From VirtualAPK with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
@Override
public void appNotRespondingViaProvider(IContentProvider icp) {
}
 
Example #27
Source File: ActivityThread.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
final void completeRemoveProvider(IContentProvider provider) {
    IBinder jBinder = provider.asBinder();
    String remoteProviderName = null;
    synchronized(mProviderMap) {
        ProviderRefCount prc = mProviderRefCountMap.get(jBinder);
        if (prc == null) {
            // Either no release is needed (so we shouldn't be here) or the
            // provider was already released.
            if (localLOGV) Slog.v(TAG, "completeRemoveProvider: release not needed");
            return;
        }

        if (prc.count != 0) {
            // There was a race!  Some other client managed to acquire
            // the provider before the removal was completed.
            // Abort the removal.  We will do it later.
            if (localLOGV) Slog.v(TAG, "completeRemoveProvider: lost the race, "
                    + "provider still in use");
            return;
        }

        mProviderRefCountMap.remove(jBinder);

        Iterator<ProviderClientRecord> iter = mProviderMap.values().iterator();
        while (iter.hasNext()) {
            ProviderClientRecord pr = iter.next();
            IBinder myBinder = pr.mProvider.asBinder();
            if (myBinder == jBinder) {
                iter.remove();
                if (pr.mLocalProvider == null) {
                    myBinder.unlinkToDeath(pr, 0);
                    if (remoteProviderName == null) {
                        remoteProviderName = pr.mName;
                    }
                }
            }
        }
    }

    if (remoteProviderName != null) {
        try {
            if (localLOGV) {
                Slog.v(TAG, "removeProvider: Invoking ActivityManagerNative."
                        + "removeContentProvider(" + remoteProviderName + ")");
            }
            ActivityManagerNative.getDefault().removeContentProvider(
                    getApplicationThread(), remoteProviderName);
        } catch (RemoteException e) {
            //do nothing content provider object is dead any way
        }
    }
}
 
Example #28
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void unstableProviderDied(IContentProvider icp) {
    mMainThread.handleUnstableProviderDied(icp.asBinder(), true);
}
 
Example #29
Source File: ContextImpl.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public void appNotRespondingViaProvider(IContentProvider icp) {
    mMainThread.appNotRespondingViaProvider(icp.asBinder());
}
 
Example #30
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
@Override
protected IContentProvider acquireProvider(Context context, String auth) {
    return mMainThread.acquireProvider(context, auth, mUser.getIdentifier(), true);
}