本文整理汇总了Java中android.content.pm.ProviderInfo类的典型用法代码示例。如果您正苦于以下问题:Java ProviderInfo类的具体用法?Java ProviderInfo怎么用?Java ProviderInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProviderInfo类属于android.content.pm包,在下文中一共展示了ProviderInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProviders
import android.content.pm.ProviderInfo; //导入依赖的package包/类
private Observable<List<ProviderInfo>> getProviders(){
return Observable.fromCallable(new Callable<List<ProviderInfo>>() {
@Override public List<ProviderInfo> call() throws Exception {
List<ProviderInfo> info = new ArrayList<>();
for (PackageInfo providerInfo :getPackageManager().getInstalledPackages(PackageManager.GET_PROVIDERS)){
if (providerInfo.providers != null){
for (ProviderInfo provider : providerInfo.providers) {
if (provider.authority != null) {
if (sp.getBoolean("need_filter",false)){
info.add(provider);
}else if(provider.readPermission!=null){
info.add(provider);
}
}
}
}
}
return info;
}
});
}
示例2: testProviderRegistry
import android.content.pm.ProviderInfo; //导入依赖的package包/类
@Test
public void testProviderRegistry() {
Context appContext = InstrumentationRegistry.getTargetContext();
PackageManager pm = appContext.getPackageManager();
// We define the component name based on the package name from the context and the
// Provider class.
ComponentName componentName = new ComponentName(appContext.getPackageName(),
FavoritesProvider.class.getName());
try {
// Fetch the provider info using the component name from the PackageManager
// This throws an exception if the provider isn't registered.
ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
// Make sure that the registered authority matches the authority from the Contract.
assertEquals("Error: FavoritesProvider registered with authority: " + providerInfo.authority
+ " instead of authority: " + FavoritesContract.AUTHORITY,
providerInfo.authority, FavoritesContract.AUTHORITY);
} catch (PackageManager.NameNotFoundException e) {
// I guess the provider isn't registered correctly.
assertTrue("Error: FavoritesProvider not registered at " + appContext.getPackageName(),
false);
}
}
示例3: addProviderInfo
import android.content.pm.ProviderInfo; //导入依赖的package包/类
private void addProviderInfo(String stubAuthority, ProviderInfo info) {
if (!targetProviderInfos.containsKey(info.authority)) {
targetProviderInfos.put(info.authority, info);
if (!pkgs.contains(info.packageName)) {
pkgs.add(info.packageName);
}
//stub map to activity info
Set<ProviderInfo> list = providerInfosMap.get(stubAuthority);
if (list == null) {
list = new TreeSet<ProviderInfo>(sProviderInfoComparator);
list.add(info);
providerInfosMap.put(stubAuthority, list);
} else {
list.add(info);
}
}
}
示例4: testProviderRegistry
import android.content.pm.ProviderInfo; //导入依赖的package包/类
public void testProviderRegistry() {
PackageManager pm = mContext.getPackageManager();
ComponentName componentName = new ComponentName(mContext.getPackageName(),
LeaderProvider.class.getName());
try {
// Fetch the provider info using the component name from the PackageManager
// This throws an exception if the provider isn't registered.
ProviderInfo providerInfo = pm.getProviderInfo(componentName, 0);
// Make sure that the registered authority matches the authority from the Contract.
assertEquals("Error: LeaderProvider registered with authority: " + providerInfo.authority +
" instead of authority: " + LeaderContract.CONTENT_AUTHORITY,
providerInfo.authority, LeaderContract.CONTENT_AUTHORITY);
} catch (PackageManager.NameNotFoundException e) {
assertTrue("Error: LeaderProvider not registered at " + mContext.getPackageName(),
false);
}
}
示例5: acquireProviderClient
import android.content.pm.ProviderInfo; //导入依赖的package包/类
@Override
public IBinder acquireProviderClient(int userId, ProviderInfo info) {
ProcessRecord callerApp;
synchronized (mPidsSelfLocked) {
callerApp = findProcessLocked(VBinder.getCallingPid());
}
if (callerApp == null) {
throw new SecurityException("Who are you?");
}
String processName = info.processName;
ProcessRecord r;
synchronized (this) {
r = startProcessIfNeedLocked(processName, userId, info.packageName);
}
if (r != null && r.client.asBinder().isBinderAlive()) {
try {
return r.client.acquireProviderClient(info);
} catch (RemoteException e) {
e.printStackTrace();
}
}
return null;
}
示例6: handleDocumentsProvider
import android.content.pm.ProviderInfo; //导入依赖的package包/类
private void handleDocumentsProvider(ProviderInfo info) {
// Ignore stopped packages for now; we might query them
// later during UI interaction.
if ((info.applicationInfo.flags & ApplicationInfo.FLAG_STOPPED) != 0) {
if (LOGD) Log.d(TAG, "Ignoring stopped authority " + info.authority);
mTaskStoppedAuthorities.add(info.authority);
return;
}
// Try using cached roots if filtering
boolean cacheHit = false;
if (mAuthority != null && !mAuthority.equals(info.authority)) {
synchronized (mLock) {
if (mTaskRoots.putAll(info.authority, mRoots.get(info.authority))) {
if (LOGD) Log.d(TAG, "Used cached roots for " + info.authority);
cacheHit = true;
}
}
}
// Cache miss, or loading everything
if (!cacheHit) {
mTaskRoots.putAll(info.authority,
loadRootsForAuthority(mContext.getContentResolver(), info.authority));
}
}
示例7: queryContentProviders
import android.content.pm.ProviderInfo; //导入依赖的package包/类
@Override
public VParceledListSlice<ProviderInfo> queryContentProviders(String processName, int vuid, int flags) {
int userId = VUserHandle.getUserId(vuid);
checkUserId(userId);
flags = updateFlagsNought(flags);
ArrayList<ProviderInfo> finalList = new ArrayList<>(3);
// reader
synchronized (mPackages) {
for (VPackage.ProviderComponent p : mProvidersByComponent.values()) {
PackageSetting ps = (PackageSetting) p.owner.mExtras;
if (processName == null || ps.appId == VUserHandle.getAppId(vuid) && p.info.processName.equals(processName)) {
ProviderInfo providerInfo = PackageParserEx.generateProviderInfo(p, flags, ps.readUserState(userId), userId);
finalList.add(providerInfo);
}
}
}
if (!finalList.isEmpty()) {
Collections.sort(finalList, sProviderInitOrderSorter);
}
return new VParceledListSlice<>(finalList);
}
示例8: queryIntentContentProviders
import android.content.pm.ProviderInfo; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public List<ResolveInfo> queryIntentContentProviders(Intent intent, String resolvedType, int flags, int userId) {
checkUserId(userId);
flags = updateFlagsNought(flags);
ComponentName comp = intent.getComponent();
if (comp == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
if (intent.getSelector() != null) {
intent = intent.getSelector();
comp = intent.getComponent();
}
}
}
if (comp != null) {
final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1);
final ProviderInfo pi = getProviderInfo(comp, flags, userId);
if (pi != null) {
final ResolveInfo ri = new ResolveInfo();
ri.providerInfo = pi;
list.add(ri);
}
return list;
}
// reader
synchronized (mPackages) {
String pkgName = intent.getPackage();
if (pkgName == null) {
return mProviders.queryIntent(intent, resolvedType, flags, userId);
}
final VPackage pkg = mPackages.get(pkgName);
if (pkg != null) {
return mProviders.queryIntentForPackage(intent, resolvedType, flags, pkg.providers, userId);
}
return Collections.emptyList();
}
}
示例9: generateProviderInfo
import android.content.pm.ProviderInfo; //导入依赖的package包/类
public static ProviderInfo generateProviderInfo(VPackage.ProviderComponent p, int flags,
PackageUserState state, int userId) {
if (p == null) return null;
if (!checkUseInstalledOrHidden(state, flags)) {
return null;
}
// Make shallow copies so we can store the metadata safely
ProviderInfo pi = new ProviderInfo(p.info);
if ((flags & PackageManager.GET_META_DATA) != 0
&& (p.metaData != null)) {
pi.metaData = p.metaData;
}
if ((flags & PackageManager.GET_URI_PERMISSION_PATTERNS) == 0) {
pi.uriPermissionPatterns = null;
}
pi.applicationInfo = generateApplicationInfo(p.owner, flags, state, userId);
return pi;
}
示例10: getMyAuthority
import android.content.pm.ProviderInfo; //导入依赖的package包/类
private String getMyAuthority() throws PackageManager.NameNotFoundException, IllegalAccessException {
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
return (String) FieldUtils.readField(this, "mAuthority");
} else {
Context context = getContext();
PackageInfo pkgInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PROVIDERS);
if (pkgInfo != null && pkgInfo.providers != null && pkgInfo.providers.length > 0) {
for (ProviderInfo info : pkgInfo.providers) {
if (TextUtils.equals(info.name, getClass().getName())) {
return info.authority;
}
}
}
}
return null;
}
示例11: resolveContentProvider
import android.content.pm.ProviderInfo; //导入依赖的package包/类
public ProviderInfo resolveContentProvider(String name, int flags) throws RemoteException {
waitForReadyInner();
try {
enforcePluginFileExists();
if (shouldNotBlockOtherInfo()) {
for (PluginPackageParser pluginPackageParser : this.mPluginCache.values()) {
for (ProviderInfo providerInfo : pluginPackageParser.getProviders()) {
if (TextUtils.equals(providerInfo.authority, name)) {
return providerInfo;
}
}
}
}
List<String> pkgs = this.mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid());
for (PluginPackageParser pluginPackageParser2 : this.mPluginCache.values()) {
for (ProviderInfo providerInfo2 : pluginPackageParser2.getProviders()) {
if (TextUtils.equals(providerInfo2.authority, name) && pkgs.contains(providerInfo2.packageName)) {
return providerInfo2;
}
}
}
} catch (Exception e) {
handleException(e);
}
return null;
}
示例12: getProviderInfo
import android.content.pm.ProviderInfo; //导入依赖的package包/类
public ProviderInfo getProviderInfo(ComponentName className, int flags) throws NameNotFoundException, RemoteException {
ProviderInfo providerInfo = null;
if (className != null) {
try {
if (!(this.mApkManager == null || className == null)) {
providerInfo = this.mApkManager.getProviderInfo(className, flags);
}
} catch (RemoteException e) {
JLog.log("wuxinrong", "获取Provider信息 失败 e=" + e.getMessage());
throw e;
} catch (Exception e2) {
JLog.log("wuxinrong", "获取Provider信息 失败 e=" + e2.getMessage());
}
}
return providerInfo;
}
示例13: getAuthorityFromPermission
import android.content.pm.ProviderInfo; //导入依赖的package包/类
private static String getAuthorityFromPermission(String permission) {
List<PackageInfo> packs = BaseApplication.getInstance().getPackageManager().getInstalledPackages(8);
if (packs != null) {
for (PackageInfo pack : packs) {
ProviderInfo[] providers = pack.providers;
if (!BaseTypeUtils.isArrayEmpty(providers)) {
for (ProviderInfo provider : providers) {
String readPermission = provider.readPermission;
if (readPermission != null && permission.equals(readPermission)) {
return provider.authority;
}
}
continue;
}
}
}
return null;
}
示例14: afterInvoke
import android.content.pm.ProviderInfo; //导入依赖的package包/类
@Override
protected void afterInvoke(Object receiver, Method method, Object[] args, Object invokeResult) throws Throwable {
if (args != null) {
if (invokeResult == null) {
final int index0 = 0, index1 = 1;
if (args.length >= 2 && args[index0] instanceof String && args[index1] instanceof Integer) {
String name = (String) args[index0];
Integer flags = (Integer) args[index1];
ProviderInfo info = PluginManager.getInstance().resolveContentProvider(name, flags);
if (info != null) {
setFakedResult(info);
}
}
}
}
super.afterInvoke(receiver, method, args, invokeResult);
}
示例15: newResult
import android.content.pm.ProviderInfo; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected ResolveInfo newResult(PackageParser.ProviderIntentInfo filter, int match) {
final PackageParser.Provider provider = filter.provider;
ProviderInfo pi = PackageParserCompat.generateProviderInfo(provider, mFlags);
if (pi == null) {
return null;
}
final ResolveInfo res = new ResolveInfo();
res.providerInfo = pi;
if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) {
res.filter = filter;
}
res.priority = filter.getPriority();
res.preferredOrder = provider.owner.mPreferredOrder;
res.match = match;
res.isDefault = filter.hasDefault;
res.labelRes = filter.labelRes;
res.nonLocalizedLabel = filter.nonLocalizedLabel;
res.icon = filter.icon;
return res;
}