blob: 51e081972f761f0ebca16ffea99d86474886d58d [file] [log] [blame]
vadimt252d0122019-12-19 18:27:36 -08001/*
2 * Copyright (C) 2020 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
17package com.android.launcher3.testing;
18
19import android.util.Log;
vadimtd633c9c2020-01-22 18:00:37 -080020import android.view.MotionEvent;
vadimt252d0122019-12-19 18:27:36 -080021
22import com.android.launcher3.Utilities;
23
vadimta17a10c2020-06-19 15:00:00 -070024import java.util.function.BiConsumer;
25
vadimt252d0122019-12-19 18:27:36 -080026public final class TestLogging {
vadimta17a10c2020-06-19 15:00:00 -070027 private static BiConsumer<String, String> sEventConsumer;
28
vadimtd633c9c2020-01-22 18:00:37 -080029 private static void recordEventSlow(String sequence, String event) {
30 Log.d(TestProtocol.TAPL_EVENTS_TAG, sequence + " / " + event);
vadimta17a10c2020-06-19 15:00:00 -070031 final BiConsumer<String, String> eventConsumer = sEventConsumer;
32 if (eventConsumer != null) {
33 eventConsumer.accept(sequence, event);
34 }
vadimtd633c9c2020-01-22 18:00:37 -080035 }
36
37 public static void recordEvent(String sequence, String event) {
vadimt252d0122019-12-19 18:27:36 -080038 if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
vadimtd633c9c2020-01-22 18:00:37 -080039 recordEventSlow(sequence, event);
40 }
41 }
42
43 public static void recordEvent(String sequence, String message, Object parameter) {
44 if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
45 recordEventSlow(sequence, message + ": " + parameter);
46 }
47 }
48
49 public static void recordMotionEvent(String sequence, String message, MotionEvent event) {
50 if (Utilities.IS_RUNNING_IN_TEST_HARNESS && event.getAction() != MotionEvent.ACTION_MOVE) {
51 recordEventSlow(sequence, message + ": " + event);
vadimt252d0122019-12-19 18:27:36 -080052 }
53 }
vadimta17a10c2020-06-19 15:00:00 -070054
55 static void setEventConsumer(BiConsumer<String, String> consumer) {
56 sEventConsumer = consumer;
57 }
vadimt252d0122019-12-19 18:27:36 -080058}