blob: c42ea5e42a250c51c59eec1573f1dc7006cfffbb [file] [log] [blame]
Pavel Maltsev8cf86912016-04-01 18:01:51 -07001/*
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 */
16package android.car.cluster.loggingrenderer;
17
Pavel Maltsev0477e292016-05-27 12:22:36 -070018import android.car.cluster.renderer.InstrumentClusterRenderingService;
Pavel Maltsev8cf86912016-04-01 18:01:51 -070019import android.car.cluster.renderer.NavigationRenderer;
20import android.car.navigation.CarNavigationInstrumentCluster;
Roberto Perez2c01f642018-09-19 17:55:52 -070021import android.content.Intent;
Pavel Maltsev1fd2ff62017-07-05 19:09:07 -070022import android.os.Bundle;
Roberto Perez2c01f642018-09-19 17:55:52 -070023import android.os.UserHandle;
Pavel Maltsev8cf86912016-04-01 18:01:51 -070024import android.util.Log;
Roberto Perez2c01f642018-09-19 17:55:52 -070025
26import androidx.car.cluster.navigation.NavigationState;
27import androidx.versionedparcelable.ParcelUtils;
28
Pavel Maltsev1fd2ff62017-07-05 19:09:07 -070029import com.google.android.collect.Lists;
Pavel Maltsev8cf86912016-04-01 18:01:51 -070030
31/**
Pavel Maltsev0477e292016-05-27 12:22:36 -070032 * Dummy implementation of {@link LoggingClusterRenderingService} to log all interaction.
Pavel Maltsev8cf86912016-04-01 18:01:51 -070033 */
Pavel Maltsev0477e292016-05-27 12:22:36 -070034public class LoggingClusterRenderingService extends InstrumentClusterRenderingService {
Pavel Maltsev0477e292016-05-27 12:22:36 -070035 private static final String TAG = LoggingClusterRenderingService.class.getSimpleName();
Roberto Perez2c01f642018-09-19 17:55:52 -070036 private static final String NAV_STATE_BUNDLE_KEY = "navstate";
37 private static final int NAV_STATE_EVENT_ID = 1;
Pavel Maltsev8cf86912016-04-01 18:01:51 -070038
39 @Override
Roberto Perez7b494e32018-12-19 18:19:28 -080040 public NavigationRenderer getNavigationRenderer() {
Pavel Maltsev8cf86912016-04-01 18:01:51 -070041 NavigationRenderer navigationRenderer = new NavigationRenderer() {
42 @Override
43 public CarNavigationInstrumentCluster getNavigationProperties() {
44 Log.i(TAG, "getNavigationProperties");
45 CarNavigationInstrumentCluster config =
46 CarNavigationInstrumentCluster.createCluster(1000);
Pavel Maltsev1fd2ff62017-07-05 19:09:07 -070047 config.getExtra().putIntegerArrayList("dummy", Lists.newArrayList(1, 2, 3, 4));
Pavel Maltsev8cf86912016-04-01 18:01:51 -070048 Log.i(TAG, "getNavigationProperties, returns: " + config);
49 return config;
50 }
51
Pavel Maltsev1fd2ff62017-07-05 19:09:07 -070052 @Override
53 public void onEvent(int eventType, Bundle bundle) {
Roberto Perez2c01f642018-09-19 17:55:52 -070054 StringBuilder bundleSummary = new StringBuilder();
55 if (eventType == NAV_STATE_EVENT_ID) {
56 bundle.setClassLoader(ParcelUtils.class.getClassLoader());
57 NavigationState navState = NavigationState
58 .fromParcelable(bundle.getParcelable(NAV_STATE_BUNDLE_KEY));
59 bundleSummary.append(navState.toString());
60
61 // Sending broadcast for testing.
62 Intent intent = new Intent("android.car.cluster.NAVIGATION_STATE_UPDATE");
63 intent.putExtra(NAV_STATE_BUNDLE_KEY, bundle);
64 sendBroadcastAsUser(intent, UserHandle.ALL);
65 } else {
66 for (String key : bundle.keySet()) {
67 bundleSummary.append(key);
68 bundleSummary.append("=");
69 bundleSummary.append(bundle.get(key));
70 bundleSummary.append(" ");
71 }
72 }
73 Log.i(TAG, "onEvent(" + eventType + ", " + bundleSummary + ")");
Pavel Maltsev1fd2ff62017-07-05 19:09:07 -070074 }
Pavel Maltsev8cf86912016-04-01 18:01:51 -070075 };
76
77 Log.i(TAG, "createNavigationRenderer, returns: " + navigationRenderer);
78 return navigationRenderer;
79 }
80}