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.apitest; 17 18 import android.car.Car; 19 import android.car.CarAppFocusManager; 20 import android.car.CarAppFocusManager.OnAppFocusOwnershipCallback; 21 import android.car.navigation.CarNavigationStatusManager; 22 import android.os.Bundle; 23 import android.test.suitebuilder.annotation.MediumTest; 24 import android.util.Log; 25 import com.google.android.collect.Lists; 26 27 /** 28 * Unit tests for {@link CarNavigationStatusManager} 29 */ 30 @MediumTest 31 public class CarNavigationManagerTest extends CarApiTestBase { 32 33 private static final String TAG = CarNavigationManagerTest.class.getSimpleName(); 34 35 private CarNavigationStatusManager mCarNavigationManager; 36 private CarAppFocusManager mCarAppFocusManager; 37 38 @Override 39 protected void setUp() throws Exception { 40 super.setUp(); 41 mCarNavigationManager = 42 (CarNavigationStatusManager) getCar().getCarManager(Car.CAR_NAVIGATION_SERVICE); 43 mCarAppFocusManager = 44 (CarAppFocusManager) getCar().getCarManager(Car.APP_FOCUS_SERVICE); 45 assertNotNull(mCarAppFocusManager); 46 } 47 48 public void testStart() throws Exception { 49 if (mCarNavigationManager == null) { 50 Log.w(TAG, "Unable to run the test: " 51 + "car navigation manager was not created succesfully."); 52 return; 53 } 54 55 try { 56 mCarNavigationManager.sendNavigationStatus(1); 57 fail(); 58 } catch (IllegalStateException expected) { 59 // Expected. Client should acquire focus ownership for APP_FOCUS_TYPE_NAVIGATION. 60 } 61 62 mCarAppFocusManager.addFocusListener(new CarAppFocusManager.OnAppFocusChangedListener() { 63 @Override 64 public void onAppFocusChanged(int appType, boolean active) { 65 // Nothing to do here. 66 } 67 }, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION); 68 OnAppFocusOwnershipCallback ownershipCallback = new OnAppFocusOwnershipCallback() { 69 @Override 70 public void onAppFocusOwnershipLost(int focus) { 71 // Nothing to do here. 72 } 73 74 @Override 75 public void onAppFocusOwnershipGranted(int focus) { 76 // Nothing to do here. 77 } 78 }; 79 mCarAppFocusManager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION, 80 ownershipCallback); 81 assertTrue(mCarAppFocusManager.isOwningFocus(ownershipCallback, 82 CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION)); 83 84 Log.i(TAG, "Instrument cluster: " + mCarNavigationManager.getInstrumentClusterInfo()); 85 86 // TODO: we should use mocked HAL to be able to verify this, right now just make sure that 87 // it is not crashing and logcat has appropriate traces. 88 mCarNavigationManager.sendNavigationStatus(1); 89 90 Bundle bundle = new Bundle(); 91 bundle.putInt("BUNDLE_INTEGER_VALUE", 1234); 92 bundle.putFloat("BUNDLE_FLOAT_VALUE", 12.3456f); 93 bundle.putStringArrayList("BUNDLE_ARRAY_OF_STRINGS", 94 Lists.newArrayList("Value A", "Value B", "Value Z")); 95 96 mCarNavigationManager.sendEvent 97 (CarNavigationStatusManager.EVENT_TYPE_NEXT_MANEUVER_INFO, bundle); 98 } 99 } 100