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
.AuthenticatorActivity
;
33 import com
.owncloud
.android
.authentication
.PassCodeManager
;
34 import com
.owncloud
.android
.datamodel
.ThumbnailsCacheManager
;
35 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
;
36 import com
.owncloud
.android
.lib
.common
.OwnCloudClientManagerFactory
.Policy
;
37 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
38 import com
.owncloud
.android
.ui
.activity
.PinCodeActivity
;
40 import java
.util
.HashSet
;
44 * Main Application of the project
46 * Contains methods to build the "static" strings. These strings were before constants in different
49 public class MainApp
extends Application
{
51 private static final String TAG
= MainApp
.class.getSimpleName();
53 private static final String AUTH_ON
= "on";
55 @SuppressWarnings("unused")
56 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT
= "single session per account";
57 @SuppressWarnings("unused")
58 private static final String POLICY_ALWAYS_NEW_CLIENT
= "always new client";
60 private static Context mContext
;
62 public void onCreate(){
64 MainApp
.mContext
= getApplicationContext();
66 boolean isSamlAuth
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
));
68 OwnCloudClientManagerFactory
.setUserAgent(getUserAgent());
70 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.SINGLE_SESSION_PER_ACCOUNT
);
72 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.ALWAYS_NEW_CLIENT
);
75 // initialise thumbnails cache on background thread
76 new ThumbnailsCacheManager
.InitDiskCacheTask().execute();
78 if (BuildConfig
.DEBUG
) {
80 String dataFolder
= getDataFolder();
82 // Set folder for store logs
83 Log_OC
.setLogDataFolder(dataFolder
);
85 Log_OC
.startLogging();
86 Log_OC
.d("Debug", "start logging");
89 // register global protection with pass code
90 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
) {
91 this.registerActivityLifecycleCallbacks( new ActivityLifecycleCallbacks() {
94 public void onActivityCreated(Activity activity
, Bundle savedInstanceState
) {
95 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onCreate(Bundle)" );
99 public void onActivityStarted(Activity activity
) {
100 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onStart()" );
101 PassCodeManager
.getPassCodeManager().onActivityStarted(activity
);
105 public void onActivityResumed(Activity activity
) {
106 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onResume()" );
110 public void onActivityPaused(Activity activity
) {
111 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onPause()");
115 public void onActivityStopped(Activity activity
) {
116 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onStop()" );
117 PassCodeManager
.getPassCodeManager().onActivityStopped(activity
);
121 public void onActivitySaveInstanceState(Activity activity
, Bundle outState
) {
122 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onSaveInstanceState(Bundle)" );
127 public void onActivityDestroyed(Activity activity
) {
128 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onDestroy()" );
135 public static Context
getAppContext() {
136 return MainApp
.mContext
;
139 // Methods to obtain Strings referring app_name
140 // From AccountAuthenticator
141 // public static final String ACCOUNT_TYPE = "owncloud";
142 public static String
getAccountType() {
143 return getAppContext().getResources().getString(R
.string
.account_type
);
146 // From AccountAuthenticator
147 // public static final String AUTHORITY = "org.owncloud";
148 public static String
getAuthority() {
149 return getAppContext().getResources().getString(R
.string
.authority
);
152 // From AccountAuthenticator
153 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
154 public static String
getAuthTokenType() {
155 return getAppContext().getResources().getString(R
.string
.authority
);
159 // public static final String DB_FILE = "owncloud.db";
160 public static String
getDBFile() {
161 return getAppContext().getResources().getString(R
.string
.db_file
);
165 // private final String mDatabaseName = "ownCloud";
166 public static String
getDBName() {
167 return getAppContext().getResources().getString(R
.string
.db_name
);
171 public static String
getDataFolder() {
172 return getAppContext().getResources().getString(R
.string
.data_folder
);
176 public static String
getLogName() {
177 return getAppContext().getResources().getString(R
.string
.log_name
);
181 public static String
getUserAgent() {
182 String appString
= getAppContext().getResources().getString(R
.string
.user_agent
);
183 String packageName
= getAppContext().getPackageName();
186 PackageInfo pInfo
= null
;
188 pInfo
= getAppContext().getPackageManager().getPackageInfo(packageName
, 0);
190 version
= pInfo
.versionName
;
192 } catch (PackageManager
.NameNotFoundException e
) {
193 Log_OC
.e(TAG
, "Trying to get packageName", e
.getCause());
196 // Mozilla/5.0 (Android) ownCloud-android/1.7.0
197 String userAgent
= String
.format(appString
, version
);