diff options
Diffstat (limited to 'src/com/android/email/activity')
11 files changed, 25 insertions, 1145 deletions
diff --git a/src/com/android/email/activity/setup/AccountCreationFragment.java b/src/com/android/email/activity/setup/AccountCreationFragment.java index e5736774c..1f0d685d7 100644 --- a/src/com/android/email/activity/setup/AccountCreationFragment.java +++ b/src/com/android/email/activity/setup/AccountCreationFragment.java @@ -28,6 +28,7 @@ import android.os.Bundle; import android.os.Handler; import android.os.RemoteException; +import com.android.email.provider.EmailProvider; import com.android.email.service.EmailServiceUtils; import com.android.email2.ui.MailActivityEmail; import com.android.emailcommon.provider.Account; @@ -298,7 +299,7 @@ public class AccountCreationFragment extends Fragment { account.mFlags &= ~Account.FLAGS_SECURITY_HOLD; AccountSettingsUtils.commitSettings(mAppContext, account); // Start up services based on new account(s) - MailActivityEmail.setServicesEnabledSync(mAppContext); + EmailProvider.setServicesEnabledSync(mAppContext); EmailServiceUtils .startService(mAppContext, account.mHostAuthRecv.mProtocol); return account; diff --git a/src/com/android/email/activity/setup/AccountSecurity.java b/src/com/android/email/activity/setup/AccountSecurity.java deleted file mode 100644 index c2be45928..000000000 --- a/src/com/android/email/activity/setup/AccountSecurity.java +++ /dev/null @@ -1,628 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.email.activity.setup; - -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.app.DialogFragment; -import android.app.FragmentManager; -import android.app.LoaderManager; -import android.app.admin.DevicePolicyManager; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.Loader; -import android.content.res.Resources; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Bundle; -import android.os.Handler; -import android.text.TextUtils; - -import com.android.email.DebugUtils; -import com.android.email.R; -import com.android.email.SecurityPolicy; -import com.android.emailcommon.provider.Account; -import com.android.emailcommon.provider.EmailContent; -import com.android.emailcommon.provider.HostAuth; -import com.android.emailcommon.provider.Policy; -import com.android.emailcommon.utility.IntentUtilities; -import com.android.mail.ui.MailAsyncTaskLoader; -import com.android.mail.utils.LogUtils; - -/** - * Psuedo-activity (no UI) to bootstrap the user up to a higher desired security level. This - * bootstrap requires the following steps. - * - * 1. Confirm the account of interest has any security policies defined - exit early if not - * 2. If not actively administrating the device, ask Device Policy Manager to start that - * 3. When we are actively administrating, check current policies and see if they're sufficient - * 4. If not, set policies - * 5. If necessary, request for user to update device password - * 6. If necessary, request for user to activate device encryption - */ -public class AccountSecurity extends Activity { - private static final String TAG = "Email/AccountSecurity"; - - private static final boolean DEBUG = false; // Don't ship with this set to true - - private static final String EXTRA_ACCOUNT_ID = "ACCOUNT_ID"; - private static final String EXTRA_SHOW_DIALOG = "SHOW_DIALOG"; - private static final String EXTRA_PASSWORD_EXPIRING = "EXPIRING"; - private static final String EXTRA_PASSWORD_EXPIRED = "EXPIRED"; - - private static final String SAVESTATE_INITIALIZED_TAG = "initialized"; - private static final String SAVESTATE_TRIED_ADD_ADMINISTRATOR_TAG = "triedAddAdministrator"; - private static final String SAVESTATE_TRIED_SET_PASSWORD_TAG = "triedSetpassword"; - private static final String SAVESTATE_TRIED_SET_ENCRYPTION_TAG = "triedSetEncryption"; - private static final String SAVESTATE_ACCOUNT_TAG = "account"; - - private static final int REQUEST_ENABLE = 1; - private static final int REQUEST_PASSWORD = 2; - private static final int REQUEST_ENCRYPTION = 3; - - private boolean mTriedAddAdministrator; - private boolean mTriedSetPassword; - private boolean mTriedSetEncryption; - - private Account mAccount; - - protected boolean mInitialized; - - private Handler mHandler; - private boolean mActivityResumed; - - private static final int ACCOUNT_POLICY_LOADER_ID = 0; - private AccountAndPolicyLoaderCallbacks mAPLoaderCallbacks; - private Bundle mAPLoaderArgs; - - public static Uri getUpdateSecurityUri(final long accountId, final boolean showDialog) { - final Uri.Builder baseUri = Uri.parse("auth://" + EmailContent.EMAIL_PACKAGE_NAME + - ".ACCOUNT_SECURITY/").buildUpon(); - IntentUtilities.setAccountId(baseUri, accountId); - baseUri.appendQueryParameter(EXTRA_SHOW_DIALOG, Boolean.toString(showDialog)); - return baseUri.build(); - } - - /** - * Used for generating intent for this activity (which is intended to be launched - * from a notification.) - * - * @param context Calling context for building the intent - * @param accountId The account of interest - * @param showDialog If true, a simple warning dialog will be shown before kicking off - * the necessary system settings. Should be true anywhere the context of the security settings - * is not clear (e.g. any time after the account has been set up). - * @return an Intent which can be used to view that account - */ - public static Intent actionUpdateSecurityIntent(Context context, long accountId, - boolean showDialog) { - Intent intent = new Intent(context, AccountSecurity.class); - intent.putExtra(EXTRA_ACCOUNT_ID, accountId); - intent.putExtra(EXTRA_SHOW_DIALOG, showDialog); - return intent; - } - - /** - * Used for generating intent for this activity (which is intended to be launched - * from a notification.) This is a special mode of this activity which exists only - * to give the user a dialog (for context) about a device pin/password expiration event. - */ - public static Intent actionDevicePasswordExpirationIntent(Context context, long accountId, - boolean expired) { - Intent intent = new ForwardingIntent(context, AccountSecurity.class); - intent.putExtra(EXTRA_ACCOUNT_ID, accountId); - intent.putExtra(expired ? EXTRA_PASSWORD_EXPIRED : EXTRA_PASSWORD_EXPIRING, true); - return intent; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - mHandler = new Handler(); - - final Intent i = getIntent(); - final long accountId; - Bundle extras = i.getExtras(); - if (extras == null) { - // We have been invoked via a uri. We need to get our parameters from the URI instead - // of looking in the intent extras. - extras = new Bundle(); - accountId = IntentUtilities.getAccountIdFromIntent(i); - extras.putLong(EXTRA_ACCOUNT_ID, accountId); - boolean showDialog = false; - final String value = i.getData().getQueryParameter(EXTRA_SHOW_DIALOG); - if (!TextUtils.isEmpty(value)) { - showDialog = Boolean.getBoolean(value); - } - extras.putBoolean(EXTRA_SHOW_DIALOG, showDialog); - } else { - accountId = i.getLongExtra(EXTRA_ACCOUNT_ID, -1); - extras = i.getExtras(); - } - - final SecurityPolicy security = SecurityPolicy.getInstance(this); - security.clearNotification(); - if (accountId == -1) { - finish(); - return; - } - - if (savedInstanceState != null) { - mInitialized = savedInstanceState.getBoolean(SAVESTATE_INITIALIZED_TAG, false); - - mTriedAddAdministrator = - savedInstanceState.getBoolean(SAVESTATE_TRIED_ADD_ADMINISTRATOR_TAG, false); - mTriedSetPassword = - savedInstanceState.getBoolean(SAVESTATE_TRIED_SET_PASSWORD_TAG, false); - mTriedSetEncryption = - savedInstanceState.getBoolean(SAVESTATE_TRIED_SET_ENCRYPTION_TAG, false); - - mAccount = savedInstanceState.getParcelable(SAVESTATE_ACCOUNT_TAG); - } - - if (!mInitialized) { - startAccountAndPolicyLoader(extras); - } - } - - @Override - protected void onSaveInstanceState(final Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(SAVESTATE_INITIALIZED_TAG, mInitialized); - - outState.putBoolean(SAVESTATE_TRIED_ADD_ADMINISTRATOR_TAG, mTriedAddAdministrator); - outState.putBoolean(SAVESTATE_TRIED_SET_PASSWORD_TAG, mTriedSetPassword); - outState.putBoolean(SAVESTATE_TRIED_SET_ENCRYPTION_TAG, mTriedSetEncryption); - - outState.putParcelable(SAVESTATE_ACCOUNT_TAG, mAccount); - } - - @Override - protected void onPause() { - super.onPause(); - mActivityResumed = false; - } - - @Override - protected void onResume() { - super.onResume(); - mActivityResumed = true; - tickleAccountAndPolicyLoader(); - } - - protected boolean isActivityResumed() { - return mActivityResumed; - } - - private void tickleAccountAndPolicyLoader() { - // If we're already initialized we don't need to tickle. - if (!mInitialized) { - getLoaderManager().initLoader(ACCOUNT_POLICY_LOADER_ID, mAPLoaderArgs, - mAPLoaderCallbacks); - } - } - - private void startAccountAndPolicyLoader(final Bundle args) { - mAPLoaderArgs = args; - mAPLoaderCallbacks = new AccountAndPolicyLoaderCallbacks(); - tickleAccountAndPolicyLoader(); - } - - private class AccountAndPolicyLoaderCallbacks - implements LoaderManager.LoaderCallbacks<Account> { - @Override - public Loader<Account> onCreateLoader(final int id, final Bundle args) { - final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1); - final boolean showDialog = args.getBoolean(EXTRA_SHOW_DIALOG, false); - final boolean passwordExpiring = - args.getBoolean(EXTRA_PASSWORD_EXPIRING, false); - final boolean passwordExpired = - args.getBoolean(EXTRA_PASSWORD_EXPIRED, false); - - return new AccountAndPolicyLoader(getApplicationContext(), accountId, - showDialog, passwordExpiring, passwordExpired); - } - - @Override - public void onLoadFinished(final Loader<Account> loader, final Account account) { - mHandler.post(new Runnable() { - @Override - public void run() { - final AccountSecurity activity = AccountSecurity.this; - if (!activity.isActivityResumed()) { - return; - } - - if (account == null || (account.mPolicyKey != 0 && account.mPolicy == null)) { - activity.finish(); - LogUtils.d(TAG, "could not load account or policy in AccountSecurity"); - return; - } - - if (!activity.mInitialized) { - activity.mInitialized = true; - - final AccountAndPolicyLoader apLoader = (AccountAndPolicyLoader) loader; - activity.completeCreate(account, apLoader.mShowDialog, - apLoader.mPasswordExpiring, apLoader.mPasswordExpired); - } - } - }); - } - - @Override - public void onLoaderReset(Loader<Account> loader) {} - } - - private static class AccountAndPolicyLoader extends MailAsyncTaskLoader<Account> { - private final long mAccountId; - public final boolean mShowDialog; - public final boolean mPasswordExpiring; - public final boolean mPasswordExpired; - - private final Context mContext; - - AccountAndPolicyLoader(final Context context, final long accountId, - final boolean showDialog, final boolean passwordExpiring, - final boolean passwordExpired) { - super(context); - mContext = context; - mAccountId = accountId; - mShowDialog = showDialog; - mPasswordExpiring = passwordExpiring; - mPasswordExpired = passwordExpired; - } - - @Override - public Account loadInBackground() { - final Account account = Account.restoreAccountWithId(mContext, mAccountId); - if (account == null) { - return null; - } - - final long policyId = account.mPolicyKey; - if (policyId != 0) { - account.mPolicy = Policy.restorePolicyWithId(mContext, policyId); - } - - account.getOrCreateHostAuthRecv(mContext); - - return account; - } - - @Override - protected void onDiscardResult(Account result) {} - } - - protected void completeCreate(final Account account, final boolean showDialog, - final boolean passwordExpiring, final boolean passwordExpired) { - mAccount = account; - - // Special handling for password expiration events - if (passwordExpiring || passwordExpired) { - FragmentManager fm = getFragmentManager(); - if (fm.findFragmentByTag("password_expiration") == null) { - PasswordExpirationDialog dialog = - PasswordExpirationDialog.newInstance(mAccount.getDisplayName(), - passwordExpired); - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Showing password expiration dialog"); - } - dialog.show(fm, "password_expiration"); - } - return; - } - // Otherwise, handle normal security settings flow - if (mAccount.mPolicyKey != 0) { - // This account wants to control security - if (showDialog) { - // Show dialog first, unless already showing (e.g. after rotation) - FragmentManager fm = getFragmentManager(); - if (fm.findFragmentByTag("security_needed") == null) { - SecurityNeededDialog dialog = - SecurityNeededDialog.newInstance(mAccount.getDisplayName()); - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Showing security needed dialog"); - } - dialog.show(fm, "security_needed"); - } - } else { - // Go directly to security settings - tryAdvanceSecurity(mAccount); - } - return; - } - finish(); - } - - /** - * After any of the activities return, try to advance to the "next step" - */ - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - tryAdvanceSecurity(mAccount); - super.onActivityResult(requestCode, resultCode, data); - } - - /** - * Walk the user through the required steps to become an active administrator and with - * the requisite security settings for the given account. - * - * These steps will be repeated each time we return from a given attempt (e.g. asking the - * user to choose a device pin/password). In a typical activation, we may repeat these - * steps a few times. It may go as far as step 5 (password) or step 6 (encryption), but it - * will terminate when step 2 (isActive()) succeeds. - * - * If at any point we do not advance beyond a given user step, (e.g. the user cancels - * instead of setting a password) we simply repost the security notification, and exit. - * We never want to loop here. - */ - private void tryAdvanceSecurity(Account account) { - SecurityPolicy security = SecurityPolicy.getInstance(this); - // Step 1. Check if we are an active device administrator, and stop here to activate - if (!security.isActiveAdmin()) { - if (mTriedAddAdministrator) { - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Not active admin: repost notification"); - } - repostNotification(account, security); - finish(); - } else { - mTriedAddAdministrator = true; - // retrieve name of server for the format string - final HostAuth hostAuth = account.mHostAuthRecv; - if (hostAuth == null) { - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "No HostAuth: repost notification"); - } - repostNotification(account, security); - finish(); - } else { - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Not active admin: post initial notification"); - } - // try to become active - must happen here in activity, to get result - Intent intent = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN); - intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, - security.getAdminComponent()); - intent.putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION, - this.getString(R.string.account_security_policy_explanation_fmt, - hostAuth.mAddress)); - startActivityForResult(intent, REQUEST_ENABLE); - } - } - return; - } - - // Step 2. Check if the current aggregate security policy is being satisfied by the - // DevicePolicyManager (the current system security level). - if (security.isActive(null)) { - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Security active; clear holds"); - } - Account.clearSecurityHoldOnAllAccounts(this); - security.syncAccount(account); - security.clearNotification(); - finish(); - return; - } - - // Step 3. Try to assert the current aggregate security requirements with the system. - security.setActivePolicies(); - - // Step 4. Recheck the security policy, and determine what changes are needed (if any) - // to satisfy the requirements. - int inactiveReasons = security.getInactiveReasons(null); - - // Step 5. If password is needed, try to have the user set it - if ((inactiveReasons & SecurityPolicy.INACTIVE_NEED_PASSWORD) != 0) { - if (mTriedSetPassword) { - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Password needed; repost notification"); - } - repostNotification(account, security); - finish(); - } else { - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Password needed; request it via DPM"); - } - mTriedSetPassword = true; - // launch the activity to have the user set a new password. - Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD); - startActivityForResult(intent, REQUEST_PASSWORD); - } - return; - } - - // Step 6. If encryption is needed, try to have the user set it - if ((inactiveReasons & SecurityPolicy.INACTIVE_NEED_ENCRYPTION) != 0) { - if (mTriedSetEncryption) { - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Encryption needed; repost notification"); - } - repostNotification(account, security); - finish(); - } else { - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Encryption needed; request it via DPM"); - } - mTriedSetEncryption = true; - // launch the activity to start up encryption. - Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION); - startActivityForResult(intent, REQUEST_ENCRYPTION); - } - return; - } - - // Step 7. No problems were found, so clear holds and exit - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Policies enforced; clear holds"); - } - Account.clearSecurityHoldOnAllAccounts(this); - security.syncAccount(account); - security.clearNotification(); - finish(); - } - - /** - * Mark an account as not-ready-for-sync and post a notification to bring the user back here - * eventually. - */ - private static void repostNotification(final Account account, final SecurityPolicy security) { - if (account == null) return; - new AsyncTask<Void, Void, Void>() { - @Override - protected Void doInBackground(Void... params) { - security.policiesRequired(account.mId); - return null; - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - /** - * Dialog briefly shown in some cases, to indicate the user that a security update is needed. - * If the user clicks OK, we proceed into the "tryAdvanceSecurity" flow. If the user cancels, - * we repost the notification and finish() the activity. - */ - public static class SecurityNeededDialog extends DialogFragment - implements DialogInterface.OnClickListener { - private static final String BUNDLE_KEY_ACCOUNT_NAME = "account_name"; - - // Public no-args constructor needed for fragment re-instantiation - public SecurityNeededDialog() {} - - /** - * Create a new dialog. - */ - public static SecurityNeededDialog newInstance(String accountName) { - final SecurityNeededDialog dialog = new SecurityNeededDialog(); - Bundle b = new Bundle(); - b.putString(BUNDLE_KEY_ACCOUNT_NAME, accountName); - dialog.setArguments(b); - return dialog; - } - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - final String accountName = getArguments().getString(BUNDLE_KEY_ACCOUNT_NAME); - - final Context context = getActivity(); - final Resources res = context.getResources(); - final AlertDialog.Builder b = new AlertDialog.Builder(context); - b.setTitle(R.string.account_security_dialog_title); - b.setIconAttribute(android.R.attr.alertDialogIcon); - b.setMessage(res.getString(R.string.account_security_dialog_content_fmt, accountName)); - b.setPositiveButton(android.R.string.ok, this); - b.setNegativeButton(android.R.string.cancel, this); - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "Posting security needed dialog"); - } - return b.create(); - } - - @Override - public void onClick(DialogInterface dialog, int which) { - dismiss(); - AccountSecurity activity = (AccountSecurity) getActivity(); - if (activity.mAccount == null) { - // Clicked before activity fully restored - probably just monkey - exit quickly - activity.finish(); - return; - } - switch (which) { - case DialogInterface.BUTTON_POSITIVE: - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "User accepts; advance to next step"); - } - activity.tryAdvanceSecurity(activity.mAccount); - break; - case DialogInterface.BUTTON_NEGATIVE: - if (DebugUtils.DEBUG || DEBUG) { - LogUtils.d(TAG, "User declines; repost notification"); - } - AccountSecurity.repostNotification( - activity.mAccount, SecurityPolicy.getInstance(activity)); - activity.finish(); - break; - } - } - } - - /** - * Dialog briefly shown in some cases, to indicate the user that the PIN/Password is expiring - * or has expired. If the user clicks OK, we launch the password settings screen. - */ - public static class PasswordExpirationDialog extends DialogFragment - implements DialogInterface.OnClickListener { - private static final String BUNDLE_KEY_ACCOUNT_NAME = "account_name"; - private static final String BUNDLE_KEY_EXPIRED = "expired"; - - /** - * Create a new dialog. - */ - public static PasswordExpirationDialog newInstance(String accountName, boolean expired) { - final PasswordExpirationDialog dialog = new PasswordExpirationDialog(); - Bundle b = new Bundle(); - b.putString(BUNDLE_KEY_ACCOUNT_NAME, accountName); - b.putBoolean(BUNDLE_KEY_EXPIRED, expired); - dialog.setArguments(b); - return dialog; - } - - // Public no-args constructor needed for fragment re-instantiation - public PasswordExpirationDialog() {} - - /** - * Note, this actually creates two slightly different dialogs (for expiring vs. expired) - */ - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - final String accountName = getArguments().getString(BUNDLE_KEY_ACCOUNT_NAME); - final boolean expired = getArguments().getBoolean(BUNDLE_KEY_EXPIRED); - final int titleId = expired - ? R.string.password_expired_dialog_title - : R.string.password_expire_warning_dialog_title; - final int contentId = expired - ? R.string.password_expired_dialog_content_fmt - : R.string.password_expire_warning_dialog_content_fmt; - - final Context context = getActivity(); - final Resources res = context.getResources(); - return new AlertDialog.Builder(context) - .setTitle(titleId) - .setIconAttribute(android.R.attr.alertDialogIcon) - .setMessage(res.getString(contentId, accountName)) - .setPositiveButton(android.R.string.ok, this) - .setNegativeButton(android.R.string.cancel, this) - .create(); - } - - @Override - public void onClick(DialogInterface dialog, int which) { - dismiss(); - AccountSecurity activity = (AccountSecurity) getActivity(); - if (which == DialogInterface.BUTTON_POSITIVE) { - Intent intent = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD); - activity.startActivity(intent); - } - activity.finish(); - } - } -} diff --git a/src/com/android/email/activity/setup/AccountServerSettingsActivity.java b/src/com/android/email/activity/setup/AccountServerSettingsActivity.java index b0782570e..f119219bb 100644 --- a/src/com/android/email/activity/setup/AccountServerSettingsActivity.java +++ b/src/com/android/email/activity/setup/AccountServerSettingsActivity.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.os.Bundle; import com.android.email.R; +import com.android.email.setup.AuthenticatorSetupIntentHelper; import com.android.emailcommon.provider.Account; import com.android.mail.utils.LogUtils; @@ -65,7 +66,7 @@ public class AccountServerSettingsActivity extends AccountSetupActivity implemen public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mSetupData.setFlowMode(SetupDataFragment.FLOW_MODE_EDIT); + mSetupData.setFlowMode(AuthenticatorSetupIntentHelper.FLOW_MODE_EDIT); setContentView(R.layout.account_server_settings); setFinishOnTouchOutside(false); diff --git a/src/com/android/email/activity/setup/AccountSettingsFragment.java b/src/com/android/email/activity/setup/AccountSettingsFragment.java index f6ea75614..91e14d608 100644 --- a/src/com/android/email/activity/setup/AccountSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountSettingsFragment.java @@ -52,7 +52,6 @@ import com.android.email.provider.EmailProvider; import com.android.email.provider.FolderPickerActivity; import com.android.email.service.EmailServiceUtils; import com.android.email.service.EmailServiceUtils.EmailServiceInfo; -import com.android.email2.ui.MailActivityEmail; import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.EmailContent; import com.android.emailcommon.provider.EmailContent.AccountColumns; @@ -402,7 +401,7 @@ public class AccountSettingsFragment extends MailAccountPrefsFragment } if (cv.size() > 0) { new UpdateTask().run(mContext.getContentResolver(), mAccount.getUri(), cv, null, null); - MailActivityEmail.setServicesEnabledAsync(mContext); + EmailProvider.setServicesEnabledAsync(mContext); } return false; } diff --git a/src/com/android/email/activity/setup/AccountSettingsUtils.java b/src/com/android/email/activity/setup/AccountSettingsUtils.java deleted file mode 100644 index dbbd51ee7..000000000 --- a/src/com/android/email/activity/setup/AccountSettingsUtils.java +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.email.activity.setup; - -import android.content.ContentResolver; -import android.content.ContentValues; -import android.content.Context; -import android.content.res.XmlResourceParser; -import android.net.Uri; -import android.text.TextUtils; - -import com.android.email.R; -import com.android.email.provider.AccountBackupRestore; -import com.android.emailcommon.Logging; -import com.android.emailcommon.VendorPolicyLoader; -import com.android.emailcommon.VendorPolicyLoader.OAuthProvider; -import com.android.emailcommon.VendorPolicyLoader.Provider; -import com.android.emailcommon.provider.Account; -import com.android.emailcommon.provider.EmailContent.AccountColumns; -import com.android.emailcommon.provider.QuickResponse; -import com.android.emailcommon.service.PolicyServiceProxy; -import com.android.emailcommon.utility.Utility; -import com.android.mail.utils.LogUtils; -import com.google.common.annotations.VisibleForTesting; - -import java.util.ArrayList; -import java.util.List; - -public class AccountSettingsUtils { - - /** Pattern to match any part of a domain */ - private final static String WILD_STRING = "*"; - /** Will match any, single character */ - private final static char WILD_CHARACTER = '?'; - private final static String DOMAIN_SEPARATOR = "\\."; - - /** - * Commits the UI-related settings of an account to the provider. This is static so that it - * can be used by the various account activities. If the account has never been saved, this - * method saves it; otherwise, it just saves the settings. - * @param context the context of the caller - * @param account the account whose settings will be committed - */ - public static void commitSettings(Context context, Account account) { - if (!account.isSaved()) { - account.save(context); - - if (account.mPolicy != null) { - // TODO: we need better handling for unsupported policies - // For now, just clear the unsupported policies, as the server will (hopefully) - // just reject our sync attempts if it's not happy with half-measures - if (account.mPolicy.mProtocolPoliciesUnsupported != null) { - LogUtils.d(LogUtils.TAG, "Clearing unsupported policies " - + account.mPolicy.mProtocolPoliciesUnsupported); - account.mPolicy.mProtocolPoliciesUnsupported = null; - } - PolicyServiceProxy.setAccountPolicy2(context, - account.getId(), - account.mPolicy, - account.mSecuritySyncKey == null ? "" : account.mSecuritySyncKey, - false /* notify */); - } - - // Set up default quick responses here... - String[] defaultQuickResponses = - context.getResources().getStringArray(R.array.default_quick_responses); - ContentValues cv = new ContentValues(); - cv.put(QuickResponse.ACCOUNT_KEY, account.mId); - ContentResolver resolver = context.getContentResolver(); - for (String quickResponse: defaultQuickResponses) { - // Allow empty entries (some localizations may not want to have the maximum - // number) - if (!TextUtils.isEmpty(quickResponse)) { - cv.put(QuickResponse.TEXT, quickResponse); - resolver.insert(QuickResponse.CONTENT_URI, cv); - } - } - } else { - ContentValues cv = getAccountContentValues(account); - account.update(context, cv); - } - - // Update the backup (side copy) of the accounts - AccountBackupRestore.backup(context); - } - - /** - * Returns a set of content values to commit account changes (not including the foreign keys - * for the two host auth's and policy) to the database. Does not actually commit anything. - */ - public static ContentValues getAccountContentValues(Account account) { - ContentValues cv = new ContentValues(); - cv.put(AccountColumns.DISPLAY_NAME, account.getDisplayName()); - cv.put(AccountColumns.SENDER_NAME, account.getSenderName()); - cv.put(AccountColumns.SIGNATURE, account.getSignature()); - cv.put(AccountColumns.SYNC_INTERVAL, account.mSyncInterval); - cv.put(AccountColumns.FLAGS, account.mFlags); - cv.put(AccountColumns.SYNC_LOOKBACK, account.mSyncLookback); - cv.put(AccountColumns.SECURITY_SYNC_KEY, account.mSecuritySyncKey); - return cv; - } - - /** - * Create the request to get the authorization code. - * - * @param context - * @param provider The OAuth provider to register with - * @param emailAddress Email address to send as a hint to the oauth service. - * @return - */ - public static Uri createOAuthRegistrationRequest(final Context context, - final OAuthProvider provider, final String emailAddress) { - final Uri.Builder b = Uri.parse(provider.authEndpoint).buildUpon(); - b.appendQueryParameter("response_type", provider.responseType); - b.appendQueryParameter("client_id", provider.clientId); - b.appendQueryParameter("redirect_uri", provider.redirectUri); - b.appendQueryParameter("scope", provider.scope); - b.appendQueryParameter("state", provider.state); - b.appendQueryParameter("login_hint", emailAddress); - return b.build(); - } - - /** - * Search for a single resource containing known oauth provider definitions. - * - * @param context - * @param id String Id of the oauth provider. - * @return The OAuthProvider if found, null if not. - */ - public static OAuthProvider findOAuthProvider(final Context context, final String id) { - return findOAuthProvider(context, id, R.xml.oauth); - } - - public static List<OAuthProvider> getAllOAuthProviders(final Context context) { - try { - List<OAuthProvider> providers = new ArrayList<OAuthProvider>(); - final XmlResourceParser xml = context.getResources().getXml(R.xml.oauth); - int xmlEventType; - OAuthProvider provider = null; - while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) { - if (xmlEventType == XmlResourceParser.START_TAG - && "provider".equals(xml.getName())) { - try { - provider = new OAuthProvider(); - provider.id = getXmlAttribute(context, xml, "id"); - provider.label = getXmlAttribute(context, xml, "label"); - provider.authEndpoint = getXmlAttribute(context, xml, "auth_endpoint"); - provider.tokenEndpoint = getXmlAttribute(context, xml, "token_endpoint"); - provider.refreshEndpoint = getXmlAttribute(context, xml, - "refresh_endpoint"); - provider.responseType = getXmlAttribute(context, xml, "response_type"); - provider.redirectUri = getXmlAttribute(context, xml, "redirect_uri"); - provider.scope = getXmlAttribute(context, xml, "scope"); - provider.state = getXmlAttribute(context, xml, "state"); - provider.clientId = getXmlAttribute(context, xml, "client_id"); - provider.clientSecret = getXmlAttribute(context, xml, "client_secret"); - providers.add(provider); - } catch (IllegalArgumentException e) { - LogUtils.w(Logging.LOG_TAG, "providers line: " + xml.getLineNumber() + - "; Domain contains multiple globals"); - } - } - } - return providers; - } catch (Exception e) { - LogUtils.e(Logging.LOG_TAG, "Error while trying to load provider settings.", e); - } - return null; - } - - /** - * Search for a single resource containing known oauth provider definitions. - * - * @param context - * @param id String Id of the oauth provider. - * @param resourceId ResourceId of the xml file to search. - * @return The OAuthProvider if found, null if not. - */ - public static OAuthProvider findOAuthProvider(final Context context, final String id, - final int resourceId) { - // TODO: Consider adding a way to cache this file during new account setup, so that we - // don't need to keep loading the file over and over. - // TODO: need a mechanism to get a list of all supported OAuth providers so that we can - // offer the user a choice of who to authenticate with. - try { - final XmlResourceParser xml = context.getResources().getXml(resourceId); - int xmlEventType; - OAuthProvider provider = null; - while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) { - if (xmlEventType == XmlResourceParser.START_TAG - && "provider".equals(xml.getName())) { - String providerId = getXmlAttribute(context, xml, "id"); - try { - if (TextUtils.equals(id, providerId)) { - provider = new OAuthProvider(); - provider.id = id; - provider.label = getXmlAttribute(context, xml, "label"); - provider.authEndpoint = getXmlAttribute(context, xml, "auth_endpoint"); - provider.tokenEndpoint = getXmlAttribute(context, xml, "token_endpoint"); - provider.refreshEndpoint = getXmlAttribute(context, xml, - "refresh_endpoint"); - provider.responseType = getXmlAttribute(context, xml, "response_type"); - provider.redirectUri = getXmlAttribute(context, xml, "redirect_uri"); - provider.scope = getXmlAttribute(context, xml, "scope"); - provider.state = getXmlAttribute(context, xml, "state"); - provider.clientId = getXmlAttribute(context, xml, "client_id"); - provider.clientSecret = getXmlAttribute(context, xml, "client_secret"); - return provider; - } - } catch (IllegalArgumentException e) { - LogUtils.w(Logging.LOG_TAG, "providers line: " + xml.getLineNumber() + - "; Domain contains multiple globals"); - } - } - } - } catch (Exception e) { - LogUtils.e(Logging.LOG_TAG, "Error while trying to load provider settings.", e); - } - return null; - } - - /** - * Search the list of known Email providers looking for one that matches the user's email - * domain. We check for vendor supplied values first, then we look in providers_product.xml, - * and finally by the entries in platform providers.xml. This provides a nominal override - * capability. - * - * A match is defined as any provider entry for which the "domain" attribute matches. - * - * @param domain The domain portion of the user's email address - * @return suitable Provider definition, or null if no match found - */ - public static Provider findProviderForDomain(Context context, String domain) { - Provider p = VendorPolicyLoader.getInstance(context).findProviderForDomain(domain); - if (p == null) { - p = findProviderForDomain(context, domain, R.xml.providers_product); - } - if (p == null) { - p = findProviderForDomain(context, domain, R.xml.providers); - } - return p; - } - - /** - * Search a single resource containing known Email provider definitions. - * - * @param domain The domain portion of the user's email address - * @param resourceId Id of the provider resource to scan - * @return suitable Provider definition, or null if no match found - */ - /*package*/ static Provider findProviderForDomain( - Context context, String domain, int resourceId) { - try { - XmlResourceParser xml = context.getResources().getXml(resourceId); - int xmlEventType; - Provider provider = null; - while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) { - if (xmlEventType == XmlResourceParser.START_TAG - && "provider".equals(xml.getName())) { - String providerDomain = getXmlAttribute(context, xml, "domain"); - try { - if (matchProvider(domain, providerDomain)) { - provider = new Provider(); - provider.id = getXmlAttribute(context, xml, "id"); - provider.label = getXmlAttribute(context, xml, "label"); - provider.domain = domain.toLowerCase(); - provider.note = getXmlAttribute(context, xml, "note"); - // TODO: Maybe this should actually do a lookup of the OAuth provider - // here, and keep a pointer to it rather than a textual key. - // To do this probably requires caching oauth.xml, otherwise the lookup - // is expensive and likely to happen repeatedly. - provider.oauth = getXmlAttribute(context, xml, "oauth"); - } - } catch (IllegalArgumentException e) { - LogUtils.w(Logging.LOG_TAG, "providers line: " + xml.getLineNumber() + - "; Domain contains multiple globals"); - } - } - else if (xmlEventType == XmlResourceParser.START_TAG - && "incoming".equals(xml.getName()) - && provider != null) { - provider.incomingUriTemplate = getXmlAttribute(context, xml, "uri"); - provider.incomingUsernameTemplate = getXmlAttribute(context, xml, "username"); - } - else if (xmlEventType == XmlResourceParser.START_TAG - && "outgoing".equals(xml.getName()) - && provider != null) { - provider.outgoingUriTemplate = getXmlAttribute(context, xml, "uri"); - provider.outgoingUsernameTemplate = getXmlAttribute(context, xml, "username"); - } - else if (xmlEventType == XmlResourceParser.START_TAG - && "incoming-fallback".equals(xml.getName()) - && provider != null) { - provider.altIncomingUriTemplate = getXmlAttribute(context, xml, "uri"); - provider.altIncomingUsernameTemplate = - getXmlAttribute(context, xml, "username"); - } - else if (xmlEventType == XmlResourceParser.START_TAG - && "outgoing-fallback".equals(xml.getName()) - && provider != null) { - provider.altOutgoingUriTemplate = getXmlAttribute(context, xml, "uri"); - provider.altOutgoingUsernameTemplate = - getXmlAttribute(context, xml, "username"); - } - else if (xmlEventType == XmlResourceParser.END_TAG - && "provider".equals(xml.getName()) - && provider != null) { - return provider; - } - } - } - catch (Exception e) { - LogUtils.e(Logging.LOG_TAG, "Error while trying to load provider settings.", e); - } - return null; - } - - /** - * Returns true if the string <code>s1</code> matches the string <code>s2</code>. The string - * <code>s2</code> may contain any number of wildcards -- a '?' character -- and/or asterisk - * characters -- '*'. Wildcards match any single character, while the asterisk matches a domain - * part (i.e. substring demarcated by a period, '.') - */ - @VisibleForTesting - public static boolean matchProvider(String testDomain, String providerDomain) { - String[] testParts = testDomain.split(DOMAIN_SEPARATOR); - String[] providerParts = providerDomain.split(DOMAIN_SEPARATOR); - if (testParts.length != providerParts.length) { - return false; - } - for (int i = 0; i < testParts.length; i++) { - String testPart = testParts[i].toLowerCase(); - String providerPart = providerParts[i].toLowerCase(); - if (!providerPart.equals(WILD_STRING) && - !matchWithWildcards(testPart, providerPart)) { - return false; - } - } - return true; - } - - private static boolean matchWithWildcards(String testPart, String providerPart) { - int providerLength = providerPart.length(); - if (testPart.length() != providerLength){ - return false; - } - for (int i = 0; i < providerLength; i++) { - char testChar = testPart.charAt(i); - char providerChar = providerPart.charAt(i); - if (testChar != providerChar && providerChar != WILD_CHARACTER) { - return false; - } - } - return true; - } - - /** - * Attempts to get the given attribute as a String resource first, and if it fails - * returns the attribute as a simple String value. - * @param xml - * @param name - * @return the requested resource - */ - private static String getXmlAttribute(Context context, XmlResourceParser xml, String name) { - int resId = xml.getAttributeResourceValue(null, name, 0); - if (resId == 0) { - return xml.getAttributeValue(null, name); - } - else { - return context.getString(resId); - } - } - - /** - * Infer potential email server addresses from domain names - * - * Incoming: Prepend "imap" or "pop3" to domain, unless "pop", "pop3", - * "imap", or "mail" are found. - * Outgoing: Prepend "smtp" if domain starts with any in the host prefix array - * - * @param server name as we know it so far - * @param incoming "pop3" or "imap" (or null) - * @param outgoing "smtp" or null - * @return the post-processed name for use in the UI - */ - public static String inferServerName(Context context, String server, String incoming, - String outgoing) { - // Default values cause entire string to be kept, with prepended server string - int keepFirstChar = 0; - int firstDotIndex = server.indexOf('.'); - if (firstDotIndex != -1) { - // look at first word and decide what to do - String firstWord = server.substring(0, firstDotIndex).toLowerCase(); - String[] hostPrefixes = - context.getResources().getStringArray(R.array.smtp_host_prefixes); - boolean canSubstituteSmtp = Utility.arrayContains(hostPrefixes, firstWord); - boolean isMail = "mail".equals(firstWord); - // Now decide what to do - if (incoming != null) { - // For incoming, we leave imap/pop/pop3/mail alone, or prepend incoming - if (canSubstituteSmtp || isMail) { - return server; - } - } else { - // For outgoing, replace imap/pop/pop3 with outgoing, leave mail alone, or - // prepend outgoing - if (canSubstituteSmtp) { - keepFirstChar = firstDotIndex + 1; - } else if (isMail) { - return server; - } else { - // prepend - } - } - } - return ((incoming != null) ? incoming : outgoing) + '.' + server.substring(keepFirstChar); - } - -} diff --git a/src/com/android/email/activity/setup/AccountSetupFinal.java b/src/com/android/email/activity/setup/AccountSetupFinal.java index 85ee24e99..ed33a5f5d 100644 --- a/src/com/android/email/activity/setup/AccountSetupFinal.java +++ b/src/com/android/email/activity/setup/AccountSetupFinal.java @@ -43,6 +43,7 @@ import android.view.inputmethod.InputMethodManager; import android.widget.Toast; import com.android.email.R; +import com.android.email.setup.AuthenticatorSetupIntentHelper; import com.android.email.service.EmailServiceUtils; import com.android.emailcommon.VendorPolicyLoader; import com.android.emailcommon.provider.Account; @@ -97,8 +98,6 @@ public class AccountSetupFinal extends AccountSetupActivity * and the appropriate incoming/outgoing information will be filled in automatically. */ private static String INTENT_FORCE_CREATE_ACCOUNT; - private static final String EXTRA_FLOW_MODE = "FLOW_MODE"; - private static final String EXTRA_FLOW_ACCOUNT_TYPE = "FLOW_ACCOUNT_TYPE"; private static final String EXTRA_CREATE_ACCOUNT_EMAIL = "EMAIL"; private static final String EXTRA_CREATE_ACCOUNT_USER = "USER"; private static final String EXTRA_CREATE_ACCOUNT_PASSWORD = "PASSWORD"; @@ -180,26 +179,6 @@ public class AccountSetupFinal extends AccountSetupActivity private static final int EXISTING_ACCOUNTS_LOADER_ID = 1; private Map<String, String> mExistingAccountsMap; - public static Intent actionNewAccountIntent(final Context context) { - final Intent i = new Intent(context, AccountSetupFinal.class); - i.putExtra(EXTRA_FLOW_MODE, SetupDataFragment.FLOW_MODE_NORMAL); - return i; - } - - public static Intent actionNewAccountWithResultIntent(final Context context) { - final Intent i = new Intent(context, AccountSetupFinal.class); - i.putExtra(EXTRA_FLOW_MODE, SetupDataFragment.FLOW_MODE_NO_ACCOUNTS); - return i; - } - - public static Intent actionGetCreateAccountIntent(final Context context, - final String accountManagerType) { - final Intent i = new Intent(context, AccountSetupFinal.class); - i.putExtra(EXTRA_FLOW_MODE, SetupDataFragment.FLOW_MODE_ACCOUNT_MANAGER); - i.putExtra(EXTRA_FLOW_ACCOUNT_TYPE, accountManagerType); - return i; - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -250,11 +229,13 @@ public class AccountSetupFinal extends AccountSetupActivity // Initialize the SetupDataFragment if (INTENT_FORCE_CREATE_ACCOUNT.equals(action)) { - mSetupData.setFlowMode(SetupDataFragment.FLOW_MODE_FORCE_CREATE); + mSetupData.setFlowMode(AuthenticatorSetupIntentHelper.FLOW_MODE_FORCE_CREATE); } else { - final int intentFlowMode = intent.getIntExtra(EXTRA_FLOW_MODE, - SetupDataFragment.FLOW_MODE_UNSPECIFIED); - final String flowAccountType = intent.getStringExtra(EXTRA_FLOW_ACCOUNT_TYPE); + final int intentFlowMode = intent.getIntExtra( + AuthenticatorSetupIntentHelper.EXTRA_FLOW_MODE, + AuthenticatorSetupIntentHelper.FLOW_MODE_UNSPECIFIED); + final String flowAccountType = intent.getStringExtra( + AuthenticatorSetupIntentHelper.EXTRA_FLOW_ACCOUNT_TYPE); mSetupData.setAmProtocol( EmailServiceUtils.getProtocolFromAccountType(this, flowAccountType)); mSetupData.setFlowMode(intentFlowMode); @@ -273,8 +254,8 @@ public class AccountSetupFinal extends AccountSetupActivity mPasswordFailed = false; } - if (!mIsProcessing - && mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_FORCE_CREATE) { + if (!mIsProcessing && mSetupData.getFlowMode() == + AuthenticatorSetupIntentHelper.FLOW_MODE_FORCE_CREATE) { /** * To support continuous testing, we allow the forced creation of accounts. * This works in a manner fairly similar to automatic setup, in which the complete @@ -679,7 +660,8 @@ public class AccountSetupFinal extends AccountSetupActivity case STATE_CREATING: mState = STATE_NAMES; updateContentFragment(true /* addToBackstack */); - if (mSetupData.getFlowMode() == SetupDataFragment.FLOW_MODE_FORCE_CREATE) { + if (mSetupData.getFlowMode() == + AuthenticatorSetupIntentHelper.FLOW_MODE_FORCE_CREATE) { getFragmentManager().executePendingTransactions(); initiateAccountFinalize(); } diff --git a/src/com/android/email/activity/setup/AccountSetupNamesFragment.java b/src/com/android/email/activity/setup/AccountSetupNamesFragment.java index 363de9bf6..f9c20dc6a 100644 --- a/src/com/android/email/activity/setup/AccountSetupNamesFragment.java +++ b/src/com/android/email/activity/setup/AccountSetupNamesFragment.java @@ -33,6 +33,7 @@ import android.widget.EditText; import com.android.email.R; import com.android.email.activity.UiUtilities; import com.android.email.service.EmailServiceUtils; +import com.android.email.setup.AuthenticatorSetupIntentHelper; import com.android.emailcommon.provider.Account; public class AccountSetupNamesFragment extends AccountSetupFragment { @@ -81,8 +82,8 @@ public class AccountSetupNamesFragment extends AccountSetupFragment { final Account account = setupData.getAccount(); - if (flowMode != SetupDataFragment.FLOW_MODE_FORCE_CREATE - && flowMode != SetupDataFragment.FLOW_MODE_EDIT) { + if (flowMode != AuthenticatorSetupIntentHelper.FLOW_MODE_FORCE_CREATE + && flowMode != AuthenticatorSetupIntentHelper.FLOW_MODE_EDIT) { final String accountEmail = account.mEmailAddress; mDescription.setText(accountEmail); @@ -99,8 +100,8 @@ public class AccountSetupNamesFragment extends AccountSetupFragment { } else { if (account.getSenderName() != null) { mName.setText(account.getSenderName()); - } else if (flowMode != SetupDataFragment.FLOW_MODE_FORCE_CREATE - && flowMode != SetupDataFragment.FLOW_MODE_EDIT) { + } else if (flowMode != AuthenticatorSetupIntentHelper.FLOW_MODE_FORCE_CREATE + && flowMode != AuthenticatorSetupIntentHelper.FLOW_MODE_EDIT) { // Attempt to prefill the name field from the profile if we don't have it, final Context loaderContext = getActivity().getApplicationContext(); getLoaderManager().initLoader(0, null, new LoaderManager.LoaderCallbacks<Cursor>() { diff --git a/src/com/android/email/activity/setup/EmailPreferenceActivity.java b/src/com/android/email/activity/setup/EmailPreferenceActivity.java index 4a5dc4ed9..cbb47b922 100644 --- a/src/com/android/email/activity/setup/EmailPreferenceActivity.java +++ b/src/com/android/email/activity/setup/EmailPreferenceActivity.java @@ -27,6 +27,7 @@ import android.view.Menu; import android.view.MenuItem; import com.android.email.R; +import com.android.email.setup.AuthenticatorSetupIntentHelper; import com.android.emailcommon.utility.IntentUtilities; import com.android.mail.providers.UIProvider.EditSettingsExtras; import com.android.mail.ui.settings.MailPreferenceActivity; @@ -201,7 +202,7 @@ public class EmailPreferenceActivity extends MailPreferenceActivity { } private void onAddNewAccount() { - final Intent setupIntent = AccountSetupFinal.actionNewAccountIntent(this); + final Intent setupIntent = AuthenticatorSetupIntentHelper.actionNewAccountIntent(this); startActivity(setupIntent); } diff --git a/src/com/android/email/activity/setup/ForwardingIntent.java b/src/com/android/email/activity/setup/ForwardingIntent.java deleted file mode 100644 index 1fc913ef7..000000000 --- a/src/com/android/email/activity/setup/ForwardingIntent.java +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2012 Google Inc. - * Licensed to The Android Open Source Project. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *******************************************************************************/ - -package com.android.email.activity.setup; - -import android.content.Context; -import android.content.Intent; - -/** - * An intent that forwards results - */ -public class ForwardingIntent extends Intent { - public ForwardingIntent(Context activity, Class klass) { - super(activity, klass); - setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); - } -} diff --git a/src/com/android/email/activity/setup/HeadlessAccountSettingsLoader.java b/src/com/android/email/activity/setup/HeadlessAccountSettingsLoader.java index 09eedd9a5..bca6d5545 100644 --- a/src/com/android/email/activity/setup/HeadlessAccountSettingsLoader.java +++ b/src/com/android/email/activity/setup/HeadlessAccountSettingsLoader.java @@ -21,13 +21,6 @@ import com.android.mail.ui.MailAsyncTaskLoader; */ public class HeadlessAccountSettingsLoader extends Activity { - public static Uri getIncomingSettingsUri(long accountId) { - final Uri.Builder baseUri = Uri.parse("auth://" + EmailContent.EMAIL_PACKAGE_NAME + - ".ACCOUNT_SETTINGS/incoming/").buildUpon(); - IntentUtilities.setAccountId(baseUri, accountId); - return baseUri.build(); - } - public static Uri getOutgoingSettingsUri(long accountId) { final Uri.Builder baseUri = Uri.parse("auth://" + EmailContent.EMAIL_PACKAGE_NAME + ".ACCOUNT_SETTINGS/outgoing/").buildUpon(); diff --git a/src/com/android/email/activity/setup/SetupDataFragment.java b/src/com/android/email/activity/setup/SetupDataFragment.java index 45b7cf1ad..9824e1b34 100644 --- a/src/com/android/email/activity/setup/SetupDataFragment.java +++ b/src/com/android/email/activity/setup/SetupDataFragment.java @@ -7,6 +7,7 @@ import android.os.Parcel; import android.os.Parcelable; import com.android.email.service.EmailServiceUtils; +import com.android.email.setup.AuthenticatorSetupIntentHelper; import com.android.emailcommon.provider.Account; import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.Policy; @@ -18,20 +19,12 @@ public class SetupDataFragment extends Fragment implements Parcelable { // The "extra" name for the Bundle saved with SetupData public static final String EXTRA_SETUP_DATA = "com.android.email.setupdata"; - // NORMAL is the standard entry from the Email app; EAS and POP_IMAP are used when entering via - // Settings -> Accounts - public static final int FLOW_MODE_UNSPECIFIED = -1; - public static final int FLOW_MODE_NORMAL = 0; - public static final int FLOW_MODE_ACCOUNT_MANAGER = 1; - public static final int FLOW_MODE_EDIT = 3; - public static final int FLOW_MODE_FORCE_CREATE = 4; // The following two modes are used to "pop the stack" and return from the setup flow. We // either return to the caller (if we're in an account type flow) or go to the message list // TODO: figure out if we still care about these public static final int FLOW_MODE_RETURN_TO_CALLER = 5; public static final int FLOW_MODE_RETURN_TO_MESSAGE_LIST = 6; public static final int FLOW_MODE_RETURN_NO_ACCOUNTS_RESULT = 7; - public static final int FLOW_MODE_NO_ACCOUNTS = 8; // Mode bits for AccountSetupCheckSettings, indicating the type of check requested public static final int CHECK_INCOMING = 1; @@ -49,7 +42,7 @@ public class SetupDataFragment extends Fragment implements Parcelable { private static final String SAVESTATE_AM_PROTOCOL = "SetupDataFragment.amProtocol"; // All access will be through getters/setters - private int mFlowMode = FLOW_MODE_NORMAL; + private int mFlowMode = AuthenticatorSetupIntentHelper.FLOW_MODE_NORMAL; private Account mAccount; private String mEmail; private Bundle mCredentialResults; |