• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
24 #include <string>
25 #include <private/android_filesystem_config.h>
26 #include <vehicle-internal.h>
27 
28 namespace android {
29 // This class is used to gate access to properties that are defined in an XML
30 // file. The property are read from /system/etc/vns/vns_policy.xml and this xml
31 // file must exist. If not, an error is generated. If the optional
32 // vendor_vns_policy.xml file is found in the same directory, properties from
33 // that file are also loaded to extend or override the properties from the
34 // vns_policy.xml file.
35 class VehiclePropertyAccessControl {
36 public:
37     VehiclePropertyAccessControl();
38     ~VehiclePropertyAccessControl();
39     bool init();
40     bool testAccess(int32_t property, int32_t uid, bool isWrite);
41     void dump(String8& msg);
42 // protected for testing
43 protected:
44     bool isHexNotation(std::string const& s);
45     bool accessToInt(int32_t* const value,const xmlChar* property,
46                    const xmlChar* uid, const xmlChar* access);
47     bool updateOrCreate(int32_t uid, int32_t property, int32_t access);
48     bool populate(xmlNode* a_node);
49     bool process(const char* policy);
50 // protected for testing
51 protected:
52     // mVehicleAccessControlMap uses "property" as a key to map to map<int,int>*
53     //
54     // map<int,int> uses "uid" as a key to map to an integer that represents
55     // "access"
56     //
57     // So "property" is used to find "uid" and "uid" is used to find "access".
58     std::map<int32_t, std::map<int32_t, int32_t>*> mVehicleAccessControlMap;
59 };
60 
61 };
62 
63 #endif /* CAR_VEHICLE_NETWORK_PROPERTY_CONFIG_H_ */
64