Add ecc database and conversion toolset v1.
Test: Manually
Bug: 111674784
Change-Id: I94b9b95b014958d90ee1251fcd872c227f450a82
diff --git a/ecc/conversion_toolset_v1/env.sh b/ecc/conversion_toolset_v1/env.sh
new file mode 100644
index 0000000..23d9f10
--- /dev/null
+++ b/ecc/conversion_toolset_v1/env.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+set -o errexit
+
+# Copyright 2018 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.
+
+INPUT_DATA="${INPUT_DIR}/eccdata.txt"
+OUTPUT_DATA="${OUTPUT_DIR}/eccdata"
+PROTOBUF_DIR="${LOCAL_TOOLSET_DIR}/proto"
+PROTOBUF_FILE="${PROTOBUF_DIR}/protobuf_ecc_data.proto"
+RAW_DATA="${INTERMEDIATE_DIR}/eccdata.raw"
+
+read -d "" PYTHON_COMMAND << END || :
+${ANDROID_BUILD_TOP}/prebuilts/python/${KERNEL}-x86/2.7.5/bin/python
+END
+PYTHONPATH="${PYTHONPATH}:${INTERMEDIATE_DIR}"
+PYTHONPATH="${PYTHONPATH}:${ANDROID_BUILD_TOP}/external/nanopb-c/generator/"
+
+if ! [ -x "${PYTHON_COMMAND}" ] ; then
+ echo "Missing ${PYTHON_COMMAND}." 1>&2
+ exit 1
+fi
+
+"${PROTOC_COMMAND}" \
+ --python_out="${INTERMEDIATE_DIR}" \
+ --proto_path="${PROTOBUF_DIR}" \
+ "${PROTOBUF_FILE}"
diff --git a/ecc/conversion_toolset_v1/gen_eccdata.sh b/ecc/conversion_toolset_v1/gen_eccdata.sh
new file mode 100644
index 0000000..8dd751f
--- /dev/null
+++ b/ecc/conversion_toolset_v1/gen_eccdata.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+set -o errexit
+
+# Copyright 2018 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.
+
+LOCAL_TOOLSET_DIR="${ECC_ROOT}/conversion_toolset_v1"
+source "${LOCAL_TOOLSET_DIR}/env.sh"
+
+${ANDROID_BUILD_TOP}/prebuilts/tools/linux-x86_64/protoc/bin/protoc \
+ --encode=ecc.AllInfo proto/protobuf_ecc_data.proto \
+ < "${INPUT_DATA}" > "${RAW_DATA}"
+
+echo
+echo "Starting strict verification"
+"${PYTHON_COMMAND}" -B \
+ "${LOCAL_TOOLSET_DIR}/verify_protobuf_compatibility.py" \
+ --input="${RAW_DATA}" --strict
+echo "Passed strict verification"
+
+echo
+echo "Compressing and encoding eccdata"
+gzip -c < "${RAW_DATA}" > "${OUTPUT_DATA}"
+echo "Done"
+
diff --git a/ecc/conversion_toolset_v1/proto/protobuf_ecc_data.proto b/ecc/conversion_toolset_v1/proto/protobuf_ecc_data.proto
new file mode 100644
index 0000000..5bd7bc3
--- /dev/null
+++ b/ecc/conversion_toolset_v1/proto/protobuf_ecc_data.proto
@@ -0,0 +1,56 @@
+syntax = "proto2";
+
+package ecc;
+
+option java_package = "com.android.phone.ecc";
+option java_outer_classname = "ProtobufEccData";
+
+// EccInfo represents an Emergency Call Code (i.e. an emergency phone
+// number such as 911, 112, ...)
+message EccInfo {
+ enum Type {
+ TYPE_UNSPECIFIED = 0;
+ POLICE = 1;
+ AMBULANCE = 2;
+ FIRE = 3;
+ }
+
+ // Required: Every EccInfo shall contain a phone number.
+ optional string phone_number = 1;
+
+ // Extra rules: Every Ecc should have at least 1 valid type.
+ repeated Type types = 2 [packed=true];
+}
+
+// CountryInfo represents available ECCs of a country/region, recognized
+// with ISO country code.
+message CountryInfo {
+ // Required: Every CountryInfo shall contain a ISO country code.
+ optional string iso_code = 1;
+
+ // Extra rules: There should be at least one EccInfo in this list.
+ repeated EccInfo eccs = 2;
+
+ // Required: Every CountryInfo shall contain a fallback number, shall
+ // be either 112 or 911.
+ //
+ // If an emergency number in EccInfo is declined by ril.ecclist, this
+ // fallback number may take the place.
+ //
+ // Per http://www.etsi.org/deliver/etsi_ts/122100_122199/122101/09.01.00_60/ts_122101v090100p.pdf,
+ // 112 and 911 shall always be available.
+ optional string ecc_fallback = 3;
+}
+
+message AllInfo {
+ // The revision value in ecc/input/eccdata.json should be increased
+ // before releasing a new content.
+ //
+ // This field is not used to compare data revision for online updating.
+ // It's reserved for identifying ecc info problems.
+ optional int32 revision = 1;
+
+ // Extra rules: There should be at least one CountryInfo in this list.
+ repeated CountryInfo countries = 2;
+}
+
diff --git a/ecc/conversion_toolset_v1/verify_eccdata_compatibility.sh b/ecc/conversion_toolset_v1/verify_eccdata_compatibility.sh
new file mode 100644
index 0000000..8686722
--- /dev/null
+++ b/ecc/conversion_toolset_v1/verify_eccdata_compatibility.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+set -o errexit
+
+# Copyright 2018 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.
+
+LOCAL_TOOLSET_DIR="${ECC_ROOT}/conversion_toolset_v1"
+source "${LOCAL_TOOLSET_DIR}/env.sh"
+
+echo "Starting compatibility verification v1"
+echo "Decoding and decompressing eccdata"
+gunzip -c < "${OUTPUT_DATA}" > "${RAW_DATA}"
+${PYTHON_COMMAND} -B \
+ "${LOCAL_TOOLSET_DIR}/verify_protobuf_compatibility.py" \
+ --input="${RAW_DATA}"
+echo "Passed compatibility verification v1"
+
diff --git a/ecc/conversion_toolset_v1/verify_protobuf_compatibility.py b/ecc/conversion_toolset_v1/verify_protobuf_compatibility.py
new file mode 100644
index 0000000..bc707eb
--- /dev/null
+++ b/ecc/conversion_toolset_v1/verify_protobuf_compatibility.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python -B
+
+# Copyright 2018 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.
+
+# Notice:
+# - verify_eccdata_strict.py: Verify data which is generated by this
+# version of this toolset.
+# - verify_eccdata_compatibility.py: Verify data which is generated by any
+# newer version of this tool set for ensuring backward compatibility.
+
+import sys
+import argparse
+import protobuf_ecc_data_pb2
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--input", required=True)
+parser.add_argument("--strict", action="store_true")
+args = parser.parse_args()
+
+all_ecc_info = protobuf_ecc_data_pb2.AllInfo()
+
+with open(args.input, "rb") as ecc_data_source_file:
+ all_ecc_info.ParseFromString(ecc_data_source_file.read())
+
+if (args.strict):
+ print("Verify in strict mode")
+
+assert all_ecc_info.HasField("revision")
+assert all_ecc_info.revision > 0
+assert len(all_ecc_info.countries) > 0
+
+loaded_iso = []
+for country_info in all_ecc_info.countries:
+ assert country_info.HasField("iso_code")
+ assert len(country_info.iso_code) > 0
+ assert country_info.iso_code == country_info.iso_code.strip().upper()
+ assert country_info.iso_code not in loaded_iso
+ loaded_iso.append(country_info.iso_code)
+ assert country_info.HasField("ecc_fallback")
+ assert len(country_info.ecc_fallback) > 0
+
+ if len(country_info.eccs) > 0:
+ loaded_phone_number = []
+ for ecc_info in country_info.eccs:
+ assert ecc_info.HasField("phone_number")
+ phone_number = ecc_info.phone_number.strip()
+ assert len(phone_number) > 0
+ assert phone_number not in loaded_phone_number
+ loaded_phone_number.append(phone_number)
+
+ if (args.strict):
+ assert len(ecc_info.types) > 0
+ loaded_types = []
+ for ecc_type in ecc_info.types:
+ assert ecc_type == protobuf_ecc_data_pb2.EccInfo.POLICE or \
+ ecc_type == protobuf_ecc_data_pb2.EccInfo.AMBULANCE or \
+ ecc_type == protobuf_ecc_data_pb2.EccInfo.FIRE
+ assert ecc_type not in loaded_types
+ loaded_types.append(ecc_type)
+ else:
+ # For forward compatibility, ecc_info.types could be null if a phone
+ # number contains only new types which is not defined now. Just leave
+ # a warning message for this case.
+ if len(ecc_info.types) == 0:
+ print("WARNING: No recognizable type for " + \
+ country_info.iso_code + " - " + ecc_info.phone_number)
+ else:
+ loaded_types = []
+ for ecc_type in ecc_info.types:
+ assert ecc_type not in loaded_types
+ loaded_types.append(ecc_type)
+ elif (args.strict):
+ print("Warning: Empty ecc list for country " + country_info.iso_code)