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 | |
| 19 | import android.app.ActivityManager; |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 20 | import android.app.IActivityManager; |
| 21 | import android.os.ServiceManager; |
| 22 | import android.os.UserHandle; |
| 23 | import android.os.RemoteException; |
| 24 | import android.test.AndroidTestCase; |
| 25 | |
| 26 | import java.util.List; |
| 27 | |
| 28 | public class ActivityManagerTest extends AndroidTestCase { |
| 29 | |
| 30 | IActivityManager service; |
| 31 | @Override |
| 32 | public void setUp() throws Exception { |
| 33 | super.setUp(); |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 34 | service = ActivityManager.getService(); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 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( |
Jeff Sharkey | 479212c | 2016-06-29 16:00:55 -0600 | [diff] [blame] | 45 | 100, 0, userId).getList(); |
Suprabh Shukla | 09a88f5 | 2015-12-02 14:36:31 -0800 | [diff] [blame] | 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 | } |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 54 | } |