• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.server.wm;
18 
19 import static android.server.wm.second.Components.TEST_ACTIVITY_WITH_SAME_AFFINITY_DIFFERENT_UID;
20 import static android.server.wm.shareuid.a.Components.TEST_ACTIVITY_WITH_SAME_AFFINITY;
21 import static android.server.wm.shareuid.a.Components.TEST_ACTIVITY_WITH_SAME_AFFINITY_SAME_APP;
22 import static android.server.wm.shareuid.b.Components.TEST_ACTIVITY_WITH_SAME_AFFINITY_SHARE_UID;
23 import static android.view.Display.DEFAULT_DISPLAY;
24 
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotEquals;
27 
28 import android.content.ComponentName;
29 import android.platform.test.annotations.Presubmit;
30 import android.server.wm.annotation.Group3;
31 
32 import org.junit.Test;
33 
34 /**
35  * Build/Install/Run:
36  *     atest CtsWindowManagerDeviceTestCases:ActivityTaskAffinityTests
37  *
38  * Tests if activities with the same taskAffinity can be in the same task.
39  */
40 @Presubmit
41 @Group3
42 public class ActivityTaskAffinityTests extends ActivityManagerTestBase {
43     @Test
testActivitiesWithSameAffinityDifferentAppDifferentUidDifferentTask()44     public void testActivitiesWithSameAffinityDifferentAppDifferentUidDifferentTask() {
45         testActivitiesShouldBeInTheSameTask(
46                 TEST_ACTIVITY_WITH_SAME_AFFINITY,
47                 TEST_ACTIVITY_WITH_SAME_AFFINITY_DIFFERENT_UID,
48                 false /* sameTask */
49         );
50     }
51 
52     @Test
testActivitiesWithSameAffinityUidDifferentAppSameTask()53     public void testActivitiesWithSameAffinityUidDifferentAppSameTask() {
54         testActivitiesShouldBeInTheSameTask(
55                 TEST_ACTIVITY_WITH_SAME_AFFINITY,
56                 TEST_ACTIVITY_WITH_SAME_AFFINITY_SHARE_UID,
57                 true /* sameTask */
58         );
59     }
60 
61     @Test
testActivitiesWithSameAffinitySameAppSameTask()62     public void testActivitiesWithSameAffinitySameAppSameTask() {
63         testActivitiesShouldBeInTheSameTask(
64                 TEST_ACTIVITY_WITH_SAME_AFFINITY,
65                 TEST_ACTIVITY_WITH_SAME_AFFINITY_SAME_APP,
66                 true /* sameTask */
67         );
68     }
69 
testActivitiesShouldBeInTheSameTask(ComponentName activityA, ComponentName activityB, boolean sameTask)70     private void testActivitiesShouldBeInTheSameTask(ComponentName activityA,
71             ComponentName activityB, boolean sameTask) {
72         launchActivity(activityA);
73         waitAndAssertTopResumedActivity(activityA, DEFAULT_DISPLAY,
74                 "Launched activity must be top-resumed.");
75         final int firstAppTaskId = mWmState.getTaskByActivity(activityA).mTaskId;
76 
77         launchActivity(activityB);
78         waitAndAssertTopResumedActivity(activityB, DEFAULT_DISPLAY,
79                 "Launched activity must be top-resumed.");
80         final int secondAppTaskId = mWmState.getTaskByActivity(activityB).mTaskId;
81 
82         if (sameTask) {
83             assertEquals("Activities with same affinity must be in the same task.",
84                     firstAppTaskId, secondAppTaskId);
85         } else {
86             assertNotEquals("Activities with same affinity but different uid must not be"
87                     + " in the same task.", firstAppTaskId, secondAppTaskId);
88         }
89     }
90 }
91