• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
20 import android.view.MotionEvent;
21 
22 import com.android.launcher3.Utilities;
23 
24 import java.util.function.BiConsumer;
25 
26 public final class TestLogging {
27     private static BiConsumer<String, String> sEventConsumer;
28 
recordEventSlow(String sequence, String event)29     private static void recordEventSlow(String sequence, String event) {
30         Log.d(TestProtocol.TAPL_EVENTS_TAG, sequence + " / " + event);
31         final BiConsumer<String, String> eventConsumer = sEventConsumer;
32         if (eventConsumer != null) {
33             eventConsumer.accept(sequence, event);
34         }
35     }
36 
recordEvent(String sequence, String event)37     public static void recordEvent(String sequence, String event) {
38         if (Utilities.IS_RUNNING_IN_TEST_HARNESS) {
39             recordEventSlow(sequence, event);
40         }
41     }
42 
recordEvent(String sequence, String message, Object parameter)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 
recordMotionEvent(String sequence, String message, MotionEvent event)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);
52         }
53     }
54 
setEventConsumer(BiConsumer<String, String> consumer)55     static void setEventConsumer(BiConsumer<String, String> consumer) {
56         sEventConsumer = consumer;
57     }
58 }
59