Home | History | Annotate | Download | only in apitest
      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 testSendEvent() 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         Bundle bundle = new Bundle();
     56         bundle.putInt("BUNDLE_INTEGER_VALUE", 1234);
     57         bundle.putFloat("BUNDLE_FLOAT_VALUE", 12.3456f);
     58         bundle.putStringArrayList("BUNDLE_ARRAY_OF_STRINGS",
     59                 Lists.newArrayList("Value A", "Value B", "Value Z"));
     60 
     61         try {
     62             mCarNavigationManager.sendEvent(1, bundle);
     63             fail();
     64         } catch (IllegalStateException expected) {
     65             // Expected. Client should acquire focus ownership for APP_FOCUS_TYPE_NAVIGATION.
     66         }
     67 
     68         mCarAppFocusManager.addFocusListener(new CarAppFocusManager.OnAppFocusChangedListener() {
     69             @Override
     70             public void onAppFocusChanged(int appType, boolean active) {
     71                 // Nothing to do here.
     72             }
     73         }, CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION);
     74         OnAppFocusOwnershipCallback ownershipCallback = new OnAppFocusOwnershipCallback() {
     75             @Override
     76             public void onAppFocusOwnershipLost(int focus) {
     77                 // Nothing to do here.
     78             }
     79 
     80             @Override
     81             public void onAppFocusOwnershipGranted(int focus) {
     82                 // Nothing to do here.
     83             }
     84         };
     85         mCarAppFocusManager.requestAppFocus(CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION,
     86                 ownershipCallback);
     87         assertTrue(mCarAppFocusManager.isOwningFocus(ownershipCallback,
     88                 CarAppFocusManager.APP_FOCUS_TYPE_NAVIGATION));
     89 
     90         Log.i(TAG, "Instrument cluster: " + mCarNavigationManager.getInstrumentClusterInfo());
     91 
     92         // TODO: we should use mocked HAL to be able to verify this, right now just make sure that
     93         // it is not crashing and logcat has appropriate traces.
     94         mCarNavigationManager.sendEvent(1, bundle);
     95     }
     96 }
     97