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_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 26 namespace android { 27 28 // Provides access to the parameters set by DeviceManager.reboot(). 29 class BootParameters { 30 public: 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. hasVolume()36 bool hasVolume() const { return mVolume >= 0; } hasBrightness()37 bool hasBrightness() const { return mBrightness >= 0; } 38 39 // Returns volume/brightness in [0,1], or -1 if unset. getVolume()40 float getVolume() const { return mVolume; } getBrightness()41 float getBrightness() const { return mBrightness; } 42 43 // Returns the additional boot parameters that were set on reboot. getParameters()44 const std::vector<ABootActionParameter>& getParameters() const { return mParameters; } 45 46 private: 47 // Raw boot saved_parameters loaded from .json. 48 struct SavedBootParameters { 49 int brightness; 50 int volume; 51 std::vector<std::unique_ptr<std::string>> param_names; 52 std::vector<std::unique_ptr<std::string>> param_values; 53 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_ 74