Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import org.koreader.launcher.device.LightsInterface
* Sends action_set_color_temperature (0-100 scale); the service rescales to 0-10 for
* the lm3630a_led hardware and calls PowerManager.setFrontlightBrightnessColor() using
* its own DEVICE_POWER privilege.
* The service also re-applies warmth on every SCREEN_ON, forcing it to cold unless its
* CTM mode is manual, so we assert that mode before the first warmth write.
* see https://github.com/koreader/koreader/issues/14574
*/
class NookGL4plusController : LightsInterface {
Expand All @@ -27,9 +29,13 @@ class NookGL4plusController : LightsInterface {
private const val GLOWLIGHT_SERVICE = "com.nook.partner.service.GlowLightService"
private const val ACTION_SET_COLOR_TEMPERATURE = "action_set_color_temperature"
private const val EXTRA_COLOR_TEMPERATURE = "extra_color_temperature"
private const val ACTION_SET_CTM_MODE = "action_set_ctm_mode"
private const val EXTRA_CTM_MODE = "extra_ctm_mode"
private const val CTM_MODE_MANUAL = 0
}

@Volatile private var currentWarmth: Int = MIN
@Volatile private var ctmModeAsserted: Boolean = false

override fun getPlatform(): String = "nook"
override fun hasFallback(): Boolean = false
Expand Down Expand Up @@ -76,11 +82,33 @@ class NookGL4plusController : LightsInterface {
Log.w(TAG, "warmth value out of range: $warmth")
return
}
if (warmth == getWarmth(activity)) return
// Never skip the first write: it seeds the value the service re-applies.
if (ctmModeAsserted && warmth == getWarmth(activity)) return
Log.v(TAG, "Setting warmth to $warmth of $WARMTH_MAX")
assertManualCtmMode(activity)
setWarmthViaService(activity, warmth)
}

/* GlowLightService is an IntentService, so this is handled before the warmth intent
* that follows it. */
private fun assertManualCtmMode(activity: Activity) {
if (ctmModeAsserted) return
try {
val intent = Intent(ACTION_SET_CTM_MODE).apply {
component = ComponentName(GLOWLIGHT_PACKAGE, GLOWLIGHT_SERVICE)
putExtra(EXTRA_CTM_MODE, CTM_MODE_MANUAL)
}
if (activity.startService(intent) != null) {
ctmModeAsserted = true
Log.v(TAG, "CTM mode set to manual")
} else {
Log.w(TAG, "GlowLightService unavailable, cannot set CTM mode")
}
} catch (e: Exception) {
Log.w(TAG, "setting CTM mode failed: $e")
}
}

private fun setWarmthViaService(activity: Activity, warmth: Int): Boolean {
return try {
val intent = Intent(ACTION_SET_COLOR_TEMPERATURE).apply {
Expand Down
Loading