Fix NPE when adding account with security policy

When adding an Exchange account with a security policy, Email
generates a notification to let the user enable the policy. The
code that generates the notification attemptes to load the folder
as part of the base notification.  Before the account policy has been
configured, it isn't possible to load the folder.  We need to handle
a null folder when generating the notification

Also, imporoved the logging when an exception is thrown from the
PolicyService

Bug: 8341882
Change-Id: I33ff57adc3c130e8318910e352146b8ea56f9a2c
This commit is contained in:
Paul Westbrook 2013-03-07 23:00:47 -08:00
parent 1eebd2f61c
commit 95bb350f38
2 changed files with 50 additions and 22 deletions

View File

@ -312,10 +312,11 @@ public class NotificationController {
UIProvider.FOLDERS_PROJECTION, null, null, null);
if (folderCursor == null) {
LogUtils.e(LOG_TAG, "Null folder cursor for mailbox %s",
// This can happen when the notification is for the security policy notification
// that happens before the account is setup
LogUtils.w(LOG_TAG, "Null folder cursor for mailbox %s",
uiAccount.settings.defaultInbox);
}
} else {
Folder folder = null;
try {
if (folderCursor.moveToFirst()) {
@ -326,13 +327,15 @@ public class NotificationController {
}
if (folder != null) {
final FolderPreferences folderPreferences =
new FolderPreferences(mContext, uiAccount.name, folder, true /* inbox */);
final FolderPreferences folderPreferences = new FolderPreferences(
mContext, uiAccount.name, folder, true /* inbox */);
ringtoneUri = folderPreferences.getNotificationRingtoneUri();
vibrate = folderPreferences.isNotificationVibrateEnabled();
} else {
LogUtils.e(LOG_TAG, "Null folder for mailbox %s", uiAccount.settings.defaultInbox);
LogUtils.e(LOG_TAG,
"Null folder for mailbox %s", uiAccount.settings.defaultInbox);
}
}
} else {
LogUtils.e(LOG_TAG, "Null uiAccount for account id %d", account.mId);

View File

@ -24,15 +24,25 @@ import android.os.IBinder;
import com.android.email.SecurityPolicy;
import com.android.emailcommon.provider.Policy;
import com.android.emailcommon.service.IPolicyService;
import com.android.mail.utils.LogTag;
import com.android.mail.utils.LogUtils;
public class PolicyService extends Service {
private static final String LOG_TAG = LogTag.getLogTag();
private SecurityPolicy mSecurityPolicy;
private Context mContext;
private final IPolicyService.Stub mBinder = new IPolicyService.Stub() {
public boolean isActive(Policy policy) {
try {
return mSecurityPolicy.isActive(policy);
} catch (RuntimeException e) {
// Catch, log and rethrow the exception, as otherwise when the exception is
// ultimately handled, the complete stack trace is losk
LogUtils.e(LOG_TAG, e, "Exception thrown during call to SecurityPolicy#isActive");
throw e;
}
}
public void setAccountHoldFlag(long accountId, boolean newState) {
@ -40,11 +50,26 @@ public class PolicyService extends Service {
}
public void remoteWipe() {
try {
mSecurityPolicy.remoteWipe();
} catch (RuntimeException e) {
// Catch, log and rethrow the exception, as otherwise when the exception is
// ultimately handled, the complete stack trace is losk
LogUtils.e(LOG_TAG, e, "Exception thrown during call to SecurityPolicy#remoteWipe");
throw e;
}
}
public void setAccountPolicy(long accountId, Policy policy, String securityKey) {
try {
mSecurityPolicy.setAccountPolicy(accountId, policy, securityKey);
} catch (RuntimeException e) {
// Catch, log and rethrow the exception, as otherwise when the exception is
// ultimately handled, the complete stack trace is losk
LogUtils.e(LOG_TAG, e,
"Exception thrown from call to SecurityPolicy#setAccountPolicy");
throw e;
}
}
};