11
This commit is contained in:
1 parent
c4806fbaf2
commit
d1cb2273d6
17 files changed
+450
-238
No files matched your search
@@ -178,6 +178,38 @@ object KioskModeManager {
|
||||
return provisionResult(false, code, message)
|
||||
}
|
||||
|
||||
/**
|
||||
* 由 Device Owner 应用自身解除设备所有者身份,使本应用恢复为普通应用、可正常卸载。
|
||||
*
|
||||
* 仅在用户主动触发后执行:先关闭自动进入并退出当前 Lock Task,再清除 Owner 身份。
|
||||
* 清除成功后 Kiosk、开机自启能力随之失效,需重新 Root 配置才能恢复。
|
||||
*/
|
||||
fun clearDeviceOwner(activity: Activity): Map<String, Any> {
|
||||
val policyManager = policyManager(activity)
|
||||
if (!policyManager.isDeviceOwnerApp(activity.packageName)) {
|
||||
return provisionResult(false, "NOT_OWNER", "当前应用不是 Device Owner,无需解除")
|
||||
}
|
||||
val autoEnterWasEnabled = isAutoEnterEnabled(activity)
|
||||
preferences(activity).edit().putBoolean(AUTO_ENTER_ENABLED_KEY, false).commit()
|
||||
exitCurrentKiosk(activity)
|
||||
return try {
|
||||
@Suppress("DEPRECATION")
|
||||
policyManager.clearDeviceOwnerApp(activity.packageName)
|
||||
if (policyManager.isDeviceOwnerApp(activity.packageName)) {
|
||||
// 厂商固件可能静默拒绝清除;回滚自动进入配置并返回明确错误。
|
||||
preferences(activity).edit()
|
||||
.putBoolean(AUTO_ENTER_ENABLED_KEY, autoEnterWasEnabled).commit()
|
||||
provisionResult(false, "OEM_REFUSED", "系统拒绝解除 Device Owner,请恢复出厂设置处理")
|
||||
} else {
|
||||
provisionResult(true, "OK", "Device Owner 已解除")
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
preferences(activity).edit()
|
||||
.putBoolean(AUTO_ENTER_ENABLED_KEY, autoEnterWasEnabled).commit()
|
||||
provisionResult(false, "CLEAR_FAILED", error.message ?: "解除 Device Owner 失败")
|
||||
}
|
||||
}
|
||||
|
||||
/** 窗口重新获得焦点时恢复 Kiosk 系统栏策略,防止临时系统界面留下可退出入口。 */
|
||||
fun reapplySystemBars(activity: Activity) {
|
||||
if (isKioskActive(activity)) hideSystemBars(activity)
|
||||
|
||||
@@ -146,6 +146,11 @@ class MainActivity : FlutterActivity() {
|
||||
}
|
||||
}
|
||||
"exitKioskToHome" -> result.success(KioskModeManager.exitToHome(this))
|
||||
"clearKioskDeviceOwner" -> result.success(
|
||||
// 清除必须先在 UI 线程退出 Lock Task,操作本身是快速本地调用。
|
||||
KioskModeManager.clearDeviceOwner(this) +
|
||||
("status" to KioskModeManager.status(this))
|
||||
)
|
||||
"validateApk" -> {
|
||||
val path = call.argument<String>("path")
|
||||
val expectedVersionCode = call.argument<Number>("expectedVersionCode")?.toLong()
|
||||
|
||||
Reference in new issue
Block a user