Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 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.loggingrenderer; |
| 17 | |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 18 | import android.car.cluster.renderer.InstrumentClusterRenderingService; |
Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 19 | import android.car.cluster.renderer.NavigationRenderer; |
| 20 | import android.car.navigation.CarNavigationInstrumentCluster; |
Roberto Perez | 2c01f64 | 2018-09-19 17:55:52 -0700 | [diff] [blame] | 21 | import android.content.Intent; |
Pavel Maltsev | 1fd2ff6 | 2017-07-05 19:09:07 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Roberto Perez | 2c01f64 | 2018-09-19 17:55:52 -0700 | [diff] [blame] | 23 | import android.os.UserHandle; |
Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 24 | import android.util.Log; |
Roberto Perez | 2c01f64 | 2018-09-19 17:55:52 -0700 | [diff] [blame] | 25 | |
| 26 | import androidx.car.cluster.navigation.NavigationState; |
| 27 | import androidx.versionedparcelable.ParcelUtils; |
| 28 | |
Pavel Maltsev | 1fd2ff6 | 2017-07-05 19:09:07 -0700 | [diff] [blame] | 29 | import com.google.android.collect.Lists; |
Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 32 | * Dummy implementation of {@link LoggingClusterRenderingService} to log all interaction. |
Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 33 | */ |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 34 | public class LoggingClusterRenderingService extends InstrumentClusterRenderingService { |
Pavel Maltsev | 0477e29 | 2016-05-27 12:22:36 -0700 | [diff] [blame] | 35 | private static final String TAG = LoggingClusterRenderingService.class.getSimpleName(); |
Roberto Perez | 2c01f64 | 2018-09-19 17:55:52 -0700 | [diff] [blame] | 36 | private static final String NAV_STATE_BUNDLE_KEY = "navstate"; |
| 37 | private static final int NAV_STATE_EVENT_ID = 1; |
Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 38 | |
| 39 | @Override |
Roberto Perez | 7b494e3 | 2018-12-19 18:19:28 -0800 | [diff] [blame^] | 40 | public NavigationRenderer getNavigationRenderer() { |
Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 41 | NavigationRenderer navigationRenderer = new NavigationRenderer() { |
| 42 | @Override |
| 43 | public CarNavigationInstrumentCluster getNavigationProperties() { |
| 44 | Log.i(TAG, "getNavigationProperties"); |
| 45 | CarNavigationInstrumentCluster config = |
| 46 | CarNavigationInstrumentCluster.createCluster(1000); |
Pavel Maltsev | 1fd2ff6 | 2017-07-05 19:09:07 -0700 | [diff] [blame] | 47 | config.getExtra().putIntegerArrayList("dummy", Lists.newArrayList(1, 2, 3, 4)); |
Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 48 | Log.i(TAG, "getNavigationProperties, returns: " + config); |
| 49 | return config; |
| 50 | } |
| 51 | |
Pavel Maltsev | 1fd2ff6 | 2017-07-05 19:09:07 -0700 | [diff] [blame] | 52 | @Override |
| 53 | public void onEvent(int eventType, Bundle bundle) { |
Roberto Perez | 2c01f64 | 2018-09-19 17:55:52 -0700 | [diff] [blame] | 54 | 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 Maltsev | 1fd2ff6 | 2017-07-05 19:09:07 -0700 | [diff] [blame] | 74 | } |
Pavel Maltsev | 8cf8691 | 2016-04-01 18:01:51 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | Log.i(TAG, "createNavigationRenderer, returns: " + navigationRenderer); |
| 78 | return navigationRenderer; |
| 79 | } |
| 80 | } |