forked from tabebqena/AppKillerManager
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove KillerManagerUtils, convert SystemUtils to kotlin
- Loading branch information
Showing
5 changed files
with
116 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
...manager/src/main/java/com/thelittlefireman/appkillermanager/utils/KillerManagerUtils.java
This file was deleted.
Oops, something went wrong.
111 changes: 0 additions & 111 deletions
111
appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/utils/SystemUtils.java
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
appkillermanager/src/main/java/com/thelittlefireman/appkillermanager/utils/SystemUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |