• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.ondevicepersonalization.systemserviceapitests;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNotEquals;
21 import static org.junit.Assert.assertTrue;
22 
23 import android.app.ondevicepersonalization.IOnDevicePersonalizationSystemService;
24 import android.app.ondevicepersonalization.IOnDevicePersonalizationSystemServiceCallback;
25 import android.app.ondevicepersonalization.OnDevicePersonalizationSystemServiceManager;
26 import android.content.Context;
27 import android.os.Bundle;
28 
29 import androidx.test.core.app.ApplicationProvider;
30 
31 import com.android.modules.utils.build.SdkLevel;
32 
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.JUnit4;
36 
37 import java.util.concurrent.CountDownLatch;
38 
39 @RunWith(JUnit4.class)
40 public class OdpSystemServiceApiTest {
41     private final Context mContext = ApplicationProvider.getApplicationContext();
42     boolean mOnResultCalled = false;
43     CountDownLatch mLatch = new CountDownLatch(1);
44 
45     @Test
testInvokeSystemServerServiceSucceedsOnU()46     public void testInvokeSystemServerServiceSucceedsOnU() throws Exception {
47         if (!SdkLevel.isAtLeastU()) {
48             return;
49         }
50 
51         OnDevicePersonalizationSystemServiceManager manager =
52                 mContext.getSystemService(OnDevicePersonalizationSystemServiceManager.class);
53         assertNotEquals(null, manager);
54         IOnDevicePersonalizationSystemService service =
55                 manager.getService();
56         assertNotEquals(null, service);
57         service.onRequest(
58                 new Bundle(),
59                 new IOnDevicePersonalizationSystemServiceCallback.Stub() {
60                     @Override public void onResult(Bundle result) {
61                         mOnResultCalled = true;
62                         mLatch.countDown();
63                     }
64                 });
65         mLatch.await();
66         assertTrue(mOnResultCalled);
67     }
68 
69     @Test
testNullSystemServiceOnT()70     public void testNullSystemServiceOnT() throws Exception {
71         if (SdkLevel.isAtLeastU()) {
72             return;
73         }
74         assertEquals(
75                 null,
76                 mContext.getSystemService(OnDevicePersonalizationSystemServiceManager.class));
77     }
78 }
79