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