Add support feature map for automatically enabling related features.
Bug: 149503895
Test: atest CarServiceTest CarServiceUnitTest
Change-Id: I491e7653ec6bdbd0fd1c4fa3e46d26719b2b6270
diff --git a/service/res/values/config.xml b/service/res/values/config.xml
index 6094848..e8a7e19 100644
--- a/service/res/values/config.xml
+++ b/service/res/values/config.xml
@@ -314,7 +314,6 @@
<item>diagnostic</item>
<item>storage_monitoring</item>
<item>vehicle_map_service</item>
- <item>vehicle_map_subscriber_service</item>
</string-array>
<!-- Configuration to enable passenger support.
diff --git a/service/src/com/android/car/CarFeatureController.java b/service/src/com/android/car/CarFeatureController.java
index 9f0d9e3..60b751a 100644
--- a/service/src/com/android/car/CarFeatureController.java
+++ b/service/src/com/android/car/CarFeatureController.java
@@ -26,6 +26,7 @@
import android.os.HandlerThread;
import android.util.AtomicFile;
import android.util.Log;
+import android.util.Pair;
import com.android.internal.annotations.GuardedBy;
@@ -42,6 +43,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -89,10 +91,16 @@
Car.DIAGNOSTIC_SERVICE,
Car.OCCUPANT_AWARENESS_SERVICE,
Car.STORAGE_MONITORING_SERVICE,
- Car.VEHICLE_MAP_SERVICE,
- Car.VMS_SUBSCRIBER_SERVICE
+ Car.VEHICLE_MAP_SERVICE
));
+ // Features that depend on another feature being enabled (i.e. legacy API support).
+ // For example, VMS_SUBSCRIBER_SERVICE will be enabled if VEHICLE_MAP_SERVICE is enabled
+ // and disabled if VEHICLE_MAP_SERVICE is disabled.
+ private static final List<Pair<String, String>> SUPPORT_FEATURES = Arrays.asList(
+ Pair.create(Car.VEHICLE_MAP_SERVICE, Car.VMS_SUBSCRIBER_SERVICE)
+ );
+
private static final String FEATURE_CONFIG_FILE_NAME = "car_feature_config.txt";
// Last line starts with this with number of features for extra sanity check.
@@ -155,6 +163,7 @@
parseDefaultConfig();
dispatchDefaultConfigUpdate();
}
+ addSupportFeatures(mEnabledFeatures);
}
@Override
@@ -369,7 +378,7 @@
if (line.startsWith(CONFIG_FILE_LAST_LINE_MARKER)) {
int numberOfFeatures;
try {
- numberOfFeatures = Integer.valueOf(line.substring(
+ numberOfFeatures = Integer.parseInt(line.substring(
CONFIG_FILE_LAST_LINE_MARKER.length()));
} catch (NumberFormatException e) {
handleCorruptConfigFileLocked(
@@ -401,6 +410,7 @@
private void persistToFeatureConfigFile() {
HashSet<String> features = new HashSet<>(mEnabledFeatures);
+ removeSupportFeatures(features);
synchronized (mLock) {
features.removeAll(mPendingDisabledFeatures);
features.addAll(mPendingEnabledFeatures);
@@ -451,4 +461,16 @@
}
Log.i(TAG, "Loaded default features:" + mEnabledFeatures);
}
+
+ private static void addSupportFeatures(Collection<String> features) {
+ SUPPORT_FEATURES.stream()
+ .filter(entry -> features.contains(entry.first))
+ .forEach(entry -> features.add(entry.second));
+ }
+
+ private static void removeSupportFeatures(Collection<String> features) {
+ SUPPORT_FEATURES.stream()
+ .filter(entry -> features.contains(entry.first))
+ .forEach(entry -> features.remove(entry.second));
+ }
}
diff --git a/tests/android_car_api_test/src/android/car/apitest/CarFeatureTest.java b/tests/android_car_api_test/src/android/car/apitest/CarFeatureTest.java
index 4516953..092cbcb 100644
--- a/tests/android_car_api_test/src/android/car/apitest/CarFeatureTest.java
+++ b/tests/android_car_api_test/src/android/car/apitest/CarFeatureTest.java
@@ -65,8 +65,7 @@
CarFeatures.FEATURE_CAR_USER_NOTICE_SERVICE,
Car.DIAGNOSTIC_SERVICE,
Car.STORAGE_MONITORING_SERVICE,
- Car.VEHICLE_MAP_SERVICE,
- Car.VMS_SUBSCRIBER_SERVICE
+ Car.VEHICLE_MAP_SERVICE
);
private static final String NON_EXISTING_FEATURE = "ThisFeatureDoesNotExist";