Loading AndroidManifest.xml +4 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ <!-- allow broadcasting secret code intents that reboot the phone --> <uses-permission android:name="android.permission.REBOOT" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <!-- allow brodcasting across all users --> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" /> <!-- send analytic events through internal package --> <uses-permission android:name="com.cyngn.cmstats.SEND_ANALYTICS" /> <!-- This tells the activity manager to not delay any of our activity start requests, even if they happen immediately after the user presses home. --> Loading res/values/analytics.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <resources> <string name="ga_trackingId">UA-51135639-5</string> </resources> No newline at end of file src/com/android/dialer/DialtactsActivity.java +24 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import com.android.contacts.common.dialog.ClearFrequentsDialog; import com.android.contacts.common.interactions.ImportExportDialogFragment; import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; import com.android.dialer.calllog.CallLogActivity; import com.android.dialer.cmstats.DialerStats; import com.android.dialer.database.DialerDatabaseHelper; import com.android.dialer.dialpad.DialpadFragment; import com.android.dialer.dialpad.SmartDialNameMatcher; Loading Loading @@ -314,6 +315,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O setContentView(R.layout.dialtacts_activity); DialerStats.sendEvent(this, "app_launch", DialtactsActivity.class.getSimpleName()); // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState // is null. Otherwise the fragment manager takes care of recreating these fragments. if (savedInstanceState == null) { Loading Loading @@ -501,6 +504,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } break; case R.id.voice_search_button: DialerStats.sendEvent(DialtactsActivity.this, "button_event", "voice_clicked"); try { startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), ACTIVITY_REQUEST_CODE_VOICE_SEARCH); Loading Loading @@ -552,6 +556,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } private void showDialpadFragment(boolean animate) { DialerStats.sendEvent(DialtactsActivity.this, "button_event", "dialer_shown"); mDialpadFragment.setAdjustTranslationForAnimation(animate); final FragmentTransaction ft = getFragmentManager().beginTransaction(); if (animate) { Loading Loading @@ -597,6 +602,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mSearchView = (EditText) findViewById(R.id.search_view); mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); mSearchView.setHint(getString(R.string.dialer_hint_find_contact)); setupEvent(mSearchViewContainer, R.id.search_view, "button_event", "search_clicked"); prepareVoiceSearchButton(); } Loading Loading @@ -1038,6 +1044,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } public void allContactsClick(View v) { DialerStats.sendEvent(DialtactsActivity.this, "button_event", "contacts_clicked"); onShowAllContacts(); } Loading Loading @@ -1108,4 +1115,21 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O private boolean shouldShowOnscreenDialButton() { return getResources().getBoolean(R.bool.config_show_onscreen_dial_button); } /** * Add analytics event for view * @param v * @param buttonId * @param category * @param action */ private void setupEvent(View v, int buttonId, final String category, final String action) { final View pageviewButton = v.findViewById(buttonId); pageviewButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialerStats.sendEvent(DialtactsActivity.this, category, action); } }); } } src/com/android/dialer/cmstats/DialerStats.java 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * 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.android.dialer.cmstats; import android.content.Context; import android.content.Intent; import android.os.UserHandle; import com.android.dialer.R; public class DialerStats { 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"; 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 void sendEvent(Context context, String category, String action, String label, String value) { 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.getResources().getString(R.string.ga_trackingId)); // append intent.putExtra(Fields.EVENT_CATEGORY, category); intent.putExtra(Fields.EVENT_ACTION, action); // check if exist if (label != null) { intent.putExtra(Fields.EVENT_LABEL, label); } if (value != null) { intent.putExtra(Fields.EVENT_VALUE, value); } // broadcast for internal package context.sendBroadcastAsUser(intent, new UserHandle(UserHandle.USER_CURRENT), ANALYTIC_PERMISSION); } public static void sendEvent(Context context, String category, String action) { sendEvent(context, category, action, null, null); } } src/com/android/dialer/cmstats/StatsUtils.java 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * 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.android.dialer.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.System.getInt(context.getContentResolver(), Settings.System.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; } } } Loading
AndroidManifest.xml +4 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,10 @@ <!-- allow broadcasting secret code intents that reboot the phone --> <uses-permission android:name="android.permission.REBOOT" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <!-- allow brodcasting across all users --> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" /> <!-- send analytic events through internal package --> <uses-permission android:name="com.cyngn.cmstats.SEND_ANALYTICS" /> <!-- This tells the activity manager to not delay any of our activity start requests, even if they happen immediately after the user presses home. --> Loading
res/values/analytics.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <resources> <string name="ga_trackingId">UA-51135639-5</string> </resources> No newline at end of file
src/com/android/dialer/DialtactsActivity.java +24 −0 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import com.android.contacts.common.dialog.ClearFrequentsDialog; import com.android.contacts.common.interactions.ImportExportDialogFragment; import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; import com.android.dialer.calllog.CallLogActivity; import com.android.dialer.cmstats.DialerStats; import com.android.dialer.database.DialerDatabaseHelper; import com.android.dialer.dialpad.DialpadFragment; import com.android.dialer.dialpad.SmartDialNameMatcher; Loading Loading @@ -314,6 +315,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O setContentView(R.layout.dialtacts_activity); DialerStats.sendEvent(this, "app_launch", DialtactsActivity.class.getSimpleName()); // Add the favorites fragment, and the dialpad fragment, but only if savedInstanceState // is null. Otherwise the fragment manager takes care of recreating these fragments. if (savedInstanceState == null) { Loading Loading @@ -501,6 +504,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } break; case R.id.voice_search_button: DialerStats.sendEvent(DialtactsActivity.this, "button_event", "voice_clicked"); try { startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), ACTIVITY_REQUEST_CODE_VOICE_SEARCH); Loading Loading @@ -552,6 +556,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } private void showDialpadFragment(boolean animate) { DialerStats.sendEvent(DialtactsActivity.this, "button_event", "dialer_shown"); mDialpadFragment.setAdjustTranslationForAnimation(animate); final FragmentTransaction ft = getFragmentManager().beginTransaction(); if (animate) { Loading Loading @@ -597,6 +602,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O mSearchView = (EditText) findViewById(R.id.search_view); mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); mSearchView.setHint(getString(R.string.dialer_hint_find_contact)); setupEvent(mSearchViewContainer, R.id.search_view, "button_event", "search_clicked"); prepareVoiceSearchButton(); } Loading Loading @@ -1038,6 +1044,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O } public void allContactsClick(View v) { DialerStats.sendEvent(DialtactsActivity.this, "button_event", "contacts_clicked"); onShowAllContacts(); } Loading Loading @@ -1108,4 +1115,21 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O private boolean shouldShowOnscreenDialButton() { return getResources().getBoolean(R.bool.config_show_onscreen_dial_button); } /** * Add analytics event for view * @param v * @param buttonId * @param category * @param action */ private void setupEvent(View v, int buttonId, final String category, final String action) { final View pageviewButton = v.findViewById(buttonId); pageviewButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DialerStats.sendEvent(DialtactsActivity.this, category, action); } }); } }
src/com/android/dialer/cmstats/DialerStats.java 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * 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.android.dialer.cmstats; import android.content.Context; import android.content.Intent; import android.os.UserHandle; import com.android.dialer.R; public class DialerStats { 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"; 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 void sendEvent(Context context, String category, String action, String label, String value) { 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.getResources().getString(R.string.ga_trackingId)); // append intent.putExtra(Fields.EVENT_CATEGORY, category); intent.putExtra(Fields.EVENT_ACTION, action); // check if exist if (label != null) { intent.putExtra(Fields.EVENT_LABEL, label); } if (value != null) { intent.putExtra(Fields.EVENT_VALUE, value); } // broadcast for internal package context.sendBroadcastAsUser(intent, new UserHandle(UserHandle.USER_CURRENT), ANALYTIC_PERMISSION); } public static void sendEvent(Context context, String category, String action) { sendEvent(context, category, action, null, null); } }
src/com/android/dialer/cmstats/StatsUtils.java 0 → 100644 +41 −0 Original line number Diff line number Diff line /* * 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.android.dialer.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.System.getInt(context.getContentResolver(), Settings.System.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; } } }