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