|
|
|
@ -16,6 +16,8 @@ import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
|
|
|
|
|
import at.bitfire.davdroid.model.ServiceDB;
|
|
|
|
|
import at.bitfire.davdroid.model.ServiceDB.Services;
|
|
|
|
@ -29,31 +31,31 @@ public class PackageChangedReceiver extends BroadcastReceiver {
|
|
|
|
|
@SuppressLint("MissingPermission")
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
if (Intent.ACTION_PACKAGE_ADDED.equals(intent.getAction()) ||
|
|
|
|
|
Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(intent.getAction())) {
|
|
|
|
|
Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(intent.getAction()))
|
|
|
|
|
updateTaskSync(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean tasksInstalled = LocalTaskList.tasksProviderAvailable(context);
|
|
|
|
|
App.log.info("Package (un)installed; OpenTasks provider now available = " + tasksInstalled);
|
|
|
|
|
static void updateTaskSync(@NonNull Context context) {
|
|
|
|
|
boolean tasksInstalled = LocalTaskList.tasksProviderAvailable(context);
|
|
|
|
|
App.log.info("Package (un)installed; OpenTasks provider now available = " + tasksInstalled);
|
|
|
|
|
|
|
|
|
|
// check all accounts and (de)activate OpenTasks if a CalDAV service is defined
|
|
|
|
|
@Cleanup ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(context);
|
|
|
|
|
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
|
|
|
|
// check all accounts and (de)activate OpenTasks if a CalDAV service is defined
|
|
|
|
|
@Cleanup ServiceDB.OpenHelper dbHelper = new ServiceDB.OpenHelper(context);
|
|
|
|
|
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
|
|
|
|
|
|
|
|
|
@Cleanup Cursor cursor = db.query(Services._TABLE, new String[] { Services.ACCOUNT_NAME },
|
|
|
|
|
Services.SERVICE + "=?", new String[] { Services.SERVICE_CALDAV }, null, null, null);
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
|
Account account = new Account(cursor.getString(0), Constants.ACCOUNT_TYPE);
|
|
|
|
|
@Cleanup Cursor cursor = db.query(Services._TABLE, new String[] { Services.ACCOUNT_NAME },
|
|
|
|
|
Services.SERVICE + "=?", new String[] { Services.SERVICE_CALDAV }, null, null, null);
|
|
|
|
|
while (cursor.moveToNext()) {
|
|
|
|
|
Account account = new Account(cursor.getString(0), Constants.ACCOUNT_TYPE);
|
|
|
|
|
|
|
|
|
|
if (tasksInstalled) {
|
|
|
|
|
if (tasksInstalled) {
|
|
|
|
|
if (ContentResolver.getIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority) <= 0) {
|
|
|
|
|
ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 1);
|
|
|
|
|
try {
|
|
|
|
|
AccountSettings settings = new AccountSettings(context, account);
|
|
|
|
|
settings.setSyncInterval(TaskProvider.ProviderName.OpenTasks.authority, Constants.DEFAULT_SYNC_INTERVAL);
|
|
|
|
|
} catch(InvalidAccountException ignored) {
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
ContentResolver.setSyncAutomatically(account, TaskProvider.ProviderName.OpenTasks.authority, true);
|
|
|
|
|
ContentResolver.addPeriodicSync(account, TaskProvider.ProviderName.OpenTasks.authority, new Bundle(), Constants.DEFAULT_SYNC_INTERVAL);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
ContentResolver.setIsSyncable(account, TaskProvider.ProviderName.OpenTasks.authority, 0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|