[Google Pixel 4 XL Themes, Apps, and Mods] animorum:
Night Light display red-only tweak

Using only the red channel for displays, such as done with CF.lumen, is important for when you want to preserve night vision (e.g., stargazing), or you want to minimize the effect of screen use on your sleep patterns. If CF.lumen ever does not work with your system, this would be an alternative approach to consider.

The below method tweaks one parameter to make Android’s built-in Night Light display use only the red channel. This use of Night Light should be combined with the also built-in Bedtime mode’s Grayscale setting to preserve display contrast.

Here are sample images with Night Light off, set to a bit more intense than normally possible, and red-only:

View attachment 5248391 View attachment 5248393 View attachment 5248395

Night Light runs based on parameters stored in /system/framework/framework-res.apk. The runtime resource overlay (RRO) approach allows such parameters to be replaced at runtime by packages in locations such as /vendor/overlay/ and /product/overlay/. Placing an APK in one of these directories that sets the config_nightDisplayColorTemperatureMin resource sufficiently low allows Night Light to use only the red channel.

Note: If you do not use Grayscale with this modified Night Light, considerable contrast will be lost in some situations, such as white text on a red background.

These instructions are written for rooted Pixel 4 XL devices running Android 10 or 11, but a similar approach should work with other Android devices.

Create a folder on your computer that you will use to build a minimal APK, with a name referred to as [APK-name] below.

Within this folder, create the following subfolders and file:

The integers.xml file should have the following contents:

<?xml version="1.0" encoding="utf-8"?><resources>
<integer name="config_nightDisplayColorTemperatureMin">0</integer>
</resources>

Note: 0 is sufficiently low to remove blue and green channels for Pixel 4 XL devices, but other devices may require negative values.

Add a manifest file to the [APK-name] folder. This will be labeled “AndroidManifest.xml” and have contents similar to the following:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.RedNightLight">
<application android:hasCode="false"/>
<overlay android:isStatic="true" android:priority="2" android:targetPackage="android"/>
</manifest>

Modify the package and priority values as appropriate. The priority value sets precedence relationships with any other RROs that target package “android”. Higher values assign higher precedence.

Build the minimal APK. If using Android SDK Build Tools, copy with the [APK-name] folder and the framework-res.apk file from your device to the SDK folder. The original framework-res.apk file should be located in the device’s /system/framework/ folder. Ensure a /compiled/ folder exists in your SDK folder, or adjust the specified paths as desired. Enter the following commands within the SDK folder:

The new APK is not signed, but does not need to be for this approach.

Pick an existing RRO APK on your device that is not critical for your use. Ensure your new APK’s filename matches that of this existing non-critical APK; it will replace that APK on your device. On the Pixel 4 XL, the AccentColorOrchidOverlay.apk file on the product partition can be a good choice, as it only changes how the orchid color is displayed. The existing overlay for AccentColorOrchid would be removed in this process, and only the default value for orchid would be used by the system.

Copy your new APK to your device such that the target file is overwritten. If you are using Magisk, create a module with the APK inserted into the appropriate file structure. Using the example of AccentColorOrchidOverlay.apk:

Include a properly formatted module.prop file in the [module-name] folder. Place the module in the location expected by Magisk (/data/adb/modules/).

Reboot the device. Afterward, you should be able to set Night Light to maximum intensity and it will only use the red color channel.

(Optional) Rename the APK file in your Magisk module to a unique name, so that it no longer overwrites an existing APK, and reboot your device. The Android system might now permit both the originally-existing APK and the new APK to affect the system.

Alternatively, one can also decompile and rebuild an existing RRO APK that targets “android”, adding the same resource as above to integers.xml. Care should be taken, however, to make sure the APK is rebuilt precisely, particularly if the APK affects many resources, such as framework-res__auto_generated_rro_vendor.apk found under /vendor/overlay/. The device’s system can easily become unstable (e.g., boot loops, consistent app crashes) if your process or software, such as Apktool, is not up to date with your current version of Android.

In the event your new Magisk module prevents successfully booting into the system, this guide is helpful for recovering: https://www.thecustomdroid.com/uninstall-magisk-modules-in-twrp-recovery-guide/

The example Magisk module described above is uploaded here and can be used if your device has the target AccentColorOrchid overlay as part of its product partition.