Add Parcelable implementation for ApfCapabilities
This is necessary to allow usage of ApfCapabilities as-is in AIDL, instead of relying on ApfCapabilitiesParcelable, assuming that stable AIDL starts allowing usage of @SystemApi classes. The Parcelable implementation would be convenient for clients in any case. Bug: 126477266 Test: atest FrameworksNetTests Change-Id: Id2ef3cad261832a2918ccb6bb6bc154d99d75746
This commit is contained in:
@@ -19,17 +19,20 @@ package android.net.apf;
|
||||
import android.annotation.SystemApi;
|
||||
import android.annotation.TestApi;
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
/**
|
||||
* APF program support capabilities.
|
||||
*
|
||||
* This class is immutable.
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
@TestApi
|
||||
public class ApfCapabilities {
|
||||
public final class ApfCapabilities implements Parcelable {
|
||||
/**
|
||||
* Version of APF instruction set supported for packet filtering. 0 indicates no support for
|
||||
* packet filtering using APF programs.
|
||||
@@ -53,6 +56,37 @@ public class ApfCapabilities {
|
||||
this.apfPacketFormat = apfPacketFormat;
|
||||
}
|
||||
|
||||
private ApfCapabilities(Parcel in) {
|
||||
apfVersionSupported = in.readInt();
|
||||
maximumApfProgramSize = in.readInt();
|
||||
apfPacketFormat = in.readInt();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(apfVersionSupported);
|
||||
dest.writeInt(maximumApfProgramSize);
|
||||
dest.writeInt(apfPacketFormat);
|
||||
}
|
||||
|
||||
public static final Creator<ApfCapabilities> CREATOR = new Creator<ApfCapabilities>() {
|
||||
@Override
|
||||
public ApfCapabilities createFromParcel(Parcel in) {
|
||||
return new ApfCapabilities(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApfCapabilities[] newArray(int size) {
|
||||
return new ApfCapabilities[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s{version: %d, maxSize: %d, format: %d}", getClass().getSimpleName(),
|
||||
|
||||
50
tests/net/java/android/net/apf/ApfCapabilitiesTest.java
Normal file
50
tests/net/java/android/net/apf/ApfCapabilitiesTest.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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 android.net.apf;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import android.net.shared.ParcelableTestUtil;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.util.TestUtils;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class ApfCapabilitiesTest {
|
||||
@Test
|
||||
public void testParcelUnparcel() {
|
||||
final ApfCapabilities caps = new ApfCapabilities(123, 456, 789);
|
||||
ParcelableTestUtil.assertFieldCountEquals(3, ApfCapabilities.class);
|
||||
|
||||
TestUtils.assertParcelingIsLossless(caps, ApfCapabilities.CREATOR);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
assertEquals(new ApfCapabilities(1, 2, 3), new ApfCapabilities(1, 2, 3));
|
||||
assertNotEquals(new ApfCapabilities(2, 2, 3), new ApfCapabilities(1, 2, 3));
|
||||
assertNotEquals(new ApfCapabilities(1, 3, 3), new ApfCapabilities(1, 2, 3));
|
||||
assertNotEquals(new ApfCapabilities(1, 2, 4), new ApfCapabilities(1, 2, 3));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user