blob: 3cd43bed140cef754fa21d1b289a2561d0b84f1c [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>
David Pursell1ecfdbd2017-09-27 14:15:21 -070024#include <boot_action/boot_action.h> // libandroidthings native API.
Ed Coyne7464ac92017-06-08 12:26:48 -070025#include <utils/RefBase.h>
26
Braden Kell6dd64f32017-09-25 17:30:28 -070027using base::JSONValueConverter;
28
Ed Coyne7464ac92017-06-08 12:26:48 -070029namespace android {
30
31class BootAction : public RefBase {
32public:
Braden Kell6dd64f32017-09-25 17:30:28 -070033 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 Coyne7464ac92017-06-08 12:26:48 -070042 ~BootAction();
Ed Coyne428ed512017-08-14 15:10:06 -070043
Braden Kell6dd64f32017-09-25 17:30:28 -070044 // 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 Coyne428ed512017-08-14 15:10:06 -070050 // libraryPath is a fully qualified path to the target .so library.
51 bool init(const std::string& libraryPath);
Ed Coyne7464ac92017-06-08 12:26:48 -070052
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
63private:
David Pursell1ecfdbd2017-09-27 14:15:21 -070064 typedef bool (*libInit)(const ABootActionParameter* parameters,
65 size_t num_parameters);
Ed Coyne7464ac92017-06-08 12:26:48 -070066 typedef void (*libStartPart)(int partNumber, int playNumber);
67 typedef void (*libShutdown)();
68
Ed Coyne7464ac92017-06-08 12:26:48 -070069 bool loadSymbol(const char* symbol, void** loaded);
Ed Coyne7464ac92017-06-08 12:26:48 -070070
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