blob: 8965152257c62d12f9b63ed4c193b9ec8f65aebf [file] [log] [blame]
Suprabh Shukla09a88f52015-12-02 14:36:31 -08001/*
2 * Copyright (C) 2016 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
17package com.android.server.am;
18
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000019import static com.google.common.truth.Truth.assertThat;
20
21import static org.junit.Assert.assertEquals;
22
Suprabh Shukla09a88f52015-12-02 14:36:31 -080023import android.app.ActivityManager;
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000024import android.app.ActivityManager.RecentTaskInfo;
Suprabh Shukla09a88f52015-12-02 14:36:31 -080025import android.app.IActivityManager;
Beverly Tai1965af22018-10-18 14:20:26 +000026import android.os.RemoteException;
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000027import android.os.UserHandle;
28import android.platform.test.annotations.Presubmit;
29
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090030import androidx.test.filters.FlakyTest;
31
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000032import org.junit.Before;
33import org.junit.Test;
Suprabh Shukla09a88f52015-12-02 14:36:31 -080034
35import java.util.List;
36
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000037/**
38 * Tests for {@link ActivityManager}.
39 *
40 * Build/Install/Run:
Tadashi G. Takaokad3eb6452018-11-03 18:21:40 -070041 * atest FrameworksServicesTests:ActivityManagerTest
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000042 */
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000043@FlakyTest(detail = "Promote to presubmit if stable")
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090044@Presubmit
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000045public class ActivityManagerTest {
46
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090047 private IActivityManager mService;
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000048
49 @Before
Suprabh Shukla09a88f52015-12-02 14:36:31 -080050 public void setUp() throws Exception {
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090051 mService = ActivityManager.getService();
Suprabh Shukla09a88f52015-12-02 14:36:31 -080052 }
53
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000054 @Test
Suprabh Shukla09a88f52015-12-02 14:36:31 -080055 public void testTaskIdsForRunningUsers() throws RemoteException {
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090056 int[] runningUserIds = mService.getRunningUserIds();
Tadashi G. Takaoka45542072018-10-18 23:15:03 +000057 assertThat(runningUserIds).isNotEmpty();
58 for (int userId : runningUserIds) {
Suprabh Shukla09a88f52015-12-02 14:36:31 -080059 testTaskIdsForUser(userId);
60 }
61 }
62
63 private void testTaskIdsForUser(int userId) throws RemoteException {
Tadashi G. Takaoka74ccec22018-10-23 11:07:13 +090064 List<?> recentTasks = mService.getRecentTasks(100, 0, userId).getList();
Tadashi G. Takaoka7bd19432018-10-19 23:15:08 +090065 if (recentTasks != null) {
66 for (Object elem : recentTasks) {
67 assertThat(elem).isInstanceOf(RecentTaskInfo.class);
68 RecentTaskInfo recentTask = (RecentTaskInfo) elem;
69 int taskId = recentTask.taskId;
70 assertEquals("The task id " + taskId + " should not belong to user " + userId,
71 taskId / UserHandle.PER_USER_RANGE, userId);
72 }
Suprabh Shukla09a88f52015-12-02 14:36:31 -080073 }
74 }
Sudheer Shankadc589ac2016-11-10 15:30:17 -080075}