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