Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f12e8219 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Replace Log in InitializerService to use Timber

parent 683ce733
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.os.IBinder;
import android.util.Log;

import com.owncloud.android.lib.common.OwnCloudClient;

@@ -30,6 +29,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;

import static com.owncloud.android.lib.resources.files.FileUtils.PATH_SEPARATOR;
import static foundation.e.drive.utils.AppConstants.MEDIA_SYNCABLE_CATEGORIES;
@@ -44,27 +44,26 @@ import androidx.work.WorkManager;
 * @author Abhishek Aggarwal
 */
public class InitializerService extends Service {
    private final String TAG = InitializerService.class.getSimpleName();
    private List<SyncedFolder> syncedFolders;
    private OwnCloudClient cloudClient;
    private Account account;

    @Override
    public void onCreate() {
        Log.i(TAG, "onCreate()");
        Timber.tag(InitializerService.class.getSimpleName());
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand(...)");
        Timber.i("onStartCommand()");
        CommonUtils.setServiceUnCaughtExceptionHandler(this);

        //Get account
        SharedPreferences prefs = this.getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);

        if (prefs.getBoolean(AppConstants.INITIALIZATION_HAS_BEEN_DONE, false)) {
            Log.w(TAG, "Initializer has already been run");
            Timber.w("Initializer has already been done");
        } else {
            String accountName = prefs.getString(AccountManager.KEY_ACCOUNT_NAME, "");
            String accountType = prefs.getString(AccountManager.KEY_ACCOUNT_TYPE, "");
@@ -80,7 +79,7 @@ public class InitializerService extends Service {
            }

            if (accountName.isEmpty()) {
                Log.w(TAG, "Account's name not found. Neither in shared prefs nor in intent's extras");
                Timber.w("Account's name not found");
                stopSelf();
            } else {
                this.account = CommonUtils.getAccount(accountName, accountType, AccountManager.get(this));
@@ -89,7 +88,7 @@ public class InitializerService extends Service {
                    this.cloudClient = DavClientProvider.getInstance().getClientInstance(account, getApplicationContext());
                    start();
                } else {
                    Log.w(TAG, "Got account is invalid.");
                    Timber.w("Got account is invalid");
                    stopSelf();
                }
            }
@@ -98,7 +97,7 @@ public class InitializerService extends Service {
    }

    public void start() {
        Log.i(TAG, "start()");
        Timber.d("start()");
        if (cloudClient == null) {
            stopSelf();
            return;
@@ -119,7 +118,7 @@ public class InitializerService extends Service {
     * @param categories categories indicating which syncedFolder to create
     */
    private void getInitialSyncedFolders(List<String> categories) {
        Log.i(TAG, "getInitialSyncedFolders");
        Timber.d("getInitialSyncedFolders");

        this.syncedFolders = new ArrayList<>();

@@ -166,7 +165,9 @@ public class InitializerService extends Service {
                                false,
                                CommonUtils.isSettingsSyncEnabled(account),
                                false));
                    } catch (Exception e) { Log.e(TAG, e.toString()); }
                    } catch (Exception exception) {
                        Timber.e(exception);
                    }
                break;
            }
        }