Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix - Check Account Type Before Sync Operation Execution and Instead Crashing The App Inform User #13440

Merged
merged 5 commits into from
Aug 23, 2024
Merged
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
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
Loading