1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.server.backup; 16 17 import android.app.backup.BlobBackupHelper; 18 import android.app.slice.ISliceManager; 19 import android.content.Context; 20 import android.os.ServiceManager; 21 import android.os.UserHandle; 22 import android.util.Log; 23 import android.util.Slog; 24 25 public class SliceBackupHelper extends BlobBackupHelper { 26 static final String TAG = "SliceBackupHelper"; 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_SLICES = "slices"; 34 SliceBackupHelper(Context context)35 public SliceBackupHelper(Context context) { 36 super(BLOB_VERSION, KEY_SLICES); 37 // context is currently unused 38 } 39 40 @Override getBackupPayload(String key)41 protected byte[] getBackupPayload(String key) { 42 byte[] newPayload = null; 43 if (KEY_SLICES.equals(key)) { 44 try { 45 ISliceManager sm = ISliceManager.Stub.asInterface( 46 ServiceManager.getService(Context.SLICE_SERVICE)); 47 // TODO: http://b/22388012 48 newPayload = sm.getBackupPayload(UserHandle.USER_SYSTEM); 49 } catch (Exception e) { 50 // Treat as no data 51 Slog.e(TAG, "Couldn't communicate with slice manager", e); 52 newPayload = null; 53 } 54 } 55 return newPayload; 56 } 57 58 @Override applyRestoredPayload(String key, byte[] payload)59 protected void applyRestoredPayload(String key, byte[] payload) { 60 if (DEBUG) Slog.v(TAG, "Got restore of " + key); 61 62 if (KEY_SLICES.equals(key)) { 63 try { 64 ISliceManager sm = ISliceManager.Stub.asInterface( 65 ServiceManager.getService(Context.SLICE_SERVICE)); 66 // TODO: http://b/22388012 67 sm.applyRestore(payload, UserHandle.USER_SYSTEM); 68 } catch (Exception e) { 69 Slog.e(TAG, "Couldn't communicate with slice manager", e); 70 } 71 } 72 } 73 74 } 75