1 /* 2 * Copyright (C) 2022 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 android.car.builtin.app; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.app.TaskInfo; 23 import android.graphics.Rect; 24 import android.os.IBinder; 25 26 /** 27 * Provides the access to the hidden fields of {@code android.app.TaskInfo}. 28 * @hide 29 */ 30 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 31 public class TaskInfoHelper { 32 33 /** Gets the id of the display this task is associated with. */ getDisplayId(@onNull TaskInfo task)34 public static int getDisplayId(@NonNull TaskInfo task) { 35 return task.displayId; 36 } 37 38 /** Gets the id of the user the task was running as if this is a leaf task. */ getUserId(@onNull TaskInfo task)39 public static int getUserId(@NonNull TaskInfo task) { 40 return task.userId; 41 } 42 43 /** Returns whether the task is actually visible or not */ isVisible(@onNull TaskInfo task)44 public static boolean isVisible(@NonNull TaskInfo task) { 45 return task.isVisible && task.isRunning && !task.isSleeping; 46 } 47 48 /** Returns the binder token of the task. */ getToken(@onNull TaskInfo task)49 public static IBinder getToken(@NonNull TaskInfo task) { 50 return task.token.asBinder(); 51 } 52 53 /** Returns the string representation of the task */ toString(@ullable TaskInfo task)54 public static String toString(@Nullable TaskInfo task) { 55 if (task == null) { 56 return "null"; 57 } 58 return "TaskInfo{" 59 + "taskId=" + task.taskId 60 + " userId=" + task.userId 61 + " displayId=" + task.displayId 62 + " isFocused=" + task.isFocused 63 + " isVisible=" + task.isVisible 64 + " isRunning=" + task.isRunning 65 + " isSleeping=" + task.isSleeping 66 + " topActivity=" + task.topActivity 67 + " baseIntent=" + task.baseIntent + " baseActivity=" + task.baseActivity 68 + "}"; 69 } 70 71 /** Returns the task bounds */ 72 @NonNull getBounds(@onNull TaskInfo task)73 public static Rect getBounds(@NonNull TaskInfo task) { 74 return task.getConfiguration().windowConfiguration.getBounds(); 75 } 76 TaskInfoHelper()77 private TaskInfoHelper() { 78 throw new UnsupportedOperationException("contains only static members"); 79 } 80 } 81