Sam Hurst | c7152db | 2016-02-29 09:35:22 -0800 | [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 | |
| 17 | #ifndef CAR_VEHICLE_PROPERTY_ACCESS_CONTROL_H_ |
| 18 | #define CAR_VEHICLE_PROPERTY_ACCESS_CONTROL_H_ |
| 19 | |
| 20 | #include <utils/String8.h> |
| 21 | #include <libxml/parser.h> |
| 22 | #include <libxml/tree.h> |
| 23 | #include <map> |
Keun-young Park | d36a995 | 2016-05-24 10:03:59 -0700 | [diff] [blame] | 24 | #include <set> |
Sam Hurst | c7152db | 2016-02-29 09:35:22 -0800 | [diff] [blame] | 25 | #include <string> |
| 26 | #include <private/android_filesystem_config.h> |
| 27 | #include <vehicle-internal.h> |
| 28 | |
| 29 | namespace android { |
| 30 | // This class is used to gate access to properties that are defined in an XML |
| 31 | // file. The property are read from /system/etc/vns/vns_policy.xml and this xml |
| 32 | // file must exist. If not, an error is generated. If the optional |
| 33 | // vendor_vns_policy.xml file is found in the same directory, properties from |
| 34 | // that file are also loaded to extend or override the properties from the |
| 35 | // vns_policy.xml file. |
| 36 | class VehiclePropertyAccessControl { |
| 37 | public: |
| 38 | VehiclePropertyAccessControl(); |
Keun-young Park | 7151bb3 | 2016-10-12 21:14:19 -0700 | [diff] [blame] | 39 | virtual ~VehiclePropertyAccessControl(); |
Sam Hurst | c7152db | 2016-02-29 09:35:22 -0800 | [diff] [blame] | 40 | bool init(); |
| 41 | bool testAccess(int32_t property, int32_t uid, bool isWrite); |
Keun-young Park | d36a995 | 2016-05-24 10:03:59 -0700 | [diff] [blame] | 42 | bool isAutoGetEnabled(int32_t property); |
Sam Hurst | c7152db | 2016-02-29 09:35:22 -0800 | [diff] [blame] | 43 | void dump(String8& msg); |
Sam Hurst | 17954fe | 2016-03-10 16:33:41 -0800 | [diff] [blame] | 44 | // protected for testing |
| 45 | protected: |
Sam Hurst | c7152db | 2016-02-29 09:35:22 -0800 | [diff] [blame] | 46 | bool isHexNotation(std::string const& s); |
Sam Hurst | c7152db | 2016-02-29 09:35:22 -0800 | [diff] [blame] | 47 | bool accessToInt(int32_t* const value,const xmlChar* property, |
| 48 | const xmlChar* uid, const xmlChar* access); |
| 49 | bool updateOrCreate(int32_t uid, int32_t property, int32_t access); |
| 50 | bool populate(xmlNode* a_node); |
| 51 | bool process(const char* policy); |
Sam Hurst | 17954fe | 2016-03-10 16:33:41 -0800 | [diff] [blame] | 52 | // protected for testing |
| 53 | protected: |
Sam Hurst | c7152db | 2016-02-29 09:35:22 -0800 | [diff] [blame] | 54 | // mVehicleAccessControlMap uses "property" as a key to map to map<int,int>* |
| 55 | // |
| 56 | // map<int,int> uses "uid" as a key to map to an integer that represents |
| 57 | // "access" |
| 58 | // |
| 59 | // So "property" is used to find "uid" and "uid" is used to find "access". |
| 60 | std::map<int32_t, std::map<int32_t, int32_t>*> mVehicleAccessControlMap; |
Keun-young Park | d36a995 | 2016-05-24 10:03:59 -0700 | [diff] [blame] | 61 | std::set<int32_t> mPropertiesWithNoAutoGet; |
Sam Hurst | c7152db | 2016-02-29 09:35:22 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | #endif /* CAR_VEHICLE_NETWORK_PROPERTY_CONFIG_H_ */ |