Java Code Examples for android.content.IContentProvider

The following are top voted examples for showing how to use android.content.IContentProvider. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: PluginM   File: PluginContentResolver.java   View source code 6 votes vote down vote up
/** @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;
}
 
Example 2
Project: PluginM   File: PluginStubMainProvider.java   View source code 6 votes vote down vote up
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;
}
 
Example 3
Project: droidel   File: ActivityThread.java   View source code 6 votes vote down vote up
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;
}
 
Example 4
Project: VirtualAPK   File: PluginContentResolver.java   View source code 5 votes vote down vote up
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;
}
 
Example 5
Project: VirtualAPK   File: PluginContentResolver.java   View source code 5 votes vote down vote up
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;
}
 
Example 6
Project: VirtualAPK   File: PluginContentResolver.java   View source code 5 votes vote down vote up
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;
}
 
Example 7
Project: VirtualAPK   File: PluginManager.java   View source code 5 votes vote down vote up
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();
    }
}
 
Example 8
Project: VirtualAPK   File: PluginManager.java   View source code 5 votes vote down vote up
public synchronized IContentProvider getIContentProvider() {
    if (mIContentProvider == null) {
        hookIContentProviderAsNeeded();
    }

    return mIContentProvider;
}
 
Example 9
Project: PluginM   File: PluginContentResolver.java   View source code 5 votes vote down vote up
/** @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;
}
 
Example 10
Project: PluginM   File: PluginContentResolver.java   View source code 5 votes vote down vote up
/** @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;
}
 
Example 11
Project: PluginM   File: PluginContentResolver.java   View source code 5 votes vote down vote up
/** @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);
    }
}
 
Example 12
Project: PluginM   File: PluginContentResolver.java   View source code 5 votes vote down vote up
/** @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);
    }
}
 
Example 13
Project: PluginM   File: PluginContentResolver.java   View source code 5 votes vote down vote up
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;
}
 
Example 14
Project: PluginM   File: PluginContentResolver.java   View source code 5 votes vote down vote up
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;
}
 
Example 15
Project: PluginM   File: PluginStubMainProvider.java   View source code 5 votes vote down vote up
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;
}
 
Example 16
Project: PluginM   File: PluginStubMainProvider.java   View source code 5 votes vote down vote up
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;
}
 
Example 17
Project: PluginM   File: ContentProviderCompat.java   View source code 5 votes vote down vote up
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;
}
 
Example 18
Project: FullRobolectricTestSample   File: ShadowApplication.java   View source code 5 votes vote down vote up
@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;
}
 
Example 19
Project: FullRobolectricTestSample   File: ShadowContentResolver.java   View source code 5 votes vote down vote up
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;
}
 
Example 20
Project: FullRobolectricTestSample   File: ShadowContentResolver.java   View source code 5 votes vote down vote up
@Implementation
public final IContentProvider acquireUnstableProvider(String name) {
  ContentProvider cp = getProvider(name);
  if (cp != null) {
    return cp.getIContentProvider();
  }
  return null;
}
 
Example 21
Project: FullRobolectricTestSample   File: ShadowContentResolver.java   View source code 5 votes vote down vote up
@Implementation
public final IContentProvider acquireUnstableProvider(Uri uri) {
  ContentProvider cp = getProvider(uri);
  if (cp != null) {
    return cp.getIContentProvider();
  }
  return null;
}
 
Example 22
Project: droidel   File: ActivityThread.java   View source code 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 23
Project: droidel   File: ActivityThread.java   View source code 5 votes vote down vote up
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;
}
 
Example 24
Project: droidel   File: ActivityThread.java   View source code 5 votes vote down vote up
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;
    }
}
 
Example 25
Project: koala--Android-Plugin-Runtime-   File: PluginManagerImpl.java   View source code 5 votes vote down vote up
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;
}
 
Example 26
Project: MiPushFramework   File: CondomContext.java   View source code 4 votes vote down vote up
@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);
}
 
Example 27
Project: MiPushFramework   File: CondomContext.java   View source code 4 votes vote down vote up
@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);
}
 
Example 28
Project: VirtualAPK   File: PluginContentResolver.java   View source code 4 votes vote down vote up
public boolean releaseProvider(IContentProvider provider) {
    return true;
}
 
Example 29
Project: VirtualAPK   File: PluginContentResolver.java   View source code 4 votes vote down vote up
public boolean releaseUnstableProvider(IContentProvider icp) {
    return true;
}
 
Example 30
Project: VirtualAPK   File: PluginContentResolver.java   View source code 4 votes vote down vote up
public void unstableProviderDied(IContentProvider icp) {
}
 
Example 31
Project: VirtualAPK   File: PluginContentResolver.java   View source code 4 votes vote down vote up
public void appNotRespondingViaProvider(IContentProvider icp) {
}
 
Example 32
Project: VirtualAPK   File: IContentProviderProxy.java   View source code 4 votes vote down vote up
private IContentProviderProxy(Context context, IContentProvider iContentProvider) {
    mBase = iContentProvider;
    mContext = context;
}
 
Example 33
Project: VirtualAPK   File: IContentProviderProxy.java   View source code 4 votes vote down vote up
public static IContentProvider newInstance(Context context, IContentProvider iContentProvider) {
    return (IContentProvider) Proxy.newProxyInstance(iContentProvider.getClass().getClassLoader(),
            new Class[] { IContentProvider.class }, new IContentProviderProxy(context, iContentProvider));
}
 
Example 34
Project: condom   File: CondomContentResolver.java   View source code 4 votes vote down vote up
@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);
}
 
Example 35
Project: condom   File: CondomContentResolver.java   View source code 4 votes vote down vote up
@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);
}
 
Example 36
Project: FullRobolectricTestSample   File: ShadowContentProviderClient.java   View source code 4 votes vote down vote up
public void __constructor__(ContentResolver contentResolver, IContentProvider contentProvider,
    boolean stable) {
  this.stable = stable;
}
 
Example 37
Project: FullRobolectricTestSample   File: ShadowContentResolver.java   View source code 4 votes vote down vote up
@Implementation
public final IContentProvider acquireProvider(String name) {
  return acquireUnstableProvider(name);
}
 
Example 38
Project: FullRobolectricTestSample   File: ShadowContentResolver.java   View source code 4 votes vote down vote up
@Implementation
public final IContentProvider acquireProvider(Uri uri) {
  return acquireUnstableProvider(uri);
}
 
Example 39
Project: koala--Android-Plugin-Runtime-   File: PluginContentResolver.java   View source code 4 votes vote down vote up
@Override
protected IContentProvider acquireProvider(Context context, String name) {
    return PluginManagerImpl.getInstance().getContentProvider(name);
}
 
Example 40
Project: koala--Android-Plugin-Runtime-   File: PluginContentResolver.java   View source code 4 votes vote down vote up
@Override
protected IContentProvider acquireUnstableProvider(Context context, String name) {
    return null;
}