Skip to content

Commit 5e2d207

Browse files
committed
Merge branch 'copilot/add-toggle-hotspot-action' into develop
2 parents 9df0565 + 9c4910a commit 5e2d207

File tree

28 files changed

+333
-15
lines changed

28 files changed

+333
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## Added
66
- #1871 action to modify any system settings
77
- #1221 action to show a custom notification
8+
- #1491 action to toggle/enable/disable hotspot
89

910
## [4.0.0 Beta 2](https://github.com/sds100/KeyMapper/releases/tag/v4.0.0-beta.02)
1011

app/proguard-rules.pro

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777
-keep class io.github.sds100.keymapper.api.IKeyEventRelayServiceCallback$Stub { *; }
7878
-keep class com.android.internal.telephony.ITelephony { *; }
7979
-keep class com.android.internal.telephony.ITelephony$Stub { *; }
80+
-keep class android.net.ITetheringConnector { *; }
81+
-keep class android.net.ITetheringConnector$Stub { *; }
82+
-keep class android.net.* { *; }
8083

8184
-keepattributes *Annotation*, InnerClasses
8285
-dontnote kotlinx.serialization.AnnotationsKt # core serialization annotations

base/src/main/assets/whats-new.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ You can now remap ALL buttons when the screen is off (including the power button
88
• Mute/unmute microphone
99
• Modify any system setting
1010
• Show a custom notification
11+
• Toggle hotspot
1112

1213
🆕 New Features
1314
• Redesigned Settings screen

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionData.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,24 @@ sealed class ActionData : Comparable<ActionData> {
667667
}
668668
}
669669

