aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt')
-rw-r--r--app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt52
1 files changed, 16 insertions, 36 deletions
diff --git a/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt b/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt
index abb5352..3053f8b 100644
--- a/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt
+++ b/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt
@@ -13,11 +13,6 @@ import android.os.Process
import android.os.UserHandle
import android.service.quicksettings.TileService
import androidx.content.pm.PackageOZ
-import com.elvishew.xlog.Logger
-import com.elvishew.xlog.XLog
-import eu.chainfire.librootjava.RootIPC
-import eu.chainfire.librootjava.RootJava
-import eu.chainfire.libsuperuser.Shell
import moe.yuuta.workmode.BuildConfig
import moe.yuuta.workmode.IAccessor
import moe.yuuta.workmode.R
@@ -144,22 +139,27 @@ class WorkModeAccessor {
// && SuspendedApp.deserializeBundle(pmAccess.getSuspendedPackageLauncherExtras(it)).isSuspendedByWorkMode
}
.collect(Collectors.toList())
- result.forEach {
- logger.d("SuspendingA-A ${it.packageName} ${it.userId}")
- }
return result
}
private fun _getInstalledApplicationsAcrossUser(pmAccess: AccessLayerUtil, hostInfo: HostInfo, flags: Int): MutableList<TransferableSuspendedApp> {
val originalApplicationInfo = mutableMapOf<TransferableSuspendedApp, ApplicationInfo>()
- val packages = pmAccess.getInstalledApplicationsAnyUser(flags).stream()
- .map {
- val sus = fillDataIfNeeded(PersistableSuspendedApp(UserHandle.getUserHandleForUid(it.uid).hashCode(),
- it.packageName), hostInfo)
- originalApplicationInfo.put(sus, it)
- return@map sus
- }
- .collect(Collectors.toList())
+ val packages =
+ if (hostInfo.userId == UserHandle.USER_OWNER) {
+ // Allow the device owner to manage all apps on the device
+ pmAccess.getInstalledApplicationsAnyUser(flags)
+ } else {
+ // He or she is not the owner, only show his or her apps
+ pmAccess.getInstalledApplicationsAsUser(flags, hostInfo.userId)
+ }.stream()
+ .map {
+ val sus = fillDataIfNeeded(PersistableSuspendedApp(UserHandle.getUserHandleForUid(it.uid).hashCode(),
+ it.packageName), hostInfo)
+ originalApplicationInfo.put(sus, it)
+ return@map sus
+ }
+ .collect(Collectors.toList())
+ logger.d("PKGS: $packages")
val packagesWithUserIds = pmAccess.collectUserIDs(packages)
val finalList = mutableListOf<TransferableSuspendedApp>()
for (userId in packagesWithUserIds.keys) {
@@ -232,7 +232,6 @@ class WorkModeAccessor {
val hostInfo = HostInfo.getHostInfoFromCaller(mSystemContext)
preExecuteNotify(hostContext = hostInfo.hostContext)
val pmAccess = AccessLayerUtil(AccessLayer(hostInfo.hostContext))
- logger.d("Installed applications (all users, debug): ${pmAccess.getInstalledApplicationsAnyUser(0)}")
val result = DumpResult(pmAccess.isPackageSuspended(packageInfo),
pmAccess.getSuspendedPackageLauncherExtras(packageInfo) ?: Bundle.EMPTY)
postExecuteNotify(hostContext = hostInfo.hostContext)
@@ -304,12 +303,6 @@ class WorkModeAccessor {
else -> throw IllegalArgumentException("Unexpected status")
}
- systemSuspendedList
- .stream()
- .forEach {
- logger.d("SYS ${it.packageName} ${it.userId}")
- }
-
val tasks = systemAllAppList.stream()
// Filter "don't care" situations, do not map them here.
.filter {
@@ -324,27 +317,21 @@ class WorkModeAccessor {
if (systemSuspended) {
if (inOurList) {
if (status == Status.ON) {
- logger.d("Ignoring $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of A")
return@filter false
} else {
- logger.d("Including $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of B")
return@filter true
}
} else {
if (status == Status.ON) {
- logger.d("Including $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of C")
return@filter true
} else {
- logger.d("Ignoring $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of D")
return@filter false
}
}
} else {
if (status == Status.ON) {
- logger.d("Ignoring/Including $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of E ($inOurList)")
return@filter inOurList
} else {
- logger.d("Ignoring $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of F")
return@filter false
}
}
@@ -352,23 +339,18 @@ class WorkModeAccessor {
ListMode.WHITELIST -> {
if (systemSuspended) {
if (inOurList) {
- logger.d("Including $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of B1")
return@filter true
} else {
if (status == Status.ON) {
- logger.d("Ignoring $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of B2")
return@filter false
} else {
- logger.d("Including $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of B3")
return@filter true
}
}
} else {
if (status == Status.ON) {
- logger.d("Ignoring/Including $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of B4 (${!inOurList})")
return@filter !inOurList
} else {
- logger.d("Ignoring $systemSuspended $inOurList ${it.packageName} (${it.userId}) because of B5")
return@filter false
}
}
@@ -415,7 +397,6 @@ class WorkModeAccessor {
return@map it.packageInfo
}
.collect(Collectors.toList())
- logger.d("Applying settings: suspend $suspendList")
if (suspendList.size > 0) {
pmAccess.suspend(suspendList,
true, hostInfo)
@@ -430,7 +411,6 @@ class WorkModeAccessor {
return@map it.packageInfo
}
.collect(Collectors.toList())
- logger.d("Applying settings: unsuspend $unsuspendList")
if (unsuspendList.size > 0) {
pmAccess.suspend(unsuspendList,
false, hostInfo)