Improve carrier id testability
Add test purpose only path to let OEM/carrier override carrier_list.pb
without building whole system image.
Bug: 159682790
Test: Push test pb and check db.
Change-Id: Icfdee63cfa04c1fa94a473c559d4fe5db714be05
diff --git a/assets/README b/assets/README
index ad6a29c..43b0965 100644
--- a/assets/README
+++ b/assets/README
@@ -10,3 +10,50 @@
DO NOT MANUALLY EDIT THIS FILE
This file defines carrier id and should be single versioned.
+
+===== How to test carrier id locally =====
+
+If you want to make change locally during testing, currently there are two ways:
+
+1. Modify carrierIdentification.db database by SQL command
+
+For example (Insert MCCMNC '12345' and gid1 'test' to carrier id 20000):
+```
+$ adb shell
+device:/ $ su
+device:/ # DB='/data/user_de/0/com.android.providers.telephony/databases/carrierIdentification.db'
+device:/ # sqlite3 $DB "INSERT INTO carrier_id(mccmnc, gid1, carrier_id, carrier_name) VALUES (12345, 'test', 20000, 'test_carrier')"
+device:/ # reboot
+```
+
+2. Override carrier_list.pb
+
+- Modify carrier_list.textpb directly (Note: You should also bump the version
+ number to let TelephonyProvider reload the carrier_list.pb)
+- Generate class file by using the carrier id proto(TelephonyProvider/proto/src/carrierId.proto)
+ (See https://developers.google.com/protocol-buffers/docs/overview#generating)
+- Create a converter by using TextFormat tool to convert textpb to pb
+ (Text Format: https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/TextFormat)
+- Rename file to carrier_list_test.pb and push the output file to
+ /data/user_de/0/com.android.providers.telephony/files/carrier_list_test.pb
+- Reboot the device
+
+Converter example:
+```
+#!/usr/bin/env python3
+from google.protobuf import text_format
+
+# Generated by: protoc -I=./ --python_out=./ ./carrierId.proto
+from carrierId_pb2 import CarrierList
+
+def main():
+ with open("carrier_list.textpb", "r") as rd:
+ carrierList = CarrierList()
+ text_format.Merge(rd.read(), carrierList)
+
+ with open("carrier_list.pb", "wb") as wf:
+ wf.write(carrierList.SerializeToString())
+
+if __name__ == '__main__':
+ main()
+```
diff --git a/src/com/android/providers/telephony/CarrierIdProvider.java b/src/com/android/providers/telephony/CarrierIdProvider.java
index 44f053d..1f5ad02 100644
--- a/src/com/android/providers/telephony/CarrierIdProvider.java
+++ b/src/com/android/providers/telephony/CarrierIdProvider.java
@@ -85,6 +85,9 @@
private static final int VERSION_BITMASK = 0x00FFFFFF;
private static final String OTA_UPDATED_PB_PATH = "misc/carrierid/" + ASSETS_PB_FILE;
private static final String PREF_FILE = CarrierIdProvider.class.getSimpleName();
+ // For testing purposes only.
+ private static final String OVERRIDE_PB_PATH =
+ "/data/user_de/0/com.android.providers.telephony/files/carrier_list_test.pb";
private static final UriMatcher s_urlMatcher = new UriMatcher(UriMatcher.NO_MATCH);
@@ -529,9 +532,14 @@
CarrierIdProto.CarrierList assets = null;
CarrierIdProto.CarrierList ota = null;
InputStream is = null;
+ File testFile = new File(OVERRIDE_PB_PATH);
try {
- is = getContext().getAssets().open(ASSETS_PB_FILE);
+ if (Build.IS_DEBUGGABLE && testFile.exists()) {
+ is = new FileInputStream(testFile);
+ } else {
+ is = getContext().getAssets().open(ASSETS_PB_FILE);
+ }
assets = CarrierIdProto.CarrierList.parseFrom(readInputStreamToByteArray(is));
} catch (IOException ex) {
Log.e(TAG, "read carrier list from assets pb failure: " + ex);