Merge "Add Parcelable implementation for ApfCapabilities" am: d64b329979 am: 57b7aa8ec2
am: 84890d80e0
Change-Id: I4d878b8dc0928aca47f944050becaa4d5206e336
This commit is contained in:
@@ -19,17 +19,20 @@ package android.net.apf;
|
|||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APF program support capabilities.
|
* APF program support capabilities.
|
||||||
*
|
*
|
||||||
|
* This class is immutable.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@TestApi
|
@TestApi
|
||||||
public class ApfCapabilities {
|
public final class ApfCapabilities implements Parcelable {
|
||||||
/**
|
/**
|
||||||
* Version of APF instruction set supported for packet filtering. 0 indicates no support for
|
* Version of APF instruction set supported for packet filtering. 0 indicates no support for
|
||||||
* packet filtering using APF programs.
|
* packet filtering using APF programs.
|
||||||
@@ -53,6 +56,37 @@ public class ApfCapabilities {
|
|||||||
this.apfPacketFormat = apfPacketFormat;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s{version: %d, maxSize: %d, format: %d}", getClass().getSimpleName(),
|
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