blob: 10283b08254aa8287aa6a3759ac5bddcd5a6c850 [file] [log] [blame]
package com.fairphone.updater.tools;
import android.util.Log;
import java.io.File;
import java.io.IOException;
public final class PrivilegeChecker {
private static final String TAG = PrivilegeChecker.class.getSimpleName();
private static final boolean isPrivilegedApp;
static {
// If we have permissions to write instructions to the recovery, we are a privileged app.
File f = new File("/cache/test.txt");
boolean success = false;
try {
success = f.createNewFile() && f.delete();
} catch (IOException ignored) {
success = false;
} finally {
isPrivilegedApp = success;
}
Log.i(TAG, "App is " + (isPrivilegedApp ? "" : "not") + " privileged.");
}
public static boolean isPrivilegedApp(){
return isPrivilegedApp;
}
}