blob: e57ebcd4f52026215f09e56a480d0a9f15223042 [file] [log] [blame]
Sam Hurstc7152db2016-02-29 09:35:22 -08001/*
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 Parkd36a9952016-05-24 10:03:59 -070024#include <set>
Sam Hurstc7152db2016-02-29 09:35:22 -080025#include <string>
26#include <private/android_filesystem_config.h>
27#include <vehicle-internal.h>
28
29namespace 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.
36class VehiclePropertyAccessControl {
37public:
38 VehiclePropertyAccessControl();
Keun-young Park7151bb32016-10-12 21:14:19 -070039 virtual ~VehiclePropertyAccessControl();
Sam Hurstc7152db2016-02-29 09:35:22 -080040 bool init();
41 bool testAccess(int32_t property, int32_t uid, bool isWrite);
Keun-young Parkd36a9952016-05-24 10:03:59 -070042 bool isAutoGetEnabled(int32_t property);
Sam Hurstc7152db2016-02-29 09:35:22 -080043 void dump(String8& msg);
Sam Hurst17954fe2016-03-10 16:33:41 -080044// protected for testing
45protected:
Sam Hurstc7152db2016-02-29 09:35:22 -080046 bool isHexNotation(std::string const& s);
Sam Hurstc7152db2016-02-29 09:35:22 -080047 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 Hurst17954fe2016-03-10 16:33:41 -080052// protected for testing
53protected:
Sam Hurstc7152db2016-02-29 09:35:22 -080054 // 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 Parkd36a9952016-05-24 10:03:59 -070061 std::set<int32_t> mPropertiesWithNoAutoGet;
Sam Hurstc7152db2016-02-29 09:35:22 -080062};
63
64};
65
66#endif /* CAR_VEHICLE_NETWORK_PROPERTY_CONFIG_H_ */