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 17package com.android.server.backup; 18 19import android.app.INotificationManager; 20import android.app.backup.BlobBackupHelper; 21import android.content.Context; 22import android.os.ServiceManager; 23import android.os.UserHandle; 24import android.util.Log; 25import android.util.Slog; 26 27public class NotificationBackupHelper extends BlobBackupHelper { 28 static final String TAG = "NotifBackupHelper"; // must be < 23 chars 29 static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); 30 31 // Current version of the blob schema 32 static final int BLOB_VERSION = 1; 33 34 // Key under which the payload blob is stored 35 static final String KEY_NOTIFICATIONS = "notifications"; 36 37 public NotificationBackupHelper(Context context) { 38 super(BLOB_VERSION, KEY_NOTIFICATIONS); 39 // context is currently unused 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 // TODO: http://b/22388012 50 newPayload = nm.getBackupPayload(UserHandle.USER_SYSTEM); 51 } catch (Exception e) { 52 // Treat as no data 53 Slog.e(TAG, "Couldn't communicate with notification manager"); 54 newPayload = null; 55 } 56 } 57 return newPayload; 58 } 59 60 @Override 61 protected void applyRestoredPayload(String key, byte[] payload) { 62 if (DEBUG) { 63 Slog.v(TAG, "Got restore of " + key); 64 } 65 66 if (KEY_NOTIFICATIONS.equals(key)) { 67 try { 68 INotificationManager nm = INotificationManager.Stub.asInterface( 69 ServiceManager.getService("notification")); 70 // TODO: http://b/22388012 71 nm.applyRestore(payload, UserHandle.USER_SYSTEM); 72 } catch (Exception e) { 73 Slog.e(TAG, "Couldn't communicate with notification manager"); 74 } 75 } 76 } 77 78} 79