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