本文整理汇总了Java中org.fdroid.fdroid.data.SanitizedFile类的典型用法代码示例。如果您正苦于以下问题:Java SanitizedFile类的具体用法?Java SanitizedFile怎么用?Java SanitizedFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SanitizedFile类属于org.fdroid.fdroid.data包,在下文中一共展示了SanitizedFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSafeUri
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
private static Uri getSafeUri(Context context, SanitizedFile tempApkFile, boolean useContentUri) {
if (useContentUri) {
// return a content Uri using support libs FileProvider
Uri apkUri = getUriForFile(context, AUTHORITY, tempApkFile);
context.grantUriPermission("org.fdroid.fdroid.privileged", apkUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.grantUriPermission("com.android.bluetooth", apkUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
return apkUri;
}
// Need the apk to be world readable, so that the installer is able to read it.
// Note that saving it into external storage for the purpose of letting the installer
// have access is insecure, because apps with permission to write to the external
// storage can overwrite the app between F-Droid asking for it to be installed and
// the installer actually installing it.
tempApkFile.setReadable(true, false);
return Uri.fromFile(tempApkFile);
}
示例2: symlinkRuntime
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
static void symlinkRuntime(SanitizedFile source, SanitizedFile dest) {
String[] commands = {
FDroidApp.SYSTEM_DIR_NAME + "/bin/ln",
"-s",
source.getAbsolutePath(),
dest.getAbsolutePath(),
};
try {
Utils.debugLog(TAG, "Executing command: " + commands[0] + " " + commands[1]
+ " " + commands[2] + " " + commands[3]);
Process proc = Runtime.getRuntime().exec(commands);
Utils.consumeStream(proc.getInputStream());
Utils.consumeStream(proc.getErrorStream());
} catch (IOException e) {
// Do nothing
}
}
示例3: writeFdroidApkToWebroot
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
private String writeFdroidApkToWebroot() {
ApplicationInfo appInfo;
String fdroidClientURL = "https://f-droid.org/FDroid.apk";
try {
appInfo = pm.getApplicationInfo(fdroidPackageName, PackageManager.GET_META_DATA);
SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir);
SanitizedFile fdroidApkLink = new SanitizedFile(fdroidDir, "F-Droid.apk");
attemptToDelete(fdroidApkLink);
if (Utils.symlinkOrCopyFileQuietly(apkFile, fdroidApkLink)) {
fdroidClientURL = "/" + fdroidDir.getName() + "/" + fdroidApkLink.getName();
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Could not set up F-Droid apk in the webroot", e);
}
return fdroidClientURL;
}
示例4: setMode
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
private static boolean setMode(SanitizedFile file, String mode) {
// The "file" must be a sanitized file, and hence only contain A-Za-z0-9.-_ already,
// but it makes no assurances about the parent directory.
final String[] args = {
"/system/bin/chmod",
mode,
file.getAbsolutePath(),
};
try {
Utils.debugLog(TAG, "Executing following command: " + args[0] + " " + args[1] + " " + args[2]);
Process proc = Runtime.getRuntime().exec(args);
Utils.consumeStream(proc.getInputStream());
Utils.consumeStream(proc.getErrorStream());
return true;
} catch (IOException e) {
return false;
}
}
示例5: writeFdroidApkToWebroot
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
private String writeFdroidApkToWebroot() {
ApplicationInfo appInfo;
String fdroidClientURL = "https://f-droid.org/FDroid.apk";
try {
appInfo = pm.getApplicationInfo(fdroidPackageName, PackageManager.GET_META_DATA);
SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir);
SanitizedFile fdroidApkLink = new SanitizedFile(webRoot, "fdroid.client.apk");
attemptToDelete(fdroidApkLink);
if (Utils.symlinkOrCopyFileQuietly(apkFile, fdroidApkLink)) {
fdroidClientURL = "/" + fdroidApkLink.getName();
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Could not set up F-Droid apk in the webroot", e);
}
return fdroidClientURL;
}
示例6: symlink
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
public static boolean symlink(SanitizedFile source, SanitizedFile dest) {
if (Build.VERSION.SDK_INT >= 21) {
symlinkOs(source, dest);
} else if (Build.VERSION.SDK_INT >= 15) {
symlinkLibcore(source, dest);
} else {
symlinkRuntime(source, dest);
}
return dest.exists();
}
示例7: symlinkLibcore
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
static void symlinkLibcore(SanitizedFile source, SanitizedFile dest) {
try {
Object os = Class.forName("libcore.io.Libcore").getField("os").get(null);
Method symlink = os.getClass().getMethod("symlink", String.class, String.class);
symlink.invoke(os, source.getAbsolutePath(), dest.getAbsolutePath());
} catch (Exception e) {
// Should catch more specific exceptions than just "Exception" here, but there are
// some which come from libcore.io.Libcore, which we don't have access to at compile time.
Log.e(TAG, "Could not symlink " + source.getAbsolutePath() + " to " + dest.getAbsolutePath(), e);
}
}
示例8: copyInstalledApkToFiles
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
/**
* Same as {@link #copyApkFromCacheToFiles(Context, File, Apk)}, except it does not need to
* verify the hash after copying. This is because we are copying from an installed apk, which
* other apps do not have permission to modify.
*/
public static SanitizedFile copyInstalledApkToFiles(Context context, PackageInfo packageInfo)
throws IOException {
ApplicationInfo appInfo = packageInfo.applicationInfo;
CharSequence name = context.getPackageManager().getApplicationLabel(appInfo);
String apkFileName = name + "-" + packageInfo.versionName + ".apk";
return copyApkToFiles(context, new File(appInfo.publicSourceDir), apkFileName, false, null, null);
}
示例9: copyApkFromCacheToFiles
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
/**
* Copy the APK to the safe location inside of the protected area
* of the app to prevent attacks based on other apps swapping the file
* out during the install process. Most likely, apkFile was just downloaded,
* so it should still be in the RAM disk cache.
*/
public static SanitizedFile copyApkFromCacheToFiles(Context context, File apkFile, Apk expectedApk)
throws IOException {
App app = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(),
expectedApk.packageName);
String name = app == null ? expectedApk.packageName : app.name;
String apkFileName = name + "-" + expectedApk.versionName + ".apk";
return copyApkToFiles(context, apkFile, apkFileName, true, expectedApk.hash, expectedApk.hashType);
}
示例10: copyApkToFiles
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
/**
* Copy an APK from {@param apkFile} to our internal files directory for 20 minutes.
*
* @param verifyHash If the file was just downloaded, then you should mark this as true and
* request the file to be verified once it has finished copying. Otherwise,
* if the app was installed from part of the system where it can't be tampered
* with (e.g. installed apks on disk) then
*/
private static SanitizedFile copyApkToFiles(Context context, File apkFile, String destinationName,
boolean verifyHash, String hash, String hashType)
throws IOException {
SanitizedFile sanitizedApkFile = new SanitizedFile(context.getFilesDir(), destinationName);
// Don't think this is necessary, but the docs for FileUtils#copyFile() are not clear
// on whether it overwrites destination files (pretty confident it does, as per the docs
// in FileUtils#copyFileToDirectory() - which delegates to copyFile()).
if (sanitizedApkFile.exists()) {
sanitizedApkFile.delete();
}
FileUtils.copyFile(apkFile, sanitizedApkFile);
// verify copied file's hash with expected hash from Apk class
if (verifyHash && !Hasher.isFileMatchingHash(sanitizedApkFile, hash, hashType)) {
FileUtils.deleteQuietly(apkFile);
throw new IOException(apkFile + " failed to verify!");
}
// 20 minutes the start of the install process, delete the file
final File apkToDelete = sanitizedApkFile;
new Thread() {
@Override
public void run() {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST);
try {
Thread.sleep(1200000);
} catch (InterruptedException ignored) {
} finally {
FileUtils.deleteQuietly(apkToDelete);
}
}
}.start();
return sanitizedApkFile;
}
示例11: getApkDownloadPath
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
/**
* Get the full path for where an APK URL will be downloaded into.
*/
public static SanitizedFile getApkDownloadPath(Context context, Uri uri) {
File dir = new File(getApkCacheDir(context), uri.getHost() + "-" + uri.getPort());
if (!dir.exists()) {
dir.mkdirs();
}
return new SanitizedFile(dir, uri.getLastPathSegment());
}
示例12: LocalRepoManager
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
private LocalRepoManager(Context c) {
context = c.getApplicationContext();
pm = c.getPackageManager();
assetManager = c.getAssets();
fdroidPackageName = c.getPackageName();
webRoot = SanitizedFile.knownSanitized(c.getFilesDir());
/* /fdroid/repo is the standard path for user repos */
fdroidDir = new SanitizedFile(webRoot, "fdroid");
fdroidDirCaps = new SanitizedFile(webRoot, "FDROID");
repoDir = new SanitizedFile(fdroidDir, "repo");
repoDirCaps = new SanitizedFile(fdroidDirCaps, "REPO");
iconsDir = new SanitizedFile(repoDir, "icons");
xmlIndexJar = new SanitizedFile(repoDir, "index.jar");
xmlIndexJarUnsigned = new SanitizedFile(repoDir, "index.unsigned.jar");
if (!fdroidDir.exists() && !fdroidDir.mkdir()) {
Log.e(TAG, "Unable to create empty base: " + fdroidDir);
}
if (!repoDir.exists() && !repoDir.mkdir()) {
Log.e(TAG, "Unable to create empty repo: " + repoDir);
}
if (!iconsDir.exists() && !iconsDir.mkdir()) {
Log.e(TAG, "Unable to create icons folder: " + iconsDir);
}
}
示例13: copyApksToRepo
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
private void copyApksToRepo(List<String> appsToCopy) {
for (final String packageName : appsToCopy) {
final App app = apps.get(packageName);
if (app.installedApk != null) {
SanitizedFile outFile = new SanitizedFile(repoDir, app.installedApk.apkName);
if (Utils.symlinkOrCopyFileQuietly(app.installedApk.installedFile, outFile)) {
continue;
}
}
// if we got here, something went wrong
throw new IllegalStateException("Unable to copy APK");
}
}
示例14: setUp
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
@Before
public void setUp() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
File dir = getWriteableDir(instrumentation);
sourceFile = SanitizedFile.knownSanitized(
AssetUtils.copyAssetToDir(instrumentation.getContext(), "simpleIndex.jar", dir));
destFile = new SanitizedFile(dir, "dest-" + UUID.randomUUID() + ".testproduct");
assertFalse(destFile.exists());
assertTrue(sourceFile.getAbsolutePath() + " should exist.", sourceFile.exists());
}
示例15: symlinkRuntime
import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
protected static void symlinkRuntime(SanitizedFile source, SanitizedFile dest) {
String[] commands = {
"/system/bin/ln",
source.getAbsolutePath(),
dest.getAbsolutePath(),
};
try {
Utils.debugLog(TAG, "Executing command: " + commands[0] + " " + commands[1] + " " + commands[2]);
Process proc = Runtime.getRuntime().exec(commands);
Utils.consumeStream(proc.getInputStream());
Utils.consumeStream(proc.getErrorStream());
} catch (IOException e) {
// Do nothing
}
}