David Pursell | 54a8fe4 | 2017-09-29 16:05:26 -0700 | [diff] [blame] | 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> |
Mickey Keeley | 953f109 | 2018-04-26 11:06:06 -0700 | [diff] [blame] | 21 | #include <string> |
David Pursell | 54a8fe4 | 2017-09-29 16:05:26 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
David Pursell | 54a8fe4 | 2017-09-29 16:05:26 -0700 | [diff] [blame] | 24 | #include <boot_action/boot_action.h> // libandroidthings native API. |
Mickey Keeley | 81121bd | 2018-05-29 17:43:22 -0700 | [diff] [blame] | 25 | #include <boot_parameters.pb.h> |
David Pursell | 54a8fe4 | 2017-09-29 16:05:26 -0700 | [diff] [blame] | 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | // Provides access to the parameters set by DeviceManager.reboot(). |
| 30 | class BootParameters { |
| 31 | public: |
| 32 | // Constructor loads the parameters for this boot and swaps the param files |
| 33 | // to clear the parameters for next boot. |
| 34 | BootParameters(); |
| 35 | |
Mickey Keeley | 1ffcc5e | 2018-05-07 09:42:19 -0700 | [diff] [blame] | 36 | // Returns whether or not this is a silent boot. |
| 37 | bool isSilentBoot() const { return mIsSilentBoot; } |
David Pursell | 54a8fe4 | 2017-09-29 16:05:26 -0700 | [diff] [blame] | 38 | |
| 39 | // Returns the additional boot parameters that were set on reboot. |
| 40 | const std::vector<ABootActionParameter>& getParameters() const { return mParameters; } |
| 41 | |
Mickey Keeley | 81121bd | 2018-05-29 17:43:22 -0700 | [diff] [blame] | 42 | // Exposed for testing. Sets the parameters to the serialized proto. |
| 43 | void parseBootParameters(const std::string &contents); |
| 44 | |
| 45 | // For devices that OTA from N to O. |
| 46 | // Exposed for testing. Sets the parameters to the raw JSON. |
| 47 | void parseLegacyBootParameters(const std::string &contents); |
| 48 | |
| 49 | // Exposed for testing. Loads the contents from |nextBootFile| and replaces |
| 50 | // |lastBootFile| with |nextBootFile|. |
| 51 | static bool swapAndLoadBootConfigContents(const char *lastBootFile, const char *nextBootFile, |
| 52 | std::string *contents); |
| 53 | |
| 54 | private: |
David Pursell | 54a8fe4 | 2017-09-29 16:05:26 -0700 | [diff] [blame] | 55 | void loadParameters(); |
| 56 | |
Mickey Keeley | 81121bd | 2018-05-29 17:43:22 -0700 | [diff] [blame] | 57 | // Replaces the legacy JSON blob with the updated version, allowing the |
| 58 | // framework to read it. |
| 59 | void storeParameters(); |
| 60 | |
| 61 | void loadStateFromProto(); |
Mickey Keeley | 1ffcc5e | 2018-05-07 09:42:19 -0700 | [diff] [blame] | 62 | |
| 63 | bool mIsSilentBoot = false; |
| 64 | |
David Pursell | 54a8fe4 | 2017-09-29 16:05:26 -0700 | [diff] [blame] | 65 | std::vector<ABootActionParameter> mParameters; |
| 66 | |
Mickey Keeley | 81121bd | 2018-05-29 17:43:22 -0700 | [diff] [blame] | 67 | // Store the proto because mParameters makes a shallow copy. |
| 68 | android::things::proto::BootParameters mProto; |
David Pursell | 54a8fe4 | 2017-09-29 16:05:26 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace android |
| 72 | |
| 73 | |
| 74 | #endif // _BOOTANIMATION_BOOT_PARAMETERS_H_ |