blob: 84550834be070d4f0e6e723f20ba8d6fd0cc6e1a [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 {
Benedict Wonge40eab62018-11-14 17:50:13 -080030 private final ParcelFileDescriptor mFileDescriptor;
31 private final String mInterfaceName;
32
33 @Override
34 public int describeContents() {
35 return (mFileDescriptor != null) ? Parcelable.CONTENTS_FILE_DESCRIPTOR : 0;
36 }
37
38 @Override
39 public void writeToParcel(Parcel out, int flags) {
40 out.writeParcelable(mFileDescriptor, PARCELABLE_WRITE_RETURN_VALUE);
41 out.writeString(mInterfaceName);
42 }
43
44 public TestNetworkInterface(ParcelFileDescriptor pfd, String intf) {
45 mFileDescriptor = pfd;
46 mInterfaceName = intf;
47 }
48
49 private TestNetworkInterface(Parcel in) {
50 mFileDescriptor = in.readParcelable(ParcelFileDescriptor.class.getClassLoader());
51 mInterfaceName = in.readString();
52 }
53
54 public ParcelFileDescriptor getFileDescriptor() {
55 return mFileDescriptor;
56 }
57
58 public String getInterfaceName() {
59 return mInterfaceName;
60 }
61
62 public static final Parcelable.Creator<TestNetworkInterface> CREATOR =
63 new Parcelable.Creator<TestNetworkInterface>() {
64 public TestNetworkInterface createFromParcel(Parcel in) {
65 return new TestNetworkInterface(in);
66 }
67
68 public TestNetworkInterface[] newArray(int size) {
69 return new TestNetworkInterface[size];
70 }
71 };
72}