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      * @throws IllegalArgumentException if {@code bundle} is null, if it cannot be parsed or if the
68      *                 {@link android.car.cluster.navigation.NavigationState.NavigationStateProto}
69      *                 generated after parsing is not valid. This object is not valid if it contains
70      *                 a {@link android.car.cluster.navigation.NavigationState.Maneuver} where
71      *                 Maneuver#typeV2 is populated but Maneuver#type is not.
72      */
73     @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER)
sendNavigationStateChange(Bundle bundle)74     public void sendNavigationStateChange(Bundle bundle) {
75         try {
76             mService.onNavigationStateChanged(bundle);
77         } catch (RemoteException e) {
78             handleRemoteExceptionFromCarService(e);
79         }
80     }
81 
82     /** @hide */
83     @Override
onCarDisconnected()84     public void onCarDisconnected() {
85     }
86 
87     /** Returns navigation features of instrument cluster */
88     @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER)
getInstrumentClusterInfo()89     public CarNavigationInstrumentCluster getInstrumentClusterInfo() {
90         try {
91             return mService.getInstrumentClusterInfo();
92         } catch (RemoteException e) {
93             return handleRemoteExceptionFromCarService(e, null);
94         }
95     }
96 }
97