1 /* 2 * Copyright (C) 2023 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.app; 18 19 import static com.android.car.internal.util.VersionUtils.assertPlatformVersionAtLeastU; 20 21 import android.annotation.NonNull; 22 import android.annotation.SystemApi; 23 import android.app.ActivityManager; 24 import android.car.annotation.ApiRequirements; 25 import android.graphics.Rect; 26 import android.os.RemoteException; 27 import android.view.SurfaceControl; 28 29 /** 30 * Represents the client part of the task view as seen by the server. This wraps the AIDL based 31 * communication with the client apps. 32 * 33 * @hide 34 */ 35 @SystemApi 36 public final class CarTaskViewClient { 37 private final ICarTaskViewClient mICarTaskViewClient; 38 CarTaskViewClient(ICarTaskViewClient iCarCarTaskViewClient)39 CarTaskViewClient(ICarTaskViewClient iCarCarTaskViewClient) { 40 mICarTaskViewClient = iCarCarTaskViewClient; 41 } 42 43 /** Returns the current bounds (in pixels) on screen for the task view's view part. */ 44 @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0, 45 minPlatformVersion = ApiRequirements.PlatformVersion.UPSIDE_DOWN_CAKE_0) 46 @NonNull getCurrentBoundsOnScreen()47 public Rect getCurrentBoundsOnScreen() { 48 assertPlatformVersionAtLeastU(); 49 try { 50 return mICarTaskViewClient.getCurrentBoundsOnScreen(); 51 } catch (RemoteException ex) { 52 ex.rethrowFromSystemServer(); 53 } 54 return null; // cannot reach here. This is just to satisfy compiler. 55 } 56 57 /** 58 * Sets the resize background color on the task view's view part. 59 * 60 * <p>See {@link android.view.SurfaceView#setResizeBackgroundColor(SurfaceControl.Transaction, 61 * int)} 62 */ 63 @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0, 64 minPlatformVersion = ApiRequirements.PlatformVersion.UPSIDE_DOWN_CAKE_0) setResizeBackgroundColor(@onNull SurfaceControl.Transaction transaction, int color)65 public void setResizeBackgroundColor(@NonNull SurfaceControl.Transaction transaction, 66 int color) { 67 assertPlatformVersionAtLeastU(); 68 try { 69 mICarTaskViewClient.setResizeBackgroundColor(transaction, color); 70 } catch (RemoteException ex) { 71 ex.rethrowFromSystemServer(); 72 } 73 } 74 75 /** Called when a task has appeared on the TaskView. */ 76 @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0, 77 minPlatformVersion = ApiRequirements.PlatformVersion.UPSIDE_DOWN_CAKE_0) onTaskAppeared(@onNull ActivityManager.RunningTaskInfo taskInfo, @NonNull SurfaceControl leash)78 public void onTaskAppeared(@NonNull ActivityManager.RunningTaskInfo taskInfo, 79 @NonNull SurfaceControl leash) { 80 assertPlatformVersionAtLeastU(); 81 try { 82 mICarTaskViewClient.onTaskAppeared(taskInfo, leash); 83 } catch (RemoteException ex) { 84 ex.rethrowFromSystemServer(); 85 } 86 } 87 88 /** Called when a task has vanished from the TaskView. */ 89 @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0, 90 minPlatformVersion = ApiRequirements.PlatformVersion.UPSIDE_DOWN_CAKE_0) onTaskVanished(@onNull ActivityManager.RunningTaskInfo taskInfo)91 public void onTaskVanished(@NonNull ActivityManager.RunningTaskInfo taskInfo) { 92 assertPlatformVersionAtLeastU(); 93 try { 94 mICarTaskViewClient.onTaskVanished(taskInfo); 95 } catch (RemoteException ex) { 96 ex.rethrowFromSystemServer(); 97 } 98 } 99 100 /** Called when the task in the TaskView is changed. */ 101 @ApiRequirements(minCarVersion = ApiRequirements.CarVersion.UPSIDE_DOWN_CAKE_0, 102 minPlatformVersion = ApiRequirements.PlatformVersion.UPSIDE_DOWN_CAKE_0) onTaskInfoChanged(@onNull ActivityManager.RunningTaskInfo taskInfo)103 public void onTaskInfoChanged(@NonNull ActivityManager.RunningTaskInfo taskInfo) { 104 assertPlatformVersionAtLeastU(); 105 try { 106 mICarTaskViewClient.onTaskInfoChanged(taskInfo); 107 } catch (RemoteException ex) { 108 ex.rethrowFromSystemServer(); 109 } 110 } 111 } 112