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 import org
.apache
.commons
.codec
.StringEncoder
;
36 * Main Application of the project
38 * Contains methods to build the "static" strings. These strings were before constants in different
41 public class MainApp
extends Application
{
43 private static final String TAG
= MainApp
.class.getSimpleName();
45 private static final String AUTH_ON
= "on";
47 @SuppressWarnings("unused")
48 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT
= "single session per account";
49 @SuppressWarnings("unused")
50 private static final String POLICY_ALWAYS_NEW_CLIENT
= "always new client";
52 private static Context mContext
;
54 public void onCreate(){
56 MainApp
.mContext
= getApplicationContext();
58 boolean isSamlAuth
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
));
60 OwnCloudClientManagerFactory
.setUserAgent(getUserAgent());
62 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.SINGLE_SESSION_PER_ACCOUNT
);
64 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.ALWAYS_NEW_CLIENT
);
67 // initialise thumbnails cache on background thread
68 new ThumbnailsCacheManager
.InitDiskCacheTask().execute();
70 if (BuildConfig
.DEBUG
) {
72 String dataFolder
= getDataFolder();
74 // Set folder for store logs
75 Log_OC
.setLogDataFolder(dataFolder
);
77 Log_OC
.startLogging();
78 Log_OC
.d("Debug", "start logging");
82 public static Context
getAppContext() {
83 return MainApp
.mContext
;
86 // Methods to obtain Strings referring app_name
87 // From AccountAuthenticator
88 // public static final String ACCOUNT_TYPE = "owncloud";
89 public static String
getAccountType() {
90 return getAppContext().getResources().getString(R
.string
.account_type
);
93 // From AccountAuthenticator
94 // public static final String AUTHORITY = "org.owncloud";
95 public static String
getAuthority() {
96 return getAppContext().getResources().getString(R
.string
.authority
);
99 // From AccountAuthenticator
100 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
101 public static String
getAuthTokenType() {
102 return getAppContext().getResources().getString(R
.string
.authority
);
106 // public static final String DB_FILE = "owncloud.db";
107 public static String
getDBFile() {
108 return getAppContext().getResources().getString(R
.string
.db_file
);
112 // private final String mDatabaseName = "ownCloud";
113 public static String
getDBName() {
114 return getAppContext().getResources().getString(R
.string
.db_name
);
118 public static String
getDataFolder() {
119 return getAppContext().getResources().getString(R
.string
.data_folder
);
123 public static String
getLogName() {
124 return getAppContext().getResources().getString(R
.string
.log_name
);
128 public static String
getUserAgent() {
129 String appString
= getAppContext().getResources().getString(R
.string
.user_agent
);
130 String packageName
= getAppContext().getPackageName();
133 PackageInfo pInfo
= null
;
135 pInfo
= getAppContext().getPackageManager().getPackageInfo(packageName
, 0);
137 version
= pInfo
.versionName
;
139 } catch (PackageManager
.NameNotFoundException e
) {
140 Log_OC
.e(TAG
, "Trying to get packageName", e
.getCause());
143 // Mozilla/5.0 (Android) ownCloud-android/1.7.0
144 String userAgent
= String
.format(appString
, version
);