Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/app lancher check for external app #1590

Merged
merged 6 commits into from
Jan 3, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ jobs:
uses: android-actions/setup-android@v2

- name: Fix Android directories
run: rm -R /usr/local/lib/android/sdk/build-tools/31.0.0/ && rm -R /usr/local/lib/android/sdk/build-tools/32.0.0/ && rm -R /usr/local/lib/android/sdk/build-tools/33.0.0/
run: rm -R /usr/local/lib/android/sdk/build-tools/31.0.0/ && rm -R /usr/local/lib/android/sdk/build-tools/32.0.0/ && rm -R /usr/local/lib/android/sdk/build-tools/33.0.0/ && rm -R /usr/local/lib/android/sdk/build-tools/33.0.1/

- name: Setup Node
uses: actions/setup-node@v2
9 changes: 6 additions & 3 deletions config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget android-versionCode="572" id="org.phidatalab.radar_armt" ios-CFBundleIdentifier="org.phidatalab.radar-armt" ios-CFBundleVersion="1" version="2.6.2-alpha" xmlns:android="http://schemas.android.com/apk/res/android">
<widget android-versionCode="573" id="org.phidatalab.radar_armt" ios-CFBundleIdentifier="org.phidatalab.radar-armt" ios-CFBundleVersion="1" version="2.6.3-alpha" xmlns:android="http://schemas.android.com/apk/res/android">
<name>RADAR Questionnaire</name>
<description>An application that collects active data for research.</description>
<author email="radar-base@kcl.ac.uk" href="http://radar-base.org/">RADAR-Base</author>
@@ -48,9 +48,12 @@
<resource-file src="resources/android/notification/drawable-xhdpi-icon.png" target="app/src/main/res/drawable-xhdpi/notification_icon.png" />
<resource-file src="resources/android/notification/drawable-xxhdpi-icon.png" target="app/src/main/res/drawable-xxhdpi/notification_icon.png" />
<resource-file src="resources/android/notification/drawable-xxxhdpi-icon.png" target="app/src/main/res/drawable-xxxhdpi/notification_icon.png" />
<custom-config-file parent="./application" target="AndroidManifest.xml">
<config-file parent="/manifest/application/" target="app/src/main/AndroidManifest.xml">
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
</custom-config-file>
</config-file>
<config-file parent="/manifest/" target="app/src/main/AndroidManifest.xml">
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
</config-file>
<custom-preference name="android-manifest/application/@android:requestLegacyExternalStorage" value="true" />
<custom-preference name="android-manifest/application/@android:usesCleartextTraffic" value="true" />
</platform>
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ export class FinishAndLaunchComponent implements OnInit, OnChanges {
displayNextTaskReminder = true
completedInClinic = false

canLaunch = true
canLaunch = false
externalAppLaunchDescription = ''

constructor(
@@ -52,7 +52,13 @@ export class FinishAndLaunchComponent implements OnInit, OnChanges {
) {}

ngOnInit() {
this.getExternalAppLaunchDescription()
this.appLauncher.isExternalAppCanLaunch(this.externalApp, this.task).then(canLaunch=>{
this.canLaunch = canLaunch
this.externalAppLaunchDescription = this.getExternalAppLaunchDescription(this.canLaunch)
}).catch(err=>{
console.log(err)
this.externalAppLaunchDescription = this.getExternalAppLaunchDescription(false)
})
}

ngOnChanges() {
@@ -68,18 +74,19 @@ export class FinishAndLaunchComponent implements OnInit, OnChanges {
this.exit.emit(this.completedInClinic)
}

getExternalAppLaunchDescription() {
getExternalAppLaunchDescription(canLaunch: boolean) {
const options = this.appLauncher.getAppLauncherOptions(
this.externalApp,
this.task
)
this.externalAppLaunchDescription =
this.externalApp.field_label && this.externalApp.field_label.length
? this.externalApp.field_label
: this.localization.translateKey(LocKeys.EXTERNAL_APP_LAUNCH_DESC) +
' ' +
(this.externalApp.external_app_name
? this.externalApp.external_app_name
: options.uri.toString())
if(canLaunch){
return this.externalApp.field_label && this.externalApp.field_label.length ?
(this.externalApp.field_label) : (this.localization.translateKey(LocKeys.EXTERNAL_APP_LAUNCH_DESC) + ' ' +
(this.externalApp.external_app_name? this.externalApp.external_app_name : options.uri.toString()))
}else{
return (this.externalApp.external_app_name?
this.externalApp.external_app_name : options.uri.toString())
+ ' ' + this.localization.translateKey(LocKeys.EXTERNAL_APP_FAILURE_ON_VALIDATING)
}
}
}
11 changes: 9 additions & 2 deletions src/app/pages/questions/containers/questions-page.component.ts
Original file line number Diff line number Diff line change
@@ -321,8 +321,15 @@ export class QuestionsPageComponent implements OnInit {
this.externalApp &&
this.appLauncher.isExternalAppUriValidForThePlatform(this.externalApp)
) {
this.showFinishAndLaunchScreen = true
this.externalAppCanLaunch = true
this.appLauncher.isExternalAppCanLaunch(this.externalApp, this.task)
.then(canLaunch => {
this.showFinishAndLaunchScreen = true
this.externalAppCanLaunch = canLaunch
})
.catch(err => {
this.showFinishAndLaunchScreen = false
console.log(err)
})
}
}
}
17 changes: 17 additions & 0 deletions src/app/pages/questions/services/app-launcher.service.ts
Original file line number Diff line number Diff line change
@@ -52,6 +52,23 @@ export class AppLauncherService {
return true
}

isExternalAppCanLaunch(externalApp: Question, task: Task) {
if(!this.isExternalAppUriValidForThePlatform(externalApp)){
return Promise.reject()
}

const options: AppLauncherOptions = this.getAppLauncherOptions(externalApp, task)

return this.appLauncher.canLaunch(options)
.then((canLaunch: boolean) => {
return canLaunch;
})
.catch(err => {
this.logger.error("External App is not installed or doesn't support deeplink.", err)
return false
})
}

getAppLauncherOptions(externalApp: ExternalApp, task: Task) {
const options: AppLauncherOptions = {}

2 changes: 1 addition & 1 deletion src/assets/data/defaultConfig.ts
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ import { Localisations } from './localisations'
export const DefaultPlatformInstance = 'RADAR-CNS'

// *Default app version
export const DefaultAppVersion = '2.6.1-alpha'
export const DefaultAppVersion = '2.6.3-alpha'

// *Default Android package name
export const DefaultPackageName = 'org.phidatalab.radar_armt'