Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Steven Moreland | ec50fdf | 2018-07-17 14:56:20 -0700 | [diff] [blame] | 17 | #pragma once |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 18 | |
| 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | struct Hash { |
Steven Moreland | 81bcf68 | 2017-08-23 17:16:21 -0700 | [diff] [blame] | 25 | static const std::vector<uint8_t> kEmptyHash; |
| 26 | |
Steven Moreland | 5bdfa70 | 2017-04-18 23:20:39 -0700 | [diff] [blame] | 27 | // path to .hal file |
Steven Moreland | ec50fdf | 2018-07-17 14:56:20 -0700 | [diff] [blame] | 28 | static const Hash& getHash(const std::string& path); |
Steven Moreland | 81bcf68 | 2017-08-23 17:16:21 -0700 | [diff] [blame] | 29 | static void clearHash(const std::string& path); |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 30 | |
Steven Moreland | 5bdfa70 | 2017-04-18 23:20:39 -0700 | [diff] [blame] | 31 | // returns matching hashes of interfaceName in path |
| 32 | // path is something like hardware/interfaces/current.txt |
| 33 | // interfaceName is something like android.hardware.foo@1.0::IFoo |
Steven Moreland | 566b0e9 | 2018-02-16 13:51:33 -0800 | [diff] [blame] | 34 | static std::vector<std::string> lookupHash(const std::string& path, |
| 35 | const std::string& interfaceName, std::string* err, |
| 36 | bool* fileExists = nullptr); |
Steven Moreland | 218625a | 2017-04-18 22:31:50 -0700 | [diff] [blame] | 37 | |
Steven Moreland | ec50fdf | 2018-07-17 14:56:20 -0700 | [diff] [blame] | 38 | static std::string hexString(const std::vector<uint8_t>& hash); |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 39 | std::string hexString() const; |
| 40 | |
Steven Moreland | ec50fdf | 2018-07-17 14:56:20 -0700 | [diff] [blame] | 41 | const std::vector<uint8_t>& raw() const; |
| 42 | const std::string& getPath() const; |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 43 | |
Steven Moreland | ec50fdf | 2018-07-17 14:56:20 -0700 | [diff] [blame] | 44 | private: |
| 45 | Hash(const std::string& path); |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 46 | |
Steven Moreland | 81bcf68 | 2017-08-23 17:16:21 -0700 | [diff] [blame] | 47 | static Hash& getMutableHash(const std::string& path); |
| 48 | |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 49 | const std::string mPath; |
Steven Moreland | 81bcf68 | 2017-08-23 17:16:21 -0700 | [diff] [blame] | 50 | std::vector<uint8_t> mHash; |
Steven Moreland | 0e4be1e | 2017-04-18 19:50:29 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | } // namespace android |