blob: ba25b1659bd22a485a1eb48632b8b91cd850b11d [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
19import android.app.ActivityManager;
Suprabh Shukla09a88f52015-12-02 14:36:31 -080020import android.app.IActivityManager;
21import android.os.ServiceManager;
22import android.os.UserHandle;
23import android.os.RemoteException;
24import android.test.AndroidTestCase;
25
26import java.util.List;
27
28public class ActivityManagerTest extends AndroidTestCase {
29
30 IActivityManager service;
31 @Override
32 public void setUp() throws Exception {
33 super.setUp();
Sudheer Shankadc589ac2016-11-10 15:30:17 -080034 service = ActivityManager.getService();
Suprabh Shukla09a88f52015-12-02 14:36:31 -080035 }
36
37 public void testTaskIdsForRunningUsers() throws RemoteException {
38 for(int userId : service.getRunningUserIds()) {
39 testTaskIdsForUser(userId);
40 }
41 }
42
43 private void testTaskIdsForUser(int userId) throws RemoteException {
44 List<ActivityManager.RecentTaskInfo> recentTasks = service.getRecentTasks(
Jeff Sharkey479212c2016-06-29 16:00:55 -060045 100, 0, userId).getList();
Suprabh Shukla09a88f52015-12-02 14:36:31 -080046 if(recentTasks != null) {
47 for(ActivityManager.RecentTaskInfo recentTask : recentTasks) {
48 int taskId = recentTask.persistentId;
49 assertEquals("The task id " + taskId + " should not belong to user " + userId,
50 taskId / UserHandle.PER_USER_RANGE, userId);
51 }
52 }
53 }
Sudheer Shankadc589ac2016-11-10 15:30:17 -080054}