AccountManagerResponse.java revision 9efe265f086d482802c236ae1a4ef75507efa76d
1/*
2 * Copyright (C) 2009 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
17package android.accounts;
18
19import android.os.Bundle;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.os.RemoteException;
23
24/**
25 * Used by Account Authenticators to return a response.
26 */
27public class AccountManagerResponse implements Parcelable {
28    private IAccountManagerResponse mResponse;
29
30    /** @hide */
31    public AccountManagerResponse(IAccountManagerResponse response) {
32        mResponse = response;
33    }
34
35    /** @hide */
36    public AccountManagerResponse(Parcel parcel) {
37        mResponse =
38                IAccountManagerResponse.Stub.asInterface(parcel.readStrongBinder());
39    }
40
41    public void onResult(Bundle result) {
42        try {
43            mResponse.onResult(result);
44        } catch (RemoteException e) {
45            // this should never happen
46        }
47    }
48
49    public void onError(int errorCode, String errorMessage) {
50        try {
51            mResponse.onError(errorCode, errorMessage);
52        } catch (RemoteException e) {
53            // this should never happen
54        }
55    }
56
57    /** @hide */
58    public int describeContents() {
59        return 0;
60    }
61
62    /** @hide */
63    public void writeToParcel(Parcel dest, int flags) {
64        dest.writeStrongBinder(mResponse.asBinder());
65    }
66
67    /** @hide */
68    public static final Creator<AccountManagerResponse> CREATOR =
69            new Creator<AccountManagerResponse>() {
70        public AccountManagerResponse createFromParcel(Parcel source) {
71            return new AccountManagerResponse(source);
72        }
73
74        public AccountManagerResponse[] newArray(int size) {
75            return new AccountManagerResponse[size];
76        }
77    };
78}
79