1 /*
2  * Copyright (C) 2016 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 package android.car.navigation;
17 
18 import android.annotation.RequiresPermission;
19 import android.annotation.SystemApi;
20 import android.car.Car;
21 import android.car.CarLibLog;
22 import android.car.CarManagerBase;
23 import android.car.cluster.renderer.IInstrumentClusterNavigation;
24 import android.os.Bundle;
25 import android.os.IBinder;
26 import android.os.RemoteException;
27 
28 /**
29  * API for providing navigation status for instrument cluster.
30  * @hide
31  */
32 @SystemApi
33 public final class CarNavigationStatusManager extends CarManagerBase {
34     private static final String TAG = CarLibLog.TAG_NAV;
35 
36     private final IInstrumentClusterNavigation mService;
37 
38     /**
39      * Only for CarServiceLoader
40      * @hide
41      */
CarNavigationStatusManager(Car car, IBinder service)42     public CarNavigationStatusManager(Car car, IBinder service) {
43         super(car);
44         mService = IInstrumentClusterNavigation.Stub.asInterface(service);
45     }
46 
47     /**
48      * Sends events from navigation app to instrument cluster.
49      *
50      * @deprecated use {@link #sendEvent(Bundle)} instead.
51      */
52     @Deprecated
53     @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER)
sendEvent(int eventType, Bundle bundle)54     public void sendEvent(int eventType, Bundle bundle) {
55         sendNavigationStateChange(bundle);
56     }
57 
58     /**
59      * Sends events from navigation app to instrument cluster.
60      *
61      * @param bundle object holding data about the navigation event. This information is
62      *               generated using <a href="https://developer.android.com/reference/androidx/car/cluster/navigation/NavigationState.html#toParcelable()">
63      *               androidx.car.cluster.navigation.NavigationState#toParcelable()</a>
64      */
65     @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER)
sendNavigationStateChange(Bundle bundle)66     public void sendNavigationStateChange(Bundle bundle) {
67         try {
68             mService.onNavigationStateChanged(bundle);
69         } catch (RemoteException e) {
70             handleRemoteExceptionFromCarService(e);
71         }
72     }
73 
74     /** @hide */
75     @Override
onCarDisconnected()76     public void onCarDisconnected() {
77     }
78 
79     /** Returns navigation features of instrument cluster */
80     @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER)
getInstrumentClusterInfo()81     public CarNavigationInstrumentCluster getInstrumentClusterInfo() {
82         try {
83             return mService.getInstrumentClusterInfo();
84         } catch (RemoteException e) {
85             return handleRemoteExceptionFromCarService(e, null);
86         }
87     }
88 }
89