deadman96385

mode

Feb 8th, 2016
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2016 The CyanogenMod Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16.  
  17. package org.cyanogenmod.hardware;
  18.  
  19. import cyanogenmod.hardware.DisplayMode;
  20. import org.cyanogenmod.hardware.util.FileUtils;
  21. import android.util.Log;
  22. import java.io.File;
  23.  
  24. /*
  25. * Display Modes API
  26. *
  27. * A device may implement a list of preset display modes for different
  28. * viewing intents, such as movies, photos, or extra vibrance. These
  29. * modes may have multiple components such as gamma correction, white
  30. * point adjustment, etc, but are activated by a single control point.
  31. *
  32. * This API provides support for enumerating and selecting the
  33. * modes supported by the hardware.
  34. */
  35.  
  36. public class DisplayModeControl {
  37.  
  38. private static String CONTROL_PATH = "/sys/devices/platform/s5p-mipi-dsim.1/lcd/panel/mdnie/mode";
  39.  
  40. private static final DisplayMode[] ALL_ITEMS = { new DisplayMode (0, "Dynamic"), new DisplayMode (1, "Standard"), new DisplayMode (2, "Natural"), new DisplayMode (3, "Movie"), new DisplayMode (4, "Auto")};
  41.  
  42. /*
  43. * All HAF classes should export this boolean.
  44. * Real implementations must, of course, return true
  45. */
  46. public static boolean isSupported() {
  47. File f = new File(CONTROL_PATH);
  48.  
  49. if(f.exists()) {
  50. return true;
  51. } else {
  52. return false;
  53. }
  54. }
  55.  
  56. /*
  57. * Get the list of available modes. A mode has an integer
  58. * identifier and a string name.
  59. *
  60. * It is the responsibility of the upper layers to
  61. * map the name to a human-readable format or perform translation.
  62. */
  63. public static DisplayMode[] getAvailableModes() {
  64. return ALL_ITEMS;
  65. }
  66.  
  67. /*
  68. * Get the name of the currently selected mode. This can return
  69. * null if no mode is selected.
  70. */
  71. public static DisplayMode getCurrentMode() {
  72. if (FileUtils.readOneLine(CONTROL_PATH).equals("0")) {
  73. return (ALL_ITEMS[0]);
  74. } else if (FileUtils.readOneLine(CONTROL_PATH).equals("1")) {
  75. return (ALL_ITEMS[1]);
  76. } else if (FileUtils.readOneLine(CONTROL_PATH).equals("2")) {
  77. return (ALL_ITEMS[2]);
  78. } else if (FileUtils.readOneLine(CONTROL_PATH).equals("3")) {
  79. return (ALL_ITEMS[3]);
  80. } else if (FileUtils.readOneLine(CONTROL_PATH).equals("4")) {
  81. return (ALL_ITEMS[4]);
  82. } else
  83. return null;
  84. }
  85.  
  86. /*
  87. * Selects a mode from the list of available modes by it's
  88. * string identifier. Returns true on success, false for
  89. * failure. It is up to the implementation to determine
  90. * if this mode is valid.
  91. */
  92. public static boolean setMode(DisplayMode mode, boolean makeDefault) {
  93. if ("0".equals(ALL_ITEMS)) {
  94. FileUtils.writeLine(CONTROL_PATH, "0");
  95. return true;
  96. } else if ("1".equals(ALL_ITEMS)) {
  97. FileUtils.writeLine(CONTROL_PATH, "1");
  98. return true;
  99. } else if ("2".equals(ALL_ITEMS)) {
  100. FileUtils.writeLine(CONTROL_PATH, "2");
  101. return true;
  102. } else if ("3".equals(ALL_ITEMS)) {
  103. FileUtils.writeLine(CONTROL_PATH, "3");
  104. return true;
  105. } else if ("4".equals(ALL_ITEMS)) {
  106. FileUtils.writeLine(CONTROL_PATH, "4");
  107. return true;
  108. } else {
  109. return false;
  110. }
  111. }
  112.  
  113. /*
  114. * Gets the preferred default mode for this device by it's
  115. * string identifier. Can return null if there is no default.
  116. */
  117. public static DisplayMode getDefaultMode() {
  118. return (ALL_ITEMS[4]);
  119. }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment