Change EAS authenticator's label according to the vendor policy.

Our original plan was to disable both authenticators by default, and enable
one of then on boot.  However, it turned out existing exchange accounts will
be removed if there's no enabled authenticators for the account type.
So, instead, in this patch we initially enable only the default one, and switch
to the other one on boot if the vendor policy indicates so.

(If a device has a vendor policy apk, it should also have the email app
preloaded, so changing the label at boot time isn't too late.)

Bug: 2382710
This commit is contained in:
Makoto Onuki 2010-01-28 10:07:51 -08:00
parent 130988e49d
commit b854d05a89
6 changed files with 191 additions and 3 deletions

View File

@ -207,6 +207,15 @@
</intent-filter>
</receiver>
<receiver
android:name=".OneTimeInitializer"
android:enabled="true"
>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name=".service.MailService"
android:enabled="false"
@ -243,12 +252,35 @@
</service>
<!--Required stanza to register the EasAuthenticatorService with AccountManager -->
<service android:name=".service.EasAuthenticatorService" android:exported="true">
<service
android:name=".service.EasAuthenticatorService"
android:exported="true"
android:enabled="true"
>
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator" />
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator"
/>
</service>
<!--
EasAuthenticatorService with the altenative label. Disabled by default,
and OneTimeInitializer enables it if the vendor policy tells so.
-->
<service
android:name=".service.EasAuthenticatorServiceAlternate"
android:exported="true"
android:enabled="false"
>
<intent-filter>
<action android:name="android.accounts.AccountAuthenticator" />
</intent-filter>
<meta-data
android:name="android.accounts.AccountAuthenticator"
android:resource="@xml/authenticator_alternate"
/>
</service>
<provider

View File

@ -574,6 +574,8 @@
<!-- Name of Microsoft Exchange account type; used by AccountManager -->
<string name="exchange_name">Corporate</string>
<!-- Name of Microsoft Exchange account type; used by AccountManager -->
<string name="exchange_name_alternate">Microsoft Exchange ActiveSync</string>
<!-- Message that appears if the AccountManager cannot create the system Account -->
<string name="system_account_create_failed">The AccountManager could not create the Account; please try again.</string>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/**
* 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.
*/
-->
<!-- The attributes in this XML file provide configuration information -->
<!-- for the Account Manager. -->
<!-- The only difference from authenticator.xml is android:label. -->
<account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
android:accountType="com.android.exchange"
android:icon="@drawable/ic_exchange_selected"
android:smallIcon="@drawable/ic_exchange_minitab_selected"
android:label="@string/exchange_name_alternate"
android:accountPreferences="@xml/account_preferences"
/>

View File

@ -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.
*
* <p>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);
}
}

View File

@ -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() {
}

View File

@ -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.
*
* <p>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 {
}