Explorar el Código

Merge pull request #13258 from nextcloud/apk

Gplay: do not allow to download APK/AAB
Tobias Kaminsky hace 10 meses
padre
commit
ae1f986468

+ 4 - 2
app/src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java

@@ -205,13 +205,15 @@ public class FileDataStorageManager {
         }
 
         if (!file.isFolder()) {
-            result.add(file);
+            if (!file.isAPKorAAB()) {
+                result.add(file);
+            }
             return result;
         }
 
         List<OCFile> filesInsideFolder = getFolderContent(file.getFileId(), false);
         for (OCFile item: filesInsideFolder) {
-            if (!item.isFolder()) {
+            if (!item.isFolder() && !item.isAPKorAAB()) {
                 result.add(item);
             } else {
                 result.addAll(getAllFilesRecursivelyInsideFolder(item));

+ 9 - 0
app/src/main/java/com/owncloud/android/datamodel/OCFile.java

@@ -20,6 +20,7 @@ import android.os.Parcel;
 import android.os.Parcelable;
 import android.text.TextUtils;
 
+import com.owncloud.android.BuildConfig;
 import com.owncloud.android.R;
 import com.owncloud.android.lib.common.network.WebdavEntry;
 import com.owncloud.android.lib.common.network.WebdavUtils;
@@ -1050,4 +1051,12 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
             this.e2eCounter = e2eCounter;
         }
     }
+    
+    public boolean isAPKorAAB() {
+        if ("gplay".equals(BuildConfig.FLAVOR)) {
+            return getFileName().endsWith(".apk") || getFileName().endsWith(".aab");
+        } else {
+            return false;
+        }
+    }
 }

+ 4 - 0
app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -285,6 +285,10 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
             additionalFilter.add(R.id.action_send_file);
             additionalFilter.add(R.id.action_sync_file);
         }
+        if (getFile().isAPKorAAB()) {
+            additionalFilter.add(R.id.action_download_file);
+            additionalFilter.add(R.id.action_export_file);
+        }
         final FragmentManager fragmentManager = getChildFragmentManager();
         FileActionsBottomSheet.newInstance(file, true, additionalFilter)
             .setResultListener(fragmentManager, this, this::optionsItemSelected)

+ 25 - 1
app/src/main/java/com/owncloud/android/ui/fragment/OCFileListFragment.java

@@ -629,7 +629,16 @@ public class OCFileListFragment extends ExtendedListFragment implements
     public void openActionsMenu(final int filesCount, final Set<OCFile> checkedFiles, final boolean isOverflow) {
         throttler.run("overflowClick", () -> {
             final FragmentManager childFragmentManager = getChildFragmentManager();
-            FileActionsBottomSheet.newInstance(filesCount, checkedFiles, isOverflow)
+
+            List<Integer> toHide = new ArrayList<>();
+            if (isAPKorAAB(checkedFiles)) {
+                toHide.add(R.id.action_send_share_file);
+                toHide.add(R.id.action_export_file);
+                toHide.add(R.id.action_sync_file);
+                toHide.add(R.id.action_download_file);
+            }
+            
+            FileActionsBottomSheet.newInstance(filesCount, checkedFiles, isOverflow, toHide)
                 .setResultListener(childFragmentManager, this, (id) -> {
                     onFileActionChosen(id, checkedFiles);
                 })
@@ -1046,6 +1055,12 @@ public class OCFileListFragment extends ExtendedListFragment implements
     }
 
     private void fileOnItemClick(OCFile file) {
+        if (isAPKorAAB(Set.of(file))) {
+            Snackbar.make(getRecyclerView(),
+                          R.string.gplay_restriction,
+                          Snackbar.LENGTH_LONG).show();
+            return;
+        }
         if (PreviewImageFragment.canBePreviewed(file)) {
             // preview image - it handles the download, if needed
             if (searchFragment) {
@@ -2106,4 +2121,13 @@ public class OCFileListFragment extends ExtendedListFragment implements
     public boolean isEmpty() {
         return mAdapter == null || mAdapter.isEmpty();
     }
+
+    private boolean isAPKorAAB(Set<OCFile> files) {
+        for (OCFile file : files) {
+            if (file.isAPKorAAB()) {
+                return true;
+            }
+        }
+        return false;
+    }
 }

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1214,6 +1214,7 @@
     <string name="sub_folder_rule_day">Year/Month/Day</string>
     <string name="secure_share_not_set_up">Secure sharing is not set up for this user</string>
     <string name="share_not_allowed_when_file_drop">Resharing is not allowed during secure file drop</string>
+    <string name="gplay_restriction">Google restricted downloading APK/AAB files!</string>
     <string name="file_list_empty_local_search">No file or folder matching your search</string>
 
     <string name="unified_search_fragment_calendar_event_not_found">Event not found, you can always sync to update. Redirecting to web…</string>