1 /* 2 * Copyright (C) 2016 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 package com.android.server.backup; 17 18 import android.app.backup.BlobBackupHelper; 19 import android.content.Context; 20 import android.content.pm.IShortcutService; 21 import android.os.ServiceManager; 22 import android.util.Slog; 23 24 public class ShortcutBackupHelper extends BlobBackupHelper { 25 private static final String TAG = "ShortcutBackupAgent"; 26 private static final int BLOB_VERSION = 1; 27 28 private static final String KEY_USER_FILE = "shortcutuser.xml"; 29 30 private final int mUserId; 31 ShortcutBackupHelper(int userId)32 public ShortcutBackupHelper(int userId) { 33 super(BLOB_VERSION, KEY_USER_FILE); 34 mUserId = userId; 35 } 36 getShortcutService()37 private IShortcutService getShortcutService() { 38 return IShortcutService.Stub.asInterface( 39 ServiceManager.getService(Context.SHORTCUT_SERVICE)); 40 } 41 42 @Override getBackupPayload(String key)43 protected byte[] getBackupPayload(String key) { 44 switch (key) { 45 case KEY_USER_FILE: 46 try { 47 return getShortcutService().getBackupPayload(mUserId); 48 } catch (Exception e) { 49 Slog.wtf(TAG, "Backup failed", e); 50 } 51 break; 52 default: 53 Slog.w(TAG, "Unknown key: " + key); 54 } 55 return null; 56 } 57 58 @Override applyRestoredPayload(String key, byte[] payload)59 protected void applyRestoredPayload(String key, byte[] payload) { 60 switch (key) { 61 case KEY_USER_FILE: 62 try { 63 getShortcutService().applyRestore(payload, mUserId); 64 } catch (Exception e) { 65 Slog.wtf(TAG, "Restore failed", e); 66 } 67 break; 68 default: 69 Slog.w(TAG, "Unknown key: " + key); 70 } 71 } 72 } 73