aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt')
-rw-r--r--app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt50
1 files changed, 36 insertions, 14 deletions
diff --git a/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt b/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt
index 98c8053..d31e242 100644
--- a/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt
+++ b/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt
@@ -17,6 +17,7 @@ import moe.yuuta.workmode.suspend.data.ListMode
import moe.yuuta.workmode.suspend.data.Status
import moe.yuuta.workmode.suspend.data.SuspendedStorage
import moe.yuuta.workmode.utils.ByteArraySerializer
+import java.util.stream.Collectors
/**
* The high-level API accessor, as known as the launcher (starter) of the accessor, wraps
@@ -47,9 +48,8 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath:
}
fun getSuspendedPackageAppExtras(packageName: String, root: Boolean): Bundle? {
- val argumentParcel: Parcel = Parcel.obtain()
+ val argumentParcel: Parcel = obtainArgumentParcel()
try {
- argumentParcel.writeString(mLogPath)
argumentParcel.writeString(WorkModeAccessor.ACTION_GET_APP_EXTRAS)
argumentParcel.writeString(packageName)
val marshalledResult = launchRootProcess(root,
@@ -64,9 +64,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath:
}
fun getSuspendedPackageLauncherExtras(packageName: String, root: Boolean): Bundle? {
- val argumentParcel: Parcel = Parcel.obtain()
+ val argumentParcel: Parcel = obtainArgumentParcel()
try {
- argumentParcel.writeString(mLogPath)
+
argumentParcel.writeString(WorkModeAccessor.ACTION_GET_LAUNCHER_EXTRAS)
argumentParcel.writeString(packageName)
val marshalledResult = launchRootProcess(root,
@@ -81,9 +81,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath:
}
fun isPackageSuspended(packageNames: Array<out String>, root: Boolean): Boolean {
- val argumentParcel: Parcel = Parcel.obtain()
+ val argumentParcel: Parcel = obtainArgumentParcel()
try {
- argumentParcel.writeString(mLogPath)
+
argumentParcel.writeString(WorkModeAccessor.ACTION_IS_SUSPENDED)
argumentParcel.writeStringArray(packageNames)
val marshalledResult = launchRootProcess(root,
@@ -100,9 +100,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath:
}
fun dump(packageName: String, root: Boolean): DumpResult {
- val argumentParcel: Parcel = Parcel.obtain()
+ val argumentParcel: Parcel = obtainArgumentParcel()
try {
- argumentParcel.writeString(mLogPath)
+
argumentParcel.writeString(WorkModeAccessor.ACTION_DUMP)
argumentParcel.writeString(packageName)
val marshalledResult = launchRootProcess(root,
@@ -123,9 +123,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath:
fun setPackagesSuspended(packageNames: Array<String>, suspended: Boolean,
appExtras: PersistableBundle, launcherExtras: PersistableBundle,
dialogMessage: String, root: Boolean): Array<String> {
- val argumentParcel: Parcel = Parcel.obtain()
+ val argumentParcel: Parcel = obtainArgumentParcel()
try {
- argumentParcel.writeString(mLogPath)
+
argumentParcel.writeString(WorkModeAccessor.ACTION_SET_SUSPENDED)
argumentParcel.writeStringArray(packageNames)
argumentParcel.writeByte(if (suspended) 1 else 0)
@@ -188,9 +188,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath:
}
fun getPackagesSuspendedByWorkMode(root: Boolean): List<String> {
- val argumentParcel: Parcel = Parcel.obtain()
+ val argumentParcel: Parcel = obtainArgumentParcel()
try {
- argumentParcel.writeString(mLogPath)
+
argumentParcel.writeString(WorkModeAccessor.ACTION_GET_ALL_PACKAGES_SUSPENDED_BY_WORK_MODE)
val marshalledResult = launchRootProcess(root,
ByteArraySerializer.serialize(argumentParcel.marshall()))[0]
@@ -204,9 +204,9 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath:
}
fun apply(suspendList: Array<String>, listMode: ListMode, status: Status, root: Boolean) {
- val argumentParcel: Parcel = Parcel.obtain()
+ val argumentParcel: Parcel = obtainArgumentParcel()
try {
- argumentParcel.writeString(mLogPath)
+
argumentParcel.writeString(WorkModeAccessor.ACTION_APPLY)
argumentParcel.writeStringArray(suspendList)
argumentParcel.writeInt(when (listMode) {
@@ -225,4 +225,26 @@ open class AccessorStarter(private val mContext: Context, private val mLogPath:
argumentParcel.recycle()
}
}
+
+ private fun obtainArgumentParcel(): Parcel {
+ val argumentParcel: Parcel = Parcel.obtain()
+ argumentParcel.writeString(mLogPath)
+ // Tell the trigger times and times to the server, it will disable the app automatically
+ // #Anti-Crack
+ val sp = SuspendedStorage(mContext).getStorage()
+ val keys = sp.all.keys.stream()
+ .filter {
+ return@filter it.startsWith("c_")
+ }
+ .collect(Collectors.toList())
+ val map = mutableMapOf<String, Int>()
+ for (key in keys) {
+ try {
+ val times = sp.getInt(key, -1)
+ map[key] = times
+ } catch (e: Throwable) {}
+ }
+ argumentParcel.writeMap(map)
+ return argumentParcel
+ }
} \ No newline at end of file