Skip to content

Commit

Permalink
add option for uninstalling system app
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkumar66 committed Mar 22, 2020
1 parent 900da71 commit 127849a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<CharSequence> entries = new ArrayList<>();
entries.add(getString(R.string.cpu_frequency));
if (gpuUtils.isGpuFrequencyScalingSupported()) {
Expand All @@ -46,6 +70,9 @@ public void onCreate(Bundle paramBundle) {
}
mMultiSelectListPreference.setEntries(charSequences);
mMultiSelectListPreference.setEntryValues(charSequences);
}

if(!SystemAppUtilities.isSystemApp(Constants.APK_NAME)) {
preferenceCategory.removePreference(uninstallSystemAppButton);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ public interface Constants {

// CPU Hotplug
String HOTPLUG_MPDEC = "mpdecision";

String APK_NAME = "performancetweaker.apk";
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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(
Expand All @@ -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<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
SystemAppManagementException error = null;
ProgressDialog progress = null;
Expand Down Expand Up @@ -162,4 +164,42 @@ private static boolean installAsSystemApp(String apk) {

return SysUtils.executeRootCommand(command);
}

public static boolean uninstallAsSystemApp(String apk) {
ArrayList<String> 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<String> 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;
}
}
8 changes: 7 additions & 1 deletion app/src/main/res/xml/settings_preferences.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<PreferenceCategory android:title="General">
<PreferenceCategory android:title="General"
android:key="settings_category">

<MultiSelectListPreference
android:dialogTitle="Apply On Boot"
android:key="select_apply_on_boot"
android:summary="Select Settings You Want to Apply on Boot"
android:title="Apply on Boot"></MultiSelectListPreference>

<Preference android:title="Uninstall System App"
android:key="uninstall_system_app"
android:summary="Remove this app from system directory"
/>

</PreferenceCategory>
</PreferenceScreen>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 127849a

Please sign in to comment.