[Samsung Galaxy J5 Guides, News, & Discussion] prototype74:
How to enable Night light on Samsung Experience 9.0 (Android 8.0.0) Oreo ROMs

Good news to oreo users: enabling Night Light on oreo is much easier than on nougat because most of the steps in the guide above aren't necessary in Oreo as Samsung kept Night Light feature in their TW Oreo ROMs. We just have to enable it framework-res.apk and add our Night Light setting to display settings. :)

Part 1 - framework-res.apk

Decompile framework-res.apk and go to framework-res.apk/res/values/bools.xml.

Search for config_setColorTransformAccelerated and change it's boolean from false to true:

<bool name="config_setColorTransformAccelerated">true</bool>

Not necessary to edit config_nightDisplayAvailable like on Nougat as it expects the same boolean value

from config_setColorTransformAccelerated:

<item type="bool" name="config_nightDisplayAvailable">@bool/config_setColorTransformAccelerated</item>

Recompile framework-res.apk

Part 2 - SecSettings.apk

Now we're adding our new Night Light setting to display settings. This setting allow us to enable/disable night light (see nougat guide)

and

enter the night light settings (similar like Blue light filter).

2.1 Decompile SecSettings.apk and go to SecSettings.apk/smali/com/samsung/android/settings/display/SecDisplaySettings.smali.

We have to implement a new interface. Add blue line:

# interfaces
[COLOR="Blue"].implements Lcom/android/internal/app/NightDisplayController$Callback;[/COLOR]
.implements Landroid/support/v7/preference/Preference$OnPreferenceChangeListener;
.implements Lcom/android/settings/search/Indexable;

Now we need 2 new variables to set our setting and calling it later in our methods. Add these variables to #instance fields:

#instance fields
...

[COLOR="blue"].field private mController:Lcom/android/internal/app/NightDisplayController;

.field private mNightDisplayPreference:Lcom/android/settings/SecSettingsSwitchPreference;[/COLOR]

...

So, now we have to add

5 new methods

in SecDisplaySettings.smali. These methods work together to enable and disable Night light:

[COLOR="Blue"].method public onActivatedNightDisplay(Z)V
.locals 1

iget-object v0, p0, Lcom/samsung/android/settings/display/SecDisplaySettings;->mNightDisplayPreference:Lcom/android/settings/SecSettingsSwitchPreference;

invoke-virtual {v0, p1}, Lcom/android/settings/SecSettingsSwitchPreference;->setChecked(Z)V

return-void
.end method

.method public onCreateNightDisplay(Landroid/os/Bundle;)V
.locals 2

invoke-virtual {p0}, Lcom/samsung/android/settings/display/SecDisplaySettings;->getContext()Landroid/content/Context;

move-result-object v0

new-instance v1, Lcom/android/internal/app/NightDisplayController;

invoke-direct {v1, v0}, Lcom/android/internal/app/NightDisplayController;-><init>(Landroid/content/Context;)V

iput-object v1, p0, Lcom/samsung/android/settings/display/SecDisplaySettings;->mController:Lcom/android/internal/app/NightDisplayController;

return-void
.end method

.method public onStartNightDisplay()V
.locals 1

iget-object v0, p0, Lcom/samsung/android/settings/display/SecDisplaySettings;->mController:Lcom/android/internal/app/NightDisplayController;

invoke-virtual {v0, p0}, Lcom/android/internal/app/NightDisplayController;->setListener(Lcom/android/internal/app/NightDisplayController$Callback;)V

iget-object v0, p0, Lcom/samsung/android/settings/display/SecDisplaySettings;->mController:Lcom/android/internal/app/NightDisplayController;

invoke-virtual {v0}, Lcom/android/internal/app/NightDisplayController;->isActivated()Z

move-result v0

invoke-virtual {p0, v0}, Lcom/samsung/android/settings/display/SecDisplaySettings;->onActivatedNightDisplay(Z)V

return-void
.end method

.method public onStopNightDisplay()V
.locals 2

iget-object v0, p0, Lcom/samsung/android/settings/display/SecDisplaySettings;->mController:Lcom/android/internal/app/NightDisplayController;

const/4 v1, 0x0

invoke-virtual {v0, v1}, Lcom/android/internal/app/NightDisplayController;->setListener(Lcom/android/internal/app/NightDisplayController$Callback;)V

return-void
.end method

.method public onPreferenceNightDisplayChange(Landroid/support/v7/preference/Preference;Ljava/lang/Object;)V
.locals 3

iget-object v0, p0, Lcom/samsung/android/settings/display/SecDisplaySettings;->mNightDisplayPreference:Lcom/android/settings/SecSettingsSwitchPreference;

