Skip to content

Commit

Permalink
Merge pull request jberkel#822 from jberkel/job-dispatcher
Browse files Browse the repository at this point in the history
Jobdispatcher
  • Loading branch information
jberkel authored Oct 29, 2017
2 parents 8087bc2 + 6c46ec4 commit 8f14195
Show file tree
Hide file tree
Showing 26 changed files with 740 additions and 268 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ language: android
android:
components:
- tools
- build-tools-26.0.0
- build-tools-26.0.2
- android-26
- extra-android-m2repository

jdk: oraclejdk8

Expand Down
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
== 1.5.11 (1555) tbd

* Use JobManager to run backups in the background (#572, #810, #822)
* Replaced WebView auth with browser (#767)
* Replaced pay-me with Play Billing Library
* Gradle build support (#638)
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,14 @@ repository and send me a [pull request][].
## <a name="credits">Credits</a>

* [Christoph Studer](http://studer.tv/) Original author of SMS Backup
* [Ben Dodson](http://github.com/bjdodson) - Contacts 2.0 / MMS support
* [Felix Knecht](http://github.com/dicer) - Call log backup code
* [Michael Scharfstein](http://github.com/smike) - Call log calendar ICS support
* [k9mail](http://code.google.com/p/k9mail/) IMAP library, with some modifications ([k9mail/sms-backup-plus](https://github.com/jberkel/k-9/tree/sms-backup-plus))
* [signpost](http://github.com/kaeppler/signpost) Signpost OAuth library
* [Ben Dodson](https://github.com/bjdodson) - Contacts 2.0 / MMS support
* [Felix Knecht](https://github.com/dicer) - Call log backup code
* [Michael Scharfstein](https://github.com/smike) - Call log calendar ICS support
* [k9mail](https://github.com/k9mail/k-9/) IMAP library, with some modifications ([k9mail/sms-backup-plus](https://github.com/jberkel/k-9/tree/sms-backup-plus))
* [signpost](https://github.com/mttkay/signpost) Natthias Käppler, Signpost OAuth library
* Shimon Simon (new icon designs)
* [bbs.goapk.com](http://bbs.goapk.com) / [Chen](http://blog.thisischen.com/) - Chinese translation
* [skolima](http://github.com/skolima) - Polish translation
* [skolima](https://github.com/skolima) - Polish translation
* Roberto Elena Ormad - Spanish translation
* Gabriele Ravanetti / [Patryk Rzucidlo](http://www.ptkdev.it/) / [Chiara De Liberato](http://www.chiaradeliberato.it/) - Italian translation
* Harun Sahin - Turkish translation
Expand All @@ -438,7 +438,7 @@ repository and send me a [pull request][].
* Yunsu Choi - Korean translation
* Javier Pico - Galician translation
* Ferran Rius - Catalan translation
* Mads Andreasen - Danish translation
* [Mads Andreasen](https://github.com/MadsAndreasen) - Danish translation, initial JobDispatcher code
* sHa - Ukrainian translation

## <a name="screenhots">Screenshots</a>
Expand Down
8 changes: 3 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ if (keystorePropertiesFile.exists()) {

android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.zegoggles.smssync"
minSdkVersion 9
Expand Down Expand Up @@ -49,13 +49,10 @@ android {
exclude 'META-INF/LGPL2.1'
}

testOptions {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}

}

dependencies {
Expand All @@ -64,10 +61,11 @@ dependencies {
exclude group: 'org.apache.httpcomponents', module: 'httpcore'
exclude group: 'commons-codec', module: 'commons-codec'
}
compile 'com.google.android:support-v4:r7'
compile 'com.squareup:otto:1.3.8'
compile 'com.github.jberkel:k-9:75bb293984'
compile 'com.android.billingclient:billing:dp-1'
compile 'com.firebase:firebase-jobdispatcher:0.8.4'
compile 'com.android.support:support-annotations:25.0.0'

testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.5'
Expand Down
22 changes: 13 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,24 @@

<service android:name=".service.SmsBackupService" android:exported="false"/>
<service android:name=".service.SmsRestoreService" android:exported="false"/>
<service android:name=".service.SmsJobService" android:exported="false">
<intent-filter>
<action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
</intent-filter>
</service>

<receiver android:name=".receiver.SmsBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

<receiver android:name=".receiver.BackupBroadcastReceiver" android:enabled="true">
<intent-filter>
<action android:name="com.zegoggles.smssync.BACKUP"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="com.zegoggles.smssync.BACKUP"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</receiver>

<!-- BroadcastReceiver that listens for incoming SMS messages -->
Expand Down Expand Up @@ -139,6 +144,5 @@
<meta-data
android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAI15zt2oJAvxMu4s5SaHisDyYsduKd2jq_-XnAug" />

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import com.zegoggles.smssync.preferences.BackupManagerWrapper;
import com.zegoggles.smssync.preferences.Preferences;
import com.zegoggles.smssync.receiver.SmsBroadcastReceiver;
import com.zegoggles.smssync.service.Alarms;
import com.zegoggles.smssync.service.BackupJobs;
import com.zegoggles.smssync.service.BackupType;
import com.zegoggles.smssync.service.SmsBackupService;
import com.zegoggles.smssync.service.SmsRestoreService;
Expand Down Expand Up @@ -314,7 +314,7 @@ public void run() {
}
}

protected String getEnabledBackupSummary() {
String getEnabledBackupSummary() {
final List<String> enabled = new ArrayList<String>();
for (DataType dataType : DataType.enabled(preferences.preferences)) {
enabled.add(getString(dataType.resId));
Expand Down Expand Up @@ -795,7 +795,7 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);

if (!isEnabled) new Alarms(MainActivity.this).cancel();
if (!isEnabled) new BackupJobs(MainActivity.this).cancel();
return true;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ public void onBillingSetupFinished(int resultCode) {
} else {
l.userDonationState(resultCode == BILLING_UNAVAILABLE ? NOT_AVAILABLE : UNKNOWN);
}
helper.endConnection();
try {
helper.endConnection();
} catch (Exception ignored) {
}
}
public void onBillingServiceDisconnected() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.zegoggles.smssync.compat;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.Log;

import static android.content.pm.PackageManager.GET_SIGNATURES;
import static android.content.pm.PackageManager.GET_UNINSTALLED_PACKAGES;
import static com.zegoggles.smssync.App.TAG;

public class GooglePlayServices {
private static final String COM_GOOGLE_ANDROID_GMS = "com.google.android.gms";
private static final String COM_ANDROID_VENDING = "com.android.vending";
private static final int MIN_GMS_VERSION = 9256030; // 9256030 9.2.56 (030-124593566)

@SuppressLint("PackageManagerGetSignatures")
public static boolean isAvailable(Context context) {
final PackageManager packageManager = context.getPackageManager();

try {
packageManager.getPackageInfo(COM_ANDROID_VENDING, GET_UNINSTALLED_PACKAGES|GET_SIGNATURES);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Google Play Store is missing");
return false;
}

try {
final PackageInfo info = packageManager.getPackageInfo(COM_GOOGLE_ANDROID_GMS, GET_SIGNATURES);
// TODO: check signatures

if (info.versionCode < MIN_GMS_VERSION) {
Log.w(TAG, "Google Play Services out of date: "+ info.versionCode);
return false;
} else {
ApplicationInfo applicationInfo = info.applicationInfo;
if (applicationInfo == null) {
try {
applicationInfo = packageManager.getApplicationInfo(COM_GOOGLE_ANDROID_GMS, 0);
} catch (PackageManager.NameNotFoundException e) {
Log.w("GooglePlayServicesUtil", "Google Play services missing when getting application info.");
return false;
}
}
return applicationInfo.enabled;
}
} catch (PackageManager.NameNotFoundException e) {
Log.d(TAG, "Google Play Services is missing");
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import static com.zegoggles.smssync.preferences.Preferences.Keys.SMS_DEFAULT_PACKAGE;
import static com.zegoggles.smssync.preferences.Preferences.Keys.SMS_DEFAULT_PACKAGE_CHANGE_SEEN;
import static com.zegoggles.smssync.preferences.Preferences.Keys.THIRD_PARTY_INTEGRATION;
import static com.zegoggles.smssync.preferences.Preferences.Keys.USE_OLD_SCHEDULER;
import static com.zegoggles.smssync.preferences.Preferences.Keys.WIFI_ONLY;

public class Preferences {
Expand Down Expand Up @@ -100,6 +101,7 @@ public enum Keys {
BACKUP_SETTINGS_SCREEN("auto_backup_settings_screen"),
SMS_DEFAULT_PACKAGE("sms_default_package"),
SMS_DEFAULT_PACKAGE_CHANGE_SEEN("sms_default_package_change_seen"),
USE_OLD_SCHEDULER("use_old_scheduler"),
;

public final String key;
Expand Down Expand Up @@ -319,6 +321,10 @@ public boolean shouldShowAboutDialog() {
}
}

public boolean isUseOldScheduler() {
return preferences.getBoolean(USE_OLD_SCHEDULER.key, false);
}

boolean isOldSmsBackupInstalled() {
try {
context.getPackageManager().getPackageInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import android.content.Intent;
import android.util.Log;
import com.zegoggles.smssync.preferences.Preferences;
import com.zegoggles.smssync.service.Alarms;
import com.zegoggles.smssync.service.BackupJobs;

import static com.zegoggles.smssync.App.LOCAL_LOGV;
import static com.zegoggles.smssync.App.TAG;
Expand All @@ -39,7 +39,7 @@ public void onReceive(Context context, Intent intent) {
private void backupRequested(Context context, Intent intent) {
if (new Preferences(context).isAllow3rdPartyIntegration()) {
Log.d(TAG, "backup requested via broadcast intent");
new Alarms(context).scheduleImmediateBackup();
new BackupJobs(context).scheduleImmediate();
} else {
Log.d(TAG, "backup requested via broadcast intent but ignored");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import android.util.Log;
import com.zegoggles.smssync.preferences.AuthPreferences;
import com.zegoggles.smssync.preferences.Preferences;
import com.zegoggles.smssync.service.Alarms;
import com.zegoggles.smssync.service.BackupJobs;
import com.zegoggles.smssync.utils.AppLog;

import static com.zegoggles.smssync.App.LOCAL_LOGV;
Expand All @@ -44,15 +44,15 @@ public void onReceive(Context context, Intent intent) {

private void bootup(Context context) {
if (shouldSchedule(context)) {
getAlarms(context).scheduleBootupBackup();
getBackupJobs(context).scheduleBootup();
} else {
Log.i(TAG, "Received bootup but not set up to back up.");
}
}

private void incomingSMS(Context context) {
if (shouldSchedule(context)) {
getAlarms(context).scheduleIncomingBackup();
getBackupJobs(context).scheduleIncoming();
} else {
Log.i(TAG, "Received SMS but not set up to back up.");
}
Expand Down Expand Up @@ -87,8 +87,8 @@ private void log(Context context, String message, boolean appLog) {
}
}

protected Alarms getAlarms(Context context) {
return new Alarms(context);
protected BackupJobs getBackupJobs(Context context) {
return new BackupJobs(context);
}

protected Preferences getPreferences(Context context) {
Expand Down
Loading

0 comments on commit 8f14195

Please sign in to comment.