1 /* 2 * Copyright (C) 2021 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.cts.encryptionapp; 18 19 import android.content.Context; 20 import android.util.Log; 21 import android.service.resumeonreboot.ResumeOnRebootService; 22 23 import javax.annotation.Nullable; 24 25 /** A implementation for {@link IResumeOnRebootService} 26 * 27 * This class provides a fake implementation for the server based resume on reboot service. 28 * It's used for cts test to verify the functionality of platform code, and it won't talk to 29 * the server when wrap/unwrap is called. 30 */ 31 public class RebootEscrowFakeService extends ResumeOnRebootService { 32 static final String TAG = "RebootEscrowFakeService"; 33 34 // Name of the shared preference for service interaction 35 static final String SERVICE_PREFS = "SERVICE_PREFERENCES"; 36 37 @Nullable 38 @Override onWrap(byte[] blob, long lifeTimeInMillis)39 public byte[] onWrap(byte[] blob, long lifeTimeInMillis) { 40 // Tests can this flag to verify that unwrap is called. 41 Context context = 42 getApplication().getApplicationContext().createDeviceProtectedStorageContext(); 43 context.getSharedPreferences(SERVICE_PREFS, 0).edit() 44 .putBoolean("WRAP_CALLED", true).commit(); 45 46 return blob; 47 } 48 49 @Nullable 50 @Override onUnwrap(byte[] wrappedBlob)51 public byte[] onUnwrap(byte[] wrappedBlob) { 52 // Tests can this flag to verify that unwrap is called. 53 Context context = 54 getApplication().getApplicationContext().createDeviceProtectedStorageContext(); 55 context.getSharedPreferences(SERVICE_PREFS, 0).edit() 56 .putBoolean("UNWRAP_CALLED", true).commit(); 57 58 return wrappedBlob; 59 } 60 } 61