Check the existence of IpSecTransformState API with try catch

IpSecTransformState is a new API that exposed from a mainline module.
Ideally before SDK finalization, platform should check the API flag
com.android.net.flags.ipsec_transform_state before calling the API.
However the flag is defined in mainline module is not accessible from
the platform. Thus previously a placeholder flag was used.

This patch removes the usage of the placeholder flag. Instead the
code will check the availability of the API with a try catch block

Bug: 328844044
Test: atest FrameworksVcnTests && atest CtsVcnTestCases
Flag: NONE mainline API flag not accessible; using try catch
      block to gate the behavior
Change-Id: Ibbcb14817a6d714cdc99cf0894f1fc935a602a2c
This commit is contained in:
Yan Yan 2024-04-16 23:30:21 +00:00
commit 95d50c97ef
2 changed files with 11 additions and 4 deletions

View file

@ -18,6 +18,7 @@ package com.android.server.vcn;
import android.annotation.NonNull;
import android.content.Context;
import android.net.IpSecTransformState;
import android.net.vcn.FeatureFlags;
import android.net.vcn.FeatureFlagsImpl;
import android.os.Looper;
@ -34,7 +35,6 @@ public class VcnContext {
@NonNull private final Looper mLooper;
@NonNull private final VcnNetworkProvider mVcnNetworkProvider;
@NonNull private final FeatureFlags mFeatureFlags;
@NonNull private final android.net.platform.flags.FeatureFlags mCoreNetFeatureFlags;
private final boolean mIsInTestMode;
public VcnContext(
@ -49,7 +49,6 @@ public class VcnContext {
// Auto-generated class
mFeatureFlags = new FeatureFlagsImpl();
mCoreNetFeatureFlags = new android.net.platform.flags.FeatureFlagsImpl();
}
@NonNull
@ -76,7 +75,16 @@ public class VcnContext {
}
public boolean isFlagIpSecTransformStateEnabled() {
return mCoreNetFeatureFlags.ipsecTransformState();
// TODO: b/328844044: Ideally this code should gate the behavior by checking the
// android.net.platform.flags.ipsec_transform_state flag but that flag is not accessible
// right now. We should either update the code when the flag is accessible or remove the
// legacy behavior after VIC SDK finalization
try {
new IpSecTransformState.Builder();
return true;
} catch (Exception e) {
return false;
}
}
@NonNull

View file

@ -107,7 +107,6 @@ public abstract class NetworkEvaluationTestBase {
@Mock protected Context mContext;
@Mock protected Network mNetwork;
@Mock protected FeatureFlags mFeatureFlags;
@Mock protected android.net.platform.flags.FeatureFlags mCoreNetFeatureFlags;
@Mock protected TelephonySubscriptionSnapshot mSubscriptionSnapshot;
@Mock protected ConnectivityManager mConnectivityManager;
@Mock protected TelephonyManager mTelephonyManager;