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
.pm
.PackageInfo
;
27 import android
.content
.pm
.PackageManager
;
28 import android
.os
.Build
;
29 import android
.os
.Bundle
;
31 import com
.owncloud
.android
.authentication
.PassCodeManager
;
32 import com
.owncloud
.android
.datamodel
.ThumbnailsCacheManager
;
33 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
34 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
.Policy
;
35 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
39 * Main Application of the project
41 * Contains methods to build the "static" strings. These strings were before constants in different
44 public class MainApp
extends Application
{
46 private static final String TAG
= MainApp
.class.getSimpleName();
48 private static final String AUTH_ON
= "on";
50 @SuppressWarnings("unused")
51 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT
= "single session per account";
52 @SuppressWarnings("unused")
53 private static final String POLICY_ALWAYS_NEW_CLIENT
= "always new client";
55 private static Context mContext
;
57 public void onCreate(){
59 MainApp
.mContext
= getApplicationContext();
61 boolean isSamlAuth
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
));
63 OwnCloudClientManagerFactory
.setUserAgent(getUserAgent());
65 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.SINGLE_SESSION_PER_ACCOUNT
);
67 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.ALWAYS_NEW_CLIENT
);
70 // initialise thumbnails cache on background thread
71 new ThumbnailsCacheManager
.InitDiskCacheTask().execute();
73 if (BuildConfig
.DEBUG
) {
75 String dataFolder
= getDataFolder();
77 // Set folder for store logs
78 Log_OC
.setLogDataFolder(dataFolder
);
80 Log_OC
.startLogging();
81 Log_OC
.d("Debug", "start logging");
84 // register global protection with pass code
85 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
) {
86 this.registerActivityLifecycleCallbacks( new ActivityLifecycleCallbacks() {
89 public void onActivityCreated(Activity activity
, Bundle savedInstanceState
) {
90 Log_OC
.d(activity
.getClass().getSimpleName(), "onCreate(Bundle) starting" );
91 PassCodeManager
.getPassCodeManager().onActivityCreated(activity
);
95 public void onActivityStarted(Activity activity
) {
96 Log_OC
.d(activity
.getClass().getSimpleName(), "onStart() starting" );
97 PassCodeManager
.getPassCodeManager().onActivityStarted(activity
);
101 public void onActivityResumed(Activity activity
) {
102 Log_OC
.d(activity
.getClass().getSimpleName(), "onResume() starting" );
106 public void onActivityPaused(Activity activity
) {
107 Log_OC
.d(activity
.getClass().getSimpleName(), "onPause() ending");
111 public void onActivityStopped(Activity activity
) {
112 Log_OC
.d(activity
.getClass().getSimpleName(), "onStop() ending" );
113 PassCodeManager
.getPassCodeManager().onActivityStopped(activity
);
117 public void onActivitySaveInstanceState(Activity activity
, Bundle outState
) {
118 Log_OC
.d(activity
.getClass().getSimpleName(), "onSaveInstanceState(Bundle) starting" );
122 public void onActivityDestroyed(Activity activity
) {
123 Log_OC
.d(activity
.getClass().getSimpleName(), "onDestroy() ending" );
129 public static Context
getAppContext() {
130 return MainApp
.mContext
;
133 // Methods to obtain Strings referring app_name
134 // From AccountAuthenticator
135 // public static final String ACCOUNT_TYPE = "owncloud";
136 public static String
getAccountType() {
137 return getAppContext().getResources().getString(R
.string
.account_type
);
140 // From AccountAuthenticator
141 // public static final String AUTHORITY = "org.owncloud";
142 public static String
getAuthority() {
143 return getAppContext().getResources().getString(R
.string
.authority
);
146 // From AccountAuthenticator
147 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
148 public static String
getAuthTokenType() {
149 return getAppContext().getResources().getString(R
.string
.authority
);
153 // public static final String DB_FILE = "owncloud.db";
154 public static String
getDBFile() {
155 return getAppContext().getResources().getString(R
.string
.db_file
);
159 // private final String mDatabaseName = "ownCloud";
160 public static String
getDBName() {
161 return getAppContext().getResources().getString(R
.string
.db_name
);
165 public static String
getDataFolder() {
166 return getAppContext().getResources().getString(R
.string
.data_folder
);
170 public static String
getLogName() {
171 return getAppContext().getResources().getString(R
.string
.log_name
);
175 public static String
getUserAgent() {
176 String appString
= getAppContext().getResources().getString(R
.string
.user_agent
);
177 String packageName
= getAppContext().getPackageName();
180 PackageInfo pInfo
= null
;
182 pInfo
= getAppContext().getPackageManager().getPackageInfo(packageName
, 0);
184 version
= pInfo
.versionName
;
186 } catch (PackageManager
.NameNotFoundException e
) {
187 Log_OC
.e(TAG
, "Trying to get packageName", e
.getCause());
190 // Mozilla/5.0 (Android) ownCloud-android/1.7.0
191 String userAgent
= String
.format(appString
, version
);