1038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly/*
2590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly * Copyright (C) 2010, The Android Open Source Project
3038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly *
4038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * Licensed under the Apache License, Version 2.0 (the "License");
5038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * you may not use this file except in compliance with the License.
6038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * You may obtain a copy of the License at
7038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly *
8590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly *     http://www.apache.org/licenses/LICENSE-2.0
9038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly *
10038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * Unless required by applicable law or agreed to in writing, software
11038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * distributed under the License is distributed on an "AS IS" BASIS,
12038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * See the License for the specific language governing permissions and
14038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * limitations under the License.
15038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly */
16038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
17590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pellypackage android.nfc;
18038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
19038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly/**
20038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * This class defines all the error codes that can be returned by the service
21038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * and producing an exception on the application level. These are needed since
22038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * binders does not support exceptions.
23590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly *
24038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly * @hide
25038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly */
26038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pellypublic class ErrorCodes {
27038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
28038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static boolean isError(int code) {
29038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly        if (code < 0) {
30038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly            return true;
31038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly        } else {
32038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly            return false;
33038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly        }
34038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    }
35038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
3668a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton    public static String asString(int code) {
3768a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton        switch (code) {
3868a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case SUCCESS: return "SUCCESS";
3968a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_IO: return "IO";
4068a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_CANCELLED: return "CANCELLED";
4168a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_TIMEOUT: return "TIMEOUT";
4268a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_BUSY: return "BUSY";
4368a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_CONNECT: return "CONNECT/DISCONNECT";
4468a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton//            case ERROR_DISCONNECT: return "DISCONNECT";
4568a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_READ: return "READ";
4668a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_WRITE: return "WRITE";
4768a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_INVALID_PARAM: return "INVALID_PARAM";
4868a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_INSUFFICIENT_RESOURCES: return "INSUFFICIENT_RESOURCES";
4968a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_SOCKET_CREATION: return "SOCKET_CREATION";
5068a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_SOCKET_NOT_CONNECTED: return "SOCKET_NOT_CONNECTED";
5168a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_BUFFER_TO_SMALL: return "BUFFER_TO_SMALL";
5268a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_SAP_USED: return "SAP_USED";
5368a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_SERVICE_NAME_USED: return "SERVICE_NAME_USED";
5468a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_SOCKET_OPTIONS: return "SOCKET_OPTIONS";
5568a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_NFC_ON: return "NFC_ON";
5668a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_NOT_INITIALIZED: return "NOT_INITIALIZED";
5768a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_SE_ALREADY_SELECTED: return "SE_ALREADY_SELECTED";
5868a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_SE_CONNECTED: return "SE_CONNECTED";
5968a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            case ERROR_NO_SE_CONNECTED: return "NO_SE_CONNECTED";
60ea51a4275ab7353d537ff94d97e6294e49b50cabMartijn Coenen            case ERROR_NOT_SUPPORTED: return "NOT_SUPPORTED";
6168a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton            default: return "UNKNOWN ERROR";
6268a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton        }
6368a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton    }
6468a5c9f3cf7292beec7ff4769b2005fed0438a7eJeff Hamilton
65038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int SUCCESS = 0;
66590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
67038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_IO = -1;
68038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
69038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_CANCELLED = -2;
70038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
71038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_TIMEOUT = -3;
72038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
73038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_BUSY = -4;
74038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
75038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_CONNECT = -5;
76038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
77038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_DISCONNECT = -5;
78038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
79038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_READ = -6;
80038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
81038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_WRITE = -7;
82038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
83038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_INVALID_PARAM = -8;
84590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
85038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_INSUFFICIENT_RESOURCES = -9;
86590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
87038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_SOCKET_CREATION = -10;
88590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
89038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_SOCKET_NOT_CONNECTED = -11;
90590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
91038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_BUFFER_TO_SMALL = -12;
92038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly
93038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_SAP_USED = -13;
94590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
95038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_SERVICE_NAME_USED = -14;
96590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
97038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_SOCKET_OPTIONS = -15;
98590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
99038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_NFC_ON = -16;
100590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
101038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_NOT_INITIALIZED = -17;
102590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
103038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_SE_ALREADY_SELECTED = -18;
104590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
105038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_SE_CONNECTED = -19;
106590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
107038cabe0247ee46df62f9363f1a303bc5b9c1028Nick Pelly    public static final int ERROR_NO_SE_CONNECTED = -20;
108590b73bc5b8e5f7b59bff1d9264a52388a5162e6Nick Pelly
109ea51a4275ab7353d537ff94d97e6294e49b50cabMartijn Coenen    public static final int ERROR_NOT_SUPPORTED = -21;
110ea51a4275ab7353d537ff94d97e6294e49b50cabMartijn Coenen
111ea51a4275ab7353d537ff94d97e6294e49b50cabMartijn Coenen}
112