Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c9ad9b1d authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Add list event clearcut logging (2/3)

- Add screen type for ME, account and group, to log where
  QuickContact is opened.
- Compare absolute position in a list and number of favorites
  in the list, to see if QuickContact is opened from favorites.
- Add mListType to the base list class ContactEntryListFragment
  so that subclasses can get the type of the list.

Bug 28718104

Change-Id: Ie35ea14c37d26e5130c7c258b587eac22989e9e6
parent 867ceebc
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter {
     */
    private boolean mIncludeFavorites;

    private int mNumberOfFavorites;

    /**
     * The root view of the fragment that this adapter is associated with.
     */
@@ -367,10 +369,15 @@ public abstract class ContactEntryListAdapter extends IndexerListAdapter {

    public void setFavoritesSectionHeader(int numberOfFavorites) {
        if (mIncludeFavorites) {
            mNumberOfFavorites = numberOfFavorites;
            setSectionHeader(R.string.star_sign, numberOfFavorites);
        }
    }

    public int getNumberOfFavorites() {
        return mNumberOfFavorites;
    }

    private void setSectionHeader(int resId, int numberOfItems) {
        SectionIndexer indexer = getIndexer();
        if (indexer != null) {
+39 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ import android.widget.ListView;

import com.android.common.widget.CompositeCursorAdapter.Partition;
import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.logging.Logger;
import com.android.contacts.common.logging.ListEvent.ActionType;
import com.android.contacts.common.preference.ContactsPreferences;
import com.android.contacts.common.util.ContactListViewUtils;

@@ -82,6 +84,8 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
    private static final String KEY_DARK_THEME = "darkTheme";
    private static final String KEY_LEGACY_COMPATIBILITY = "legacyCompatibility";
    private static final String KEY_DIRECTORY_RESULT_LIMIT = "directoryResultLimit";
    private static final String KEY_LOGS_LIST_EVENTS = "logsListEvents";
    private static final String KEY_DATA_LOADED = "dataLoaded";

    private static final String DIRECTORY_ID_ARG_KEY = "directoryId";

@@ -105,6 +109,11 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
    private int mDirectorySearchMode = DirectoryListLoader.SEARCH_MODE_NONE;
    private boolean mSelectionVisible;
    private boolean mLegacyCompatibility;
    // Whether we should log list LOAD events. It may be modified when list filter is changed.
    private boolean mLogListEvents = true;
    // Whether data has been loaded ever. It will stay true once it's set to true in the lifecycle.
    // We use this flag to log LOAD events when the activity/fragment is initialized.
    private boolean mDataLoaded;

    private boolean mEnabled = true;

@@ -123,6 +132,11 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
     */
    private Parcelable mListState;

    /**
     * The type of the contacts list.
     */
    private int mListType;

    private int mDisplayOrder;
    private int mSortOrder;
    private int mDirectoryResultLimit = DEFAULT_DIRECTORY_RESULT_LIMIT;
@@ -252,6 +266,8 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
        outState.putString(KEY_QUERY_STRING, mQueryString);
        outState.putInt(KEY_DIRECTORY_RESULT_LIMIT, mDirectoryResultLimit);
        outState.putBoolean(KEY_DARK_THEME, mDarkTheme);
        outState.putBoolean(KEY_LOGS_LIST_EVENTS, mLogListEvents);
        outState.putBoolean(KEY_DATA_LOADED, mDataLoaded);

        if (mListView != null) {
            outState.putParcelable(KEY_LIST_STATE, mListView.onSaveInstanceState());
@@ -432,6 +448,12 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
                    }
                }
            } else {
                if (!mDataLoaded || mLogListEvents) {
                    Logger.logListEvent(ActionType.LOAD, getListType(), getAdapter().getCount(),
                        /* clickedIndex */ -1, /* numSelected */ 0);
                    mLogListEvents = false;
                    mDataLoaded = true;
                }
                mDirectoryListStatus = STATUS_NOT_LOADED;
                getLoaderManager().destroyLoader(DIRECTORY_LOADER_ID);
            }
@@ -725,6 +747,11 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
            mListView.requestFocus();
        }

        if (savedInstanceState != null) {
            mLogListEvents = savedInstanceState.getBoolean(KEY_LOGS_LIST_EVENTS, true);
            mDataLoaded = savedInstanceState.getBoolean(KEY_DATA_LOADED, false);
        }

        return mView;
    }

