SetupWizard: Add metrics for internal builds that ship with CMStats

Change-Id: Id932a105c18332e32605530d1502ff99b7cf380a
This commit is contained in:
cretin45 2015-03-04 13:06:26 -08:00
parent c9c13f20c9
commit ef4cd78d5f
17 changed files with 377 additions and 18 deletions

View File

@ -45,6 +45,7 @@
<uses-permission android:name="android.permission.BACKUP" /> <uses-permission android:name="android.permission.BACKUP" />
<uses-permission android:name="org.whispersystems.whisperpush.permissions.REGISTER" /> <uses-permission android:name="org.whispersystems.whisperpush.permissions.REGISTER" />
<uses-permission android:name="cyanogenmod.permission.FINISH_SETUP" /> <uses-permission android:name="cyanogenmod.permission.FINISH_SETUP" />
<uses-permission android:name="com.cyngn.cmstats.SEND_ANALYTICS" />
<permission <permission
android:name="cyanogenmod.permission.PROTECTED_APP" android:name="cyanogenmod.permission.PROTECTED_APP"

View File

@ -0,0 +1,160 @@
/*
* Copyright (C) 2014 The CyanogenMod 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.cyanogenmod.setupwizard.cmstats;
import android.content.Context;
import android.content.Intent;
import android.os.UserHandle;
import android.util.Log;
import java.util.LinkedList;
public class SetupStats {
private static final String TAG = SetupStats.class.getSimpleName();
private static final String ANALYTIC_INTENT = "com.cyngn.cmstats.action.SEND_ANALYTIC_EVENT";
private static final String ANALYTIC_PERMISSION = "com.cyngn.cmstats.RECEIVE_ANALYTICS";
public static final String TRACKING_ID = "tracking_id";
private final LinkedList<Event> mEvents = new LinkedList<Event>();
private static final SetupStats sInstance = new SetupStats();
private static final boolean DEBUG = false;
private SetupStats() {}
public static void addEvent(String category, String action,
String label, String value) {
sInstance.mEvents.add(new Event(category, action, label, value));
}
public static void addEvent(String category, String action) {
sInstance.mEvents.add(new Event(category, action, null, null));
}
public static void sendEvents(Context context) {
while (!sInstance.mEvents.isEmpty()) {
sInstance.sendEvent(context, sInstance.mEvents.remove());
}
}
private void sendEvent(Context context, Event event) {
if (!StatsUtils.isStatsPackageInstalled(context)
|| !StatsUtils.isStatsCollectionEnabled(context)) {
return;
}
// Create new intent
Intent intent = new Intent();
intent.setAction(ANALYTIC_INTENT);
// add tracking id
intent.putExtra(TRACKING_ID, context.getPackageName());
// append
intent.putExtra(Fields.EVENT_CATEGORY, event.category);
if (DEBUG) Log.d(TAG, Fields.EVENT_CATEGORY + "=" + event.category);
intent.putExtra(Fields.EVENT_ACTION, event.action);
if (DEBUG) Log.d(TAG, Fields.EVENT_ACTION + "=" + event.action);
// check if exist
if (event.label != null) {
intent.putExtra(Fields.EVENT_LABEL, event.label);
if (DEBUG) Log.d(TAG, Fields.EVENT_LABEL + "=" + event.label);
}
if (event.value != null) {
intent.putExtra(Fields.EVENT_VALUE, event.value);
if (DEBUG) Log.d(TAG, Fields.EVENT_VALUE + "=" + event.value);
}
// broadcast for internal package
context.sendBroadcastAsUser(intent,
new UserHandle(UserHandle.USER_CURRENT), ANALYTIC_PERMISSION);
}
private static final class Event {
private final String category;
private final String action;
private final String label;
private final String value;
public Event(String category, String action, String label, String value) {
this.action = action;
this.category = category;
this.label = label;
this.value = value;
}
}
public static final class Fields {
public static final String EVENT_CATEGORY = "category";
public static final String EVENT_ACTION = "action";
public static final String EVENT_LABEL = "label";
public static final String EVENT_VALUE = "value";
}
public static final class Categories {
public static final String APP_LAUNCH = "app_launch";
public static final String APP_FINISHED = "app_finish";
public static final String PAGE_LOAD = "page_load";
public static final String EXTERNAL_PAGE_LOAD = "external_page_load";
public static final String BUTTON_CLICK = "button_click";
public static final String SETTING_CHANGED = "setting_changed";
}
public static final class Action {
public static final String PAGE_LOADED = "page_loaded";
public static final String PREVIOUS_BUTTON = "previous_button";
public static final String NEXT_BUTTON = "next_button";
public static final String CHANGE_LOCALE = "change_local";
public static final String EXTERNAL_PAGE_LAUNCH = "external_page_launch";
public static final String EXTERNAL_PAGE_RESULT = "external_page_result";
public static final String ENABLE_MOBILE_DATA = "enable_mobile_data";
public static final String PREFERRED_DATA_SIM = "preferred_data_sim";
public static final String APPLY_CUSTOM_THEME = "apply_custom_theme";
public static final String USE_SECURE_SMS = "use_secure_sms";
public static final String ENABLE_BACKUP = "enable_backup";
public static final String ENABLE_NAV_KEYS = "enable_nav_keys";
public static final String ENABLE_LOCATION = "enable_location";
public static final String ENABLE_NETWORK_LOCATION = "enable_network_location";
public static final String ENABLE_GPS_LOCATION = "enable_gps_location";
public static final String DATE_CHANGED = "date_changed";
public static final String TIME_CHANGED = "time_changed";
public static final String TIMEZONE_CHANGED = "timezone_changed";
}
public static final class Label {
public static final String PAGE = "page";
public static final String LOCALE = "local";
public static final String RESULT = "result";
public static final String WIFI_SETUP = "wifi_setup";
public static final String CYANOGEN_ACCOUNT = "cyanogen_account_setup";
public static final String CAPTIVE_PORTAL_LOGIN = "captive_portal_login";
public static final String EMERGENCY_CALL = "emergency_call";
public static final String GMS_ACCOUNT = "gms_account";
public static final String RESTORE = "restore";
public static final String CHECKED = "checked";
public static final String VALUE = "value";
public static final String SLOT = "slot";
public static final String TOTAL_TIME = "total_time";
}
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2014 The CyanogenMod 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.cyanogenmod.setupwizard.cmstats;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.provider.Settings;
public class StatsUtils {
private static final String STATS_PACKAGE = "com.cyngn.cmstats";
public static boolean isStatsCollectionEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.STATS_COLLECTION, 1) != 0;
}
public static boolean isStatsPackageInstalled(Context context) {
try {
PackageInfo pi = context.getPackageManager().getPackageInfo(STATS_PACKAGE, 0);
return pi.applicationInfo.enabled;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
}

View File

@ -36,6 +36,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import java.util.List; import java.util.List;
@ -179,7 +180,14 @@ public class ChooseDataSimPage extends SetupPage {
private void setDataSubChecked(SubInfoRecord subInfoRecord) { private void setDataSubChecked(SubInfoRecord subInfoRecord) {
if (isDetached()) return; if (isDetached()) return;
for (int i = 0; i < mCheckBoxes.size(); i++) { for (int i = 0; i < mCheckBoxes.size(); i++) {
mCheckBoxes.get(i).setChecked(subInfoRecord.slotId == i); if (subInfoRecord.slotId == i) {
mCheckBoxes.get(i).setChecked(true);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.PREFERRED_DATA_SIM,
SetupStats.Label.SLOT, String.valueOf(i + 1));
} else {
mCheckBoxes.get(i).setChecked(false);
}
} }
} }

View File

@ -31,8 +31,8 @@ import android.os.Bundle;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.LoadingFragment; import com.cyanogenmod.setupwizard.ui.LoadingFragment;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.io.IOException; import java.io.IOException;
@ -98,11 +98,19 @@ public class CyanogenServicesPage extends SetupPage {
public boolean onActivityResult(int requestCode, int resultCode, Intent data) { public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN) { if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN) {
if (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_FIRST_USER) { if (resultCode == Activity.RESULT_OK || resultCode == Activity.RESULT_FIRST_USER) {
if (SetupWizardUtils.accountExists(mContext, mContext.getString(R.string.cm_account_type))) { SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.CYANOGEN_ACCOUNT,
resultCode == Activity.RESULT_OK ? "success" : "skipped");
if (SetupWizardUtils.accountExists(mContext,
mContext.getString(R.string.cm_account_type))) {
setHidden(true); setHidden(true);
} }
getCallbacks().onNextPage(); getCallbacks().onNextPage();
} else if (resultCode == Activity.RESULT_CANCELED) { } else if (resultCode == Activity.RESULT_CANCELED) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.CYANOGEN_ACCOUNT, "canceled");
getCallbacks().onPreviousPage(); getCallbacks().onPreviousPage();
} }
} }
@ -128,11 +136,17 @@ public class CyanogenServicesPage extends SetupPage {
android.R.anim.fade_in, android.R.anim.fade_in,
android.R.anim.fade_out); android.R.anim.fade_out);
if (!mFragment.isDetached()) { if (!mFragment.isDetached()) {
SetupStats
.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
SetupStats.Label.PAGE,
SetupStats.Label.CYANOGEN_ACCOUNT);
mFragment.startActivityForResult(intent, mFragment.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN, SetupWizardApp.REQUEST_CODE_SETUP_CYANOGEN,
options.toBundle()); options.toBundle());
} else { } else {
if (getCallbacks().isCurrentPage(CyanogenServicesPage.this)) { if (getCallbacks().
isCurrentPage(CyanogenServicesPage.this)) {
getCallbacks().onNextPage(); getCallbacks().onNextPage();
} }
} }

View File

@ -41,6 +41,7 @@ import android.widget.CheckBox;
import android.widget.TextView; import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment; import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
@ -127,6 +128,10 @@ public class CyanogenSettingsPage extends SetupPage {
@Override @Override
public void run() { public void run() {
if (getData().containsKey(KEY_ENABLE_NAV_KEYS)) { if (getData().containsKey(KEY_ENABLE_NAV_KEYS)) {
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.ENABLE_NAV_KEYS,
SetupStats.Label.CHECKED,
String.valueOf(getData().getBoolean(KEY_ENABLE_NAV_KEYS)));
writeDisableNavkeysOption(mContext, getData().getBoolean(KEY_ENABLE_NAV_KEYS)); writeDisableNavkeysOption(mContext, getData().getBoolean(KEY_ENABLE_NAV_KEYS));
} }
} }
@ -139,8 +144,12 @@ public class CyanogenSettingsPage extends SetupPage {
private void handleWhisperPushRegistration() { private void handleWhisperPushRegistration() {
Bundle privacyData = getData(); Bundle privacyData = getData();
if (privacyData != null && if (privacyData != null &&
privacyData.containsKey(CyanogenSettingsPage.KEY_REGISTER_WHISPERPUSH) && privacyData.containsKey(KEY_REGISTER_WHISPERPUSH) &&
privacyData.getBoolean(CyanogenSettingsPage.KEY_REGISTER_WHISPERPUSH)) { privacyData.getBoolean(KEY_REGISTER_WHISPERPUSH)) {
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.USE_SECURE_SMS,
SetupStats.Label.CHECKED,
String.valueOf(privacyData.getBoolean(KEY_REGISTER_WHISPERPUSH)));
Log.i(TAG, "Registering with WhisperPush"); Log.i(TAG, "Registering with WhisperPush");
WhisperPushUtils.startRegistration(mContext); WhisperPushUtils.startRegistration(mContext);
} }
@ -149,9 +158,9 @@ public class CyanogenSettingsPage extends SetupPage {
private void handleEnableMetrics() { private void handleEnableMetrics() {
Bundle privacyData = getData(); Bundle privacyData = getData();
if (privacyData != null if (privacyData != null
&& privacyData.containsKey(CyanogenSettingsPage.KEY_SEND_METRICS)) { && privacyData.containsKey(KEY_SEND_METRICS)) {
Settings.System.putInt(mContext.getContentResolver(), CyanogenSettingsPage.SETTING_METRICS, Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.STATS_COLLECTION,
privacyData.getBoolean(CyanogenSettingsPage.KEY_SEND_METRICS) ? 1 : 0); privacyData.getBoolean(KEY_SEND_METRICS) ? 1 : 0);
} }
} }
@ -159,9 +168,14 @@ public class CyanogenSettingsPage extends SetupPage {
Bundle privacyData = getData(); Bundle privacyData = getData();
if (!ThemeUtils.getDefaultThemePackageName(mContext).equals(ThemeConfig.SYSTEM_DEFAULT) && if (!ThemeUtils.getDefaultThemePackageName(mContext).equals(ThemeConfig.SYSTEM_DEFAULT) &&
privacyData != null && privacyData.getBoolean(KEY_APPLY_DEFAULT_THEME)) { privacyData != null && privacyData.getBoolean(KEY_APPLY_DEFAULT_THEME)) {
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.APPLY_CUSTOM_THEME,
SetupStats.Label.CHECKED,
String.valueOf(privacyData.getBoolean(KEY_APPLY_DEFAULT_THEME)));
Log.i(TAG, "Applying default theme"); Log.i(TAG, "Applying default theme");
final ThemeManager tm = (ThemeManager) mContext.getSystemService(Context.THEME_SERVICE); final ThemeManager tm = (ThemeManager) mContext.getSystemService(Context.THEME_SERVICE);
tm.applyDefaultTheme(); tm.applyDefaultTheme();
} else { } else {
getCallbacks().finishSetup(); getCallbacks().finishSetup();
} }

View File

@ -42,6 +42,7 @@ import android.widget.TextView;
import android.widget.TimePicker; import android.widget.TimePicker;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
@ -135,6 +136,8 @@ public class DateTimePage extends SetupPage {
mDateView.setOnClickListener(new View.OnClickListener() { mDateView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
SetupStats.addEvent(SetupStats.Categories.BUTTON_CLICK,
"date_picker");
showDatePicker(); showDatePicker();
} }
}); });
@ -142,6 +145,8 @@ public class DateTimePage extends SetupPage {
mTimeView.setOnClickListener(new View.OnClickListener() { mTimeView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
SetupStats.addEvent(SetupStats.Categories.BUTTON_CLICK,
"time_picker");
showTimePicker(); showTimePicker();
} }
}); });
@ -162,11 +167,17 @@ public class DateTimePage extends SetupPage {
final Map<?, ?> map = (Map<?, ?>) adapterView.getItemAtPosition(position); final Map<?, ?> map = (Map<?, ?>) adapterView.getItemAtPosition(position);
final String tzId = (String) map.get(KEY_ID); final String tzId = (String) map.get(KEY_ID);
if (mCurrentTimeZone != null && !mCurrentTimeZone.getID().equals(tzId)) { if (mCurrentTimeZone != null && !mCurrentTimeZone.getID().equals(tzId)) {
SetupStats.addEvent(SetupStats.Categories.BUTTON_CLICK,
"timezone_picker");
// Update the system timezone value // Update the system timezone value
final Activity activity = getActivity(); final Activity activity = getActivity();
final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE); final AlarmManager alarm = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
alarm.setTimeZone(tzId); alarm.setTimeZone(tzId);
mCurrentTimeZone = TimeZone.getTimeZone(tzId); mCurrentTimeZone = TimeZone.getTimeZone(tzId);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.TIMEZONE_CHANGED,
SetupStats.Label.VALUE,
mCurrentTimeZone.getDisplayName());
} }
} }
@ -209,6 +220,10 @@ public class DateTimePage extends SetupPage {
if (activity != null) { if (activity != null) {
setDate(activity, year, month, day); setDate(activity, year, month, day);
updateTimeAndDateDisplay(activity); updateTimeAndDateDisplay(activity);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.DATE_CHANGED,
SetupStats.Label.VALUE,
month+"/"+day+"/"+year);
} }
} }
@ -218,6 +233,10 @@ public class DateTimePage extends SetupPage {
if (activity != null) { if (activity != null) {
setTime(activity, hourOfDay, minute); setTime(activity, hourOfDay, minute);
updateTimeAndDateDisplay(activity); updateTimeAndDateDisplay(activity);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.TIME_CHANGED,
SetupStats.Label.VALUE,
hourOfDay+":"+minute);
} }
} }

View File

@ -36,6 +36,7 @@ import android.util.Log;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.LoadingFragment; import com.cyanogenmod.setupwizard.ui.LoadingFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
@ -125,12 +126,15 @@ public class GmsAccountPage extends SetupPage {
public boolean onActivityResult(int requestCode, int resultCode, Intent data) { public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS) { if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS) {
if (!mBackupEnabled && SetupWizardUtils.isOwner() && resultCode == Activity.RESULT_OK) { if (!mBackupEnabled && SetupWizardUtils.isOwner() && resultCode == Activity.RESULT_OK) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.GMS_ACCOUNT, "success");
launchGmsRestorePage(); launchGmsRestorePage();
} else { } else {
handleResult(resultCode); handleResult(requestCode, resultCode);
} }
} else if (requestCode == SetupWizardApp.REQUEST_CODE_RESTORE_GMS) { } else if (requestCode == SetupWizardApp.REQUEST_CODE_RESTORE_GMS) {
handleResult(resultCode); handleResult(requestCode, resultCode);
setHidden(true); setHidden(true);
} }
return true; return true;
@ -147,10 +151,25 @@ public class GmsAccountPage extends SetupPage {
} }
} }
private void handleResult(int resultCode) { private void handleResult(int requestCode, int resultCode) {
if (resultCode == Activity.RESULT_CANCELED) { if (resultCode == Activity.RESULT_CANCELED) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS ?
SetupStats.Label.GMS_ACCOUNT : SetupStats.Label.RESTORE, "canceled");
getCallbacks().onPreviousPage(); getCallbacks().onPreviousPage();
} else { } else {
if (resultCode == Activity.RESULT_OK) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS ?
SetupStats.Label.GMS_ACCOUNT : SetupStats.Label.RESTORE, "success");
} else {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
requestCode == SetupWizardApp.REQUEST_CODE_SETUP_GMS ?
SetupStats.Label.GMS_ACCOUNT : SetupStats.Label.RESTORE, "skipped");
}
if (SetupWizardUtils.accountExists(mContext, SetupWizardApp.ACCOUNT_TYPE_GMS)) { if (SetupWizardUtils.accountExists(mContext, SetupWizardApp.ACCOUNT_TYPE_GMS)) {
setHidden(true); setHidden(true);
} }
@ -174,6 +193,9 @@ public class GmsAccountPage extends SetupPage {
ActivityOptions.makeCustomAnimation(mContext, ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in, android.R.anim.fade_in,
android.R.anim.fade_out); android.R.anim.fade_out);
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
SetupStats.Label.PAGE, SetupStats.Label.RESTORE);
mFragment.startActivityForResult( mFragment.startActivityForResult(
intent, intent,
SetupWizardApp.REQUEST_CODE_RESTORE_GMS, options.toBundle()); SetupWizardApp.REQUEST_CODE_RESTORE_GMS, options.toBundle());
@ -204,6 +226,9 @@ public class GmsAccountPage extends SetupPage {
android.R.anim.fade_in, android.R.anim.fade_in,
android.R.anim.fade_out); android.R.anim.fade_out);
if (!mFragment.isDetached()) { if (!mFragment.isDetached()) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
SetupStats.Label.PAGE, SetupStats.Label.GMS_ACCOUNT);
mFragment.startActivityForResult(intent, mFragment.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_GMS, options.toBundle()); SetupWizardApp.REQUEST_CODE_SETUP_GMS, options.toBundle());
} else { } else {

View File

@ -33,6 +33,7 @@ import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
@ -103,6 +104,9 @@ public class MobileDataPage extends SetupPage {
boolean checked = !mEnableMobileData.isChecked(); boolean checked = !mEnableMobileData.isChecked();
SetupWizardUtils.setMobileDataEnabled(getActivity(), checked); SetupWizardUtils.setMobileDataEnabled(getActivity(), checked);
mEnableMobileData.setChecked(checked); mEnableMobileData.setChecked(checked);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.ENABLE_MOBILE_DATA,
SetupStats.Label.CHECKED, String.valueOf(checked));
} }
}; };

View File

@ -38,6 +38,7 @@ import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment; import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
@ -253,6 +254,9 @@ public class OtherSettingsPage extends SetupPage {
private void onToggleBackup(boolean checked) { private void onToggleBackup(boolean checked) {
try { try {
mBackupManager.setBackupEnabled(checked); mBackupManager.setBackupEnabled(checked);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.ENABLE_BACKUP,
SetupStats.Label.CHECKED, String.valueOf(checked));
} catch (RemoteException e) {} } catch (RemoteException e) {}
updateBackupToggle(); updateBackupToggle();
} }
@ -263,11 +267,20 @@ public class OtherSettingsPage extends SetupPage {
boolean networkEnabled = Settings.Secure.isLocationProviderEnabled( boolean networkEnabled = Settings.Secure.isLocationProviderEnabled(
mContentResolver, LocationManager.NETWORK_PROVIDER); mContentResolver, LocationManager.NETWORK_PROVIDER);
mGps.setChecked(gpsEnabled); mGps.setChecked(gpsEnabled);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.ENABLE_GPS_LOCATION,
SetupStats.Label.CHECKED, String.valueOf(gpsEnabled));
mNetwork.setChecked(networkEnabled); mNetwork.setChecked(networkEnabled);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.ENABLE_NETWORK_LOCATION,
SetupStats.Label.CHECKED, String.valueOf(networkEnabled));
mLocationAccess.setChecked(gpsEnabled || networkEnabled); mLocationAccess.setChecked(gpsEnabled || networkEnabled);
} }
private void onToggleLocationAccess(boolean checked) { private void onToggleLocationAccess(boolean checked) {
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.ENABLE_LOCATION,
SetupStats.Label.CHECKED, String.valueOf(checked));
Settings.Secure.setLocationProviderEnabled(mContentResolver, Settings.Secure.setLocationProviderEnabled(mContentResolver,
LocationManager.GPS_PROVIDER, checked); LocationManager.GPS_PROVIDER, checked);
mGps.setEnabled(checked); mGps.setEnabled(checked);

View File

@ -26,6 +26,7 @@ import android.transition.Transition;
import android.view.Gravity; import android.view.Gravity;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
public abstract class SetupPage implements Page { public abstract class SetupPage implements Page {
@ -75,12 +76,18 @@ public abstract class SetupPage implements Page {
public void doLoadAction(FragmentManager fragmentManager, int action) { public void doLoadAction(FragmentManager fragmentManager, int action) {
Fragment fragment = getFragment(fragmentManager, action); Fragment fragment = getFragment(fragmentManager, action);
if (action == Page.ACTION_NEXT) { if (action == Page.ACTION_NEXT) {
SetupStats.addEvent(SetupStats.Categories.BUTTON_CLICK,
SetupStats.Action.NEXT_BUTTON, getKey(),
String.valueOf(System.currentTimeMillis()));
Transition t = new Slide(Gravity.RIGHT); Transition t = new Slide(Gravity.RIGHT);
fragment.setEnterTransition(t); fragment.setEnterTransition(t);
fragmentManager.beginTransaction() fragmentManager.beginTransaction()
.replace(R.id.content,fragment, getKey()) .replace(R.id.content,fragment, getKey())
.commit(); .commit();
} else { } else {
SetupStats.addEvent(SetupStats.Categories.BUTTON_CLICK,
SetupStats.Action.PREVIOUS_BUTTON, getKey(),
String.valueOf(System.currentTimeMillis()));
Transition t = new Slide(Gravity.LEFT); Transition t = new Slide(Gravity.LEFT);
fragment.setEnterTransition(t); fragment.setEnterTransition(t);
fragmentManager.beginTransaction() fragmentManager.beginTransaction()

View File

@ -30,6 +30,7 @@ import android.widget.ArrayAdapter;
import android.widget.NumberPicker; import android.widget.NumberPicker;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.LocalePicker; import com.cyanogenmod.setupwizard.ui.LocalePicker;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
@ -72,6 +73,10 @@ public class WelcomePage extends SetupPage {
ActivityOptions.makeCustomAnimation(mContext, ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in, android.R.anim.fade_in,
android.R.anim.fade_out); android.R.anim.fade_out);
SetupStats.addEvent(SetupStats.Categories.BUTTON_CLICK, SetupStats.Label.EMERGENCY_CALL);
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
SetupStats.Label.PAGE, SetupStats.Label.EMERGENCY_CALL);
mContext.startActivity(intent, options.toBundle()); mContext.startActivity(intent, options.toBundle());
return true; return true;
} }
@ -158,6 +163,9 @@ public class WelcomePage extends SetupPage {
localResources.updateConfiguration(localConfiguration1, null); localResources.updateConfiguration(localConfiguration1, null);
mHandler.removeCallbacks(mUpdateLocale); mHandler.removeCallbacks(mUpdateLocale);
mCurrentLocale = paramLocale; mCurrentLocale = paramLocale;
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.CHANGE_LOCALE, SetupStats.Label.LOCALE,
mCurrentLocale.getDisplayName());
mHandler.postDelayed(mUpdateLocale, 1000); mHandler.postDelayed(mUpdateLocale, 1000);
} }

View File

@ -29,6 +29,7 @@ import android.util.Log;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.LoadingFragment; import com.cyanogenmod.setupwizard.ui.LoadingFragment;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
@ -75,6 +76,9 @@ public class WifiSetupPage extends SetupPage {
ActivityOptions.makeCustomAnimation(mContext, ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in, android.R.anim.fade_in,
android.R.anim.fade_out); android.R.anim.fade_out);
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
SetupStats.Label.PAGE, SetupStats.Label.CAPTIVE_PORTAL_LOGIN);
mLoadingFragment.startActivityForResult(intent, mLoadingFragment.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL, SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL,
options.toBundle()); options.toBundle());
@ -141,16 +145,31 @@ public class WifiSetupPage extends SetupPage {
public boolean onActivityResult(int requestCode, int resultCode, Intent data) { public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_WIFI) { if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_WIFI) {
if (resultCode == Activity.RESULT_CANCELED) { if (resultCode == Activity.RESULT_CANCELED) {
getCallbacks().onPreviousPage(); SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.WIFI_SETUP, "canceled");
getCallbacks().onPreviousPage();
} else if (resultCode == Activity.RESULT_OK) { } else if (resultCode == Activity.RESULT_OK) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.WIFI_SETUP, "success");
checkForCaptivePortal(); checkForCaptivePortal();
} else { } else {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.WIFI_SETUP, "skipped");
getCallbacks().onNextPage(); getCallbacks().onNextPage();
} }
} else if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL) { } else if (requestCode == SetupWizardApp.REQUEST_CODE_SETUP_CAPTIVE_PORTAL) {
if (resultCode == Activity.RESULT_CANCELED) { if (resultCode == Activity.RESULT_CANCELED) {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "canceled");
launchWifiSetup(); launchWifiSetup();
} else { } else {
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_RESULT,
SetupStats.Label.CAPTIVE_PORTAL_LOGIN, "success");
getCallbacks().onNextPage(); getCallbacks().onNextPage();
} }
} else { } else {
@ -210,6 +229,9 @@ public class WifiSetupPage extends SetupPage {
ActivityOptions.makeCustomAnimation(mContext, ActivityOptions.makeCustomAnimation(mContext,
android.R.anim.fade_in, android.R.anim.fade_in,
android.R.anim.fade_out); android.R.anim.fade_out);
SetupStats.addEvent(SetupStats.Categories.EXTERNAL_PAGE_LOAD,
SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
SetupStats.Label.PAGE, SetupStats.Label.WIFI_SETUP);
mLoadingFragment.startActivityForResult(intent, mLoadingFragment.startActivityForResult(intent,
SetupWizardApp.REQUEST_CODE_SETUP_WIFI, options.toBundle()); SetupWizardApp.REQUEST_CODE_SETUP_WIFI, options.toBundle());
} }

View File

@ -26,6 +26,7 @@ import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.setup.Page; import com.cyanogenmod.setupwizard.setup.Page;
import com.cyanogenmod.setupwizard.setup.SetupDataCallbacks; import com.cyanogenmod.setupwizard.setup.SetupDataCallbacks;
@ -47,6 +48,8 @@ public abstract class SetupPageFragment extends Fragment {
if (mKey == null) { if (mKey == null) {
throw new IllegalArgumentException("No KEY_PAGE_ARGUMENT given"); throw new IllegalArgumentException("No KEY_PAGE_ARGUMENT given");
} }
SetupStats.addEvent(SetupStats.Categories.PAGE_LOAD, SetupStats.Action.PAGE_LOADED,
mKey, String.valueOf(System.currentTimeMillis()));
} }
@Override @Override

View File

@ -41,6 +41,7 @@ import android.widget.ProgressBar;
import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.setup.CMSetupWizardData; import com.cyanogenmod.setupwizard.setup.CMSetupWizardData;
import com.cyanogenmod.setupwizard.setup.Page; import com.cyanogenmod.setupwizard.setup.Page;
import com.cyanogenmod.setupwizard.setup.SetupDataCallbacks; import com.cyanogenmod.setupwizard.setup.SetupDataCallbacks;
@ -71,6 +72,8 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
private volatile boolean mIsFinishing = false; private volatile boolean mIsFinishing = false;
private static long sLaunchTime = 0;
private final ArrayList<Runnable> mFinishRunnables = new ArrayList<Runnable>(); private final ArrayList<Runnable> mFinishRunnables = new ArrayList<Runnable>();
private ThemeManager.ThemeChangeListener mThemeChangeListener = new ThemeManager.ThemeChangeListener() { private ThemeManager.ThemeChangeListener mThemeChangeListener = new ThemeManager.ThemeChangeListener() {
@ -90,6 +93,10 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (sLaunchTime == 0) {
SetupStats.addEvent(SetupStats.Categories.APP_LAUNCH, TAG);
sLaunchTime = System.nanoTime();
}
getWindow().setWindowAnimations(android.R.anim.fade_in); getWindow().setWindowAnimations(android.R.anim.fade_in);
setContentView(R.layout.setup_main); setContentView(R.layout.setup_main);
mRootView = findViewById(R.id.root); mRootView = findViewById(R.id.root);
@ -300,6 +307,9 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
final ThemeManager tm = (ThemeManager) getSystemService(Context.THEME_SERVICE); final ThemeManager tm = (ThemeManager) getSystemService(Context.THEME_SERVICE);
tm.addClient(mThemeChangeListener); tm.addClient(mThemeChangeListener);
mSetupData.finishPages(); mSetupData.finishPages();
SetupStats.addEvent(SetupStats.Categories.APP_FINISHED, TAG,
SetupStats.Label.TOTAL_TIME, String.valueOf(
System.nanoTime() - sLaunchTime));
} }
@Override @Override
@ -322,9 +332,6 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
@Override @Override
public void finish() { public void finish() {
super.finish(); super.finish();
for (Runnable runnable : mFinishRunnables) {
runnable.run();
}
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
} }
@ -411,11 +418,11 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
if (mEnableAccessibilityController != null) { if (mEnableAccessibilityController != null) {
mEnableAccessibilityController.onDestroy(); mEnableAccessibilityController.onDestroy();
} }
SetupWizardUtils.disableGMSSetupWizard(SetupWizardActivity.this);
SetupWizardUtils.disableSetupWizard(SetupWizardActivity.this);
final ThemeManager tm = final ThemeManager tm =
(ThemeManager) SetupWizardActivity.this.getSystemService(THEME_SERVICE); (ThemeManager) SetupWizardActivity.this.getSystemService(THEME_SERVICE);
tm.removeClient(mThemeChangeListener); tm.removeClient(mThemeChangeListener);
SetupStats.sendEvents(SetupWizardActivity.this);
SetupWizardUtils.disableGMSSetupWizard(SetupWizardActivity.this);
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME); intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent); startActivity(intent);
@ -425,5 +432,9 @@ public class SetupWizardActivity extends Activity implements SetupDataCallbacks
} }
}); });
finish(); finish();
for (Runnable runnable : mFinishRunnables) {
runnable.run();
}
SetupWizardUtils.disableSetupWizard(SetupWizardActivity.this);
} }
} }

View File

@ -39,6 +39,7 @@ import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.IAccessibilityManager; import android.view.accessibility.IAccessibilityManager;
import com.android.internal.R; import com.android.internal.R;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -275,6 +276,8 @@ public class EnableAccessibilityController {
// Turn on accessibility mode last. // Turn on accessibility mode last.
Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_ENABLED, Settings.Secure.putIntForUser(resolver, Settings.Secure.ACCESSIBILITY_ENABLED,
1, userId); 1, userId);
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
"accessibility_enabled");
} else if (keyguardLocked) { } else if (keyguardLocked) {
try { try {
mAccessibilityManager.temporaryEnableAccessibilityStateUntilKeyguardRemoved( mAccessibilityManager.temporaryEnableAccessibilityStateUntilKeyguardRemoved(

View File

@ -27,6 +27,7 @@ import android.net.NetworkInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
@ -42,6 +43,11 @@ public class SetupWizardUtils {
private SetupWizardUtils(){} private SetupWizardUtils(){}
public static boolean isStatsCollectionEnabled(Context context) {
return Settings.Secure.getInt(context.getContentResolver(),
Settings.Secure.STATS_COLLECTION, 1) != 0;
}
public static void tryEnablingWifi(Context context) { public static void tryEnablingWifi(Context context) {
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) { if (!wifiManager.isWifiEnabled()) {