Home | History | Annotate | Download | only in am
      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;
     20 import android.app.ActivityManagerNative;
     21 import android.app.IActivityManager;
     22 import android.os.ServiceManager;
     23 import android.os.UserHandle;
     24 import android.os.RemoteException;
     25 import android.test.AndroidTestCase;
     26 
     27 import java.util.List;
     28 
     29 public class ActivityManagerTest extends AndroidTestCase {
     30 
     31     IActivityManager service;
     32     @Override
     33     public void setUp() throws Exception {
     34         super.setUp();
     35         service = ActivityManagerNative.getDefault();
     36     }
     37 
     38     public void testTaskIdsForRunningUsers() throws RemoteException {
     39         for(int userId : service.getRunningUserIds()) {
     40             testTaskIdsForUser(userId);
     41         }
     42     }
     43 
     44     private void testTaskIdsForUser(int userId) throws RemoteException {
     45         List<ActivityManager.RecentTaskInfo> recentTasks = service.getRecentTasks(
     46                 100, 0, userId).getList();
     47         if(recentTasks != null) {
     48             for(ActivityManager.RecentTaskInfo recentTask : recentTasks) {
     49                 int taskId = recentTask.persistentId;
     50                 assertEquals("The task id " + taskId + " should not belong to user " + userId,
     51                         taskId / UserHandle.PER_USER_RANGE, userId);
     52             }
     53         }
     54     }
     55 }