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