• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.car.apitest;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import static org.junit.Assert.assertThrows;
22 
23 import android.car.Car;
24 import android.car.app.CarActivityManager;
25 import android.car.test.ApiCheckerRule.Builder;
26 import android.content.ActivityNotFoundException;
27 import android.content.ComponentName;
28 import android.test.suitebuilder.annotation.MediumTest;
29 import android.util.Log;
30 import android.view.Display;
31 
32 import org.junit.Before;
33 import org.junit.Test;
34 
35 @MediumTest
36 public final class CarActivityManagerTest extends CarApiTestBase {
37     private static final String TAG = CarActivityManagerTest.class.getSimpleName();
38 
39     // Comes from android.window.DisplayAreaOrganizer.FEATURE_DEFAULT_TASK_CONTAINER
40     private static final int FEATURE_DEFAULT_TASK_CONTAINER = 1;
41 
42     // Comes from android.window.DisplayAreaOrganizer.FEATURE_UNDEFINED
43     private static final int FEATURE_UNDEFINED = -1;
44 
45     private CarActivityManager mCarActivityManager;
46 
47     private final ComponentName mTestActivity = new ComponentName("test.pkg", "test.activity");
48 
49     // TODO(b/242350638): add missing annotations, remove (on child bug of 242350638)
50     @Override
configApiCheckerRule(Builder builder)51     protected void configApiCheckerRule(Builder builder) {
52         Log.w(TAG, "Disabling API requirements check");
53         builder.disableAnnotationsCheck();
54     }
55 
56     @Before
setUp()57     public void setUp() throws Exception {
58         mCarActivityManager = (CarActivityManager) getCar().getCarManager(Car.CAR_ACTIVITY_SERVICE);
59         assertThat(mCarActivityManager).isNotNull();
60     }
61 
62     @Test
testSetPersistentActivity()63     public void testSetPersistentActivity() {
64         // Set
65         int retSet = mCarActivityManager.setPersistentActivity(
66                 mTestActivity, Display.DEFAULT_DISPLAY, FEATURE_DEFAULT_TASK_CONTAINER);
67         assertThat(retSet).isEqualTo(CarActivityManager.RESULT_SUCCESS);
68 
69         // Remove
70         int retRemove = mCarActivityManager.setPersistentActivity(
71                 mTestActivity, Display.DEFAULT_DISPLAY, FEATURE_UNDEFINED);
72         assertThat(retRemove).isEqualTo(CarActivityManager.RESULT_SUCCESS);
73     }
74 
75     @Test
testSetPersistentActivity_throwsExceptionForInvalidDisplayId()76     public void testSetPersistentActivity_throwsExceptionForInvalidDisplayId() {
77         int invalidDisplayId = 999999990;
78 
79         assertThrows(IllegalArgumentException.class,
80                 () -> mCarActivityManager.setPersistentActivity(
81                         mTestActivity, invalidDisplayId, FEATURE_DEFAULT_TASK_CONTAINER));
82     }
83 
84     @Test
testSetPersistentActivity_throwsExceptionForInvalidFeatureId()85     public void testSetPersistentActivity_throwsExceptionForInvalidFeatureId() {
86         int unknownFeatureId = 999999990;
87 
88         assertThrows(IllegalArgumentException.class,
89                 () -> mCarActivityManager.setPersistentActivity(
90                         mTestActivity, Display.DEFAULT_DISPLAY, unknownFeatureId));
91     }
92 
93     @Test
testSetPersistentActivity_throwsExceptionForUnknownActivity()94     public void testSetPersistentActivity_throwsExceptionForUnknownActivity() {
95         // Tries to remove the Activity without registering it.
96         assertThrows(ActivityNotFoundException.class,
97                 () -> mCarActivityManager.setPersistentActivity(
98                         mTestActivity, Display.DEFAULT_DISPLAY, FEATURE_UNDEFINED));
99     }
100 }
101