/** * Check if given filename is valid for an ext4 filesystem. */ public static boolean isValidExtFilename(String name) { return (name != null) && name.equals(buildValidExtFilename(name)); }
private void chmodPackageDictionary(File packageFile) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (FileUtils.isSymlink(packageFile)) { return; } FileUtils.chmod(packageFile.getParentFile().getAbsolutePath(), FileUtils.FileMode.MODE_755); FileUtils.chmod(packageFile.getAbsolutePath(), FileUtils.FileMode.MODE_755); } } catch (Exception e) { e.printStackTrace(); } }
public static void copyFile(File source, File target) throws IOException { FileInputStream inputStream = null; FileOutputStream outputStream = null; try { inputStream = new FileInputStream(source); outputStream = new FileOutputStream(target); FileChannel iChannel = inputStream.getChannel(); FileChannel oChannel = outputStream.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(1024); while (true) { buffer.clear(); int r = iChannel.read(buffer); if (r == -1) break; buffer.limit(buffer.position()); buffer.position(0); oChannel.write(buffer); } } finally { closeQuietly(inputStream); closeQuietly(outputStream); } }
public static boolean deleteDir(String dir) { return deleteDir(new File(dir)); }
File libDir = new File(appDir, "lib"); if (res.isUpdate) { FileUtils.deleteDir(libDir); VEnvironment.getOdexFile(pkg.packageName).delete(); VActivityManagerService.get().killAppByPkg(pkg.packageName, VUserHandle.USER_ALL); FileUtils.copyFile(packageFile, privatePackageFile); } catch (IOException e) { privatePackageFile.delete();
private void createRemoveSplitMarker(String splitName) throws IOException { try { final String markerName = splitName + REMOVE_SPLIT_MARKER_EXTENSION; if (!FileUtils.isValidExtFilename(markerName)) { throw new IllegalArgumentException("Invalid marker: " + markerName); } final File target = new File(resolveStageDir(), markerName); target.createNewFile(); Os.chmod(target.getAbsolutePath(), 0 /*mode*/); } catch (ErrnoException e) { throw new IOException(e); } }
public static void systemReady() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { FileUtils.chmod(ROOT.getAbsolutePath(), FileUtils.FileMode.MODE_755); FileUtils.chmod(DATA_DIRECTORY.getAbsolutePath(), FileUtils.FileMode.MODE_755); FileUtils.chmod(getDataAppDirectory().getAbsolutePath(), FileUtils.FileMode.MODE_755); } catch (Exception e) { e.printStackTrace(); } } }
private boolean handleInstallRequest(Intent intent) { IAppRequestListener listener = VirtualCore.get().getAppRequestListener(); if (listener != null) { Uri packageUri = intent.getData(); String sourcePath = FileUtils.getFileFromUri(getHostContext(), packageUri); try { listener.onRequestInstall(sourcePath); return true; } catch (RemoteException e) { e.printStackTrace(); } } return false; }
/** * Mutate the given filename to make it valid for an ext4 filesystem, * replacing any invalid characters with "_". */ public static String buildValidExtFilename(String name) { if (TextUtils.isEmpty(name) || ".".equals(name) || "..".equals(name)) { return "(invalid)"; } final StringBuilder res = new StringBuilder(name.length()); for (int i = 0; i < name.length(); i++) { final char c = name.charAt(i); if (isValidExtFilenameChar(c)) { res.append(c); } else { res.append('_'); } } return res.toString(); }
private void save() { File uidFile = VEnvironment.getUidListFile(); File bakUidFile = VEnvironment.getBakUidListFile(); if (uidFile.exists()) { if (bakUidFile.exists() && !bakUidFile.delete()) { VLog.w(TAG, "Warning: Unable to delete the expired file --\n " + bakUidFile.getPath()); } try { FileUtils.copyFile(uidFile, bakUidFile); } catch (IOException e) { e.printStackTrace(); } } try { ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(uidFile)); os.writeInt(mFreeUid); os.writeObject(mSharedUserIdMap); os.close(); } catch (IOException e) { e.printStackTrace(); } }
public static boolean deleteDir(File dir, Set<File> ignores) { if (dir.isDirectory()) { String[] children = dir.list(); for (String file : children) { boolean success = deleteDir(new File(dir, file), ignores); if (!success) { return false; } } } return ignores != null && ignores.contains(dir) || dir.delete(); }
File libDir = new File(appDir, "lib"); if (res.isUpdate) { FileUtils.deleteDir(libDir); VEnvironment.getOdexFile(pkg.packageName).delete(); VActivityManagerService.get().killAppByPkg(pkg.packageName, VUserHandle.USER_ALL); FileUtils.copyFile(packageFile, privatePackageFile); } catch (IOException e) { privatePackageFile.delete();
public static void copyDir(String sourcePath, String targetPath) throws IOException { File from = new File(sourcePath); if (!from.exists()) { return; } File to = new File(targetPath); if (!to.exists()) { boolean mkdirs = to.mkdirs(); if (!mkdirs) { return; } } String[] child = from.list(); for (String file : child) { File childSource = new File(sourcePath, file); if (childSource.isDirectory()) { copyDir(sourcePath + File.separator + file, targetPath + File.separator + file); } else { copyFile(childSource, new File(targetPath, file)); } } }
private ParcelFileDescriptor openReadInternal(String name) throws IOException { assertPreparedAndNotSealed("openRead"); try { if (!FileUtils.isValidExtFilename(name)) { throw new IllegalArgumentException("Invalid name: " + name); } final File target = new File(resolveStageDir(), name); final FileDescriptor targetFd = Os.open(target.getAbsolutePath(), O_RDONLY, 0); return ParcelFileDescriptor.dup(targetFd); } catch (ErrnoException e) { throw new IOException(e); } }
public static void systemReady() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { FileUtils.chmod(ROOT.getAbsolutePath(), FileUtils.FileMode.MODE_755); FileUtils.chmod(DATA_DIRECTORY.getAbsolutePath(), FileUtils.FileMode.MODE_755); FileUtils.chmod(getDataAppDirectory().getAbsolutePath(), FileUtils.FileMode.MODE_755); } catch (Exception e) { e.printStackTrace(); } } }
private boolean handleInstallRequest(Intent intent) { IAppRequestListener listener = VirtualCore.get().getAppRequestListener(); if (listener != null) { Uri packageUri = intent.getData(); String sourcePath = FileUtils.getFileFromUri(getHostContext(), packageUri); try { listener.onRequestInstall(sourcePath); return true; } catch (RemoteException e) { e.printStackTrace(); } } return false; }
/** * Mutate the given filename to make it valid for an ext4 filesystem, * replacing any invalid characters with "_". */ public static String buildValidExtFilename(String name) { if (TextUtils.isEmpty(name) || ".".equals(name) || "..".equals(name)) { return "(invalid)"; } final StringBuilder res = new StringBuilder(name.length()); for (int i = 0; i < name.length(); i++) { final char c = name.charAt(i); if (isValidExtFilenameChar(c)) { res.append(c); } else { res.append('_'); } } return res.toString(); }
private void save() { File uidFile = VEnvironment.getUidListFile(); File bakUidFile = VEnvironment.getBakUidListFile(); if (uidFile.exists()) { if (bakUidFile.exists() && !bakUidFile.delete()) { VLog.w(TAG, "Warning: Unable to delete the expired file --\n " + bakUidFile.getPath()); } try { FileUtils.copyFile(uidFile, bakUidFile); } catch (IOException e) { e.printStackTrace(); } } try { ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(uidFile)); os.writeInt(mFreeUid); os.writeObject(mSharedUserIdMap); os.close(); } catch (IOException e) { e.printStackTrace(); } }