1 /* 2 * Copyright (C) 2018 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.settings.core.instrumentation; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.util.Pair; 22 23 import com.android.settingslib.core.instrumentation.LogWriter; 24 25 public class StatsLogWriter implements LogWriter { 26 27 @Override visible(Context context, int attribution, int pageId, int latency)28 public void visible(Context context, int attribution, int pageId, int latency) { 29 SettingsStatsLog.write(SettingsStatsLog.SETTINGS_UI_CHANGED /* Atom name */, 30 attribution, /* from pageId */ 31 SettingsEnums.PAGE_VISIBLE /* action */, 32 pageId, /* target pageId */ 33 "" /* changedPreferenceKey */, 34 latency /* changedPreferenceIntValue */, 35 ElapsedTimeUtils.getElapsedTime(System.currentTimeMillis())); 36 } 37 38 @Override hidden(Context context, int pageId, int visibleTime)39 public void hidden(Context context, int pageId, int visibleTime) { 40 SettingsStatsLog.write(SettingsStatsLog.SETTINGS_UI_CHANGED /* Atom name */, 41 SettingsEnums.PAGE_UNKNOWN /* attribution */, 42 SettingsEnums.PAGE_HIDE /* action */, 43 pageId, 44 "" /* changedPreferenceKey */, 45 visibleTime /* changedPreferenceIntValue */, 46 ElapsedTimeUtils.getElapsedTime(System.currentTimeMillis())); 47 } 48 49 @Override clicked(int sourceCategory, String key)50 public void clicked(int sourceCategory, String key) { 51 SettingsStatsLog.write(SettingsStatsLog.SETTINGS_UI_CHANGED /* Atom name */, 52 sourceCategory /* attribution */, 53 SettingsEnums.ACTION_SETTINGS_TILE_CLICK /* action */, 54 SettingsEnums.PAGE_UNKNOWN /* pageId */, 55 key /* changedPreferenceKey */, 56 0 /* changedPreferenceIntValue */, 57 ElapsedTimeUtils.getElapsedTime(System.currentTimeMillis())); 58 } 59 60 @Override changed(int sourceCategory, String key, int value)61 public void changed(int sourceCategory, String key, int value) { 62 SettingsStatsLog.write(SettingsStatsLog.SETTINGS_UI_CHANGED /* Atom name */, 63 sourceCategory /* attribution */, 64 SettingsEnums.ACTION_SETTINGS_PREFERENCE_CHANGE /* action */, 65 SettingsEnums.PAGE_UNKNOWN /* pageId */, 66 key /* changedPreferenceKey */, 67 value /* changedPreferenceIntValue */, 68 ElapsedTimeUtils.getElapsedTime(System.currentTimeMillis())); 69 } 70 71 @Override action(Context context, int action, Pair<Integer, Object>... taggedData)72 public void action(Context context, int action, Pair<Integer, Object>... taggedData) { 73 action(SettingsEnums.PAGE_UNKNOWN /* attribution */, 74 action, 75 SettingsEnums.PAGE_UNKNOWN /* pageId */, 76 null /* changedPreferenceKey */, 77 0 /* changedPreferenceIntValue */); 78 } 79 80 @Override action(Context context, int action, int value)81 public void action(Context context, int action, int value) { 82 action(SettingsEnums.PAGE_UNKNOWN /* attribution */, 83 action, 84 SettingsEnums.PAGE_UNKNOWN /* pageId */, 85 null /* changedPreferenceKey */, 86 value /* changedPreferenceIntValue */); 87 } 88 89 @Override action(Context context, int action, boolean value)90 public void action(Context context, int action, boolean value) { 91 action(SettingsEnums.PAGE_UNKNOWN /* attribution */, 92 action, 93 SettingsEnums.PAGE_UNKNOWN /* pageId */, 94 null /* changedPreferenceKey */, 95 value ? 1 : 0 /* changedPreferenceIntValue */); 96 } 97 98 @Override action(Context context, int action, String pkg)99 public void action(Context context, int action, String pkg) { 100 action(SettingsEnums.PAGE_UNKNOWN /* attribution */, 101 action, 102 SettingsEnums.PAGE_UNKNOWN /* pageId */, 103 pkg /* changedPreferenceKey */, 104 1 /* changedPreferenceIntValue */); 105 } 106 107 @Override action(int attribution, int action, int pageId, String key, int value)108 public void action(int attribution, int action, int pageId, String key, int value) { 109 SettingsStatsLog.write(SettingsStatsLog.SETTINGS_UI_CHANGED /* atomName */, 110 attribution, 111 action, 112 pageId, 113 key, 114 value, 115 ElapsedTimeUtils.getElapsedTime(System.currentTimeMillis())); 116 } 117 } 118