• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 android.net.ipmemorystore;
18 
19 import android.annotation.NonNull;
20 
21 import com.android.internal.annotations.VisibleForTesting;
22 
23 /**
24  * A parcelable status representing the result of an operation.
25  * Parcels as StatusParceled.
26  * @hide
27  */
28 public class Status {
29     public static final int SUCCESS = 0;
30 
31     public static final int ERROR_GENERIC = -1;
32     public static final int ERROR_ILLEGAL_ARGUMENT = -2;
33     public static final int ERROR_DATABASE_CANNOT_BE_OPENED = -3;
34     public static final int ERROR_STORAGE = -4;
35     public static final int ERROR_UNKNOWN = -5;
36 
37     public final int resultCode;
38 
Status(final int resultCode)39     public Status(final int resultCode) {
40         this.resultCode = resultCode;
41     }
42 
43     @VisibleForTesting
Status(@onNull final StatusParcelable parcelable)44     public Status(@NonNull final StatusParcelable parcelable) {
45         this(parcelable.resultCode);
46     }
47 
48     /** Converts this Status to a parcelable object */
49     @NonNull
toParcelable()50     public StatusParcelable toParcelable() {
51         final StatusParcelable parcelable = new StatusParcelable();
52         parcelable.resultCode = resultCode;
53         return parcelable;
54     }
55 
isSuccess()56     public boolean isSuccess() {
57         return SUCCESS == resultCode;
58     }
59 
60     /** Pretty print */
61     @Override
toString()62     public String toString() {
63         switch (resultCode) {
64             case SUCCESS: return "SUCCESS";
65             case ERROR_GENERIC: return "GENERIC ERROR";
66             case ERROR_ILLEGAL_ARGUMENT: return "ILLEGAL ARGUMENT";
67             case ERROR_DATABASE_CANNOT_BE_OPENED: return "DATABASE CANNOT BE OPENED";
68             // "DB storage error" is not very helpful but SQLite does not provide specific error
69             // codes upon store failure. Thus this indicates SQLite returned some error upon store
70             case ERROR_STORAGE: return "DATABASE STORAGE ERROR";
71             default: return "Unknown value ?!";
72         }
73     }
74 }
75