Skip to content

Commit

Permalink
Merge pull request #15 from rapidpro/android-api-updates
Browse files Browse the repository at this point in the history
Switch to manual sync intervals
  • Loading branch information
nicpottier authored Dec 7, 2018
2 parents e853922 + 5ed7cfc commit bd31615
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 199 deletions.
12 changes: 8 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.rapidpro.androidchannel"
android:versionCode="196"
android:versionName="1.9.6" >
android:versionCode="197"
android:versionName="1.9.7" >

<!-- App receives FCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
Expand Down Expand Up @@ -85,15 +85,19 @@
</service>

<service
android:name=".SyncService"
android:name=".SyncIntentService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:enabled="true">
<intent-filter>
<action android:name="io.rapidpro.androidchannel.StartSync" />
</intent-filter>
</service>


<service
android:name=".SyncJobService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:enabled="true">
</service>

<service
android:name=".FCMPingService"
Expand Down
21 changes: 8 additions & 13 deletions app/src/main/java/io/rapidpro/androidchannel/RapidPro.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

package io.rapidpro.androidchannel;

import android.Manifest;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand All @@ -33,7 +31,6 @@
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
Expand All @@ -42,7 +39,6 @@
import android.provider.Telephony;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -51,12 +47,9 @@
import java.util.UUID;

import io.rapidpro.androidchannel.data.DBCommandHelper;
import io.rapidpro.androidchannel.payload.Command;
import io.rapidpro.androidchannel.payload.MTTextMessage;
import io.rapidpro.androidchannel.payload.ResetCommand;

import static android.support.v4.app.ActivityCompat.requestPermissions;

public class RapidPro extends Application {

public static Logger LOG = new Logger();
Expand All @@ -70,6 +63,7 @@ public class RapidPro extends Application {
public static final String LAST_FCM_TIME = "lastFcm";
public static final String LAST_RUN_COMMANDS_TIME = "lastRun";
public static final String FIRST_FCM_TIME = "firstGcm";
public static final String SYNCING = "syncing";

public static final int NOTIFICATION_ID = 1;
public static final String NOTIFICATION_CHANNEL_ID = "RapidPro_notification_channel";
Expand Down Expand Up @@ -135,11 +129,12 @@ public void registerObservers() {

updateNotification();

JobInfo syncJob = new JobInfo.Builder(SyncJobService.JOB_ID, new ComponentName(getPackageName(), SyncJobService.class.getName()))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
.setOverrideDeadline(5000).build();

JobScheduler jobScheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE);
jobScheduler.schedule(new JobInfo.Builder(SyncService.JOB_ID,
new ComponentName(this, SyncService.class))
.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).setPeriodic(60000)
.build());
jobScheduler.schedule(syncJob);

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {

Expand Down Expand Up @@ -323,13 +318,13 @@ public void sync(boolean force) {
// Stop if RapidPro is paused
if (isPaused()) return;

Intent intent = new Intent(this, SyncService.class);
Intent intent = new Intent(this, SyncIntentService.class);
intent.putExtra(Intents.SYNC_TIME, System.currentTimeMillis());
if (force){
intent.putExtra(Intents.FORCE_EXTRA, true);
}

SyncService.enqueueWork(this, intent);
SyncIntentService.enqueueWork(this, intent);
}

public void pingFCM(){
Expand Down
Loading

0 comments on commit bd31615

Please sign in to comment.