1 /* 2 * Copyright (C) 2022 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 android.app.sdksandbox.testutils; 18 19 import android.app.sdksandbox.ISharedPreferencesSyncCallback; 20 21 public class FakeSharedPreferencesSyncCallback extends ISharedPreferencesSyncCallback.Stub { 22 boolean mOnSandboxStartCalled = false; 23 boolean mOnErrorCalled = false; 24 private WaitableCountDownLatch mSyncDataLatch = new WaitableCountDownLatch(5); 25 private int mErrorCode; 26 private String mErrorMsg; 27 28 @Override onSandboxStart()29 public void onSandboxStart() { 30 mOnSandboxStartCalled = true; 31 mSyncDataLatch.countDown(); 32 } 33 34 @Override onError(int errorCode, String errorMsg)35 public void onError(int errorCode, String errorMsg) { 36 mOnErrorCalled = true; 37 mErrorCode = errorCode; 38 mErrorMsg = errorMsg; 39 mSyncDataLatch.countDown(); 40 } 41 hasSandboxStarted()42 public boolean hasSandboxStarted() { 43 mSyncDataLatch.waitForLatch(); 44 return mOnSandboxStartCalled; 45 } 46 hasError()47 public boolean hasError() { 48 mSyncDataLatch.waitForLatch(); 49 return mOnErrorCalled; 50 } 51 getErrorCode()52 public int getErrorCode() { 53 mSyncDataLatch.waitForLatch(); 54 return mErrorCode; 55 } 56 getErrorMsg()57 public String getErrorMsg() { 58 mSyncDataLatch.waitForLatch(); 59 return mErrorMsg; 60 } 61 resetLatch()62 public void resetLatch() { 63 mSyncDataLatch = new WaitableCountDownLatch(5); 64 } 65 66 } 67