Java 类android.content.IContentProvider 实例源码
项目:PluginM
文件:PluginContentResolver.java
/** @Override **/
protected IContentProvider acquireExistingProvider(Context context, String auth) {
Logger.d(TAG, "acquireExistingProvider() auth = " + auth);
try {
IContentProvider iContentProvider = getTargetProvider(auth);
if (iContentProvider != null) {
return iContentProvider;
}
Method method = mOriginContentResolver.getClass().getDeclaredMethod("acquireExistingProvider", new Class[]{Context.class, String.class});
method.setAccessible(true);
return (IContentProvider) method.invoke(mOriginContentResolver, context, auth);
} catch (Exception e) {
Logger.e(TAG, "acquireExistingProvider() error!", e);
}
return null;
}
项目:PluginM
文件:PluginStubMainProvider.java
private IContentProvider getIContentProvider(@NonNull PluginInfo pluginInfo, @NonNull ProviderInfo providerInfo) {
if (pluginInfo != null && providerInfo != null) {
ContentProvider contentProvider;
synchronized (mContentProviderMap) {
contentProvider = mContentProviderMap.get(providerInfo.name);
}
if (contentProvider == null) {
contentProvider = installProvider(pluginInfo, providerInfo);
}
if (contentProvider != null) {
return ContentProviderCompat.getIContentProvider(contentProvider);
} else {
throw new RuntimeException("CAN NOT get IContentProvider for " + providerInfo);
}
}
return null;
}
项目:droidel
文件:ActivityThread.java
private ProviderClientRecord installProviderAuthoritiesLocked(IContentProvider provider,
ContentProvider localProvider, IActivityManager.ContentProviderHolder holder) {
final String auths[] = PATTERN_SEMICOLON.split(holder.info.authority);
final int userId = UserHandle.getUserId(holder.info.applicationInfo.uid);
final ProviderClientRecord pcr = new ProviderClientRecord(
auths, provider, localProvider, holder);
for (String auth : auths) {
final ProviderKey key = new ProviderKey(auth, userId);
final ProviderClientRecord existing = mProviderMap.get(key);
if (existing != null) {
Slog.w(TAG, "Content provider " + pcr.mHolder.info.name
+ " already published as " + auth);
} else {
mProviderMap.put(key, pcr);
}
}
return pcr;
}
项目:VirtualAPK
文件:PluginContentResolver.java
protected IContentProvider acquireProvider(Context context, String auth) {
try {
if (mPluginManager.resolveContentProvider(auth, 0) != null) {
return mPluginManager.getIContentProvider();
}
return (IContentProvider) sAcquireProvider.invoke(mBase, context, auth);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
项目:VirtualAPK
文件:PluginContentResolver.java
protected IContentProvider acquireExistingProvider(Context context, String auth) {
try {
if (mPluginManager.resolveContentProvider(auth, 0) != null) {
return mPluginManager.getIContentProvider();
}
return (IContentProvider) sAcquireExistingProvider.invoke(mBase, context, auth);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
项目:VirtualAPK
文件:PluginContentResolver.java
protected IContentProvider acquireUnstableProvider(Context context, String auth) {
try {
if (mPluginManager.resolveContentProvider(auth, 0) != null) {
return mPluginManager.getIContentProvider();
}
return (IContentProvider) sAcquireUnstableProvider.invoke(mBase, context, auth);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
项目:VirtualAPK
文件:PluginManager.java
private void hookIContentProviderAsNeeded() {
Uri uri = Uri.parse(PluginContentResolver.getUri(mContext));
mContext.getContentResolver().call(uri, "wakeup", null, null);
try {
Field authority = null;
Field mProvider = null;
ActivityThread activityThread = (ActivityThread) ReflectUtil.getActivityThread(mContext);
Map mProviderMap = (Map) ReflectUtil.getField(activityThread.getClass(), activityThread, "mProviderMap");
Iterator iter = mProviderMap.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(PluginContentResolver.getAuthority(mContext))) {
if (mProvider == null) {
mProvider = val.getClass().getDeclaredField("mProvider");
mProvider.setAccessible(true);
}
IContentProvider rawProvider = (IContentProvider) mProvider.get(val);
IContentProvider proxy = IContentProviderProxy.newInstance(mContext, rawProvider);
mIContentProvider = proxy;
Log.d(TAG, "hookIContentProvider succeed : " + mIContentProvider);
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
项目:VirtualAPK
文件:PluginManager.java
public synchronized IContentProvider getIContentProvider() {
if (mIContentProvider == null) {
hookIContentProviderAsNeeded();
}
return mIContentProvider;
}
项目:PluginM
文件:PluginContentResolver.java
/** @Override **/
public boolean releaseProvider(IContentProvider provider) {
Logger.d(TAG, "releaseProvider() IContentProvider = " + provider);
try {
Method method = mOriginContentResolver.getClass().getDeclaredMethod("releaseProvider", new Class[]{IContentProvider.class});
method.setAccessible(true);
method.invoke(mOriginContentResolver, provider);
} catch (Exception e) {
Logger.e(TAG, "releaseProvider() error!", e);
}
return false;
}
项目:PluginM
文件:PluginContentResolver.java
/** @Override **/
public boolean releaseUnstableProvider(IContentProvider icp) {
Logger.d(TAG, "releaseUnstableProvider() IContentProvider = " + icp);
try {
Method method = mOriginContentResolver.getClass().getDeclaredMethod("releaseUnstableProvider", new Class[]{IContentProvider.class});
method.setAccessible(true);
return (Boolean) method.invoke(mOriginContentResolver, icp);
} catch (Exception e) {
Logger.e(TAG, "releaseUnstableProvider() error!", e);
}
return false;
}
项目:PluginM
文件:PluginContentResolver.java
/** @Override **/
public void unstableProviderDied(IContentProvider icp) {
Logger.d(TAG, "acquireProvider() IContentProvider = " + icp);
try {
Method method = mOriginContentResolver.getClass().getDeclaredMethod("unstableProviderDied", new Class[]{IContentProvider.class});
method.setAccessible(true);
method.invoke(mOriginContentResolver, icp);
} catch (Exception e) {
Logger.e(TAG, "acquireProvider() error!", e);
}
}
项目:PluginM
文件:PluginContentResolver.java
/** @Override **/
public void appNotRespondingViaProvider(IContentProvider icp) {
Logger.d(TAG, "appNotRespondingViaProvider() IContentProvider = " + icp);
try {
Method method = mOriginContentResolver.getClass().getDeclaredMethod("appNotRespondingViaProvider", new Class[]{IContentProvider.class});
method.setAccessible(true);
method.invoke(mOriginContentResolver, icp);
} catch (Exception e) {
Logger.e(TAG, "appNotRespondingViaProvider() error!", e);
}
}
项目:PluginM
文件:PluginContentResolver.java
private IContentProvider getTargetProvider(String auth) {
Pair<Uri, Bundle> uriAndBundle = PluginManager.getInstance(mAppContext).getPluginProviderUri(auth);
Logger.d(TAG, "getTargetProvider() auth = " + auth + " -> uriAndBundle = " + uriAndBundle);
if (uriAndBundle != null) {
return getIContentProvider(uriAndBundle);
}
return null;
}
项目:PluginM
文件:PluginContentResolver.java
private IContentProvider getIContentProvider(Pair<Uri, Bundle> uriAndBundle) {
Logger.d(TAG, "getIContentProvider() uriAndBundle = " + uriAndBundle);
final Uri uri = uriAndBundle.first;
if (uri != null) {
Bundle providerBundle = uriAndBundle.second;
Bundle bundle = mOriginContentResolver.call(uri, PluginStubMainProvider.METHOD_GET_PROVIDER, null, providerBundle);
Logger.d(TAG, "getIContentProvider() return bundle = " + bundle);
if (bundle != null) {
return PluginStubMainProvider.parseIContentProvider(bundle);
}
}
return null;
}
项目:PluginM
文件:PluginStubMainProvider.java
public
@Nullable
Bundle call(@NonNull String method, @Nullable String arg,
@Nullable Bundle extras) {
Logger.d(TAG, "call() method =" + method + ", arg=" + arg);
if (METHOD_GET_PROVIDER.equals(method)) {
final ProviderInfo providerInfo = extras.getParcelable(PluginManager.EXTRA_INTENT_TARGET_PROVIDERINFO);
final Bundle resultBundle = new Bundle();
PluginInfo loadedPluginInfo = PluginManager.getInstance(getContext()).loadPlugin(providerInfo.packageName);
if (loadedPluginInfo == null) {
return null;
}
try {
IContentProvider iContentProvider = getIContentProvider(loadedPluginInfo, providerInfo);
Logger.d(TAG, "call() iContentProvider = " + iContentProvider);
if (iContentProvider != null) {
BinderParcelable binderParcelable = new BinderParcelable(iContentProvider.asBinder());
resultBundle.putParcelable(EXTRA_BINDER, binderParcelable);
return resultBundle;
}
} catch (Exception e) {
Logger.e(TAG, "found provider error!", e);
}
return null;
} else if (METHOD_START_PROCESS.equals(method)) {
// return an empty bundle
return new Bundle();
}
return null;
}
项目:PluginM
文件:PluginStubMainProvider.java
public static IContentProvider parseIContentProvider(Bundle bundle) {
IBinder iBinder = parseBinderParacelable(bundle);
if (iBinder != null) {
try {
return (IContentProvider) MethodUtils.invokeStaticMethod(sContentProviderNativeClass, "asInterface", iBinder);
} catch (Exception e) {
Logger.e(TAG, "parseIContentProvider() error!", e);
}
}
return null;
}
项目:PluginM
文件:ContentProviderCompat.java
public static IContentProvider getIContentProvider(ContentProvider cp) {
if (sGetIContentProviderMethod != null) {
try {
return (IContentProvider) sGetIContentProviderMethod.invoke(cp);
} catch (Exception e) {
Logger.e(TAG, "getIContentProvider() error!", e);
}
}
return null;
}
项目:FullRobolectricTestSample
文件:ShadowApplication.java
@Implementation
@Override
public ContentResolver getContentResolver() {
if (contentResolver == null) {
contentResolver = new ContentResolver(realApplication) {
@Override
protected IContentProvider acquireProvider(Context c, String name) {
return null;
}
@Override
public boolean releaseProvider(IContentProvider icp) {
return false;
}
@Override
protected IContentProvider acquireUnstableProvider(Context c, String name) {
return null;
}
@Override
public boolean releaseUnstableProvider(IContentProvider icp) {
return false;
}
@Override
public void unstableProviderDied(IContentProvider icp) {
}
};
}
return contentResolver;
}
项目:FullRobolectricTestSample
文件:ShadowContentResolver.java
private ContentProviderClient getContentProviderClient(ContentProvider provider, boolean stable) {
ContentProviderClient client =
Robolectric.newInstance(ContentProviderClient.class,
new Class[] {ContentResolver.class, IContentProvider.class, boolean.class},
new Object[] {realContentResolver, provider.getIContentProvider(), stable});
Robolectric.shadowOf(client).setContentProvider(provider);
return client;
}
项目:FullRobolectricTestSample
文件:ShadowContentResolver.java
@Implementation
public final IContentProvider acquireUnstableProvider(String name) {
ContentProvider cp = getProvider(name);
if (cp != null) {
return cp.getIContentProvider();
}
return null;
}
项目:FullRobolectricTestSample
文件:ShadowContentResolver.java
@Implementation
public final IContentProvider acquireUnstableProvider(Uri uri) {
ContentProvider cp = getProvider(uri);
if (cp != null) {
return cp.getIContentProvider();
}
return null;
}
项目:droidel
文件:ActivityThread.java
ProviderClientRecord(String[] names, IContentProvider provider,
ContentProvider localProvider,
IActivityManager.ContentProviderHolder holder) {
mNames = names;
mProvider = provider;
mLocalProvider = localProvider;
mHolder = holder;
}
项目:droidel
文件:ActivityThread.java
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;
}
项目:droidel
文件:ActivityThread.java
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;
}
}
项目:koala--Android-Plugin-Runtime-
文件:PluginManagerImpl.java
IContentProvider getExistContentProvider(String name) {
Iterator<Plugin> iter = mPlugins.values().iterator();
while (iter.hasNext()) {
Plugin plugin = iter.next();
if (plugin.mProviderMap.containsKey(name)) {
return plugin.mProviderMap.get(name);
}
}
return null;
}
项目:MiPushFramework
文件:CondomContext.java
@Override public IContentProvider acquireUnstableProvider(final Context context, final String name) {
if (! mCondom.shouldAllowProvider(context, name, PackageManager.GET_UNINSTALLED_PACKAGES)) return null;
return super.acquireUnstableProvider(context, name);
}
项目:MiPushFramework
文件:CondomContext.java
@Override public IContentProvider acquireProvider(final Context context, final String name) {
if (! mCondom.shouldAllowProvider(context, name, PackageManager.GET_UNINSTALLED_PACKAGES)) return null;
return super.acquireProvider(context, name);
}
项目:VirtualAPK
文件:PluginContentResolver.java
public boolean releaseProvider(IContentProvider provider) {
return true;
}
项目:VirtualAPK
文件:PluginContentResolver.java
public boolean releaseUnstableProvider(IContentProvider icp) {
return true;
}
项目:VirtualAPK
文件:PluginContentResolver.java
public void unstableProviderDied(IContentProvider icp) {
}
项目:VirtualAPK
文件:PluginContentResolver.java
public void appNotRespondingViaProvider(IContentProvider icp) {
}
项目:VirtualAPK
文件:IContentProviderProxy.java
private IContentProviderProxy(Context context, IContentProvider iContentProvider) {
mBase = iContentProvider;
mContext = context;
}
项目:VirtualAPK
文件:IContentProviderProxy.java
public static IContentProvider newInstance(Context context, IContentProvider iContentProvider) {
return (IContentProvider) Proxy.newProxyInstance(iContentProvider.getClass().getClassLoader(),
new Class[] { IContentProvider.class }, new IContentProviderProxy(context, iContentProvider));
}
项目:condom
文件:CondomContentResolver.java
@Override public IContentProvider acquireUnstableProvider(final Context context, final String name) {
if (! mCondom.shouldAllowProvider(context, name, PackageManager.MATCH_ALL)) return null;
return super.acquireUnstableProvider(context, name);
}
项目:condom
文件:CondomContentResolver.java
@Override public IContentProvider acquireProvider(final Context context, final String name) {
if (! mCondom.shouldAllowProvider(context, name, PackageManager.MATCH_ALL)) return null;
return super.acquireProvider(context, name);
}
项目:FullRobolectricTestSample
文件:ShadowContentProviderClient.java
public void __constructor__(ContentResolver contentResolver, IContentProvider contentProvider,
boolean stable) {
this.stable = stable;
}
项目:FullRobolectricTestSample
文件:ShadowContentResolver.java
@Implementation
public final IContentProvider acquireProvider(String name) {
return acquireUnstableProvider(name);
}
项目:FullRobolectricTestSample
文件:ShadowContentResolver.java
@Implementation
public final IContentProvider acquireProvider(Uri uri) {
return acquireUnstableProvider(uri);
}
项目:koala--Android-Plugin-Runtime-
文件:PluginContentResolver.java
@Override
protected IContentProvider acquireProvider(Context context, String name) {
return PluginManagerImpl.getInstance().getContentProvider(name);
}
项目:koala--Android-Plugin-Runtime-
文件:PluginContentResolver.java
@Override
protected IContentProvider acquireUnstableProvider(Context context, String name) {
return null;
}