if-ne p1, v0, :cond_0

invoke-virtual {p0}, Lcom/samsung/android/settings/display/SecDisplaySettings;->getContentResolver()Landroid/content/ContentResolver;

move-result-object v1

const-string v2, "night_display_activated"

check-cast p2, Ljava/lang/Boolean;

invoke-virtual {p2}, Ljava/lang/Boolean;->booleanValue()Z

move-result v0

if-eqz v0, :cond_1

const/4 v0, 0x1

:goto_0
invoke-static {v1, v2, v0}, Landroid/provider/Settings$Secure;->putInt(Landroid/content/ContentResolver;Ljava/lang/String;I)Z

:cond_0
return-void

:cond_1
const/4 v0, 0x0

goto :goto_0
.end method[/COLOR]

Now we have added these methods but none call them. In order to make them working we have to call them in already existing methods in SecDisplaySettings.smali

Search for

[B].method public onCreate(Landroid/os/Bundle;)V[/B]

and add blue line:

.method public onCreate(Landroid/os/Bundle;)V
.locals 29

invoke-super/range {p0 .. p1}, Lcom/android/settings/SettingsPreferenceFragment;->onCreate(Landroid/os/Bundle;)V

[COLOR="Blue"]invoke-virtual/range {p0 .. p1}, Lcom/samsung/android/settings/display/SecDisplaySettings;->onCreateNightDisplay(Landroid/os/Bundle;)V[/COLOR]

....

in same method scroll down until you reached end of method (.end method)

It should look something like this:

...

:cond_50
const-string/jumbo v25, "screen_timeout_for_dex"

move-object/from16 v0, p0

move-object/from16 v1, v25

invoke-virtual {v0, v1}, Lcom/samsung/android/settings/display/SecDisplaySettings;->removePreference(Ljava/lang/String;)V

goto/16 :goto_22

[COLOR="Red"]:cond_51[/COLOR]
const-string/jumbo v25, "double_tab_to_wake_up"

move-object/from16 v0, p0

move-object/from16 v1, v25

invoke-virtual {v0, v1}, Lcom/samsung/android/settings/display/SecDisplaySettings;->removePreference(Ljava/lang/String;)V

goto/16 :goto_23
.end method

Replace :cond_51 with blue lines:

...

:cond_50
const-string/jumbo v25, "screen_timeout_for_dex"

move-object/from16 v0, p0

move-object/from16 v1, v25

invoke-virtual {v0, v1}, Lcom/samsung/android/settings/display/SecDisplaySettings;->removePreference(Ljava/lang/String;)V

goto/16 :goto_22

[COLOR="Blue"] :cond_51
const-string/jumbo v25, "night_display_activated"

move-object/from16 v0, p0

move-object/from16 v1, v25

invoke-virtual {v0, v1}, Lcom/samsung/android/settings/display/SecDisplaySettings;->findPreference(Ljava/lang/CharSequence;)Landroid/support/v7/preference/Preference;

move-result-object v25

check-cast v25, Lcom/android/settings/SecSettingsSwitchPreference;

move-object/from16 v0, v25

move-object/from16 v1, p0

iput-object v0, v1, Lcom/samsung/android/settings/display/SecDisplaySettings;->mNightDisplayPreference:Lcom/android/settings/SecSettingsSwitchPreference;

move-object/from16 v0, p0

iget-object v0, v0, Lcom/samsung/android/settings/display/SecDisplaySettings;->mNightDisplayPreference:Lcom/android/settings/SecSettingsSwitchPreference;

move-object/from16 v25, v0

if-eqz v25, :cond_52

move-object/from16 v0, p0

iget-object v0, v0, Lcom/samsung/android/settings/display/SecDisplaySettings;->mNightDisplayPreference:Lcom/android/settings/SecSettingsSwitchPreference;

move-object/from16 v25, v0

move-object/from16 v0, v25

move-object/from16 v1, p0

invoke-virtual {v0, v1}, Lcom/android/settings/SecSettingsSwitchPreference;->setOnPreferenceChangeListener(Landroid/support/v7/preference/Preference$OnPreferenceChangeListener;)V

invoke-virtual {v1}, Lcom/samsung/android/settings/display/SecDisplaySettings;->onStartNightDisplay()V

:cond_52[/COLOR]
const-string/jumbo v25, "double_tab_to_wake_up"

move-object/from16 v0, p0

move-object/from16 v1, v25

invoke-virtual {v0, v1}, Lcom/samsung/android/settings/display/SecDisplaySettings;->removePreference(Ljava/lang/String;)V

goto/16 :goto_23
.end method

