• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright (C) 2020 Google LLC
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17###############################################################################
18# Input files and output directory: can be customized.
19INPUT_CARRIERCONFIG_XML_FILE="packages/apps/CarrierConfig/res/xml/vendor.xml"
20INPUT_CARRIERCONFIG_ASSETS_DIR="packages/apps/CarrierConfig/assets"
21INPUT_APNS_XML_FILE="device/sample/etc/apns-full-conf.xml"
22OUTPUT_DIR="/tmp/CarrierSettings/etc"
23###############################################################################
24
25( # start sub-shell so can use 'set -e' to abort on any failure
26set -e
27
28# 1. Build tools
29echo 'step 1. Building tools ...'
30m CarrierConfigConverterV2 update_apn update_carrier_data GenCarrierList GenDeviceSettings
31echo 'Done.'
32
33echo 'step 2. Converting config files ...'
34# 2a. Create a temp directory as workspace
35TMP_DIR=$(mktemp -d -t cs-XXXXXXX)
36DATA_SETTING_DIR=$TMP_DIR/data/setting
37DATA_DEVICE_DIR=$TMP_DIR/data/device
38ASSETS_DIR=$TMP_DIR/assets
39INNER_TMP_DIR=$TMP_DIR/tmp
40TIER1_CARRIERS_FILE=$TMP_DIR/data/tier1_carriers.textpb
41DEVICE_FILE=$DATA_DEVICE_DIR/device.textpb
42mkdir -p "$DATA_SETTING_DIR" > /dev/null
43mkdir -p "$DATA_DEVICE_DIR" > /dev/null
44mkdir -p "$ASSETS_DIR" > /dev/null
45mkdir -p "$INNER_TMP_DIR" > /dev/null
46touch "$TIER1_CARRIERS_FILE" > /dev/null
47touch "$DEVICE_FILE" > /dev/null
48
49# 2b. Copy input files to workspace
50cp $INPUT_CARRIERCONFIG_XML_FILE "$TMP_DIR"/vendor.xml > /dev/null
51cp $INPUT_CARRIERCONFIG_ASSETS_DIR/* "$ASSETS_DIR"/ > /dev/null
52cp $INPUT_APNS_XML_FILE "$TMP_DIR"/apns-full-conf.xml > /dev/null
53
54# 2c. Convert XMLs to TEXTPB
55
56EPOCH=$(date -d '2018-06-01T00:00:00Z' +%s)
57NOW=$(date +%s)
58TIMESTAMP="$((NOW-EPOCH))"
59# Use TIMESTAMP as version number
60# To customize the version number, assign the customized value to VERSION.
61VERSION="$TIMESTAMP"
62
63SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
64UPDATE_APN=$SCRIPT_DIR/bin/update_apn
65[ -x "$UPDATE_APN" ] || UPDATE_APN=out/host/linux-x86/bin/update_apn
66UPDATE_CARRIER_DATA=$SCRIPT_DIR/bin/update_carrier_data
67[ -x "$UPDATE_CARRIER_DATA" ] || UPDATE_CARRIER_DATA=out/host/linux-x86/bin/update_carrier_data
68
69# To use multiple vendor.xml files, just provide multiple `--vendor_xml=___.xml`
70# lines in the command below. The order decides config precedence: a file is
71# overwritten by files AFTER it.
72out/host/linux-x86/bin/CarrierConfigConverterV2 \
73  --output_dir="$TMP_DIR"/data \
74  --vendor_xml="$TMP_DIR"/vendor.xml \
75  --assets="$ASSETS_DIR"/ \
76  --version=$VERSION > /dev/null
77"$UPDATE_APN" \
78  --apn_file="$TMP_DIR"/apns-full-conf.xml \
79  --data_dir="$TMP_DIR"/data \
80  --out_file="$INNER_TMP_DIR"/apns.textpb
81"$UPDATE_CARRIER_DATA" \
82  --data_dir="$TMP_DIR"/data \
83  --in_file="$INNER_TMP_DIR"/apns.textpb
84
85# 2d. Convert TEXTPB to PB
86mkdir -p "$INNER_TMP_DIR"/pb > /dev/null
87mkdir -p "$INNER_TMP_DIR"/textpb > /dev/null
88
89out/host/linux-x86/bin/GenCarrierList \
90  --version_offset=0 \
91  --with_version_number \
92  --out_pb="$INNER_TMP_DIR"/carrier_list.pb \
93  --in_textpbs="$TIER1_CARRIERS_FILE","$TMP_DIR"/data/other_carriers.textpb \
94  > /dev/null
95mv "$INNER_TMP_DIR"/carrier_list*.pb "$INNER_TMP_DIR"/pb > /dev/null
96mv "$INNER_TMP_DIR"/carrier_list.textpb "$INNER_TMP_DIR"/textpb > /dev/null
97
98for device in "$DATA_DEVICE_DIR"/*.textpb; do
99  [[ -e "$device" ]] || break
100  device=${device%.*} && device=${device##*/} \
101  && device_dir="${INNER_TMP_DIR}/${device}" && mkdir -p "${INNER_TMP_DIR}" \
102  && mkdir -p "${INNER_TMP_DIR}/textpb/${device}" > /dev/null \
103  && out/host/linux-x86/bin/GenDeviceSettings \
104  --device_overlay="$DATA_DEVICE_DIR/${device}.textpb" \
105  --base_setting_dir="$DATA_SETTING_DIR" \
106  --device_setting_dir="${device_dir}" \
107  --version_offset=0 \
108  --with_device_name="${device}" \
109  --with_version_number > /dev/null \
110  && mv "${device_dir}"/*.pb "${INNER_TMP_DIR}/pb" > /dev/null \
111  && mv "${device_dir}"/*.textpb "${INNER_TMP_DIR}/textpb/${device}" > /dev/null \
112  && rmdir "${device_dir}"
113done
114
115echo 'Done.'
116
117echo 'step 3. Copy generated files to output directory ...'
118
119mkdir -p $OUTPUT_DIR > /dev/null
120rm -rf "${OUTPUT_DIR:?}"/* > /dev/null
121cp -r "$INNER_TMP_DIR"/pb  $OUTPUT_DIR > /dev/null
122cp -r "$INNER_TMP_DIR"/textpb  $OUTPUT_DIR > /dev/null
123rm -rf "${TMP_DIR:?}" > /dev/null
124
125echo 'Generated files:'
126find $OUTPUT_DIR -type f
127
128echo 'Done.'
129) # end sub-shell
130