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
.PinCheck
;
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 private static final Set
<String
> sExemptOfPasscodeActivites
;
58 sExemptOfPasscodeActivites
= new HashSet
<String
>();
59 sExemptOfPasscodeActivites
.add(AuthenticatorActivity
.class.getCanonicalName());
60 sExemptOfPasscodeActivites
.add(PinCodeActivity
.class.getCanonicalName());
63 @SuppressWarnings("unused")
64 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT
= "single session per account";
65 @SuppressWarnings("unused")
66 private static final String POLICY_ALWAYS_NEW_CLIENT
= "always new client";
68 private static Context mContext
;
70 public void onCreate(){
72 MainApp
.mContext
= getApplicationContext();
74 boolean isSamlAuth
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
));
76 OwnCloudClientManagerFactory
.setUserAgent(getUserAgent());
78 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.SINGLE_SESSION_PER_ACCOUNT
);
80 OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.ALWAYS_NEW_CLIENT
);
83 // initialise thumbnails cache on background thread
84 new ThumbnailsCacheManager
.InitDiskCacheTask().execute();
86 if (BuildConfig
.DEBUG
) {
88 String dataFolder
= getDataFolder();
90 // Set folder for store logs
91 Log_OC
.setLogDataFolder(dataFolder
);
93 Log_OC
.startLogging();
94 Log_OC
.d("Debug", "start logging");
97 // register global protection with pass code
98 if (Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
) {
99 this.registerActivityLifecycleCallbacks( new ActivityLifecycleCallbacks() {
102 public void onActivityCreated(Activity activity
, Bundle savedInstanceState
) {
103 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onCreate(Bundle)" );
107 public void onActivityStarted(Activity activity
) {
108 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onStart()" );
112 public void onActivityResumed(Activity activity
) {
113 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onResume()" );
114 if (!sExemptOfPasscodeActivites
.contains(activity
.getClass().getCanonicalName()) &&
115 PinCheck
.checkIfPinEntry()
117 Intent i
= new Intent(MainApp
.getAppContext(), PinCodeActivity
.class);
118 //i.putExtra(PinCodeActivity.EXTRA_ACTIVITY, activity.getClass().getSimpleName());
119 i
.setAction(PinCodeActivity
.ACTION_REQUEST
);
120 activity
.startActivity(i
);
125 public void onActivityPaused(Activity activity
) {
126 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onPause()");
127 PinCheck
.setUnlockTimestamp();
131 public void onActivityStopped(Activity activity
) {
132 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onStop()" );
137 public void onActivitySaveInstanceState(Activity activity
, Bundle outState
) {
138 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onSaveInstanceState(Bundle)" );
143 public void onActivityDestroyed(Activity activity
) {
144 Log_OC
.d(TAG
, activity
.getClass().getSimpleName() + " in onDestroy()" );
151 public static Context
getAppContext() {
152 return MainApp
.mContext
;
155 // Methods to obtain Strings referring app_name
156 // From AccountAuthenticator
157 // public static final String ACCOUNT_TYPE = "owncloud";
158 public static String
getAccountType() {
159 return getAppContext().getResources().getString(R
.string
.account_type
);
162 // From AccountAuthenticator
163 // public static final String AUTHORITY = "org.owncloud";
164 public static String
getAuthority() {
165 return getAppContext().getResources().getString(R
.string
.authority
);
168 // From AccountAuthenticator
169 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
170 public static String
getAuthTokenType() {
171 return getAppContext().getResources().getString(R
.string
.authority
);
175 // public static final String DB_FILE = "owncloud.db";
176 public static String
getDBFile() {
177 return getAppContext().getResources().getString(R
.string
.db_file
);
181 // private final String mDatabaseName = "ownCloud";
182 public static String
getDBName() {
183 return getAppContext().getResources().getString(R
.string
.db_name
);
187 public static String
getDataFolder() {
188 return getAppContext().getResources().getString(R
.string
.data_folder
);
192 public static String
getLogName() {
193 return getAppContext().getResources().getString(R
.string
.log_name
);
197 public static String
getUserAgent() {
198 String appString
= getAppContext().getResources().getString(R
.string
.user_agent
);
199 String packageName
= getAppContext().getPackageName();
202 PackageInfo pInfo
= null
;
204 pInfo
= getAppContext().getPackageManager().getPackageInfo(packageName
, 0);
206 version
= pInfo
.versionName
;
208 } catch (PackageManager
.NameNotFoundException e
) {
209 Log_OC
.e(TAG
, "Trying to get packageName", e
.getCause());
212 // Mozilla/5.0 (Android) ownCloud-android/1.7.0
213 String userAgent
= String
.format(appString
, version
);