/** * Restore Backup * * @param name name of backup * @throws BackupNotFoundException * @throws RestoreBackupException */ public void restoreBackup(@NonNull String name) throws BackupNotFoundException, RestoreBackupException { // create source path object File src = new File(SmartphonePreferencesHandler.getBackupPath() + File.separator + name); if (src.exists()) { try { // create destination path object File dst = new File(context.getFilesDir().getParent()); // delete existing files for (File fileOrFolder : dst.listFiles()) { if (fileOrFolder .getPath() .equals(context.getFilesDir().getParent() + File.separator + "shared_prefs") || fileOrFolder .getPath() .equals(context.getFilesDir().getParent() + File.separator + "databases")) { deleteRecursive(fileOrFolder); } } // copy directory to system folder copyDirectory(src, dst); } catch (Exception e) { Log.e(e); throw new RestoreBackupException(e); } } else { throw new BackupNotFoundException(); } }
private void kill_pcscd() { File f = new File(ctx.getFilesDir() + "/pcscd/pcscd.pid"); FileInputStream fis = null; if (f.exists()) { try { // read pid fis = new FileInputStream(f); byte[] pid = new byte[fis.available()]; int num = fis.read(pid); if (num > 0) { // kill pcsc daemon ProcessBuilder pb = new ProcessBuilder("kill", "-9", new String(pid, "UTF-8")); pb.start(); } // cleanup files String del = ctx.getFilesDir() + "/pcscd/*"; ProcessBuilder pb = new ProcessBuilder("rm", "-r", del); pb.start(); } catch (IOException e) { logger.error("Killing the pcsc daemon or cleanup failed.", e); } finally { try { if (fis != null) { fis.close(); } } catch (IOException e) { // ignore } } } }
@Override public void setUp() throws Exception { mTestContext = new RenamingDelegatingContext(getContext(), TEST_PREFIX); Log.d(TAG, "Saving tasks to '" + mTestContext.getFilesDir() + "'"); mTaskStoreUnderTest = JobStore.initAndGetForTesting(mTestContext, mTestContext.getFilesDir()); mComponent = new ComponentName(getContext().getPackageName(), StubClass.class.getName()); }
/** private constructor */ private UninstallCallback(Context c) { /** API level大于17,需要获取userSerialNumber */ if (Build.VERSION.SDK_INT >= 17) { mUserSerial = getUserSerial(c); } this.mContext = c; mFileDir = c.getFilesDir().getPath(); mAppDir = c.getFilesDir().getParent(); mObservedFile = mFileDir + File.separator + UninstallConsts.OBSERVED_FILE; mLockFile = mFileDir + File.separator + UninstallConsts.LOCK_FILE; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { String exPath = Environment.getExternalStorageDirectory().getAbsolutePath(); mLocalPage = exPath + File.separator + UninstallConsts.EXTERNAL_APP_PATH + File.separator + UninstallConsts.LOCAL_PAGE_NAME; } if (mLocalPage != null) { File localPageFile = new File(mLocalPage); if (!localPageFile.exists()) { prepareLocalPage(); } mLocalUrl = UninstallConsts.LOCAL_FILE_URL_HEADER + mLocalPage; } mRemoteUrl = UninstallConsts.REMOTE_URL; };
public static void copyAssetsFromPackage(Context ctx, String fromPath) throws IOException { new File(ctx.getFilesDir().getPath() + "/" + fromPath).mkdir(); for (String f : ctx.getAssets().list(fromPath)) { String current_name = fromPath + "/" + f; InputStream lInputStream; try { lInputStream = ctx.getAssets().open(current_name); } catch (IOException e) { // probably a dir new File(ctx.getFilesDir().getPath() + "/" + current_name).mkdir(); copyAssetsFromPackage(ctx, current_name); continue; } FileOutputStream lOutputStream = new FileOutputStream( new File( ctx.getFilesDir().getPath() + "/" + current_name)); // ctx.openFileOutput (fromPath+"/"+f, 0); int readByte; byte[] buff = new byte[8048]; while ((readByte = lInputStream.read(buff)) != -1) { lOutputStream.write(buff, 0, readByte); } lOutputStream.flush(); lOutputStream.close(); lInputStream.close(); } }
private void save(Context ctx, Object data, String name, String folder) { if (ctx == null) { return; } File file; if (!folder.isEmpty()) { File fileDir = new File(ctx.getFilesDir(), folder); if (!fileDir.exists() || !fileDir.isDirectory()) { fileDir.mkdir(); } file = new File(fileDir, name); } else { file = new File(ctx.getFilesDir(), name); } if (file.exists()) { file.delete(); } try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); oos.writeObject(data); oos.close(); } catch (Exception e) { e.printStackTrace(); } }
@SuppressWarnings("unchecked") private ArrayList<T> load(Context ctx, String name, String folder) { ArrayList<T> data = null; File file; if (!folder.isEmpty()) { File fileDir = new File(ctx.getFilesDir(), folder); if (!fileDir.exists() || !fileDir.isDirectory()) { fileDir.mkdir(); } file = new File(fileDir, name); } else { file = new File(ctx.getFilesDir(), name); } if (file.exists()) { try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); data = (ArrayList<T>) ois.readObject(); ois.close(); } catch (Exception e) { e.printStackTrace(); } } if (data == null) { data = new ArrayList<>(); } return data; }
@SuppressWarnings("unchecked") public T loadGlobalObject(Context ctx, String name) { String folder = FILDER_GLOBAL; T data = null; File file; if (!folder.isEmpty()) { File fileDir = new File(ctx.getFilesDir(), folder); if (!fileDir.exists() || !fileDir.isDirectory()) { fileDir.mkdir(); } file = new File(fileDir, name); } else { file = new File(ctx.getFilesDir(), name); } if (file.exists()) { try { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); data = (T) ois.readObject(); ois.close(); } catch (Exception e) { e.printStackTrace(); } } return data; }
public static String getLocalFilePath(Context context, String name) { if (TextUtils.isEmpty(name)) { return context.getFilesDir() + File.separator + "local_resource"; } else { return context.getFilesDir() + File.separator + "local_resource" + File.separator + name; } }
/** * Clear out cached images. * * @param context * @param age The max age of a file. Files older than this age will be removed. */ public static void cleanup(final Context context, long age) { if (mHasCleaned) { return; } mHasCleaned = true; try { // purge any *.urlimage files over a week old final String[] files = context.getFilesDir().list(); if (files == null) { return; } for (final String file : files) { if (!file.endsWith(".urlimage")) { continue; } final File f = new File(context.getFilesDir().getAbsolutePath() + '/' + file); if (System.currentTimeMillis() > f.lastModified() + CACHE_DURATION_ONE_WEEK) { f.delete(); } } } catch (final Exception e) { e.printStackTrace(); } }
@Override public void log(JSONObject logData, String fileName) throws SecurityException, IOException { File file = new File(activity.getFilesDir(), FILE_NAME0); File file2 = new File(activity.getFilesDir(), ANALYTICS_FILE_NAME0); try { if (!file.exists() || file.length() == 0 && !logData.getString("level").equals("ANALYTICS")) { // make a non-empty file so send() continues, but it will actually pick up data from this // mock FileOutputStream fos = new FileOutputStream(file); fos.write('a'); fos.close(); } if (!file2.exists() || file2.length() == 0 && logData.getString("level").equals("ANALYTICS")) { // make a non-empty file so sendAnalytics() continues, but it will actually pick up data // from this mock FileOutputStream fos = new FileOutputStream(file2); fos.write('a'); fos.close(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } jsonObjects.put(logData); }
/** * Creates a new Backup * * @param useExternalStorage use external storage path instead of internal? * @param name name of backup * @param force overwrite existing folders? * @throws CreateBackupException * @throws BackupAlreadyExistsException */ public void createBackup(boolean useExternalStorage, @NonNull String name, boolean force) throws CreateBackupException, BackupAlreadyExistsException { if (useExternalStorage) { // TODO: kp wie man internen und externen speicher unterscheidet } else { File src; File dst; dst = new File(SmartphonePreferencesHandler.getBackupPath() + File.separator + name); if (!dst.exists()) { dst.mkdirs(); } else { if (force) { // remove existing backup try { if (!deleteRecursive(dst)) { throw new CreateBackupException("Error deleting existing Backup"); } } catch (Exception e) { Log.e(e); throw new CreateBackupException(e); } dst.mkdirs(); } else { throw new BackupAlreadyExistsException(); } } try { // copy database src = new File(context.getFilesDir().getParent() + File.separator + "databases"); dst = new File( SmartphonePreferencesHandler.getBackupPath() + File.separator + name + File.separator + "databases"); if (src.exists()) { copyDirectory(src, dst); } // copy preferences src = new File(context.getFilesDir().getParent() + File.separator + "shared_prefs"); dst = new File( SmartphonePreferencesHandler.getBackupPath() + File.separator + name + File.separator + "shared_prefs"); if (src.exists()) { copyDirectory(src, dst); } } catch (Exception e) { Log.e(e); throw new CreateBackupException(e); } } }
private boolean migrateFrom_v1_0_262(Context context) { // these directories were used by the object store // if any of these exist, we migrate from an existing wallet. File objectStoreMain = new File(context.getFilesDir(), "mainnet_wallet_" + "_uuid_object_storage"); File objectStoreTest = new File(context.getFilesDir(), "testnet_wallet_" + "_uuid_object_storage"); return objectStoreMain.exists() || objectStoreTest.exists(); }
@Override public Transmissible execute(Context context) { try { Thread.sleep(5000); // Le temps de se scynchroniser. // Verification des security codes dis = new DataInputStream( new BufferedInputStream( new FileInputStream(new File(context.getFilesDir(), "monSC.txt")))); int sC = dis.readInt(); dis.close(); if (sC != monSC) return new Transmission(ErreurTransmission.SCINCORRECT); dis = new DataInputStream( new BufferedInputStream( new FileInputStream(new File(context.getFilesDir(), "tonSC.txt")))); sC = dis.readInt(); if (sC != tonSC) return new Transmission(ErreurTransmission.SCINCORRECT); // On met ce client dans la liste d'attente oos = new ObjectOutputStream( new BufferedOutputStream( new FileOutputStream(new File(context.getFilesDir(), "enCours.txt")))); oos.writeObject(adresse); oos.flush(); // On envoie alors sa fiche bumpfriend perso Log.i("Connexion", context.getFilesDir().toString()); ois = new ObjectInputStream( new FileInputStream(new File(context.getFilesDir(), "fichePerso.txt"))); return (BumpFriend) ois.readObject(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } finally { try { dis.close(); oos.close(); ois.close(); } catch (IOException e) { e.printStackTrace(); } } return new Transmission(ErreurTransmission.PROBLEMETRAITEMENT); }
public Installer(Context mContext, Shell mShell, Runnable reloadUI, File APK) { this.mContext = mContext; this.reloadUI = reloadUI; this.mShell = mShell; mNotifyer = new Notifyer(mContext); downloaded_apk = APK; chromesyncapk = new File(mContext.getFilesDir(), "ChromeBookmarksSyncAdapter.apk"); busybox = new File(mContext.getFilesDir(), "busybox"); }
public FlashUtil(Shell mShell, Context mContext, Device mDevice, File CustomIMG, int JOB) { this.mShell = mShell; this.mContext = mContext; this.mDevice = mDevice; this.JOB = JOB; this.CustomIMG = CustomIMG; mToolbox = new Toolbox(mShell); busybox = new File(mContext.getFilesDir(), "busybox"); flash_image = mDevice.getFlash_image(); dump_image = mDevice.getDump_image(); tmpFile = new File(mContext.getFilesDir(), CustomIMG.getName()); }
private void setupJRuby(Activity startActivity) { System.setProperty("jruby.bytecode.version", "1.5"); // enable proxy classes System.setProperty( "jruby.ji.proxyClassFactory", "com.rickbutton.rubydroid.DalvikProxyClassFactory"); System.setProperty("jruby.ji.upper.case.package.name.allowed", "true"); System.setProperty("jruby.class.cache.path", appContext.getDir("dex", 0).getAbsolutePath()); // setup jruby home String apkName = getApkName(); String jrubyHome = "file:" + apkName + "!/jruby.home"; System.setProperty("jruby.home", jrubyHome); // configure jruby System.setProperty("jruby.compile.mode", "OFF"); // OFF OFFIR JITIR? FORCE FORCEIR // System.setProperty("jruby.compile.backend", "DALVIK"); System.setProperty("jruby.bytecode.version", "1.6"); System.setProperty("jruby.interfaces.useProxy", "true"); System.setProperty("jruby.management.enabled", "false"); System.setProperty("jruby.objectspace.enabled", "false"); System.setProperty("jruby.thread.pooling", "true"); System.setProperty("jruby.native.enabled", "false"); System.setProperty("jruby.ir.passes", "LocalOptimizationPass,DeadCodeElimination"); System.setProperty("jruby.backtrace.style", "normal"); // normal raw full mri ClassLoader loader = new PathClassLoader(apkName, RubySystem.class.getClassLoader()); // disable gems RubyInstanceConfig config = new RubyInstanceConfig(); config.setDisableGems(true); config.setLoader(loader); Ruby.newInstance(config); container = new ScriptingContainer(LocalContextScope.SINGLETON, LocalVariableBehavior.PERSISTENT); container.setClassLoader(loader); Thread.currentThread().setContextClassLoader(loader); if (appContext.getFilesDir() != null) { container.setCurrentDirectory(appContext.getFilesDir().getPath()); } container.put("$package_name", appContext.getPackageName()); container.put("app_context", appContext); container.put("system", this); rubyContext = container.runScriptlet(PathType.CLASSPATH, "ruby/droid/init.rb"); Object mainActivity = container.get("MainActivity"); container.callMethod(rubyContext, "start_ruby_activity", mainActivity, startActivity); }
public static String getDownloadedFilePath(Context context, DownloadInfo info) { if (WallpaperUtils.isWallpaper(info)) { return WallpaperUtils.getWallPaperPath(info.product_id); } String id = null == info ? null : info.product_id; if (TextUtils.isEmpty(id)) { return context.getFilesDir() + File.separator + "downloaded_resource"; } else { return context.getFilesDir() + File.separator + "downloaded_resource" + File.separator + id; } }
public void DD() throws FailedExecuteCommand, IOException, InterruptedException { String Command = ""; if (isJobFlash() || isJobRestore()) { if (mDevice.getName().startsWith("g2") && Build.MANUFACTURER.equals("lge") && isJobFlash()) { File aboot = new File("/dev/block/platform/msm_sdcc.1/by-name/aboot"); File extracted_aboot = new File(mContext.getFilesDir(), "aboot.img"); File patched_CustomIMG = new File(mContext.getFilesDir(), CustomIMG.getName() + ".lok"); File loki_patch = new File(mContext.getFilesDir(), "loki_patch"); File loki_flash = new File(mContext.getFilesDir(), "loki_flash"); mShell.execCommand( "dd if=" + aboot.getAbsolutePath() + " of=" + extracted_aboot.getAbsolutePath(), true); mShell.execCommand( loki_patch.getAbsolutePath() + " recovery " + CustomIMG.getAbsolutePath() + " " + patched_CustomIMG.getAbsolutePath() + " || exit 1", true); Command = loki_flash.getAbsolutePath() + " recovery " + patched_CustomIMG.getAbsolutePath() + " || exit 1"; } else { Log.i(TAG, "Flash started!"); Common.copyFile(CustomIMG, tmpFile); Command = busybox.getAbsolutePath() + " dd if=\"" + tmpFile.getAbsolutePath() + "\" " + "of=\"" + CurrentPartition.getAbsolutePath() + "\""; } } else if (isJobBackup()) { Log.i(TAG, "Backup started!"); Command = busybox.getAbsolutePath() + " dd if=\"" + CurrentPartition.getAbsolutePath() + "\" " + "of=\"" + tmpFile.getAbsolutePath() + "\""; } mShell.execCommand(Command, true); if (isJobBackup()) placeImgBack(); }
private List<Article> loadNewsFromFile(Context context) { startedLoadingNews = true; List<Article> articles = new ArrayList<>(); if (newsFile == null) newsFile = new File(context.getFilesDir(), NEWS_FILE_NAME); if (newsFile.exists()) { try { BufferedReader reader = new BufferedReader(new FileReader(newsFile)); String currentLine = reader.readLine(); if (currentLine != null) { String[] split = currentLine.split("-"); if (split.length > 1) { for (int i = 0; i < Integer.parseInt(split[1]); i++) { // TODO figure out why all lines, after i = 18, are null. currentLine = reader.readLine(); Article a = readArticle(reader); articles.add(a); Log.d("q32", "" + i + "line: " + currentLine); } } else { updateNews(context); } // if we didn't find the number of articles, the file must be corrupt. Update the file. } else updateNews(context); } catch (IOException e) { Log.d("Unit5Calendar", e.getMessage(), e); } Collections.sort(newsArticles, Utils.articlePubDateSorter); newsReady = true; } return articles; }
public static SQLiteDatabase OpenDataBase(Context mContext, String dbName, String assertDBName) { File dataFolder = mContext.getFilesDir(); File dbFile = new File(dataFolder.getAbsolutePath() + "/" + dbName); Log.v("DataCenter", dbFile.getAbsolutePath()); if (!dbFile.exists()) { try { InputStream inputStream = mContext.getAssets().open(assertDBName); FileOutputStream fso = new FileOutputStream(dbFile); byte[] buffer = new byte[1024]; int readCount = 0; while ((readCount = inputStream.read(buffer)) > 0) { fso.write(buffer); } inputStream.close(); fso.close(); } catch (IOException e) { // TODO: handle exception e.printStackTrace(); } } SQLiteDatabase db = SQLiteDatabase.openDatabase( dbFile.getAbsolutePath(), null, SQLiteDatabase.CREATE_IF_NECESSARY); return db; }
public static void LoadApplication(Context context, String runtimeDataDir, String[] apks) { synchronized (lock) { if (!initialized) { System.loadLibrary("monodroid"); Locale locale = Locale.getDefault(); String language = locale.getLanguage() + "-" + locale.getCountry(); String filesDir = context.getFilesDir().getAbsolutePath(); String cacheDir = context.getCacheDir().getAbsolutePath(); String dataDir = context.getApplicationInfo().dataDir + "/lib"; ClassLoader loader = context.getClassLoader(); Runtime.init( language, apks, runtimeDataDir, new String[] { filesDir, cacheDir, dataDir, }, loader, new java.io.File( android.os.Environment.getExternalStorageDirectory(), "Android/data/" + context.getPackageName() + "/files/.__override__") .getAbsolutePath(), MonoPackageManager_Resources.Assemblies); initialized = true; } } }
/** * Constructor Takes and keeps a reference of the passed context in order to access to the * application assets and resources. * * @param context */ public DBHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; DB_PATH = myContext.getFilesDir().getParent() + "/databases/"; myPath = DB_PATH + DB_NAME; }
private void writeToInternalStorage(GeotriggerConfig config) { Log.v(Config.TAG, "writeToInternalStorage"); try { // String endOfLine = System.getProperty("line.separator"); File file = new File(mContext.getFilesDir(), CONFIG_FILE); if (file.exists()) { file.delete(); } file.createNewFile(); // MODE_PRIVATE will create the file (or replace a file of the same name) and make it // private to your application. Other modes available are: MODE_APPEND, MODE_WORLD_READABLE, // and MODE_WORLD_WRITEABLE. FileOutputStream fos = new FileOutputStream(file, false); fos.write(config.toString().getBytes()); Log.v(Config.TAG, "writeFileToInternalStorage complete.. " + config.toString()); // writer.write(userName); fos.close(); } catch (Exception e) { Log.v(Config.TAG, "Error: " + e.getMessage()); } }
public void saveTicket() { Log.d("GenTicket", "saveTicket...ok(1)"); FileOutputStream outputStream; File file = new File(context.getFilesDir(), filename); Log.d("saveTicket", "path:" + file.getAbsolutePath()); String newuser = currentUser + "\n"; try { outputStream = context.openFileOutput(filename, Context.MODE_PRIVATE); outputStream.write(newuser.getBytes()); Log.d("saving", "user:"******"saving", "ticket:" + currentTicket); outputStream.write(currentTicket.getBytes()); outputStream.close(); } catch (Exception e) { Toast toast = Toast.makeText( context, "Ocurrio el siguiente error al escribir un archivo:" + e.getMessage(), Toast.LENGTH_LONG); toast.show(); } Log.d("GenTicket", "saveTicket...ok(2)"); }
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()) if (!fdroidDir.mkdir()) Log.e(TAG, "Unable to create empty base: " + fdroidDir); if (!repoDir.exists()) if (!repoDir.mkdir()) Log.e(TAG, "Unable to create empty repo: " + repoDir); if (!iconsDir.exists()) if (!iconsDir.mkdir()) Log.e(TAG, "Unable to create icons folder: " + iconsDir); }
private static String initGeckoEnvironment() { final Context context = GeckoAppShell.getApplicationContext(); GeckoLoader.loadMozGlue(context); setState(State.MOZGLUE_READY); final Locale locale = Locale.getDefault(); final Resources res = context.getResources(); if (locale.toString().equalsIgnoreCase("zh_hk")) { final Locale mappedLocale = Locale.TRADITIONAL_CHINESE; Locale.setDefault(mappedLocale); Configuration config = res.getConfiguration(); config.locale = mappedLocale; res.updateConfiguration(config, null); } String[] pluginDirs = null; try { pluginDirs = GeckoAppShell.getPluginDirectories(); } catch (Exception e) { Log.w(LOGTAG, "Caught exception getting plugin dirs.", e); } final String resourcePath = context.getPackageResourcePath(); GeckoLoader.setupGeckoEnvironment(context, pluginDirs, context.getFilesDir().getPath()); GeckoLoader.loadSQLiteLibs(context, resourcePath); GeckoLoader.loadNSSLibs(context, resourcePath); GeckoLoader.loadGeckoLibs(context, resourcePath); setState(State.LIBS_READY); return resourcePath; }
/** * 获得应用的根目录 <br> * <li>如果DEBUG==true,返回的是ExternalStorage路径方便调试 /storage/emulated/0/Android/data/<App Name>/files * <li>如果DEBUG==false,返回的时InternalStorage /data/data/<App Name>/files * * @param context * @return */ @SuppressWarnings("unused") public static String getRootPath(Context context) { if (StorageUtils.isExternalStorageWritable() && DEBUG) { return context.getExternalFilesDir(null).getAbsolutePath(); } return context.getFilesDir().getAbsolutePath(); }
String[] getHandles() { try { Context context = this.getApplicationContext(); BufferedReader reader = new BufferedReader(new FileReader(new File(context.getFilesDir(), "handles.txt"))); ArrayList<String> res = new ArrayList<>(); while (true) { String s = reader.readLine(); if (s == null) break; res.add(s); } reader.close(); Toast.makeText( getApplicationContext(), "we have " + res.size() + " handles", Toast.LENGTH_SHORT) .show(); return res.toArray(new String[res.size()]); } catch (IOException e) { e.printStackTrace(); FileWriter out = null; String[] res = new String[] {"enot.1.10", "antonkov", "subscriber", "tourist"}; try { out = new FileWriter(new File(this.getApplicationContext().getFilesDir(), "handles.txt")); for (String h : res) { out.write(h + "\n"); } out.close(); } catch (IOException e1) { e1.printStackTrace(); } Toast.makeText(getApplicationContext(), "fail", Toast.LENGTH_SHORT).show(); return res; } }
@Test public void testFileRecreated() throws Exception { // don't use the mock FileLogger in this test LogPersister.setContext(activity); LogPersister.setLogLevel(LEVEL.DEBUG); File file = new File(activity.getFilesDir(), FILE_NAME0); Logger logger = Logger.getLogger("package"); LogPersister.storeLogs(true); logger.info("a message"); waitForNotify(logger); assertTrue(file.exists()); // If I deleted it instead of letting java.util.logger manage the files, will // java.util.logger recreate it? Let's make sure it does. file.delete(); assertFalse(file.exists()); logger.info("another message"); waitForNotify(logger); assertTrue(file.exists()); }