Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 35 additions & 57 deletions owncloudApp/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* ownCloud Android client application
*
* @author masensio
Expand Down Expand Up @@ -29,6 +29,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;

import com.owncloud.android.authentication.FingerprintManager;
import com.owncloud.android.authentication.PassCodeManager;
Expand All @@ -48,33 +49,34 @@

/**
* Main Application of the project
*
* <p>
* 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();
public static final String CLICK_DEV_MENU = "clickDeveloperMenu";
public static final int CLICKS_NEEDED_TO_BE_DEVELOPER = 5;

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 final int DEFAULT_0 = 0;

private static Context mContext;

// TODO Enable when "On Device" is recovered?
// TODO better place
// private static boolean mOnlyOnDevice = false;

public static String BETA_VERSION = "beta";
private static boolean mDeveloper;

public void onCreate() {
super.onCreate();
MainApp.mContext = getApplicationContext();

readIsDeveloper();

OwnCloudClient.setContext(mContext);

boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
Expand Down Expand Up @@ -111,17 +113,6 @@ public void onCreate() {
// initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute();

if (BuildConfig.DEBUG || isBeta()) {

String dataFolder = getDataFolder();

// Set folder for store logs
Log_OC.setLogDataFolder(dataFolder);

Log_OC.startLogging(Environment.getExternalStorageDirectory().getAbsolutePath());
Log_OC.d(BuildConfig.BUILD_TYPE, "start logging " + BuildConfig.VERSION_NAME);
}

// register global protection with pass code, pattern lock and fingerprint lock
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {

Expand All @@ -144,7 +135,7 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

@Override
public void onActivityStarted(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onStart() starting");
Log_OC.v(activity.getClass().getSimpleName(), "onStart() starting");
PassCodeManager.getPassCodeManager().onActivityStarted(activity);
PatternManager.getPatternManager().onActivityStarted(activity);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Expand All @@ -154,17 +145,17 @@ public void onActivityStarted(Activity activity) {

@Override
public void onActivityResumed(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onResume() starting");
Log_OC.v(activity.getClass().getSimpleName(), "onResume() starting");
}

@Override
public void onActivityPaused(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onPause() ending");
Log_OC.v(activity.getClass().getSimpleName(), "onPause() ending");
}

@Override
public void onActivityStopped(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onStop() ending");
Log_OC.v(activity.getClass().getSimpleName(), "onStop() ending");
PassCodeManager.getPassCodeManager().onActivityStopped(activity);
PatternManager.getPatternManager().onActivityStopped(activity);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Expand All @@ -179,12 +170,12 @@ public void onActivityStopped(Activity activity) {

@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
Log_OC.d(activity.getClass().getSimpleName(), "onSaveInstanceState(Bundle) starting");
Log_OC.v(activity.getClass().getSimpleName(), "onSaveInstanceState(Bundle) starting");
}

@Override
public void onActivityDestroyed(Activity activity) {
Log_OC.d(activity.getClass().getSimpleName(), "onDestroy() ending");
Log_OC.v(activity.getClass().getSimpleName(), "onDestroy() ending");
}
});
}
Expand Down Expand Up @@ -219,31 +210,10 @@ public static String getAuthTokenType() {
return getAppContext().getResources().getString(R.string.authority);
}

public static String getDBFile() {
return getAppContext().getResources().getString(R.string.db_file);
}

public static String getDBName() {
return getAppContext().getResources().getString(R.string.db_name);
}

public static String getDataFolder() {
return getAppContext().getResources().getString(R.string.data_folder);
}

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);
Expand All @@ -264,18 +234,26 @@ public static String getUserAgent() {
return String.format(appString, version);
}

public static boolean isBeta() {
boolean isBeta = false;
try {
String packageName = getAppContext().getPackageName();
PackageInfo packageInfo = getAppContext().getPackageManager().getPackageInfo(packageName, 0);
String versionName = packageInfo.versionName;
if (versionName.contains(BETA_VERSION)) {
isBeta = true;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
public static boolean isDeveloper() {
return mDeveloper;
}

public void readIsDeveloper() {
mDeveloper = BuildConfig.DEBUG || PreferenceManager.getDefaultSharedPreferences(getApplicationContext())
Comment thread
hannesa2 marked this conversation as resolved.
Resolved
.getInt(CLICK_DEV_MENU, DEFAULT_0) > CLICKS_NEEDED_TO_BE_DEVELOPER;


if (isDeveloper()) {
Comment thread
hannesa2 marked this conversation as resolved.
Resolved

String dataFolder = getDataFolder();

// Set folder for store logs
Log_OC.setLogDataFolder(dataFolder);

Log_OC.startLogging(Environment.getExternalStorageDirectory().getAbsolutePath());
Log_OC.d(BuildConfig.BUILD_TYPE, "start logging " + BuildConfig.VERSION_NAME + " " +
BuildConfig.COMMIT_SHA1);
}
return isBeta;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

/// protection against screen recording
if (!BuildConfig.DEBUG) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove import com.owncloud.android.BuildConfig;

if (!MainApp.isDeveloper()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} // else, let it go, or taking screenshots & testing will not be possible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected FingerprintManager() {
}

public void onActivityCreated(Activity activity) {
if (!BuildConfig.DEBUG) {
Comment thread
hannesa2 marked this conversation as resolved.
Resolved
if (!MainApp.isDeveloper()) {
if (isFingerPrintEnabled()) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import android.view.WindowManager;

import com.owncloud.android.MainApp;
import com.owncloud.android.lib.BuildConfig;
import com.owncloud.android.ui.activity.PassCodeActivity;

import java.util.HashSet;
Expand All @@ -40,7 +39,7 @@ public class PassCodeManager {
private static final Set<Class> sExemptOfPasscodeActivites;

static {
sExemptOfPasscodeActivites = new HashSet<Class>();
sExemptOfPasscodeActivites = new HashSet<>();
sExemptOfPasscodeActivites.add(PassCodeActivity.class);
// other activities may be exempted, if needed
}
Expand All @@ -57,14 +56,14 @@ public static PassCodeManager getPassCodeManager() {
return mPassCodeManagerInstance;
}

private Long mTimestamp = 0l;
private Long mTimestamp = 0L;
private int mVisibleActivitiesCounter = 0;

protected PassCodeManager() {
}

public void onActivityCreated(Activity activity) {
if (!BuildConfig.DEBUG) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same and in the rest of the classes where you have removed it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need of this anymore
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I mean, if is not needed anymore, please delete the import com.owncloud.android.BuildConfig; dependency at the top of the classes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this I missunderstood

if (!MainApp.isDeveloper()) {
if (isPassCodeEnabled()) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
Expand Down Expand Up @@ -133,7 +132,7 @@ public boolean isPassCodeEnabled() {
/**
* This can be used for example for onActivityResult, where you don't want to re authenticate
* again.
*
* <p>
* USE WITH CARE
*/
public void bayPassUnlockOnce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected PatternManager() {
}

