diff options
author | 2025-03-15 04:33:56 -0700 | |
---|---|---|
committer | 2025-03-15 04:33:56 -0700 | |
commit | 66e8a5a00ba353a355750e2046748dad5bc1620b (patch) | |
tree | d58ffd7bd2c9b6e0e747601c72aef5ff2f8b9e50 /src | |
parent | 1378341f4b6cae112b3e407ffcf61f1aae0044dd (diff) | |
parent | cf6acd5f461941168708a6b852247cf1433677d7 (diff) |
Merge "Support overrding data version and backup/restore config data for CTS" into main
Diffstat (limited to 'src')
-rw-r--r-- | src/java/com/android/internal/telephony/configupdate/ConfigParser.java | 11 | ||||
-rw-r--r-- | src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java | 103 |
2 files changed, 111 insertions, 3 deletions
diff --git a/src/java/com/android/internal/telephony/configupdate/ConfigParser.java b/src/java/com/android/internal/telephony/configupdate/ConfigParser.java index 5c3ac866df..f7691da908 100644 --- a/src/java/com/android/internal/telephony/configupdate/ConfigParser.java +++ b/src/java/com/android/internal/telephony/configupdate/ConfigParser.java @@ -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; @@ -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; @@ -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); + } } diff --git a/src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java b/src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java index b299411ce4..60afc799c8 100644 --- a/src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java +++ b/src/java/com/android/internal/telephony/configupdate/TelephonyConfigUpdateInstallReceiver.java @@ -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(); @@ -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, @@ -311,11 +320,11 @@ public class TelephonyConfigUpdateInstallReceiver extends ConfigUpdateInstallRec new ByteArrayInputStream(Integer.toString(-1).getBytes())); // new_telephony_config.pb - writeUpdate(updateDir, updateContent, new ByteArrayInputStream(new byte[] {})); + writeUpdate(updateDir, updateContent, new ByteArrayInputStream(new byte[]{})); // valid_telephony_config.pb File validConfigContentPath = new File(updateDir, VALID_CONFIG_CONTENT_PATH); - writeUpdate(updateDir, validConfigContentPath, new ByteArrayInputStream(new byte[] {})); + writeUpdate(updateDir, validConfigContentPath, new ByteArrayInputStream(new byte[]{})); } catch (IOException e) { Log.e(TAG, "Failed to clean telephony config files: " + e); return false; @@ -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; + } } |