| 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.annotation.NonNull; |
| 20 |
import android.annotation.UserIdInt; |
| 21 |
import android.app.backup.BlobBackupHelper; |
| 22 |
import android.permission.PermissionManagerInternal; |
| 23 |
import android.util.Slog; |
| 24 |
|
| 25 |
import com.android.server.LocalServices; |
| 26 |
|
| 27 |
public class PermissionBackupHelper extends BlobBackupHelper { |
| 28 |
private static final String TAG = "PermissionBackup"; |
| 29 |
private static final boolean DEBUG = false; |
| 30 |
|
| 31 |
|
| 32 |
private static final int STATE_VERSION = 1; |
| 33 |
|
| 34 |
|
| 35 |
private static final String KEY_PERMISSIONS = "permissions"; |
| 36 |
|
| 37 |
private final @UserIdInt int mUserId; |
| 38 |
|
| 39 |
private final @NonNull PermissionManagerInternal mPermissionManager; |
| 40 |
|
| 41 |
public PermissionBackupHelper(int userId) { |
| 42 |
super(STATE_VERSION, KEY_PERMISSIONS); |
| 43 |
|
| 44 |
mUserId = userId; |
| 45 |
mPermissionManager = LocalServices.getService(PermissionManagerInternal.class); |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
protected byte[] getBackupPayload(String key) { |
| 50 |
if (DEBUG) { |
| 51 |
Slog.d(TAG, "Handling backup of " + key); |
| 52 |
} |
| 53 |
try { |
| 54 |
switch (key) { |
| 55 |
case KEY_PERMISSIONS: |
| 56 |
return mPermissionManager.backupRuntimePermissions(mUserId); |
| 57 |
|
| 58 |
default: |
| 59 |
Slog.w(TAG, "Unexpected backup key " + key); |
| 60 |
} |
| 61 |
} catch (Exception e) { |
| 62 |
Slog.e(TAG, "Unable to store payload " + key, e); |
| 63 |
} |
| 64 |
return null; |
| 65 |
} |
| 66 |
|
| 67 |
@Override |
| 68 |
protected void applyRestoredPayload(String key, byte[] payload) { |
| 69 |
if (DEBUG) { |
| 70 |
Slog.d(TAG, "Handling restore of " + key); |
| 71 |
} |
| 72 |
try { |
| 73 |
switch (key) { |
| 74 |
case KEY_PERMISSIONS: |
| 75 |
mPermissionManager.restoreRuntimePermissions(payload, mUserId); |
| 76 |
break; |
| 77 |
|
| 78 |
default: |
| 79 |
Slog.w(TAG, "Unexpected restore key " + key); |
| 80 |
} |
| 81 |
} catch (Exception e) { |
| 82 |
Slog.e(TAG, "Unable to restore key " + key, e); |
| 83 |
} |
| 84 |
} |
| 85 |
} |