diff --git a/AndroidManifest.xml b/AndroidManifest.xml index caf95926b..13210efde 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -207,6 +207,15 @@ + + + + + + - + - + + + + + + + + Corporate + + Microsoft Exchange ActiveSync The AccountManager could not create the Account; please try again. diff --git a/res/xml/authenticator_alternate.xml b/res/xml/authenticator_alternate.xml new file mode 100644 index 000000000..44b756667 --- /dev/null +++ b/res/xml/authenticator_alternate.xml @@ -0,0 +1,31 @@ + + + + + + + + + diff --git a/src/com/android/email/OneTimeInitializer.java b/src/com/android/email/OneTimeInitializer.java new file mode 100644 index 000000000..24c49cba3 --- /dev/null +++ b/src/com/android/email/OneTimeInitializer.java @@ -0,0 +1,87 @@ +/* + * 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; + +import com.android.email.service.EasAuthenticatorService; +import com.android.email.service.EasAuthenticatorServiceAlternate; + +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.util.Config; +import android.util.Log; + +/** + * A class that performs one-time initialization after installation. + * + *

Android doesn't offer any mechanism to trigger an app right after installation, so we use the + * BOOT_COMPLETED broadcast intent instead. This means, when the app is upgraded, the + * initialization code here won't run until the device reboots. + */ +public class OneTimeInitializer extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) { + initialize(context); + } + } + + /** + * Perform the one-time initialization. + */ + private void initialize(Context context) { + if (Config.LOGD) { + Log.d(Email.LOG_TAG, "OneTimeInitializer: initializing..."); + } + final Preferences pref = Preferences.getPreferences(context); + int progress = pref.getOneTimeInitializationProgress(); + + if (progress < 1) { + progress = 1; + if (VendorPolicyLoader.getInstance(context).useAlternateExchangeStrings()) { + setComponentEnabled(context, EasAuthenticatorServiceAlternate.class, true); + setComponentEnabled(context, EasAuthenticatorService.class, false); + } + } + + // If we need other initializations in the future... + // - add your initialization code here, and + // - rename this class to something like "OneTimeInitializer2" (and modify AndroidManifest + // accordingly) + // Renaming is necessary because once we disable a component, it won't be automatically + // enabled again even when the app is upgraded. + + // Use "progress" to skip the initializations that's already done before. + // Using this preference also makes it safe when a user skips an upgrade. (i.e. upgrading + // version N to version N+2) + + // Save progress and disable itself. + pref.setOneTimeInitializationProgress(progress); + setComponentEnabled(context, getClass(), false); + } + + private void setComponentEnabled(Context context, Class clazz, boolean enabled) { + final ComponentName c = new ComponentName(context, clazz.getName()); + context.getPackageManager().setComponentEnabledSetting(c, + enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED + : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); + } +} diff --git a/src/com/android/email/Preferences.java b/src/com/android/email/Preferences.java index 773baef7b..c960d0546 100644 --- a/src/com/android/email/Preferences.java +++ b/src/com/android/email/Preferences.java @@ -36,6 +36,7 @@ public class Preferences { private static final String ENABLE_EXCHANGE_LOGGING = "enableExchangeLogging"; private static final String ENABLE_EXCHANGE_FILE_LOGGING = "enableExchangeFileLogging"; private static final String DEVICE_UID = "deviceUID"; + private static final String ONE_TIME_INITIALIZATION_PROGRESS = "oneTimeInitializationProgress"; private static Preferences preferences; @@ -178,6 +179,14 @@ public class Preferences { return result; } + public int getOneTimeInitializationProgress() { + return mSharedPreferences.getInt(ONE_TIME_INITIALIZATION_PROGRESS, 0); + } + + public void setOneTimeInitializationProgress(int progress) { + mSharedPreferences.edit().putInt(ONE_TIME_INITIALIZATION_PROGRESS, progress).commit(); + } + public void save() { } diff --git a/src/com/android/email/service/EasAuthenticatorServiceAlternate.java b/src/com/android/email/service/EasAuthenticatorServiceAlternate.java new file mode 100644 index 000000000..2c8d47263 --- /dev/null +++ b/src/com/android/email/service/EasAuthenticatorServiceAlternate.java @@ -0,0 +1,27 @@ +/* + * 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.service; + +/** + * {@link EasAuthenticatorService} used with the alternative label. + * + *

Functionality wise, it's a 100% clone of {@link EasAuthenticatorService}, but in order to + * independently disable/enable each service we need to give it a different class name. + */ +public class EasAuthenticatorServiceAlternate extends EasAuthenticatorService { + +}