1/*
2 * Copyright (C) 2017 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.os.Parcel;
19import android.os.Parcelable;
20
21/**
22 * This class is used to return an SPI and corresponding status from the IpSecService to an
23 * IpSecManager.SecurityParameterIndex.
24 *
25 * @hide
26 */
27public final class IpSecSpiResponse implements Parcelable {
28    private static final String TAG = "IpSecSpiResponse";
29
30    public final int resourceId;
31    public final int status;
32    public final int spi;
33    // Parcelable Methods
34
35    @Override
36    public int describeContents() {
37        return 0;
38    }
39
40    @Override
41    public void writeToParcel(Parcel out, int flags) {
42        out.writeInt(status);
43        out.writeInt(resourceId);
44        out.writeInt(spi);
45    }
46
47    public IpSecSpiResponse(int inStatus, int inResourceId, int inSpi) {
48        status = inStatus;
49        resourceId = inResourceId;
50        spi = inSpi;
51    }
52
53    public IpSecSpiResponse(int inStatus) {
54        if (inStatus == IpSecManager.Status.OK) {
55            throw new IllegalArgumentException("Valid status implies other args must be provided");
56        }
57        status = inStatus;
58        resourceId = IpSecManager.INVALID_RESOURCE_ID;
59        spi = IpSecManager.INVALID_SECURITY_PARAMETER_INDEX;
60    }
61
62    private IpSecSpiResponse(Parcel in) {
63        status = in.readInt();
64        resourceId = in.readInt();
65        spi = in.readInt();
66    }
67
68    public static final Parcelable.Creator<IpSecSpiResponse> CREATOR =
69            new Parcelable.Creator<IpSecSpiResponse>() {
70                public IpSecSpiResponse createFromParcel(Parcel in) {
71                    return new IpSecSpiResponse(in);
72                }
73
74                public IpSecSpiResponse[] newArray(int size) {
75                    return new IpSecSpiResponse[size];
76                }
77            };
78}
79