1a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana/* 2a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * Copyright (C) 2009 The Android Open Source Project 3a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * 4a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * Licensed under the Apache License, Version 2.0 (the "License"); 5a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * you may not use this file except in compliance with the License. 6a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * You may obtain a copy of the License at 7a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * 8a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * http://www.apache.org/licenses/LICENSE-2.0 9a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * 10a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * Unless required by applicable law or agreed to in writing, software 11a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * distributed under the License is distributed on an "AS IS" BASIS, 12a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * See the License for the specific language governing permissions and 14a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * limitations under the License. 15a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana */ 16a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana 17a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintanapackage android.accounts; 18a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana 19a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintanaimport android.app.Activity; 20a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintanaimport android.os.Bundle; 21a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana 22a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana/** 23a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * Base class for implementing an Activity that is used to help implement an 24756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * AbstractAccountAuthenticator. If the AbstractAccountAuthenticator needs to use an activity 25756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * to handle the request then it can have the activity extend AccountAuthenticatorActivity. 26756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * The AbstractAccountAuthenticator passes in the response to the intent using the following: 27756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <pre> 2846703b099516c383a6882815bcf9cd4df0ec538dBrian Carlstrom * intent.putExtra({@link AccountManager#KEY_ACCOUNT_AUTHENTICATOR_RESPONSE}, response); 29756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * </pre> 30756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * The activity then sets the result that is to be handed to the response via 31756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * {@link #setAccountAuthenticatorResult(android.os.Bundle)}. 32a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * This result will be sent as the result of the request when the activity finishes. If this 33756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * is never set or if it is set to null then error {@link AccountManager#ERROR_CODE_CANCELED} 34756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * will be called on the response. 35a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana */ 36a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintanapublic class AccountAuthenticatorActivity extends Activity { 37a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null; 38a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana private Bundle mResultBundle = null; 39a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana 40a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana /** 41a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * Set the result that is to be sent as the result of the request that caused this 42a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * Activity to be launched. If result is null or this method is never called then 43a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * the request will be canceled. 44a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * @param result this is returned as the result of the AbstractAccountAuthenticator request 45a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana */ 46a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana public final void setAccountAuthenticatorResult(Bundle result) { 47a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana mResultBundle = result; 48a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana } 49a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana 50a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana /** 51a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * Retreives the AccountAuthenticatorResponse from either the intent of the icicle, if the 52a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * icicle is non-zero. 53a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * @param icicle the save instance data of this Activity, may be null 54a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana */ 55a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana protected void onCreate(Bundle icicle) { 56a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana super.onCreate(icicle); 57a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana 5831957f1badbb900bbfe211317e1ea992d650a72dFred Quintana mAccountAuthenticatorResponse = 5931957f1badbb900bbfe211317e1ea992d650a72dFred Quintana getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE); 60a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana 61a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana if (mAccountAuthenticatorResponse != null) { 62a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana mAccountAuthenticatorResponse.onRequestContinued(); 63a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana } 64a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana } 65a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana 66a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana /** 67a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana * Sends the result or a Constants.ERROR_CODE_CANCELED error if a result isn't present. 68a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana */ 69a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana public void finish() { 70a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana if (mAccountAuthenticatorResponse != null) { 71a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana // send the result bundle back if set, otherwise send an error. 72a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana if (mResultBundle != null) { 73a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana mAccountAuthenticatorResponse.onResult(mResultBundle); 74a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana } else { 7531957f1badbb900bbfe211317e1ea992d650a72dFred Quintana mAccountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, 7631957f1badbb900bbfe211317e1ea992d650a72dFred Quintana "canceled"); 77a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana } 78a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana mAccountAuthenticatorResponse = null; 79a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana } 80a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana super.finish(); 81a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana } 82a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana} 83