@Override public File getFileStreamPath(String name) { return mBase.getFileStreamPath(name); }
public boolean fileExists(Context context, String filename) { File file = context.getFileStreamPath(filename); if(file == null || !file.exists()) { return false; } return true; }
/** * If you want to make sure that the next exception of any time is posted, you need to clear limiter data * * ACRA 5.3.x does this automatically on version upgrade (https://github.com/ACRA/acra/pull/696), until then they blessed deleting file * @param context the context leading to the directory with ACRA limiter data */ public static void deleteACRALimiterData(Context context) { context.getFileStreamPath("ACRA-limiter.json").delete(); }
protected void updateMonitoringStatusTime(long time) { File file = mContext.getFileStreamPath(STATUS_PRESERVATION_FILE_NAME); file.setLastModified(time); }
protected long getLastMonitoringStatusUpdateTime() { File file = mContext.getFileStreamPath(STATUS_PRESERVATION_FILE_NAME); return file.lastModified(); }
public static void startup(Context context) { File flagFile = context.getFileStreamPath(Constants.NO_NOTIFICATION_FLAG); if (Build.VERSION.SDK_INT >= 25 && flagFile.exists()) { showNotification = false; } context.startService(new Intent(context, DaemonService.class)); if (VirtualCore.get().isServerProcess()) { // PrivilegeAppOptimizer.notifyBootFinish(); DaemonJobService.scheduleJob(context); } }
private void handlePipeOutput(OutputStream output) throws DumpException { File hprofFile = mContext.getFileStreamPath("hprof-dump.hprof"); try { writeHprof(hprofFile); try { InputStream input = new FileInputStream(hprofFile); try { Util.copy(input, output, new byte[2048]); } finally { input.close(); } } catch (IOException e) { throw new DumpException("Failure copying " + hprofFile + " to dumper output"); } } finally { if (hprofFile.exists()) { hprofFile.delete(); } } }
public void store(@NonNull Context context) throws IOException { IOUtils.writeStringToFile(context.getFileStreamPath(FILE_LIMITER_DATA), toJSON()); }
private static void saveEventsToDisk( PersistedEvents eventsToPersist) { ObjectOutputStream oos = null; Context context = FacebookSdk.getApplicationContext(); try { oos = new ObjectOutputStream( new BufferedOutputStream( context.openFileOutput(PERSISTED_EVENTS_FILENAME, 0))); oos.writeObject(eventsToPersist); } catch (Exception e) { Log.w(TAG, "Got unexpected exception while persisting events: ", e); try { context.getFileStreamPath(PERSISTED_EVENTS_FILENAME).delete(); } catch (Exception innerException) { // ignore } } finally { Utility.closeQuietly(oos); } }
@Override public void dump(DumperContext dumpContext) throws DumpException { final PrintStream output = dumpContext.getStdout(); Iterator<String> argsIter = dumpContext.getArgsAsList().iterator(); String outputPath = argsIter.hasNext() ? argsIter.next() : null; if (outputPath == null) { usage(output); } else { if ("-".equals(outputPath)) { handlePipeOutput(output); } else { File outputFile = new File(outputPath); if (!outputFile.isAbsolute()) { outputFile = mContext.getFileStreamPath(outputPath); } writeHprof(outputFile); output.println("Wrote to " + outputFile); } } }
/** * 把Assets里面得文件复制到 /data/data/files 目录下 * * @param context * @param sourceName */ public static void extractAssets(Context context, String sourceName) { AssetManager am = context.getAssets(); InputStream is = null; FileOutputStream fos = null; try { is = am.open(sourceName); File extractFile = context.getFileStreamPath(sourceName); fos = new FileOutputStream(extractFile); byte[] buffer = new byte[1024]; int count = 0; while ((count = is.read(buffer)) > 0) { fos.write(buffer, 0, count); } fos.flush(); } catch (IOException e) { e.printStackTrace(); } finally { closeSilently(is); closeSilently(fos); } }
/** * 把Assets里面得文件复制到 /data/data/files 目录下 * * @param context * @param sourceName */ public static void extractAssets(Context context, String sourceName) { AssetManager am = context.getAssets(); InputStream is = null; FileOutputStream fos = null; try { is = am.open(sourceName); File extractFile = context.getFileStreamPath(sourceName); fos = new FileOutputStream(extractFile); byte[] buffer = new byte[1024]; int count = 0; while ((count = is.read(buffer)) > 0) { fos.write(buffer, 0, count); } fos.flush(); } catch (IOException e) { e.printStackTrace(); } finally { closeSilently(is); closeSilently(fos); } }
private static File getPluginBaseDir(String packageName) { if (sBaseDir == null) { sBaseDir = UPFApplication.getContext().getFileStreamPath("plugin"); enforceDirExists(sBaseDir); } return enforceDirExists(new File(sBaseDir, packageName)); }
context.getFileStreamPath(PERSISTED_EVENTS_FILENAME).delete(); } catch (Exception ex) { Log.w(TAG, "Got unexpected exception when removing events file: ", ex);
public static VPackage parsePackage(File packageFile) throws Throwable { PackageParser parser = PackageParserCompat.createParser(packageFile); PackageParser.Package p = PackageParserCompat.parsePackage(parser, packageFile, 0); if (p.requestedPermissions.contains("android.permission.FAKE_PACKAGE_SIGNATURE") && p.mAppMetaData != null && p.mAppMetaData.containsKey("fake-signature")) { String sig = p.mAppMetaData.getString("fake-signature"); p.mSignatures = new Signature[]{new Signature(sig)}; VLog.d(TAG, "Using fake-signature feature on : " + p.packageName); } else { try { PackageParserCompat.collectCertificates(parser, p, PackageParser.PARSE_IS_SYSTEM); } catch (Throwable e) { VLog.e(TAG, "collectCertificates failed", e); if (VirtualCore.get().getContext().getFileStreamPath(Constants.FAKE_SIGNATURE_FLAG).exists()) { VLog.w(TAG, "Using fake signature: " + p.packageName); p.mSignatures = new Signature[]{new Signature(FAKE_SIG)}; } else { throw e; } } } return buildPackageCache(p); }
@Override public File getFileStreamPath(String name) { return mBase.getFileStreamPath(name); }
boolean enableXposed = !VirtualCore.get().getContext().getFileStreamPath(".disable_xposed").exists(); if (enableXposed) { VLog.i(TAG, "Xposed is enabled.");
/** * Write to the given file in the private files dir, first renaming an old one to .bak * * @param context A context * @param filename A filename as for @{link {@link Context#openFileOutput(String, int)}} * @return See @{link {@link Context#openFileOutput(String, int)}} * @throws IOException See @{link {@link Context#openFileOutput(String, int)}} */ public static OutputStream openWrite(Context context, String filename) throws IOException { File out = context.getFileStreamPath(filename); // Create backup out.renameTo(context.getFileStreamPath(filename + ".bak")); return context.openFileOutput(filename, Context.MODE_PRIVATE); }
@Test public void testOpenWrite() throws Exception { File file = mock(File.class); File file2 = mock(File.class); FileOutputStream fos = mock(FileOutputStream.class); when(mockContext.getFileStreamPath(eq("filename"))).thenReturn(file); when(mockContext.getFileStreamPath(eq("filename.bak"))).thenReturn(file2); when(mockContext.openFileOutput(eq("filename"), anyInt())).thenReturn(fos); assertSame(fos, FileHelper.openWrite(mockContext, "filename")); Mockito.verify(file).renameTo(file2); Mockito.verify(mockContext).openFileOutput(eq("filename"), anyInt()); }
// Renames a file stored in the application's private store. public static void RenameAppFile(Context context, String originalFileName, String newFileName) { File originalFile = context.getFileStreamPath(originalFileName); File newFile = new File(originalFile.getParent(), newFileName); if (newFile.exists()) { // Or you could throw here. context.deleteFile(newFileName); } originalFile.renameTo(newFile); }