2 * ownCloud Android client application
5 * @author David A. Velasco
6 * Copyright (C) 2015 ownCloud Inc.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com
.owncloud
.android
;
23 import android
.app
.Application
;
24 import android
.content
.Context
;
25 import android
.content
.pm
.PackageInfo
;
26 import android
.content
.pm
.PackageManager
;
28 import com
.owncloud
.android
.datamodel
.ThumbnailsCacheManager
;
29 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
30 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
.Policy
;
31 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
33 * Main Application of the project
35 * Contains methods to build the "static" strings. These strings were before constants in different
38 public class MainApp
extends Application
{
40 private static final String AUTH_ON
= "on";
42 @SuppressWarnings("unused")
43 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT
= "single session per account";
44 @SuppressWarnings("unused")
45 private static final String POLICY_ALWAYS_NEW_CLIENT
= "always new client";
47 private static Context mContext
;
49 public void onCreate(){
51 MainApp
.mContext
= getApplicationContext();
53 boolean isSamlAuth
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
));
55 OwnCloudClientManagerFactory
.setUserAgent(getUserAgent());
57 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.SINGLE_SESSION_PER_ACCOUNT
);
60 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.ALWAYS_NEW_CLIENT
);
63 // initialise thumbnails cache on background thread
64 new ThumbnailsCacheManager
.InitDiskCacheTask().execute();
66 if (BuildConfig
.DEBUG
) {
68 String dataFolder
= getDataFolder();
70 // Set folder for store logs
71 Log_OC
.setLogDataFolder(dataFolder
);
73 Log_OC
.startLogging();
74 Log_OC
.d("Debug", "start logging");
78 public static Context
getAppContext() {
79 return MainApp
.mContext
;
82 // Methods to obtain Strings referring app_name
83 // From AccountAuthenticator
84 // public static final String ACCOUNT_TYPE = "owncloud";
85 public static String
getAccountType() {
86 return getAppContext().getResources().getString(R
.string
.account_type
);
89 // From AccountAuthenticator
90 // public static final String AUTHORITY = "org.owncloud";
91 public static String
getAuthority() {
92 return getAppContext().getResources().getString(R
.string
.authority
);
95 // From AccountAuthenticator
96 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
97 public static String
getAuthTokenType() {
98 return getAppContext().getResources().getString(R
.string
.authority
);
102 // public static final String DB_FILE = "owncloud.db";
103 public static String
getDBFile() {
104 return getAppContext().getResources().getString(R
.string
.db_file
);
108 // private final String mDatabaseName = "ownCloud";
109 public static String
getDBName() {
110 return getAppContext().getResources().getString(R
.string
.db_name
);
114 public static String
getDataFolder() {
115 return getAppContext().getResources().getString(R
.string
.data_folder
);
119 public static String
getLogName() {
120 return getAppContext().getResources().getString(R
.string
.log_name
);
124 public static String
getUserAgent() {
125 String appString
= getAppContext().getResources().getString(R
.string
.user_agent
);
126 String packageName
= getAppContext().getPackageName();
127 PackageInfo pInfo
= null
;
129 pInfo
= getAppContext().getPackageManager().getPackageInfo(packageName
, 0);
130 } catch (PackageManager
.NameNotFoundException e
) {
135 version
= "/" + pInfo
.versionName
;
138 // Mozilla/5.0 (Android) ownCloud /1.7.0
139 String userAgent
= appString
+ version
;