blob: c10bd44bc2ca60310774665e16a9e38ce0f1dac6 [file] [log] [blame]
David Pursell54a8fe42017-09-29 16:05:26 -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_BOOT_PARAMETERS_H_
18#define _BOOTANIMATION_BOOT_PARAMETERS_H_
19
20#include <list>
21#include <vector>
22
23#include <base/json/json_value_converter.h>
24#include <boot_action/boot_action.h> // libandroidthings native API.
25
26namespace android {
27
28// Provides access to the parameters set by DeviceManager.reboot().
29class BootParameters {
30public:
31 // Constructor loads the parameters for this boot and swaps the param files
32 // to clear the parameters for next boot.
33 BootParameters();
34
35 // Returns true if volume/brightness were explicitly set on reboot.
36 bool hasVolume() const { return mVolume >= 0; }
37 bool hasBrightness() const { return mBrightness >= 0; }
38
39 // Returns volume/brightness in [0,1], or -1 if unset.
40 float getVolume() const { return mVolume; }
41 float getBrightness() const { return mBrightness; }
42
43 // Returns the additional boot parameters that were set on reboot.
44 const std::vector<ABootActionParameter>& getParameters() const { return mParameters; }
45
46private:
47 // Raw boot saved_parameters loaded from .json.
48 struct SavedBootParameters {
49 int brightness;
50 int volume;
Jaesung Chunge175aaa2017-12-13 23:20:38 +090051 std::vector<std::unique_ptr<std::string>> param_names;
52 std::vector<std::unique_ptr<std::string>> param_values;
David Pursell54a8fe42017-09-29 16:05:26 -070053
54 SavedBootParameters();
55 static void RegisterJSONConverter(
56 ::base::JSONValueConverter<SavedBootParameters>* converter);
57 };
58
59 void loadParameters();
60
61 float mVolume = -1.f;
62 float mBrightness = -1.f;
63 std::vector<ABootActionParameter> mParameters;
64
65 // ABootActionParameter is just a raw pointer so we need to keep the
66 // original strings around to avoid losing them.
67 SavedBootParameters mRawParameters;
68};
69
70} // namespace android
71
72
73#endif // _BOOTANIMATION_BOOT_PARAMETERS_H_