From c7eed23de90ff3bc4e8f757986a993031b0c85a0 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Fri, 24 Feb 2017 13:15:31 +0100 Subject: [PATCH] Add Google Firebase analytics --- .gitignore | 1 + build.gradle | 2 +- google-services.json | 35 +++++++ src/custom/java/MainApp.java | 156 +++++++++++++++----------------- src/custom/res/values/setup.xml | 110 ++++++++++++++++++++++ src/main/res/values/setup.xml | 5 +- 6 files changed, 223 insertions(+), 86 deletions(-) create mode 100644 google-services.json create mode 100644 src/custom/res/values/setup.xml diff --git a/.gitignore b/.gitignore index 0d18cdf6bb..797e6b6500 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ tests/proguard-project.txt *.iml build /gradle.properties +src/custom/google-services.json diff --git a/build.gradle b/build.gradle index 05a02309ed..b9a5394bc9 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/google-services.json b/google-services.json new file mode 100644 index 0000000000..4916126561 --- /dev/null +++ b/google-services.json @@ -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" +} diff --git a/src/custom/java/MainApp.java b/src/custom/java/MainApp.java index 3cd2f706f5..71fb750e9a 100644 --- a/src/custom/java/MainApp.java +++ b/src/custom/java/MainApp.java @@ -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 . - * - * 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 . + * @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 . + *

+ * 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 . */ 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; + } + } } diff --git a/src/custom/res/values/setup.xml b/src/custom/res/values/setup.xml new file mode 100644 index 0000000000..1a16e5a8ee --- /dev/null +++ b/src/custom/res/values/setup.xml @@ -0,0 +1,110 @@ + + + + false + + + Nextcloud + nextcloud + org.nextcloud + org.nextcloud.documents + org.nextcloud.files + nextcloud.db + nextcloud + nextcloud + nextcloud + Nextcloud + Mozilla/5.0 (Android) ownCloud-android/%1$s + + + + true + false + "https://nextcloud.com/providers" + + + + off + off + + + on + true + true + + + + @color/white + #7fC0E3 + #FFFFFF + #FFFFFF + #FFFFFF + #0082c9 + #0082c9 + @color/owncloud_blue_accent + @color/white + #D6D7D7 + @color/black + @color/owncloud_blue_accent + + + #000000 + + + #757575 + #616161 + #ECECEC + + + true + + + false + false + false + false + + + false + + + true + true + false + true + true + false + https://help.nextcloud.com/c/feature + + "mailto:" + "mailto:android@nextcloud.com" + "https://play.google.com/store/apps/details?id=com.nextcloud.client" + https://nextcloud.com/install + + + + + + https://f-droid.org/repository/browse/?fdid=com.nextcloud.android.beta + https://github.com/nextcloud/android/raw/beta/apks/latest.apk + https://play.google.com/apps/testing/com.nextcloud.client + https://f-droid.org/repository/browse/?fdid=com.nextcloud.client + http://webchat.freenode.net?channels=nextcloud-mobile + https://help.nextcloud.com/c/clients/android + https://www.transifex.com/nextcloud/nextcloud/android/ + https://github.com/nextcloud/android/blob/master/CONTRIBUTING.md + https://github.com/nextcloud/android/issues + + + cloud + + + true + + + Home + + + + diff --git a/src/main/res/values/setup.xml b/src/main/res/values/setup.xml index 144e5ca0d3..c71a3b6d16 100644 --- a/src/main/res/values/setup.xml +++ b/src/main/res/values/setup.xml @@ -98,8 +98,9 @@ cloud - - + + false Files