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