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 */
16package com.android.contacts.logging;
17
18import android.app.Activity;
19
20import com.android.contacts.logging.ScreenEvent.ScreenType;
21import com.android.contactsbind.ObjectFactory;
22
23/**
24 * Logs analytics events.
25 */
26public abstract class Logger {
27    public static final String TAG = "Logger";
28
29    private static Logger getInstance() {
30        return ObjectFactory.getLogger();
31    }
32
33    /**
34     * Logs an event indicating that a screen was displayed.
35     *
36     * @param screenType integer identifier of the displayed screen
37     * @param activity Parent activity of the displayed screen.
38     */
39    public static void logScreenView(Activity activity, int screenType) {
40        logScreenView(activity, screenType, ScreenType.UNKNOWN);
41    }
42
43    /**
44     * @param previousScreenType integer identifier of the displayed screen the user came from.
45     */
46    public static void logScreenView(Activity activity, int screenType, int previousScreenType) {
47        final Logger logger = getInstance();
48        if (logger != null) {
49            logger.logScreenViewImpl(screenType, previousScreenType);
50        }
51    }
52
53    /**
54     * Logs the results of a user search for a particular contact.
55     */
56    public static void logSearchEvent(SearchState searchState) {
57        final Logger logger = getInstance();
58        if (logger != null) {
59            logger.logSearchEventImpl(searchState);
60        }
61    }
62
63    /**
64     * Logs how users view and use a contacts list. See {@link ListEvent} for definition of
65     * parameters.
66     */
67    public static void logListEvent(int actionType, int listType, int count, int clickedIndex,
68            int numSelected) {
69        final ListEvent event = new ListEvent();
70        event.actionType = actionType;
71        event.listType = listType;
72        event.count = count;
73        event.clickedIndex = clickedIndex;
74        event.numSelected = numSelected;
75
76        final Logger logger = getInstance();
77        if (logger != null) {
78            logger.logListEventImpl(event);
79        }
80    }
81
82    /**
83     * Logs an event on QuickContact. See {@link QuickContactEvent} for definition of parameters.
84     */
85    public static void logQuickContactEvent(String referrer, int contactType, int cardType,
86            int actionType, String thirdPartyAction) {
87        final Logger logger = getInstance();
88        if (logger != null) {
89            final QuickContactEvent event = new QuickContactEvent();
90            event.referrer = referrer == null ? "Unknown" : referrer;
91            event.contactType = contactType;
92            event.cardType = cardType;
93            event.actionType = actionType;
94            event.thirdPartyAction = thirdPartyAction == null ? "" : thirdPartyAction;
95            logger.logQuickContactEventImpl(event);
96        }
97    }
98
99    public static void logEditorEvent(int eventType, int numberRawContacts) {
100        final Logger logger = getInstance();
101        if (logger != null) {
102            final EditorEvent event = new EditorEvent();
103            event.eventType = eventType;
104            event.numberRawContacts = numberRawContacts;
105            logger.logEditorEventImpl(event);
106        }
107    }
108
109    public abstract void logScreenViewImpl(int screenType, int previousScreenType);
110    public abstract void logSearchEventImpl(SearchState searchState);
111    public abstract void logListEventImpl(ListEvent event);
112    public abstract void logQuickContactEventImpl(QuickContactEvent event);
113    public abstract void logEditorEventImpl(EditorEvent event);
114}
115