AccountAuthenticatorResponse.java revision a698f4276968d078b1b9e2f3738c4f559a3307b2
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 that wraps calls to an {@link IAccountAuthenticatorResponse} object.
26 * TODO: this interface is still in flux
27 */
28public class AccountAuthenticatorResponse implements Parcelable {
29    private IAccountAuthenticatorResponse mAccountAuthenticatorResponse;
30
31    public AccountAuthenticatorResponse(IAccountAuthenticatorResponse response) {
32        mAccountAuthenticatorResponse = response;
33    }
34
35    public AccountAuthenticatorResponse(Parcel parcel) {
36        mAccountAuthenticatorResponse =
37                IAccountAuthenticatorResponse.Stub.asInterface(parcel.readStrongBinder());
38    }
39
40    public void onResult(Bundle result) {
41        try {
42            mAccountAuthenticatorResponse.onResult(result);
43        } catch (RemoteException e) {
44            // this should never happen
45        }
46    }
47
48    public void onRequestContinued() {
49        try {
50            mAccountAuthenticatorResponse.onRequestContinued();
51        } catch (RemoteException e) {
52            // this should never happen
53        }
54    }
55
56    public void onError(int errorCode, String errorMessage) {
57        try {
58            mAccountAuthenticatorResponse.onError(errorCode, errorMessage);
59        } catch (RemoteException e) {
60            // this should never happen
61        }
62    }
63
64    public int describeContents() {
65        return 0;
66    }
67
68    public void writeToParcel(Parcel dest, int flags) {
69        dest.writeStrongBinder(mAccountAuthenticatorResponse.asBinder());
70    }
71
72    public static final Creator<AccountAuthenticatorResponse> CREATOR =
73            new Creator<AccountAuthenticatorResponse>() {
74        public AccountAuthenticatorResponse createFromParcel(Parcel source) {
75            return new AccountAuthenticatorResponse(source);
76        }
77
78        public AccountAuthenticatorResponse[] newArray(int size) {
79            return new AccountAuthenticatorResponse[size];
80        }
81    };
82}
83