• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.os.IBinder;
20 import android.os.RemoteException;
21 
22 /**
23  * This class wraps the client's {@link CarSystemUIProxy} implementation & facilitates the
24  * communication with {@link ICarSystemUIProxy}.
25  */
26 final class CarSystemUIProxyAidlWrapper extends ICarSystemUIProxy.Stub {
27     private final CarSystemUIProxy mCarSystemUIProxy;
28 
CarSystemUIProxyAidlWrapper(CarSystemUIProxy carSystemUIProxy)29     CarSystemUIProxyAidlWrapper(CarSystemUIProxy carSystemUIProxy) {
30         mCarSystemUIProxy = carSystemUIProxy;
31     }
32 
33     @Override
createControlledCarTaskView(ICarTaskViewClient client)34     public ICarTaskViewHost createControlledCarTaskView(ICarTaskViewClient client) {
35         return createCarTaskView(client);
36     }
37 
38     @Override
createCarTaskView(ICarTaskViewClient client)39     public ICarTaskViewHost createCarTaskView(ICarTaskViewClient client) {
40         CarTaskViewHost carTaskViewHost =
41                 mCarSystemUIProxy.createCarTaskView(new CarTaskViewClient(client));
42 
43         IBinder.DeathRecipient clientDeathRecipient = new IBinder.DeathRecipient() {
44             @Override
45             public void binderDied() {
46                 carTaskViewHost.release();
47                 client.asBinder().unlinkToDeath(this, /* flags= */ 0);
48             }
49         };
50 
51         try {
52             client.asBinder().linkToDeath(clientDeathRecipient, /* flags= */ 0);
53         } catch (RemoteException ex) {
54             throw new IllegalStateException(
55                     "Linking to binder death failed for "
56                             + "ICarTaskViewClient, the System UI might already died");
57         }
58 
59         return new CarTaskViewHostAidlToImplAdapter(carTaskViewHost);
60     }
61 }
62