@@ -14,10 +14,11 @@ import kotlinx.coroutines.CompletableDeferred
1414import kotlinx.coroutines.flow.MutableStateFlow
1515import kotlinx.coroutines.flow.updateAndGet
1616import li.songe.gkd.MainActivity
17+ import li.songe.gkd.MainViewModel
1718import li.songe.gkd.app
19+ import li.songe.gkd.shizuku.SafeAppOpsService
1820import li.songe.gkd.shizuku.SafePackageManager
1921import li.songe.gkd.shizuku.shizukuContextFlow
20- import li.songe.gkd.ui.share.LocalMainViewModel
2122import li.songe.gkd.util.AndroidTarget
2223import li.songe.gkd.util.toast
2324import li.songe.gkd.util.updateAllAppInfo
@@ -88,8 +89,7 @@ private suspend fun asyncRequestPermission(
8889 return deferred.await()
8990}
9091
91- @Suppress(" SameParameterValue" )
92- private fun checkAllowedOp (op : String ): Boolean = app.appOpsManager.checkOpNoThrow(
92+ fun checkAllowedOp (op : String ): Boolean = app.appOpsManager.checkOpNoThrow(
9393 op,
9494 android.os.Process .myUid(),
9595 app.packageName
@@ -111,16 +111,74 @@ val foregroundServiceSpecialUseState by lazy {
111111 },
112112 reason = AuthReason (
113113 text = { " 当前操作权限「特殊用途的前台服务」已被限制, 请先解除限制" },
114- renderConfirm = {
115- val mainVm = LocalMainViewModel .current
116- {
117- mainVm.navigatePage(AppOpsAllowPageDestination )
118- }
119- }
114+ confirm = {
115+ MainViewModel .instance.navigatePage(AppOpsAllowPageDestination )
116+ },
120117 ),
121118 )
122119}
123120
121+ // https://github.com/orgs/gkd-kit/discussions/1234
122+ val accessA11yState by lazy {
123+ PermissionState (
124+ name = " 访问无障碍" ,
125+ check = {
126+ if (AndroidTarget .Q ) {
127+ checkAllowedOp(" android:access_accessibility" )
128+ } else {
129+ true
130+ }
131+ },
132+ )
133+ }
134+
135+ val createA11yOverlayState by lazy {
136+ PermissionState (
137+ name = " 创建无障碍悬浮窗" ,
138+ check = {
139+ if (SafeAppOpsService .supportCreateA11yOverlay) {
140+ checkAllowedOp(" android:create_accessibility_overlay" )
141+ } else {
142+ true
143+ }
144+ },
145+ )
146+ }
147+
148+ val getAppOpsStatsState by lazy {
149+ PermissionState (
150+ name = " 获取应用操作状态" ,
151+ check = {
152+ ContextCompat .checkSelfPermission(
153+ app,
154+ " android.permission.GET_APP_OPS_STATS" ,
155+ ) == PackageManager .PERMISSION_GRANTED
156+ },
157+ )
158+ }
159+
160+ val accessRestrictedSettingsState by lazy {
161+ PermissionState (
162+ name = " 访问受限设置" ,
163+ check = {
164+ if (AndroidTarget .TIRAMISU && getAppOpsStatsState.updateAndGet()) {
165+ checkAllowedOp(" android:access_restricted_settings" )
166+ } else {
167+ true
168+ }
169+ },
170+ )
171+ }
172+
173+ val appOpsRestrictStateList by lazy {
174+ arrayOf(
175+ accessA11yState,
176+ createA11yOverlayState,
177+ accessRestrictedSettingsState,
178+ foregroundServiceSpecialUseState,
179+ )
180+ }
181+
124182val notificationState by lazy {
125183 val permission = PermissionLists .getNotificationServicePermission()
126184 PermissionState (
@@ -258,6 +316,10 @@ val allPermissionStates by lazy {
258316 listOf (
259317 notificationState,
260318 foregroundServiceSpecialUseState,
319+ accessA11yState,
320+ createA11yOverlayState,
321+ getAppOpsStatsState,
322+ accessRestrictedSettingsState,
261323 canDrawOverlaysState,
262324 canWriteExternalStorage,
263325 ignoreBatteryOptimizationsState,
0 commit comments