blob: 504fdba4f8c5d4bcd934861d8fd4a788e976bab1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package moe.yuuta.workmode.suspend
import android.content.ComponentName
import android.content.Context
import android.os.PersistableBundle
import android.service.quicksettings.TileService
import moe.yuuta.workmode.R
import moe.yuuta.workmode.access.ApplicationAccessorStarter
import moe.yuuta.workmode.suspend.data.SuspendedStorage
/**
* The highest-level suspender to wrap all information needed to suspend or vice versa. This
* should be called from UI components directly
* Chain: UI -> Suspender -> AccessorStarter -> WorkModeAccessor -> AccessLayer -> Framework
*/
class Suspender(private val mContext: Context) {
fun suspend(packageNames: Array<String>, suspended: Boolean): Array<String> =
ApplicationAccessorStarter(mContext).setPackagesSuspended(packageNames,
suspended,
PersistableBundle(),
SuspendedApp.getDefault().serializeBundle(), // We use LauncherExtras because they are easy to read
mContext.getString(R.string.suspended_message),
true)
fun isSuspended(packageNames: Array<String>): Boolean =
ApplicationAccessorStarter(mContext).isPackageSuspended(packageNames, true)
fun getPackagesSuspendedByWorkMode(): List<String> =
ApplicationAccessorStarter(mContext).getPackagesSuspendedByWorkMode(true)
fun applyFromSettings() {
val storage = SuspendedStorage.get(mContext)
storage.cleanList(mContext)
val status = storage.getStatus()
val listMode = storage.getListMode()
val list = storage.getList()
ApplicationAccessorStarter(mContext).apply(list.toTypedArray(), listMode, status, true)
TileService.requestListeningState(mContext, ComponentName(mContext, SuspendTile::class.java))
}
}
|