San Mehat | 4c27e0e | 2010-01-29 05:22:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.server; |
| 18 | |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 19 | import android.os.Parcel; |
| 20 | |
San Mehat | 4c27e0e | 2010-01-29 05:22:17 -0800 | [diff] [blame] | 21 | /** |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 22 | * An exception that indicates there was an error with a |
| 23 | * {@link NativeDaemonConnector} operation. |
San Mehat | 4c27e0e | 2010-01-29 05:22:17 -0800 | [diff] [blame] | 24 | */ |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 25 | public class NativeDaemonConnectorException extends Exception { |
San Mehat | ec4caa0 | 2010-02-03 10:48:21 -0800 | [diff] [blame] | 26 | private String mCmd; |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 27 | private NativeDaemonEvent mEvent; |
San Mehat | 4c27e0e | 2010-01-29 05:22:17 -0800 | [diff] [blame] | 28 | |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 29 | public NativeDaemonConnectorException(String detailMessage) { |
| 30 | super(detailMessage); |
San Mehat | 4c27e0e | 2010-01-29 05:22:17 -0800 | [diff] [blame] | 31 | } |
| 32 | |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 33 | public NativeDaemonConnectorException(String detailMessage, Throwable throwable) { |
| 34 | super(detailMessage, throwable); |
| 35 | } |
| 36 | |
| 37 | public NativeDaemonConnectorException(String cmd, NativeDaemonEvent event) { |
| 38 | super("command '" + cmd + "' failed with '" + event + "'"); |
San Mehat | ec4caa0 | 2010-02-03 10:48:21 -0800 | [diff] [blame] | 39 | mCmd = cmd; |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 40 | mEvent = event; |
San Mehat | 4c27e0e | 2010-01-29 05:22:17 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | public int getCode() { |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 44 | return mEvent.getCode(); |
San Mehat | 4c27e0e | 2010-01-29 05:22:17 -0800 | [diff] [blame] | 45 | } |
San Mehat | ec4caa0 | 2010-02-03 10:48:21 -0800 | [diff] [blame] | 46 | |
| 47 | public String getCmd() { |
| 48 | return mCmd; |
| 49 | } |
Jeff Sharkey | 31c6e48 | 2011-11-18 17:09:01 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Rethrow as a {@link RuntimeException} subclass that is handled by |
| 53 | * {@link Parcel#writeException(Exception)}. |
| 54 | */ |
| 55 | public IllegalArgumentException rethrowAsParcelableException() { |
| 56 | throw new IllegalStateException(getMessage(), this); |
| 57 | } |
San Mehat | 4c27e0e | 2010-01-29 05:22:17 -0800 | [diff] [blame] | 58 | } |