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      * @throws IllegalStateException if the client is not holding
66      *                 {@link android.car.CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION} focus.
67      */
68     @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER)
sendNavigationStateChange(Bundle bundle)69     public void sendNavigationStateChange(Bundle bundle) {
70         try {
71             mService.onNavigationStateChanged(bundle);
72         } catch (RemoteException e) {
73             handleRemoteExceptionFromCarService(e);
74         }
75     }
76 
77     /** @hide */
78     @Override
onCarDisconnected()79     public void onCarDisconnected() {
80     }
81 
82     /** Returns navigation features of instrument cluster */
83     @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER)
getInstrumentClusterInfo()84     public CarNavigationInstrumentCluster getInstrumentClusterInfo() {
85         try {
86             return mService.getInstrumentClusterInfo();
87         } catch (RemoteException e) {
88             return handleRemoteExceptionFromCarService(e, null);
89         }
90     }
91 }
92