Skip to content

Commit e1970e3

Browse files
committed
#1996 fix: check if Night Shift is supported on a device before activating to prevent the screen going black when activated
1 parent 9cc046c commit e1970e3

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
- #2007 Volume up/down action bottom sheet is cut off on some devices.
77
- #2004 Do not crash when launching wireless debugging screen on some devices.
88
- #2005 NPE in onSaveInstanceState.
9-
- #2000 tell the user to tap OS version or build number
9+
- #2000 tell the user to tap OS version or build number.
10+
- #1996 Check if Night Shift is supported on a device before activating to prevent the screen going black when activated.
1011

1112
## [4.0.0](https://github.com/sds100/KeyMapper/releases/tag/v4.0.0)
1213

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.sds100.keymapper.base.actions
22

33
import android.content.pm.PackageManager
4+
import android.content.res.Resources
45
import android.os.Build
56
import io.github.sds100.keymapper.common.utils.KMError
67
import io.github.sds100.keymapper.system.SystemError
@@ -56,6 +57,18 @@ class IsActionSupportedUseCaseImpl(
5657
}
5758
}
5859

60+
if (id == ActionId.TOGGLE_NIGHT_SHIFT ||
61+
id == ActionId.ENABLE_NIGHT_SHIFT ||
62+
id == ActionId.DISABLE_NIGHT_SHIFT
63+
) {
64+
// See https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/base/core/java/android/hardware/display/ColorDisplayManager.java;l=498;drc=787314ed22d859e510163327dd6c58b215c2f7f9
65+
val res = Resources.getSystem()
66+
val resId = res.getIdentifier("config_nightDisplayAvailable", "bool", "android")
67+
if (resId == 0 || !res.getBoolean(resId)) {
68+
return KMError.NightDisplayNotSupported
69+
}
70+
}
71+
5972
if (ActionUtils.getRequiredPermissions(id).contains(Permission.ROOT) &&
6073
!permissionAdapter.isGranted(Permission.ROOT)
6174
) {

base/src/main/java/io/github/sds100/keymapper/base/utils/ErrorUtils.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ fun KMError.getFullMessage(resourceProvider: ResourceProvider): String {
362362
R.string.error_variable_flashlight_strength_unsupported,
363363
)
364364

365+
KMError.NightDisplayNotSupported ->
366+
resourceProvider.getString(R.string.error_night_display_not_supported)
367+
365368
is KMError.FailedToModifySystemSetting ->
366369
resourceProvider.getString(
367370
R.string.error_failed_to_modify_system_setting,

base/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@
817817
<string name="error_front_flash_not_found">No front flash</string>
818818
<string name="error_back_flash_not_found">No back flash</string>
819819
<string name="error_variable_flashlight_strength_unsupported">Variable flashlight strength unsupported</string>
820+
<string name="error_night_display_not_supported">Your device doesn\'t support night display.</string>
820821

821822
<string name="error_accessibility_service_disabled">Accessibility service needs to be enabled!</string>
822823
<string name="error_accessibility_service_crashed">The accessibility service needs to be restarted!</string>

common/src/main/java/io/github/sds100/keymapper/common/utils/KMResult.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ abstract class KMError : KMResult<Nothing>() {
5353
data object MaxCamerasInUse : KMError()
5454
data object CameraError : KMError()
5555
data object CameraVariableFlashlightStrengthUnsupported : KMError()
56+
data object NightDisplayNotSupported : KMError()
5657

5758
data class FailedToModifySystemSetting(val setting: String) : KMError()
5859
data object SwitchImeFailed : KMError()

0 commit comments

Comments
 (0)