Skip to content

Commit

Permalink
Check account type before sync operation execution and instead crash …
Browse files Browse the repository at this point in the history
…app warn user

Signed-off-by: alperozturk <alper_ozturk@proton.me>
  • Loading branch information
alperozturk96 committed Aug 23, 2024
1 parent e0cc413 commit 27b8787
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import android.os.Handler;

import com.nextcloud.common.NextcloudClient;
import com.nextcloud.utils.extensions.ContextExtensionsKt;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
Expand Down Expand Up @@ -46,10 +48,11 @@ public SyncOperation(@NonNull FileDataStorageManager storageManager) {
*/
public RemoteOperationResult execute(Context context) {
if (storageManager.getUser().isAnonymous()) {
throw new IllegalArgumentException("Trying to execute a sync operation with a " +
"storage manager for an anonymous account");
ContextExtensionsKt.showToast(context, R.string.anonymous_account_type_warning_text);
return new RemoteOperationResult(RemoteOperationResult.ResultCode.ACCOUNT_EXCEPTION);
} else {
return super.execute(this.storageManager.getUser(), context);
}
return super.execute(this.storageManager.getUser(), context);
}

public RemoteOperationResult execute(@NonNull NextcloudClient client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ private void onNavigationItemClicked(final MenuItem menuItem) {
} else if (itemId == R.id.nav_logout) {
mCheckedMenuItem = -1;
MenuItem isNewMenuItemChecked = menuItem.setChecked(false);
Log_OC.d(TAG,"onNavigationItemClicked nav_logout setChecked " + isNewMenuItemChecked);
Log_OC.d(TAG, "onNavigationItemClicked nav_logout setChecked " + isNewMenuItemChecked);
final Optional<User> optionalUser = getUser();
if (optionalUser.isPresent()) {
UserInfoActivity.openAccountRemovalDialog(optionalUser.get(), getSupportFragmentManager());
Expand Down Expand Up @@ -1164,7 +1164,7 @@ public void showFiles(boolean onDeviceOnly, boolean onlyPersonalFiles) {
public void avatarGenerated(Drawable avatarDrawable, Object callContext) {
if (callContext instanceof MenuItem menuItem) {
MenuItem newIcon = menuItem.setIcon(avatarDrawable);
Log_OC.d(TAG,"avatarGenerated new icon: " + newIcon);
Log_OC.d(TAG, "avatarGenerated new icon: " + newIcon);
} else if (callContext instanceof ImageView imageView) {
imageView.setImageDrawable(avatarDrawable);
} else if (callContext instanceof MaterialButton materialButton) {
Expand Down Expand Up @@ -1229,60 +1229,60 @@ 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) {
if (!getBaseContext().getResources().getBoolean(R.bool.show_external_links)) {
return;
}

Thread t = new Thread(() -> {
User user = accountManager.getUser();
if (user.isAnonymous()) {
accountManager.startAccountCreation(this);
} else {
if ((getCapabilities() == null || getCapabilities().getAccountName() != null && getCapabilities().getAccountName().isEmpty()) && getStorageManager() != null) {
GetCapabilitiesOperation getCapabilities = new GetCapabilitiesOperation(getStorageManager());
getCapabilities.execute(getBaseContext());
}

User user = accountManager.getUser();
if (getStorageManager() != null && CapabilityUtils.getCapability(user, this)
.getExternalLinks().isTrue()) {

int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT);
if (getStorageManager() != null && CapabilityUtils.getCapability(user, this).getExternalLinks().isTrue()) {
int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT);

if (count > 10 || count == -1 || force) {
if (force) {
Log_OC.d("ExternalLinks", "force update");
}

arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT, "0");
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, "0");

Log_OC.d("ExternalLinks", "update via api");
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
RemoteOperationResult result = getExternalLinksOperation.execute(user, this);

if (result.isSuccess() && result.getData() != null) {
externalLinksProvider.deleteAllExternalLinks();

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

ArrayList<ExternalLink> externalLinks = (ArrayList<ExternalLink>) result.getData();
for (ExternalLink link : externalLinks) {
externalLinksProvider.storeExternalLink(link);
}
}
} else {
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL,
FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
arbitraryDataProvider.storeOrUpdateKeyValue(FilesSyncHelper.GLOBAL, FileActivity.APP_OPENED_COUNT, String.valueOf(count + 1));
}
} else {
externalLinksProvider.deleteAllExternalLinks();
Log_OC.d("ExternalLinks", "links disabled");
}

runOnUiThread(this::updateExternalLinksInDrawer);
});
t.start();
}
}
});
t.start();
}

protected void handleDeepLink(@NonNull Uri uri) {
String path = uri.getLastPathSegment();
if (path == null) return;
if (path == null) {
return;
}

DeepLinkConstants deepLinkType = DeepLinkConstants.Companion.fromPath(path);
if (deepLinkType == null) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
-->
<resources>
<string name="anonymous_account_type_warning_text">Trying to execute a sync operation with anonymous account, operation cancelled"</string>
<string name="about_android">%1$s Android app</string>
<string name="about_version">version %1$s</string>
<string name="about_version_with_build">version %1$s, build #%2$s</string>
Expand Down

0 comments on commit 27b8787

Please sign in to comment.