vadimt | 252d012 | 2019-12-19 18:27:36 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.launcher3.testing; |
| 18 | |
| 19 | import android.util.Log; |
vadimt | d633c9c | 2020-01-22 18:00:37 -0800 | [diff] [blame] | 20 | import android.view.MotionEvent; |
vadimt | 252d012 | 2019-12-19 18:27:36 -0800 | [diff] [blame] | 21 | |
| 22 | import com.android.launcher3.Utilities; |
| 23 | |
vadimt | a17a10c | 2020-06-19 15:00:00 -0700 | [diff] [blame] | 24 | import java.util.function.BiConsumer; |
| 25 | |
vadimt | 252d012 | 2019-12-19 18:27:36 -0800 | [diff] [blame] | 26 | public final class TestLogging { |
vadimt | a17a10c | 2020-06-19 15:00:00 -0700 | [diff] [blame] | 27 | private static BiConsumer<String, String> sEventConsumer; |
| 28 | |
vadimt | d633c9c | 2020-01-22 18:00:37 -0800 | [diff] [blame] | 29 | private static void recordEventSlow(String sequence, String event) { |
| 30 | Log.d(TestProtocol.TAPL_EVENTS_TAG, sequence + " / " + event); |
vadimt | a17a10c | 2020-06-19 15:00:00 -0700 | [diff] [blame] | 31 | final BiConsumer<String, String> eventConsumer = sEventConsumer; |
| 32 | if (eventConsumer != null) { |
| 33 | eventConsumer.accept(sequence, event); |
| 34 | } |
vadimt | d633c9c | 2020-01-22 18:00:37 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | public static void recordEvent(String sequence, String event) { |
vadimt | 252d012 | 2019-12-19 18:27:36 -0800 | [diff] [blame] | 38 | if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { |
vadimt | d633c9c | 2020-01-22 18:00:37 -0800 | [diff] [blame] | 39 | 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); |
vadimt | 252d012 | 2019-12-19 18:27:36 -0800 | [diff] [blame] | 52 | } |
| 53 | } |
vadimt | a17a10c | 2020-06-19 15:00:00 -0700 | [diff] [blame] | 54 | |
| 55 | static void setEventConsumer(BiConsumer<String, String> consumer) { |
| 56 | sEventConsumer = consumer; |
| 57 | } |
vadimt | 252d012 | 2019-12-19 18:27:36 -0800 | [diff] [blame] | 58 | } |