Add Google Firebase analytics

This commit is contained in:
Mario Danic 2017-02-24 13:15:31 +01:00
parent 4d1a0a60c8
commit c7eed23de9
6 changed files with 223 additions and 86 deletions

1
.gitignore vendored
View file

@ -33,3 +33,4 @@ tests/proguard-project.txt
*.iml
build
/gradle.properties
src/custom/google-services.json

View file

@ -161,7 +161,7 @@ dependencies {
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.google.code.findbugs:annotations:2.0.1'
customCompile 'com.google.android.gms:play-services-analytics:10.2.0'
customCompile 'com.google.firebase:firebase-core:10.2.0'
/// dependencies for local unit tests
testCompile 'junit:junit:4.12'

35
google-services.json Normal file
View file

@ -0,0 +1,35 @@
{
"project_info": {
"project_number": "",
"project_id": ""
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "",
"android_client_info": {
"package_name": "com.nextcloud.client"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": ""
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 1
}
}
}
],
"configuration_version": "1"
}

View file

@ -1,39 +1,39 @@
/**
* ownCloud Android client application
* ownCloud Android client application
*
* @author masensio
* @author David A. Velasco
* @author Mario Danic
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2017 Mario Danic
* Copyright (C) 2017 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* All changes by Mario Danic are under AGPL3+
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* @author masensio
* @author David A. Velasco
* @author Mario Danic
* Copyright (C) 2015 ownCloud Inc.
* Copyright (C) 2017 Mario Danic
* Copyright (C) 2017 Nextcloud GmbH
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* <p>
* All changes by Mario Danic are under AGPL3+
* <p>
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
* <p>
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* <p>
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import android.app.Activity;
@ -49,11 +49,8 @@ import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.owncloud.android.BuildConfig;
import com.owncloud.android.R;
import com.owncloud.android.authentication.PassCodeManager;
@ -70,7 +67,7 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Main Application of the project
*
*
* Contains methods to build the "static" strings. These strings were before constants in different
* classes
*/
@ -93,19 +90,22 @@ public class MainApp extends Application {
private static SyncedFolderObserverService mObserverService;
private FirebaseAnalytics mFirebaseAnalytics;
private boolean analyticsEnabled;
@SuppressWarnings("unused")
private boolean mBound;
private Tracker mTracker;
@SuppressFBWarnings("ST") public void onCreate(){
@SuppressFBWarnings("ST")
public void onCreate() {
super.onCreate();
MainApp.mContext = getApplicationContext();
SharedPreferences appPrefs =
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
MainApp.storagePath = appPrefs.getString(Preferences.PreferenceKeys.STORAGE_PATH, Environment.
getExternalStorageDirectory().getAbsolutePath());
getExternalStorageDirectory().getAbsolutePath());
boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
@ -118,7 +118,7 @@ public class MainApp extends Application {
// initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
if (BuildConfig.DEBUG) {
String dataFolder = getDataFolder();
@ -135,38 +135,30 @@ public class MainApp extends Application {
startService(i);
bindService(i, syncedFolderObserverServiceConnection, Context.BIND_AUTO_CREATE);
boolean analyticsEnabled = false;
String analyticsId;
if (!TextUtils.isEmpty(analyticsId = getAppContext().getResources().getString(R.string.analytics_tracking_id))) {
if ((analyticsEnabled = getAppContext().getResources().getBoolean(R.bool.firebase_analytics_enabled))) {
analyticsEnabled = true;
mTracker = getDefaultTracker(analyticsId);
mFirebaseAnalytics = getFirebaseAnalytics();
}
// register global protection with pass code
final boolean finalAnalyticsEnabled = analyticsEnabled;
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
Log_OC.d(activity.getClass().getSimpleName(), "onCreate(Bundle) starting" );
Log_OC.d(activity.getClass().getSimpleName(), "onCreate(Bundle) starting");
WhatsNewActivity.runIfNeeded(activity);
PassCodeManager.getPassCodeManager().onActivityCreated(activity);
}
@Override
public void onActivityStarted(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onStart() starting" );
Log_OC.d(activity.getClass().getSimpleName(), "onStart() starting");
PassCodeManager.getPassCodeManager().onActivityStarted(activity);
if (finalAnalyticsEnabled) {
mTracker.setScreenName(activity.getClass().getSimpleName());
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}
}
@Override
public void onActivityResumed(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onResume() starting" );
Log_OC.d(activity.getClass().getSimpleName(), "onResume() starting");
}
@Override
@ -176,45 +168,31 @@ public class MainApp extends Application {
@Override
public void onActivityStopped(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onStop() ending" );
Log_OC.d(activity.getClass().getSimpleName(), "onStop() ending");
PassCodeManager.getPassCodeManager().onActivityStopped(activity);
if (finalAnalyticsEnabled) {
mTracker.setScreenName(activity.getClass().getSimpleName());
mTracker.send(new HitBuilders.ScreenViewBuilder().build());
}
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
Log_OC.d(activity.getClass().getSimpleName(), "onSaveInstanceState(Bundle) starting" );
Log_OC.d(activity.getClass().getSimpleName(), "onSaveInstanceState(Bundle) starting");
}
@Override
public void onActivityDestroyed(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onDestroy() ending" );
Log_OC.d(activity.getClass().getSimpleName(), "onDestroy() ending");
}
});
}
synchronized public Tracker getDefaultTracker(String analyticsID) {
if (mTracker == null) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
// To enable debug logging use: adb shell setprop log.tag.GAv4 DEBUG
mTracker = analytics.newTracker(analyticsID);
}
return mTracker;
}
public static Context getAppContext() {
return MainApp.mContext;
}
public static String getStoragePath(){
public static String getStoragePath() {
return MainApp.storagePath;
}
public static void setStoragePath(String path){
public static void setStoragePath(String path) {
MainApp.storagePath = path;
}
@ -241,42 +219,42 @@ public class MainApp extends Application {
public static String getAuthority() {
return getAppContext().getResources().getString(R.string.authority);
}
// From AccountAuthenticator
// public static final String AUTH_TOKEN_TYPE = "org.owncloud";
public static String getAuthTokenType() {
return getAppContext().getResources().getString(R.string.authority);
}
// From ProviderMeta
// public static final String DB_FILE = "owncloud.db";
public static String getDBFile() {
return getAppContext().getResources().getString(R.string.db_file);
}
// From ProviderMeta
// private final String mDatabaseName = "ownCloud";
public static String getDBName() {
return getAppContext().getResources().getString(R.string.db_name);
}
/**
* name of data_folder, e.g., "owncloud"
*/
public static String getDataFolder() {
return getAppContext().getResources().getString(R.string.data_folder);
}
// log_name
public static String getLogName() {
return getAppContext().getResources().getString(R.string.log_name);
}
public static void showOnlyFilesOnDevice(boolean state){
public static void showOnlyFilesOnDevice(boolean state) {
mOnlyOnDevice = state;
}
public static boolean isOnlyOnDevice(){
public static boolean isOnlyOnDevice() {
return mOnlyOnDevice;
}
@ -322,4 +300,16 @@ public class MainApp extends Application {
}
};
public FirebaseAnalytics getFirebaseAnalytics() {
if (analyticsEnabled) {
if (mFirebaseAnalytics != null) {
return mFirebaseAnalytics;
} else {
mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
return mFirebaseAnalytics;
}
} else {
return null;
}
}
}

View file

@ -0,0 +1,110 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Beta indicator -->
<bool name="is_beta">false</bool>
<!-- App name and other strings-->
<string name="app_name">Nextcloud</string>
<string name="account_type">nextcloud</string> <!-- better if was a domain name; but changing it now would require migrate accounts when the app is updated -->
<string name="authority">org.nextcloud</string> <!-- better if was the app package with ".provider" appended ; it identifies the provider -->
<string name="document_provider_authority">org.nextcloud.documents</string>
<string name="file_provider_authority">org.nextcloud.files</string>
<string name ="db_file">nextcloud.db</string>
<string name ="db_name">nextcloud</string>
<string name ="data_folder">nextcloud</string>
<string name ="log_name">nextcloud</string>
<string name ="default_display_name_for_root_folder">Nextcloud</string>
<string name ="user_agent">Mozilla/5.0 (Android) ownCloud-android/%1$s</string>
<!-- URLs and flags related -->
<string name="server_url"></string>
<bool name="show_server_url_input">true</bool>
<bool name="show_welcome_link">false</bool>
<string name="welcome_link_url">"https://nextcloud.com/providers"</string>
<string name="share_api_link"></string>
<!-- Flags to setup the authentication methods available in the app -->
<string name="auth_method_oauth2">off</string>
<string name="auth_method_saml_web_sso">off</string>
<!-- Flags to enable/disable some features -->
<string name = "send_files_to_other_apps">on</string>
<bool name = "share_via_link_feature">true</bool>
<bool name = "share_with_users_feature">true</bool>
<!-- Colors -->
<color name="login_text_color">@color/white</color>
<color name="login_text_hint_color">#7fC0E3</color>
<color name="login_background_color">#FFFFFF</color>
<color name="login_logo_background_color">#FFFFFF</color>
<color name="background_color">#FFFFFF</color>
<color name="actionbar_start_color">#0082c9</color>
<color name="actionbar_end_color">#0082c9</color>
<color name="primary_button_background_color">@color/owncloud_blue_accent</color>
<color name="primary_button_text_color">@color/white</color>
<color name="secondary_button_background_color">#D6D7D7</color>
<color name="secondary_button_text_color">@color/black</color>
<color name="drawer_header_color">@color/owncloud_blue_accent</color>
<!-- Button -->
<color name="button_text_color">#000000</color>
<!-- Multiselect backgrounds -->
<color name="action_mode_background">#757575</color>
<color name="action_mode_status_bar_background">#616161</color>
<color name="selected_item_background">#ECECEC</color>
<!-- Multiaccount support -->
<bool name="multiaccount_support">true</bool>
<!-- Drawer options -->
<bool name="recently_added_enabled">false</bool>
<bool name="recently_modified_enabled">false</bool>
<bool name="shared_enabled">false</bool>
<bool name="videos_enabled">false</bool>
<!-- Bottom toolbar -->
<bool name="bottom_toolbar_enabled">false</bool>
<!-- Help, imprint and feedback -->
<bool name="calendar_contacts_enabled">true</bool>
<bool name="help_enabled">true</bool>
<bool name="imprint_enabled">false</bool>
<bool name="recommend_enabled">true</bool>
<bool name="feedback_enabled">true</bool>
<bool name="logger_enabled">false</bool>
<string name="url_help">https://help.nextcloud.com/c/feature</string>
<string name="url_imprint"></string>
<string name="mail_recommend">"mailto:"</string>
<string name="mail_feedback">"mailto:android@nextcloud.com"</string>
<string name="url_app_download">"https://play.google.com/store/apps/details?id=com.nextcloud.client"</string>
<string name="url_server_install">https://nextcloud.com/install</string>
<!--Destination mail for sending log files -->
<string name="mail_logger"></string>
<!-- Participate links -->
<string name="fdroid_beta_link" translatable="false">https://f-droid.org/repository/browse/?fdid=com.nextcloud.android.beta</string>
<string name="beta_apk_link" translatable="false">https://github.com/nextcloud/android/raw/beta/apks/latest.apk</string>
<string name="play_store_register_beta" translatable="false">https://play.google.com/apps/testing/com.nextcloud.client</string>
<string name="fdroid_link" translatable="false">https://f-droid.org/repository/browse/?fdid=com.nextcloud.client</string>
<string name="irc_weblink" translatable="false">http://webchat.freenode.net?channels=nextcloud-mobile</string>
<string name="help_link" translatable="false">https://help.nextcloud.com/c/clients/android</string>
<string name="translation_link" translatable="false">https://www.transifex.com/nextcloud/nextcloud/android/</string>
<string name="contributing_link" translatable="false">https://github.com/nextcloud/android/blob/master/CONTRIBUTING.md</string>
<string name="report_issue_link" translatable="false">https://github.com/nextcloud/android/issues</string>
<!-- login data links -->
<string name="login_data_own_scheme" translatable="false">cloud</string>
<!-- firebase_analytics_enabled - to be used only with custom* build variants
note that it will always log basic stuff when you have google-services.json-->
<bool name="firebase_analytics_enabled">true</bool>
<!-- custom things -->
<string name="files_drawer_toolbar">Home</string>
</resources>

View file

@ -98,8 +98,9 @@
<!-- login data links -->
<string name="login_data_own_scheme" translatable="false">cloud</string>
<!-- analytics_tracking_id - to be used only with custom* build variants -->
<string name="analytics_tracking_id" translatable="false"></string>
<!-- firebase_analytics_enabled - to be used only with custom* build variants
note that it will always log basic stuff when you have google-services.json-->
<bool name="firebase_analytics_enabled">false</bool>
<!-- custom things -->
<string name="files_drawer_toolbar">Files</string>