ActivityManagerTest.java revision dc589ac82b5fe2063f4cfd94c8ae26d43d5420a0
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
17package com.android.server.am;
18
19import android.app.ActivityManager;
20import 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();
34        service = ActivityManager.getService();
35    }
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(
45                100, 0, userId).getList();
46        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    }
54}
55