Skip to content
This repository has been archived by the owner on Jul 23, 2023. It is now read-only.

Commit

Permalink
Fixes for Android 11, improved performance of getPackageName function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzoantonelli committed Feb 15, 2021
1 parent 9cf92ee commit 5689a1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/lorenzoantonelli/tapdebloater/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class Main extends Application {

@Override
public void start(Stage stage) throws IOException {
Scene scene = new Scene(loadFXML("mainFxml"));
Scene scene = new Scene(loadFXML());
stage.setScene(scene);
stage.setResizable(false);
stage.setTitle("TapDebloater");
stage.show();
}

private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource(fxml + ".fxml"));
private static Parent loadFXML() throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Main.class.getResource("mainFxml" + ".fxml"));
return fxmlLoader.load();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public void disableCustomApp(){

@FXML
public void uninstallFacebook(){
boolean status=utils.removeApp("com.facebook.appmanager") |
boolean status=
utils.removeApp("com.facebook.appmanager") |
utils.removeApp("com.facebook.services") |
utils.removeApp("com.facebook.system");
new Alert(Alert.AlertType.NONE,((status)? "Operazione completata con successo!":"Operazione fallita!"), ButtonType.OK).show();
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/org/lorenzoantonelli/tapdebloater/core/AdbUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public class AdbUtils {
/**
* List of apps that shouldn't be removed.
*/
private final List<String> blacklist=Arrays.asList("com.android.settings ", "com.android.vending ");
private final List<String> blacklist=Arrays.asList("com.android.settings", "com.android.vending");

/**
* Android version of the device.
*/
private int androidVersion;

/**
* @see #isWindows
Expand Down Expand Up @@ -96,22 +100,21 @@ public boolean findDevice(){
}

return false;

}

/**
* Returns the package name of the current app running in the device as a string.
* @return the current app's package name, as a string.
*/
public String getPackageName(){
String[] toParse=

String toParse=
runShell(adbPath+" shell dumpsys activity recents | " +
((isWindows)? "findstr":"grep")+" Recent").split("\n");
((isWindows)? "findstr /c:\"Recent #0\"":"grep \"\\<Recent #0\\>\""));

for(String toCheck:toParse){
if(toCheck.contains("Recent #0") && toCheck.contains("A")){
return toCheck.substring(toCheck.indexOf("A")+2,toCheck.indexOf("U"));
}
if(toParse.contains("Recent #0") && (toParse.contains("A="))){
String temp=toParse.substring(toParse.indexOf("A="));
return temp.substring((androidVersion>10?temp.indexOf(":")+1:2),temp.indexOf("U=")-1);
}

return "";
Expand All @@ -128,7 +131,7 @@ public String getAppName(String packageName){
String result = runShell(adbPath + " shell pm list packages -f | " + ((isWindows) ? "findstr " : "grep ") + packageName);

if (!result.equals("-1")) {
String path = result.substring(result.indexOf("package:") + 8, result.indexOf("apk") + 3);
String path = result.substring(result.indexOf("package:") + 8, result.indexOf(".apk") + 4);
String name = runShell(adbPath + " shell /data/local/tmp/aapt-arm-pie d badging " + path + " | " + ((isWindows) ? "findstr" : "grep") + " application-label").split("\n")[0];
return name.substring(name.indexOf(":'") + 2, name.length() - 1);
}
Expand Down Expand Up @@ -163,11 +166,13 @@ public boolean disableApp(String packageName){
/**
* Copy aapt-arm-pie (taken from https://github.com/Calsign/APDE/blob/master/APDE/src/main/assets/aapt-binaries/aapt-arm-pie)
* in /data/local/tmp with 0755 permissions.
* Updates the device Android version.
*/
public void installTool(){
runShell(adbPath+" push aapt-arm-pie /data/local/tmp");
if(!runShell(adbPath+" shell chmod 0755 /data/local/tmp/aapt-arm-pie").equals("-1")){
hasTool=true;
androidVersion=Integer.parseInt(runShell("adb shell getprop ro.build.version.release").replace("\n",""));
}
}

Expand Down

0 comments on commit 5689a1b

Please sign in to comment.