Skip to content

Commit

Permalink
#1298 feat: add action to launch the Android device controls screen
Browse files Browse the repository at this point in the history
  • Loading branch information
sds100 committed Dec 15, 2024
1 parent d8a2974 commit fb3789d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -647,4 +647,9 @@ sealed class ActionData {
object EndCall : ActionData() {
override val id: ActionId = ActionId.END_PHONE_CALL
}

@Serializable
object DeviceControls : ActionData() {
override val id: ActionId = ActionId.DEVICE_CONTROLS
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import io.github.sds100.keymapper.util.getKey
import io.github.sds100.keymapper.util.success
import io.github.sds100.keymapper.util.then
import io.github.sds100.keymapper.util.valueOrNull
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import splitties.bitflags.hasFlag
Expand Down Expand Up @@ -482,6 +481,7 @@ object ActionDataEntityMapper {
ActionId.DISMISS_ALL_NOTIFICATIONS -> ActionData.DismissAllNotifications
ActionId.ANSWER_PHONE_CALL -> ActionData.AnswerCall
ActionId.END_PHONE_CALL -> ActionData.EndCall
ActionId.DEVICE_CONTROLS -> ActionData.DeviceControls
}
}

Expand Down Expand Up @@ -806,5 +806,6 @@ object ActionDataEntityMapper {

ActionId.ANSWER_PHONE_CALL to "answer_phone_call",
ActionId.END_PHONE_CALL to "end_phone_call",
ActionId.DEVICE_CONTROLS to "device_controls",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@ enum class ActionId {

ANSWER_PHONE_CALL,
END_PHONE_CALL,
DEVICE_CONTROLS,
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ object ActionUtils {

ActionId.DISMISS_MOST_RECENT_NOTIFICATION -> ActionCategory.NOTIFICATIONS
ActionId.DISMISS_ALL_NOTIFICATIONS -> ActionCategory.NOTIFICATIONS
ActionId.DEVICE_CONTROLS -> ActionCategory.APPS
}

@StringRes
Expand Down Expand Up @@ -267,6 +268,7 @@ object ActionUtils {
ActionId.DISMISS_ALL_NOTIFICATIONS -> R.string.action_dismiss_all_notifications
ActionId.ANSWER_PHONE_CALL -> R.string.action_answer_call
ActionId.END_PHONE_CALL -> R.string.action_end_call
ActionId.DEVICE_CONTROLS -> R.string.action_device_controls
}

@DrawableRes
Expand Down Expand Up @@ -378,6 +380,7 @@ object ActionUtils {
ActionId.DISMISS_ALL_NOTIFICATIONS -> R.drawable.ic_baseline_clear_all_24
ActionId.ANSWER_PHONE_CALL -> R.drawable.ic_outline_call_24
ActionId.END_PHONE_CALL -> R.drawable.ic_outline_call_end_24
ActionId.DEVICE_CONTROLS -> R.drawable.ic_home_automation
}

fun getMinApi(id: ActionId): Int = when (id) {
Expand Down Expand Up @@ -412,6 +415,7 @@ object ActionUtils {
-> Build.VERSION_CODES.JELLY_BEAN_MR2

ActionId.SHOW_POWER_MENU -> Build.VERSION_CODES.LOLLIPOP
ActionId.DEVICE_CONTROLS -> Build.VERSION_CODES.S

else -> Constants.MIN_API
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ abstract class BaseActionUiHelper<MAPPING : Mapping<A>, A : Action>(

ActionData.AnswerCall -> getString(R.string.action_answer_call)
ActionData.EndCall -> getString(R.string.action_end_call)

ActionData.DeviceControls -> getString(R.string.action_device_controls)
}

override fun getIcon(action: ActionData): IconInfo? = when (action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ class CreateActionViewModelImpl(
ActionId.DISMISS_ALL_NOTIFICATIONS -> return ActionData.DismissAllNotifications
ActionId.ANSWER_PHONE_CALL -> return ActionData.AnswerCall
ActionId.END_PHONE_CALL -> return ActionData.EndCall
ActionId.DEVICE_CONTROLS -> return ActionData.DeviceControls
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.github.sds100.keymapper.system.inputmethod.InputKeyModel
import io.github.sds100.keymapper.system.inputmethod.InputMethodAdapter
import io.github.sds100.keymapper.system.inputmethod.KeyMapperImeMessenger
import io.github.sds100.keymapper.system.intents.IntentAdapter
import io.github.sds100.keymapper.system.intents.IntentTarget
import io.github.sds100.keymapper.system.keyevents.KeyEventUtils
import io.github.sds100.keymapper.system.lock.LockScreenAdapter
import io.github.sds100.keymapper.system.media.MediaAdapter
Expand Down Expand Up @@ -786,6 +787,14 @@ class PerformActionsUseCaseImpl(
phoneAdapter.endCall()
result = success()
}

ActionData.DeviceControls -> {
result = intentAdapter.send(
IntentTarget.ACTIVITY,
uri = "#Intent;action=android.intent.action.MAIN;package=com.android.systemui;component=com.android.systemui/.controls.ui.ControlsActivity;end",
extras = emptyList(),
)
}
}

when (result) {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_home_automation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,3L2,12H5V20H19V12H22L12,3M12,8.5C14.34,8.5 16.46,9.43 18,10.94L16.8,12.12C15.58,10.91 13.88,10.17 12,10.17C10.12,10.17 8.42,10.91 7.2,12.12L6,10.94C7.54,9.43 9.66,8.5 12,8.5M12,11.83C13.4,11.83 14.67,12.39 15.6,13.3L14.4,14.47C13.79,13.87 12.94,13.5 12,13.5C11.06,13.5 10.21,13.87 9.6,14.47L8.4,13.3C9.33,12.39 10.6,11.83 12,11.83M12,15.17C12.94,15.17 13.7,15.91 13.7,16.83C13.7,17.75 12.94,18.5 12,18.5C11.06,18.5 10.3,17.75 10.3,16.83C10.3,15.91 11.06,15.17 12,15.17Z" />
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,7 @@
<string name="action_play_sound">Play sound</string>
<string name="action_dismiss_most_recent_notification">Dismiss most recent notification</string>
<string name="action_dismiss_all_notifications">Dismiss all notifications</string>
<string name="action_device_controls">Device controls screen</string>
<!-- action labels -->

<!-- action category labels -->
Expand Down

0 comments on commit fb3789d

Please sign in to comment.