Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.am; |
| 18 | |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 19 | import static com.google.common.truth.Truth.assertThat; |
| 20 | |
| 21 | import static org.junit.Assert.assertEquals; |
| 22 | |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 24 | import android.app.ActivityManager.RecentTaskInfo; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 25 | import android.app.IActivityManager; |
Beverly Tai | 1965af2 | 2018-10-18 14:20:26 +0000 | [diff] [blame] | 26 | import android.os.RemoteException; |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 27 | import android.os.UserHandle; |
| 28 | import android.platform.test.annotations.Presubmit; |
| 29 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 30 | import androidx.test.filters.FlakyTest; |
| 31 | |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 32 | import org.junit.Before; |
| 33 | import org.junit.Test; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 34 | |
| 35 | import java.util.List; |
| 36 | |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 37 | /** |
| 38 | * Tests for {@link ActivityManager}. |
| 39 | * |
| 40 | * Build/Install/Run: |
Tadashi G. Takaoka | d3eb645 | 2018-11-03 18:21:40 -0700 | [diff] [blame] | 41 | * atest FrameworksServicesTests:ActivityManagerTest |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 42 | */ |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 43 | @FlakyTest(detail = "Promote to presubmit if stable") |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 44 | @Presubmit |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 45 | public class ActivityManagerTest { |
| 46 | |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 47 | private IActivityManager mService; |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 48 | |
| 49 | @Before |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 50 | public void setUp() throws Exception { |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 51 | mService = ActivityManager.getService(); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 52 | } |
| 53 | |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 54 | @Test |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 55 | public void testTaskIdsForRunningUsers() throws RemoteException { |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 56 | int[] runningUserIds = mService.getRunningUserIds(); |
Tadashi G. Takaoka | 4554207 | 2018-10-18 23:15:03 +0000 | [diff] [blame] | 57 | assertThat(runningUserIds).isNotEmpty(); |
| 58 | for (int userId : runningUserIds) { |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 59 | testTaskIdsForUser(userId); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | private void testTaskIdsForUser(int userId) throws RemoteException { |
Tadashi G. Takaoka | 74ccec2 | 2018-10-23 11:07:13 +0900 | [diff] [blame] | 64 | List<?> recentTasks = mService.getRecentTasks(100, 0, userId).getList(); |
Tadashi G. Takaoka | 7bd1943 | 2018-10-19 23:15:08 +0900 | [diff] [blame] | 65 | 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 Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 73 | } |
| 74 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 75 | } |