-
Notifications
You must be signed in to change notification settings - Fork 393
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 2 features for rooted phones : - Clear cache and - Clear data. …
…MLManagerApplication is created to provide single instace of AppPreferences. Earlier multiple instances were being created which is not required. RootUtils added for checking some root related info. Tested on a few rooted and unrooted phones.
- Loading branch information
Vijay Rawat
committed
Jun 21, 2015
1 parent
af335db
commit e6e176c
Showing
14 changed files
with
260 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/javiersantos/mlmanager/MLManagerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.javiersantos.mlmanager; | ||
|
||
import android.app.Application; | ||
|
||
import com.javiersantos.mlmanager.utils.AppPreferences; | ||
|
||
/** | ||
* Created by vijay.rawat01 on 6/21/15. | ||
*/ | ||
public class MLManagerApplication extends Application { | ||
|
||
private static AppPreferences sAppPreferences; | ||
|
||
@Override | ||
public void onCreate() { | ||
sAppPreferences = new AppPreferences(this); | ||
super.onCreate(); | ||
} | ||
|
||
public static AppPreferences getAppPreferences() { | ||
return sAppPreferences; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/main/java/com/javiersantos/mlmanager/utils/RootUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.javiersantos.mlmanager.utils; | ||
|
||
import android.os.Build; | ||
|
||
import com.javiersantos.mlmanager.MLManagerApplication; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Created by vijay.rawat01 on 6/21/15. | ||
*/ | ||
public class RootUtils { | ||
|
||
private static final int ROOT_STATUS_NOT_CHECKED = 0; | ||
private static final int ROOT_STATUS_ROOTED = 1; | ||
private static final int ROOT_STATUS_NOT_ROOTED = 2; | ||
|
||
private RootUtils() { | ||
} | ||
|
||
public static boolean isRooted() { | ||
int rootStatus = MLManagerApplication.getAppPreferences().getRootStatus(); | ||
boolean isRooted = false; | ||
if (rootStatus == ROOT_STATUS_NOT_CHECKED) { | ||
isRooted = isRootByBuildTag() || isRootedByFileSU() || isRootedByExecutingCommand(); | ||
MLManagerApplication.getAppPreferences().setRootStatus(isRooted ? ROOT_STATUS_ROOTED : ROOT_STATUS_NOT_ROOTED); | ||
} else if (rootStatus == ROOT_STATUS_ROOTED) { | ||
isRooted = true; | ||
} | ||
return isRooted; | ||
} | ||
|
||
public static boolean isRootByBuildTag() { | ||
String buildTags = Build.TAGS; | ||
return ((buildTags != null && buildTags.contains("test-keys"))); | ||
} | ||
|
||
public static boolean isRootedByFileSU() { | ||
try { | ||
File file = new File("/system/app/Superuser.apk"); | ||
if (file.exists()) { | ||
return true; | ||
} | ||
} catch (Exception e1) { | ||
} | ||
return false; | ||
} | ||
|
||
public static boolean isRootedByExecutingCommand() { | ||
return canExecuteCommand("/system/xbin/which su") | ||
|| canExecuteCommand("/system/bin/which su") | ||
|| canExecuteCommand("which su"); | ||
} | ||
|
||
public static boolean removeWithRootPermission(String directory) { | ||
boolean status = false; | ||
try { | ||
String[] command = new String[]{"su", "-c", "rm -rf " + directory}; | ||
Process process = Runtime.getRuntime().exec(command); | ||
process.waitFor(); | ||
int i = process.exitValue(); | ||
if (i == 0) { | ||
status = true; | ||
} | ||
} catch (Exception e) { | ||
} | ||
return status; | ||
} | ||
|
||
private static boolean canExecuteCommand(String command) { | ||
boolean isExecuted; | ||
try { | ||
Runtime.getRuntime().exec(command); | ||
isExecuted = true; | ||
} catch (Exception e) { | ||
isExecuted = false; | ||
} | ||
|
||
return isExecuted; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.