| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.server.backup; |
| 18 |
|
| 19 |
import android.accounts.AccountManagerInternal; |
| 20 |
import android.app.backup.BlobBackupHelper; |
| 21 |
import android.os.UserHandle; |
| 22 |
import android.util.Slog; |
| 23 |
import com.android.server.LocalServices; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class AccountManagerBackupHelper extends BlobBackupHelper { |
| 29 |
private static final String TAG = "AccountsBackup"; |
| 30 |
private static final boolean DEBUG = false; |
| 31 |
|
| 32 |
|
| 33 |
private static final int STATE_VERSION = 1; |
| 34 |
|
| 35 |
|
| 36 |
private static final String KEY_ACCOUNT_ACCESS_GRANTS = "account_access_grants"; |
| 37 |
|
| 38 |
public AccountManagerBackupHelper() { |
| 39 |
super(STATE_VERSION, KEY_ACCOUNT_ACCESS_GRANTS); |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
protected byte[] getBackupPayload(String key) { |
| 44 |
AccountManagerInternal am = LocalServices.getService(AccountManagerInternal.class); |
| 45 |
if (DEBUG) { |
| 46 |
Slog.d(TAG, "Handling backup of " + key); |
| 47 |
} |
| 48 |
try { |
| 49 |
switch (key) { |
| 50 |
case KEY_ACCOUNT_ACCESS_GRANTS: { |
| 51 |
return am.backupAccountAccessPermissions(UserHandle.USER_SYSTEM); |
| 52 |
} |
| 53 |
|
| 54 |
default: { |
| 55 |
Slog.w(TAG, "Unexpected backup key " + key); |
| 56 |
} |
| 57 |
} |
| 58 |
} catch (Exception e) { |
| 59 |
Slog.e(TAG, "Unable to store payload " + key, e); |
| 60 |
} |
| 61 |
|
| 62 |
return new byte[0]; |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
protected void applyRestoredPayload(String key, byte[] payload) { |
| 67 |
AccountManagerInternal am = LocalServices.getService(AccountManagerInternal.class); |
| 68 |
if (DEBUG) { |
| 69 |
Slog.d(TAG, "Handling restore of " + key); |
| 70 |
} |
| 71 |
try { |
| 72 |
switch (key) { |
| 73 |
case KEY_ACCOUNT_ACCESS_GRANTS: { |
| 74 |
am.restoreAccountAccessPermissions(payload, UserHandle.USER_SYSTEM); |
| 75 |
} break; |
| 76 |
|
| 77 |
default: { |
| 78 |
Slog.w(TAG, "Unexpected restore key " + key); |
| 79 |
} |
| 80 |
} |
| 81 |
} catch (Exception e) { |
| 82 |
Slog.e(TAG, "Unable to restore key " + key, e); |
| 83 |
} |
| 84 |
} |
| 85 |
} |