Loading app/src/main/AndroidManifest.xml +3 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/> <queries> <package android:name="com.nextcloud.client" /> Loading Loading @@ -175,7 +177,7 @@ <provider android:authorities="it.niedermann.owncloud.notes.providers.AppContentProvider" android:authorities="foundation.e.notes.android.providers.AppContentProvider" android:name=".providers.AppContentProvider" android:enabled="true" android:exported="true"/> Loading app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java +68 −65 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ import it.niedermann.owncloud.notes.shared.model.ImportStatus; import it.niedermann.owncloud.notes.shared.model.NavigationCategory; import it.niedermann.owncloud.notes.shared.model.NotesSettings; import it.niedermann.owncloud.notes.shared.model.SyncResultStatus; import it.niedermann.owncloud.notes.shared.util.AccountSyncUtil; import it.niedermann.owncloud.notes.shared.util.ApiVersionUtil; import it.niedermann.owncloud.notes.shared.util.NoteUtil; import it.niedermann.owncloud.notes.shared.util.SSOUtil; Loading Loading @@ -815,6 +816,7 @@ public class NotesRepository { syncActive.put(account.getId(), false); } Log.d(TAG, "Sync requested (" + (onlyLocalChanges ? "onlyLocalChanges" : "full") + "; " + (Boolean.TRUE.equals(syncActive.get(account.getId())) ? "sync active" : "sync NOT active") + ") ..."); if (AccountSyncUtil.isSyncEnable(context, account)) { if (isSyncPossible() && (!Boolean.TRUE.equals(syncActive.get(account.getId())) || onlyLocalChanges)) { syncActive.put(account.getId(), true); try { Loading Loading @@ -894,6 +896,7 @@ public class NotesRepository { } } } } public void updateNetworkStatus() { try { Loading app/src/main/java/it/niedermann/owncloud/notes/shared/util/AccountSyncUtil.java 0 → 100644 +62 −0 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2023 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package it.niedermann.owncloud.notes.shared.util; import android.accounts.AccountManager; import android.content.ContentResolver; import android.content.Context; import android.util.Log; import it.niedermann.owncloud.notes.persistence.entity.Account; public class AccountSyncUtil { private static final String TAG = AccountSyncUtil.class.getSimpleName(); private static final String murena_account_type = "e.foundation.webdav.eelo"; private static final String notes_content_authority = "foundation.e.notes.android.providers.AppContentProvider"; private AccountSyncUtil() { throw new UnsupportedOperationException("Do not instantiate this util class."); } private static android.accounts.Account[] getMurenaAccountsOnDevice(AccountManager accountManager) { return accountManager.getAccountsByType(murena_account_type); } private static boolean isSyncEnable(android.accounts.Account account) { return ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(account, notes_content_authority); } public static boolean isSyncEnable(Context context, Account account) { AccountManager accountManager = AccountManager.get(context); try { android.accounts.Account[] murenaAccounts = getMurenaAccountsOnDevice(accountManager); for (android.accounts.Account murenaAccount : murenaAccounts) { if (account.getAccountName().equals(murenaAccount.name)) { return isSyncEnable(murenaAccount); } } } catch (SecurityException e) { Log.e(TAG, "Failed to load murena accounts", e); } return true; } } Loading
app/src/main/AndroidManifest.xml +3 −1 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/> <queries> <package android:name="com.nextcloud.client" /> Loading Loading @@ -175,7 +177,7 @@ <provider android:authorities="it.niedermann.owncloud.notes.providers.AppContentProvider" android:authorities="foundation.e.notes.android.providers.AppContentProvider" android:name=".providers.AppContentProvider" android:enabled="true" android:exported="true"/> Loading
app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java +68 −65 Original line number Diff line number Diff line Loading @@ -70,6 +70,7 @@ import it.niedermann.owncloud.notes.shared.model.ImportStatus; import it.niedermann.owncloud.notes.shared.model.NavigationCategory; import it.niedermann.owncloud.notes.shared.model.NotesSettings; import it.niedermann.owncloud.notes.shared.model.SyncResultStatus; import it.niedermann.owncloud.notes.shared.util.AccountSyncUtil; import it.niedermann.owncloud.notes.shared.util.ApiVersionUtil; import it.niedermann.owncloud.notes.shared.util.NoteUtil; import it.niedermann.owncloud.notes.shared.util.SSOUtil; Loading Loading @@ -815,6 +816,7 @@ public class NotesRepository { syncActive.put(account.getId(), false); } Log.d(TAG, "Sync requested (" + (onlyLocalChanges ? "onlyLocalChanges" : "full") + "; " + (Boolean.TRUE.equals(syncActive.get(account.getId())) ? "sync active" : "sync NOT active") + ") ..."); if (AccountSyncUtil.isSyncEnable(context, account)) { if (isSyncPossible() && (!Boolean.TRUE.equals(syncActive.get(account.getId())) || onlyLocalChanges)) { syncActive.put(account.getId(), true); try { Loading Loading @@ -894,6 +896,7 @@ public class NotesRepository { } } } } public void updateNetworkStatus() { try { Loading
app/src/main/java/it/niedermann/owncloud/notes/shared/util/AccountSyncUtil.java 0 → 100644 +62 −0 Original line number Diff line number Diff line /* * Copyright MURENA SAS 2023 * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ package it.niedermann.owncloud.notes.shared.util; import android.accounts.AccountManager; import android.content.ContentResolver; import android.content.Context; import android.util.Log; import it.niedermann.owncloud.notes.persistence.entity.Account; public class AccountSyncUtil { private static final String TAG = AccountSyncUtil.class.getSimpleName(); private static final String murena_account_type = "e.foundation.webdav.eelo"; private static final String notes_content_authority = "foundation.e.notes.android.providers.AppContentProvider"; private AccountSyncUtil() { throw new UnsupportedOperationException("Do not instantiate this util class."); } private static android.accounts.Account[] getMurenaAccountsOnDevice(AccountManager accountManager) { return accountManager.getAccountsByType(murena_account_type); } private static boolean isSyncEnable(android.accounts.Account account) { return ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(account, notes_content_authority); } public static boolean isSyncEnable(Context context, Account account) { AccountManager accountManager = AccountManager.get(context); try { android.accounts.Account[] murenaAccounts = getMurenaAccountsOnDevice(accountManager); for (android.accounts.Account murenaAccount : murenaAccounts) { if (account.getAccountName().equals(murenaAccount.name)) { return isSyncEnable(murenaAccount); } } } catch (SecurityException e) { Log.e(TAG, "Failed to load murena accounts", e); } return true; } }