Loading src/java/com/android/internal/telephony/configupdate/ConfigParser.java +11 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.internal.telephony.configupdate; import android.annotation.NonNull; import android.annotation.Nullable; import android.util.Log; import java.io.File; import java.io.FileInputStream; Loading @@ -25,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; public abstract class ConfigParser<T> { private static final String TAG = "ConfigParser"; public static final int VERSION_UNKNOWN = -1; Loading Loading @@ -97,4 +99,13 @@ public abstract class ConfigParser<T> { * @param data the config data */ protected abstract void parseData(@Nullable byte[] data); /** * This API is used by CTS to override the version */ protected void overrideVersion(int version) { mVersion = version; Log.d(TAG, "overrideVersion: mVersion=" + mVersion); } } src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java +100 −3 Original line number Diff line number Diff line Loading @@ -52,16 +52,21 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) protected static final String NEW_CONFIG_CONTENT_PATH = "new_telephony_config.pb"; protected static final String VALID_CONFIG_CONTENT_PATH = "valid_telephony_config.pb"; private static final String BACKUP_CONTENT_PATH = "backup_telephony_config.pb"; protected static final String UPDATE_METADATA_PATH = "metadata/"; public static final String VERSION = "version"; public static final String BACKUP_VERSION = "backup_version"; private ConcurrentHashMap<Executor, Callback> mCallbackHashMap = new ConcurrentHashMap<>(); @NonNull private final Object mConfigParserLock = new Object(); @GuardedBy("mConfigParserLock") private ConfigParser mConfigParser; @NonNull private final ConfigUpdaterMetricsStats mConfigUpdaterMetricsStats; @NonNull private final ConfigUpdaterMetricsStats mConfigUpdaterMetricsStats; private int mOriginalVersion; public static TelephonyConfigUpdateInstallReceiver sReceiverAdaptorInstance = new TelephonyConfigUpdateInstallReceiver(); Loading Loading @@ -139,6 +144,10 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec @Override @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED) public void postInstall(Context context, Intent intent) { postInstall(); } private void postInstall() { Log.d(TAG, "Telephony config is updated in file partition"); ConfigParser newConfigParser = getNewConfigParser(DOMAIN_SATELLITE, Loading Loading @@ -327,4 +336,92 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec } return true; } /** * This API is used by CTS to override the version of the config data * * @param reset Whether to restore the original version * @param version The overriding version * @return {@code true} if successful, {@code false} otherwise */ public boolean overrideVersion(boolean reset, int version) { Log.d(TAG, "overrideVersion: reset=" + reset + ", version=" + version); if (reset) { version = mOriginalVersion; if (!restoreContentData()) { return false; } } else { mOriginalVersion = version; if (!backupContentData()) { return false; } } return overrideVersion(version); } private boolean overrideVersion(int version) { synchronized (getInstance().mConfigParserLock) { try { writeUpdate(updateDir, updateVersion, new ByteArrayInputStream(Long.toString(version).getBytes())); if (getInstance().mConfigParser != null) { getInstance().mConfigParser.overrideVersion(version); } } catch (IOException e) { Log.e(TAG, "overrideVersion: e=" + e); return false; } return true; } } private boolean isFileExists(@NonNull String fileName) { Log.d(TAG, "isFileExists"); if (fileName == null) { Log.d(TAG, "fileName cannot be null"); return false; } File sourceFile = new File(UPDATE_DIR, fileName); return sourceFile.exists() && sourceFile.isFile(); } private boolean backupContentData() { if (!isFileExists(VALID_CONFIG_CONTENT_PATH)) { Log.d(TAG, VALID_CONFIG_CONTENT_PATH + " is not exit, no need to backup"); return true; } if (!copySourceFileToTargetFile(VALID_CONFIG_CONTENT_PATH, BACKUP_CONTENT_PATH)) { Log.e(TAG, "backupContentData: fail to backup the config data"); return false; } if (!copySourceFileToTargetFile(UPDATE_METADATA_PATH + VERSION, UPDATE_METADATA_PATH + BACKUP_VERSION)) { Log.e(TAG, "bakpuackupContentData: fail to backup the version"); return false; } Log.d(TAG, "backupContentData: backup success"); return true; } private boolean restoreContentData() { if (!isFileExists(BACKUP_CONTENT_PATH)) { Log.d(TAG, BACKUP_CONTENT_PATH + " is not exit, no need to restore"); return true; } if (!copySourceFileToTargetFile(BACKUP_CONTENT_PATH, NEW_CONFIG_CONTENT_PATH)) { Log.e(TAG, "restoreContentData: fail to restore the config data"); return false; } if (!copySourceFileToTargetFile(UPDATE_METADATA_PATH + BACKUP_VERSION, UPDATE_METADATA_PATH + VERSION)) { Log.e(TAG, "restoreContentData: fail to restore the version"); return false; } Log.d(TAG, "restoreContentData: populate the data to SatelliteController"); postInstall(); Log.d(TAG, "restoreContentData: success"); return true; } } Loading
src/java/com/android/internal/telephony/configupdate/ConfigParser.java +11 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.internal.telephony.configupdate; import android.annotation.NonNull; import android.annotation.Nullable; import android.util.Log; import java.io.File; import java.io.FileInputStream; Loading @@ -25,6 +26,7 @@ import java.io.IOException; import java.io.InputStream; public abstract class ConfigParser<T> { private static final String TAG = "ConfigParser"; public static final int VERSION_UNKNOWN = -1; Loading Loading @@ -97,4 +99,13 @@ public abstract class ConfigParser<T> { * @param data the config data */ protected abstract void parseData(@Nullable byte[] data); /** * This API is used by CTS to override the version */ protected void overrideVersion(int version) { mVersion = version; Log.d(TAG, "overrideVersion: mVersion=" + mVersion); } }
src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java +100 −3 Original line number Diff line number Diff line Loading @@ -52,16 +52,21 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE) protected static final String NEW_CONFIG_CONTENT_PATH = "new_telephony_config.pb"; protected static final String VALID_CONFIG_CONTENT_PATH = "valid_telephony_config.pb"; private static final String BACKUP_CONTENT_PATH = "backup_telephony_config.pb"; protected static final String UPDATE_METADATA_PATH = "metadata/"; public static final String VERSION = "version"; public static final String BACKUP_VERSION = "backup_version"; private ConcurrentHashMap<Executor, Callback> mCallbackHashMap = new ConcurrentHashMap<>(); @NonNull private final Object mConfigParserLock = new Object(); @GuardedBy("mConfigParserLock") private ConfigParser mConfigParser; @NonNull private final ConfigUpdaterMetricsStats mConfigUpdaterMetricsStats; @NonNull private final ConfigUpdaterMetricsStats mConfigUpdaterMetricsStats; private int mOriginalVersion; public static TelephonyConfigUpdateInstallReceiver sReceiverAdaptorInstance = new TelephonyConfigUpdateInstallReceiver(); Loading Loading @@ -139,6 +144,10 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec @Override @VisibleForTesting(visibility = VisibleForTesting.Visibility.PROTECTED) public void postInstall(Context context, Intent intent) { postInstall(); } private void postInstall() { Log.d(TAG, "Telephony config is updated in file partition"); ConfigParser newConfigParser = getNewConfigParser(DOMAIN_SATELLITE, Loading Loading @@ -327,4 +336,92 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec } return true; } /** * This API is used by CTS to override the version of the config data * * @param reset Whether to restore the original version * @param version The overriding version * @return {@code true} if successful, {@code false} otherwise */ public boolean overrideVersion(boolean reset, int version) { Log.d(TAG, "overrideVersion: reset=" + reset + ", version=" + version); if (reset) { version = mOriginalVersion; if (!restoreContentData()) { return false; } } else { mOriginalVersion = version; if (!backupContentData()) { return false; } } return overrideVersion(version); } private boolean overrideVersion(int version) { synchronized (getInstance().mConfigParserLock) { try { writeUpdate(updateDir, updateVersion, new ByteArrayInputStream(Long.toString(version).getBytes())); if (getInstance().mConfigParser != null) { getInstance().mConfigParser.overrideVersion(version); } } catch (IOException e) { Log.e(TAG, "overrideVersion: e=" + e); return false; } return true; } } private boolean isFileExists(@NonNull String fileName) { Log.d(TAG, "isFileExists"); if (fileName == null) { Log.d(TAG, "fileName cannot be null"); return false; } File sourceFile = new File(UPDATE_DIR, fileName); return sourceFile.exists() && sourceFile.isFile(); } private boolean backupContentData() { if (!isFileExists(VALID_CONFIG_CONTENT_PATH)) { Log.d(TAG, VALID_CONFIG_CONTENT_PATH + " is not exit, no need to backup"); return true; } if (!copySourceFileToTargetFile(VALID_CONFIG_CONTENT_PATH, BACKUP_CONTENT_PATH)) { Log.e(TAG, "backupContentData: fail to backup the config data"); return false; } if (!copySourceFileToTargetFile(UPDATE_METADATA_PATH + VERSION, UPDATE_METADATA_PATH + BACKUP_VERSION)) { Log.e(TAG, "bakpuackupContentData: fail to backup the version"); return false; } Log.d(TAG, "backupContentData: backup success"); return true; } private boolean restoreContentData() { if (!isFileExists(BACKUP_CONTENT_PATH)) { Log.d(TAG, BACKUP_CONTENT_PATH + " is not exit, no need to restore"); return true; } if (!copySourceFileToTargetFile(BACKUP_CONTENT_PATH, NEW_CONFIG_CONTENT_PATH)) { Log.e(TAG, "restoreContentData: fail to restore the config data"); return false; } if (!copySourceFileToTargetFile(UPDATE_METADATA_PATH + BACKUP_VERSION, UPDATE_METADATA_PATH + VERSION)) { Log.e(TAG, "restoreContentData: fail to restore the version"); return false; } Log.d(TAG, "restoreContentData: populate the data to SatelliteController"); postInstall(); Log.d(TAG, "restoreContentData: success"); return true; } }