17a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev/* 27a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * Copyright (C) 2016 The Android Open Source Project 37a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * 47a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * Licensed under the Apache License, Version 2.0 (the "License"); 57a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * you may not use this file except in compliance with the License. 67a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * You may obtain a copy of the License at 77a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * 87a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * http://www.apache.org/licenses/LICENSE-2.0 97a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * 107a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * Unless required by applicable law or agreed to in writing, software 117a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * distributed under the License is distributed on an "AS IS" BASIS, 127a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 137a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * See the License for the specific language governing permissions and 147a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * limitations under the License. 157a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev */ 16e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Parkpackage android.car.navigation; 177a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 18e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Parkimport android.car.CarApiUtil; 19e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Parkimport android.car.CarLibLog; 20e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Parkimport android.car.CarManagerBase; 21e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Parkimport android.car.CarNotConnectedException; 220477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsevimport android.car.cluster.renderer.IInstrumentClusterNavigation; 231fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsevimport android.os.Bundle; 24e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Parkimport android.os.IBinder; 257a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport android.os.RemoteException; 267a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsevimport android.util.Log; 27a928f13d7e41030331afaad33ee62e3772d96541Pavel Maltsev 287a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev/** 297a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * API for providing navigation status for instrument cluster. 307a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev */ 313388e7848f3a30029935463afafe9b8280939127Keun-young Parkpublic final class CarNavigationStatusManager implements CarManagerBase { 32e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Park private static final String TAG = CarLibLog.TAG_NAV; 33e54ac276796c6535558f8444d882adecd19ce2bdKeun-young Park 340477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsev private final IInstrumentClusterNavigation mService; 350477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsev 367a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** 377a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * Only for CarServiceLoader 387a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev * @hide 397a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev */ 403388e7848f3a30029935463afafe9b8280939127Keun-young Park public CarNavigationStatusManager(IBinder service) { 410477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsev mService = IInstrumentClusterNavigation.Stub.asInterface(service); 427a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 437a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 447a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev /** 451fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev * Sends events from navigation app to instrument cluster. 461fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev * 478099f2f6eb3348d2fbb79eb411b2a23514d53488Dean Harding * <p>The event type and bundle can be populated by 488099f2f6eb3348d2fbb79eb411b2a23514d53488Dean Harding * {@link android.support.car.navigation.CarNavigationStatusEvent}. 498099f2f6eb3348d2fbb79eb411b2a23514d53488Dean Harding * 501fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev * @param eventType event type 511fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev * @param bundle object that holds data about the event 521fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev * @throws CarNotConnectedException if the connection to the car service has been lost. 531fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev */ 541fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev public void sendEvent(int eventType, Bundle bundle) throws CarNotConnectedException { 551fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev try { 561fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev mService.onEvent(eventType, bundle); 571fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev } catch (IllegalStateException e) { 581fd2ff63ed701ccc8d2f86d6285e09410eedb411Pavel Maltsev CarApiUtil.checkCarNotConnectedExceptionFromCarService(e); 597a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } catch (RemoteException e) { 607a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev handleCarServiceRemoteExceptionAndThrow(e); 617a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 627a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 637a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 648099f2f6eb3348d2fbb79eb411b2a23514d53488Dean Harding /** @hide */ 657a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev @Override 668099f2f6eb3348d2fbb79eb411b2a23514d53488Dean Harding public void onCarDisconnected() {} 677a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 680477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsev /** Returns navigation features of instrument cluster */ 690477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsev public CarNavigationInstrumentCluster getInstrumentClusterInfo() 707a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev throws CarNotConnectedException { 717a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev try { 720477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsev return mService.getInstrumentClusterInfo(); 737a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } catch (RemoteException e) { 740477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsev handleCarServiceRemoteExceptionAndThrow(e); 757a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 760477e29bb17ee8ec99acfa5fa966889cd45ebf34Pavel Maltsev return null; 777a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 787a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 797a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private void handleCarServiceRemoteExceptionAndThrow(RemoteException e) 807a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev throws CarNotConnectedException { 817a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev handleCarServiceRemoteException(e); 827a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev throw new CarNotConnectedException(); 837a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 847a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev 857a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev private void handleCarServiceRemoteException(RemoteException e) { 867a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev Log.w(TAG, "RemoteException from car service:" + e.getMessage()); 877a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev // nothing to do for now 887a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev } 897a948e54331cccf96f178ab426cb7810472c2dc8Pavel Maltsev} 90