Bugfix and new APIs

Fix permitted accessibility services and permitted ime, close #165
New APIs, close #166
Optimize shortcuts creation, add ShortcutUtils
This commit is contained in:
BinTianqi
2025-09-25 23:01:02 +08:00
parent 289afb63ff
commit 5928dbb657
10 changed files with 158 additions and 123 deletions

View File

@@ -1,12 +1,8 @@
package com.bintianqi.owndroid
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.graphics.drawable.IconCompat
import android.util.Log
class ShortcutsReceiverActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
@@ -17,50 +13,24 @@ class ShortcutsReceiverActivity : Activity() {
when (action) {
"LOCK" -> Privilege.DPM.lockNow()
"DISABLE_CAMERA" -> {
Privilege.DPM.setCameraDisabled(Privilege.DAR, !Privilege.DPM.getCameraDisabled(Privilege.DAR))
createShortcuts(this)
val state = Privilege.DPM.getCameraDisabled(Privilege.DAR)
Privilege.DPM.setCameraDisabled(Privilege.DAR, !state)
ShortcutUtils.setShortcut(this, MyShortcut.DisableCamera, state)
}
"MUTE" -> {
Privilege.DPM.setMasterVolumeMuted(Privilege.DAR, !Privilege.DPM.isMasterVolumeMuted(Privilege.DAR))
createShortcuts(this)
val state = Privilege.DPM.isMasterVolumeMuted(Privilege.DAR)
Privilege.DPM.setMasterVolumeMuted(Privilege.DAR, !state)
ShortcutUtils.setShortcut(this, MyShortcut.Mute, state)
}
}
Log.d(TAG, "Received intent: $action")
showOperationResultToast(true)
}
} finally {
finish()
}
}
}
fun createShortcuts(context: Context) {
if (!SP.shortcuts) return
val action = "com.bintianqi.owndroid.action"
val baseIntent = Intent(context, ShortcutsReceiverActivity::class.java)
val cameraDisabled = Privilege.DPM.getCameraDisabled(Privilege.DAR)
val muted = Privilege.DPM.isMasterVolumeMuted(Privilege.DAR)
val list = listOf(
ShortcutInfoCompat.Builder(context, "LOCK")
.setIcon(IconCompat.createWithResource(context, R.drawable.screen_lock_portrait_fill0))
.setShortLabel(context.getString(R.string.lock_screen))
.setIntent(Intent(baseIntent).setAction("$action.LOCK")),
ShortcutInfoCompat.Builder(context, "DISABLE_CAMERA")
.setIcon(
IconCompat.createWithResource(
context,
if (cameraDisabled) R.drawable.photo_camera_fill0 else R.drawable.no_photography_fill0
)
)
.setShortLabel(context.getString(if (cameraDisabled) R.string.enable_camera else R.string.disable_cam))
.setIntent(Intent(baseIntent).setAction("$action.DISABLE_CAMERA")),
ShortcutInfoCompat.Builder(context, "MUTE")
.setIcon(
IconCompat.createWithResource(
context,
if (muted) R.drawable.volume_up_fill0 else R.drawable.volume_off_fill0
)
)
.setShortLabel(context.getString(if (muted) R.string.unmute else R.string.mute))
.setIntent(Intent(baseIntent).setAction("$action.MUTE"))
)
ShortcutManagerCompat.setDynamicShortcuts(context, list.map { it.build() })
companion object {
private const val TAG = "ShortcutsReceiver"
}
}