Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion app/src/androidTest/java/com/owncloud/android/FileIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public void testRenameFolder() throws IOException {
assertTrue(new SynchronizeFolderOperation(targetContext,
folderPath,
user,
fileDataStorageManager)
fileDataStorageManager,
false)
.execute(targetContext)
.isSuccess());

Expand Down
5 changes: 5 additions & 0 deletions app/src/gplay/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
android:name="android.permission.REQUEST_INSTALL_PACKAGES"
tools:node="remove"/>

<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:node="remove"
tools:ignore="ScopedStorage" />

<application
android:name=".MainApp"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,7 @@ default void onDarkThemeModeChanged(DarkMode mode) {

boolean shouldStopDownloadJobsOnStart();
void setStopDownloadJobsOnStart(boolean value);

boolean isAutoUploadGPlayWarningShown();
void setAutoUploadGPlayWarningShown(boolean value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public final class AppPreferencesImpl implements AppPreferences {
private static final String PREF__TWO_WAY_SYNC_INTERVAL = "two_way_sync_interval";

private static final String PREF__STOP_DOWNLOAD_JOBS_ON_START = "stop_download_jobs_on_start";

private static final String PREF__AUTO_UPLOAD_GPLAY_WARNING_SHOWN = "auto_upload_gplay_warning_shown";

private static final String LOG_ENTRY = "log_entry";

Expand Down Expand Up @@ -824,4 +826,14 @@ public boolean shouldStopDownloadJobsOnStart() {
public void setStopDownloadJobsOnStart(boolean value) {
preferences.edit().putBoolean(PREF__STOP_DOWNLOAD_JOBS_ON_START, value).apply();
}

@Override
public boolean isAutoUploadGPlayWarningShown() {
return preferences.getBoolean(PREF__AUTO_UPLOAD_GPLAY_WARNING_SHOWN, false);
}

@Override
public void setAutoUploadGPlayWarningShown(boolean value) {
preferences.edit().putBoolean(PREF__AUTO_UPLOAD_GPLAY_WARNING_SHOWN, value).apply();
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/nextcloud/utils/BuildHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2024 Tobias Kaminsky <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.utils

object BuildHelper {
const val GPLAY: String = "gplay"
}
2 changes: 2 additions & 0 deletions app/src/main/java/com/owncloud/android/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ private static void updateToAutoUpload(Context context) {
}
}



private static void showAutoUploadAlertDialog(Context context) {
new MaterialAlertDialogBuilder(context, R.style.Theme_ownCloud_Dialog)
.setTitle(R.string.drawer_synced_folders)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.os.Parcelable;
import android.text.TextUtils;

import com.nextcloud.utils.BuildHelper;
import com.owncloud.android.BuildConfig;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.network.WebdavEntry;
Expand Down Expand Up @@ -1084,7 +1085,7 @@ public void setInternalFolderSyncResult(String internalFolderSyncResult) {
}

public boolean isAPKorAAB() {
if ("gplay".equals(BuildConfig.FLAVOR)) {
if (BuildHelper.GPLAY.equals(BuildConfig.FLAVOR)) {
return getFileName().endsWith(".apk") || getFileName().endsWith(".aab");
} else {
return false;
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.Manifest;
import android.accounts.Account;
import android.accounts.AuthenticatorException;
import android.annotation.SuppressLint;
Expand Down Expand Up @@ -50,6 +51,7 @@
import com.nextcloud.client.account.User;
import com.nextcloud.client.appinfo.AppInfo;
import com.nextcloud.client.core.AsyncRunner;
import com.nextcloud.client.core.Clock;
import com.nextcloud.client.di.Injectable;
import com.nextcloud.client.editimage.EditImageActivity;
import com.nextcloud.client.files.DeepLinkHandler;
Expand All @@ -64,17 +66,21 @@
import com.nextcloud.client.utils.IntentUtil;
import com.nextcloud.model.WorkerState;
import com.nextcloud.model.WorkerStateLiveData;
import com.nextcloud.utils.BuildHelper;
import com.nextcloud.utils.extensions.ActivityExtensionsKt;
import com.nextcloud.utils.extensions.BundleExtensionsKt;
import com.nextcloud.utils.extensions.FileExtensionsKt;
import com.nextcloud.utils.extensions.IntentExtensionsKt;
import com.nextcloud.utils.fileNameValidator.FileNameValidator;
import com.nextcloud.utils.view.FastScrollUtils;
import com.owncloud.android.BuildConfig;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.databinding.FilesBinding;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.SyncedFolder;
import com.owncloud.android.datamodel.SyncedFolderProvider;
import com.owncloud.android.datamodel.VirtualFolderType;
import com.owncloud.android.files.services.NameCollisionPolicy;
import com.owncloud.android.lib.common.OwnCloudClient;
Expand Down Expand Up @@ -241,6 +247,8 @@ public class FileDisplayActivity extends FileActivity

@Inject FastScrollUtils fastScrollUtils;
@Inject AsyncRunner asyncRunner;
@Inject Clock clock;
@Inject SyncedFolderProvider syncedFolderProvider;

public static Intent openFileIntent(Context context, User user, OCFile file) {
final Intent intent = new Intent(context, PreviewImageActivity.class);
Expand Down Expand Up @@ -275,12 +283,55 @@ protected void onCreate(Bundle savedInstanceState) {
mPlayerConnection = new PlayerServiceConnection(this);

checkStoragePath();
checkAutoUploadOnGPlay();

initSyncBroadcastReceiver();
observeWorkerState();
registerRefreshFolderEventReceiver();
}

private void checkAutoUploadOnGPlay() {
if (!BuildHelper.GPLAY.equals(BuildConfig.FLAVOR)) {
return;
}

// only show on Android11+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
return;
}

if (PermissionUtil.checkSelfPermission(this, Manifest.permission.MANAGE_EXTERNAL_STORAGE)) {
return;
}

if (preferences.isAutoUploadGPlayWarningShown()) {
return;
}

boolean showInfoDialog = false;
for (SyncedFolder syncedFolder : syncedFolderProvider.getSyncedFolders()) {
// move or delete after success
if (syncedFolder.getUploadAction() == 1 || syncedFolder.getUploadAction() == 2) {
showInfoDialog = true;
break;
}
}

if (showInfoDialog) {
new MaterialAlertDialogBuilder(this, R.style.Theme_ownCloud_Dialog)
.setTitle(R.string.auto_upload_gplay)
.setMessage(R.string.auto_upload_gplay_desc)
.setNegativeButton(R.string.dialog_close, (dialog, which) -> {
dialog.dismiss();
})
.setIcon(R.drawable.nav_synced_folders)
.create()
.show();
}

preferences.setAutoUploadGPlayWarningShown(true);
}

@SuppressWarnings("unchecked")
private void loadSavedInstanceState(Bundle savedInstanceState) {
if (savedInstanceState != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.owncloud.android.ui.fragment.LocalFileListFragment;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.FileSortOrder;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.PermissionUtil;

import java.io.File;
Expand Down Expand Up @@ -567,7 +568,8 @@ public void onDirectoryClick(File directory) {
}

private void checkWritableFolder(File folder) {
boolean canWriteIntoFolder = folder.canWrite();
boolean canWriteIntoFolder = FileStorageUtils.isFolderWritable(folder);

binding.uploadFilesSpinnerBehaviour.setEnabled(canWriteIntoFolder);

TextView textView = findViewById(R.id.upload_files_upload_files_behaviour_text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ class SyncedFolderPreferencesDialogFragment : DialogFragment(), Injectable {
binding?.settingInstantBehaviourContainer?.alpha = ALPHA_DISABLED
return
}
if (syncedFolder!!.localPath != null && File(syncedFolder!!.localPath).canWrite()) {
if (syncedFolder!!.localPath != null &&
FileStorageUtils.isFolderWritable(File(syncedFolder!!.localPath))
) {
binding?.settingInstantBehaviourContainer?.isEnabled = true
binding?.settingInstantBehaviourContainer?.alpha = ALPHA_ENABLED
binding?.settingInstantBehaviourSummary?.text =
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,16 @@ public static boolean checkIfEnoughSpace(OCFile file) {

return checkIfEnoughSpace(availableSpaceOnDevice, file);
}

public static boolean isFolderWritable(File folder) {
File[] children = folder.listFiles();

if (children != null && children.length > 0) {
return children[0].canWrite();
} else {
return folder.canWrite();
}
}

@VisibleForTesting
public static boolean checkIfEnoughSpace(long availableSpaceOnDevice, OCFile file) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1253,4 +1253,6 @@
<string name="two_way_sync_activity_empty_list_desc">To set up a two way sync folder, please enable it in the details tab of the folder in question.</string>
<string name="two_way_sync_activity_title">Internal two way sync</string>
<string name="two_way_sync_activity_disable_all_button_title">Disable for all folders</string>
<string name="auto_upload_gplay">Auto upload behaviour changed</string>
<string name="auto_upload_gplay_desc">Due to new restrictions imposed by Google, the auto upload feature will no longer be able to automatically remove uploaded files.</string>
</resources>
Loading