diff --git a/DisplayMode/Android.bp b/DisplayMode/Android.bp
new file mode 100644
index 000000000..e11847a0f
--- /dev/null
+++ b/DisplayMode/Android.bp
@@ -0,0 +1,41 @@
+//
+// Copyright (C) 2013 The CyanogenMod Project
+// Copyright (C) 2017 The LineageOS Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+android_app {
+ name: "DisplayMode",
+
+ defaults: [
+ "SettingsLibDefaults",
+ ],
+
+ srcs: ["src/**/*.java"],
+ certificate: "platform",
+ platform_apis: true,
+ system_ext_specific: true,
+ privileged: true,
+
+ static_libs: [
+ "androidx.core_core",
+ "androidx.preference_preference",
+ ],
+
+ resource_dirs: ["res"],
+
+ optimize: {
+ proguard_flags_files: ["proguard.flags"],
+ },
+
+}
diff --git a/DisplayMode/AndroidManifest.xml b/DisplayMode/AndroidManifest.xml
new file mode 100644
index 000000000..3401b85d0
--- /dev/null
+++ b/DisplayMode/AndroidManifest.xml
@@ -0,0 +1,95 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DisplayMode/proguard.flags b/DisplayMode/proguard.flags
new file mode 100644
index 000000000..c06359e81
--- /dev/null
+++ b/DisplayMode/proguard.flags
@@ -0,0 +1,3 @@
+-keep class co.aospa.settings.DisplayMode.* {
+ *;
+}
diff --git a/DisplayMode/res/drawable-nodpi/color_mode_preview1.jpg b/DisplayMode/res/drawable-nodpi/color_mode_preview1.jpg
new file mode 100644
index 000000000..71bcb7e59
Binary files /dev/null and b/DisplayMode/res/drawable-nodpi/color_mode_preview1.jpg differ
diff --git a/DisplayMode/res/drawable-nodpi/color_mode_preview2.jpg b/DisplayMode/res/drawable-nodpi/color_mode_preview2.jpg
new file mode 100644
index 000000000..4153d8e75
Binary files /dev/null and b/DisplayMode/res/drawable-nodpi/color_mode_preview2.jpg differ
diff --git a/DisplayMode/res/drawable-nodpi/color_mode_preview3.jpg b/DisplayMode/res/drawable-nodpi/color_mode_preview3.jpg
new file mode 100644
index 000000000..ab83f08c9
Binary files /dev/null and b/DisplayMode/res/drawable-nodpi/color_mode_preview3.jpg differ
diff --git a/DisplayMode/res/drawable/ic_color_arrow_left_lt.xml b/DisplayMode/res/drawable/ic_color_arrow_left_lt.xml
new file mode 100644
index 000000000..237a1a3a9
--- /dev/null
+++ b/DisplayMode/res/drawable/ic_color_arrow_left_lt.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
diff --git a/DisplayMode/res/drawable/ic_color_arrow_right_lt.xml b/DisplayMode/res/drawable/ic_color_arrow_right_lt.xml
new file mode 100644
index 000000000..510724386
--- /dev/null
+++ b/DisplayMode/res/drawable/ic_color_arrow_right_lt.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
diff --git a/DisplayMode/res/drawable/ic_color_page_indicator_focused.xml b/DisplayMode/res/drawable/ic_color_page_indicator_focused.xml
new file mode 100644
index 000000000..617335803
--- /dev/null
+++ b/DisplayMode/res/drawable/ic_color_page_indicator_focused.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
diff --git a/DisplayMode/res/drawable/ic_color_page_indicator_unfocused.xml b/DisplayMode/res/drawable/ic_color_page_indicator_unfocused.xml
new file mode 100644
index 000000000..57a13d822
--- /dev/null
+++ b/DisplayMode/res/drawable/ic_color_page_indicator_unfocused.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
diff --git a/DisplayMode/res/drawable/ic_hbm_tile.xml b/DisplayMode/res/drawable/ic_hbm_tile.xml
new file mode 100644
index 000000000..95cf54615
--- /dev/null
+++ b/DisplayMode/res/drawable/ic_hbm_tile.xml
@@ -0,0 +1,7 @@
+
+
+
diff --git a/DisplayMode/res/drawable/ic_info_outline_24dp.xml b/DisplayMode/res/drawable/ic_info_outline_24dp.xml
new file mode 100644
index 000000000..3fe1e9e5c
--- /dev/null
+++ b/DisplayMode/res/drawable/ic_info_outline_24dp.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
diff --git a/DisplayMode/res/drawable/ic_panel_tile.xml b/DisplayMode/res/drawable/ic_panel_tile.xml
new file mode 100644
index 000000000..ee0137ff2
--- /dev/null
+++ b/DisplayMode/res/drawable/ic_panel_tile.xml
@@ -0,0 +1,7 @@
+
+
+
diff --git a/DisplayMode/res/layout/color_mode_view1.xml b/DisplayMode/res/layout/color_mode_view1.xml
new file mode 100644
index 000000000..4bdaec1da
--- /dev/null
+++ b/DisplayMode/res/layout/color_mode_view1.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DisplayMode/res/layout/color_mode_view2.xml b/DisplayMode/res/layout/color_mode_view2.xml
new file mode 100644
index 000000000..c70fa75c4
--- /dev/null
+++ b/DisplayMode/res/layout/color_mode_view2.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DisplayMode/res/layout/color_mode_view3.xml b/DisplayMode/res/layout/color_mode_view3.xml
new file mode 100644
index 000000000..430e3b2fe
--- /dev/null
+++ b/DisplayMode/res/layout/color_mode_view3.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DisplayMode/res/layout/image_layout.xml b/DisplayMode/res/layout/image_layout.xml
new file mode 100644
index 000000000..6a3e40919
--- /dev/null
+++ b/DisplayMode/res/layout/image_layout.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
diff --git a/DisplayMode/res/layout/panel_modes.xml b/DisplayMode/res/layout/panel_modes.xml
new file mode 100644
index 000000000..12378d752
--- /dev/null
+++ b/DisplayMode/res/layout/panel_modes.xml
@@ -0,0 +1,156 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DisplayMode/res/values/dimens.xml b/DisplayMode/res/values/dimens.xml
new file mode 100644
index 000000000..e7e99f4fd
--- /dev/null
+++ b/DisplayMode/res/values/dimens.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ 320dp
+
diff --git a/DisplayMode/res/values/pa_strings.xml b/DisplayMode/res/values/pa_strings.xml
new file mode 100644
index 000000000..648642cc9
--- /dev/null
+++ b/DisplayMode/res/values/pa_strings.xml
@@ -0,0 +1,31 @@
+
+
+
+ Display modes
+ Adjust settings and preferences for display
+
+ sRGB
+
+ High brightness mode
+ AMOLED Wide Gamut
+
+ DCI-P3
+ Natural
+ Vivid
+ Panel modes
+ Modes for panel color correction
+ Off
+ Panel modes
+ High brightness modes
+ Disabling panel mode requires a reboot
+
diff --git a/DisplayMode/res/xml/main.xml b/DisplayMode/res/xml/main.xml
new file mode 100644
index 000000000..d6794cd7e
--- /dev/null
+++ b/DisplayMode/res/xml/main.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/DeviceSettings.java b/DisplayMode/src/co/aospa/settings/DisplayMode/DeviceSettings.java
new file mode 100644
index 000000000..5bb6aa7ce
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/DeviceSettings.java
@@ -0,0 +1,87 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.provider.Settings;
+import android.view.MenuItem;
+import android.view.View;
+
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceFragment;
+import androidx.preference.SwitchPreference;
+import androidx.preference.TwoStatePreference;
+
+import co.aospa.settings.DisplayMode.ModeSwitch.HBMModeSwitch;
+
+public class DeviceSettings extends PreferenceFragment
+ implements Preference.OnPreferenceChangeListener {
+
+ private static final String KEY_CATEGORY_GRAPHICS = "graphics";
+ public static final String KEY_SRGB_SWITCH = "srgb";
+ public static final String KEY_HBM_SWITCH = "hbm";
+ public static final String KEY_DCI_SWITCH = "dci";
+ public static final String KEY_WIDECOLOR_SWITCH = "widecolor";
+ public static final String KEY_NATURAL_SWITCH = "natural";
+ public static final String KEY_VIVID_SWITCH = "vivid";
+
+ private TwoStatePreference mHBMModeSwitch;
+
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ addPreferencesFromResource(R.xml.main);
+ getActivity().getActionBar().setDisplayHomeAsUpEnabled(true);
+
+ mHBMModeSwitch = findPreference(KEY_HBM_SWITCH);
+ mHBMModeSwitch.setEnabled(HBMModeSwitch.isSupported());
+ mHBMModeSwitch.setChecked(HBMModeSwitch.isCurrentlyEnabled());
+ mHBMModeSwitch.setOnPreferenceChangeListener(this);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ mHBMModeSwitch.setChecked(HBMModeSwitch.isCurrentlyEnabled());
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ if (preference == mHBMModeSwitch) {
+ Boolean enabled = (Boolean) newValue;
+ Utils.writeValue(HBMModeSwitch.getFile(), enabled ? "5" : "0");
+ Intent hbmIntent = new Intent(this.getContext(),
+ co.aospa.settings.DisplayMode.HBMModeService.class);
+ if (enabled) {
+ this.getContext().startService(hbmIntent);
+ } else {
+ this.getContext().stopService(hbmIntent);
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(Preference preference) {
+ return super.onPreferenceTreeClick(preference);
+ }
+
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/DeviceSettingsActivity.java b/DisplayMode/src/co/aospa/settings/DisplayMode/DeviceSettingsActivity.java
new file mode 100644
index 000000000..821bb7858
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/DeviceSettingsActivity.java
@@ -0,0 +1,35 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import android.os.Bundle;
+
+import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity;
+import com.android.settingslib.collapsingtoolbar.R;
+
+public class DeviceSettingsActivity extends CollapsingToolbarBaseActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ getFragmentManager().beginTransaction()
+ .add(R.id.content_frame, new DeviceSettings())
+ .commit();
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeService.java b/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeService.java
new file mode 100644
index 000000000..120f0a7fd
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeService.java
@@ -0,0 +1,57 @@
+/*
+* Copyright (C) 2020 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.IBinder;
+
+import co.aospa.settings.DisplayMode.ModeSwitch.HBMModeSwitch;
+
+public class HBMModeService extends Service {
+
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (action.equals(Intent.ACTION_SCREEN_OFF)) {
+ Utils.writeValue(HBMModeSwitch.getFile(), "0");
+ stopSelf();
+ }
+ }
+ };
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ IntentFilter intentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
+ registerReceiver(mReceiver, intentFilter);
+ return START_REDELIVER_INTENT;
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) { return null; }
+
+ @Override
+ public void onDestroy() {
+ unregisterReceiver(mReceiver);
+ super.onDestroy();
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeSwitch.java b/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeSwitch.java
new file mode 100644
index 000000000..7dc064d71
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeSwitch.java
@@ -0,0 +1,53 @@
+/*
+* Copyright (C) Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode.ModeSwitch;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+import androidx.preference.PreferenceManager;
+
+import co.aospa.settings.DisplayMode.Utils;
+
+public class HBMModeSwitch implements OnPreferenceChangeListener {
+
+ private static final String FILE = "/sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/hbm";
+
+ public static String getFile() {
+ if (Utils.fileWritable(FILE)) {
+ return FILE;
+ }
+ return null;
+ }
+
+ public static boolean isSupported() {
+ return Utils.fileWritable(getFile());
+ }
+
+ public static boolean isCurrentlyEnabled() {
+ return Utils.getFileValueAsBoolean(getFile(), false);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Boolean enabled = (Boolean) newValue;
+ Utils.writeValue(getFile(), enabled ? "5" : "0");
+ return true;
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeTileService.java b/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeTileService.java
new file mode 100644
index 000000000..89ecc5fa3
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/HBMModeTileService.java
@@ -0,0 +1,82 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import android.content.Intent;
+import android.service.quicksettings.Tile;
+import android.service.quicksettings.TileService;
+
+import co.aospa.settings.DisplayMode.ModeSwitch.HBMModeSwitch;
+
+public class HBMModeTileService extends TileService {
+ private Intent mHbmIntent;
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public void onTileAdded() {
+ super.onTileAdded();
+ }
+
+ @Override
+ public void onTileRemoved() {
+ tryStopService();
+ super.onTileRemoved();
+ }
+
+ @Override
+ public void onStartListening() {
+ super.onStartListening();
+ updateState();
+ }
+
+ @Override
+ public void onStopListening() {
+ super.onStopListening();
+ }
+
+ @Override
+ public void onClick() {
+ super.onClick();
+ boolean enabled = HBMModeSwitch.isCurrentlyEnabled();
+ // NOTE: reverse logic, enabled reflects the state before press
+ Utils.writeValue(HBMModeSwitch.getFile(), enabled ? "0" : "5");
+ if (!enabled) {
+ mHbmIntent = new Intent(this,
+ co.aospa.settings.DisplayMode.HBMModeService.class);
+ this.startService(mHbmIntent);
+ }
+ updateState();
+ }
+
+ private void updateState() {
+ boolean enabled = HBMModeSwitch.isCurrentlyEnabled();
+ if (!enabled) tryStopService();
+ getQsTile().setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
+ getQsTile().updateTile();
+ }
+
+ private void tryStopService() {
+ if (mHbmIntent == null) return;
+ this.stopService(mHbmIntent);
+ mHbmIntent = null;
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/DCIModeSwitch.java b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/DCIModeSwitch.java
new file mode 100644
index 000000000..2469588f7
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/DCIModeSwitch.java
@@ -0,0 +1,50 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode.ModeSwitch;
+
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+
+import co.aospa.settings.DisplayMode.Utils;
+
+public class DCIModeSwitch implements OnPreferenceChangeListener {
+
+ private static final String FILE = "/sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/native_display_customer_p3_mode";
+
+ public static String getFile() {
+ if (Utils.fileWritable(FILE)) {
+ return FILE;
+ }
+ return null;
+ }
+
+ public static boolean isSupported() {
+ return Utils.fileWritable(getFile());
+ }
+
+ public static boolean isCurrentlyEnabled() {
+ return Utils.getFileValueAsBoolean(getFile(), false);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Boolean enabled = (Boolean) newValue;
+ Utils.writeValue(getFile(), enabled ? "1" : "0");
+ return true;
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/NaturalModeSwitch.java b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/NaturalModeSwitch.java
new file mode 100644
index 000000000..406f2db5a
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/NaturalModeSwitch.java
@@ -0,0 +1,50 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode.ModeSwitch;
+
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+
+import co.aospa.settings.DisplayMode.Utils;
+
+public class NaturalModeSwitch implements OnPreferenceChangeListener {
+
+ private static final String FILE = "/sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/native_display_srgb_color_mode";
+
+ public static String getFile() {
+ if (Utils.fileWritable(FILE)) {
+ return FILE;
+ }
+ return null;
+ }
+
+ public static boolean isSupported() {
+ return Utils.fileWritable(getFile());
+ }
+
+ public static boolean isCurrentlyEnabled() {
+ return Utils.getFileValueAsBoolean(getFile(), false);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Boolean enabled = (Boolean) newValue;
+ Utils.writeValue(getFile(), enabled ? "1" : "0");
+ return true;
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/SRGBModeSwitch.java b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/SRGBModeSwitch.java
new file mode 100644
index 000000000..f70a2b063
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/SRGBModeSwitch.java
@@ -0,0 +1,50 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode.ModeSwitch;
+
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+
+import co.aospa.settings.DisplayMode.Utils;
+
+public class SRGBModeSwitch implements OnPreferenceChangeListener {
+
+ private static final String FILE = "/sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/native_display_customer_srgb_mode";
+
+ public static String getFile() {
+ if (Utils.fileWritable(FILE)) {
+ return FILE;
+ }
+ return null;
+ }
+
+ public static boolean isSupported() {
+ return Utils.fileWritable(getFile());
+ }
+
+ public static boolean isCurrentlyEnabled() {
+ return Utils.getFileValueAsBoolean(getFile(), false);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Boolean enabled = (Boolean) newValue;
+ Utils.writeValue(getFile(), enabled ? "1" : "0");
+ return true;
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/VividModeSwitch.java b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/VividModeSwitch.java
new file mode 100644
index 000000000..cc2c3d2f7
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/VividModeSwitch.java
@@ -0,0 +1,50 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode.ModeSwitch;
+
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+
+import co.aospa.settings.DisplayMode.Utils;
+
+public class VividModeSwitch implements OnPreferenceChangeListener {
+
+ private static final String FILE = "/sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/native_display_p3_mode";
+
+ public static String getFile() {
+ if (Utils.fileWritable(FILE)) {
+ return FILE;
+ }
+ return null;
+ }
+
+ public static boolean isSupported() {
+ return Utils.fileWritable(getFile());
+ }
+
+ public static boolean isCurrentlyEnabled() {
+ return Utils.getFileValueAsBoolean(getFile(), false);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Boolean enabled = (Boolean) newValue;
+ Utils.writeValue(getFile(), enabled ? "1" : "0");
+ return true;
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/WideColorModeSwitch.java b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/WideColorModeSwitch.java
new file mode 100644
index 000000000..d8e066ca0
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/ModeSwitch/WideColorModeSwitch.java
@@ -0,0 +1,50 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode.ModeSwitch;
+
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceChangeListener;
+
+import co.aospa.settings.DisplayMode.Utils;
+
+public class WideColorModeSwitch implements OnPreferenceChangeListener {
+
+ private static final String FILE = "/sys/devices/platform/soc/ae00000.qcom,mdss_mdp/drm/card0/card0-DSI-1/native_display_wide_color_mode";
+
+ public static String getFile() {
+ if (Utils.fileWritable(FILE)) {
+ return FILE;
+ }
+ return null;
+ }
+
+ public static boolean isSupported() {
+ return Utils.fileWritable(getFile());
+ }
+
+ public static boolean isCurrentlyEnabled() {
+ return Utils.getFileValueAsBoolean(getFile(), false);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Boolean enabled = (Boolean) newValue;
+ Utils.writeValue(getFile(), enabled ? "1" : "0");
+ return true;
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/PanelModeTileService.java b/DisplayMode/src/co/aospa/settings/DisplayMode/PanelModeTileService.java
new file mode 100644
index 000000000..d1fcc33e0
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/PanelModeTileService.java
@@ -0,0 +1,56 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import android.content.Intent;
+import android.service.quicksettings.TileService;
+
+public class PanelModeTileService extends TileService {
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public void onTileAdded() {
+ super.onTileAdded();
+ }
+
+ @Override
+ public void onTileRemoved() {
+ super.onTileRemoved();
+ }
+
+ @Override
+ public void onStartListening() {
+ super.onStartListening();
+ }
+
+ @Override
+ public void onStopListening() {
+ super.onStopListening();
+ }
+
+ @Override
+ public void onClick() {
+ super.onClick();
+ Intent panelModes = new Intent(this, PanelSettingsActivity.class);
+ panelModes.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivityAndCollapse(panelModes);
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/PanelSettings.java b/DisplayMode/src/co/aospa/settings/DisplayMode/PanelSettings.java
new file mode 100644
index 000000000..3075196cf
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/PanelSettings.java
@@ -0,0 +1,258 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RadioGroup;
+
+import androidx.preference.PreferenceFragment;
+import androidx.preference.PreferenceManager;
+import androidx.viewpager.widget.PagerAdapter;
+import androidx.viewpager.widget.ViewPager;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import co.aospa.settings.DisplayMode.ModeSwitch.*;
+
+public class PanelSettings extends PreferenceFragment implements RadioGroup.OnCheckedChangeListener {
+
+ private static final int DOT_INDICATOR_SIZE = 12;
+ private static final int DOT_INDICATOR_LEFT_PADDING = 6;
+ private static final int DOT_INDICATOR_RIGHT_PADDING = 6;
+ private static final String PAGE_VIEWER_SELECTION_INDEX = "page_viewer_selection_index";
+
+ private View mViewArrowPrevious;
+ private View mViewArrowNext;
+ private ViewPager mViewPager;
+
+ private ArrayList mPageList;
+ private ImageView[] mDotIndicators;
+ private View[] mViewPagerImages;
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ RadioGroup mRadioGroup = view.findViewById(R.id.radio_group);
+ int checkedButtonId = R.id.off_mode;
+ if (NaturalModeSwitch.isCurrentlyEnabled()) {
+ checkedButtonId = R.id.natural_mode;
+ } else if (VividModeSwitch.isCurrentlyEnabled()) {
+ checkedButtonId = R.id.vivid_mode;
+ } else if (DCIModeSwitch.isCurrentlyEnabled()) {
+ checkedButtonId = R.id.dci_mode;
+ } else if (SRGBModeSwitch.isCurrentlyEnabled()) {
+ checkedButtonId = R.id.srgb_mode;
+ } else if (WideColorModeSwitch.isCurrentlyEnabled()) {
+ checkedButtonId = R.id.wide_color_mode;
+ }
+ mRadioGroup.check(checkedButtonId);
+ mRadioGroup.setOnCheckedChangeListener(this);
+
+ if (savedInstanceState != null) {
+ final int selectedPosition = savedInstanceState.getInt(PAGE_VIEWER_SELECTION_INDEX);
+ mViewPager.setCurrentItem(selectedPosition);
+ updateIndicator(selectedPosition);
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState){
+ super.onSaveInstanceState(outState);
+ outState.putInt(PAGE_VIEWER_SELECTION_INDEX, mViewPager.getCurrentItem());
+ }
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ final View rootView = inflater.inflate(R.layout.panel_modes, container, false);
+
+ addViewPager(rootView);
+ return rootView;
+ }
+
+ @Override
+ public void onCheckedChanged(RadioGroup group, int checkedId) {
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
+ SharedPreferences.Editor edit = sharedPrefs.edit();
+ boolean natural = checkedId == R.id.natural_mode;
+ Utils.writeValue(NaturalModeSwitch.getFile(), natural ? "1" : "0");
+ edit.putBoolean(DeviceSettings.KEY_NATURAL_SWITCH, natural);
+
+ boolean vivid = checkedId == R.id.vivid_mode;
+ Utils.writeValue(VividModeSwitch.getFile(), vivid ? "1" : "0");
+ edit.putBoolean(DeviceSettings.KEY_VIVID_SWITCH, vivid);
+
+ boolean dci = checkedId == R.id.dci_mode;
+ Utils.writeValue(DCIModeSwitch.getFile(), dci ? "1" : "0");
+ edit.putBoolean(DeviceSettings.KEY_DCI_SWITCH, dci);
+
+ boolean wide = checkedId == R.id.wide_color_mode;
+ Utils.writeValue(WideColorModeSwitch.getFile(), wide ? "1" : "0");
+ edit.putBoolean(DeviceSettings.KEY_WIDECOLOR_SWITCH, wide);
+
+ boolean srgb = checkedId == R.id.srgb_mode;
+ Utils.writeValue(SRGBModeSwitch.getFile(), srgb ? "1" : "0");
+ edit.putBoolean(DeviceSettings.KEY_SRGB_SWITCH, srgb);
+
+ edit.apply();
+ }
+
+ private ArrayList getViewPagerResource() {
+ return new ArrayList<>(
+ Arrays.asList(
+ R.layout.color_mode_view1,
+ R.layout.color_mode_view2,
+ R.layout.color_mode_view3));
+ }
+
+ private void addViewPager(View rootView) {
+ final ArrayList tmpviewPagerList = getViewPagerResource();
+ mViewPager = rootView.findViewById(R.id.viewpager);
+
+ mViewPagerImages = new View[3];
+ for (int idx = 0; idx < tmpviewPagerList.size(); idx++) {
+ mViewPagerImages[idx] =
+ getLayoutInflater().inflate(tmpviewPagerList.get(idx), null /* root */);
+ }
+
+ mPageList = new ArrayList<>();
+ mPageList.add(mViewPagerImages[0]);
+ mPageList.add(mViewPagerImages[1]);
+ mPageList.add(mViewPagerImages[2]);
+
+ mViewPager.setAdapter(new ColorPagerAdapter(mPageList));
+
+ mViewArrowPrevious = rootView.findViewById(R.id.arrow_previous);
+ mViewArrowPrevious.setOnClickListener(v -> {
+ final int previousPos = mViewPager.getCurrentItem() - 1;
+ mViewPager.setCurrentItem(previousPos, true);
+ });
+
+ mViewArrowNext = rootView.findViewById(R.id.arrow_next);
+ mViewArrowNext.setOnClickListener(v -> {
+ final int nextPos = mViewPager.getCurrentItem() + 1;
+ mViewPager.setCurrentItem(nextPos, true);
+ });
+
+ mViewPager.addOnPageChangeListener(createPageListener());
+
+ final ViewGroup viewGroup = rootView.findViewById(R.id.viewGroup);
+ mDotIndicators = new ImageView[mPageList.size()];
+ for (int i = 0; i < mPageList.size(); i++) {
+ final ImageView imageView = new ImageView(getContext());
+ final ViewGroup.MarginLayoutParams lp =
+ new ViewGroup.MarginLayoutParams(DOT_INDICATOR_SIZE, DOT_INDICATOR_SIZE);
+ lp.setMargins(DOT_INDICATOR_LEFT_PADDING, 0, DOT_INDICATOR_RIGHT_PADDING, 0);
+ imageView.setLayoutParams(lp);
+ mDotIndicators[i] = imageView;
+
+ viewGroup.addView(mDotIndicators[i]);
+ }
+
+ updateIndicator(mViewPager.getCurrentItem());
+ }
+
+ private ViewPager.OnPageChangeListener createPageListener() {
+ return new ViewPager.OnPageChangeListener() {
+ @Override
+ public void onPageScrolled(
+ int position, float positionOffset, int positionOffsetPixels) {
+ if (positionOffset != 0) {
+ for (int idx = 0; idx < mPageList.size(); idx++)
+ mViewPagerImages[idx].setVisibility(View.VISIBLE);
+ } else {
+ updateIndicator(position);
+ }
+ }
+
+ @Override
+ public void onPageSelected(int position) {}
+
+ @Override
+ public void onPageScrollStateChanged(int state) {}
+ };
+ }
+
+ private void updateIndicator(int position) {
+ for (int i = 0; i < mPageList.size(); i++) {
+ if (position == i) {
+ mDotIndicators[i].setBackgroundResource(
+ R.drawable.ic_color_page_indicator_focused);
+
+ mViewPagerImages[i].setVisibility(View.VISIBLE);
+ } else {
+ mDotIndicators[i].setBackgroundResource(
+ R.drawable.ic_color_page_indicator_unfocused);
+
+ mViewPagerImages[i].setVisibility(View.INVISIBLE);
+ }
+ }
+
+ if (position == 0) {
+ mViewArrowPrevious.setVisibility(View.INVISIBLE);
+ mViewArrowNext.setVisibility(View.VISIBLE);
+ } else if (position == (mPageList.size() - 1)) {
+ mViewArrowPrevious.setVisibility(View.VISIBLE);
+ mViewArrowNext.setVisibility(View.INVISIBLE);
+ } else {
+ mViewArrowPrevious.setVisibility(View.VISIBLE);
+ mViewArrowNext.setVisibility(View.VISIBLE);
+ }
+ }
+
+ private static class ColorPagerAdapter extends PagerAdapter {
+ private final ArrayList mPageViewList;
+
+ ColorPagerAdapter(ArrayList pageViewList) {
+ mPageViewList = pageViewList;
+ }
+
+ @Override
+ public void destroyItem(ViewGroup container, int position, Object object) {
+ if (mPageViewList.get(position) != null) {
+ container.removeView(mPageViewList.get(position));
+ }
+ }
+
+ @Override
+ public Object instantiateItem(ViewGroup container, int position) {
+ container.addView(mPageViewList.get(position));
+ return mPageViewList.get(position);
+ }
+
+ @Override
+ public int getCount() {
+ return mPageViewList.size();
+ }
+
+ @Override
+ public boolean isViewFromObject(View view, Object object) {
+ return object == view;
+ }
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/PanelSettingsActivity.java b/DisplayMode/src/co/aospa/settings/DisplayMode/PanelSettingsActivity.java
new file mode 100644
index 000000000..0452654cb
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/PanelSettingsActivity.java
@@ -0,0 +1,33 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class PanelSettingsActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ getFragmentManager().beginTransaction()
+ .add(android.R.id.content, new PanelSettings())
+ .commit();
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/Startup.java b/DisplayMode/src/co/aospa/settings/DisplayMode/Startup.java
new file mode 100644
index 000000000..bda0d1c5b
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/Startup.java
@@ -0,0 +1,51 @@
+/*
+* Copyright (C) 2021 Yet Another AOSP Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import androidx.preference.PreferenceManager;
+
+import co.aospa.settings.DisplayMode.ModeSwitch.*;
+
+public class Startup extends BroadcastReceiver {
+
+ private void restore(String file, boolean enabled) {
+ if (file == null) return;
+ if (enabled) Utils.writeValue(file, "1");
+ }
+
+ @Override
+ public void onReceive(final Context context, final Intent bootintent) {
+ SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
+ restore(SRGBModeSwitch.getFile(),
+ sharedPrefs.getBoolean(DeviceSettings.KEY_SRGB_SWITCH, false));
+ restore(HBMModeSwitch.getFile(),
+ sharedPrefs.getBoolean(DeviceSettings.KEY_HBM_SWITCH, false));
+ restore(DCIModeSwitch.getFile(),
+ sharedPrefs.getBoolean(DeviceSettings.KEY_DCI_SWITCH, false));
+ restore(WideColorModeSwitch.getFile(),
+ sharedPrefs.getBoolean(DeviceSettings.KEY_WIDECOLOR_SWITCH, false));
+ restore(NaturalModeSwitch.getFile(),
+ sharedPrefs.getBoolean(DeviceSettings.KEY_NATURAL_SWITCH, false));
+ restore(VividModeSwitch.getFile(),
+ sharedPrefs.getBoolean(DeviceSettings.KEY_VIVID_SWITCH, false));
+ }
+}
diff --git a/DisplayMode/src/co/aospa/settings/DisplayMode/Utils.java b/DisplayMode/src/co/aospa/settings/DisplayMode/Utils.java
new file mode 100644
index 000000000..7bfadf37a
--- /dev/null
+++ b/DisplayMode/src/co/aospa/settings/DisplayMode/Utils.java
@@ -0,0 +1,104 @@
+/*
+* Copyright (C) 2013 The OmniROM Project
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see .
+*
+*/
+package co.aospa.settings.DisplayMode;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.BufferedReader;
+import java.io.FileReader;
+
+public class Utils {
+
+ /**
+ * Write a string value to the specified file.
+ * @param filename The filename
+ * @param value The value
+ */
+ public static void writeValue(String filename, String value) {
+ if (filename == null) {
+ return;
+ }
+ try {
+ FileOutputStream fos = new FileOutputStream(new File(filename));
+ fos.write(value.getBytes());
+ fos.flush();
+ fos.close();
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Check if the specified file exists.
+ * @param filename The filename
+ * @return Whether the file exists or not
+ */
+ public static boolean fileExists(String filename) {
+ if (filename == null) {
+ return false;
+ }
+ return new File(filename).exists();
+ }
+
+ public static boolean fileWritable(String filename) {
+ return fileExists(filename) && new File(filename).canWrite();
+ }
+
+ public static String readLine(String filename) {
+ if (filename == null) {
+ return null;
+ }
+ BufferedReader br = null;
+ String line = null;
+ try {
+ br = new BufferedReader(new FileReader(filename), 1024);
+ line = br.readLine();
+ } catch (IOException e) {
+ return null;
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ return line;
+ }
+
+ public static boolean getFileValueAsBoolean(String filename, boolean defValue) {
+ String fileValue = readLine(filename);
+ if(fileValue!=null){
+ return (fileValue.equals("0")?false:true);
+ }
+ return defValue;
+ }
+
+ public static String getFileValue(String filename, String defValue) {
+ String fileValue = readLine(filename);
+ if(fileValue!=null){
+ return fileValue;
+ }
+ return defValue;
+ }
+}