No Description

device.cpp 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (C) 2015 The Android Open Source 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. #include "device.h"
  17. #define ARRAY_SIZE(A) (sizeof(A)/sizeof(*(A)))
  18. // *** Main menu ***
  19. static const menu_type_t MAIN_MENU_TYPE = MT_GRID;
  20. static const MenuItem MAIN_MENU_ITEMS[] = {
  21. MenuItem("Reboot", "ic_reboot", "ic_reboot_sel"),
  22. MenuItem("Apply update", "ic_system_update", "ic_system_update_sel"),
  23. MenuItem("Factory reset", "ic_factory_reset", "ic_factory_reset_sel"),
  24. MenuItem("Advanced", "ic_options_advanced", "ic_options_advanced_sel"),
  25. };
  26. static const MenuItemVector main_menu_items_ =
  27. MenuItemVector(MAIN_MENU_ITEMS,
  28. MAIN_MENU_ITEMS + ARRAY_SIZE(MAIN_MENU_ITEMS));
  29. static const Device::BuiltinAction MAIN_MENU_ACTIONS[] = {
  30. Device::REBOOT,
  31. Device::APPLY_UPDATE,
  32. Device::WIPE_MENU,
  33. Device::ADVANCED_MENU,
  34. };
  35. static const Device::MenuActionVector main_menu_actions_ =
  36. Device::MenuActionVector(MAIN_MENU_ACTIONS,
  37. MAIN_MENU_ACTIONS + ARRAY_SIZE(MAIN_MENU_ACTIONS));
  38. static_assert(ARRAY_SIZE(MAIN_MENU_ITEMS) ==
  39. ARRAY_SIZE(MAIN_MENU_ACTIONS),
  40. "MAIN_MENU_ITEMS and MAIN_MENU_ACTIONS should have the same length.");
  41. // *** Wipe menu ***
  42. static const menu_type_t WIPE_MENU_TYPE = MT_LIST;
  43. static const MenuItem WIPE_MENU_ITEMS[] = {
  44. MenuItem("Wipe data / factory reset"),
  45. #ifndef AB_OTA_UPDATER
  46. MenuItem("Wipe cache"),
  47. #endif
  48. MenuItem("Wipe system"),
  49. };
  50. static const MenuItemVector wipe_menu_items_ =
  51. MenuItemVector(WIPE_MENU_ITEMS,
  52. WIPE_MENU_ITEMS + ARRAY_SIZE(WIPE_MENU_ITEMS));
  53. static const Device::BuiltinAction WIPE_MENU_ACTIONS[] = {
  54. Device::WIPE_DATA,
  55. #ifndef AB_OTA_UPDATER
  56. Device::WIPE_CACHE,
  57. #endif
  58. Device::WIPE_SYSTEM,
  59. };
  60. static const Device::MenuActionVector wipe_menu_actions_ =
  61. Device::MenuActionVector(WIPE_MENU_ACTIONS,
  62. WIPE_MENU_ACTIONS + ARRAY_SIZE(WIPE_MENU_ACTIONS));
  63. static_assert(ARRAY_SIZE(WIPE_MENU_ITEMS) ==
  64. ARRAY_SIZE(WIPE_MENU_ACTIONS),
  65. "WIPE_MENU_ITEMS and WIPE_MENU_ACTIONS should have the same length.");
  66. // *** Advanced menu
  67. static const menu_type_t ADVANCED_MENU_TYPE = MT_LIST;
  68. static const MenuItem ADVANCED_MENU_ITEMS[] = {
  69. #ifdef DOWNLOAD_MODE
  70. MenuItem("Reboot to download mode"),
  71. #else
  72. MenuItem("Reboot to bootloader"),
  73. #endif
  74. MenuItem("Mount system"),
  75. MenuItem("View logs"),
  76. MenuItem("Run graphics test"),
  77. MenuItem("Run locale test"),
  78. MenuItem("Power off"),
  79. };
  80. static const MenuItemVector advanced_menu_items_ =
  81. MenuItemVector(ADVANCED_MENU_ITEMS,
  82. ADVANCED_MENU_ITEMS + ARRAY_SIZE(ADVANCED_MENU_ITEMS));
  83. static const Device::BuiltinAction ADVANCED_MENU_ACTIONS[] = {
  84. Device::REBOOT_BOOTLOADER,
  85. Device::MOUNT_SYSTEM,
  86. Device::VIEW_RECOVERY_LOGS,
  87. Device::RUN_GRAPHICS_TEST,
  88. Device::RUN_LOCALE_TEST,
  89. Device::SHUTDOWN,
  90. };
  91. static const Device::MenuActionVector advanced_menu_actions_ =
  92. Device::MenuActionVector(ADVANCED_MENU_ACTIONS,
  93. ADVANCED_MENU_ACTIONS + ARRAY_SIZE(ADVANCED_MENU_ACTIONS));
  94. static_assert(ARRAY_SIZE(ADVANCED_MENU_ITEMS) ==
  95. ARRAY_SIZE(ADVANCED_MENU_ACTIONS),
  96. "ADVANCED_MENU_ITEMS and ADVANCED_MENU_ACTIONS should have the same length.");
  97. Device::Device(RecoveryUI* ui) :
  98. ui_(ui)
  99. {
  100. GoHome();
  101. }
  102. Device::BuiltinAction Device::InvokeMenuItem(int menu_position) {
  103. if (menu_position < 0) {
  104. if (menu_position == Device::kGoBack ||
  105. menu_position == Device::kGoHome) {
  106. // Assume only two menu levels, so back is equivalent to home.
  107. GoHome();
  108. }
  109. return NO_ACTION;
  110. }
  111. BuiltinAction action = menu_actions_.at(menu_position);
  112. switch (action) {
  113. case WIPE_MENU:
  114. menu_is_main_ = false;
  115. menu_type_ = WIPE_MENU_TYPE;
  116. menu_items_ = wipe_menu_items_;
  117. menu_actions_ = wipe_menu_actions_;
  118. break;
  119. case ADVANCED_MENU:
  120. menu_is_main_ = false;
  121. menu_type_ = ADVANCED_MENU_TYPE;
  122. menu_items_ = advanced_menu_items_;
  123. menu_actions_ = advanced_menu_actions_;
  124. break;
  125. default:
  126. break; // Fall through
  127. }
  128. return action;
  129. }
  130. void Device::GoHome() {
  131. menu_is_main_ = true;
  132. menu_type_ = MAIN_MENU_TYPE;
  133. menu_items_ = main_menu_items_;
  134. menu_actions_ = main_menu_actions_;
  135. }
  136. int Device::HandleMenuKey(int key, bool visible) {
  137. if (!visible) {
  138. return kNoAction;
  139. }
  140. switch (key) {
  141. case KEY_RIGHTSHIFT:
  142. case KEY_DOWN:
  143. case KEY_VOLUMEDOWN:
  144. case KEY_MENU:
  145. return kHighlightDown;
  146. case KEY_LEFTSHIFT:
  147. case KEY_UP:
  148. case KEY_VOLUMEUP:
  149. case KEY_SEARCH:
  150. return kHighlightUp;
  151. case KEY_ENTER:
  152. case KEY_POWER:
  153. case BTN_MOUSE:
  154. case KEY_SEND:
  155. return kInvokeItem;
  156. case KEY_HOME:
  157. case KEY_HOMEPAGE:
  158. return kGoHome;
  159. case KEY_BACKSPACE:
  160. case KEY_BACK:
  161. return kGoBack;
  162. case KEY_REFRESH:
  163. return kRefresh;
  164. default:
  165. // If you have all of the above buttons, any other buttons
  166. // are ignored. Otherwise, any button cycles the highlight.
  167. return ui_->HasThreeButtons() ? kNoAction : kHighlightDown;
  168. }
  169. }