• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 package android.net;
17 
18 import android.annotation.NonNull;
19 import android.annotation.SystemApi;
20 import android.os.Parcel;
21 import android.os.ParcelFileDescriptor;
22 import android.os.Parcelable;
23 
24 /**
25  * This class is used to return the interface name and fd of the test interface
26  *
27  * @hide
28  */
29 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
30 public final class TestNetworkInterface implements Parcelable {
31     @NonNull
32     private final ParcelFileDescriptor mFileDescriptor;
33     @NonNull
34     private final String mInterfaceName;
35 
36     @Override
describeContents()37     public int describeContents() {
38         return (mFileDescriptor != null) ? Parcelable.CONTENTS_FILE_DESCRIPTOR : 0;
39     }
40 
41     @Override
writeToParcel(@onNull Parcel out, int flags)42     public void writeToParcel(@NonNull Parcel out, int flags) {
43         out.writeParcelable(mFileDescriptor, PARCELABLE_WRITE_RETURN_VALUE);
44         out.writeString(mInterfaceName);
45     }
46 
TestNetworkInterface(@onNull ParcelFileDescriptor pfd, @NonNull String intf)47     public TestNetworkInterface(@NonNull ParcelFileDescriptor pfd, @NonNull String intf) {
48         mFileDescriptor = pfd;
49         mInterfaceName = intf;
50     }
51 
TestNetworkInterface(@onNull Parcel in)52     private TestNetworkInterface(@NonNull Parcel in) {
53         mFileDescriptor = in.readParcelable(ParcelFileDescriptor.class.getClassLoader());
54         mInterfaceName = in.readString();
55     }
56 
57     @NonNull
getFileDescriptor()58     public ParcelFileDescriptor getFileDescriptor() {
59         return mFileDescriptor;
60     }
61 
62     @NonNull
getInterfaceName()63     public String getInterfaceName() {
64         return mInterfaceName;
65     }
66 
67     @NonNull
68     public static final Parcelable.Creator<TestNetworkInterface> CREATOR =
69             new Parcelable.Creator<TestNetworkInterface>() {
70                 public TestNetworkInterface createFromParcel(Parcel in) {
71                     return new TestNetworkInterface(in);
72                 }
73 
74                 public TestNetworkInterface[] newArray(int size) {
75                     return new TestNetworkInterface[size];
76                 }
77             };
78 }
79