- Use RootTools to check cache file existence simple normal file commands don't work
- Fix copy to cache verification
diff --git a/src/com/fairphone/updater/fragments/DownloadAndRestartFragment.java b/src/com/fairphone/updater/fragments/DownloadAndRestartFragment.java
index d8c0fba..75ce6ca 100644
--- a/src/com/fairphone/updater/fragments/DownloadAndRestartFragment.java
+++ b/src/com/fairphone/updater/fragments/DownloadAndRestartFragment.java
@@ -573,8 +573,10 @@
DownloadableItem item = mIsVersion ? mSelectedVersion : mSelectedStore;
String otaPackagePath = Utils.getOtaPackagePath(resources, item, mIsVersion);
- File f = new File(otaPackagePath);
- if (!f.exists())
+
+ boolean fileNotExists = !Utils.fileExists(otaPackagePath);
+
+ if (fileNotExists)
{
abortUpdateProcess();
}
@@ -749,13 +751,13 @@
Utils.clearCache();
- File otaFilePath = new File(originalFilePath);
- File otaFileCache = new File(destinyFilePath);
+ File otaOriginalFile = new File(originalFilePath);
+ File otaDestinyFile = new File(destinyFilePath);
- if (!otaFileCache.exists())
+ if (otaOriginalFile.exists())
{
try {
- Utils.copy(otaFilePath, otaFileCache);
+ Utils.copy(otaOriginalFile, otaDestinyFile);
} catch (IOException e) {
Log.e(TAG, "Failed to copy files to cache: "+e.getLocalizedMessage());
abortUpdateProcess();
diff --git a/src/com/fairphone/updater/gappsinstaller/GappsInstallerHelper.java b/src/com/fairphone/updater/gappsinstaller/GappsInstallerHelper.java
index 291de2c..49cba1f 100644
--- a/src/com/fairphone/updater/gappsinstaller/GappsInstallerHelper.java
+++ b/src/com/fairphone/updater/gappsinstaller/GappsInstallerHelper.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.content.SharedPreferences;
+import com.fairphone.updater.tools.Utils;
import com.fairphone.updater.widgets.gapps.GoogleAppsInstallerWidget;
import java.io.File;
@@ -36,9 +37,7 @@
public static boolean areGappsInstalled()
{
- File f = new File("/system/app/OneTimeInitializer.apk");
-
- return f.exists();
+ return Utils.fileExists("/system/app/OneTimeInitializer.apk");
}
public static void checkGappsAreInstalled(Context context)
diff --git a/src/com/fairphone/updater/tools/PrivilegeChecker.java b/src/com/fairphone/updater/tools/PrivilegeChecker.java
index 8ff0d0a..da72977 100644
--- a/src/com/fairphone/updater/tools/PrivilegeChecker.java
+++ b/src/com/fairphone/updater/tools/PrivilegeChecker.java
@@ -26,7 +26,7 @@
isPrivilegedApp = success;
}
}
- Log.d(TAG, "App is " + (isPrivilegedApp ? "" : "not") + " privileged.");
+ Log.i(TAG, "App is " + (isPrivilegedApp ? "" : "not") + " privileged.");
}
public static boolean isPrivilegedApp(){
diff --git a/src/com/fairphone/updater/tools/Utils.java b/src/com/fairphone/updater/tools/Utils.java
index 31e7479..02e53cc 100644
--- a/src/com/fairphone/updater/tools/Utils.java
+++ b/src/com/fairphone/updater/tools/Utils.java
@@ -318,23 +318,32 @@
public static void clearCache()
{
- File f = Environment.getDownloadCacheDirectory();
- File[] files = f.listFiles();
- if (files != null)
- {
- Log.d(TAG, "Size: " + files.length);
- for (File file : files) {
- String filename = file.getName();
+ if(PrivilegeChecker.isPrivilegedApp()) {
+ File f = Environment.getDownloadCacheDirectory();
+ File[] files = f.listFiles();
+ if (files != null) {
+ Log.d(TAG, "Size: " + files.length);
+ for (File file : files) {
+ String filename = file.getName();
- if (filename.endsWith(".zip")) {
- final boolean delete = file.delete();
- if (delete) {
- Log.d(TAG, "Deleted file " + filename);
- } else {
- Log.d(TAG, "Failed to delete file " + filename);
- }
- }
- }
+ if (filename.endsWith(".zip")) {
+ final boolean delete = file.delete();
+ if (delete) {
+ Log.d(TAG, "Deleted file " + filename);
+ } else {
+ Log.d(TAG, "Failed to delete file " + filename);
+ }
+ }
+ }
+ }
+ } else {
+ if(RootTools.isAccessGiven()) {
+ try {
+ Shell.runRootCommand(new CommandCapture(0, "rm -f *.zip"));
+ } catch (IOException | TimeoutException |RootDeniedException e) {
+ Log.w(TAG, "Failed to clear cache: " + e.getLocalizedMessage());
+ }
+ }
}
}
@@ -578,4 +587,15 @@
// Log.wtf(TAG, sb.toString());
// }
// --Commented out by Inspection STOP (06/02/2015 12:25)
+
+ public static boolean fileExists(String otaPackagePath) {
+ boolean fileExists;
+ if(PrivilegeChecker.isPrivilegedApp()){
+ File f = new File(otaPackagePath);
+ fileExists = f.exists();
+ }else {
+ fileExists = RootTools.exists(otaPackagePath);
+ }
+ return fileExists;
+ }
}