Skip to content

Commit

Permalink
Merge pull request #13096 from nextcloud/backport/13084/stable-3.29
Browse files Browse the repository at this point in the history
[stable-3.29] Bugfix General Crash Fixes
  • Loading branch information
tobiasKaminsky authored Jun 14, 2024
2 parents 241ea03 + 4cc4805 commit 7d52acf
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ private void synchronizeData(List<Object> folderAndFiles) {
// get 'fresh data' from the database
mLocalFolder = mStorageManager.getFileByPath(mLocalFolder.getRemotePath());

if (mLocalFolder == null) {
Log_OC.d(TAG,"mLocalFolder cannot be null");
return;
}

// parse data from remote folder
OCFile remoteFolder = FileStorageUtils.fillOCFile((RemoteFile) folderAndFiles.get(0));
remoteFolder.setParentId(mLocalFolder.getParentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package com.owncloud.android.ui.activity;

import android.accounts.Account;
import android.accounts.AuthenticatorException;
import android.annotation.SuppressLint;
import android.app.Activity;
Expand All @@ -31,7 +32,9 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Parcelable;
import android.text.TextUtils;
import android.view.Menu;
Expand Down Expand Up @@ -609,20 +612,34 @@ private void setLeftFragment(Fragment fragment, boolean showSortListGroup) {

private OCFileListFragment getOCFileListFragmentFromFile() {
final Fragment leftFragment = getLeftFragment();
OCFileListFragment listOfFiles = null;
OCFileListFragment listOfFiles;

if (leftFragment instanceof OCFileListFragment) {
listOfFiles = (OCFileListFragment) leftFragment;
} else {
listOfFiles = new OCFileListFragment();
Bundle args = new Bundle();
args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
listOfFiles.setArguments(args);
setLeftFragment(listOfFiles);
getSupportFragmentManager().executePendingTransactions();

FragmentManager fm = getSupportFragmentManager();
boolean isExecutingTransactions = !fm.isStateSaved() && !fm.executePendingTransactions();

if (isExecutingTransactions) {
setLeftFragment(listOfFiles);
fm.executePendingTransactions();
} else {
new Handler(Looper.getMainLooper()).post(() -> {
setLeftFragment(listOfFiles);
fm.executePendingTransactions();
});
}
}

return listOfFiles;
}


public void showFileActions(OCFile file) {
dismissLoadingDialog();
OCFileListFragment listOfFiles = getOCFileListFragmentFromFile();
Expand Down Expand Up @@ -1354,7 +1371,8 @@ private class UploadFinishReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
String uploadedRemotePath = intent.getStringExtra(FileUploadWorker.EXTRA_REMOTE_PATH);
String accountName = intent.getStringExtra(FileUploadWorker.ACCOUNT_NAME);
boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
Account account = getAccount();
boolean sameAccount = accountName != null && account != null && accountName.equals(account.name);
OCFile currentDir = getCurrentDir();
boolean isDescendant = currentDir != null && uploadedRemotePath != null && uploadedRemotePath.startsWith(currentDir.getRemotePath());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,18 +454,21 @@ public int getColumnsCount() {
* Restore index and position
*/
protected void restoreIndexAndTopPosition() {
if (mIndexes.size() > 0) {
// needs to be checked; not every browse-up had a browse-down before
if (mIndexes == null || mIndexes.isEmpty()) {
Log_OC.d(TAG,"Indexes is null or empty");
return;
}

int index = mIndexes.remove(mIndexes.size() - 1);
final int firstPosition = mFirstPositions.remove(mFirstPositions.size() - 1);
int top = mTops.remove(mTops.size() - 1);
// needs to be checked; not every browse-up had a browse-down before

Log_OC.v(TAG, "Setting selection to position: " + firstPosition + "; top: "
+ top + "; index: " + index);
int index = mIndexes.remove(mIndexes.size() - 1);
final int firstPosition = mFirstPositions.remove(mFirstPositions.size() - 1);
int top = mTops.remove(mTops.size() - 1);

scrollToPosition(firstPosition);
}
Log_OC.v(TAG, "Setting selection to position: " + firstPosition + "; top: "
+ top + "; index: " + index);

scrollToPosition(firstPosition);
}

private void scrollToPosition(int position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,24 @@ public void listDirectory(OCFile directory, boolean onlyOnDevice, boolean fromSe
listDirectory(directory, null, onlyOnDevice, fromSearch);
}

private OCFile getDirectoryForListDirectory(OCFile directory, FileDataStorageManager storageManager) {
if (directory == null) {
if (mFile != null) {
directory = mFile;
} else {
directory = storageManager.getFileByPath(ROOT_PATH);
}
}

// If that's not a directory -> List its parent
if (!directory.isFolder()) {
Log_OC.w(TAG, "You see, that is not a directory -> " + directory);
directory = storageManager.getFileById(directory.getParentId());
}

return directory;
}

/**
* Lists the given directory on the view. When the input parameter is null, it will either refresh the last known
* directory. list the root if there never was a directory.
Expand All @@ -1301,52 +1319,47 @@ public void listDirectory(OCFile directory, boolean onlyOnDevice, boolean fromSe
public void listDirectory(OCFile directory, OCFile file, boolean onlyOnDevice, boolean fromSearch) {
if (!searchFragment) {
FileDataStorageManager storageManager = mContainerActivity.getStorageManager();
if (storageManager != null) {
// Check input parameters for null
if (directory == null) {
if (mFile != null) {
directory = mFile;
} else {
directory = storageManager.getFileByPath(ROOT_PATH);
if (directory == null) {
return; // no files, wait for sync
}
}
}
if (storageManager == null) {
Log_OC.d(TAG, "fileDataStorageManager is null");
return;
}

// If that's not a directory -> List its parent
if (!directory.isFolder()) {
Log_OC.w(TAG, "You see, that is not a directory -> " + directory);
directory = storageManager.getFileById(directory.getParentId());
directory = getDirectoryForListDirectory(directory, storageManager);
if (directory == null) {
Log_OC.d(TAG, "directory is null, no files, wait for sync");
return;
}

if (directory == null) {
return; // no files, wait for sync
}
}
if (mLimitToMimeType == null) {
Log_OC.d(TAG, "mLimitToMimeType is null");
return;
}

mAdapter.swapDirectory(
accountManager.getUser(),
directory,
storageManager,
onlyOnDevice,
mLimitToMimeType
);
if (mAdapter == null) {
Log_OC.d(TAG, "mAdapter is null");
return;
}

OCFile previousDirectory = mFile;
mFile = directory;
mAdapter.swapDirectory(
accountManager.getUser(),
directory,
storageManager,
onlyOnDevice,
mLimitToMimeType);

updateLayout();
OCFile previousDirectory = mFile;
mFile = directory;

if (file != null) {
mAdapter.setHighlightedItem(file);
int position = mAdapter.getItemPosition(file);
if (position != -1) {
getRecyclerView().scrollToPosition(position);
}
} else if (previousDirectory == null || !previousDirectory.equals(directory)) {
getRecyclerView().scrollToPosition(0);
}
updateLayout();

if (file != null) {
mAdapter.setHighlightedItem(file);
int position = mAdapter.getItemPosition(file);
if (position != -1) {
getRecyclerView().scrollToPosition(position);
}
} else if (previousDirectory == null || !previousDirectory.equals(directory)) {
getRecyclerView().scrollToPosition(0);
}
} else if (isSearchEventSet(searchEvent)) {
handleSearchEvent(searchEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
}
}


@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.nextcloud.client.network.ClientFactory
import com.nextcloud.common.NextcloudClient
import com.owncloud.android.lib.common.SearchProviders
import com.owncloud.android.lib.common.utils.Log_OC
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand All @@ -24,12 +25,18 @@ class UnifiedSearchRemoteRepository(
) : IUnifiedSearchRepository {

private var providers: SearchProviders? = null
private val tag = "UnifiedSearchRemoteRepository"

private fun runAsyncWithNcClient(callback: (client: NextcloudClient) -> Unit) =
CoroutineScope(Dispatchers.IO).launch {
private fun runAsyncWithNcClient(callback: (client: NextcloudClient) -> Unit) {
val coroutineExceptionHandler = CoroutineExceptionHandler { _, exception ->
Log_OC.d(tag, "CoroutineExceptionHandler got at runAsyncWithNcClient $exception")
}

CoroutineScope(Dispatchers.IO).launch(coroutineExceptionHandler) {
val client = clientFactory.createNextcloudClient(currentAccountProvider.user)
callback(client)
}
}

override fun queryAll(
query: String,
Expand Down

0 comments on commit 7d52acf

Please sign in to comment.