应用里有个自升级的功能,下载完 apk 后,通过 FileProvider 提供 Uri 进行安装。我修改了文件下载路径后,功能失效了,报错如下:
1 2 3
java.lang.IllegalArgumentException: Failed to find configured root that contains /data/user/0/org.mazhuang.test/cache/download/xxx.apk at android.support.v4.content.FileProvider$SimplePathStrategy.getUriForFile(FileProvider.java:738) at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:417)
@Override public ProviderInfo resolveContentProvider(String name, int flags, int userId) { if (!sUserManager.exists(userId)) returnnull; flags = updateFlagsForComponent(flags, userId, name); finalStringinstantAppPkgName= getInstantAppPackageName(Binder.getCallingUid()); // reader synchronized (mPackages) { final PackageParser.Providerprovider= mProvidersByAuthority.get(name); // some code here } // some code here }
/** * Adds a scanned package to the system. When this method is finished, the package will * be available for query, resolution, etc... */ privatevoidcommitPackageSettings(PackageParser.Package pkg, PackageSetting pkgSetting, UserHandle user, int scanFlags, boolean chatty)throws PackageManagerException { // some code here synchronized (mPackages) { // some code here for (i=0; i<N; i++) { PackageParser.Providerp= pkg.providers.get(i); p.info.processName = fixProcessName(pkg.applicationInfo.processName, p.info.processName); mProviders.addProvider(p); p.syncable = p.info.isSyncable; if (p.info.authority != null) { String names[] = p.info.authority.split(";"); p.info.authority = null; for (intj=0; j < names.length; j++) { // some code here // 【我们要找的地方】 if (!mProvidersByAuthority.containsKey(names[j])) { mProvidersByAuthority.put(names[j], p); if (p.info.authority == null) { p.info.authority = names[j]; } else { p.info.authority = p.info.authority + ";" + names[j]; } // some code here