| #!/usr/bin/env python |
| # |
| # Copyright (C) 2016 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| """Generate vns_policy.xml from vehicle.h""" |
| import os |
| import re |
| import sys |
| import datetime |
| |
| curYear = datetime.datetime.now().year |
| |
| |
| XML_HEADER = \ |
| """<!-- Copyright (C) """ + str(curYear) + """ The Android Open Source Project |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| / |
| |
| //Autogenerated from vehicle.h using tools/vns_policy_gen.py. |
| //Do not modify manually. |
| --> |
| |
| <ALLOW> |
| <PROPERTY name="VEHICLE_PROPERTY_INVALID" value = "0x0"> |
| <!-- Property 0 write is used to allow hal mocking --> |
| <UID name="AID_SYSTEM" access="rw" value="1000"/> |
| <UID name="AID_AUDIOSERVER" access="r" value="1041"/> |
| </PROPERTY> |
| |
| """ |
| |
| XML_TRAIL = \ |
| """</ALLOW> |
| """ |
| |
| RE_PROPERTY_PATTERN = r'/\*\*(.*?)\*/\n\#define\s+VEHICLE_PROPERTY_(\S+)\s+(\(0x\S+\))' |
| AUDIOSERVER_RO_PARAMS = ['VEHICLE_PROPERTY_AUDIO_FOCUS'] |
| AUDIOSERVER_WO_PARAMS = ['VEHICLE_PROPERTY_INTERNAL_AUDIO_STREAM_STATE'] |
| NO_AUTO_GET_PARAMS = ['VEHICLE_PROPERTY_AUDIO_VOLUME', 'VEHICLE_PROPERTY_AUDIO_VOLUME_LIMIT'] |
| |
| class PropertyInfo(object): |
| def __init__(self, value, name): |
| self.value = value |
| self.name = name |
| self.type = "" |
| self.changeMode = "" |
| self.access = "" |
| self.unit = "" |
| self.startEnd = 0 # _START/END property |
| self.aid_audioserver = "" |
| self.no_auto_get = 0 |
| # Check if this property requires special handling |
| if name in AUDIOSERVER_RO_PARAMS: |
| self.aid_audioserver = 'r' |
| if name in AUDIOSERVER_WO_PARAMS: |
| self.aid_audioserver = 'w' |
| if name in NO_AUTO_GET_PARAMS: |
| self.no_auto_get = 1 |
| |
| def printProperties(props, f): |
| for p in props: |
| if p.startEnd == 0: |
| if p.no_auto_get == 0: |
| f.write(""" <PROPERTY name=\"""" + p.name + "\" value=\"" + p.value + "\">\n") |
| else: |
| f.write(""" <PROPERTY name=\"""" + p.name + "\" value=\"" + p.value + """" no_auto_get="true">\n""") |
| f.write(""" <UID name="AID_SYSTEM" access=\"""" + p.access + """" value="1000"/>\n""") |
| if p.aid_audioserver: |
| f.write(""" <UID name="AID_AUDIOSERVER" access=\"""" + p.aid_audioserver + """" value="1041"/>\n""") |
| f.write(" </PROPERTY>\n\n") |
| elif p.name == 'VEHICLE_PROPERTY_INTERNAL_START': |
| f.write("<!-- Internal Vehicle Properties -->\n\n") |
| |
| def main(argv): |
| # If user hasn't called build/envsetup.sh, use relative path |
| base_path = os.getenv('ANDROID_BUILD_TOP', "../../../..") |
| |
| # Parse vehicle.h file |
| vehicle_h_path = base_path + "/hardware/libhardware/include/hardware/vehicle.h" |
| #print vehicle_h_path |
| f = open(vehicle_h_path, 'r') |
| text = f.read() |
| f.close() |
| |
| # Parse vehicle_internal.h |
| vehicle_internal_h_path = base_path + "/packages/services/Car/libvehiclenetwork/include/vehicle-internal.h" |
| f = open(vehicle_internal_h_path, 'r') |
| text = text + f.read() |
| f.close() |
| |
| # Open the vns_policy.xml file |
| vns_policy_path = base_path + "/packages/services/Car/vns_policy/vns_policy.xml" |
| f = open(vns_policy_path, 'w') |
| |
| props = [] |
| property_re = re.compile(RE_PROPERTY_PATTERN, re.MULTILINE | re.DOTALL) |
| for match in property_re.finditer(text): |
| words = match.group(1).split() |
| name = "VEHICLE_PROPERTY_" + match.group(2) |
| value = match.group(3) |
| if (value[0] == "(" and value[-1] == ")"): |
| value = value[1:-1] |
| prop = PropertyInfo(value, name) |
| i = 0 |
| while i < len(words): |
| if words[i] == "@access": |
| i += 1 |
| if words[i].find("READ") > 0: |
| if words[i].find("WRITE") > 0: |
| prop.access = 'rw' |
| else: |
| prop.access = 'r' |
| else: |
| prop.access = 'w' |
| elif words[i] == "@range_start" or words[i] == "@range_end": |
| prop.startEnd = 1 |
| i += 1 |
| props.append(prop) |
| #print prop |
| |
| f.write(XML_HEADER) |
| printProperties(props, f) |
| f.write(XML_TRAIL) |
| |
| if __name__ == '__main__': |
| main(sys.argv) |
| |