Search for

.method public onPause()V

and add blue line:

.method public onPause()V
.locals 2

invoke-super {p0}, Lcom/android/settings/SettingsPreferenceFragment;->onPause()V

[COLOR="Blue"]invoke-virtual {p0}, Lcom/samsung/android/settings/display/SecDisplaySettings;->onStopNightDisplay()V[/COLOR]

...
.end method

At last, search for

[B].method public onPreferenceChange(Landroid/support/v7/preference/Preference;Ljava/lang/Object;)Z[/B]

and add blue line:

.method public onPreferenceChange(Landroid/support/v7/preference/Preference;Ljava/lang/Object;)Z
.locals 38

[COLOR="Blue"]invoke-virtual/range {p0 .. p2}, Lcom/samsung/android/settings/display/SecDisplaySettings;->onPreferenceNightDisplayChange(Landroid/support/v7/preference/Preference;Ljava/lang/Object;)V[/COLOR]

invoke-virtual/range {p1 .. p1}, Landroid/support/v7/preference/Preference;->getKey()Ljava/lang/String;

move-result-object v22

....
.end method

We're done with SecDisplaySettings.smali

2.2 We need to call onPreferenceNightDisplayChange in an another smali too. Go to SecSettings.apk/smali/com/samsung/android/settings/display/SecDisplaySettings$19.smali

Search for

invoke-virtual {v0, v1, v14}, Lcom/samsung/android/settings/display/SecDisplaySettings;->onPreferenceChange(Landroid/support/v7/preference/Preference;Ljava/lang/Object;)Z

And add blue line:

...

move-object/from16 v1, v23

invoke-virtual {v0, v1, v14}, Lcom/samsung/android/settings/display/SecDisplaySettings;->onPreferenceChange(Landroid/support/v7/preference/Preference;Ljava/lang/Object;)Z

[COLOR="Blue"] invoke-virtual {v0, v1, v14}, Lcom/samsung/android/settings/display/SecDisplaySettings;->onPreferenceNightDisplayChange(Landroid/support/v7/preference/Preference;Ljava/lang/Object;)V[/COLOR]

move-object/from16 v0, p0

iget-object v0, v0, Lcom/samsung/android/settings/display/SecDisplaySettings$19;->this$0:Lcom/samsung/android/settings/display/SecDisplaySettings;

...

2.3 Now we'll add our new switch preference setting to display settings. Go to SecSettings.apk/res/xml/sec_display_settings.xml and add blue line:

...
<com.samsung.android.settings.display.BrightnessSeekBarPreference android:icon="@drawable/st_ic_display_brightness" android:persistent="false" android:title="@string/brightness_title" android:key="secbrightness" settings:SettingsMode="UPSM" settings:dbMatchingName="screen_brightness;screen_brightness_mode;auto_brightness_detail" settings:dbMatchingTable="system" />
<com.android.settings.SecSettingsSwitchPreference android:title="@string/auto_adjust_brightness" android:key="auto_brightness" android:summary="@string/auto_adjust_brightness_summary" android:fragment="com.samsung.android.settings.display.AutoBrightness" />
<com.samsung.android.settings.display.AutoBrightnessNoPacPreference android:title="@string/auto_adjust_brightness" android:key="auto_brightness_no_pac" android:summary="@string/auto_adjust_brightness_summary_nopac" />
<SecSwitchPreference android:title="@string/outdoor_mode_title" android:key="outdoor_mode" android:summary="@string/outdoor_mode_summary" />
<com.samsung.android.settings.display.DisplayDisabledAppearanceSwitchPreference android:title="@string/blue_light_filter_title" android:key="blue_light_filter" android:summary="@string/blue_light_filter_summary_off" />
[COLOR="Blue"]<com.android.settings.SecSettingsSwitchPreference android:title="@string/night_display_title" android:key="night_display_activated" android:summary="@string/night_display_text" android:fragment="com.android.settings.display.NightDisplaySettings" />[/COLOR]
<SecPreferenceScreen android:title="@string/screen_zoom_and_font" android:key="font_preview" android:summary="@string/screen_zoom_and_font_summary" />
<SecPreferenceScreen android:title="@string/wallpaper" android:key="wallpaper">
<intent android:targetPackage="com.sec.android.app.wallpaperchooser" android:action="android.intent.action.MAIN" android:targetClass="com.sec.android.app.wallpaperchooser.WallpaperPickerActivity" />
</SecPreferenceScreen>
...

Recompile SecSettings.apk

Part 3 - Add Night light tile to quick settings (OPTIONAL)

Please follow Part 3 from Post #1 above

Enjoy Night Light on Oreo!