From 757fe89c745fc404259bda6653c046c13a4e617f Mon Sep 17 00:00:00 2001 From: YuutaW <17158086+trumeet@users.noreply.github.com> Date: Tue, 7 May 2019 17:01:52 -0700 Subject: feat(app): only display the user's apps for non-owner users This is not tested because librootjava does not support multi-user (https://github.com/Chainfire/librootjava/issues/5) Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com> --- .../moe/yuuta/workmode/access/AccessorStarter.kt | 7 +-- .../moe/yuuta/workmode/access/WorkModeAccessor.kt | 52 +++++++--------------- 2 files changed, 18 insertions(+), 41 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 ac198d9..a7056c4 100644 --- a/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt +++ b/app/src/main/java/moe/yuuta/workmode/access/AccessorStarter.kt @@ -6,11 +6,6 @@ import android.os.Bundle import android.os.PersistableBundle import android.service.quicksettings.TileService import androidx.annotation.WorkerThread -import com.elvishew.xlog.Logger -import com.elvishew.xlog.XLog -import eu.chainfire.librootjava.RootIPCReceiver -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 @@ -87,6 +82,8 @@ open class AccessorStarter(private val mContext: Context, private val mService: // We assume that the server must return a non-null result or an exception. if (err != null) throw err as Throwable + if (res == null) + throw NullPointerException("Process completed, but it does not return any result") return res!! } } 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 { val originalApplicationInfo = mutableMapOf() - 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() 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) -- cgit v1.2.3