blob: d8bff75d7408e3e2ae40929be46a08c4e9572b28 [file] [log] [blame]
Ed Coyne7464ac92017-06-08 12:26:48 -07001/*
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 Kell6dd64f32017-09-25 17:30:28 -070020#include <map>
Ed Coyne7464ac92017-06-08 12:26:48 -070021#include <string>
22
Braden Kell6dd64f32017-09-25 17:30:28 -070023#include <base/json/json_value_converter.h>
Ed Coyne7464ac92017-06-08 12:26:48 -070024#include <utils/RefBase.h>
25
Braden Kell6dd64f32017-09-25 17:30:28 -070026using base::JSONValueConverter;
27
Ed Coyne7464ac92017-06-08 12:26:48 -070028namespace android {
29
30class BootAction : public RefBase {
31public:
Braden Kell6dd64f32017-09-25 17:30:28 -070032 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 Coyne7464ac92017-06-08 12:26:48 -070046 ~BootAction();
Ed Coyne428ed512017-08-14 15:10:06 -070047
Braden Kell6dd64f32017-09-25 17:30:28 -070048 // 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 Coyne428ed512017-08-14 15:10:06 -070054 // libraryPath is a fully qualified path to the target .so library.
55 bool init(const std::string& libraryPath);
Ed Coyne7464ac92017-06-08 12:26:48 -070056
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
67private:
Braden Kell6dd64f32017-09-25 17:30:28 -070068 typedef bool (*libInit)(const BootParameter* parameters, size_t num_parameters);
Ed Coyne7464ac92017-06-08 12:26:48 -070069 typedef void (*libStartPart)(int partNumber, int playNumber);
70 typedef void (*libShutdown)();
71
Ed Coyne7464ac92017-06-08 12:26:48 -070072 bool loadSymbol(const char* symbol, void** loaded);
Ed Coyne7464ac92017-06-08 12:26:48 -070073
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