MOBILE-4145 core: Handle opening apk files
Co-authored-by: Dani Palou <dani@moodle.com>main
parent
609a948945
commit
c24d518594
|
@ -1474,6 +1474,7 @@
|
||||||
"core.cannotconnecttrouble": "local_moodlemobileapp",
|
"core.cannotconnecttrouble": "local_moodlemobileapp",
|
||||||
"core.cannotconnectverify": "local_moodlemobileapp",
|
"core.cannotconnectverify": "local_moodlemobileapp",
|
||||||
"core.cannotdownloadfiles": "local_moodlemobileapp",
|
"core.cannotdownloadfiles": "local_moodlemobileapp",
|
||||||
|
"core.cannotinstallapk": "local_moodlemobileapp",
|
||||||
"core.cannotlogoutpageblocks": "local_moodlemobileapp",
|
"core.cannotlogoutpageblocks": "local_moodlemobileapp",
|
||||||
"core.cannotopeninapp": "local_moodlemobileapp",
|
"core.cannotopeninapp": "local_moodlemobileapp",
|
||||||
"core.cannotopeninappdownload": "local_moodlemobileapp",
|
"core.cannotopeninappdownload": "local_moodlemobileapp",
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
"cannotconnecttrouble": "We're having trouble connecting to your site.",
|
"cannotconnecttrouble": "We're having trouble connecting to your site.",
|
||||||
"cannotconnectverify": "<strong>Please check the address is correct.</strong>",
|
"cannotconnectverify": "<strong>Please check the address is correct.</strong>",
|
||||||
"cannotdownloadfiles": "File downloading is disabled. Please contact your site administrator.",
|
"cannotdownloadfiles": "File downloading is disabled. Please contact your site administrator.",
|
||||||
|
"cannotinstallapk": "For security reasons, you can't install unknown apps on your device from this app. Please open the file using a browser.",
|
||||||
"cannotlogoutpageblocks": "Please save or discard your changes before continuing.",
|
"cannotlogoutpageblocks": "Please save or discard your changes before continuing.",
|
||||||
"cannotopeninapp": "This file may not work as expected on this device. Would you like to open it anyway?",
|
"cannotopeninapp": "This file may not work as expected on this device. Would you like to open it anyway?",
|
||||||
"cannotopeninappdownload": "This file may not work as expected on this device. Would you like to download it anyway?",
|
"cannotopeninappdownload": "This file may not work as expected on this device. Would you like to download it anyway?",
|
||||||
|
|
|
@ -30,6 +30,7 @@ import { makeSingleton, Translate } from '@singletons';
|
||||||
import { CoreNetworkError } from '@classes/errors/network-error';
|
import { CoreNetworkError } from '@classes/errors/network-error';
|
||||||
import { CoreConfig } from './config';
|
import { CoreConfig } from './config';
|
||||||
import { CoreCanceledError } from '@classes/errors/cancelederror';
|
import { CoreCanceledError } from '@classes/errors/cancelederror';
|
||||||
|
import { CoreMimetypeUtils } from '@services/utils/mimetype';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider to provide some helper functions regarding files and packages.
|
* Provider to provide some helper functions regarding files and packages.
|
||||||
|
@ -306,18 +307,23 @@ export class CoreFileHelperProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the file has to be opened in browser (external repository).
|
* Whether the file has to be opened in browser.
|
||||||
* The file must have a mimetype attribute.
|
|
||||||
*
|
*
|
||||||
* @param file The file to check.
|
* @param file The file to check.
|
||||||
* @return Whether the file should be opened in browser.
|
* @return Whether the file should be opened in browser.
|
||||||
*/
|
*/
|
||||||
shouldOpenInBrowser(file: CoreWSFile): boolean {
|
shouldOpenInBrowser(file: CoreWSFile): boolean {
|
||||||
if (!file || !('isexternalfile' in file) || !file.isexternalfile || !file.mimetype) {
|
if (!file.mimetype) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const mimetype = file.mimetype;
|
const mimetype = file.mimetype;
|
||||||
|
|
||||||
|
if (!('isexternalfile' in file) || !file.isexternalfile) {
|
||||||
|
return mimetype === 'application/vnd.android.package-archive'
|
||||||
|
|| CoreMimetypeUtils.getFileExtension(file.filename ?? '') === 'apk';
|
||||||
|
}
|
||||||
|
|
||||||
if (mimetype.indexOf('application/vnd.google-apps.') != -1) {
|
if (mimetype.indexOf('application/vnd.google-apps.') != -1) {
|
||||||
// Google Docs file, always open in browser.
|
// Google Docs file, always open in browser.
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1410,6 +1410,19 @@ export class CoreFilepoolProvider {
|
||||||
return this.getFilePath(siteId, fileId);
|
return this.getFilePath(siteId, fileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the url of a file form its path.
|
||||||
|
*
|
||||||
|
* @param siteId The site ID.
|
||||||
|
* @param path File path.
|
||||||
|
* @returns File url.
|
||||||
|
*/
|
||||||
|
async getFileUrlByPath(siteId: string, path: string): Promise<string> {
|
||||||
|
const record = await this.filesTables[siteId].getOne({ path });
|
||||||
|
|
||||||
|
return record.url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get site Filepool Folder Path
|
* Get site Filepool Folder Path
|
||||||
*
|
*
|
||||||
|
|
|
@ -36,6 +36,9 @@ import { CoreWindow } from '@singletons/window';
|
||||||
import { CoreColors } from '@singletons/colors';
|
import { CoreColors } from '@singletons/colors';
|
||||||
import { CorePromisedValue } from '@classes/promised-value';
|
import { CorePromisedValue } from '@classes/promised-value';
|
||||||
import { CorePlatform } from '@services/platform';
|
import { CorePlatform } from '@services/platform';
|
||||||
|
import { CoreErrorWithOptions } from '@classes/errors/errorwithtitle';
|
||||||
|
import { CoreFilepool } from '@services/filepool';
|
||||||
|
import { CoreSites } from '@services/sites';
|
||||||
|
|
||||||
export type TreeNode<T> = T & { children: TreeNode<T>[] };
|
export type TreeNode<T> = T & { children: TreeNode<T>[] };
|
||||||
|
|
||||||
|
@ -970,6 +973,23 @@ export class CoreUtilsProvider {
|
||||||
this.openInApp(path);
|
this.openInApp(path);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
} else if (extension === 'apk' && CoreApp.isAndroid()) {
|
||||||
|
const url = await CoreUtils.ignoreErrors(
|
||||||
|
CoreFilepool.getFileUrlByPath(CoreSites.getCurrentSiteId(), CoreFile.removeBasePath(path)),
|
||||||
|
);
|
||||||
|
|
||||||
|
// @todo MOBILE-4167: Handle urls with expired tokens.
|
||||||
|
|
||||||
|
throw new CoreErrorWithOptions(
|
||||||
|
Translate.instant('core.cannotinstallapk'),
|
||||||
|
undefined,
|
||||||
|
url
|
||||||
|
? [{
|
||||||
|
text: Translate.instant('core.openinbrowser'),
|
||||||
|
handler: () => this.openInBrowser(url),
|
||||||
|
}]
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Path needs to be decoded, the file won't be opened if the path has %20 instead of spaces and so.
|
// Path needs to be decoded, the file won't be opened if the path has %20 instead of spaces and so.
|
||||||
|
|
Loading…
Reference in New Issue