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 com.android.server.wm; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.os.IBinder; 23 24 25 /** 26 * Wrapper of {@link Task}. 27 * @hide 28 */ 29 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 30 public final class TaskWrapper { 31 private final Task mTask; 32 TaskWrapper(Task task)33 private TaskWrapper(Task task) { 34 mTask = task; 35 } 36 37 /** @hide */ 38 @Nullable create(@ullable Task task)39 public static TaskWrapper create(@Nullable Task task) { 40 if (task == null) return null; 41 return new TaskWrapper(task); 42 } 43 44 /** Creates an instance of {@link TaskWrapper} based on the task's remote {@code token}. */ 45 @Nullable createFromToken(@onNull IBinder token)46 public static TaskWrapper createFromToken(@NonNull IBinder token) { 47 return create((Task) WindowContainer.fromBinder(token)); 48 } 49 50 /** 51 * Gets the {@code userId} of this {@link Task} is created for 52 */ getUserId()53 public int getUserId() { 54 return mTask.mUserId; 55 } 56 57 /** 58 * Gets the root {@link TaskWrapper} of the this. 59 */ getRootTask()60 public TaskWrapper getRootTask() { 61 return create(mTask.getRootTask()); 62 } 63 64 /** 65 * Gets the {@link TaskDisplayAreaWrapper} this {@link Task} is on. 66 */ getTaskDisplayArea()67 public TaskDisplayAreaWrapper getTaskDisplayArea() { 68 return TaskDisplayAreaWrapper.create(mTask.getTaskDisplayArea()); 69 } 70 71 @Override toString()72 public String toString() { 73 return mTask.toString(); 74 } 75 } 76