forked from owncloud/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainApp.java
More file actions
209 lines (170 loc) · 7.36 KB
/
MainApp.java
File metadata and controls
209 lines (170 loc) · 7.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/**
* 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,
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.owncloud.android;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import com.owncloud.android.authentication.PassCodeManager;
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
*/
public class MainApp extends Application {
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;
// TODO Enable when "On Device" is recovered?
// TODO better place
// private static boolean mOnlyOnDevice = false;
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");
}
// register global protection with pass code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
this.registerActivityLifecycleCallbacks( new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
Log_OC.d(activity.getClass().getSimpleName(), "onCreate(Bundle) starting" );
PassCodeManager.getPassCodeManager().onActivityCreated(activity);
}
@Override
public void onActivityStarted(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onStart() starting" );
PassCodeManager.getPassCodeManager().onActivityStarted(activity);
}
@Override
public void onActivityResumed(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onResume() starting" );
}
@Override
public void onActivityPaused(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onPause() ending");
}
@Override
public void onActivityStopped(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onStop() ending" );
PassCodeManager.getPassCodeManager().onActivityStopped(activity);
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
Log_OC.d(activity.getClass().getSimpleName(), "onSaveInstanceState(Bundle) starting" );
}
@Override
public void onActivityDestroyed(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onDestroy() ending" );
}
});
}
}
public static Context getAppContext() {
return MainApp.mContext;
}
// Methods to obtain Strings referring app_name
// From AccountAuthenticator
// public static final String ACCOUNT_TYPE = "owncloud";
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() {
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);
}
// data_folder
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);
}
// TODO Enable when "On Device" is recovered ?
// public static void showOnlyFilesOnDevice(boolean state){
// mOnlyOnDevice = state;
// }
//
// public static boolean getOnlyOnDevice(){
// return mOnlyOnDevice;
// }
// 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;
}
}