Changes to improve security policy setup

* SecurityPolicy:  Fix bug that prevents any notifications after the
    user hits "cancel all" from the notification pane.
* AccountSecurity: If the user cancels the device admin acceptance
    activity, repost the notification.
* MesageList:  Catch security hold condition when entering a mailbox, and
    launch security setup activity.

Bug: 2585159
Change-Id: I60d5d8c693cc5f00fe98a9cc69265802f5bee813
This commit is contained in:
Andrew Stadler 2010-04-13 02:15:37 -07:00
parent 0cd062ebd0
commit a87f8d8bbc
3 changed files with 70 additions and 19 deletions

View File

@ -49,7 +49,6 @@ public class SecurityPolicy {
private DevicePolicyManager mDPM;
private ComponentName mAdminName;
private PolicySet mAggregatePolicy;
private boolean mNotificationActive;
/* package */ static final PolicySet NO_POLICY_SET =
new PolicySet(0, PolicySet.PASSWORD_MODE_NONE, 0, 0, false);
@ -102,7 +101,6 @@ public class SecurityPolicy {
mDPM = null;
mAdminName = new ComponentName(context, PolicyAdmin.class);
mAggregatePolicy = null;
mNotificationActive = false;
}
/**
@ -368,20 +366,7 @@ public class SecurityPolicy {
// Mark the account as "on hold".
setAccountHoldFlag(account, true);
// Put up a notification (unless there already is one)
synchronized (this) {
if (mNotificationActive) {
// no need to do anything - we've already been notified, and we've already
// put up a notification
return;
} else {
// Prepare & post a notification
// record that we're watching this one
mNotificationActive = true;
}
}
// At this point, we will put up a notification
// Put up a notification
String tickerText = mContext.getString(R.string.security_notification_ticker_fmt,
account.getDisplayName());
String contentTitle = mContext.getString(R.string.security_notification_content_title);
@ -421,11 +406,10 @@ public class SecurityPolicy {
* Called from the notification's intent receiver to register that the notification can be
* cleared now.
*/
public synchronized void clearNotification(long accountId) {
public void clearNotification(long accountId) {
NotificationManager notificationManager =
(NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(MailService.NOTIFICATION_ID_SECURITY_NEEDED);
mNotificationActive = false;
}
/**

View File

@ -20,6 +20,7 @@ import com.android.email.Controller;
import com.android.email.Email;
import com.android.email.R;
import com.android.email.Utility;
import com.android.email.activity.setup.AccountSecurity;
import com.android.email.activity.setup.AccountSettings;
import com.android.email.mail.AuthenticationFailedException;
import com.android.email.mail.CertificateValidationException;
@ -92,6 +93,8 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
private static final String STATE_CHECKED_ITEMS =
"com.android.email.activity.MessageList.checkedItems";
private static final int REQUEST_SECURITY = 0;
// UI support
private ListView mListView;
private View mMultiSelectPanel;
@ -140,6 +143,10 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
private static final String[] ACCOUNT_NAME_PROJECTION = new String[] {
AccountColumns.DISPLAY_NAME };
private static final int ACCOUNT_INFO_COLUMN_FLAGS = 0;
private static final String[] ACCOUNT_INFO_PROJECTION = new String[] {
AccountColumns.FLAGS };
private static final String ID_SELECTION = EmailContent.RECORD_ID + "=?";
private Boolean mPushModeMailbox = null;
@ -1060,6 +1067,7 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
private final int mMailboxType;
private final boolean mOkToRecurse;
private boolean showWelcomeActivity;
private boolean showSecurityActivity;
/**
* Special constructor to cache some local info
@ -1068,10 +1076,17 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
mAccountId = accountId;
mMailboxType = mailboxType;
mOkToRecurse = okToRecurse;
showWelcomeActivity = false;
showSecurityActivity = false;
}
@Override
protected Long doInBackground(Void... params) {
// Quick check that account is not in security hold
if (isSecurityHold(mAccountId)) {
showSecurityActivity = true;
return Long.valueOf(-1);
}
// See if we can find the requested mailbox in the DB.
long mailboxId = Mailbox.findMailboxOfType(MessageList.this, mAccountId, mMailboxType);
if (mailboxId == Mailbox.NO_MAILBOX) {
@ -1092,6 +1107,13 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
@Override
protected void onPostExecute(Long mailboxId) {
if (showSecurityActivity) {
// launch the security setup activity
Intent i = AccountSecurity.actionUpdateSecurityIntent(
MessageList.this, mAccountId);
MessageList.this.startActivityForResult(i, REQUEST_SECURITY);
return;
}
if (showWelcomeActivity) {
// Let the Welcome activity show the default screen.
Welcome.actionStart(MessageList.this);
@ -1109,6 +1131,41 @@ public class MessageList extends ListActivity implements OnItemClickListener, On
}
}
/**
* Check a single account for security hold status. Do not call from UI thread.
*/
private boolean isSecurityHold(long accountId) {
Cursor c = MessageList.this.getContentResolver().query(
ContentUris.withAppendedId(Account.CONTENT_URI, accountId),
ACCOUNT_INFO_PROJECTION, null, null, null);
try {
if (c.moveToFirst()) {
int flags = c.getInt(ACCOUNT_INFO_COLUMN_FLAGS);
if ((flags & Account.FLAGS_SECURITY_HOLD) != 0) {
return true;
}
}
} finally {
c.close();
}
return false;
}
/**
* Handle the eventual result from the security update activity
*
* Note, this is extremely coarse, and it simply returns the user to the Accounts list.
* Anything more requires refactoring of this Activity.
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_SECURITY:
onAccounts();
}
super.onActivityResult(requestCode, resultCode, data);
}
/**
* Async task for loading a single folder out of the UI thread
*

View File

@ -102,7 +102,17 @@ public class AccountSecurity extends Activity {
// now active - try to set actual policies
setActivePolicies();
} else {
// failed - just give up and go away
// failed - repost notification, and exit
final long accountId = getIntent().getLongExtra(EXTRA_ACCOUNT_ID, -1);
if (accountId != -1) {
new Thread() {
@Override
public void run() {
SecurityPolicy.getInstance(AccountSecurity.this)
.policiesRequired(accountId);
}
}.start();
}
}
}
finish();