From e697eccc51e772649a355fcd4fa08e9db716bfad Mon Sep 17 00:00:00 2001 From: Prashanth Swaminathan <40780424+prashanthswami@users.noreply.github.com> Date: Wed, 28 Feb 2024 09:55:03 -0800 Subject: [PATCH] roboelectric: Remove references to kitkat (#10953) In addition to removing a test that only applies to KitKat, switch tests that require 19 to not specifying the SDK version as we only support min sdk version 21, which has the required API. Also removes the SDK version check from isProfileOwner, to trigger a runtime exception when too low of an SDK version is used. --- .../java/io/grpc/binder/SecurityPolicies.java | 3 ++- .../io/grpc/binder/SecurityPoliciesTest.java | 16 ---------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/binder/src/main/java/io/grpc/binder/SecurityPolicies.java b/binder/src/main/java/io/grpc/binder/SecurityPolicies.java index 41f80c3798..ea17b9828f 100644 --- a/binder/src/main/java/io/grpc/binder/SecurityPolicies.java +++ b/binder/src/main/java/io/grpc/binder/SecurityPolicies.java @@ -203,12 +203,13 @@ public final class SecurityPolicies { * Creates {@link SecurityPolicy} which checks if the app is a profile owner app. See * {@link DevicePolicyManager}. */ + @androidx.annotation.RequiresApi(21) public static SecurityPolicy isProfileOwner(Context applicationContext) { DevicePolicyManager devicePolicyManager = (DevicePolicyManager) applicationContext.getSystemService(Context.DEVICE_POLICY_SERVICE); return anyPackageWithUidSatisfies( applicationContext, - pkg -> VERSION.SDK_INT >= 21 && devicePolicyManager.isProfileOwnerApp(pkg), + pkg -> devicePolicyManager.isProfileOwnerApp(pkg), "Rejected by profile owner policy. No packages found for UID.", "Rejected by profile owner policy"); } diff --git a/binder/src/test/java/io/grpc/binder/SecurityPoliciesTest.java b/binder/src/test/java/io/grpc/binder/SecurityPoliciesTest.java index eda1b286a7..e0f9f98793 100644 --- a/binder/src/test/java/io/grpc/binder/SecurityPoliciesTest.java +++ b/binder/src/test/java/io/grpc/binder/SecurityPoliciesTest.java @@ -330,7 +330,6 @@ public final class SecurityPoliciesTest { } @Test - @Config(sdk = 19) public void testIsDeviceOwner_succeedsForDeviceOwner() throws Exception { PackageInfo info = newBuilder().setPackageName(OTHER_UID_PACKAGE_NAME).setSignatures(SIG2).build(); @@ -345,7 +344,6 @@ public final class SecurityPoliciesTest { } @Test - @Config(sdk = 19) public void testIsDeviceOwner_failsForNotDeviceOwner() throws Exception { PackageInfo info = newBuilder().setPackageName(OTHER_UID_PACKAGE_NAME).setSignatures(SIG2).build(); @@ -358,7 +356,6 @@ public final class SecurityPoliciesTest { } @Test - @Config(sdk = 19) public void testIsDeviceOwner_failsWhenNoPackagesForUid() throws Exception { policy = SecurityPolicies.isDeviceOwner(appContext); @@ -402,19 +399,6 @@ public final class SecurityPoliciesTest { assertThat(policy.checkAuthorization(OTHER_UID).getCode()).isEqualTo(Status.UNAUTHENTICATED.getCode()); } - @Test - @Config(sdk = 19) - public void testIsProfileOwner_failsForSdkLevelTooLow() throws Exception { - PackageInfo info = - newBuilder().setPackageName(OTHER_UID_PACKAGE_NAME).setSignatures(SIG2).build(); - - installPackages(OTHER_UID, info); - - policy = SecurityPolicies.isProfileOwner(appContext); - - assertThat(policy.checkAuthorization(OTHER_UID).getCode()).isEqualTo(Status.PERMISSION_DENIED.getCode()); - } - @Test @Config(sdk = 30) public void testIsProfileOwnerOnOrgOwned_succeedsForProfileOwnerOnOrgOwned() throws Exception {