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

Commit 0a9420db authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Use WorkManager API to schedule periodic sync

parent c616ea09
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
image: "registry.gitlab.e.foundation:5000/e/apps/docker-android-apps-cicd:latest"
image: "registry.gitlab.e.foundation/e/os/docker-android-apps-cicd:latest"

stages:
- test
+14 −19
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ def getTestProp(String propName) {


android {
    compileSdkVersion 28
    compileSdkVersion 31
    defaultConfig {
        applicationId "foundation.e.drive"
        minSdkVersion 26
@@ -53,32 +53,27 @@ android {
            //includeAndroidResources = true
        }
    }

}


dependencies {
    api project(':NextcloudLib')
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'androidx.annotation:annotation:1.3.0'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    api 'androidx.annotation:annotation:1.3.0'
    api project(':NextcloudLib')

    //start to add lib for test - 1/4/21
    //@TODO: add junit runner as lib for testImplementation
    def work_version = "2.7.1"
    // (Java only)
    implementation "androidx.work:work-runtime:$work_version"

    testImplementation 'com.android.support.test:runner:1.0.2'
    testImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'androidx.test:runner:1.4.0'
    androidTestImplementation 'androidx.test:rules:1.4.0'
    androidTestImplementation 'androidx.annotation:annotation:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation  'junit:junit:4.12'

    testImplementation 'androidx.test:runner:1.4.0'
    testImplementation 'androidx.test:rules:1.4.0'
    testImplementation 'junit:junit:4.12'
    //testImplementation 'org.robolectric:robolectric:4.4' //need AndroidX
    testImplementation "org.robolectric:robolectric:3.8"
    testImplementation 'org.robolectric:robolectric:4.4'
    testImplementation('org.mockito:mockito-inline:3.4.0')

    //testImplementation Libs.AndroidX.Test.archCoreTesting //TODO: replace by not android X version
    //implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
    androidTestImplementation  'junit:junit:4.12'
}
+0 −11
Original line number Diff line number Diff line
@@ -61,22 +61,11 @@ http://www.gnu.org/licenses/gpl.html
                <action android:name="drive.services.ResetService" />
            </intent-filter>
        </service>
        <service
            android:name=".jobs.ScannerJob"
            android:permission="android.permission.BIND_JOB_SERVICE" />
        <service
            android:name=".services.ObserverService"
            android:enabled="true" />
        <service android:name=".services.OperationManagerService" />

        <receiver
            android:name=".receivers.BatteryStateReceiver"
            android:enabled="true">
            <intent-filter>
                <action android:name="android.intent.action.BATTERY_LOW" />
                <action android:name="android.intent.action.BATTERY_OKAY" />
            </intent-filter>
        </receiver>
        <receiver
            android:name=".receivers.PackageEventReceiver"
            android:enabled="true">
+1 −9
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ import android.util.Log;

import foundation.e.drive.utils.AppConstants;
import foundation.e.drive.utils.CommonUtils;
import foundation.e.drive.utils.JobUtils;

/**
 * Class representing the eDrive application.
@@ -36,7 +35,7 @@ public class EdriveApplication extends Application {

        SharedPreferences prefs = getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE);
        if (prefs.getString(AccountManager.KEY_ACCOUNT_NAME, null) != null) {
            scheduleScannerJob();
            Log.d(TAG, "Account already registered");
        } else {
            Account mAccount = CommonUtils.getAccount(getString(R.string.eelo_account_type), AccountManager.get(this));
            if (mAccount != null) {
@@ -47,17 +46,10 @@ public class EdriveApplication extends Application {
                        .putString(AccountManager.KEY_ACCOUNT_TYPE, accountType)
                        .apply();

                scheduleScannerJob();
            }
        }
    }

    private void scheduleScannerJob() {
        if (!JobUtils.isScannerJobRegistered(this)) {
            JobUtils.scheduleScannerJob(this);
        }
    }

    private void resetOperationManagerSetting() {
        getSharedPreferences(AppConstants.SHARED_PREFERENCE_NAME, Context.MODE_PRIVATE).edit()
                .putBoolean(AppConstants.KEY_OMS_IS_WORKING, false)
+0 −54
Original line number Diff line number Diff line
/*
 * Copyright © Vincent Bourgmayer (/e/ foundation).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 */

package foundation.e.drive.jobs;

import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;
import foundation.e.drive.receivers.ScreenOffReceiver;
import foundation.e.drive.services.ObserverService;
import foundation.e.drive.utils.CommonUtils;

/**
 * @author Vincent Bourgmayer
 */
public class ScannerJob extends JobService {
    final private String TAG = ScannerJob.class.getSimpleName(); //Tag for log

    @Override
    public boolean onStartJob(JobParameters params) {
        Log.i(TAG, "onStartJob()");

        Log.d(TAG, "RegisterReceiver: screenOffReceiver");
        IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        getApplicationContext().registerReceiver(ScreenOffReceiver.getInstance(), filter);

        Intent observerServiceIntent = new Intent(this, ObserverService.class);
        this.startService(observerServiceIntent);
        jobFinished(params, false);
        return true;
    }

    /**
     *
     * @param params
     * @return default return... ?
     */
    @Override
    public boolean onStopJob(JobParameters params) {
        Log.i(TAG, "onStopJob");
        boolean unregisteredReceiver = CommonUtils.unregisterScreenOff(getApplicationContext());
        Intent observerServiceIntent = new Intent(this, ObserverService.class);
        this.stopService(observerServiceIntent);
        return false;
    }
}
Loading