Apply telephony_config_json_parser for satellite accesss control
Bug: 349604674
flag: com.android.internal.telephony.flags.carrier_roaming_nb_iot_ntn
Test: atest
SatelliteAccessConfigurationParserTest(http://ab/I04800010335080673-passed)
Test: Manually verified if the json file is parsed well.
Change-Id: If806a37bd7defdb42916b3570845bb5057260be0
diff --git a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParser.java b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParser.java
new file mode 100644
index 0000000..0658279
--- /dev/null
+++ b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParser.java
@@ -0,0 +1,392 @@
+/*
+ * Copyright (C) 2024 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.
+ */
+
+package com.android.phone.satellite.accesscontrol;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.net.ParseException;
+import android.os.Build;
+import android.telephony.satellite.EarfcnRange;
+import android.telephony.satellite.SatelliteAccessConfiguration;
+import android.telephony.satellite.SatelliteInfo;
+import android.telephony.satellite.SatellitePosition;
+import android.util.Log;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.ByteArrayOutputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+public class SatelliteAccessConfigurationParser {
+ private static final String TAG = "SatelliteAccessConfigurationParser";
+
+ public static final String SATELLITE_ACCESS_CONTROL_CONFIGS = "access_control_configs";
+ public static final String SATELLITE_CONFIG_ID = "config_id";
+ public static final String SATELLITE_INFOS = "satellite_infos";
+ public static final String SATELLITE_ID = "satellite_id";
+ public static final String SATELLITE_POSITION = "satellite_position";
+ public static final String SATELLITE_LONGITUDE = "longitude";
+ public static final String SATELLITE_ALTITUDE = "altitude";
+ public static final String SATELLITE_EARFCN_RANGES = "earfcn_ranges";
+ public static final String SATELLITE_START_EARFCN = "start_earfcn";
+ public static final String SATELLITE_END_EARFCN = "end_earfcn";
+ public static final String SATELLITE_BANDS = "bands";
+ public static final String SATELLITE_TAG_ID_LIST = "tag_ids";
+
+
+ /**
+ * Parses a JSON file containing satellite access configurations.
+ *
+ * @param fileName The name of the JSON file to parse.
+ * @return A map of satellite access configurations, keyed by config ID.
+ * @throws RuntimeException if the JSON file cannot be parsed or if a required field is missing.
+ */
+ @Nullable
+ public static Map<Integer, SatelliteAccessConfiguration> parse(@NonNull String fileName) {
+ logd("SatelliteAccessConfigurationParser: parse: " + fileName);
+ Map<Integer, SatelliteAccessConfiguration> satelliteAccessConfigurationMap;
+
+ try {
+ String jsonString = readJsonStringFromFile(fileName);
+ JSONObject satelliteAccessConfigJsonObject = new JSONObject(jsonString);
+ JSONArray configurationArrayJson = satelliteAccessConfigJsonObject.optJSONArray(
+ SATELLITE_ACCESS_CONTROL_CONFIGS);
+
+ if (configurationArrayJson == null) {
+ loge("parse : failed to parse satellite access configurations json");
+ return null;
+ }
+
+ satelliteAccessConfigurationMap =
+ parseSatelliteAccessConfigurations(configurationArrayJson);
+
+ } catch (JSONException | ParseException e) {
+ loge("Failed to parse satellite access configurations: " + e.getMessage());
+ throw new RuntimeException(e);
+ }
+
+ logd("satelliteAccessConfigurationMap= " + satelliteAccessConfigurationMap);
+ return satelliteAccessConfigurationMap;
+ }
+
+ private static void logd(String log) {
+ if (!Build.TYPE.equals("user")) {
+ Log.d(TAG, log);
+ }
+ }
+
+ private static void loge(String log) {
+ Log.e(TAG, log);
+ }
+
+ @NonNull
+ protected static List<Integer> parseSatelliteTagIdList(@NonNull JSONObject satelliteInfoJson) {
+ List<Integer> tagIdList = new ArrayList<>();
+ try {
+ JSONArray tagIdArray = satelliteInfoJson.optJSONArray(SATELLITE_TAG_ID_LIST);
+ tagIdList = parseIntegerList(tagIdArray);
+ } catch (JSONException e) {
+ loge("parseSatelliteInfo: parsing is error");
+ return tagIdList;
+ }
+
+ logd("parseSatelliteBandList: " + tagIdList);
+ return tagIdList;
+ }
+
+ @Nullable
+ private static Map<Integer, SatelliteAccessConfiguration> parseSatelliteAccessConfigurations(
+ JSONArray satelliteAccessConfigurationJsonArray) throws JSONException {
+ Map<Integer, SatelliteAccessConfiguration> satelliteConfigMap = new HashMap<>();
+ if (satelliteAccessConfigurationJsonArray == null) {
+ loge("parseSatelliteAccessConfigurations: jsonArray is null, return null");
+ return null;
+ }
+
+ for (int i = 0; i < satelliteAccessConfigurationJsonArray.length(); i++) {
+ JSONObject satelliteAccessConfigurationJson =
+ satelliteAccessConfigurationJsonArray.getJSONObject(i);
+
+ int configId = satelliteAccessConfigurationJson.optInt(SATELLITE_CONFIG_ID, -1);
+ if (!isRegionalConfigIdValid(configId)) {
+ loge("parseAccessControlConfigs: invalid config_id, return null");
+ return null;
+ }
+
+ JSONArray satelliteInfoJsonArray = satelliteAccessConfigurationJson
+ .getJSONArray(SATELLITE_INFOS);
+ List<SatelliteInfo> satelliteInfoList = parseSatelliteInfoList(satelliteInfoJsonArray);
+ if (satelliteInfoList.isEmpty()) {
+ logd("parseAccessControlConfigs: satelliteInfoList is empty");
+ }
+
+ List<Integer> tagIdList = parseSatelliteTagIdList(satelliteAccessConfigurationJson);
+ if (satelliteInfoList.isEmpty() && tagIdList.isEmpty()) {
+ loge("parseAccessControlConfigs: satelliteInfoList is empty and tagId is null");
+ return null;
+ }
+
+ satelliteConfigMap.put(configId,
+ new SatelliteAccessConfiguration(satelliteInfoList, tagIdList));
+ }
+
+ logd("parseSatelliteAccessConfigurations: " + satelliteConfigMap);
+ return satelliteConfigMap;
+ }
+
+ /**
+ * Checks if a regional configuration ID is valid.
+ * A valid regional configuration ID is a non-null integer that is greater than or equal to
+ * zero.
+ *
+ * @param configId The regional configuration ID to check.
+ * @return {@code true} if the ID is valid, {@code false} otherwise.
+ */
+ public static boolean isRegionalConfigIdValid(@Nullable Integer configId) {
+ return (configId != null && configId >= 0);
+ }
+
+ @Nullable
+ protected static UUID parseSatelliteId(@NonNull JSONObject satelliteInfoJson) {
+ String uuidString = satelliteInfoJson.optString(SATELLITE_ID, null);
+ UUID satelliteId;
+ if (uuidString != null) {
+ try {
+ satelliteId = UUID.fromString(uuidString);
+ } catch (IllegalArgumentException e) {
+ loge("getSatelliteId: invalid UUID format: " + uuidString + " | " + e.getMessage());
+ return null;
+ }
+ } else {
+ loge("getSatelliteId: satellite uuid is missing");
+ return null;
+ }
+
+ logd("getSatelliteId: satellite uuid is " + satelliteId);
+ return satelliteId;
+ }
+
+ @Nullable
+ protected static SatellitePosition parseSatellitePosition(
+ @NonNull JSONObject satelliteInfoJson) {
+ JSONObject jsonObject = satelliteInfoJson.optJSONObject(SATELLITE_POSITION);
+ if (jsonObject == null) {
+ loge("parseSatellitePosition: jsonObject is null");
+ return null;
+ }
+ SatellitePosition satellitePosition;
+ try {
+ double longitude = jsonObject.getDouble(SATELLITE_LONGITUDE);
+ double altitude = jsonObject.getDouble(SATELLITE_ALTITUDE);
+ if (isValidLongitude(longitude) && isValidAltitude(altitude)) {
+ satellitePosition = new SatellitePosition(longitude, altitude);
+ } else {
+ loge("parseSatellitePosition: invalid value: " + longitude + " | " + altitude);
+ return null;
+ }
+ } catch (JSONException e) {
+ loge("parseSatellitePosition: json parsing error " + e.getMessage());
+ return null;
+ }
+
+ logd("parseSatellitePosition: " + satellitePosition);
+ return satellitePosition;
+ }
+
+ @NonNull
+ protected static List<EarfcnRange> parseSatelliteEarfcnRangeList(
+ @NonNull JSONObject satelliteInfoJson) {
+ JSONArray earfcnRangesArray = satelliteInfoJson.optJSONArray(SATELLITE_EARFCN_RANGES);
+ List<EarfcnRange> earfcnRangeList = new ArrayList<>();
+ if (earfcnRangesArray == null) {
+ loge("parseSatelliteEarfcnRangeList: earfcn_ranges is missing");
+ return earfcnRangeList;
+ }
+
+ try {
+ for (int j = 0; j < earfcnRangesArray.length(); j++) {
+ JSONObject earfcnRangeJson = earfcnRangesArray.getJSONObject(j);
+ EarfcnRange earfcnRange = parseEarfcnRange(earfcnRangeJson);
+ if (earfcnRange == null) {
+ loge("parseSatelliteEarfcnRangeList: earfcnRange is null, return empty list");
+ earfcnRangeList.clear();
+ return earfcnRangeList;
+ }
+ earfcnRangeList.add(earfcnRange);
+ }
+ } catch (JSONException e) {
+ loge("parseSatelliteEarfcnRangeList: earfcnRange json parsing error");
+ earfcnRangeList.clear();
+ return earfcnRangeList;
+ }
+ logd("parseSatelliteEarfcnRangeList: " + earfcnRangeList);
+ return earfcnRangeList;
+ }
+
+ @NonNull
+ protected static List<Integer> parseSatelliteBandList(@NonNull JSONObject satelliteInfoJson) {
+ List<Integer> bandList = new ArrayList<>();
+ try {
+ JSONArray bandArray = satelliteInfoJson.getJSONArray(SATELLITE_BANDS);
+ bandList = parseIntegerList(bandArray);
+ } catch (JSONException e) {
+ loge("parseSatelliteInfo: bands parsing is error");
+ return bandList;
+ }
+
+ logd("parseSatelliteBandList: " + bandList);
+ return bandList;
+ }
+
+ @NonNull
+ protected static List<SatelliteInfo> parseSatelliteInfoList(JSONArray satelliteInfojsonArray)
+ throws JSONException {
+ List<SatelliteInfo> satelliteInfoList = new ArrayList<>();
+ for (int i = 0; i < satelliteInfojsonArray.length(); i++) {
+ JSONObject SatelliteInfoJson = satelliteInfojsonArray.getJSONObject(i);
+ if (SatelliteInfoJson == null) {
+ satelliteInfoList.clear();
+ break;
+ }
+ UUID id = parseSatelliteId(SatelliteInfoJson);
+ SatellitePosition position = parseSatellitePosition(SatelliteInfoJson);
+ List<EarfcnRange> earfcnRangeList = parseSatelliteEarfcnRangeList(SatelliteInfoJson);
+ List<Integer> bandList = parseSatelliteBandList(SatelliteInfoJson);
+
+ if (id == null || (bandList.isEmpty() && earfcnRangeList.isEmpty())) {
+ loge("parseSatelliteInfo: id is " + id
+ + " or both band list and earfcn range list are empty");
+ satelliteInfoList.clear();
+ return satelliteInfoList;
+ }
+
+ SatelliteInfo info = new SatelliteInfo(id, position, bandList, earfcnRangeList);
+ satelliteInfoList.add(info);
+ }
+ logd("parseSatelliteInfoList: " + satelliteInfoList);
+ return satelliteInfoList;
+ }
+
+ /**
+ * Load json file from the filePath
+ *
+ * @param jsonFilePath The file path of json file
+ * @return json string type json contents
+ */
+ @Nullable
+ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
+ public static String readJsonStringFromFile(@NonNull String jsonFilePath) {
+ logd("jsonFilePath is " + jsonFilePath);
+ String json = null;
+ try (InputStream inputStream = new FileInputStream(jsonFilePath);
+ ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream()) {
+ byte[] buffer = new byte[1024];
+ int length;
+ while ((length = inputStream.read(buffer)) != -1) {
+ byteArrayStream.write(buffer, 0, length);
+ }
+ json = byteArrayStream.toString(StandardCharsets.UTF_8);
+ } catch (FileNotFoundException e) {
+ loge("Error file " + jsonFilePath + " is not founded: " + e.getMessage());
+ } catch (IOException | NullPointerException e) {
+ loge("Error reading file " + jsonFilePath + ": " + e);
+ } finally {
+ logd("jsonString is " + json);
+ }
+ return json;
+ }
+
+ private static boolean isValidEarfcn(int earfcn) {
+ if (earfcn >= 0 && earfcn <= 65535) {
+ return true;
+ }
+ loge("isValidEarfcn: earfcn value is out of valid range: " + earfcn);
+ return false;
+ }
+
+ private static boolean isValidEarfcnRange(int start, int end) {
+ if (start <= end) {
+ return true;
+ }
+ loge("isValidEarfcnRange: earfcn range start " + start + " is bigger than end " + end);
+ return false;
+ }
+
+ @Nullable
+ private static EarfcnRange parseEarfcnRange(@Nullable JSONObject jsonObject) {
+ logd("parseEarfcnRange");
+ if (jsonObject == null) {
+ loge("parseEarfcnRange: jsonObject is null");
+ return null;
+ }
+ try {
+ int start = jsonObject.getInt(SATELLITE_START_EARFCN);
+ int end = jsonObject.getInt(SATELLITE_END_EARFCN);
+
+ if (isValidEarfcn(start) && isValidEarfcn(end) && isValidEarfcnRange(start, end)) {
+ return new EarfcnRange(start, end);
+ }
+
+ loge("parseEarfcnRange: earfcn value is not valid, return null");
+ return null;
+ } catch (JSONException e) {
+ loge("parseEarfcnRange: json parsing error: " + e.getMessage());
+ return null;
+ }
+ }
+
+ @NonNull
+ private static List<Integer> parseIntegerList(@Nullable JSONArray jsonArray)
+ throws JSONException {
+ List<Integer> intList = new ArrayList<>();
+ if (jsonArray == null) {
+ loge("parseIntegerList: jsonArray is null, return IntArray with empty");
+ return intList;
+ }
+ for (int i = 0; i < jsonArray.length(); i++) {
+ try {
+ intList.add(jsonArray.getInt(i));
+ } catch (JSONException e) {
+ loge("parseIntegerList: jsonArray parsing error: " + e.getMessage());
+ intList.clear();
+ }
+ }
+ logd("parseIntegerList: " + intList);
+ return intList;
+ }
+
+ private static boolean isValidLongitude(double longitude) {
+ return (longitude >= -180.0 && longitude <= 180.0);
+ }
+
+ private static boolean isValidAltitude(double altitude) {
+ return (altitude >= 0);
+ }
+}
diff --git a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
index d0d0e8f..9aca905 100644
--- a/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
+++ b/src/com/android/phone/satellite/accesscontrol/SatelliteAccessController.java
@@ -20,15 +20,16 @@
import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_COMMUNICATION_ALLOWED;
import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_PROVISIONED;
import static android.telephony.satellite.SatelliteManager.KEY_SATELLITE_SUPPORTED;
-import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED;
-import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED;
-import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_IN_ALLOWED_REGION;
-import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP;
import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_LOCATION_DISABLED;
+import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_IN_ALLOWED_REGION;
+import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_PROVISIONED;
+import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_NOT_SUPPORTED;
+import static android.telephony.satellite.SatelliteManager.SATELLITE_DISALLOWED_REASON_UNSUPPORTED_DEFAULT_MSG_APP;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_INVALID_TELEPHONY_STATE;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_LOCATION_DISABLED;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_LOCATION_NOT_AVAILABLE;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_NOT_SUPPORTED;
+import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_NO_RESOURCES;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
@@ -126,6 +127,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@@ -184,7 +186,7 @@
private static final int SATELLITE_DISALLOWED_REASON_NONE = -1;
private static final List<Integer> DISALLOWED_REASONS_TO_BE_RESET =
Arrays.asList(SATELLITE_DISALLOWED_REASON_NOT_IN_ALLOWED_REGION,
- SATELLITE_DISALLOWED_REASON_LOCATION_DISABLED);
+ SATELLITE_DISALLOWED_REASON_LOCATION_DISABLED);
private static final HashMap<Integer, Pair<Integer, Integer>>
SATELLITE_SOS_UNAVAILABLE_REASONS = new HashMap<>(Map.of(
@@ -229,6 +231,8 @@
/** Feature flags to control behavior and errors. */
@NonNull
private final FeatureFlags mFeatureFlags;
+ @NonNull
+ private final Context mContext;
@GuardedBy("mLock")
@Nullable
protected SatelliteOnDeviceAccessController mSatelliteOnDeviceAccessController;
@@ -276,6 +280,7 @@
@Nullable
private File mOverriddenSatelliteS2CellFile;
private long mOverriddenLocationFreshDurationNanos;
+
@GuardedBy("mLock")
@NonNull
private final Map<SatelliteOnDeviceAccessController.LocationToken, Integer>
@@ -299,14 +304,10 @@
@GuardedBy("mLock")
@Nullable
protected Integer mNewRegionalConfigId = null;
-
- /** Key: Config ID; Value: SatelliteAccessConfiguration */
@NonNull
- private HashMap<Integer, SatelliteAccessConfiguration> mSatelliteAccessConfigMap =
- new HashMap<>();
- @NonNull private final CarrierConfigManager mCarrierConfigManager;
- @NonNull private final CarrierConfigManager.CarrierConfigChangeListener
- mCarrierConfigChangeListener;
+ private final CarrierConfigManager mCarrierConfigManager;
+ @NonNull
+ private final CarrierConfigManager.CarrierConfigChangeListener mCarrierConfigChangeListener;
/**
* Key: Sub Id, Value: (key: Regional satellite config Id, value: SatelliteRegionalConfig
* contains satellite config IDs and set of earfcns in the corresponding regions).
@@ -316,6 +317,11 @@
mSatelliteRegionalConfigPerSubMap = new HashMap();
@NonNull private final Object mRegionalSatelliteEarfcnsLock = new Object();
+ /** Key: Config ID; Value: SatelliteAccessConfiguration */
+ @GuardedBy("mLock")
+ @Nullable
+ private Map<Integer, SatelliteAccessConfiguration> mSatelliteAccessConfigMap;
+
/** These are used for CTS test */
private Path mCtsSatS2FilePath = null;
protected static final String GOOGLE_US_SAN_SAT_S2_FILE_NAME = "google_us_san_sat_s2.dat";
@@ -428,6 +434,7 @@
@Nullable SatelliteOnDeviceAccessController satelliteOnDeviceAccessController,
@Nullable File s2CellFile) {
super(looper);
+ mContext = context;
if (isSatellitePersistentLoggingEnabled(context, featureFlags)) {
mPersistentLogger = new PersistentLogger(
DropBoxManagerLoggerBackend.getInstance(context));
@@ -709,28 +716,29 @@
SatelliteAccessConfiguration satelliteAccessConfig = null;
synchronized (mLock) {
- if (isSatelliteCommunicationAllowed && isRegionalConfigIdValid(
- mRegionalConfigId)) {
+ if (isSatelliteCommunicationAllowed && SatelliteAccessConfigurationParser
+ .isRegionalConfigIdValid(mRegionalConfigId)) {
plogd("requestSatelliteAccessConfigurationForCurrentLocation : "
+ "mRegionalConfigId is " + mRegionalConfigId);
- satelliteAccessConfig =
- mSatelliteAccessConfigMap.get(mRegionalConfigId);
+ satelliteAccessConfig = Optional.ofNullable(mSatelliteAccessConfigMap)
+ .map(map -> map.get(mRegionalConfigId))
+ .orElse(null);
}
}
plogd("requestSatelliteAccessConfigurationForCurrentLocation : "
+ "satelliteAccessConfig is " + satelliteAccessConfig);
- Bundle bundle = new Bundle();
- bundle.putParcelable(KEY_SATELLITE_ACCESS_CONFIGURATION, satelliteAccessConfig);
- result.send(resultCode, bundle);
+ if (satelliteAccessConfig == null) {
+ result.send(SATELLITE_RESULT_NO_RESOURCES, null);
+ } else {
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(KEY_SATELLITE_ACCESS_CONFIGURATION, satelliteAccessConfig);
+ result.send(resultCode, bundle);
+ }
}
};
requestIsCommunicationAllowedForCurrentLocation(internalResultReceiver, false);
}
- private boolean isRegionalConfigIdValid(@Nullable Integer configId) {
- return (configId != null && configId >= 0);
- }
-
/**
* This API should be used by only CTS tests to override the overlay configs of satellite
* access controller.
@@ -1094,6 +1102,7 @@
ploge("The satellite S2 cell file " + satelliteS2CellFileName + " does not exist");
mSatelliteS2CellFile = null;
}
+
mLocationFreshDurationNanos = getSatelliteLocationFreshDurationFromOverlayConfig(context);
mAccessControllerMetricsStats.setConfigDataSource(
SatelliteConstants.CONFIG_DATA_SOURCE_DEVICE_CONFIG);
@@ -1104,6 +1113,28 @@
mLocationQueryThrottleIntervalNanos = getLocationQueryThrottleIntervalNanos(context);
}
+ protected void loadSatelliteAccessConfigurationFromDeviceConfig() {
+ String satelliteConfigurationFileName =
+ getSatelliteConfigurationFileNameFromOverlayConfig(mContext);
+ loadSatelliteAccessConfigurationFromFile(satelliteConfigurationFileName);
+ }
+
+ protected void loadSatelliteAccessConfigurationFromFile(String fileName) {
+ logd("loadSatelliteAccessConfigurationFromFile: " + fileName);
+ if (!TextUtils.isEmpty(fileName)) {
+ try {
+ synchronized (mLock) {
+ mSatelliteAccessConfigMap =
+ SatelliteAccessConfigurationParser.parse(fileName);
+ }
+ } catch (Exception e) {
+ loge("loadSatelliteAccessConfigurationFromFile: failed load json file: " + e);
+ }
+ } else {
+ loge("loadSatelliteAccessConfigurationFromFile: fileName is empty");
+ }
+ }
+
private void loadConfigUpdaterConfigs() {
if (mSharedPreferences == null) {
ploge("loadConfigUpdaterConfigs : mSharedPreferences is null");
@@ -1339,7 +1370,7 @@
}
private void sendSatelliteAllowResultToReceivers(int resultCode, Bundle resultData,
- boolean allowed) {
+ boolean allowed) {
plogd("sendSatelliteAllowResultToReceivers : resultCode is " + resultCode);
if (resultCode == SATELLITE_RESULT_SUCCESS) {
updateCurrentSatelliteAllowedState(allowed);
@@ -1521,9 +1552,8 @@
createUnavailableNotifications(context);
}
- private Notification createNotification(@NonNull Context context,
- String title,
- String content) {
+ private Notification createNotification(@NonNull Context context, String title,
+ String content) {
Notification.Builder notificationBuilder = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(content)
@@ -1939,7 +1969,9 @@
if (!Objects.equals(mRegionalConfigId, mNewRegionalConfigId)) {
mRegionalConfigId = mNewRegionalConfigId;
notifyRegionalSatelliteConfigurationChanged(
- mSatelliteAccessConfigMap.get(mRegionalConfigId));
+ Optional.ofNullable(mSatelliteAccessConfigMap)
+ .map(map -> map.get(mRegionalConfigId))
+ .orElse(null));
}
}
}
@@ -2090,7 +2122,8 @@
* {@link SatelliteOnDeviceAccessController} instance and the
* device is using a user build.
*/
- private boolean initSatelliteOnDeviceAccessController() throws IllegalStateException {
+ private boolean initSatelliteOnDeviceAccessController()
+ throws IllegalStateException {
synchronized (mLock) {
if (getSatelliteS2CellFile() == null) return false;
@@ -2107,6 +2140,7 @@
restartKeepOnDeviceAccessControllerResourcesTimer();
mS2Level = mSatelliteOnDeviceAccessController.getS2Level();
plogd("mS2Level=" + mS2Level);
+ loadSatelliteAccessConfigurationFromDeviceConfig();
} catch (Exception ex) {
ploge("Got exception in creating an instance of SatelliteOnDeviceAccessController,"
+ " ex=" + ex + ", sat s2 file="
@@ -2114,6 +2148,7 @@
reportAnomaly(UUID_CREATE_ON_DEVICE_ACCESS_CONTROLLER_EXCEPTION,
"Exception in creating on-device satellite access controller");
mSatelliteOnDeviceAccessController = null;
+ mSatelliteAccessConfigMap = null;
if (!mIsOverlayConfigOverridden) {
mSatelliteS2CellFile = null;
}
@@ -2134,6 +2169,7 @@
ploge("cleanupOnDeviceAccessControllerResources: ex=" + ex);
}
mSatelliteOnDeviceAccessController = null;
+ mSatelliteAccessConfigMap = null;
stopKeepOnDeviceAccessControllerResourcesTimer();
}
}
@@ -2232,6 +2268,28 @@
return accessAllowed;
}
+
+ @Nullable
+ protected String getSatelliteConfigurationFileNameFromOverlayConfig(
+ @NonNull Context context) {
+ String satelliteAccessControlInfoFile = null;
+
+ if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
+ logd("mFeatureFlags: carrierRoamingNbIotNtn is disabled");
+ return satelliteAccessControlInfoFile;
+ }
+
+ try {
+ satelliteAccessControlInfoFile = context.getResources().getString(
+ com.android.internal.R.string.satellite_access_config_file);
+ } catch (Resources.NotFoundException ex) {
+ loge("getSatelliteConfigurationFileNameFromOverlayConfig: got ex=" + ex);
+ }
+
+ logd("satelliteAccessControlInfoFile =" + satelliteAccessControlInfoFile);
+ return satelliteAccessControlInfoFile;
+ }
+
@Nullable
private static String getSatelliteS2CellFileFromOverlayConfig(@NonNull Context context) {
String s2CellFile = null;
@@ -2461,7 +2519,9 @@
}
synchronized (mLock) {
SatelliteAccessConfiguration satelliteAccessConfig =
- mSatelliteAccessConfigMap.get(mRegionalConfigId);
+ Optional.ofNullable(mSatelliteAccessConfigMap)
+ .map(map -> map.get(mRegionalConfigId))
+ .orElse(null);
callback.onSatelliteAccessConfigurationChanged(satelliteAccessConfig);
logd("registerForCommunicationAllowedStateChanged: satelliteAccessConfig: "
+ satelliteAccessConfig + " of mRegionalConfigId: "
@@ -2500,9 +2560,9 @@
* Returns integer array of disallowed reasons of satellite.
*
* @return Integer array of disallowed reasons of satellite.
- *
*/
- @NonNull public List<Integer> getSatelliteDisallowedReasons() {
+ @NonNull
+ public List<Integer> getSatelliteDisallowedReasons() {
if (!mFeatureFlags.carrierRoamingNbIotNtn()) {
plogd("getSatelliteDisallowedReasons: carrierRoamingNbIotNtn is disabled");
return new ArrayList<>();
@@ -2517,7 +2577,6 @@
* Registers for disallowed reasons change event from satellite service.
*
* @param callback The callback to handle disallowed reasons changed event.
- *
*/
public void registerForSatelliteDisallowedReasonsChanged(
@NonNull ISatelliteDisallowedReasonsCallback callback) {
@@ -2551,7 +2610,7 @@
*
* @param callback The callback that was passed to
* {@link #registerForSatelliteDisallowedReasonsChanged(
- * ISatelliteDisallowedReasonsCallback)}.
+ *ISatelliteDisallowedReasonsCallback)}.
*/
public void unregisterForSatelliteDisallowedReasonsChanged(
@NonNull ISatelliteDisallowedReasonsCallback callback) {
@@ -2709,7 +2768,7 @@
Rlog.w(TAG, log);
}
- private static void loge(@NonNull String log) {
+ protected static void loge(@NonNull String log) {
Rlog.e(TAG, log);
}
diff --git a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParserTest.java b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParserTest.java
new file mode 100644
index 0000000..d577a63
--- /dev/null
+++ b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessConfigurationParserTest.java
@@ -0,0 +1,314 @@
+/*
+ * Copyright (C) 2024 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.
+ */
+
+package com.android.phone.satellite.accesscontrol;
+
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.SATELLITE_ACCESS_CONTROL_CONFIGS;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.SATELLITE_CONFIG_ID;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.SATELLITE_INFOS;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.isRegionalConfigIdValid;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.parseSatelliteBandList;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.parseSatelliteEarfcnRangeList;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.parseSatelliteId;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.parseSatelliteInfoList;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.parseSatellitePosition;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.parseSatelliteTagIdList;
+import static com.android.phone.satellite.accesscontrol.SatelliteAccessConfigurationParser.readJsonStringFromFile;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import android.content.Context;
+import android.telephony.satellite.EarfcnRange;
+import android.telephony.satellite.SatelliteAccessConfiguration;
+import android.telephony.satellite.SatelliteInfo;
+import android.telephony.satellite.SatellitePosition;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+/** Unit test for {@link SatelliteAccessConfigurationParser} */
+@RunWith(AndroidJUnit4.class)
+public class SatelliteAccessConfigurationParserTest {
+ private static final String TAG = "SatelliteAccessConfigurationParserTest";
+
+ private static final String TEST_FILE_NAME = "test.json";
+ private static final String TEST_INVALID_FILE_NAME = "nonexistent_file.json";
+
+ private static final String TEST_SATELLITE_UUID1 = "5d0cc4f8-9223-4196-ad7a-803002db7af7";
+ private static final String TEST_SATELLITE_UUID2 = "0d30312e-a73f-444d-b99b-a893dfb42ee9";
+ private static final String TEST_SATELLITE_UUID3 = "01a0b0ca-11bc-4777-87ae-f39afbbec1e9";
+
+ private static final String VALID_JSON_STRING =
+ """
+ {
+ "access_control_configs": [
+ {
+ "config_id": 123,
+ "satellite_infos": [
+ {
+ "satellite_id": "5d0cc4f8-9223-4196-ad7a-803002db7af7",
+ "satellite_position": {
+ "longitude": 45.5,
+ "altitude": 35786000
+ },
+ "bands": [
+ 1234,
+ 5678
+ ],
+ "earfcn_ranges": [
+ {
+ "start_earfcn": 1500,
+ "end_earfcn": 1800
+ }
+ ]
+ },
+ {
+ "satellite_id": "0d30312e-a73f-444d-b99b-a893dfb42ee9",
+ "satellite_position": {
+ "longitude": -120.3,
+ "altitude": 35786000
+ },
+ "bands": [
+ 3456,
+ 7890
+ ],
+ "earfcn_ranges": [
+ {
+ "start_earfcn": 2000,
+ "end_earfcn": 2300
+ }
+ ]
+ }
+ ],
+ "tag_ids": [
+ 7,
+ 10
+ ]
+ },
+ {
+ "config_id": 890,
+ "satellite_infos": [
+ {
+ "satellite_id": "01a0b0ca-11bc-4777-87ae-f39afbbec1e9",
+ "satellite_position": {
+ "longitude": -120,
+ "altitude": 1234567
+ },
+ "bands": [
+ 13579,
+ 24680
+ ],
+ "earfcn_ranges": [
+ {
+ "start_earfcn": 6420,
+ "end_earfcn": 15255
+ }
+ ]
+ }
+ ],
+ "tag_ids": [
+ 6420,
+ 15255
+ ]
+ }
+ ]
+ }
+ """;
+
+
+ // Mandatory : config_id ( >= 0)
+ // SatelliteInfoList : NonNull
+ // UUID (0-9, a-f and hyphen : '_' and 'z' are invalid)
+ // longitude (-180 ~ 180)
+ // altitude ( >= 0)
+ private static final String INVALID_JSON_STRING =
+ """
+ {
+ "access_control_configs": [
+ {
+ "config_id": -100,
+ "satellite_infos": [
+ {
+ "satellite_id": "01z0b0ca-11bc-4777_87ae-f39afbbec1e9",
+ "satellite_position": {
+ "longitude": -181,
+ "altitude": -1
+ },
+ "earfcn_ranges": [
+ {
+ "start_earfcn": -1,
+ "end_earfcn": 65536
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ """;
+
+ @Before
+ public void setUp() throws Exception {
+ Log.d(TAG, "setUp");
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ Log.d(TAG, "tearDown");
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception {
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws Exception {
+ }
+
+ private static File createTestJsonFile(@NonNull String content) throws Exception {
+ Log.d(TAG, "createTestJsonFile");
+ Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ File testFile = new File(context.getCacheDir(), TEST_FILE_NAME);
+ try (FileOutputStream fos = new FileOutputStream(testFile)) {
+ fos.write(content.getBytes(StandardCharsets.UTF_8));
+ }
+ return testFile;
+ }
+
+ @Test
+ public void testLoadJsonFile() throws Exception {
+ Log.d(TAG, "testLoadJsonFile");
+ assertNull(readJsonStringFromFile(TEST_INVALID_FILE_NAME));
+ assertNull(readJsonStringFromFile(null));
+
+ File file = createTestJsonFile(VALID_JSON_STRING);
+ assertEquals(VALID_JSON_STRING, readJsonStringFromFile(file.getPath()));
+
+ assertTrue(file.delete());
+ }
+
+
+ private SatelliteInfo getSatelliteInfo(UUID id, SatellitePosition position,
+ List<Integer> bandList, List<EarfcnRange> rangeList) {
+ return new SatelliteInfo(id, position, bandList, rangeList);
+ }
+
+ private Map<Integer, SatelliteAccessConfiguration> getExpectedMap() {
+ List<SatelliteInfo> satelliteInfoList1 = new ArrayList<>();
+ satelliteInfoList1.add(
+ getSatelliteInfo(UUID.fromString(TEST_SATELLITE_UUID1),
+ new SatellitePosition(45.5, 35786000),
+ List.of(1234, 5678),
+ new ArrayList<>(List.of(new EarfcnRange(1500, 1800)))
+ ));
+ satelliteInfoList1.add(
+ getSatelliteInfo(UUID.fromString(TEST_SATELLITE_UUID2),
+ new SatellitePosition(-120.3, 35786000),
+ List.of(3456, 7890),
+ new ArrayList<>(List.of(new EarfcnRange(2000, 2300)))
+ ));
+
+ List<Integer> tagIdList1 = List.of(7, 10);
+ SatelliteAccessConfiguration satelliteAccessConfiguration1 =
+ new SatelliteAccessConfiguration(satelliteInfoList1, tagIdList1);
+
+ HashMap<Integer, SatelliteAccessConfiguration> expectedResult = new HashMap<>();
+ expectedResult.put(123, satelliteAccessConfiguration1);
+
+ List<SatelliteInfo> satelliteInfoList2 = new ArrayList<>();
+ List<Integer> tagIdList2 = List.of(6420, 15255);
+ satelliteInfoList2.add(
+ getSatelliteInfo(UUID.fromString(TEST_SATELLITE_UUID3),
+ new SatellitePosition(-120, 1234567),
+ List.of(13579, 24680),
+ new ArrayList<>(List.of(new EarfcnRange(6420, 15255)))
+ ));
+ SatelliteAccessConfiguration satelliteAccessConfiguration2 =
+ new SatelliteAccessConfiguration(satelliteInfoList2, tagIdList2);
+ expectedResult.put(890, satelliteAccessConfiguration2);
+ return expectedResult;
+ }
+
+
+ @Test
+ public void testParsingValidSatelliteAccessConfiguration() throws Exception {
+ Log.d(TAG, "testParsingValidSatelliteAccessConfiguration");
+ File file = createTestJsonFile(VALID_JSON_STRING);
+ assertEquals(getExpectedMap(),
+ SatelliteAccessConfigurationParser.parse(file.getCanonicalPath()));
+ }
+
+ @Test
+ public void testParsingInvalidSatelliteAccessConfiguration() throws Exception {
+ Log.d(TAG, "testParsingInvalidSatelliteAccessConfiguration");
+ File file = createTestJsonFile(INVALID_JSON_STRING);
+ String jsonString = readJsonStringFromFile(file.getCanonicalPath());
+ JSONObject satelliteAccessConfigJsonObject = new JSONObject(jsonString);
+ JSONArray configurationArrayJson = satelliteAccessConfigJsonObject.optJSONArray(
+ SATELLITE_ACCESS_CONTROL_CONFIGS);
+
+ for (int i = 0; i < configurationArrayJson.length(); i++) {
+ JSONObject configJson = configurationArrayJson.getJSONObject(i);
+
+ int configId = configJson.optInt(SATELLITE_CONFIG_ID, -1);
+ assertFalse(isRegionalConfigIdValid(configId));
+
+ JSONArray satelliteInfoArray = configJson.getJSONArray(SATELLITE_INFOS);
+ List<SatelliteInfo> satelliteInfoList = parseSatelliteInfoList(satelliteInfoArray);
+ assertNotNull(satelliteInfoList);
+ assertTrue(satelliteInfoList.isEmpty());
+
+ for (int j = 0; j < satelliteInfoArray.length(); j++) {
+ JSONObject infoJson = satelliteInfoArray.getJSONObject(i);
+ assertNull(parseSatelliteId(infoJson));
+ assertNull(parseSatellitePosition(infoJson));
+ assertTrue(parseSatelliteEarfcnRangeList(infoJson).isEmpty());
+ assertNotNull(parseSatelliteBandList(infoJson));
+ assertEquals(0, parseSatelliteBandList(infoJson).size());
+ }
+
+ List<Integer> tagIdList = parseSatelliteTagIdList(configJson);
+ assertNotNull(tagIdList);
+ }
+ }
+}
diff --git a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
index b388954..c8013d6 100644
--- a/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
+++ b/tests/src/com/android/phone/satellite/accesscontrol/SatelliteAccessControllerTest.java
@@ -27,6 +27,7 @@
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_LOCATION_NOT_AVAILABLE;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_MODEM_ERROR;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_NOT_SUPPORTED;
+import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_NO_RESOURCES;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_REQUEST_NOT_SUPPORTED;
import static android.telephony.satellite.SatelliteManager.SATELLITE_RESULT_SUCCESS;
@@ -619,10 +620,9 @@
verify(mockResultReceiver, times(1)).send(resultCodeCaptor.capture(),
bundleCaptor.capture());
- assertEquals(SATELLITE_RESULT_SUCCESS, (int) resultCodeCaptor.getValue());
- assertTrue(bundleCaptor.getValue().containsKey(KEY_SATELLITE_ACCESS_CONFIGURATION));
- assertNull(bundleCaptor.getValue().getParcelable(KEY_SATELLITE_ACCESS_CONFIGURATION,
- SatelliteAccessConfiguration.class));
+ assertEquals(SATELLITE_RESULT_NO_RESOURCES, (int) resultCodeCaptor.getValue());
+ assertNull(bundleCaptor.getValue());
+
verify(mockSatelliteAllowedStateCallback, times(1))
.onSatelliteAccessConfigurationChanged(
satelliteAccessConfigurationCaptor.capture());
@@ -1410,6 +1410,33 @@
}
@Test
+ public void testLoadSatelliteAccessConfigurationFromDeviceConfig() {
+ when(mMockFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(false);
+ assertNull(mSatelliteAccessControllerUT
+ .getSatelliteConfigurationFileNameFromOverlayConfig(mMockContext));
+
+ when(mMockFeatureFlags.oemEnabledSatelliteFlag()).thenReturn(true);
+ when(mMockContext.getResources()).thenReturn(mMockResources);
+ when(mMockResources
+ .getString(eq(com.android.internal.R.string.satellite_access_config_file)))
+ .thenReturn("test_satellite_file.json");
+ assertEquals("test_satellite_file.json", mSatelliteAccessControllerUT
+ .getSatelliteConfigurationFileNameFromOverlayConfig(mMockContext));
+
+ when(mMockResources
+ .getString(eq(com.android.internal.R.string.satellite_access_config_file)))
+ .thenReturn(null);
+ assertNull(mSatelliteAccessControllerUT
+ .getSatelliteConfigurationFileNameFromOverlayConfig(mMockContext));
+ try {
+ mSatelliteAccessControllerUT.loadSatelliteAccessConfigurationFromDeviceConfig();
+ } catch (Exception e) {
+ fail("Unexpected exception thrown: " + e.getMessage());
+ }
+ }
+
+
+ @Test
public void testUpdateSatelliteConfigData() throws Exception {
verify(mMockSatelliteController).registerForConfigUpdateChanged(
mConfigUpdateHandlerCaptor.capture(), mConfigUpdateIntCaptor.capture(),