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