Skip to content

Commit

Permalink
Gplay: do not allow to download APK/AAB
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <[email protected]>
  • Loading branch information
tobiasKaminsky committed Aug 23, 2024
1 parent 5002593 commit 55f34ec
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,15 @@ public List<OCFile> getAllFilesRecursivelyInsideFolder(OCFile file) {
}

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));
Expand Down
9 changes: 9 additions & 0 deletions 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.owncloud.android.BuildConfig;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.network.WebdavEntry;
import com.owncloud.android.lib.common.network.WebdavUtils;
Expand Down Expand Up @@ -1050,4 +1051,12 @@ public void setE2eCounter(@Nullable Long e2eCounter) {
this.e2eCounter = e2eCounter;
}
}

public boolean isAPKorAAB() {
if ("gplay".equals(BuildConfig.FLAVOR)) {
return getFileName().endsWith(".apk") || getFileName().endsWith(".aab");
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ private void onOverflowIconClicked() {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,16 @@ public void onOverflowIconClicked(OCFile file, View view) {
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);
})
Expand Down Expand Up @@ -1037,6 +1046,12 @@ private void folderOnItemClick(OCFile file, int position) {
}

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) {
Expand Down Expand Up @@ -2063,4 +2078,13 @@ public void setFabEnabled(final boolean enabled) {
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 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,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>
<string name="unified_search_fragment_contact_not_found">Contact not found, you can always sync to update. Redirecting to web…</string>
Expand Down

0 comments on commit 55f34ec

Please sign in to comment.