use of android.content.ContentProvider in project VirtualAPK by didi.
the class RemoteContentProvider method getContentProvider.
private ContentProvider getContentProvider(final Uri uri) {
final PluginManager pluginManager = PluginManager.getInstance(getContext());
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
final String auth = pluginUri.getAuthority();
ContentProvider cachedProvider = sCachedProviders.get(auth);
if (cachedProvider != null) {
return cachedProvider;
}
synchronized (sCachedProviders) {
LoadedPlugin plugin = pluginManager.getLoadedPlugin(uri.getQueryParameter(KEY_PKG));
if (plugin == null) {
try {
pluginManager.loadPlugin(new File(uri.getQueryParameter(KEY_PLUGIN)));
} catch (Exception e) {
e.printStackTrace();
}
}
final ProviderInfo providerInfo = pluginManager.resolveContentProvider(auth, 0);
if (providerInfo != null) {
RunUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
LoadedPlugin loadedPlugin = pluginManager.getLoadedPlugin(uri.getQueryParameter(KEY_PKG));
ContentProvider contentProvider = (ContentProvider) Class.forName(providerInfo.name).newInstance();
contentProvider.attachInfo(loadedPlugin.getPluginContext(), providerInfo);
sCachedProviders.put(auth, contentProvider);
} catch (Exception e) {
e.printStackTrace();
}
}
}, true);
return sCachedProviders.get(auth);
}
}
return null;
}
use of android.content.ContentProvider in project VirtualAPK by didi.
the class RemoteContentProvider method insert.
@Override
public Uri insert(Uri uri, ContentValues values) {
ContentProvider provider = getContentProvider(uri);
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
if (provider != null) {
return provider.insert(pluginUri, values);
}
return uri;
}
use of android.content.ContentProvider in project VirtualAPK by didi.
the class RemoteContentProvider method getType.
@Override
public String getType(Uri uri) {
ContentProvider provider = getContentProvider(uri);
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
if (provider != null) {
return provider.getType(pluginUri);
}
return null;
}
use of android.content.ContentProvider in project AndroidLife by CaMnter.
the class RemoteContentProvider method applyBatch.
/**
* 反射替换 ContentProviderOperation 集合中所有的 ContentProviderOperation # Uri mUri
*
* 在 ContentProviderOperation 集合存在数据的情况下
* 取出每个 ContentProviderOperation 对应的插件 ContentProvider
* 手动调用 ContentProvider # applyBatch(...)
*
* @param operations operations
* @return ContentProviderResult[]
* @throws OperationApplicationException OperationApplicationException
*/
@NonNull
@Override
public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) throws OperationApplicationException {
try {
Field uriField = ContentProviderOperation.class.getDeclaredField("mUri");
uriField.setAccessible(true);
for (ContentProviderOperation operation : operations) {
Uri pluginUri = Uri.parse(operation.getUri().getQueryParameter(KEY_URI));
uriField.set(operation, pluginUri);
}
} catch (Exception e) {
return new ContentProviderResult[0];
}
if (operations.size() > 0) {
ContentProvider provider = getContentProvider(operations.get(0).getUri());
if (provider != null) {
return provider.applyBatch(operations);
}
}
return new ContentProviderResult[0];
}
use of android.content.ContentProvider in project AndroidLife by CaMnter.
the class RemoteContentProvider method getType.
/**
* 获取插件 ContentProvider 后
* 解析复合 Uri 协议,获取其中包含的插件 Uri 协议
*
* 手动调用 插件 ContentProvider # getType(...)
*
* @param uri uri
* @return String
*/
@Override
public String getType(Uri uri) {
ContentProvider provider = getContentProvider(uri);
Uri pluginUri = Uri.parse(uri.getQueryParameter(KEY_URI));
if (provider != null) {
return provider.getType(pluginUri);
}
return null;
}
Aggregations