From 9904c69fa57ffaf4b557b2d0e6bb30d3db76459f Mon Sep 17 00:00:00 2001 From: Mark Chien Date: Fri, 27 Mar 2020 16:53:45 +0000 Subject: [PATCH 1/2] Unbreak testStartUsingNetworkFeature_enableHipri failure aosp/1261619 break legacy API that only supported for SDK which is smaller than android M, caller need to have network stack permission to request network with legacy type. Fix failure by whitelist permission check for the caller who built with order SDK(< M). Bug: 152229492 Test: atest CtsTetheringTest atest ConnectivityManagerLegacyTest# \ testStartUsingNetworkFeature_enableHipri Change-Id: I02504c0eed10ee4e08c8fbf032951022255ba5fa Merged-In: I367dff0429f26f266282300edc38637b55eece38 (cherry picked from commit b1c8acf0d6ba1fe35d8e81673d2c5c24fa2fea79) --- .../com/android/server/ConnectivityService.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 237a961fd3..5d350be5b0 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -63,6 +63,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageManager; import android.content.res.Configuration; import android.database.ContentObserver; import android.net.CaptivePortal; @@ -5405,12 +5406,25 @@ public class ConnectivityService extends IConnectivityManager.Stub } } + private boolean checkUnsupportedStartingFrom(int version, String callingPackageName) { + final PackageManager pm = mContext.getPackageManager(); + final int userId = UserHandle.getCallingUserId(); + try { + final int callingVersion = pm.getApplicationInfoAsUser( + callingPackageName, 0 /* flags */, userId).targetSdkVersion; + if (callingVersion < version) return false; + } catch (PackageManager.NameNotFoundException e) { } + return true; + } + @Override public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities, Messenger messenger, int timeoutMs, IBinder binder, int legacyType, @NonNull String callingPackageName) { if (legacyType != TYPE_NONE && !checkNetworkStackPermission()) { - throw new SecurityException("Insufficient permissions to specify legacy type"); + if (checkUnsupportedStartingFrom(Build.VERSION_CODES.M, callingPackageName)) { + throw new SecurityException("Insufficient permissions to specify legacy type"); + } } final int callingUid = Binder.getCallingUid(); final NetworkRequest.Type type = (networkCapabilities == null) From ef40b406c5eed1783ee53b31d67717484bc8e727 Mon Sep 17 00:00:00 2001 From: Xiao Ma Date: Thu, 26 Mar 2020 01:36:53 +0000 Subject: [PATCH 2/2] Add CTS tests for ApfCapabilities static APIs. Add tests for getApfEtherTypeBlackList and getApfDrop8023Frames APIs. Bug: 150640397 Test: atest CtsNetTestCasesLatestSdk:android.net.apf.ApfCapabilitiesTest on both of Q and R devices. Change-Id: I11555934df4b27cbb6b7ddbb81022d8fb7c25e15 Merged-In: I11555934df4b27cbb6b7ddbb81022d8fb7c25e15 (cherry picked from commit 7d51a72487dba5b2747a9de12f50ba2087007264) --- .../android/net/apf/ApfCapabilitiesTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/net/common/java/android/net/apf/ApfCapabilitiesTest.java b/tests/net/common/java/android/net/apf/ApfCapabilitiesTest.java index f4f804aff0..84805442e5 100644 --- a/tests/net/common/java/android/net/apf/ApfCapabilitiesTest.java +++ b/tests/net/common/java/android/net/apf/ApfCapabilitiesTest.java @@ -21,17 +21,31 @@ import static com.android.testutils.ParcelUtilsKt.assertParcelSane; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import android.content.Context; + +import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import java.util.Arrays; + @RunWith(AndroidJUnit4.class) @SmallTest public class ApfCapabilitiesTest { + private Context mContext; + + @Before + public void setUp() { + mContext = InstrumentationRegistry.getContext(); + } + @Test public void testConstructAndParcel() { final ApfCapabilities caps = new ApfCapabilities(123, 456, 789); @@ -59,4 +73,27 @@ public class ApfCapabilitiesTest { caps = new ApfCapabilities(4 /* apfVersionSupported */, 5, 6); assertTrue(caps.hasDataAccess()); } + + @Test + public void testGetApfDrop8023Frames() { + // Get com.android.internal.R.bool.config_apfDrop802_3Frames. The test cannot directly + // use R.bool.config_apfDrop802_3Frames because that is not a stable resource ID. + final int resId = mContext.getResources().getIdentifier("config_apfDrop802_3Frames", + "bool", "android"); + final boolean shouldDrop8023Frames = mContext.getResources().getBoolean(resId); + final boolean actual = ApfCapabilities.getApfDrop8023Frames(); + assertEquals(shouldDrop8023Frames, actual); + } + + @Test + public void testGetApfEtherTypeBlackList() { + // Get com.android.internal.R.array.config_apfEthTypeBlackList. The test cannot directly + // use R.array.config_apfEthTypeBlackList because that is not a stable resource ID. + final int resId = mContext.getResources().getIdentifier("config_apfEthTypeBlackList", + "array", "android"); + final int[] blacklistedEtherTypeArray = mContext.getResources().getIntArray(resId); + final int[] actual = ApfCapabilities.getApfEtherTypeBlackList(); + assertNotNull(actual); + assertTrue(Arrays.equals(blacklistedEtherTypeArray, actual)); + } }