aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoogler <noreply@google.com>2024-04-09 09:33:52 -0700
committerCopybara-Service <copybara-worker@google.com>2024-04-09 09:34:27 -0700
commitc4ee6e00019aae33fc3bae87b1ece6216282562f (patch)
treedacbfa55848b2d7ab30874278cc17ba854db77a1
parentcf59fe60062d50f2087bd03a35b3fdef10e45b1c (diff)
downloadrobolectric-c4ee6e00019aae33fc3bae87b1ece6216282562f.tar.gz
Support FileIntegrityManager.isApkVeritySupported in robolectric
Api added in R https://developer.android.com/reference/android/security/FileIntegrityManager#isApkVeritySupported() PiperOrigin-RevId: 623193132
-rw-r--r--robolectric/src/test/java/org/robolectric/shadows/ShadowFileIntegrityManagerTest.java38
-rw-r--r--shadows/framework/src/main/java/org/robolectric/shadows/ShadowFileIntegrityManager.java28
-rw-r--r--shadows/framework/src/main/java/org/robolectric/shadows/ShadowServiceManager.java2
3 files changed, 68 insertions, 0 deletions
diff --git a/robolectric/src/test/java/org/robolectric/shadows/ShadowFileIntegrityManagerTest.java b/robolectric/src/test/java/org/robolectric/shadows/ShadowFileIntegrityManagerTest.java
new file mode 100644
index 000000000..35a1c2e40
--- /dev/null
+++ b/robolectric/src/test/java/org/robolectric/shadows/ShadowFileIntegrityManagerTest.java
@@ -0,0 +1,38 @@
+package org.robolectric.shadows;
+
+import static android.os.Build.VERSION_CODES.R;
+import static com.google.common.truth.Truth.assertThat;
+import static org.robolectric.Shadows.shadowOf;
+
+import android.security.FileIntegrityManager;
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.annotation.Config;
+
+@RunWith(AndroidJUnit4.class)
+@Config(minSdk = R)
+public final class ShadowFileIntegrityManagerTest {
+
+ private FileIntegrityManager fileIntegrityManager;
+
+ @Before
+ public void setUp() {
+ fileIntegrityManager =
+ ApplicationProvider.getApplicationContext().getSystemService(FileIntegrityManager.class);
+ }
+
+ @Test
+ public void isApkVeritySupported_returnsTrue() {
+ assertThat(fileIntegrityManager.isApkVeritySupported()).isTrue();
+ }
+
+ @Test
+ public void isApkVeritySupported_setFalse_returnsFalse() {
+ shadowOf(fileIntegrityManager).setIsApkVeritySupported(false);
+
+ assertThat(fileIntegrityManager.isApkVeritySupported()).isFalse();
+ }
+}
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowFileIntegrityManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowFileIntegrityManager.java
new file mode 100644
index 000000000..f00259319
--- /dev/null
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowFileIntegrityManager.java
@@ -0,0 +1,28 @@
+package org.robolectric.shadows;
+
+import static android.os.Build.VERSION_CODES.R;
+
+import android.security.FileIntegrityManager;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+/** Shadow for {@link FileIntegrityManager}. */
+@Implements(value = FileIntegrityManager.class, minSdk = R)
+public class ShadowFileIntegrityManager {
+
+ private boolean isApkVeritySupported = true;
+
+ /** Sets the value of {@link #isApkVeritySupported}. */
+ public void setIsApkVeritySupported(boolean isApkVeritySupported) {
+ this.isApkVeritySupported = isApkVeritySupported;
+ }
+
+ /**
+ * Returns {@code true} by default, or can be changed by {@link
+ * #setIsApkVeritySupported(boolean)}.
+ */
+ @Implementation
+ protected boolean isApkVeritySupported() {
+ return isApkVeritySupported;
+ }
+}
diff --git a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowServiceManager.java b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowServiceManager.java
index e33bc335b..fe74b37f1 100644
--- a/shadows/framework/src/main/java/org/robolectric/shadows/ShadowServiceManager.java
+++ b/shadows/framework/src/main/java/org/robolectric/shadows/ShadowServiceManager.java
@@ -82,6 +82,7 @@ import android.os.storage.IStorageManager;
import android.permission.ILegacyPermissionManager;
import android.permission.IPermissionManager;
import android.safetycenter.ISafetyCenterManager;
+import android.security.IFileIntegrityService;
import android.speech.IRecognitionServiceManager;
import android.uwb.IUwbAdapter;
import android.view.IWindowManager;
@@ -242,6 +243,7 @@ public class ShadowServiceManager {
addBinderService(binderServices, Context.TETHERING_SERVICE, ITetheringConnector.class);
addBinderService(binderServices, "telephony.registry", ITelephonyRegistry.class);
addBinderService(binderServices, Context.PLATFORM_COMPAT_SERVICE, IPlatformCompat.class);
+ addBinderService(binderServices, Context.FILE_INTEGRITY_SERVICE, IFileIntegrityService.class);
}
if (RuntimeEnvironment.getApiLevel() >= S) {
addBinderService(binderServices, "permissionmgr", IPermissionManager.class);