Skip to content

Commit acd799c

Browse files
committed
MOBILE-4134 core: Display error when opening APK in Android
1 parent c230fbb commit acd799c

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

scripts/langindex.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,7 @@
14711471
"core.cannotconnecttrouble": "local_moodlemobileapp",
14721472
"core.cannotconnectverify": "local_moodlemobileapp",
14731473
"core.cannotdownloadfiles": "local_moodlemobileapp",
1474+
"core.cannotinstallapk": "local_moodlemobileapp",
14741475
"core.cannotlogoutpageblocks": "local_moodlemobileapp",
14751476
"core.cannotopeninapp": "local_moodlemobileapp",
14761477
"core.cannotopeninappdownload": "local_moodlemobileapp",

src/core/lang.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"cannotconnecttrouble": "We're having trouble connecting to your site.",
1919
"cannotconnectverify": "<strong>Please check the address is correct.</strong>",
2020
"cannotdownloadfiles": "File downloading is disabled. Please contact your site administrator.",
21+
"cannotinstallapk": "For security reasons, it is not allowed to install unknown apps from the Moodle app. Please open the file using a browser.",
2122
"cannotlogoutpageblocks": "Please save or discard your changes before continuing.",
2223
"cannotopeninapp": "This file may not work as expected on this device. Would you like to open it anyway?",
2324
"cannotopeninappdownload": "This file may not work as expected on this device. Would you like to download it anyway?",

src/core/services/file-helper.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { CoreConstants } from '@/core/constants';
2727
import { CoreError } from '@classes/errors/error';
2828
import { makeSingleton, Translate } from '@singletons';
2929
import { CoreNetworkError } from '@classes/errors/network-error';
30+
import { CoreMimetypeUtils } from './utils/mimetype';
3031

3132
/**
3233
* Provider to provide some helper functions regarding files and packages.
@@ -303,18 +304,22 @@ export class CoreFileHelperProvider {
303304
}
304305

305306
/**
306-
* Whether the file has to be opened in browser (external repository).
307-
* The file must have a mimetype attribute.
307+
* Whether the file has to be opened in browser.
308308
*
309309
* @param file The file to check.
310310
* @return Whether the file should be opened in browser.
311311
*/
312312
shouldOpenInBrowser(file: CoreWSFile): boolean {
313-
if (!file || !('isexternalfile' in file) || !file.isexternalfile || !file.mimetype) {
313+
if (!file.mimetype) {
314314
return false;
315315
}
316316

317317
const mimetype = file.mimetype;
318+
if (!('isexternalfile' in file) || !file.isexternalfile) {
319+
return mimetype === 'application/vnd.android.package-archive' ||
320+
CoreMimetypeUtils.getFileExtension(file.filename ?? '') === 'apk';
321+
}
322+
318323
if (mimetype.indexOf('application/vnd.google-apps.') != -1) {
319324
// Google Docs file, always open in browser.
320325
return true;

src/core/services/utils/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { CoreFileEntry } from '@services/file-helper';
3434
import { CoreConstants } from '@/core/constants';
3535
import { CoreWindow } from '@singletons/window';
3636
import { CoreColors } from '@singletons/colors';
37+
import { CoreError } from '@classes/errors/error';
3738

3839
type TreeNode<T> = T & { children: TreeNode<T>[] };
3940

@@ -958,6 +959,8 @@ export class CoreUtilsProvider {
958959
this.openInApp(path);
959960

960961
return;
962+
} else if (extension === 'apk' && CoreApp.isAndroid()) {
963+
throw new CoreError(Translate.instant('core.cannotinstallapk'));
961964
}
962965

963966
// Path needs to be decoded, the file won't be opened if the path has %20 instead of spaces and so.

0 commit comments

Comments
 (0)