请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SanitizedFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.fdroid.fdroid.data.SanitizedFile的典型用法代码示例。如果您正苦于以下问题:Java SanitizedFile类的具体用法?Java SanitizedFile怎么用?Java SanitizedFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SanitizedFile类属于org.fdroid.fdroid.data包,在下文中一共展示了SanitizedFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:19,代码来源:ApkFileProvider.java


示例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
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:18,代码来源:FileCompat.java


示例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;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:18,代码来源:LocalRepoManager.java


示例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;
        }

    }
 
开发者ID:CmDnoEdition,项目名称:fdroid,代码行数:22,代码来源:FileCompat.java


示例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;
}
 
开发者ID:CmDnoEdition,项目名称:fdroid,代码行数:18,代码来源:LocalRepoManager.java


示例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();
    }
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:13,代码来源:FileCompat.java


示例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);
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:12,代码来源:FileCompat.java


示例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);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:13,代码来源:ApkCache.java


示例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);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:15,代码来源:ApkCache.java


示例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;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:46,代码来源:ApkCache.java


示例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());
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:11,代码来源:ApkCache.java


示例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);
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:29,代码来源:LocalRepoManager.java


示例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");
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:15,代码来源:LocalRepoManager.java


示例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());
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:11,代码来源:FileCompatTest.java


示例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
    }
}
 
开发者ID:CmDnoEdition,项目名称:fdroid,代码行数:16,代码来源:FileCompat.java


示例16: symlinkLibcore

import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
protected 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);
    }
}
 
开发者ID:CmDnoEdition,项目名称:fdroid,代码行数:12,代码来源:FileCompat.java


示例17: setReadable

import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
@TargetApi(9)
public static boolean setReadable(SanitizedFile file, boolean readable, boolean ownerOnly) {

    if (Build.VERSION.SDK_INT >= 9) {
        return file.setReadable(readable, ownerOnly);
    }
    String mode;
    if (readable) {
        mode = ownerOnly ? "0600" : "0644";
    } else {
        mode = "0000";
    }
    return setMode(file, mode);

}
 
开发者ID:CmDnoEdition,项目名称:fdroid,代码行数:16,代码来源:FileCompat.java


示例18: setExecutable

import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
@TargetApi(9)
public static boolean setExecutable(SanitizedFile file, boolean executable, boolean ownerOnly) {

    if (Build.VERSION.SDK_INT >= 9) {
        return file.setExecutable(executable, ownerOnly);
    }
    String mode;
    if (executable) {
        mode = ownerOnly ? "0700" : "0711";
    } else {
        mode = ownerOnly ? "0600" : "0600";
    }
    return setMode(file, mode);

}
 
开发者ID:CmDnoEdition,项目名称:fdroid,代码行数:16,代码来源:FileCompat.java


示例19: 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");
    xmlIndex = new SanitizedFile(repoDir, "index.xml");
    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);
    }
}
 
开发者ID:CmDnoEdition,项目名称:fdroid,代码行数:30,代码来源:LocalRepoManager.java


示例20: getApkCacheDir

import org.fdroid.fdroid.data.SanitizedFile; //导入依赖的package包/类
/**
 * This location is only for caching, do not install directly from this location
 * because if the file is on the External Storage, any other app could swap out
 * the APK while the install was in process, allowing malware to install things.
 * Using {@link org.fdroid.fdroid.installer.Installer#installPackage(File, String, String)}
 * is fine since that does the right thing.
 */
public static SanitizedFile getApkCacheDir(Context context) {
    final SanitizedFile apkCacheDir = new SanitizedFile(StorageUtils.getCacheDirectory(context, true), "apks");
    if (!apkCacheDir.exists()) {
        apkCacheDir.mkdir();
    }
    return apkCacheDir;
}
 
开发者ID:CmDnoEdition,项目名称:fdroid,代码行数:15,代码来源:Utils.java



注:本文中的org.fdroid.fdroid.data.SanitizedFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AutoEncoder类代码示例发布时间:2022-05-16
下一篇:
Java Request类代码示例发布时间:2022-05-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap