1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.email.provider;
18
19import android.content.ContentResolver;
20import android.content.Context;
21
22/**
23 * Helper class to facilitate EmailProvider's account backup/restore facility.
24 *
25 * Account backup/restore was implemented entirely for the purpose of recovering from database
26 * corruption errors that were/are sporadic and of undetermined cause (though the prevailing wisdom
27 * is that this is due to some kind of memory issue).  Rather than have the offending database get
28 * deleted by SQLiteDatabase and forcing the user to recreate his accounts from scratch, it was
29 * decided to backup accounts when created/modified and then restore them if 1) there are no
30 * accounts in the database and 2) there are backup accounts.  This, at least, would cause user's
31 * email data for IMAP/EAS to be re-synced and prevent the worst outcomes from occurring.
32 *
33 * To accomplish backup/restore, we use the facility now built in to EmailProvider to store a
34 * backup version of the Account and HostAuth tables in a second database (EmailProviderBackup.db)
35 *
36 * TODO: We might look into having our own DatabaseErrorHandler that tries to be clever about
37 * determining whether or not a "corrupt" database is truly corrupt; the problem here is that it
38 * has proven impossible to reproduce the bug, and therefore any "solution" of this kind of utterly
39 * impossible to test in the wild.
40 */
41public class AccountBackupRestore {
42    /**
43     * Backup user Account and HostAuth data into our backup database
44     *
45     * TODO Make EmailProvider do this automatically.
46     */
47    public static void backup(Context context) {
48        ContentResolver resolver = context.getContentResolver();
49        resolver.update(EmailProvider.ACCOUNT_BACKUP_URI, null, null, null);
50    }
51}
52