1 /* 2 * Copyright (C) 2015 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 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"; // must be < 23 chars 27 static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 28 29 // Current version of the blob schema 30 static final int BLOB_VERSION = 1; 31 32 // Key under which the payload blob is stored 33 static final String KEY_NOTIFICATIONS = "notifications"; 34 35 private final int mUserId; 36 NotificationBackupHelper(int userId)37 public NotificationBackupHelper(int userId) { 38 super(BLOB_VERSION, KEY_NOTIFICATIONS); 39 mUserId = userId; 40 } 41 42 @Override getBackupPayload(String key)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 // Treat as no data 52 Slog.e(TAG, "Couldn't communicate with notification manager", e); 53 newPayload = null; 54 } 55 } 56 return newPayload; 57 } 58 59 @Override applyRestoredPayload(String key, byte[] payload)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 } 77