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 * <p> 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 @KeepaliveStatusCode 58 public final int statusCode; 59 60 /** An error code indicating a lower layer failure, if any */ 61 public final int errorCode; 62 KeepaliveStatus(int error)63 public KeepaliveStatus(int error) { 64 sessionHandle = INVALID_HANDLE; 65 statusCode = STATUS_INACTIVE; 66 errorCode = error; 67 } 68 KeepaliveStatus(int handle, @KeepaliveStatusCode int code)69 public KeepaliveStatus(int handle, @KeepaliveStatusCode int code) { 70 sessionHandle = handle; 71 statusCode = code; 72 errorCode = ERROR_NONE; 73 } 74 75 76 @Override toString()77 public String toString() { 78 return String.format("{errorCode=%d, sessionHandle=%d, statusCode=%d}", 79 errorCode, sessionHandle, statusCode); 80 } 81 82 // Parcelable Implementation 83 @Override describeContents()84 public int describeContents() { 85 return 0; 86 } 87 88 @Override writeToParcel(Parcel dest, int flags)89 public void writeToParcel(Parcel dest, int flags) { 90 dest.writeInt(errorCode); 91 dest.writeInt(sessionHandle); 92 dest.writeInt(statusCode); 93 } 94 KeepaliveStatus(Parcel p)95 private KeepaliveStatus(Parcel p) { 96 errorCode = p.readInt(); 97 sessionHandle = p.readInt(); 98 statusCode = p.readInt(); 99 } 100 101 public static final Parcelable.Creator<KeepaliveStatus> CREATOR = 102 new Parcelable.Creator<>() { 103 @Override 104 public KeepaliveStatus createFromParcel(Parcel source) { 105 return new KeepaliveStatus(source); 106 } 107 108 @Override 109 public KeepaliveStatus[] newArray(int size) { 110 return new KeepaliveStatus[size]; 111 } 112 }; 113 } 114