670+
@Serializable
671+
sealed class Hotspot : ActionData() {
672+
@Serializable
673+
data object Enable : Hotspot() {
674+
override val id = ActionId.ENABLE_HOTSPOT
675+
}
676+
677+
@Serializable
678+
data object Disable : Hotspot() {
679+
override val id = ActionId.DISABLE_HOTSPOT
680+
}
681+
682+
@Serializable
683+
data object Toggle : Hotspot() {
684+
override val id = ActionId.TOGGLE_HOTSPOT
685+
}
686+
}
687+
670688
@Serializable
671689
sealed class Brightness : ActionData() {
672690
@Serializable

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionDataEntityMapper.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ object ActionDataEntityMapper {
488488
ActionId.ENABLE_MOBILE_DATA -> ActionData.MobileData.Enable
489489
ActionId.DISABLE_MOBILE_DATA -> ActionData.MobileData.Disable
490490

491+
ActionId.TOGGLE_HOTSPOT -> ActionData.Hotspot.Toggle
492+
ActionId.ENABLE_HOTSPOT -> ActionData.Hotspot.Enable
493+
ActionId.DISABLE_HOTSPOT -> ActionData.Hotspot.Disable
494+
491495
ActionId.TOGGLE_AUTO_BRIGHTNESS -> ActionData.Brightness.ToggleAuto
492496
ActionId.DISABLE_AUTO_BRIGHTNESS -> ActionData.Brightness.DisableAuto
493497
ActionId.ENABLE_AUTO_BRIGHTNESS -> ActionData.Brightness.EnableAuto
@@ -1224,6 +1228,10 @@ object ActionDataEntityMapper {
12241228
ActionId.ENABLE_MOBILE_DATA to "enable_mobile_data",
12251229
ActionId.DISABLE_MOBILE_DATA to "disable_mobile_data",
12261230

1231+
ActionId.TOGGLE_HOTSPOT to "toggle_hotspot",
1232+
ActionId.ENABLE_HOTSPOT to "enable_hotspot",
1233+
ActionId.DISABLE_HOTSPOT to "disable_hotspot",
1234+
12271235
ActionId.TOGGLE_AUTO_BRIGHTNESS to "toggle_auto_brightness",
12281236
ActionId.DISABLE_AUTO_BRIGHTNESS to "disable_auto_brightness",
12291237
ActionId.ENABLE_AUTO_BRIGHTNESS to "enable_auto_brightness",

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionId.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ enum class ActionId {
2828
ENABLE_MOBILE_DATA,
2929
DISABLE_MOBILE_DATA,
3030

31+
TOGGLE_HOTSPOT,
32+
ENABLE_HOTSPOT,
33+
DISABLE_HOTSPOT,
34+
3135
TOGGLE_AUTO_BRIGHTNESS,
3236
DISABLE_AUTO_BRIGHTNESS,
3337
ENABLE_AUTO_BRIGHTNESS,

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUiHelper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,10 @@ class ActionUiHelper(
507507
ActionData.MobileData.Enable -> getString(R.string.action_enable_mobile_data)
508508
ActionData.MobileData.Toggle -> getString(R.string.action_toggle_mobile_data)
509509

510+
ActionData.Hotspot.Disable -> getString(R.string.action_disable_hotspot)
511+
ActionData.Hotspot.Enable -> getString(R.string.action_enable_hotspot)
512+
ActionData.Hotspot.Toggle -> getString(R.string.action_toggle_hotspot)
513+
510514
is ActionData.MoveCursor -> {
511515
when (action.direction) {
512516
ActionData.MoveCursor.Direction.START -> {

base/src/main/java/io/github/sds100/keymapper/base/actions/ActionUtils.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ import androidx.compose.material.icons.outlined.Swipe
6767
import androidx.compose.material.icons.outlined.TouchApp
6868
import androidx.compose.material.icons.outlined.VerticalSplit
6969
import androidx.compose.material.icons.outlined.ViewArray
70+
import androidx.compose.material.icons.outlined.WifiTethering
71+
import androidx.compose.material.icons.outlined.WifiTetheringOff
7072
import androidx.compose.material.icons.rounded.Abc
7173
import androidx.compose.material.icons.rounded.Android
7274
import androidx.compose.material.icons.rounded.Bluetooth
@@ -143,6 +145,10 @@ object ActionUtils {
143145
ActionId.ENABLE_MOBILE_DATA -> ActionCategory.CONNECTIVITY
144146
ActionId.DISABLE_MOBILE_DATA -> ActionCategory.CONNECTIVITY
145147

148+
ActionId.TOGGLE_HOTSPOT -> ActionCategory.CONNECTIVITY
149+
ActionId.ENABLE_HOTSPOT -> ActionCategory.CONNECTIVITY
150+
ActionId.DISABLE_HOTSPOT -> ActionCategory.CONNECTIVITY
151+
146152
ActionId.TOGGLE_AUTO_BRIGHTNESS -> ActionCategory.DISPLAY
147153
ActionId.DISABLE_AUTO_BRIGHTNESS -> ActionCategory.DISPLAY
148154
ActionId.ENABLE_AUTO_BRIGHTNESS -> ActionCategory.DISPLAY
@@ -388,6 +394,9 @@ object ActionUtils {
388394
ActionId.CLEAR_RECENT_APP -> R.string.action_clear_recent_app
389395

390396
ActionId.MODIFY_SETTING -> R.string.action_modify_setting
397+
ActionId.TOGGLE_HOTSPOT -> R.string.action_toggle_hotspot
398+
ActionId.ENABLE_HOTSPOT -> R.string.action_enable_hotspot
399+
ActionId.DISABLE_HOTSPOT -> R.string.action_disable_hotspot
391400
}
392401

393402
@DrawableRes
@@ -555,6 +564,13 @@ object ActionUtils {
555564
ActionId.SHOW_POWER_MENU -> Build.VERSION_CODES.LOLLIPOP
556565
ActionId.DEVICE_CONTROLS -> Build.VERSION_CODES.S
557566

567+
// It could be supported on older versions but system bridge min API is Q and its extra
568+
// maintenance effort to support the older tethering system API.
569+
ActionId.TOGGLE_HOTSPOT,
570+
ActionId.ENABLE_HOTSPOT,
571+
ActionId.DISABLE_HOTSPOT,
572+
-> Build.VERSION_CODES.R
573+
558574
else -> Constants.MIN_API
559575
}
560576

@@ -620,6 +636,11 @@ object ActionUtils {
620636
ActionId.DISABLE_MOBILE_DATA,
621637
-> true
622638

639+
ActionId.TOGGLE_HOTSPOT,
640+
ActionId.ENABLE_HOTSPOT,
641+
ActionId.DISABLE_HOTSPOT,
642+
-> true
643+
623644
ActionId.ENABLE_NFC,
624645
ActionId.DISABLE_NFC,
625646
ActionId.TOGGLE_NFC,
@@ -904,6 +925,9 @@ object ActionUtils {
904925
ActionId.CLEAR_RECENT_APP -> Icons.Outlined.VerticalSplit
905926

906927
ActionId.MODIFY_SETTING -> Icons.Outlined.Settings
928+
ActionId.TOGGLE_HOTSPOT -> Icons.Outlined.WifiTethering
929+
ActionId.ENABLE_HOTSPOT -> Icons.Outlined.WifiTethering
930+
ActionId.DISABLE_HOTSPOT -> Icons.Outlined.WifiTetheringOff
907931
}
908932
}
909933

base/src/main/java/io/github/sds100/keymapper/base/actions/CreateActionDelegate.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,10 @@ class CreateActionDelegate(
975975
ActionId.ENABLE_MOBILE_DATA -> return ActionData.MobileData.Enable
976976
ActionId.DISABLE_MOBILE_DATA -> return ActionData.MobileData.Disable
977977

978+
ActionId.TOGGLE_HOTSPOT -> return ActionData.Hotspot.Toggle
979+
ActionId.ENABLE_HOTSPOT -> return ActionData.Hotspot.Enable
980+
ActionId.DISABLE_HOTSPOT -> return ActionData.Hotspot.Disable
981+
978982
ActionId.TOGGLE_AUTO_BRIGHTNESS -> return ActionData.Brightness.ToggleAuto
979983
ActionId.DISABLE_AUTO_BRIGHTNESS -> return ActionData.Brightness.DisableAuto
980984
ActionId.ENABLE_AUTO_BRIGHTNESS -> return ActionData.Brightness.EnableAuto

base/src/main/java/io/github/sds100/keymapper/base/actions/PerformActionsUseCase.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,28 @@ class PerformActionsUseCaseImpl @AssistedInject constructor(
483483
result = networkAdapter.disableMobileData()
484484
}
485485

486+
is ActionData.Hotspot.Toggle -> {
487+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
488+
result = networkAdapter.isHotspotEnabled().then { isEnabled ->
489+
if (isEnabled) {
490+
networkAdapter.disableHotspot()
491+
} else {
492+
networkAdapter.enableHotspot()
493+
}
494+
}
495+
} else {
496+
result = SdkVersionTooLow(minSdk = Build.VERSION_CODES.R)
497+
}
498+
}
499+
500+
is ActionData.Hotspot.Enable -> {
501+
result = networkAdapter.enableHotspot()
502+
}
503+
504+
is ActionData.Hotspot.Disable -> {
505+
result = networkAdapter.disableHotspot()
506+
}
507+
486508
is ActionData.Brightness.ToggleAuto -> {
487509
result = if (displayAdapter.isAutoBrightnessEnabled()) {
488510
displayAdapter.disableAutoBrightness()

0 commit comments

Comments
 (0)