1 /* 2 * Copyright (C) 2023 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.server.ondevicepersonalization; 18 19 import static org.junit.Assert.assertTrue; 20 21 import android.content.Context; 22 import android.ondevicepersonalization.IOnDevicePersonalizationSystemServiceCallback; 23 import android.os.Bundle; 24 25 import androidx.test.core.app.ApplicationProvider; 26 27 import com.android.modules.utils.build.SdkLevel; 28 import com.android.ondevicepersonalization.testing.utils.DeviceSupportHelper; 29 30 import org.junit.Assume; 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.junit.runners.JUnit4; 35 36 import java.util.concurrent.CountDownLatch; 37 38 @RunWith(JUnit4.class) 39 public class OdpSystemServiceImplTest { 40 private final Context mContext = ApplicationProvider.getApplicationContext(); 41 private boolean mOnResultCalled = false; 42 private boolean mOnErrorCalled = false; 43 private Bundle mResult; 44 private int mErrorCode = 0; 45 private CountDownLatch mLatch = new CountDownLatch(1); 46 private OnDevicePersonalizationSystemService mService = 47 new OnDevicePersonalizationSystemService(mContext); 48 private IOnDevicePersonalizationSystemServiceCallback mCallback; 49 50 @Before setUp()51 public void setUp() throws Exception { 52 Assume.assumeTrue(DeviceSupportHelper.isDeviceSupported()); 53 Assume.assumeTrue(SdkLevel.isAtLeastU()); 54 mCallback = new IOnDevicePersonalizationSystemServiceCallback.Stub() { 55 @Override 56 public void onResult(Bundle bundle) { 57 mOnResultCalled = true; 58 mResult = bundle; 59 mLatch.countDown(); 60 } 61 62 @Override 63 public void onError(int errorCode) { 64 mOnErrorCalled = true; 65 mErrorCode = errorCode; 66 mLatch.countDown(); 67 } 68 }; 69 } 70 71 @Test testSystemServerServiceOnRequest()72 public void testSystemServerServiceOnRequest() throws Exception { 73 mService.onRequest(new Bundle(), mCallback); 74 mLatch.await(); 75 assertTrue(mOnResultCalled); 76 } 77 } 78