diff --git a/app/src/main/java/com/performancetweaker/app/ui/MainActivity.java b/app/src/main/java/com/performancetweaker/app/ui/MainActivity.java index 404237b..09c0d25 100755 --- a/app/src/main/java/com/performancetweaker/app/ui/MainActivity.java +++ b/app/src/main/java/com/performancetweaker/app/ui/MainActivity.java @@ -20,6 +20,7 @@ import android.widget.TextView; import android.support.v7.app.AppCompatActivity; +import com.asksven.android.common.utils.SystemAppInstaller; import com.performancetweaker.app.BuildConfig; import com.performancetweaker.app.R; import com.performancetweaker.app.ui.fragments.BuildPropEditorFragment; diff --git a/app/src/main/java/com/performancetweaker/app/ui/fragments/SettingsFragment.java b/app/src/main/java/com/performancetweaker/app/ui/fragments/SettingsFragment.java index eff43a7..14c32da 100755 --- a/app/src/main/java/com/performancetweaker/app/ui/fragments/SettingsFragment.java +++ b/app/src/main/java/com/performancetweaker/app/ui/fragments/SettingsFragment.java @@ -2,19 +2,25 @@ import android.os.Bundle; import android.preference.MultiSelectListPreference; +import android.preference.Preference; +import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import com.performancetweaker.app.R; +import com.performancetweaker.app.utils.Constants; import com.performancetweaker.app.utils.GpuUtils; +import com.performancetweaker.app.utils.SystemAppUtilities; import java.util.ArrayList; public class SettingsFragment extends PreferenceFragment { MultiSelectListPreference mMultiSelectListPreference; + Preference uninstallSystemAppButton; GpuUtils gpuUtils; @Override @@ -30,7 +36,25 @@ public void onCreate(Bundle paramBundle) { gpuUtils = GpuUtils.getInstance(); + final PreferenceCategory preferenceCategory = (PreferenceCategory) findPreference("settings_category"); mMultiSelectListPreference = (MultiSelectListPreference) findPreference("select_apply_on_boot"); + uninstallSystemAppButton = findPreference("uninstall_system_app"); + uninstallSystemAppButton.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference preference) { + Boolean status = SystemAppUtilities.uninstallAsSystemApp(Constants.APK_NAME); + if(status) { + if(!SystemAppUtilities.isSystemApp(Constants.APK_NAME)) { + preferenceCategory.removePreference(uninstallSystemAppButton); + } + Toast.makeText(getActivity(),"Successfully uninstalled app from system\n Please reboot for changes to take place",Toast.LENGTH_LONG); + }else { + Toast.makeText(getActivity(),"Unknown error occurred while uninstalling app",Toast.LENGTH_SHORT); + } + return true; + } + }); + ArrayList entries = new ArrayList<>(); entries.add(getString(R.string.cpu_frequency)); if (gpuUtils.isGpuFrequencyScalingSupported()) { @@ -46,6 +70,9 @@ public void onCreate(Bundle paramBundle) { } mMultiSelectListPreference.setEntries(charSequences); mMultiSelectListPreference.setEntryValues(charSequences); - } + if(!SystemAppUtilities.isSystemApp(Constants.APK_NAME)) { + preferenceCategory.removePreference(uninstallSystemAppButton); + } + } } diff --git a/app/src/main/java/com/performancetweaker/app/ui/fragments/WakeLocksFragment.java b/app/src/main/java/com/performancetweaker/app/ui/fragments/WakeLocksFragment.java index 7efffcf..ee33b07 100755 --- a/app/src/main/java/com/performancetweaker/app/ui/fragments/WakeLocksFragment.java +++ b/app/src/main/java/com/performancetweaker/app/ui/fragments/WakeLocksFragment.java @@ -108,11 +108,7 @@ public void onItemSelected(AdapterView parent, View view, int position, long .setNeutralButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - try { - SystemAppUtilities.installAsSystemApp(getActivity()); - } catch (SystemAppManagementException e) { - e.printStackTrace(); - } + SystemAppUtilities.installAsSystemApp(getActivity()); } }).setNegativeButton("No", null).show(); } else { diff --git a/app/src/main/java/com/performancetweaker/app/utils/Constants.java b/app/src/main/java/com/performancetweaker/app/utils/Constants.java index e58f290..99c7bc8 100755 --- a/app/src/main/java/com/performancetweaker/app/utils/Constants.java +++ b/app/src/main/java/com/performancetweaker/app/utils/Constants.java @@ -75,4 +75,6 @@ public interface Constants { // CPU Hotplug String HOTPLUG_MPDEC = "mpdecision"; + + String APK_NAME = "performancetweaker.apk"; } diff --git a/app/src/main/java/com/performancetweaker/app/utils/SystemAppUtilities.java b/app/src/main/java/com/performancetweaker/app/utils/SystemAppUtilities.java index 11fbabf..b5be49a 100755 --- a/app/src/main/java/com/performancetweaker/app/utils/SystemAppUtilities.java +++ b/app/src/main/java/com/performancetweaker/app/utils/SystemAppUtilities.java @@ -1,5 +1,6 @@ package com.performancetweaker.app.utils; +import com.asksven.android.common.RootShell; import com.asksven.android.common.utils.SystemAppInstaller; import com.stericson.RootTools.RootTools; @@ -13,14 +14,15 @@ import android.util.Log; import java.util.ArrayList; +import java.util.List; public class SystemAppUtilities { private static final String SYSTEM_DIR_4_4 = "/system/priv-app/"; private static final String SYSTEM_DIR = "/system/app/"; - private static String getAPKName(Context ctx, boolean includeFullPath, boolean doWildCard) - throws com.performancetweaker.app.utils.SystemAppManagementException { + public static String getAPKName(Context ctx, boolean includeFullPath, boolean doWildCard) + throws SystemAppManagementException { String fullPath = ctx.getApplicationInfo().sourceDir; if (fullPath.isEmpty() || (fullPath.lastIndexOf('/') == -1)) { throw new com.performancetweaker.app.utils.SystemAppManagementException( @@ -39,7 +41,7 @@ private static String getAPKName(Context ctx, boolean includeFullPath, boolean d return fullPath; } - public static void installAsSystemApp(final Context ctx) throws SystemAppManagementException { + public static void installAsSystemApp(final Context ctx) { AsyncTask task = new AsyncTask() { SystemAppManagementException error = null; ProgressDialog progress = null; @@ -162,4 +164,42 @@ private static boolean installAsSystemApp(String apk) { return SysUtils.executeRootCommand(command); } + + public static boolean uninstallAsSystemApp(String apk) { + ArrayList command = new ArrayList<>(); + command.add("mount -o rw,remount /system"); + + if (Build.VERSION.SDK_INT >= 19) { + command.add("rm"+" "+SYSTEM_DIR_4_4 + "performancetweaker.apk"); + } else { + command.add("rm"+" "+ SYSTEM_DIR + "performancetweaker.apk"); + } + + return SysUtils.executeRootCommand(command); + } + + public static boolean isSystemApp(String apk) + { + boolean ret = false; + List res; + + String command = ""; + if (Build.VERSION.SDK_INT >= 19) + { + command = "ls " + SYSTEM_DIR_4_4 + "/" + apk; + } + else + { + command = "ls " + SYSTEM_DIR + "/" + apk; + } + + res = RootShell.getInstance().run(command); + + if (res.size() > 0) + { + ret = !res.get(0).contains("No such file or directory"); + } + + return ret; + } } diff --git a/app/src/main/res/xml/settings_preferences.xml b/app/src/main/res/xml/settings_preferences.xml index 47e44b0..80cdf2b 100755 --- a/app/src/main/res/xml/settings_preferences.xml +++ b/app/src/main/res/xml/settings_preferences.xml @@ -1,7 +1,8 @@ - + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index e722a4c..6285368 100755 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { // mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' + classpath 'com.android.tools.build:gradle:3.6.1' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ea9dce7..5777843 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sun Apr 28 21:32:54 IST 2019 +#Sun Mar 22 11:50:38 IST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip