Skip to content

Commit

Permalink
Merge pull request #13440 from nextcloud/bugfix/check-user-type-for-s…
Browse files Browse the repository at this point in the history
…ync-operation

BugFix - Check Account Type Before Sync Operation Execution and Instead Crashing The App Inform User
  • Loading branch information
alperozturk96 authored Aug 23, 2024
2 parents e0cc413 + afb6396 commit 5002593
Showing 1 changed file with 44 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1229,55 +1229,62 @@ public void onAccountRemovedEvent(AccountRemovedEvent event) {
* Retrieves external links via api from 'external' app
*/
public void fetchExternalLinks(final boolean force) {
if (getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
Thread t = new Thread(() -> {
// fetch capabilities as early as possible
if ((getCapabilities() == null || getCapabilities().getAccountName().isEmpty())
&& getStorageManager() != null) {
GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
getCapabilities.execute(getBaseContext());
}
if (!getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
return;
}

User user = accountManager.getUser();
if (getStorageManager() != null && CapabilityUtils.getCapability(user, this)
.getExternalLinks().isTrue()) {
User user = accountManager.getUser();
if (user.isAnonymous()) {
Log_OC.d(TAG, "Trying to execute a sync operation with a storage manager for an anonymous account");
return;
}

int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT);
Thread t = new Thread(() -> {
// fetch capabilities as early as possible
if ((getCapabilities() == null || getCapabilities().getAccountName() != null && getCapabilities().getAccountName().isEmpty())
&& getStorageManager() != null) {
GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
getCapabilities.execute(getBaseContext());
}

if (count > 10 || count == -1 || force) {
if (force) {
Log_OC.d("ExternalLinks", "force update");
}
if (getStorageManager() != null && CapabilityUtils.getCapability(user, this)
.getExternalLinks().isTrue()) {

arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT, "0");
int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT);

Log_OC.d("ExternalLinks", "update via api");
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
RemoteOperationResult result = getExternalLinksOperation.execute(user, this);
if (count > 10 || count == -1 || force) {
if (force) {
Log_OC.d("ExternalLinks", "force update");
}

if (result.isSuccess() && result.getData() != null) {
externalLinksProvider.deleteAllExternalLinks();
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT, "0");

ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) (Object) result.getData();
Log_OC.d("ExternalLinks", "update via api");
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
RemoteOperationResult result = getExternalLinksOperation.execute(user, this);

for (ExternalLink link : externalLinks) {
externalLinksProvider.storeExternalLink(link);
}
if (result.isSuccess() && result.getData() != null) {
externalLinksProvider.deleteAllExternalLinks();

ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) (Object) result.getData();

for (ExternalLink link : externalLinks) {
externalLinksProvider.storeExternalLink(link);
}
} else {
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
}
} else {
externalLinksProvider.deleteAllExternalLinks();
Log_OC.d("ExternalLinks", "links disabled");
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
}
runOnUiThread(this::updateExternalLinksInDrawer);
});
t.start();
}
} else {
externalLinksProvider.deleteAllExternalLinks();
Log_OC.d("ExternalLinks", "links disabled");
}
runOnUiThread(this::updateExternalLinksInDrawer);
});
t.start();
}

protected void handleDeepLink(@NonNull Uri uri) {
Expand Down

0 comments on commit 5002593

Please sign in to comment.