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.cluster; 17 18 import android.car.cluster.navigation.NavigationState.NavigationStateProto; 19 import android.car.cluster.renderer.InstrumentClusterRenderingService; 20 import android.car.cluster.renderer.NavigationRenderer; 21 import android.car.navigation.CarNavigationInstrumentCluster; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.os.UserHandle; 25 import android.util.Log; 26 27 import com.google.android.collect.Lists; 28 import com.google.protobuf.InvalidProtocolBufferException; 29 30 /** 31 * Mock implementation of {@link ClusterRenderingService} to log all interaction. 32 */ 33 public class LoggingClusterRenderingService extends InstrumentClusterRenderingService { 34 private static final String TAG = LoggingClusterRenderingService.class.getSimpleName(); 35 private static final String NAV_STATE_PROTO_BUNDLE_KEY = "navstate2"; 36 37 @Override getNavigationRenderer()38 public NavigationRenderer getNavigationRenderer() { 39 NavigationRenderer navigationRenderer = new NavigationRenderer() { 40 @Override 41 public CarNavigationInstrumentCluster getNavigationProperties() { 42 Log.i(TAG, "getNavigationProperties"); 43 CarNavigationInstrumentCluster config = 44 CarNavigationInstrumentCluster.createCluster(1000); 45 config.getExtra().putIntegerArrayList("foo", Lists.newArrayList(1, 2, 3, 4)); 46 Log.i(TAG, "getNavigationProperties, returns: " + config); 47 return config; 48 } 49 50 @Override 51 public void onNavigationStateChanged(Bundle bundle) { 52 StringBuilder bundleSummary = new StringBuilder(); 53 54 // Attempt to read proto byte array 55 byte[] protoBytes = bundle.getByteArray(NAV_STATE_PROTO_BUNDLE_KEY); 56 if (protoBytes != null) { 57 try { 58 NavigationStateProto navState = NavigationStateProto.parseFrom(protoBytes); 59 bundleSummary.append(navState.toString()); 60 61 // Sending broadcast for testing. 62 Intent intent = new Intent( 63 "android.car.cluster.NAVIGATION_STATE_UPDATE"); 64 intent.putExtra(NAV_STATE_PROTO_BUNDLE_KEY, bundle); 65 sendBroadcastAsUser(intent, UserHandle.ALL); 66 } catch (InvalidProtocolBufferException e) { 67 Log.e(TAG, "Error parsing navigation state proto", e); 68 } 69 } else { 70 Log.e(TAG, "Received nav state byte array is null"); 71 } 72 73 Log.i(TAG, "onEvent(" + bundleSummary + ")"); 74 } 75 }; 76 77 Log.i(TAG, "createNavigationRenderer, returns: " + navigationRenderer); 78 return navigationRenderer; 79 } 80 } 81