From 93baf35b077fbeef73222e674034a2201fba43a1 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 2 Mar 2017 18:27:04 +0100 Subject: [PATCH 1/5] Attempt to fix transaction too big --- .../operations/RefreshFolderOperation.java | 9 ++- .../android/syncadapter/FileSyncAdapter.java | 11 ++- .../ui/activity/FileDisplayActivity.java | 9 ++- .../ui/activity/FolderPickerActivity.java | 9 ++- .../ReceiveExternalFilesActivity.java | 7 +- .../android/utils/DataHolderUtil.java | 69 +++++++++++++++++++ 6 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 src/com/owncloud/android/utils/DataHolderUtil.java diff --git a/src/com/owncloud/android/operations/RefreshFolderOperation.java b/src/com/owncloud/android/operations/RefreshFolderOperation.java index df320f8d9450..118cd6a0967f 100644 --- a/src/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/com/owncloud/android/operations/RefreshFolderOperation.java @@ -38,6 +38,7 @@ import com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation; import com.owncloud.android.lib.resources.shares.OCShare; import com.owncloud.android.syncadapter.FileSyncAdapter; +import com.owncloud.android.utils.DataHolderUtil; import com.owncloud.android.utils.FileStorageUtils; import com.owncloud.android.utils.MimeTypeUtil; @@ -519,10 +520,16 @@ private void sendLocalBroadcast( Log_OC.d(TAG, "Send broadcast " + event); Intent intent = new Intent(event); intent.putExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME, mAccount.name); + if (dirRemotePath != null) { intent.putExtra(FileSyncAdapter.EXTRA_FOLDER_PATH, dirRemotePath); } - intent.putExtra(FileSyncAdapter.EXTRA_RESULT, result); + + DataHolderUtil dataHolderUtil = DataHolderUtil.getInstance(); + String dataHolderItemId; + dataHolderUtil.save(dataHolderItemId = dataHolderUtil.nextItemId(), result); + intent.putExtra(FileSyncAdapter.EXTRA_RESULT, dataHolderItemId); + intent.setPackage(mContext.getPackageName()); mContext.sendStickyBroadcast(intent); //LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index f8c5cb83d89f..bfffed54808d 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java @@ -45,6 +45,7 @@ import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.UpdateOCVersionOperation; import com.owncloud.android.ui.activity.ErrorsWhileCopyingHandlerActivity; +import com.owncloud.android.utils.DataHolderUtil; import org.apache.jackrabbit.webdav.DavException; @@ -82,8 +83,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { public static final String EXTRA_FOLDER_PATH = FileSyncAdapter.class.getName() + ".EXTRA_FOLDER_PATH"; public static final String EXTRA_RESULT = FileSyncAdapter.class.getName() + ".EXTRA_RESULT"; - - + /** Time stamp for the current synchronization process, used to distinguish fresh data */ private long mCurrentSyncTime; @@ -373,9 +373,14 @@ private void sendLocalBroadcast(String event, String dirRemotePath, if (dirRemotePath != null) { intent.putExtra(FileSyncAdapter.EXTRA_FOLDER_PATH, dirRemotePath); } + if (result != null) { - intent.putExtra(FileSyncAdapter.EXTRA_RESULT, result); + DataHolderUtil dataHolderUtil = DataHolderUtil.getInstance(); + String dataHolderItemId; + dataHolderUtil.save(dataHolderItemId = dataHolderUtil.nextItemId(), result); + intent.putExtra(FileSyncAdapter.EXTRA_RESULT, dataHolderItemId); } + intent.setPackage(getContext().getPackageName()); getContext().sendStickyBroadcast(intent); //LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent); diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index f795bda9c416..6e96cc246bd6 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -90,6 +90,7 @@ import com.owncloud.android.ui.preview.PreviewMediaFragment; import com.owncloud.android.ui.preview.PreviewTextFragment; import com.owncloud.android.ui.preview.PreviewVideoActivity; +import com.owncloud.android.utils.DataHolderUtil; import com.owncloud.android.utils.DisplayUtils; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.PermissionUtil; @@ -1088,9 +1089,8 @@ public void onReceive(Context context, Intent intent) { String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH); - RemoteOperationResult synchResult = - (RemoteOperationResult) intent.getSerializableExtra( - FileSyncAdapter.EXTRA_RESULT); + RemoteOperationResult synchResult = (RemoteOperationResult) + DataHolderUtil.getInstance().retrieve(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null); @@ -1159,6 +1159,8 @@ public void onReceive(Context context, Intent intent) { } removeStickyBroadcast(intent); + DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); + Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); setIndeterminate(mSyncInProgress); @@ -1174,6 +1176,7 @@ public void onReceive(Context context, Intent intent) { // avoid app crashes after changing the serial id of RemoteOperationResult // in owncloud library with broadcast notifications pending to process removeStickyBroadcast(intent); + DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); } } } diff --git a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java index f0ae165513a6..02cc7103fc7b 100644 --- a/src/com/owncloud/android/ui/activity/FolderPickerActivity.java +++ b/src/com/owncloud/android/ui/activity/FolderPickerActivity.java @@ -52,6 +52,7 @@ import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; import com.owncloud.android.ui.fragment.FileFragment; import com.owncloud.android.ui.fragment.OCFileListFragment; +import com.owncloud.android.utils.DataHolderUtil; import com.owncloud.android.utils.ErrorMessageAdapter; import java.util.ArrayList; @@ -431,9 +432,9 @@ public void onReceive(Context context, Intent intent) { String event = intent.getAction(); Log_OC.d(TAG, "Received broadcast " + event); String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME); - String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH); - RemoteOperationResult synchResult = (RemoteOperationResult)intent. - getSerializableExtra(FileSyncAdapter.EXTRA_RESULT); + String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH); + RemoteOperationResult synchResult = (RemoteOperationResult) + DataHolderUtil.getInstance().retrieve(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null); @@ -495,6 +496,7 @@ public void onReceive(Context context, Intent intent) { } } removeStickyBroadcast(intent); + DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress); setIndeterminate(mSyncInProgress); @@ -506,6 +508,7 @@ public void onReceive(Context context, Intent intent) { // avoid app crashes after changing the serial id of RemoteOperationResult // in owncloud library with broadcast notifications pending to process removeStickyBroadcast(intent); + DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); } } } diff --git a/src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java b/src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java index dcade50c57f3..3b0f23f5a625 100755 --- a/src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java +++ b/src/com/owncloud/android/ui/activity/ReceiveExternalFilesActivity.java @@ -86,6 +86,7 @@ import com.owncloud.android.ui.dialog.CreateFolderDialogFragment; import com.owncloud.android.ui.fragment.TaskRetainerFragment; import com.owncloud.android.ui.helpers.UriUploader; +import com.owncloud.android.utils.DataHolderUtil; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.FileStorageUtils; @@ -1032,9 +1033,8 @@ public void onReceive(Context context, Intent intent) { String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME); String synchFolderRemotePath = intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH); - RemoteOperationResult synchResult = - (RemoteOperationResult) intent.getSerializableExtra( - FileSyncAdapter.EXTRA_RESULT); + RemoteOperationResult synchResult = (RemoteOperationResult) + DataHolderUtil.getInstance().retrieve(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); boolean sameAccount = (getAccount() != null && accountName.equals(getAccount().name) && getStorageManager() != null); @@ -1099,6 +1099,7 @@ public void onReceive(Context context, Intent intent) { // avoid app crashes after changing the serial id of RemoteOperationResult // in owncloud library with broadcast notifications pending to process removeStickyBroadcast(intent); + DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT)); } } } diff --git a/src/com/owncloud/android/utils/DataHolderUtil.java b/src/com/owncloud/android/utils/DataHolderUtil.java new file mode 100644 index 000000000000..25dba0055ea3 --- /dev/null +++ b/src/com/owncloud/android/utils/DataHolderUtil.java @@ -0,0 +1,69 @@ +/** + * Nextcloud Android client application + * + * @author Mario Danic + * Copyright (C) 2017 Mario Danic + *

+ * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + *

+ * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package com.owncloud.android.utils; + +import java.lang.ref.WeakReference; +import java.math.BigInteger; +import java.security.SecureRandom; +import java.util.HashMap; +import java.util.Map; + +/** + * Data holder utility to store & retrieve stuff + */ + +public class DataHolderUtil { + Map> data = new HashMap>(); + + private static DataHolderUtil instance; + + private SecureRandom random = new SecureRandom(); + + public static synchronized DataHolderUtil getInstance() { + if (instance == null) { + instance = new DataHolderUtil(); + } + return instance; + } + + public void save(String id, Object object) { + data.put(id, new WeakReference(object)); + } + + public Object retrieve(String id) { + WeakReference objectWeakReference = data.get(id); + return objectWeakReference.get(); + } + + public void delete(String id) { + data.remove(id); + } + + + public String nextItemId() { + String nextItemId = new BigInteger(130, random).toString(32); + while (data.containsKey(nextItemId)) { + nextItemId = new BigInteger(130, random).toString(32); + } + return nextItemId; + } + + +} From dff70117aae5e36fa498312e7346ffb284ec91d4 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 2 Mar 2017 18:30:07 +0100 Subject: [PATCH 2/5] Sanity --- src/com/owncloud/android/utils/DataHolderUtil.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/com/owncloud/android/utils/DataHolderUtil.java b/src/com/owncloud/android/utils/DataHolderUtil.java index 25dba0055ea3..ba6881094470 100644 --- a/src/com/owncloud/android/utils/DataHolderUtil.java +++ b/src/com/owncloud/android/utils/DataHolderUtil.java @@ -53,7 +53,9 @@ public Object retrieve(String id) { } public void delete(String id) { - data.remove(id); + if (id != null) { + data.remove(id); + } } From 1e884dedef6590772b9318feb1d4940b0727eba7 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 2 Mar 2017 19:02:04 +0100 Subject: [PATCH 3/5] Scope things --- src/com/owncloud/android/utils/DataHolderUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/owncloud/android/utils/DataHolderUtil.java b/src/com/owncloud/android/utils/DataHolderUtil.java index ba6881094470..eb46618afbf2 100644 --- a/src/com/owncloud/android/utils/DataHolderUtil.java +++ b/src/com/owncloud/android/utils/DataHolderUtil.java @@ -30,7 +30,7 @@ */ public class DataHolderUtil { - Map> data = new HashMap>(); + private Map> data = new HashMap>(); private static DataHolderUtil instance; From 1e310b00fbe24d118799e3fed77132742c609337 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 2 Mar 2017 19:15:15 +0100 Subject: [PATCH 4/5] Remove useless spaces --- src/com/owncloud/android/utils/DataHolderUtil.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/com/owncloud/android/utils/DataHolderUtil.java b/src/com/owncloud/android/utils/DataHolderUtil.java index eb46618afbf2..52ac12331617 100644 --- a/src/com/owncloud/android/utils/DataHolderUtil.java +++ b/src/com/owncloud/android/utils/DataHolderUtil.java @@ -58,7 +58,6 @@ public void delete(String id) { } } - public String nextItemId() { String nextItemId = new BigInteger(130, random).toString(32); while (data.containsKey(nextItemId)) { @@ -66,6 +65,4 @@ public String nextItemId() { } return nextItemId; } - - } From c25b9284fa3a336c69a6319feef6f0dc08dc9a49 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Thu, 2 Mar 2017 20:02:15 +0100 Subject: [PATCH 5/5] Reorganization --- .../owncloud/android/operations/RefreshFolderOperation.java | 4 ++-- src/com/owncloud/android/syncadapter/FileSyncAdapter.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/owncloud/android/operations/RefreshFolderOperation.java b/src/com/owncloud/android/operations/RefreshFolderOperation.java index 118cd6a0967f..2294f4c69b93 100644 --- a/src/com/owncloud/android/operations/RefreshFolderOperation.java +++ b/src/com/owncloud/android/operations/RefreshFolderOperation.java @@ -526,8 +526,8 @@ private void sendLocalBroadcast( } DataHolderUtil dataHolderUtil = DataHolderUtil.getInstance(); - String dataHolderItemId; - dataHolderUtil.save(dataHolderItemId = dataHolderUtil.nextItemId(), result); + String dataHolderItemId = dataHolderUtil.nextItemId(); + dataHolderUtil.save(dataHolderItemId, result); intent.putExtra(FileSyncAdapter.EXTRA_RESULT, dataHolderItemId); intent.setPackage(mContext.getPackageName()); diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index bfffed54808d..ed040eb3af35 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java @@ -376,8 +376,8 @@ private void sendLocalBroadcast(String event, String dirRemotePath, if (result != null) { DataHolderUtil dataHolderUtil = DataHolderUtil.getInstance(); - String dataHolderItemId; - dataHolderUtil.save(dataHolderItemId = dataHolderUtil.nextItemId(), result); + String dataHolderItemId = dataHolderUtil.nextItemId(); + dataHolderUtil.save(dataHolderUtil.nextItemId(), result); intent.putExtra(FileSyncAdapter.EXTRA_RESULT, dataHolderItemId); }