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
.Activity
;
24 import android
.app
.Application
;
25 import android
.content
.Context
;
26 import android
.content
.Intent
;
27 import android
.content
.pm
.PackageInfo
;
28 import android
.content
.pm
.PackageManager
;
29 import android
.os
.Build
;
30 import android
.os
.Bundle
;
32 import com
.owncloud
.android
.authentication
.PassCodeManager
;
33 import com
.owncloud
.android
.datamodel
.ThumbnailsCacheManager
;
34 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
35 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
.Policy
;
36 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
37 import com
.owncloud
.android
.utils
.ExceptionHandler
;
41 * Main Application of the project
43 * Contains methods to build the "static" strings. These strings were before constants in different
46 public class MainApp
extends Application
{
48 private static final String TAG
= MainApp
.class.getSimpleName();
50 private static final String AUTH_ON
= "on";
52 @SuppressWarnings("unused")
53 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT
= "single session per account";
54 @SuppressWarnings("unused")
55 private static final String POLICY_ALWAYS_NEW_CLIENT
= "always new client";
57 private static Context mContext
;
59 private static boolean mOnlyOnDevice
= false
;
62 public void onCreate(){
64 MainApp
.mContext
= getApplicationContext();
66 // Setup handler for uncaught exceptions.
67 Thread
.setDefaultUncaughtExceptionHandler(new ExceptionHandler());
69 boolean isSamlAuth
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
));
71 OwnCloudClientManagerFactory
.setUserAgent(getUserAgent());
73 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.SINGLE_SESSION_PER_ACCOUNT
);
75 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.ALWAYS_NEW_CLIENT
);
78 // initialise thumbnails cache on background thread
79 new ThumbnailsCacheManager
.InitDiskCacheTask().execute();
81 if (BuildConfig
.DEBUG
) {
83 String dataFolder
= getDataFolder();
85 // Set folder for store logs
86 Log_OC
.setLogDataFolder(dataFolder
);
88 Log_OC
.startLogging();
89 Log_OC
.d("Debug", "start logging");
92 // register global protection with pass code
93 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
) {
94 this.registerActivityLifecycleCallbacks( new ActivityLifecycleCallbacks() {
97 public void onActivityCreated(Activity activity
, Bundle savedInstanceState
) {
98 Log_OC
.d(activity
.getClass().getSimpleName(), "onCreate(Bundle) starting" );
99 PassCodeManager
.getPassCodeManager().onActivityCreated(activity
);
103 public void onActivityStarted(Activity activity
) {
104 Log_OC
.d(activity
.getClass().getSimpleName(), "onStart() starting" );
105 PassCodeManager
.getPassCodeManager().onActivityStarted(activity
);
109 public void onActivityResumed(Activity activity
) {
110 Log_OC
.d(activity
.getClass().getSimpleName(), "onResume() starting" );
114 public void onActivityPaused(Activity activity
) {
115 Log_OC
.d(activity
.getClass().getSimpleName(), "onPause() ending");
119 public void onActivityStopped(Activity activity
) {
120 Log_OC
.d(activity
.getClass().getSimpleName(), "onStop() ending" );
121 PassCodeManager
.getPassCodeManager().onActivityStopped(activity
);
125 public void onActivitySaveInstanceState(Activity activity
, Bundle outState
) {
126 Log_OC
.d(activity
.getClass().getSimpleName(), "onSaveInstanceState(Bundle) starting" );
130 public void onActivityDestroyed(Activity activity
) {
131 Log_OC
.d(activity
.getClass().getSimpleName(), "onDestroy() ending" );
137 public static Context
getAppContext() {
138 return MainApp
.mContext
;
141 // Methods to obtain Strings referring app_name
142 // From AccountAuthenticator
143 // public static final String ACCOUNT_TYPE = "owncloud";
144 public static String
getAccountType() {
145 return getAppContext().getResources().getString(R
.string
.account_type
);
148 // From AccountAuthenticator
149 // public static final String AUTHORITY = "org.owncloud";
150 public static String
getAuthority() {
151 return getAppContext().getResources().getString(R
.string
.authority
);
154 // From AccountAuthenticator
155 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
156 public static String
getAuthTokenType() {
157 return getAppContext().getResources().getString(R
.string
.authority
);
161 // public static final String DB_FILE = "owncloud.db";
162 public static String
getDBFile() {
163 return getAppContext().getResources().getString(R
.string
.db_file
);
167 // private final String mDatabaseName = "ownCloud";
168 public static String
getDBName() {
169 return getAppContext().getResources().getString(R
.string
.db_name
);
173 public static String
getDataFolder() {
174 return getAppContext().getResources().getString(R
.string
.data_folder
);
178 public static String
getLogName() {
179 return getAppContext().getResources().getString(R
.string
.log_name
);
182 public static void showOnlyFilesOnDevice(boolean state
){
183 mOnlyOnDevice
= state
;
186 public static boolean getOnlyOnDevice(){
187 return mOnlyOnDevice
;
191 public static String
getUserAgent() {
192 String appString
= getAppContext().getResources().getString(R
.string
.user_agent
);
193 String packageName
= getAppContext().getPackageName();
196 PackageInfo pInfo
= null
;
198 pInfo
= getAppContext().getPackageManager().getPackageInfo(packageName
, 0);
200 version
= pInfo
.versionName
;
202 } catch (PackageManager
.NameNotFoundException e
) {
203 Log_OC
.e(TAG
, "Trying to get packageName", e
.getCause());
206 // Mozilla/5.0 (Android) ownCloud-android/1.7.0
207 String userAgent
= String
.format(appString
, version
);