@@ -931,4 +958,16 @@ public abstract class ContactEntryListFragment<T extends ContactEntryListAdapter
                return View.SCROLLBAR_POSITION_RIGHT;
        }
    }

    public void setListType(int listType) {
        mListType = listType;
    }

    public int getListType() {
        return mListType;
    }

    public void setLogListEvents(boolean logListEvents) {
        mLogListEvents = logListEvents;
    }
}
+82 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.contacts.common.logging;

import com.google.common.base.Objects;

/**
 * Describes how user view and use a list
 */
public final class ListEvent {

    /** The type of action taken by the user. **/
    public int actionType;

    /** The type of list the user is viewing. **/
    public int listType;

    /** The number of contacts in the list. **/
    public int count;

    /** The index of contact clicked by user. **/
    public int clickedIndex = -1;

    /** The number of contact selected when user takes an action (link, delete, share, etc). **/
    public int numSelected;

    // Should match ContactsExtension.ListEvent.ActionType values in
    // http://cs/google3/logs/proto/wireless/android/contacts/contacts_extensions.proto
    public static final class ActionType {
        public static final int UNKNOWN = 0;
        public static final int LOAD = 1;
        public static final int CLICK = 2;
        public static final int SELECT = 3;
        public static final int SHARE = 4;
        public static final int DELETE = 5;
        public static final int LINK = 6;
        public static final int REMOVE_LABEL = 7;

        private ActionType() {
        }
    }

    // Should match ContactsExtension.ListEvent.ListType values in
    // http://cs/google3/logs/proto/wireless/android/contacts/contacts_extensions.proto
    public static final class ListType {
        public static final int UNKNOWN_LIST = 0;
        public static final int ALL_CONTACTS = 1;
        public static final int ACCOUNT = 2;
        public static final int GROUP = 3;
        public static final int SEARCH_RESULT = 4;

        private ListType() {
        }
    }

    public ListEvent() {
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this)
                .add("actionType", actionType)
                .add("listType", listType)
                .add("count", count)
                .add("clickedIndex", clickedIndex)
                .add("numSelected", numSelected)
                .toString();
    }
}
+21 −1
Original line number Diff line number Diff line
@@ -69,6 +69,26 @@ public abstract class Logger {
        }
    }

    /**
     * Logs how users view and use a contacts list. See {@link ListEvent} for definition of
     * parameters.
     */
    public static void logListEvent(int actionType, int listType, int count, int clickedIndex,
            int numSelected) {
        final ListEvent event = new ListEvent();
        event.actionType = actionType;
        event.listType = listType;
        event.count = count;
        event.clickedIndex = clickedIndex;
        event.numSelected = numSelected;

        final Logger logger = getInstance();
        if (logger != null) {
            logger.logListEventImpl(event);
        }
    }

    public abstract void logScreenViewImpl(int screenType, int previousScreenType);
    public abstract void logSearchEventImpl(SearchState searchState);
    public abstract void logListEventImpl(ListEvent event);
}
+6 −0
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ public class ScreenEvent {
        public static final int ALL_CONTACTS = 4;
        public static final int QUICK_CONTACT = 5;
        public static final int EDITOR = 6;
        public static final int LIST_ACCOUNT = 7;
        public static final int LIST_GROUP = 8;
        public static final int ME_CONTACT = 9;

        public static String getFriendlyName(int screenType) {
            switch (screenType) {
@@ -40,6 +43,9 @@ public class ScreenEvent {
                case ALL_CONTACTS: return "AllContacts";
                case QUICK_CONTACT: return "QuickContact";
                case EDITOR: return "Editor";
                case LIST_ACCOUNT: return "ListAccount";
                case LIST_GROUP: return "ListGroup";
                case ME_CONTACT: return "MeContact";
                case UNKNOWN: // fall-through
                default: return null;
            }
Loading