Skip to content

Commit

Permalink
Performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-TSNG committed Apr 15, 2021
1 parent ba6a0de commit cb543b3
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 128 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "com.tsng.hidemyapplist"
minSdkVersion 24
targetSdkVersion 30
versionCode 10
versionName "1.3.1"
versionCode 11
versionName "1.3.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/tsng/hidemyapplist/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@ class MainActivity : AppCompatActivity(), View.OnClickListener {

private fun isModuleActivated(): Boolean { return false }
private fun isHookSelf(): Boolean { return getSharedPreferences("Settings", MODE_WORLD_READABLE).getBoolean("HookSelf", false) }
private fun isServiceWorking(): Boolean {
private fun getServiceVersion(): Int {
return try {
packageManager.getPackageUid("checkHMAServiceStatus", 0)
true
} catch (e : PackageManager.NameNotFoundException) { false }
packageManager.getPackageUid("checkHMAServiceVersion", 0)
} catch (e : PackageManager.NameNotFoundException) { 0 }
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
try {
getSharedPreferences("Settings", MODE_WORLD_READABLE)
val serviceVersion = getServiceVersion()
if (isModuleActivated()) {
if (isServiceWorking()) {
if (serviceVersion != 0) {
xposed_status.setCardBackgroundColor(getColor(R.color.teal))
xposed_status_icon.setImageDrawable(getDrawable(R.drawable.ic_activited))
xposed_status_text.text = getString(R.string.xposed_activated)
xposed_status_sub_text.text = getString(R.string.xposed_service_on)
} else {
xposed_status.setCardBackgroundColor(getColor(R.color.info))
xposed_status_icon.setImageDrawable(getDrawable(R.drawable.ic_activited))
xposed_status_text.text = getString(R.string.xposed_activated)
xposed_status_sub_text.text = getString(R.string.xposed_service_off)
}
} else {
xposed_status.setCardBackgroundColor(getColor(R.color.gray))
xposed_status_icon.setImageDrawable(getDrawable(R.drawable.ic_not_activated))
xposed_status_text.text = getString(R.string.xposed_not_activated)
xposed_status_sub_text.text = getString(if(isServiceWorking())R.string.xposed_service_on else R.string.xposed_service_off)
}
if (serviceVersion != 0)
xposed_status_sub_text.text = getString(R.string.xposed_service_on) + "$serviceVersion]"
else xposed_status_sub_text.text = getString(R.string.xposed_service_off)
} catch (e : SecurityException) {
permissionError = true
xposed_status.setCardBackgroundColor(getColor(R.color.error))
Expand Down
24 changes: 11 additions & 13 deletions app/src/main/java/com/tsng/hidemyapplist/ui/DetectionActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.pm.ResolveInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Process;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
Expand All @@ -31,7 +30,6 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -115,7 +113,7 @@ private class DetectionTask extends AsyncTask<Void, Void, Void> {
}};

final Map<String, Integer> M2 = new LinkedHashMap<String, Integer>() {{
put("getPackagesForUid", 0);
put("getPackageUid", 0);
}};

final Map<String, Integer> M3 = new LinkedHashMap<String, Integer>() {{
Expand Down Expand Up @@ -154,7 +152,7 @@ protected Void doInBackground(Void... voids) {
method_intent();
publishProgress();

method_getPackagesForUid();
method_getPackageUid();
publishProgress();

method_file();
Expand Down Expand Up @@ -248,18 +246,18 @@ private void method_intent() {
methodStatus[1][M1.get("queryIntentActivities")] = findPackages(packages);
}

private void method_getPackagesForUid() {
Set<String> packages = new HashSet<>();
for (int i = Process.SYSTEM_UID; i <= Process.LAST_APPLICATION_UID; i++) {
String[] uid = getPackageManager().getPackagesForUid(i);
if (uid != null)
Collections.addAll(packages, uid);
}
if (packages.isEmpty()) packages = null;
methodStatus[2][M2.get("getPackagesForUid")] = findPackages(packages);
private void method_getPackageUid() {
for (String pkg : targets)
try {
getPackageManager().getPackageUid(pkg, 0);
methodStatus[2][M2.get("getPackageUid")] = 1;
return;
} catch (PackageManager.NameNotFoundException ignored) { }
methodStatus[2][M2.get("getPackageUid")] = 0;
}

private native boolean isFileExists(String path);

private void method_file() {
methodStatus[3][M3.get("javaFile")] = 0;
methodStatus[3][M3.get("nativeFile")] = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.tsng.hidemyapplist.ui

import android.content.pm.ApplicationInfo
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.ListPreference
import androidx.preference.PreferenceFragmentCompat
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.tsng.hidemyapplist.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.ListPreference
import androidx.preference.PreferenceFragmentCompat
import com.tsng.hidemyapplist.R
Expand Down Expand Up @@ -33,7 +33,7 @@ class SettingsActivity : AppCompatActivity() {
summary = entry
setOnPreferenceChangeListener { _, newValue ->
summary = newValue as CharSequence?
if(value != newValue)
if (value != newValue)
Toast.makeText(activity, R.string.settings_need_reboot, Toast.LENGTH_SHORT).show()
true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.tsng.hidemyapplist.ui

import android.content.pm.ApplicationInfo
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.CheckBoxPreference
import androidx.preference.Preference
Expand Down
37 changes: 11 additions & 26 deletions app/src/main/java/com/tsng/hidemyapplist/xposed/XposedUtils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.tsng.hidemyapplist.xposed

import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import com.tsng.hidemyapplist.BuildConfig
import de.robv.android.xposed.XSharedPreferences
Expand All @@ -11,6 +13,13 @@ class XposedUtils {
const val LOG = "hma_log"
const val APPNAME = BuildConfig.APPLICATION_ID

@JvmStatic
fun callServiceUpdatePref(context: Context) {
try {
context.packageManager.getPackageUid("updatePreference", 0)
} catch (e: PackageManager.NameNotFoundException) { }
}

@JvmStatic
fun getTemplatePref(pkg: String?): XSharedPreferences? {
val pref = XSharedPreferences(APPNAME, "Scope")
Expand All @@ -20,32 +29,8 @@ class XposedUtils {
}

@JvmStatic
fun isUseHook(pref: XSharedPreferences?, callerName: String?, hook: String): Boolean {
if (pref == null) return false
if (callerName == APPNAME)
if (!XSharedPreferences(APPNAME, "Settings").getBoolean("HookSelf", false))
return false
val enableAllHooks = pref.getBoolean("EnableAllHooks", false)
val enabled = pref.getStringSet("ApplyHooks", HashSet())
return enableAllHooks or enabled.contains(hook)
}

@JvmStatic
fun isToHide(pref: XSharedPreferences?, callerName: String, pkgstr: String?): Boolean {
if (pref == null || pkgstr == null) return false
if (pref.getBoolean("ExcludeSelf", false) && pkgstr.contains(callerName)) return false
if (pref.getBoolean("HideAllApps", false)) return true
val set = pref.getStringSet("HideApps", HashSet())
for (pkg in set) if (pkgstr.contains(pkg)) {
ld("HIDE $pkgstr")
return true
}
return false
}

@JvmStatic
fun getRecursiveField(entry: Any, list: List<String>) : Any? {
var field : Any? = entry
fun getRecursiveField(entry: Any, list: List<String>): Any? {
var field: Any? = entry
for (it in list)
field = XposedHelpers.getObjectField(field, it) ?: return null
return field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import de.robv.android.xposed.XSharedPreferences
import de.robv.android.xposed.XposedHelpers
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam
import java.io.*
import java.nio.charset.StandardCharsets

class IndividualHooks : IXposedHookLoadPackage {
override fun handleLoadPackage(lpp: LoadPackageParam) {
Expand Down
Loading

0 comments on commit cb543b3

Please sign in to comment.