AccountAuthenticatorResponse.java revision 89c40f50347f8ec3128611a7d1c5e4e0eeb01fc2
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.Parcelable;
21import android.os.Parcel;
22import android.os.RemoteException;
23
24/**
25 * Object used to communicate responses back to the AccountManager
26 */
27public class AccountAuthenticatorResponse implements Parcelable {
28    private IAccountAuthenticatorResponse mAccountAuthenticatorResponse;
29
30    /**
31     * @hide
32     */
33    /* package private */ AccountAuthenticatorResponse(IAccountAuthenticatorResponse response) {
34        mAccountAuthenticatorResponse = response;
35    }
36
37    public AccountAuthenticatorResponse(Parcel parcel) {
38        mAccountAuthenticatorResponse =
39                IAccountAuthenticatorResponse.Stub.asInterface(parcel.readStrongBinder());
40    }
41
42    public void onResult(Bundle result) {
43        try {
44            mAccountAuthenticatorResponse.onResult(result);
45        } catch (RemoteException e) {
46            // this should never happen
47        }
48    }
49
50    public void onRequestContinued() {
51        try {
52            mAccountAuthenticatorResponse.onRequestContinued();
53        } catch (RemoteException e) {
54            // this should never happen
55        }
56    }
57
58    public void onError(int errorCode, String errorMessage) {
59        try {
60            mAccountAuthenticatorResponse.onError(errorCode, errorMessage);
61        } catch (RemoteException e) {
62            // this should never happen
63        }
64    }
65
66    public int describeContents() {
67        return 0;
68    }
69
70    public void writeToParcel(Parcel dest, int flags) {
71        dest.writeStrongBinder(mAccountAuthenticatorResponse.asBinder());
72    }
73
74    public static final Creator<AccountAuthenticatorResponse> CREATOR =
75            new Creator<AccountAuthenticatorResponse>() {
76        public AccountAuthenticatorResponse createFromParcel(Parcel source) {
77            return new AccountAuthenticatorResponse(source);
78        }
79
80        public AccountAuthenticatorResponse[] newArray(int size) {
81            return new AccountAuthenticatorResponse[size];
82        }
83    };
84}
85