Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Narayan Kamath | f1a9b1b | 2014-11-27 17:20:21 +0000 | [diff] [blame] | 17 | package android.webkit; |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
| 20 | import android.util.Log; |
| 21 | |
| 22 | /** |
| 23 | * Localized strings for the error codes defined in EventHandler. |
| 24 | * |
| 25 | * {@hide} |
| 26 | */ |
Narayan Kamath | f1a9b1b | 2014-11-27 17:20:21 +0000 | [diff] [blame] | 27 | class LegacyErrorStrings { |
| 28 | private LegacyErrorStrings() { /* Utility class, don't instantiate. */ } |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 29 | |
| 30 | private static final String LOGTAG = "Http"; |
| 31 | |
| 32 | /** |
| 33 | * Get the localized error message resource for the given error code. |
| 34 | * If the code is unknown, we'll return a generic error message. |
| 35 | */ |
Narayan Kamath | f1a9b1b | 2014-11-27 17:20:21 +0000 | [diff] [blame] | 36 | static String getString(int errorCode, Context context) { |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 37 | return context.getText(getResource(errorCode)).toString(); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Get the localized error message resource for the given error code. |
| 42 | * If the code is unknown, we'll return a generic error message. |
| 43 | */ |
Narayan Kamath | f1a9b1b | 2014-11-27 17:20:21 +0000 | [diff] [blame] | 44 | private static int getResource(int errorCode) { |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 45 | switch(errorCode) { |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 46 | case 0: /* EventHandler.OK: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 47 | return com.android.internal.R.string.httpErrorOk; |
| 48 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 49 | case -1: /* EventHandler.ERROR: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 50 | return com.android.internal.R.string.httpError; |
| 51 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 52 | case -2: /* EventHandler.ERROR_LOOKUP: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 53 | return com.android.internal.R.string.httpErrorLookup; |
| 54 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 55 | case -3: /* EventHandler.ERROR_UNSUPPORTED_AUTH_SCHEME: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 56 | return com.android.internal.R.string.httpErrorUnsupportedAuthScheme; |
| 57 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 58 | case -4: /* EventHandler.ERROR_AUTH: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 59 | return com.android.internal.R.string.httpErrorAuth; |
| 60 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 61 | case -5: /* EventHandler.ERROR_PROXYAUTH: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 62 | return com.android.internal.R.string.httpErrorProxyAuth; |
| 63 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 64 | case -6: /* EventHandler.ERROR_CONNECT: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 65 | return com.android.internal.R.string.httpErrorConnect; |
| 66 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 67 | case -7: /* EventHandler.ERROR_IO: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 68 | return com.android.internal.R.string.httpErrorIO; |
| 69 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 70 | case -8: /* EventHandler.ERROR_TIMEOUT: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 71 | return com.android.internal.R.string.httpErrorTimeout; |
| 72 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 73 | case -9: /* EventHandler.ERROR_REDIRECT_LOOP: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 74 | return com.android.internal.R.string.httpErrorRedirectLoop; |
| 75 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 76 | case -10: /* EventHandler.ERROR_UNSUPPORTED_SCHEME: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 77 | return com.android.internal.R.string.httpErrorUnsupportedScheme; |
| 78 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 79 | case -11: /* EventHandler.ERROR_FAILED_SSL_HANDSHAKE: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 80 | return com.android.internal.R.string.httpErrorFailedSslHandshake; |
| 81 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 82 | case -12: /* EventHandler.ERROR_BAD_URL: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 83 | return com.android.internal.R.string.httpErrorBadUrl; |
| 84 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 85 | case -13: /* EventHandler.FILE_ERROR: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 86 | return com.android.internal.R.string.httpErrorFile; |
| 87 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 88 | case -14: /* EventHandler.FILE_NOT_FOUND_ERROR: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 89 | return com.android.internal.R.string.httpErrorFileNotFound; |
| 90 | |
Narayan Kamath | 3bdd327 | 2014-11-27 18:17:35 +0000 | [diff] [blame^] | 91 | case -15: /* EventHandler.TOO_MANY_REQUESTS_ERROR: */ |
Iain Merrick | 83d4a23 | 2010-11-12 14:11:16 +0000 | [diff] [blame] | 92 | return com.android.internal.R.string.httpErrorTooManyRequests; |
| 93 | |
| 94 | default: |
| 95 | Log.w(LOGTAG, "Using generic message for unknown error code: " + errorCode); |
| 96 | return com.android.internal.R.string.httpError; |
| 97 | } |
| 98 | } |
| 99 | } |