From f02787275d311af463d5250c5998f541e5529982 Mon Sep 17 00:00:00 2001 From: YuutaW <17158086+trumeet@users.noreply.github.com> Date: Sat, 30 Mar 2019 16:28:27 -0700 Subject: feat(app): give non-owner user a notice for apps suspended by owner Signed-off-by: YuutaW <17158086+Trumeet@users.noreply.github.com> --- .../moe/yuuta/workmode/access/AccessLayerUtil.kt | 22 +++++++++++++--------- .../moe/yuuta/workmode/access/WorkModeAccessor.kt | 6 +++--- 2 files changed, 16 insertions(+), 12 deletions(-) (limited to 'app/src/main/java/moe') diff --git a/app/src/main/java/moe/yuuta/workmode/access/AccessLayerUtil.kt b/app/src/main/java/moe/yuuta/workmode/access/AccessLayerUtil.kt index 4bfee58..7248198 100644 --- a/app/src/main/java/moe/yuuta/workmode/access/AccessLayerUtil.kt +++ b/app/src/main/java/moe/yuuta/workmode/access/AccessLayerUtil.kt @@ -1,10 +1,7 @@ package moe.yuuta.workmode.access import android.content.pm.ApplicationInfo -import android.os.BaseBundle -import android.os.Bundle -import android.os.PersistableBundle -import android.os.UserManager +import android.os.* import com.elvishew.xlog.XLog import moe.yuuta.workmode.R import moe.yuuta.workmode.suspend.data.TransferableSuspendedApp @@ -33,7 +30,8 @@ internal class AccessLayerUtil(private val accessLayer: AccessLayer) { suspended: Boolean, appExtras: BaseBundle, launcherExtras: BaseBundle, - dialogMessage: String): Array { + dialogMessage: String?, + hostInfo: HostInfo): Array { val packagesWithUserIds = collectUserIDs(packages) val result = mutableListOf() @@ -52,17 +50,23 @@ internal class AccessLayerUtil(private val accessLayer: AccessLayer) { is PersistableBundle -> launcherExtras is Bundle -> BundleUtils.toPersistableBundle(launcherExtras) else -> PersistableBundle() - }, dialogMessage, userId)) + }, if (dialogMessage == null) { + if (userId == hostInfo.userId || + userId == UserHandle.USER_OWNER) accessLayer.mContext.getString(R.string.suspended_message) + else accessLayer.mContext.getString(R.string.suspended_message_managed) + } else dialogMessage, + userId)) } return result.toTypedArray() } - fun suspend(packages: List, suspended: Boolean): Array = + fun suspend(packages: List, suspended: Boolean, hostInfo: HostInfo): Array = suspend(packages, suspended, Bundle(), - PersistableBundle(), // Removed because there is an unknown bug which prevents from writing launcher extras from the owner (?) - accessLayer.mContext.getString(R.string.suspended_message)) + PersistableBundle(), // Removed because there is an unknown bug which prevents from writing launcher extras from the owner (?) + null, + hostInfo) fun getSuspendedPackageAppExtras(packageInfo: TransferableSuspendedApp): PersistableBundle? = accessLayer.getSuspendedPackageAppExtras(packageName = packageInfo.packageName, 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 5f50d67..abb5352 100644 --- a/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt +++ b/app/src/main/java/moe/yuuta/workmode/access/WorkModeAccessor.kt @@ -252,7 +252,7 @@ class WorkModeAccessor { logger.d("Running suspend: $suspended on ${packages.size} packages.") val result = Bundle() result.putStringArray(AccessorStarter.EXTRA_DATA, - pmAccess.suspend(packages, suspended, appExtras, launcherExtras, dialogMessage)) + pmAccess.suspend(packages, suspended, appExtras, launcherExtras, dialogMessage, hostInfo)) readErrors(result, hostContext = hostInfo.hostContext) postExecuteNotify(hostContext = hostInfo.hostContext) return result @@ -418,7 +418,7 @@ class WorkModeAccessor { logger.d("Applying settings: suspend $suspendList") if (suspendList.size > 0) { pmAccess.suspend(suspendList, - true) + true, hostInfo) } } // Then unsuspand @@ -433,7 +433,7 @@ class WorkModeAccessor { logger.d("Applying settings: unsuspend $unsuspendList") if (unsuspendList.size > 0) { pmAccess.suspend(unsuspendList, - false) + false, hostInfo) } readErrors(result, hostContext = hostInfo.hostContext) postExecuteNotify(hostContext = hostInfo.hostContext) -- cgit v1.2.3