blob: 30e68f5b9854c10ffe6fdb6a31c54582a14df335 [file] [log] [blame]
Benedict Wonge40eab62018-11-14 17:50:13 -08001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package android.net;
17
18import android.annotation.TestApi;
19import android.os.Parcel;
20import android.os.ParcelFileDescriptor;
21import android.os.Parcelable;
22
23/**
24 * This class is used to return the interface name and fd of the test interface
25 *
26 * @hide
27 */
28@TestApi
29public final class TestNetworkInterface implements Parcelable {
30 private static final String TAG = "TestNetworkInterface";
31
32 private final ParcelFileDescriptor mFileDescriptor;
33 private final String mInterfaceName;
34
35 @Override
36 public int describeContents() {
37 return (mFileDescriptor != null) ? Parcelable.CONTENTS_FILE_DESCRIPTOR : 0;
38 }
39
40 @Override
41 public void writeToParcel(Parcel out, int flags) {
42 out.writeParcelable(mFileDescriptor, PARCELABLE_WRITE_RETURN_VALUE);
43 out.writeString(mInterfaceName);
44 }
45
46 public TestNetworkInterface(ParcelFileDescriptor pfd, String intf) {
47 mFileDescriptor = pfd;
48 mInterfaceName = intf;
49 }
50
51 private TestNetworkInterface(Parcel in) {
52 mFileDescriptor = in.readParcelable(ParcelFileDescriptor.class.getClassLoader());
53 mInterfaceName = in.readString();
54 }
55
56 public ParcelFileDescriptor getFileDescriptor() {
57 return mFileDescriptor;
58 }
59
60 public String getInterfaceName() {
61 return mInterfaceName;
62 }
63
64 public static final Parcelable.Creator<TestNetworkInterface> CREATOR =
65 new Parcelable.Creator<TestNetworkInterface>() {
66 public TestNetworkInterface createFromParcel(Parcel in) {
67 return new TestNetworkInterface(in);
68 }
69
70 public TestNetworkInterface[] newArray(int size) {
71 return new TestNetworkInterface[size];
72 }
73 };
74}