X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/44ffdc3fb18b4e229cd10a2c4b521ac1e3d616f8..5ca1b94865fcb868c44fe11df01ba17d33673b17:/src/com/owncloud/android/MainApp.java?ds=inline diff --git a/src/com/owncloud/android/MainApp.java b/src/com/owncloud/android/MainApp.java index 85718ff6..760a5e79 100644 --- a/src/com/owncloud/android/MainApp.java +++ b/src/com/owncloud/android/MainApp.java @@ -1,5 +1,9 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. +/** + * ownCloud Android client application + * + * @author masensio + * @author David A. Velasco + * Copyright (C) 2015 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -18,20 +22,59 @@ package com.owncloud.android; import android.app.Application; import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; + +import com.owncloud.android.datamodel.ThumbnailsCacheManager; +import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; +import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy; +import com.owncloud.android.lib.common.utils.Log_OC; + /** * Main Application of the project * - * Contains methods to build the "static" strings. These strings were before constants in different classes - * - * @author masensio + * Contains methods to build the "static" strings. These strings were before constants in different + * classes */ public class MainApp extends Application { - private static Context mContext; + private static final String TAG = MainApp.class.getSimpleName(); + private static final String AUTH_ON = "on"; + + @SuppressWarnings("unused") + private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account"; + @SuppressWarnings("unused") + private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client"; + + private static Context mContext; + public void onCreate(){ super.onCreate(); MainApp.mContext = getApplicationContext(); + + boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso)); + + OwnCloudClientManagerFactory.setUserAgent(getUserAgent()); + if (isSamlAuth) { + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT); + } else { + OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT); + } + + // initialise thumbnails cache on background thread + new ThumbnailsCacheManager.InitDiskCacheTask().execute(); + + if (BuildConfig.DEBUG) { + + String dataFolder = getDataFolder(); + + // Set folder for store logs + Log_OC.setLogDataFolder(dataFolder); + + Log_OC.startLogging(); + Log_OC.d("Debug", "start logging"); + } } public static Context getAppContext() { @@ -44,7 +87,7 @@ public class MainApp extends Application { public static String getAccountType() { return getAppContext().getResources().getString(R.string.account_type); } - + // From AccountAuthenticator // public static final String AUTHORITY = "org.owncloud"; public static String getAuthority() { @@ -78,4 +121,26 @@ public class MainApp extends Application { public static String getLogName() { return getAppContext().getResources().getString(R.string.log_name); } + + // user agent + public static String getUserAgent() { + String appString = getAppContext().getResources().getString(R.string.user_agent); + String packageName = getAppContext().getPackageName(); + String version = ""; + + PackageInfo pInfo = null; + try { + pInfo = getAppContext().getPackageManager().getPackageInfo(packageName, 0); + if (pInfo != null) { + version = pInfo.versionName; + } + } catch (PackageManager.NameNotFoundException e) { + Log_OC.e(TAG, "Trying to get packageName", e.getCause()); + } + + // Mozilla/5.0 (Android) ownCloud-android/1.7.0 + String userAgent = String.format(appString, version); + + return userAgent; + } }