| 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.app.INotificationManager; |
| 20 |
import android.app.backup.BlobBackupHelper; |
| 21 |
import android.os.ServiceManager; |
| 22 |
import android.util.Log; |
| 23 |
import android.util.Slog; |
| 24 |
|
| 25 |
public class NotificationBackupHelper extends BlobBackupHelper { |
| 26 |
static final String TAG = "NotifBackupHelper"; |
| 27 |
static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
| 28 |
|
| 29 |
|
| 30 |
static final int BLOB_VERSION = 1; |
| 31 |
|
| 32 |
|
| 33 |
static final String KEY_NOTIFICATIONS = "notifications"; |
| 34 |
|
| 35 |
private final int mUserId; |
| 36 |
|
| 37 |
public NotificationBackupHelper(int userId) { |
| 38 |
super(BLOB_VERSION, KEY_NOTIFICATIONS); |
| 39 |
mUserId = userId; |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
protected byte[] getBackupPayload(String key) { |
| 44 |
byte[] newPayload = null; |
| 45 |
if (KEY_NOTIFICATIONS.equals(key)) { |
| 46 |
try { |
| 47 |
INotificationManager nm = INotificationManager.Stub.asInterface( |
| 48 |
ServiceManager.getService("notification")); |
| 49 |
newPayload = nm.getBackupPayload(mUserId); |
| 50 |
} catch (Exception e) { |
| 51 |
|
| 52 |
Slog.e(TAG, "Couldn't communicate with notification manager", e); |
| 53 |
newPayload = null; |
| 54 |
} |
| 55 |
} |
| 56 |
return newPayload; |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
protected void applyRestoredPayload(String key, byte[] payload) { |
| 61 |
if (DEBUG) { |
| 62 |
Slog.v(TAG, "Got restore of " + key); |
| 63 |
} |
| 64 |
|
| 65 |
if (KEY_NOTIFICATIONS.equals(key)) { |
| 66 |
try { |
| 67 |
INotificationManager nm = INotificationManager.Stub.asInterface( |
| 68 |
ServiceManager.getService("notification")); |
| 69 |
nm.applyRestore(payload, mUserId); |
| 70 |
} catch (Exception e) { |
| 71 |
Slog.e(TAG, "Couldn't communicate with notification manager", e); |
| 72 |
} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
} |