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.annotation.AddedInOrBefore; 24 import android.car.cluster.renderer.IInstrumentClusterNavigation; 25 import android.os.Bundle; 26 import android.os.IBinder; 27 import android.os.RemoteException; 28 29 /** 30 * API for providing navigation status for instrument cluster. 31 * @hide 32 */ 33 @SystemApi 34 public final class CarNavigationStatusManager extends CarManagerBase { 35 private static final String TAG = CarLibLog.TAG_NAV; 36 37 private final IInstrumentClusterNavigation mService; 38 39 /** 40 * Only for CarServiceLoader 41 * @hide 42 */ CarNavigationStatusManager(Car car, IBinder service)43 public CarNavigationStatusManager(Car car, IBinder service) { 44 super(car); 45 mService = IInstrumentClusterNavigation.Stub.asInterface(service); 46 } 47 48 /** 49 * Sends events from navigation app to instrument cluster. 50 * 51 * @deprecated use {@link #sendEvent(Bundle)} instead. 52 */ 53 @Deprecated 54 @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER) 55 @AddedInOrBefore(majorVersion = 33) sendEvent(int eventType, Bundle bundle)56 public void sendEvent(int eventType, Bundle bundle) { 57 sendNavigationStateChange(bundle); 58 } 59 60 /** 61 * Sends events from navigation app to instrument cluster. 62 * 63 * @param bundle object holding data about the navigation event. This information is 64 * generated using <a href="https://developer.android.com/reference/androidx/car/cluster/navigation/NavigationState.html#toParcelable()"> 65 * androidx.car.cluster.navigation.NavigationState#toParcelable()</a> 66 * 67 * @throws IllegalStateException if the client is not holding 68 * {@link android.car.CarAppFocusManager#APP_FOCUS_TYPE_NAVIGATION} focus. 69 * @throws IllegalArgumentException if {@code bundle} is null, if it cannot be parsed or if the 70 * {@link android.car.cluster.navigation.NavigationState.NavigationStateProto} 71 * generated after parsing is not valid. This object is not valid if it contains 72 * a {@link android.car.cluster.navigation.NavigationState.Maneuver} where 73 * Maneuver#typeV2 is populated but Maneuver#type is not. 74 */ 75 @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER) 76 @AddedInOrBefore(majorVersion = 33) sendNavigationStateChange(Bundle bundle)77 public void sendNavigationStateChange(Bundle bundle) { 78 try { 79 mService.onNavigationStateChanged(bundle); 80 } catch (RemoteException e) { 81 handleRemoteExceptionFromCarService(e); 82 } 83 } 84 85 /** @hide */ 86 @Override 87 @AddedInOrBefore(majorVersion = 33) onCarDisconnected()88 public void onCarDisconnected() { 89 } 90 91 /** Returns navigation features of instrument cluster */ 92 @RequiresPermission(Car.PERMISSION_CAR_NAVIGATION_MANAGER) 93 @AddedInOrBefore(majorVersion = 33) getInstrumentClusterInfo()94 public CarNavigationInstrumentCluster getInstrumentClusterInfo() { 95 try { 96 return mService.getInstrumentClusterInfo(); 97 } catch (RemoteException e) { 98 return handleRemoteExceptionFromCarService(e, null); 99 } 100 } 101 } 102