use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.
the class LocalRepoManager method writeFdroidApkToWebroot.
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;
}
use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.
the class ApkCache method copyInstalledApkToFiles.
/**
* 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);
}
use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.
the class ApkCache method copyApkToFiles.
/**
* 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);
// 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 && !Utils.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;
}
use of org.fdroid.fdroid.data.SanitizedFile in project fdroidclient by f-droid.
the class FileCompatTest method setUp.
@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());
}
Aggregations