Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 _BOOTANIMATION_BOOTACTION_H |
| 18 | #define _BOOTANIMATION_BOOTACTION_H |
| 19 | |
Braden Kell | 6dd64f3 | 2017-09-25 17:30:28 -0700 | [diff] [blame^] | 20 | #include <map> |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 21 | #include <string> |
| 22 | |
Braden Kell | 6dd64f3 | 2017-09-25 17:30:28 -0700 | [diff] [blame^] | 23 | #include <base/json/json_value_converter.h> |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
| 25 | |
Braden Kell | 6dd64f3 | 2017-09-25 17:30:28 -0700 | [diff] [blame^] | 26 | using base::JSONValueConverter; |
| 27 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
| 30 | class BootAction : public RefBase { |
| 31 | public: |
Braden Kell | 6dd64f3 | 2017-09-25 17:30:28 -0700 | [diff] [blame^] | 32 | struct BootParameter { |
| 33 | const char* key; |
| 34 | const char* value; |
| 35 | }; |
| 36 | |
| 37 | struct SavedBootParameters { |
| 38 | int brightness; |
| 39 | int volume; |
| 40 | ScopedVector<std::string> param_names; |
| 41 | ScopedVector<std::string> param_values; |
| 42 | static void RegisterJSONConverter( |
| 43 | JSONValueConverter<SavedBootParameters>* converter); |
| 44 | }; |
| 45 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 46 | ~BootAction(); |
Ed Coyne | 428ed51 | 2017-08-14 15:10:06 -0700 | [diff] [blame] | 47 | |
Braden Kell | 6dd64f3 | 2017-09-25 17:30:28 -0700 | [diff] [blame^] | 48 | // Rename next_boot.json to last_boot.json so that we don't repeat |
| 49 | // parameters if there is a crash before the framework comes up. |
| 50 | // TODO(b/65462981): Is this what we want to do? Should we swap in the |
| 51 | // framework instead? |
| 52 | static void swapBootConfigs(); |
| 53 | |
Ed Coyne | 428ed51 | 2017-08-14 15:10:06 -0700 | [diff] [blame] | 54 | // libraryPath is a fully qualified path to the target .so library. |
| 55 | bool init(const std::string& libraryPath); |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 56 | |
| 57 | // The animation is going to start playing partNumber for the playCount'th |
| 58 | // time, update the action as needed. |
| 59 | // This is run in the same thread as the boot animation, |
| 60 | // you must not block here. |
| 61 | void startPart(int partNumber, int playCount); |
| 62 | |
| 63 | // Shutdown the boot action, this will be called shortly before the |
| 64 | // process is shut down to allow time for cleanup. |
| 65 | void shutdown(); |
| 66 | |
| 67 | private: |
Braden Kell | 6dd64f3 | 2017-09-25 17:30:28 -0700 | [diff] [blame^] | 68 | typedef bool (*libInit)(const BootParameter* parameters, size_t num_parameters); |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 69 | typedef void (*libStartPart)(int partNumber, int playNumber); |
| 70 | typedef void (*libShutdown)(); |
| 71 | |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 72 | bool loadSymbol(const char* symbol, void** loaded); |
Ed Coyne | 7464ac9 | 2017-06-08 12:26:48 -0700 | [diff] [blame] | 73 | |
| 74 | void* mLibHandle = nullptr; |
| 75 | libInit mLibInit = nullptr; |
| 76 | libStartPart mLibStartPart = nullptr; |
| 77 | libShutdown mLibShutdown = nullptr; |
| 78 | }; |
| 79 | |
| 80 | } // namespace android |
| 81 | |
| 82 | |
| 83 | #endif // _BOOTANIMATION_BOOTACTION_H |