Skip to content

Commit

Permalink
Remove KillerManagerUtils, convert SystemUtils to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
mklkj committed May 20, 2020
1 parent 587f58e commit e5b06d9
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 203 deletions.
Original file line number Diff line number Diff line change
@@ -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.*
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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? = ""
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit e5b06d9

Please sign in to comment.