summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFarruh Habibullaev <farruhh@google.com>2021-10-01 12:02:09 -0700
committerFarruh Habibullaev <farruhh@google.com>2021-10-05 18:44:18 +0000
commit748f78628fc27e63d12fcbb979b5515c88267829 (patch)
tree083d2c5b6cbc1ae6e8db59a880dcd1048735b49b
parentf7bf676eaac04f315a566714f68c53c34629334d (diff)
downloadsetupwizard-748f78628fc27e63d12fcbb979b5515c88267829.tar.gz
Add the version support on FeatureResolver.java to
- support splitNavLayoutFeature based on the version number Test: added FeatureResolverTest.java to unit test the functionality Test: Manually tested it. Change-Id: I3a69503227140fa9bb592a31920f6f43125f2171 Bug: b/201835961
-rw-r--r--library/main/Android.bp6
-rw-r--r--library/main/build.gradle1
-rw-r--r--library/main/src/com/android/car/setupwizardlib/util/FeatureResolver.java57
-rw-r--r--library/main/tests/robotests/src/com/android/car/setupwizardlib/util/FeatureResolverTest.java136
4 files changed, 185 insertions, 15 deletions
diff --git a/library/main/Android.bp b/library/main/Android.bp
index 530430e..506dee5 100644
--- a/library/main/Android.bp
+++ b/library/main/Android.bp
@@ -22,7 +22,11 @@ android_library {
srcs: ["src/**/*.java"],
resource_dirs: ["res"],
libs: ["android.car-system-stubs"],
- static_libs: ["androidx.car_car-resources-partially-dejetified", "car-ui-lib"],
+ static_libs: [
+ "androidx.car_car-resources-partially-dejetified",
+ "car-ui-lib",
+ "androidx.test.core"
+ ],
optimize: {
enabled: false,
},
diff --git a/library/main/build.gradle b/library/main/build.gradle
index 412e3b0..17ab59a 100644
--- a/library/main/build.gradle
+++ b/library/main/build.gradle
@@ -78,6 +78,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core:1.3.2'
implementation 'androidx.annotation:annotation:1.2.0'
+ implementation 'androidx.test:core:1.4.0'
testImplementation 'com.google.truth:truth:0.41'
testImplementation 'org.mockito:mockito-core:3.6.0'
diff --git a/library/main/src/com/android/car/setupwizardlib/util/FeatureResolver.java b/library/main/src/com/android/car/setupwizardlib/util/FeatureResolver.java
index 966e87f..98f467a 100644
--- a/library/main/src/com/android/car/setupwizardlib/util/FeatureResolver.java
+++ b/library/main/src/com/android/car/setupwizardlib/util/FeatureResolver.java
@@ -27,7 +27,9 @@ import androidx.annotation.NonNull;
import java.util.HashMap;
import java.util.Map;
-/** A class to resolve feature enablement and versions */
+/**
+ * A class to resolve feature enablement and versions
+ */
public class FeatureResolver {
private static final String TAG = FeatureResolver.class.getSimpleName();
@@ -36,6 +38,7 @@ public class FeatureResolver {
static final String AUTHORITY =
CarSetupWizardUiUtils.SETUP_WIZARD_PACKAGE + ".feature_management";
static final String GET_FEATURE_VERSION_METHOD = "getFeatureVersion";
+ static final String GET_FEATURE_ENABLEMENT_METHOD = "getFeatureEnablement";
static final String SPLIT_NAV_LAYOUT_FEATURE = "split_nav_layout";
static final String VALUE = "value";
@@ -43,7 +46,9 @@ public class FeatureResolver {
private Map<String, Bundle> mResultMap = new HashMap<>();
- /** Factory method to get an instance */
+ /**
+ * Factory method to get an instance
+ */
public static FeatureResolver get(@NonNull Context context) {
if (sInstance == null) {
synchronized (FeatureResolver.class) {
@@ -55,30 +60,54 @@ public class FeatureResolver {
return sInstance;
}
- /** Returns whether the alternative layout feature is enabled */
+ /**
+ * Returns whether the alternative layout feature is enabled
+ */
public boolean isSplitNavLayoutFeatureEnabled() {
Bundle bundle;
- if (mResultMap.containsKey(SPLIT_NAV_LAYOUT_FEATURE)) {
- bundle = mResultMap.get(SPLIT_NAV_LAYOUT_FEATURE);
+ String bundleKey = SPLIT_NAV_LAYOUT_FEATURE.concat(GET_FEATURE_ENABLEMENT_METHOD);
+ if (mResultMap.containsKey(bundleKey)) {
+ bundle = mResultMap.get(bundleKey);
+ } else {
+ bundle = getFeatureBundle(SPLIT_NAV_LAYOUT_FEATURE, GET_FEATURE_ENABLEMENT_METHOD);
+ mResultMap.put(bundleKey, bundle);
+ }
+ boolean isSplitNavLayoutFeatureEnabled = bundle != null
+ && bundle.getBoolean(VALUE, false);
+ Log.v(TAG, String.format("isSplitNavLayoutEnabled: %s", isSplitNavLayoutFeatureEnabled));
+ return isSplitNavLayoutFeatureEnabled;
+ }
+
+ /**
+ * Returns the enabled version number of split-nav layout
+ */
+ public int getSplitNavLayoutFeatureVersion() {
+ Bundle bundle;
+ String bundleKey = SPLIT_NAV_LAYOUT_FEATURE.concat(GET_FEATURE_VERSION_METHOD);
+ if (mResultMap.containsKey(bundleKey)) {
+ bundle = mResultMap.get(bundleKey);
} else {
- bundle = getFeatureBundle(SPLIT_NAV_LAYOUT_FEATURE);
- mResultMap.put(SPLIT_NAV_LAYOUT_FEATURE, bundle);
+ bundle = getFeatureBundle(SPLIT_NAV_LAYOUT_FEATURE, GET_FEATURE_VERSION_METHOD);
+ mResultMap.put(bundleKey, bundle);
}
- return bundle != null && bundle.getBoolean(VALUE, false);
+ int splitNavLayoutFeatureVersion = bundle != null
+ ? bundle.getInt(VALUE, 0) : 0;
+ Log.v(TAG, String.format("splitNavLayoutFeatureVersion: %s", splitNavLayoutFeatureVersion));
+ return splitNavLayoutFeatureVersion;
}
- private Bundle getFeatureBundle(String feature) {
+ private Bundle getFeatureBundle(String feature, String method) {
try {
Uri contentUri =
new Uri.Builder()
- .scheme(ContentResolver.SCHEME_CONTENT)
- .authority(AUTHORITY)
- .appendPath(GET_FEATURE_VERSION_METHOD)
- .build();
+ .scheme(ContentResolver.SCHEME_CONTENT)
+ .authority(AUTHORITY)
+ .appendPath(method)
+ .build();
return mContext.getContentResolver().call(
contentUri,
- GET_FEATURE_VERSION_METHOD,
+ method,
feature,
/* extras= */ null);
} catch (IllegalArgumentException exception) {
diff --git a/library/main/tests/robotests/src/com/android/car/setupwizardlib/util/FeatureResolverTest.java b/library/main/tests/robotests/src/com/android/car/setupwizardlib/util/FeatureResolverTest.java
new file mode 100644
index 0000000..046a9f7
--- /dev/null
+++ b/library/main/tests/robotests/src/com/android/car/setupwizardlib/util/FeatureResolverTest.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2021 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.car.setupwizardlib.util;
+
+import static com.android.car.setupwizardlib.util.FeatureResolver.VALUE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.net.Uri;
+import android.os.Bundle;
+
+import androidx.test.core.app.ApplicationProvider;
+
+import com.android.car.setupwizardlib.robolectric.BaseRobolectricTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.robolectric.RobolectricTestRunner;
+
+import java.lang.reflect.Constructor;
+
+@RunWith(RobolectricTestRunner.class)
+public class FeatureResolverTest extends BaseRobolectricTest {
+
+ @Mock
+ private ContentResolver mContentResolver;
+
+ private FeatureResolver mFeatureResolver;
+ private Context mContext;
+
+ @Before
+ public void setUp() throws Exception {
+ Constructor<FeatureResolver> constructor = FeatureResolver.class
+ .getDeclaredConstructor(Context.class);
+ constructor.setAccessible(true);
+ mContext = spy(ApplicationProvider.getApplicationContext());
+ mFeatureResolver = constructor.newInstance(mContext);
+ doReturn(mContentResolver).when(mContext).getContentResolver();
+ }
+
+ @Test
+ public void testFeatureResolverInstance() {
+ assertThat(FeatureResolver.get(mContext)).isNotNull();
+ }
+
+ @Test
+ public void testFeatureResolverSingletonInstance() {
+ FeatureResolver instance = FeatureResolver.get(mContext);
+
+ assertThat(instance).isEqualTo(FeatureResolver.get(mContext));
+ }
+
+ @Test
+ public void testIsSplitNavLayoutFeatureEnabled_whenReturnsTrue() {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(VALUE, true);
+ doReturn(bundle).when(mContentResolver).call((Uri) any(), any(), any(), any());
+
+ boolean isSplitNavLayoutFeatureEnabled = mFeatureResolver.isSplitNavLayoutFeatureEnabled();
+
+ assertThat(isSplitNavLayoutFeatureEnabled).isTrue();
+ }
+
+ @Test
+ public void testIsSplitNavLayoutFeatureEnabled_whenReturnsFalse() {
+ Bundle bundle = new Bundle();
+ bundle.putBoolean(VALUE, false);
+ doReturn(bundle).when(mContentResolver).call((Uri) any(), any(), any(), any());
+
+ boolean isSplitNavLayoutFeatureEnabled = mFeatureResolver.isSplitNavLayoutFeatureEnabled();
+
+ assertThat(isSplitNavLayoutFeatureEnabled).isFalse();
+ }
+
+ @Test
+ public void testIsSplitNavLayoutFeatureEnabled_whenReturnsBundleNull() {
+ doReturn(null).when(mContentResolver).call((Uri) any(), any(), any(), any());
+
+ boolean isSplitNavLayoutFeatureEnabled = mFeatureResolver.isSplitNavLayoutFeatureEnabled();
+
+ assertThat(isSplitNavLayoutFeatureEnabled).isFalse();
+ }
+
+ @Test
+ public void testGetSplitNavLayoutFeatureVersion_whenVersionNumber1() {
+ Bundle bundle = new Bundle();
+ bundle.putInt(VALUE, 1);
+ doReturn(bundle).when(mContentResolver).call((Uri) any(), any(), any(), any());
+
+ int splitNavLayoutFeatureVersion = mFeatureResolver.getSplitNavLayoutFeatureVersion();
+
+ assertThat(splitNavLayoutFeatureVersion).isEqualTo(1);
+ }
+
+ @Test
+ public void testGetSplitNavLayoutFeatureVersion_whenVersionNumber0() {
+ Bundle bundle = new Bundle();
+ bundle.putInt(VALUE, 0);
+ doReturn(bundle).when(mContentResolver).call((Uri) any(), any(), any(), any());
+
+ int splitNavLayoutFeatureVersion = mFeatureResolver.getSplitNavLayoutFeatureVersion();
+
+ assertThat(splitNavLayoutFeatureVersion).isEqualTo(0);
+ }
+
+ @Test
+ public void testGetSplitNavLayoutFeatureVersion_whenReturnsBundleNull() {
+ doReturn(null).when(mContentResolver).call((Uri) any(), any(), any(), any());
+
+ int splitNavLayoutFeatureVersion = mFeatureResolver.getSplitNavLayoutFeatureVersion();
+
+ assertThat(splitNavLayoutFeatureVersion).isEqualTo(0);
+ }
+}