diff --git a/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java b/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java index 30f5a93624..816612e690 100644 --- a/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java +++ b/app/src/gplay/java/com/owncloud/android/utils/PushUtils.java @@ -19,6 +19,7 @@ import com.google.gson.Gson; import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.preferences.AppPreferences; import com.nextcloud.client.preferences.AppPreferencesImpl; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -26,9 +27,7 @@ import com.owncloud.android.datamodel.ArbitraryDataProviderImpl; import com.owncloud.android.datamodel.PushConfigurationState; import com.owncloud.android.datamodel.SignatureVerification; import com.owncloud.android.lib.common.OwnCloudAccount; -import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; -import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.notifications.RegisterAccountDeviceForNotificationsOperation; @@ -131,14 +130,11 @@ public final class PushUtils { try { ocAccount = new OwnCloudAccount(account, context); - OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). - getClientFor(ocAccount, context); + NextcloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). + getNextcloudClientFor(ocAccount, context); - RemoteOperation unregisterAccountDeviceForNotificationsOperation = new - UnregisterAccountDeviceForNotificationsOperation(); - - RemoteOperationResult remoteOperationResult = unregisterAccountDeviceForNotificationsOperation. - execute(mClient); + RemoteOperationResult remoteOperationResult = + new UnregisterAccountDeviceForNotificationsOperation().execute(mClient); if (remoteOperationResult.getHttpCode() == HttpStatus.SC_ACCEPTED) { String arbitraryValue; @@ -201,8 +197,8 @@ public final class PushUtils { TextUtils.isEmpty(providerValue)) { try { OwnCloudAccount ocAccount = new OwnCloudAccount(account, context); - OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton(). - getClientFor(ocAccount, context); + NextcloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton(). + getNextcloudClientFor(ocAccount, context); RemoteOperationResult remoteOperationResult = new RegisterAccountDeviceForNotificationsOperation(pushTokenHash, diff --git a/app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt b/app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt index 9e560a907f..e6f37a16e2 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/NotificationWork.kt @@ -29,6 +29,7 @@ import com.nextcloud.client.integrations.deck.DeckApi import com.owncloud.android.R import com.owncloud.android.datamodel.DecryptedPushMessage import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.OwnCloudClientFactory import com.owncloud.android.lib.common.OwnCloudClientManagerFactory import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.utils.Log_OC @@ -236,8 +237,7 @@ class NotificationWork constructor( } val user = optionalUser.get() try { - val client = OwnCloudClientManagerFactory.getDefaultSingleton() - .getClientFor(user.toOwnCloudAccount(), context) + val client = OwnCloudClientFactory.createNextcloudClient(user, context) val result = GetNotificationRemoteOperation(decryptedPushMessage.nid) .execute(client) if (result.isSuccess) { @@ -287,6 +287,7 @@ class NotificationWork constructor( val user = optionalUser.get() val client = OwnCloudClientManagerFactory.getDefaultSingleton() .getClientFor(user.toOwnCloudAccount(), context) + val nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, context) val actionType = intent.getStringExtra(KEY_NOTIFICATION_ACTION_TYPE) val actionLink = intent.getStringExtra(KEY_NOTIFICATION_ACTION_LINK) val success: Boolean = if (!actionType.isNullOrEmpty() && !actionLink.isNullOrEmpty()) { @@ -294,7 +295,7 @@ class NotificationWork constructor( resultCode == HttpStatus.SC_OK || resultCode == HttpStatus.SC_ACCEPTED } else { DeleteNotificationRemoteOperation(numericNotificationId) - .execute(client).isSuccess + .execute(nextcloudClient).isSuccess } if (success) { if (oldNotification == null) { diff --git a/app/src/main/java/com/nextcloud/utils/extensions/OwnCloudClientExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/OwnCloudClientExtensions.kt new file mode 100644 index 0000000000..2b36ebf5b9 --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/OwnCloudClientExtensions.kt @@ -0,0 +1,24 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2023 ZetaTom + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH + * SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only + */ + +package com.nextcloud.utils.extensions + +import android.content.Context +import com.nextcloud.common.NextcloudClient +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.OwnCloudClientFactory + +fun OwnCloudClient.toNextcloudClient(context: Context): NextcloudClient { + return OwnCloudClientFactory.createNextcloudClient( + baseUri, + userId, + credentials.toOkHttpCredentials(), + context, + isFollowRedirects + ) +} diff --git a/app/src/main/java/com/owncloud/android/services/OperationsService.java b/app/src/main/java/com/owncloud/android/services/OperationsService.java index 6ea23a8662..4cf151b3f7 100644 --- a/app/src/main/java/com/owncloud/android/services/OperationsService.java +++ b/app/src/main/java/com/owncloud/android/services/OperationsService.java @@ -29,6 +29,7 @@ import android.util.Pair; import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; +import com.nextcloud.common.NextcloudClient; import com.nextcloud.utils.extensions.IntentExtensionsKt; import com.owncloud.android.MainApp; import com.owncloud.android.datamodel.ArbitraryDataProvider; @@ -260,7 +261,7 @@ public class OperationsService extends Service { */ private final ConcurrentMap mBoundListeners = new ConcurrentHashMap<>(); - private ServiceHandler mServiceHandler; + private final ServiceHandler mServiceHandler; public OperationsServiceBinder(ServiceHandler serviceHandler) { mServiceHandler = serviceHandler; @@ -380,7 +381,7 @@ public class OperationsService extends Service { OperationsService mService; - private ConcurrentLinkedQueue> mPendingOperations = + private final ConcurrentLinkedQueue> mPendingOperations = new ConcurrentLinkedQueue<>(); private RemoteOperation mCurrentOperation; private Target mLastTarget; @@ -416,11 +417,12 @@ public class OperationsService extends Service { if (next != null) { mCurrentOperation = next.second; RemoteOperationResult result; + OwnCloudAccount ocAccount = null; + try { /// prepare client object to send the request to the ownCloud server if (mLastTarget == null || !mLastTarget.equals(next.first)) { mLastTarget = next.first; - OwnCloudAccount ocAccount; if (mLastTarget.mAccount != null) { ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService); } else { @@ -430,9 +432,21 @@ public class OperationsService extends Service { getClientFor(ocAccount, mService); } - /// perform the operation - result = mCurrentOperation.execute(mOwnCloudClient); - } catch (AccountsException e) { + // perform the operation + try { + result = mCurrentOperation.execute(mOwnCloudClient); + } catch (UnsupportedOperationException e) { + // TODO remove - added to aid in transition to NextcloudClient + + if (ocAccount == null) { + throw e; + } + + NextcloudClient nextcloudClient = OwnCloudClientManagerFactory.getDefaultSingleton() + .getNextcloudClientFor(ocAccount, mService.getBaseContext()); + result = mCurrentOperation.run(nextcloudClient); + } + } catch (AccountsException | IOException e) { if (mLastTarget.mAccount == null) { Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", e); @@ -442,15 +456,6 @@ public class OperationsService extends Service { } result = new RemoteOperationResult(e); - } catch (IOException e) { - if (mLastTarget.mAccount == null) { - Log_OC.e(TAG, "Error while trying to get authorization for a NULL account", - e); - } else { - Log_OC.e(TAG, "Error while trying to get authorization for " + - mLastTarget.mAccount.name, e); - } - result = new RemoteOperationResult(e); } catch (Exception e) { if (mLastTarget.mAccount == null) { Log_OC.e(TAG, "Unexpected error for a NULL account", e); @@ -537,10 +542,6 @@ public class OperationsService extends Service { false); updateLinkOperation.setHideFileDownload(hideFileDownload); -// if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) { -// updateLinkOperation.setPublicUpload(true); -// } - if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) { updateLinkOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL)); } diff --git a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt index 63b9573cb7..471390356e 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt @@ -19,11 +19,11 @@ import com.nextcloud.client.account.User import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.jobs.NotificationWork import com.nextcloud.client.network.ClientFactory.CreationException +import com.nextcloud.common.NextcloudClient import com.owncloud.android.R import com.owncloud.android.databinding.NotificationsLayoutBinding import com.owncloud.android.datamodel.ArbitraryDataProvider import com.owncloud.android.datamodel.ArbitraryDataProviderImpl -import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.notifications.GetNotificationsRemoteOperation import com.owncloud.android.lib.resources.notifications.models.Notification @@ -44,7 +44,7 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { private var adapter: NotificationListAdapter? = null private var snackbar: Snackbar? = null - private var client: OwnCloudClient? = null + private var client: NextcloudClient? = null private var optionalUser: Optional? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -213,16 +213,16 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { val t = Thread { initializeAdapter() val getRemoteNotificationOperation = GetNotificationsRemoteOperation() - val result = getRemoteNotificationOperation.execute(client) - if (result.isSuccess && result.resultData != null) { + val result = client?.let { getRemoteNotificationOperation.execute(it) } + if (result?.isSuccess == true && result.resultData != null) { runOnUiThread { populateList(result.resultData) } } else { - Log_OC.d(TAG, result.logMessage) + Log_OC.d(TAG, result?.logMessage) // show error runOnUiThread { setEmptyContent( getString(R.string.notifications_no_results_headline), - result.logMessage + result?.logMessage ) } } @@ -235,7 +235,7 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { if (client == null && optionalUser?.isPresent == true) { try { val user = optionalUser?.get() - client = clientFactory.create(user) + client = clientFactory.createNextcloudClient(user) } catch (e: CreationException) { Log_OC.e(TAG, "Error initializing client", e) } diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java index 99cf32ab66..0894dd98ac 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java @@ -36,9 +36,9 @@ import com.bumptech.glide.load.resource.file.FileToStreamDecoder; import com.caverock.androidsvg.SVG; import com.google.android.material.button.MaterialButton; import com.nextcloud.android.common.ui.theme.utils.ColorRole; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.R; import com.owncloud.android.databinding.NotificationListItemBinding; -import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.resources.notifications.models.Action; import com.owncloud.android.lib.resources.notifications.models.Notification; import com.owncloud.android.lib.resources.notifications.models.RichObject; @@ -71,11 +71,11 @@ public class NotificationListAdapter extends RecyclerView.Adapter notificationsList; - private final OwnCloudClient client; + private final NextcloudClient client; private final NotificationsActivity notificationsActivity; private final ViewThemeUtils viewThemeUtils; - public NotificationListAdapter(OwnCloudClient client, + public NotificationListAdapter(NextcloudClient client, NotificationsActivity notificationsActivity, ViewThemeUtils viewThemeUtils) { this.notificationsList = new ArrayList<>(); diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteAllNotificationsTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteAllNotificationsTask.java index 3afbc89a12..26165a2aae 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteAllNotificationsTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteAllNotificationsTask.java @@ -9,7 +9,7 @@ package com.owncloud.android.ui.asynctasks; import android.os.AsyncTask; -import com.owncloud.android.lib.common.OwnCloudClient; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.notifications.DeleteAllNotificationsRemoteOperation; import com.owncloud.android.lib.resources.notifications.models.Action; @@ -17,10 +17,10 @@ import com.owncloud.android.ui.activity.NotificationsActivity; import com.owncloud.android.ui.notifications.NotificationsContract; public class DeleteAllNotificationsTask extends AsyncTask { - private OwnCloudClient client; - private NotificationsContract.View notificationsActivity; + private NextcloudClient client; + private final NotificationsContract.View notificationsActivity; - public DeleteAllNotificationsTask(OwnCloudClient client, NotificationsActivity notificationsActivity) { + public DeleteAllNotificationsTask(NextcloudClient client, NotificationsActivity notificationsActivity) { this.client = client; this.notificationsActivity = notificationsActivity; } diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteNotificationTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteNotificationTask.java index 2e414e005d..458e642b49 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteNotificationTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteNotificationTask.java @@ -9,7 +9,7 @@ package com.owncloud.android.ui.asynctasks; import android.os.AsyncTask; -import com.owncloud.android.lib.common.OwnCloudClient; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.notifications.DeleteNotificationRemoteOperation; import com.owncloud.android.lib.resources.notifications.models.Action; @@ -21,10 +21,10 @@ import com.owncloud.android.ui.notifications.NotificationsContract; public class DeleteNotificationTask extends AsyncTask { private Notification notification; private NotificationListAdapter.NotificationViewHolder holder; - private OwnCloudClient client; + private NextcloudClient client; private NotificationsContract.View notificationsActivity; - public DeleteNotificationTask(OwnCloudClient client, Notification notification, + public DeleteNotificationTask(NextcloudClient client, Notification notification, NotificationListAdapter.NotificationViewHolder holder, NotificationsActivity notificationsActivity) { this.client = client; diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java index 47b6e8ba9f..1e3d15d650 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java @@ -8,7 +8,12 @@ package com.owncloud.android.ui.asynctasks; import android.os.AsyncTask; -import com.owncloud.android.lib.common.OwnCloudClient; +import com.nextcloud.common.NextcloudClient; +import com.nextcloud.common.OkHttpMethodBase; +import com.nextcloud.operations.DeleteMethod; +import com.nextcloud.operations.GetMethod; +import com.nextcloud.operations.PostMethod; +import com.nextcloud.operations.PutMethod; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.notifications.models.Action; @@ -16,23 +21,20 @@ import com.owncloud.android.lib.resources.notifications.models.Notification; import com.owncloud.android.ui.activity.NotificationsActivity; import com.owncloud.android.ui.adapter.NotificationListAdapter; -import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.DeleteMethod; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PutMethod; -import org.apache.commons.httpclient.methods.Utf8PostMethod; import java.io.IOException; +import okhttp3.RequestBody; + public class NotificationExecuteActionTask extends AsyncTask { - private NotificationListAdapter.NotificationViewHolder holder; - private OwnCloudClient client; - private Notification notification; - private NotificationsActivity notificationsActivity; + private final NotificationListAdapter.NotificationViewHolder holder; + private final NextcloudClient client; + private final Notification notification; + private final NotificationsActivity notificationsActivity; - public NotificationExecuteActionTask(OwnCloudClient client, + public NotificationExecuteActionTask(NextcloudClient client, NotificationListAdapter.NotificationViewHolder holder, Notification notification, NotificationsActivity notificationsActivity) { @@ -44,36 +46,29 @@ public class NotificationExecuteActionTask extends AsyncTask method = new GetMethod(action.link, true); + case "POST" -> method = new PostMethod(action.link, true, RequestBody.create("", null)); + case "DELETE" -> method = new DeleteMethod(action.link, true); + case "PUT" -> method = new PutMethod(action.link, true, null); + default -> { + // do nothing + return Boolean.FALSE; + } + } + + method.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE); int status; try { - status = client.executeMethod(method); + status = client.execute(method); } catch (IOException e) { Log_OC.e(this, "Execution of notification action failed: " + e); return Boolean.FALSE; diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 8fc5b31d37..3d8dda2670 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -672,6 +672,7 @@ Sem envio de notificações devido à sessão de login desatualizada. Considere readicionar sua conta. Atualmente o envio de notificações está indisponível. Não foi possível ler o código QR! + A pasta não pode ser encontrada, a operação de sincronização foi cancelada Experimente %1$s em seu dispositivo! Quero convidar você a usar %1$s em seu dispositivo.\nBaixe daqui: %2$s %1$s ou %2$s diff --git a/app/src/main/res/values-sr/strings.xml b/app/src/main/res/values-sr/strings.xml index 2d7c5ab9f1..7f6dc7a660 100644 --- a/app/src/main/res/values-sr/strings.xml +++ b/app/src/main/res/values-sr/strings.xml @@ -672,6 +672,7 @@ Нема брзих обавештења јер је сесија застарела. Избришите и додајте поново налог. Брза обавештења тренутно нису доступна. QR кôд није могао да се прочита! + Не може да се пронађе фолдер, операција синхронизације је отказана Испробај %1$s на свом уређају! Желим да те позовем да испробаш %1$s на свом уређају.\nПреузми га овде: %2$s %1$s или %2$s diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 2a77423846..d9a1b24e93 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -672,6 +672,7 @@ Oturumunuzun süresi dolduğundan anında bildirimler gönderilemez. Lütfen hesabınızı yeniden eklemeyi düşünün. Anında bildirimler şu anda kullanılamıyor. QR kodu okunamadı! + Klasör bulunamadı. Eşitleme işlemi iptal edildi %1$s uygulamasını aygıtınız üzerinde deneyin! Aygıtında %1$s kullanmanı öneriyorum!\nŞuradan indirebilirsin: %2$s %1$s ya da %2$s diff --git a/build.gradle b/build.gradle index e09bc6b973..ccdbe63537 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ */ buildscript { ext { - androidLibraryVersion ="ba9a356aeed51ab59c1e950aedc6d0acf34f0fe5" + androidLibraryVersion = "cda1b08aa81b74201177f29c2326abee62f32c15" androidPluginVersion = '8.4.0' androidxMediaVersion = '1.3.1' androidxTestVersion = "1.5.0" diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 349409bb16..fb4891e889 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -5909,14 +5909,17 @@ - - - - - - - - + + + + + + + + diff --git a/scripts/analysis/detectWrongSettings.sh b/scripts/analysis/detectWrongSettings.sh index e62281ac1d..1af82b0228 100755 --- a/scripts/analysis/detectWrongSettings.sh +++ b/scripts/analysis/detectWrongSettings.sh @@ -4,12 +4,24 @@ # SPDX-FileCopyrightText: 2016 Tobias Kaminsky # SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only -snapshotCount=$(./gradlew dependencies | grep SNAPSHOT | grep -v "com.github.nextcloud:android-library" -c) +snapshotCount=$(./gradlew dependencies | grep SNAPSHOT -c) betaCount=$(grep "true" app/src/main/res/values/setup.xml -c) +libraryHash=$(grep androidLibraryVersion build.gradle | cut -f2 -d'"' | grep "^[0-9a-zA-Z]\{40\}$" -c) -if [[ $snapshotCount -eq 0 && $betaCount -eq 0 ]] ; then - exit 0 -else + +if [[ $snapshotCount -gt 0 ]] ; then + echo "Snapshot found in dependencies" + exit 1 +fi +if [[ $betaCount -gt 0 ]] ; then + echo "Beta is set in setup.xml" + exit 1 +fi + +if [[ $libraryHash -eq 0 ]] ; then + echo "Library hash is wrong!" exit 1 fi +exit 0 +