diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 41f9436cbc3412da861b3e2936a784926480192a..2e4362555caa79a75052fdacbfcad8ac132d1227 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -109,6 +109,7 @@ + diff --git a/app/src/main/java/foundation/e/drive/EdriveApplication.java b/app/src/main/java/foundation/e/drive/EdriveApplication.java index 493b027c47bdd1fdeba3d48521d1311b98855fee..069c05090eed1d7ed22b0ea2f869fe4c521a2a43 100644 --- a/app/src/main/java/foundation/e/drive/EdriveApplication.java +++ b/app/src/main/java/foundation/e/drive/EdriveApplication.java @@ -21,6 +21,7 @@ import foundation.e.drive.FileObservers.RecursiveFileObserver; import foundation.e.drive.services.SynchronizationService; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; +import foundation.e.drive.utils.ReleaseTree; import timber.log.Timber; import static timber.log.Timber.DebugTree; @@ -42,7 +43,7 @@ public class EdriveApplication extends Application { Timber.plant(new DebugTree()); } else { //Not handled yet - //Timber.plant(new ReleaseTree()); + Timber.plant(new ReleaseTree()); } Timber.tag("EdriveApplication"); diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java index 109936ae769337ef37abbda1013e8bee2b3985e9..7acb1ea8d9ab541274c6f37ec6b030d409508d5b 100644 --- a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java +++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java @@ -24,7 +24,6 @@ import android.content.ComponentName; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.util.Log; import android.view.View; import androidx.appcompat.app.AppCompatActivity; @@ -38,9 +37,9 @@ import foundation.e.drive.databinding.ActivityAccountsBinding; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.DavClientProvider; import foundation.e.drive.widgets.EDriveWidget; +import timber.log.Timber; public class AccountsActivity extends AppCompatActivity { - private static final String TAG = AccountsActivity.class.getSimpleName(); public static final String NON_OFFICIAL_AVATAR_PATH = "/index.php/avatar/"; private static final String ACCOUNT_SETTINGS = @@ -51,6 +50,7 @@ public class AccountsActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Timber.tag(AccountsActivity.class.getSimpleName()); binding = ActivityAccountsBinding.inflate(getLayoutInflater()); setContentView(binding.getRoot()); @@ -98,7 +98,7 @@ public class AccountsActivity extends AppCompatActivity { totalShownQuota = CommonUtils.humanReadableByteCountBin(totalQuotaLong); } } catch (NumberFormatException ignored) { - Log.i(TAG, "Bad totalQuotaLong " + totalQuota); + Timber.i("Bad totalQuotaLong " + totalQuota); } try { @@ -107,7 +107,7 @@ public class AccountsActivity extends AppCompatActivity { usedShownQuota = CommonUtils.humanReadableByteCountBin(usedQuotaLong); } } catch (NumberFormatException ignore) { - Log.i(TAG, "Bad usedQuotaLong " + usedQuota); + Timber.i("Bad usedQuotaLong " + usedQuota); } binding.plan.setText(getString(R.string.free_plan, totalShownQuota)); diff --git a/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java b/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java index afb752ccddb84f6cded82385951762dc4ddb82ef..9e0e10b4cefa179122314a468db9202218aa8e2b 100644 --- a/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java +++ b/app/src/main/java/foundation/e/drive/receivers/DebugCmdReceiver.java @@ -14,6 +14,7 @@ import android.util.Log; import foundation.e.drive.database.DbHelper; import foundation.e.drive.services.ObserverService; +import foundation.e.drive.utils.ReleaseTree; import timber.log.Timber; /** @@ -24,7 +25,8 @@ public class DebugCmdReceiver extends BroadcastReceiver { public static final String ACTION_FORCE_SYNC = "foundation.e.drive.action.FORCE_SYNC"; public static final String ACTION_DUMP_DATABASE = "foundation.e.drive.action.DUMP_DATABASE"; - + public static final String ACTION_FULL_LOG_ON_PROD = "foundation.e.drive.action.FULL_LOG_ON_PROD"; + private static final String FULL_LOG_ENABLE_KEY = "full_log_enable"; @Override public void onReceive(Context context, Intent intent) { Timber.tag(DebugCmdReceiver.class.getSimpleName()).v("onReceive"); @@ -37,6 +39,11 @@ public class DebugCmdReceiver extends BroadcastReceiver { Timber.d("Dump database intent received"); DbHelper.dumpDatabase(context); break; + case ACTION_FULL_LOG_ON_PROD: + final boolean allow_full_log = intent.getBooleanExtra(FULL_LOG_ENABLE_KEY, false); + ReleaseTree.allowDebugLogOnProd(allow_full_log); + Timber.d("Allow full log on prod: %s", allow_full_log); + break; default: break; } diff --git a/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java new file mode 100644 index 0000000000000000000000000000000000000000..26b62d750519446a86d36b86359df48728473dbf --- /dev/null +++ b/app/src/main/java/foundation/e/drive/utils/ReleaseTree.java @@ -0,0 +1,43 @@ +package foundation.e.drive.utils; + +import android.util.Log; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import timber.log.Timber; + +public class ReleaseTree extends Timber.Tree { + private static boolean debugEnable = false; + + public static void allowDebugLogOnProd(boolean allow) { + debugEnable = allow; + } + + @Override + protected void log(int priority, @Nullable String tag, @NonNull String message, @Nullable Throwable throwable) { + if (!debugEnable && priority < Log.INFO ) { + return; + } + switch (priority) { + case Log.VERBOSE: + Log.v(tag, message, throwable); + break; + case Log.DEBUG: + Log.d(tag, message, throwable); + break; + case Log.INFO: + Log.i(tag, message, throwable); + break; + case Log.WARN: + Log.w(tag, message, throwable); + break; + case Log.ERROR: + Log.w(tag, message, throwable); + break; + case Log.ASSERT: + Log.wtf(tag, message, throwable); + break; + } + } +} diff --git a/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java b/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java index 957d5eebe71c44406ef2e93dac95ff16b2597819..6fcc83c52799047f65a5a33e0c97b67d625c2c3f 100644 --- a/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java +++ b/app/src/main/java/foundation/e/drive/work/AccountUserInfoWorker.java @@ -23,7 +23,6 @@ import android.appwidget.AppWidgetManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.util.Log; import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; @@ -48,13 +47,13 @@ import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.DavClientProvider; import foundation.e.drive.widgets.EDriveWidget; +import timber.log.Timber; /** * @author vincent Bourgmayer * @author TheScarastic */ public class AccountUserInfoWorker extends Worker { - private static final String TAG = AccountUserInfoWorker.class.getSimpleName(); public static final String UNIQUE_WORK_NAME = "AccountUserInfoWorker"; private final AccountManager accountManager; private final GetUserInfoRemoteOperation GetUserInfoRemoteOperation = new GetUserInfoRemoteOperation(); @@ -64,6 +63,7 @@ public class AccountUserInfoWorker extends Worker { public AccountUserInfoWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); + Timber.tag(AccountUserInfoWorker.class.getSimpleName()); mContext = context; accountManager = AccountManager.get(context); } @@ -100,7 +100,7 @@ public class AccountUserInfoWorker extends Worker { final String userId = userInfo.getId(); client.setUserId(userId); AccountManager.get(mContext).setUserData(account, ACCOUNT_USER_ID_KEY, userId); - Log.v(TAG, "UserId "+ userId +" saved for account"); + Timber.v("UserId %s saved for account", userId); } final Quota userQuota = userInfo.getQuota(); final double relativeQuota = userQuota.getRelative(); @@ -117,10 +117,10 @@ public class AccountUserInfoWorker extends Worker { accountManager.setUserData(account, ACCOUNT_DATA_USED_QUOTA_KEY, "" + userQuota.getUsed()); addNotifAboutQuota(relativeQuota); - Log.d(TAG+"fetchUserInfo()", "Success"); + Timber.d("fetchUserInfo(): success"); return true; } - Log.d(TAG+"fetchUserInfo()", "Failure"); + Timber.d("fetchUserInfo(): failure"); return false; } @@ -196,7 +196,7 @@ public class AccountUserInfoWorker extends Worker { } } accountManager.setUserData(account, ACCOUNT_DATA_ALIAS_KEY, aliases); - Log.d(TAG+"fetchAliases()", "Success"); + Timber.d("fetchAliases(): success"); return true; } diff --git a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java b/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java index 2d995c642d3bbfb15c4c266abc659aaea804ea0b..280051993622c5107fd709dda9ee0aa6df216366 100644 --- a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java +++ b/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java @@ -12,7 +12,6 @@ import android.accounts.Account; import android.accounts.AccountManager; import android.content.Context; import android.content.SharedPreferences; -import android.util.Log; import androidx.annotation.NonNull; import androidx.work.Data; @@ -31,6 +30,7 @@ import foundation.e.drive.models.SyncedFolder; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; import foundation.e.drive.utils.DavClientProvider; +import timber.log.Timber; /** * /!\ Doesn't require NextcloudClient yet @@ -38,7 +38,6 @@ import foundation.e.drive.utils.DavClientProvider; * @author Vincent Bourgmayer */ public class CreateRemoteFolderWorker extends Worker { - private static final String TAG = CreateRemoteFolderWorker.class.getSimpleName(); public static final String DATA_KEY_ID="id"; public static final String DATA_KEY_LIBELLE="libelle"; public static final String DATA_KEY_LOCAL_PATH="localPath"; @@ -52,6 +51,7 @@ public class CreateRemoteFolderWorker extends Worker { public CreateRemoteFolderWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); + Timber.tag(CreateRemoteFolderWorker.class.getSimpleName()); } @NonNull @@ -60,18 +60,18 @@ public class CreateRemoteFolderWorker extends Worker { final Context context = getApplicationContext(); final Account account = getAccount(); if (account == null) { - Log.e(TAG, "Can't get valid account: stop everything"); + Timber.e("doWork(): Can't get valid account"); return Result.failure(); } final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); if (!CommonUtils.haveNetworkConnection(context, meteredNetworkAllowed)) { - Log.e(TAG, "Can't create remote folder because there is no usable connection"); + Timber.d("doWork(): no usable connection"); return Result.retry(); } final SyncedFolder syncedFolder = getSyncedFolderFromData(); - Log.d(TAG, "doWork() for :"+syncedFolder.getLocalFolder()); + Timber.v("doWork() for : %s", syncedFolder.getLocalFolder()); final File folder = new File(syncedFolder.getLocalFolder() ); if (!folder.exists()) { folder.mkdirs(); @@ -81,7 +81,7 @@ public class CreateRemoteFolderWorker extends Worker { //final NextcloudClient client = DavClientProvider.getInstance().getNcClientInstance(account, context); final OwnCloudClient client = DavClientProvider.getInstance().getClientInstance(account, context); if (client == null) { - Log.e(TAG, "Can't get OwnCloudClient."); + Timber.d("doWork(): Can't get OwnCloudClient"); return Result.retry(); } @@ -90,9 +90,7 @@ public class CreateRemoteFolderWorker extends Worker { final RemoteOperationResult result = mkcolRequest.execute(client); if (result.isSuccess() || result.getCode() == RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS) { - if(DbHelper.insertSyncedFolder(syncedFolder, context) >= 0 ) { - Log.d(TAG, "Insertion in DB succeed"); - } + DbHelper.insertSyncedFolder(syncedFolder, context); return Result.success(); } diff --git a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java index c112d36e6b4b7eb830b792b72f4c60cd980578bc..4898f79bfc3c6954a7330b0e05f6bc2cd5acc855 100644 --- a/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FirstStartWorker.java @@ -12,7 +12,6 @@ import static foundation.e.drive.utils.AppConstants.INITIALFOLDERS_NUMBER; import android.content.Context; import android.content.Intent; -import android.util.Log; import androidx.annotation.NonNull; import androidx.work.WorkManager; @@ -22,6 +21,7 @@ import androidx.work.WorkerParameters; import foundation.e.drive.EdriveApplication; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; +import timber.log.Timber; /** * This class start eDrive work after initialization. @@ -30,15 +30,15 @@ import foundation.e.drive.utils.CommonUtils; * @author Vincent Bourgmayer */ public class FirstStartWorker extends Worker { - private static final String TAG = FirstStartWorker.class.getSimpleName(); public FirstStartWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); + Timber.tag(FirstStartWorker.class.getSimpleName()); } @NonNull @Override public Result doWork() { - Log.d(TAG, "doWork()"); + Timber.v("doWork()"); final Context appContext = getApplicationContext(); appContext.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE) diff --git a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java index bc895434786a2401483313a4f9e0d2463ffd7394..2dd503bfb861d2b04fe0d352e3845533224b44e6 100644 --- a/app/src/main/java/foundation/e/drive/work/FullScanWorker.java +++ b/app/src/main/java/foundation/e/drive/work/FullScanWorker.java @@ -13,7 +13,6 @@ import android.accounts.AccountManager; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.util.Log; import androidx.annotation.NonNull; import androidx.work.Worker; @@ -22,6 +21,7 @@ import androidx.work.WorkerParameters; import foundation.e.drive.services.ObserverService; import foundation.e.drive.utils.AppConstants; import foundation.e.drive.utils.CommonUtils; +import timber.log.Timber; /** * As a first step, this class must replace foundation.e.drive.jobs.ScannerJob @@ -33,17 +33,17 @@ import foundation.e.drive.utils.CommonUtils; * @author Vincent Bourgmayer */ public class FullScanWorker extends Worker { - private final static String TAG = FullScanWorker.class.getSimpleName(); public final static String UNIQUE_WORK_NAME = "FullScan"; public FullScanWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) { super(context, workerParams); + Timber.tag(FullScanWorker.class.getSimpleName()); } @NonNull @Override public Result doWork() { - Log.d(TAG, "doWork(): going to send intent to ObserverService"); + Timber.v("doWork(): going to send intent to ObserverService"); final SharedPreferences prefs = getApplicationContext().getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE); final String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, ""); @@ -55,7 +55,7 @@ public class FullScanWorker extends Worker { final Intent observerServiceIntent = new Intent(this.getApplicationContext(), ObserverService.class); this.getApplicationContext().startService(observerServiceIntent); } else { - Log.w(TAG, "Intent for ObserverService not send : account is null or \"settings sync\" & \"media sync\" settings are disabled"); + Timber.d("Intent for ObserverService not send : account is null or \"settings sync\" & \"media sync\" settings are disabled"); } return Result.success();