2 * Copyright 2011 Google Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.ipc.invalidation.external.client.android.service;
19 import com.google.ipc.invalidation.external.client.types.ErrorInfo;
21 import android.os.Parcel;
22 import android.os.Parcelable;
25 * Wraps an {link ErrorInfo} to enable writing to and reading from a
28 class ParcelableErrorInfo implements Parcelable {
29 final ErrorInfo errorInfo;
32 * Creator required by the Parcelable implementation conventions.
34 public static final Parcelable.Creator<ParcelableErrorInfo> CREATOR =
35 new Parcelable.Creator<ParcelableErrorInfo>() {
37 public ParcelableErrorInfo createFromParcel(Parcel in) {
38 return new ParcelableErrorInfo(in);
42 public ParcelableErrorInfo[] newArray(int size) {
43 return new ParcelableErrorInfo[size];
48 * Creates a new wrapper around the provided error info.
50 ParcelableErrorInfo(ErrorInfo errorInfo) {
51 this.errorInfo = errorInfo;
55 * Creates a new ErrorInfo wrapper by reading data from a parcel.
57 public ParcelableErrorInfo(Parcel in) {
58 int reason = in.readInt();
59 boolean isTransient = in.createBooleanArray()[0];
60 String message = in.readString();
61 this.errorInfo = ErrorInfo.newInstance(reason, isTransient, message, null);
65 public int describeContents() {
66 return 0; // no special contents
70 public void writeToParcel(Parcel parcel, int flags) {
72 // Data written to parcel is:
74 // 2. boolean [] { isTransient }
75 // 3. String error message
76 // TODO: Add support for object marshaling when needed
77 parcel.writeInt(errorInfo.getErrorReason());
78 parcel.writeBooleanArray(new boolean[]{errorInfo.isTransient()});
79 parcel.writeString(errorInfo.getErrorMessage());
83 public boolean equals(Object object) {
84 return object instanceof ParcelableErrorInfo
85 && errorInfo.equals(((ParcelableErrorInfo) object).errorInfo);
89 public int hashCode() {
90 return errorInfo.hashCode();