37a3e6ff81258608c3cc1def76120904a8f0185b
[pub/Android/ownCloud.git] / src / com / owncloud / android / MainApp.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17 package com.owncloud.android;
18
19 import android.app.Application;
20 import android.content.Context;
21
22 import com.owncloud.android.authentication.AccountUtils;
23 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
24 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
25 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
26 import com.owncloud.android.lib.common.utils.Log_OC;
27 /**
28 * Main Application of the project
29 *
30 * Contains methods to build the "static" strings. These strings were before constants in different
31 * classes
32 *
33 * @author masensio
34 * @author David A. Velasco
35 */
36 public class MainApp extends Application {
37
38 private static final String AUTH_ON = "on";
39
40 @SuppressWarnings("unused")
41 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account";
42 @SuppressWarnings("unused")
43 private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client";
44
45 private static Context mContext;
46
47 public void onCreate(){
48 super.onCreate();
49 MainApp.mContext = getApplicationContext();
50
51 boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
52
53 if (isSamlAuth) {
54 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
55
56 } else {
57 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
58 }
59
60 // initialise thumbnails cache on background thread
61 new ThumbnailsCacheManager.InitDiskCacheTask(AccountUtils.getCurrentOwnCloudAccount(mContext),
62 mContext).execute();
63
64 if (BuildConfig.DEBUG) {
65
66 String dataFolder = getDataFolder();
67
68 // Set folder for store logs
69 Log_OC.setLogDataFolder(dataFolder);
70
71 Log_OC.startLogging();
72 Log_OC.d("Debug", "start logging");
73 }
74 }
75
76 public static Context getAppContext() {
77 return MainApp.mContext;
78 }
79
80 // Methods to obtain Strings referring app_name
81 // From AccountAuthenticator
82 // public static final String ACCOUNT_TYPE = "owncloud";
83 public static String getAccountType() {
84 return getAppContext().getResources().getString(R.string.account_type);
85 }
86
87 // From AccountAuthenticator
88 // public static final String AUTHORITY = "org.owncloud";
89 public static String getAuthority() {
90 return getAppContext().getResources().getString(R.string.authority);
91 }
92
93 // From AccountAuthenticator
94 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
95 public static String getAuthTokenType() {
96 return getAppContext().getResources().getString(R.string.authority);
97 }
98
99 // From ProviderMeta
100 // public static final String DB_FILE = "owncloud.db";
101 public static String getDBFile() {
102 return getAppContext().getResources().getString(R.string.db_file);
103 }
104
105 // From ProviderMeta
106 // private final String mDatabaseName = "ownCloud";
107 public static String getDBName() {
108 return getAppContext().getResources().getString(R.string.db_name);
109 }
110
111 // data_folder
112 public static String getDataFolder() {
113 return getAppContext().getResources().getString(R.string.data_folder);
114 }
115
116 // log_name
117 public static String getLogName() {
118 return getAppContext().getResources().getString(R.string.log_name);
119 }
120
121 }