public void onActivityCreated(Activity activity) {
if (!BuildConfig.DEBUG) {
if (!MainApp.isDeveloper()) {
if (isPatternEnabled()) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ private void syncAvailableOfflineFiles(List<Pair<OCFile, String>> availableOffli

File localFile = new File(localPath);

if (localFile.lastModified() <= fileForAccount.first.getLastSyncDateForData() &&
(BuildConfig.DEBUG || MainApp.isBeta())) {
if (localFile.lastModified() <= fileForAccount.first.getLastSyncDateForData() && MainApp.isDeveloper()) {
Log_OC.i(TAG, "File " + fileForAccount.first.getRemotePath() + " already synchronized " +
"in account " + fileForAccount.second + ", ignoring");
continue;
Expand All @@ -136,7 +135,7 @@ private void syncAvailableOfflineFiles(List<Pair<OCFile, String>> availableOffli
* @param accountName account to synchronize the available offline file with
*/
private void startSyncOperation(OCFile availableOfflineFile, String accountName) {
if (BuildConfig.DEBUG || MainApp.isBeta()) {
if (MainApp.isDeveloper()) {
Log_OC.i(
TAG,
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
}
}

if (BuildConfig.DEBUG || MainApp.isBeta()) {
if (MainApp.isDeveloper()) {
Log_OC.i(TAG, "Synchronizing " + mAccount.name + ", file " + mLocalFile.getRemotePath() +
": " + result.getLogMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
import java.util.ArrayList;
import java.util.List;

import static com.owncloud.android.MainApp.isBeta;
import static com.owncloud.android.MainApp.isDeveloper;
import static com.owncloud.android.db.PreferenceManager.getSortOrder;

/**
Expand Down Expand Up @@ -214,7 +214,7 @@ protected void onCreate(Bundle savedInstanceState) {

Log_OC.v(TAG, "onCreate() end");

if (getResources().getBoolean(R.bool.enable_rate_me_feature) && !isBeta()) {
if (getResources().getBoolean(R.bool.enable_rate_me_feature) && !isDeveloper()) {
AppRater.appLaunched(this, getPackageName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import com.google.android.material.snackbar.Snackbar;
import com.owncloud.android.BuildConfig;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.utils.PreferenceUtils;
Expand Down Expand Up @@ -90,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

/// protection against screen recording
if (!BuildConfig.DEBUG) {
if (!MainApp.isDeveloper()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
} // else, let it go, or taking screenshots & testing will not be possible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.andrognito.patternlockview.utils.PatternLockUtils;
import com.google.android.material.snackbar.Snackbar;
import com.owncloud.android.BuildConfig;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.utils.PreferenceUtils;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class PatternLockActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!BuildConfig.DEBUG) {
if (!MainApp.isDeveloper()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
setContentView(R.layout.activity_pattern_lock);
Expand Down
Loading