Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def requireWifi = project.requireWifi ?: 'false';
// database unencrypted so that it can be easily inspected using Stetho.
def encryptionPassword = project.encryptionPassword ?: '';

def syncAccountName = "sync";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for defining this in the build.gradle instead of in the code where it was defined before?


logger.info('Default server hostname: ${server}')
logger.info("Default OpenMRS root URL: ${openmrsRootUrl}")
logger.info("Default OpenMRS user: ${openmrsUser}")
Expand Down Expand Up @@ -208,6 +210,7 @@ android {
buildConfigField 'String', 'CONTENT_AUTHORITY', '"' + contentAuthority + '"'
resValue 'string', 'account_type', appId
buildConfigField 'String', 'ACCOUNT_TYPE', '"' + appId + '"'
buildConfigField 'String', 'ACCOUNT_NAME', '"' + syncAccountName + '"'

// Set the SQLite database encryption password.
buildConfigField 'String', 'ENCRYPTION_PASSWORD', '"' + encryptionPassword + '"'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public BuendiaModuleHealthCheckRunnable(Handler handler) {
case HttpURLConnection.HTTP_FORBIDDEN:
case HttpURLConnection.HTTP_UNAUTHORIZED:
reportIssue(HealthIssue.SERVER_AUTHENTICATION_ISSUE);
stopImpl();
break;
case HttpURLConnection.HTTP_NOT_FOUND:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
*/
public class SyncAccountService extends Service {

public static final String ACCOUNT_NAME = "sync";
private static final Logger LOG = Logger.create();
private static final long SYNC_PERIOD = 5*60; // 5 minutes (in seconds)
@Inject static AppSettings sSettings;
Expand Down Expand Up @@ -88,7 +87,7 @@ public static void startFullSync() {

/** Gets the app's sync account (call initialize() before using this). */
public static Account getAccount() {
return new Account(ACCOUNT_NAME, BuildConfig.ACCOUNT_TYPE);
return new Account(BuildConfig.ACCOUNT_NAME, BuildConfig.ACCOUNT_TYPE);
}

/** Starts an sync of just the observations. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import android.support.annotation.StringRes;
import android.util.TimingLogger;

import com.android.volley.AuthFailureError;

import org.joda.time.Instant;
import org.projectbuendia.client.App;
import org.projectbuendia.client.R;
Expand Down Expand Up @@ -221,6 +223,11 @@ public SyncAdapter(Context context, boolean autoInitialize, boolean allowParalle
LOG.e(e, "Error during sync");
syncResult.stats.numIoExceptions++;
getContext().sendBroadcast(syncFailedIntent);

if (e.getCause().getCause() instanceof AuthFailureError) {
ContentResolver.setIsSyncable(account, Contracts.CONTENT_AUTHORITY, 0);
ContentResolver.setSyncAutomatically(account, Contracts.CONTENT_AUTHORITY, false);
}
return;
} finally {
LOG.i("Releasing savepoint %s", SYNC_SAVEPOINT_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

package org.projectbuendia.client.ui;

import android.accounts.Account;
import android.annotation.TargetApi;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -26,8 +28,10 @@
import android.view.MenuItem;

import org.projectbuendia.client.App;
import org.projectbuendia.client.BuildConfig;
import org.projectbuendia.client.R;
import org.projectbuendia.client.models.AppModel;
import org.projectbuendia.client.providers.Contracts;
import org.projectbuendia.client.ui.login.LoginActivity;

import java.util.List;
Expand Down Expand Up @@ -69,6 +73,11 @@ public class SettingsActivity extends PreferenceActivity {
static final Preference.OnPreferenceChangeListener sPrefListener =
new Preference.OnPreferenceChangeListener() {
@Override public boolean onPreferenceChange(Preference pref, Object value) {
//Enable sync
Account account = new Account(BuildConfig.ACCOUNT_NAME, BuildConfig.ACCOUNT_TYPE);
ContentResolver.setIsSyncable(account, Contracts.CONTENT_AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, Contracts.CONTENT_AUTHORITY, true);

updatePrefSummary(pref, value);
if (updatingPrefValues)
return true; // prevent endless recursion
Expand Down