No Description

device.h 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2011 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. #ifndef _RECOVERY_DEVICE_H
  17. #define _RECOVERY_DEVICE_H
  18. #include "ui.h"
  19. class Device {
  20. public:
  21. explicit Device(RecoveryUI* ui);
  22. virtual ~Device() {}
  23. // Called to obtain the UI object that should be used to display the recovery user interface for
  24. // this device. You should not have called Init() on the UI object already, the caller will do
  25. // that after this method returns.
  26. virtual RecoveryUI* GetUI() {
  27. return ui_;
  28. }
  29. // Called when recovery starts up (after the UI has been obtained and initialized and after the
  30. // arguments have been parsed, but before anything else).
  31. virtual void StartRecovery() {};
  32. // Called from the main thread when recovery is at the main menu and waiting for input, and a key
  33. // is pressed. (Note that "at" the main menu does not necessarily mean the menu is visible;
  34. // recovery will be at the main menu with it invisible after an unsuccessful operation [ie OTA
  35. // package failure], or if recovery is started with no command.)
  36. //
  37. // 'key' is the code of the key just pressed. (You can call IsKeyPressed() on the RecoveryUI
  38. // object you returned from GetUI if you want to find out if other keys are held down.)
  39. //
  40. // 'visible' is true if the menu is visible.
  41. //
  42. // Returns one of the defined constants below in order to:
  43. //
  44. // - move the menu highlight (kHighlight{Up,Down})
  45. // - invoke the highlighted item (kInvokeItem)
  46. // - do nothing (kNoAction)
  47. // - invoke a specific action (a menu position: any non-negative number)
  48. virtual int HandleMenuKey(int key, bool visible);
  49. enum BuiltinAction {
  50. NO_ACTION = 0,
  51. // Main menu
  52. REBOOT = 1,
  53. APPLY_UPDATE = 2,
  54. WIPE_MENU = 3,
  55. ADVANCED_MENU = 4,
  56. // Wipe menu
  57. WIPE_DATA = 10,
  58. WIPE_CACHE = 11,
  59. WIPE_SYSTEM = 12,
  60. // Advanced menu
  61. REBOOT_BOOTLOADER = 20,
  62. MOUNT_SYSTEM = 21,
  63. VIEW_RECOVERY_LOGS = 22,
  64. RUN_GRAPHICS_TEST = 23,
  65. RUN_LOCALE_TEST = 24,
  66. SHUTDOWN = 25,
  67. };
  68. typedef std::vector<MenuItem> MenuItemVector;
  69. typedef std::vector<BuiltinAction> MenuActionVector;
  70. // Return the menu properties. The menu_position passed to InvokeMenuItem
  71. // will correspond to the indexes in the associated vectors.
  72. virtual bool IsMainMenu() const { return menu_is_main_; }
  73. virtual menu_type_t GetMenuType() const { return menu_type_; }
  74. virtual const MenuItemVector& GetMenuItems() const { return menu_items_; }
  75. // Perform a recovery action selected from the menu. 'menu_position' will be the item number of
  76. // the selected menu item, or a non-negative number returned from HandleMenuKey(). The menu will
  77. // be hidden when this is called; implementations can call ui_print() to print information to the
  78. // screen. If the menu position is one of the builtin actions, you can just return the
  79. // corresponding enum value. If it is an action specific to your device, you actually perform it
  80. // here and return NO_ACTION.
  81. virtual BuiltinAction InvokeMenuItem(int menu_position);
  82. virtual void GoHome();
  83. static const int kNoAction = -1;
  84. static const int kHighlightUp = -2;
  85. static const int kHighlightDown = -3;
  86. static const int kInvokeItem = -4;
  87. static const int kGoBack = -5;
  88. static const int kGoHome = -6;
  89. static const int kRefresh = -7;
  90. // Called before and after we do a wipe data/factory reset operation, either via a reboot from the
  91. // main system with the --wipe_data flag, or when the user boots into recovery image manually and
  92. // selects the option from the menu, to perform whatever device-specific wiping actions as needed.
  93. // Returns true on success; returning false from PreWipeData will prevent the regular wipe, and
  94. // returning false from PostWipeData will cause the wipe to be considered a failure.
  95. virtual bool PreWipeData() {
  96. return true;
  97. }
  98. virtual bool PostWipeData() {
  99. return true;
  100. }
  101. virtual void handleVolumeChanged() { ui_->onVolumeChanged(); }
  102. private:
  103. RecoveryUI* ui_;
  104. bool menu_is_main_;
  105. menu_type_t menu_type_;
  106. MenuItemVector menu_items_;
  107. MenuActionVector menu_actions_;
  108. };
  109. // The device-specific library must define this function (or the default one will be used, if there
  110. // is no device-specific library). It returns the Device object that recovery should use.
  111. Device* make_device();
  112. #endif // _DEVICE_H