• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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  */
16 
17 package com.android.internal.telephony.data;
18 
19 import android.annotation.IntDef;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 
23 /**
24  * This class serves to pass around the parameters of Keepalive session
25  * status within the telephony framework.
26  *
27  * {@hide}
28  */
29 public class KeepaliveStatus implements Parcelable {
30     /** This should match the HAL {@code KeepaliveStatus.aidl}. */
31     @IntDef(prefix = {"STATUS_REASON_"},
32             value = {
33                     STATUS_ACTIVE,
34                     STATUS_INACTIVE,
35                     STATUS_PENDING,
36             })
37     public @interface KeepaliveStatusCode {}
38 
39     public static final int STATUS_ACTIVE = 0;
40     public static final int STATUS_INACTIVE = 1;
41     public static final int STATUS_PENDING = 2;
42 
43     public static final int ERROR_NONE = 0;
44     public static final int ERROR_UNSUPPORTED = 1;
45     public static final int ERROR_NO_RESOURCES = 2;
46     public static final int ERROR_UNKNOWN = 3;
47 
48     public static final int INVALID_HANDLE = Integer.MAX_VALUE;
49 
50     /** An opaque value that identifies this Keepalive status to the modem */
51     public final int sessionHandle;
52 
53     /**
54      * A status code indicating whether this Keepalive session is
55      * active, inactive, or pending activation
56      */
57     public final @KeepaliveStatusCode int statusCode;
58 
59     /** An error code indicating a lower layer failure, if any */
60     public final int errorCode;
61 
KeepaliveStatus(int error)62     public KeepaliveStatus(int error) {
63         sessionHandle = INVALID_HANDLE;
64         statusCode = STATUS_INACTIVE;
65         errorCode = error;
66     }
67 
KeepaliveStatus(int handle, @KeepaliveStatusCode int code)68     public KeepaliveStatus(int handle, @KeepaliveStatusCode int code) {
69         sessionHandle = handle;
70         statusCode = code;
71         errorCode = ERROR_NONE;
72     }
73 
74 
75     @Override
toString()76     public String toString() {
77         return String.format("{errorCode=%d, sessionHandle=%d, statusCode=%d}",
78                 errorCode, sessionHandle, statusCode);
79     }
80 
81     // Parcelable Implementation
82     @Override
describeContents()83     public int describeContents() {
84         return 0;
85     }
86 
87     @Override
writeToParcel(Parcel dest, int flags)88     public void writeToParcel(Parcel dest, int flags) {
89         dest.writeInt(errorCode);
90         dest.writeInt(sessionHandle);
91         dest.writeInt(statusCode);
92     }
93 
KeepaliveStatus(Parcel p)94     private KeepaliveStatus(Parcel p) {
95         errorCode = p.readInt();
96         sessionHandle = p.readInt();
97         statusCode = p.readInt();
98     }
99 
100     public static final Parcelable.Creator<KeepaliveStatus> CREATOR =
101             new Parcelable.Creator<KeepaliveStatus>() {
102                 @Override
103                 public KeepaliveStatus createFromParcel(Parcel source) {
104                     return new KeepaliveStatus(source);
105                 }
106 
107                 @Override
108                 public KeepaliveStatus[] newArray(int size) {
109                     return new KeepaliveStatus[size];
110                 }
111             };
112 }
113