Remove KillerManagerUtils, convert SystemUtils to kotlin
This commit is contained in:
parent
587f58ed30
commit
e5b06d9508
5 changed files with 116 additions and 203 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.thelittlefireman.appkillermanager
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.thelittlefireman.appkillermanager.devices.*
|
||||
|
@ -40,7 +41,7 @@ object AppKillerManager {
|
|||
it.manufacturer.toString()
|
||||
}
|
||||
|
||||
Timber.w("More than one corresponding device: %s. Debug info: %s", logDevices, SystemUtils.getDefaultDebugInformation())
|
||||
Timber.w("More than one corresponding device: %s. Debug info: %s", logDevices, SystemUtils.defaultDebugInformation)
|
||||
}
|
||||
|
||||
return currentDevice.firstOrNull()
|
||||
|
@ -106,6 +107,7 @@ object AppKillerManager {
|
|||
* @param action the wanted actions
|
||||
* @return the intent
|
||||
*/
|
||||
@SuppressLint("BinaryOperationInTimber")
|
||||
private fun getIntentFromAction(context: Context, action: Action): Intent? {
|
||||
val sDevice = getDevice()
|
||||
return if (sDevice != null) {
|
||||
|
@ -118,19 +120,16 @@ object AppKillerManager {
|
|||
// Intent found action succeed
|
||||
intent
|
||||
} else {
|
||||
Timber.e("""
|
||||
INTENT NOT FOUND :${ActionsUtils.getExtrasDebugInformations(intent)}
|
||||
Actions: ${action.name}
|
||||
SYSTEM UTILS: ${SystemUtils.getDefaultDebugInformation()}
|
||||
DEVICE: ${sDevice.getExtraDebugInfo(context)}
|
||||
""".trimIndent()
|
||||
)
|
||||
Timber.e("INTENT NOT FOUND :${ActionsUtils.getExtrasDebugInformations(intent)}\n" +
|
||||
"Actions: ${action.name}\n" +
|
||||
"DEVICE: ${sDevice.getExtraDebugInfo(context)}\n" +
|
||||
"SYSTEM UTILS: ${SystemUtils.defaultDebugInformation}")
|
||||
// Intent not found action failed
|
||||
null
|
||||
}
|
||||
} else {
|
||||
// device not found action failed
|
||||
Timber.w("DEVICE NOT FOUND. %s", SystemUtils.getDefaultDebugInformation())
|
||||
Timber.w("DEVICE NOT FOUND. %s", SystemUtils.defaultDebugInformation)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import android.content.pm.PackageManager
|
|||
import android.os.Build
|
||||
import com.thelittlefireman.appkillermanager.utils.ActionsUtils
|
||||
import com.thelittlefireman.appkillermanager.utils.Manufacturer
|
||||
import com.thelittlefireman.appkillermanager.utils.SystemUtils.getEmuiRomName
|
||||
import com.thelittlefireman.appkillermanager.utils.SystemUtils.emuiRomName
|
||||
import timber.log.Timber
|
||||
|
||||
class Huawei : Device {
|
||||
|
@ -25,13 +25,13 @@ class Huawei : Device {
|
|||
}
|
||||
|
||||
override val isThatRom: Boolean
|
||||
get() = "EmotionUI_2.3".equals(getEmuiRomName(), ignoreCase = true) ||
|
||||
get() = "EmotionUI_2.3".equals(emuiRomName, ignoreCase = true) ||
|
||||
Build.DISPLAY.contains("emui2.3", ignoreCase = true) ||
|
||||
"EMUI 2.3".equals(getEmuiRomName(), ignoreCase = true) ||
|
||||
"EmotionUI_3.0".equals(getEmuiRomName(), ignoreCase = true) ||
|
||||
"EmotionUI_3.0.1".equals(getEmuiRomName(), ignoreCase = true) ||
|
||||
"EmotionUI_3.1".equals(getEmuiRomName(), ignoreCase = true) ||
|
||||
"EmotionUI_4.1".equals(getEmuiRomName(), ignoreCase = true) ||
|
||||
"EMUI 2.3".equals(emuiRomName, ignoreCase = true) ||
|
||||
"EmotionUI_3.0".equals(emuiRomName, ignoreCase = true) ||
|
||||
"EmotionUI_3.0.1".equals(emuiRomName, ignoreCase = true) ||
|
||||
"EmotionUI_3.1".equals(emuiRomName, ignoreCase = true) ||
|
||||
"EmotionUI_4.1".equals(emuiRomName, ignoreCase = true) ||
|
||||
Build.BRAND.equals(manufacturer.toString(), ignoreCase = true) ||
|
||||
Build.MANUFACTURER.equals(manufacturer.toString(), ignoreCase = true) ||
|
||||
Build.FINGERPRINT.contains(manufacturer.toString(), ignoreCase = true)
|
||||
|
@ -77,7 +77,7 @@ class Huawei : Device {
|
|||
|
||||
override fun getExtraDebugInfo(context: Context): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
stringBuilder.append("ROM_VERSION").append(getEmuiRomName())
|
||||
stringBuilder.append("ROM_VERSION").append(emuiRomName)
|
||||
stringBuilder.append("HuaweiSystemManagerVersionMethod:").append(getHuaweiSystemManagerVersion(context))
|
||||
|
||||
var versionStr: String? = ""
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
package com.thelittlefireman.appkillermanager.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.thelittlefireman.appkillermanager.AppKillerManager;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
public class KillerManagerUtils {
|
||||
private static final String DONT_SHOW_AGAIN = "DONT_SHOW_AGAIN";
|
||||
private static final String IS_DONE = "IS_DONE_";
|
||||
|
||||
private static SharedPreferences getSharedPreferences(Context mContext) {
|
||||
return mContext.getSharedPreferences("KillerManager", MODE_PRIVATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set for a specifique actions that we dont need to show the popupAgain
|
||||
*
|
||||
* @param mContext
|
||||
* @param action
|
||||
* @param enable
|
||||
*/
|
||||
public static void setDontShowAgain(Context mContext, AppKillerManager.Action action, boolean enable) {
|
||||
final SharedPreferences.Editor editor = getSharedPreferences(mContext).edit();
|
||||
editor.putBoolean(DONT_SHOW_AGAIN + action.toString(), enable);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
public static void setAllDontShowAgain(Context mContext, boolean enable) {
|
||||
final SharedPreferences.Editor editor = getSharedPreferences(mContext).edit();
|
||||
for (AppKillerManager.Action action : AppKillerManager.Action.values()) {
|
||||
editor.putBoolean(DONT_SHOW_AGAIN + action.toString(), enable);
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean isDontShowAgain(Context mContext, AppKillerManager.Action action) {
|
||||
return getSharedPreferences(mContext).getBoolean(DONT_SHOW_AGAIN + action.toString(), false);
|
||||
}
|
||||
|
||||
public static boolean isAllDontShowAgain(Context context) {
|
||||
for (AppKillerManager.Action action : AppKillerManager.Action.values()) {
|
||||
if (!isDontShowAgain(context, action)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isAnyDontShowAgain(Context context) {
|
||||
for (AppKillerManager.Action action : AppKillerManager.Action.values()) {
|
||||
if (isDontShowAgain(context, action)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void updateIsActionDone(Context context, AppKillerManager.Action action, boolean b) {
|
||||
final SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean(IS_DONE + action.toString(), b);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
||||
public static boolean isActionDone(Context context, AppKillerManager.Action action) {
|
||||
final SharedPreferences prfs = getSharedPreferences(context);
|
||||
return prfs.getBoolean(IS_DONE + action.toString(), false);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
package com.thelittlefireman.appkillermanager.utils;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Process;
|
||||
import android.os.UserManager;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class SystemUtils {
|
||||
|
||||
public static String getDefaultDebugInformation() {
|
||||
return "Display_id:" + Build.DISPLAY +
|
||||
"MODEL:" + Build.MODEL +
|
||||
"MANUFACTURER:" + Build.MANUFACTURER +
|
||||
"PRODUCT:" + Build.PRODUCT;
|
||||
}
|
||||
|
||||
public static String getEmuiRomName() {
|
||||
try {
|
||||
return SystemUtils.getSystemProperty("ro.build.version.emui");
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getApplicationName(Context context) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
ApplicationInfo applicationInfo = null;
|
||||
try {
|
||||
applicationInfo = packageManager.getApplicationInfo(context.getApplicationInfo().packageName, 0);
|
||||
} catch (final PackageManager.NameNotFoundException e) {
|
||||
}
|
||||
return (String) (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "Unknown");
|
||||
}
|
||||
|
||||
public static String getMiuiRomName() {
|
||||
try {
|
||||
return SystemUtils.getSystemProperty("ro.miui.ui.version.name");
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static String getSystemProperty(String propName) {
|
||||
String line;
|
||||
BufferedReader input = null;
|
||||
try {
|
||||
java.lang.Process p = Runtime.getRuntime().exec("getprop " + propName);
|
||||
input = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
|
||||
line = input.readLine();
|
||||
input.close();
|
||||
} catch (IOException ex) {
|
||||
Timber.e(ex, "Unable to read system property %s", propName);
|
||||
return null;
|
||||
} finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
Timber.e(e, "Exception while closing InputStream");
|
||||
}
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
// INFO http://imsardine.simplbug.com/note/android/adb/commands/am-start.html
|
||||
|
||||
/**
|
||||
* Open an Activity by using Application Manager System (prevent from crash permission exception)
|
||||
*
|
||||
* @param context current application Context
|
||||
* @param packageName pacakge name of the target application (exemple: com.huawei.systemmanager)
|
||||
* @param activityPackage activity name of the target application (exemple: .optimize.process.ProtectActivity)
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
public static void startActivityByAMSystem(Context context, String packageName, String activityPackage)
|
||||
throws IOException {
|
||||
String cmd = "am start -n " + packageName + "/" + activityPackage;
|
||||
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
cmd += " --user " + um.getSerialNumberForUser(Process.myUserHandle());
|
||||
Runtime.getRuntime().exec(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an Action by using Application Manager System (prevent from crash permission exception)
|
||||
*
|
||||
* @param context current application Context
|
||||
* @param intentAction action of the target application (exemple: com.huawei.systemmanager)
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
public static void startActionByAMSystem(Context context, String intentAction)
|
||||
throws IOException {
|
||||
String cmd = "am start -a " + intentAction;
|
||||
UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||
cmd += " --user " + um.getSerialNumberForUser(Process.myUserHandle());
|
||||
Runtime.getRuntime().exec(cmd);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package com.thelittlefireman.appkillermanager.utils
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Process
|
||||
import android.os.UserManager
|
||||
import androidx.annotation.RequiresApi
|
||||
import timber.log.Timber
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
|
||||
object SystemUtils {
|
||||
val defaultDebugInformation: String
|
||||
get() = "Display_id: ${Build.DISPLAY}\n" +
|
||||
"MODEL: ${Build.MODEL}\n" +
|
||||
"MANUFACTURER: ${Build.MANUFACTURER}\n" +
|
||||
"PRODUCT: ${Build.PRODUCT}"
|
||||
|
||||
val emuiRomName: String?
|
||||
get() = try {
|
||||
getSystemProperty("ro.build.version.emui")
|
||||
} catch (e: Exception) {
|
||||
""
|
||||
}
|
||||
|
||||
fun getApplicationName(context: Context): String {
|
||||
val packageManager = context.packageManager
|
||||
var applicationInfo: ApplicationInfo? = null
|
||||
try {
|
||||
applicationInfo = packageManager.getApplicationInfo(context.applicationInfo.packageName, 0)
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
}
|
||||
return (if (applicationInfo != null) packageManager.getApplicationLabel(applicationInfo) else "Unknown") as String
|
||||
}
|
||||
|
||||
val miuiRomName: String?
|
||||
get() = try {
|
||||
getSystemProperty("ro.miui.ui.version.name")
|
||||
} catch (e: Exception) {
|
||||
""
|
||||
}
|
||||
|
||||
private fun getSystemProperty(propName: String): String? {
|
||||
val line: String
|
||||
var input: BufferedReader? = null
|
||||
try {
|
||||
val p = Runtime.getRuntime().exec("getprop $propName")
|
||||
input = BufferedReader(InputStreamReader(p.inputStream), 1024)
|
||||
line = input.readLine()
|
||||
input.close()
|
||||
} catch (ex: IOException) {
|
||||
Timber.e(ex, "Unable to read system property %s", propName)
|
||||
return null
|
||||
} finally {
|
||||
if (input != null) {
|
||||
try {
|
||||
input.close()
|
||||
} catch (e: IOException) {
|
||||
Timber.e(e, "Exception while closing InputStream")
|
||||
}
|
||||
}
|
||||
}
|
||||
return line
|
||||
}
|
||||
// INFO http://imsardine.simplbug.com/note/android/adb/commands/am-start.html
|
||||
/**
|
||||
* Open an Activity by using Application Manager System (prevent from crash permission exception)
|
||||
*
|
||||
* @param context current application Context
|
||||
* @param packageName pacakge name of the target application (exemple: com.huawei.systemmanager)
|
||||
* @param activityPackage activity name of the target application (exemple: .optimize.process.ProtectActivity)
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
fun startActivityByAMSystem(context: Context, packageName: String, activityPackage: String) {
|
||||
var cmd = "am start -n $packageName/$activityPackage"
|
||||
val um = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
cmd += " --user " + um.getSerialNumberForUser(Process.myUserHandle())
|
||||
Runtime.getRuntime().exec(cmd)
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an Action by using Application Manager System (prevent from crash permission exception)
|
||||
*
|
||||
* @param context current application Context
|
||||
* @param intentAction action of the target application (exemple: com.huawei.systemmanager)
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
fun startActionByAMSystem(context: Context, intentAction: String) {
|
||||
var cmd = "am start -a $intentAction"
|
||||
val um = context.getSystemService(Context.USER_SERVICE) as UserManager
|
||||
cmd += " --user " + um.getSerialNumberForUser(Process.myUserHandle())
|
||||
Runtime.getRuntime().exec(cmd)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue