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

Updates android-browser-helper and enables WebView fallback on config #126

Merged
merged 2 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions packages/core/src/lib/TwaManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const DEFAULT_SIGNING_KEY_ALIAS = 'android';
const DEFAULT_ENABLE_NOTIFICATIONS = false;
const DEFAULT_GENERATOR_APP_NAME = 'unknown';

export type FallbackType = 'customtabs' | 'webview';

/**
* A wrapper around the WebManifest's ShortcutInfo.
*/
Expand Down Expand Up @@ -100,6 +102,7 @@ export class TwaManifest {
shortcuts: ShortcutInfo[];
generatorApp: string;
webManifestUrl?: URL;
fallbackType: FallbackType;

private static log: Log = new Log('twa-manifest');

Expand All @@ -122,6 +125,7 @@ export class TwaManifest {
this.shortcuts = data.shortcuts;
this.generatorApp = data.generatorApp || DEFAULT_GENERATOR_APP_NAME;
this.webManifestUrl = data.webManifestUrl ? new URL(data.webManifestUrl) : undefined;
this.fallbackType = data.fallbackType || 'customtabs';
}

/**
Expand Down Expand Up @@ -290,6 +294,7 @@ export interface TwaManifestJson {
shortcuts: ShortcutInfo[];
generatorApp?: string;
webManifestUrl?: string;
fallbackType?: FallbackType;
}

export interface SigningKeyInfo {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/spec/lib/TwaManifestSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('TwaManifest', () => {
expect(twaManifest.generateShortcuts())
.toBe('[[name:\'shortcut name\', short_name:\'short\',' +
' url:\'https://pwa-directory.com/launch\', icon:\'shortcut_0\']]');
expect(twaManifest.fallbackType).toBe('customtabs');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test as well to check that webview works?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});

it('Sets correct defaults for unavailable fields', () => {
Expand Down
9 changes: 7 additions & 2 deletions packages/core/template_project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ def twaManifest = [
shortcuts: <%= generateShortcuts() %>,
// The duration of fade out animation in milliseconds to be played when removing splash screen.
splashScreenFadeOutDuration: <%= splashScreenFadeOutDuration %>,
generatorApp: '<%= generatorApp %>' // Apllication that generated the Android Project
generatorApp: '<%= generatorApp %>', // Apllication that generated the Android Project
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: type in "Apllication"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// The fallback strategy for when Trusted Web Activity is not avilable. Possible values are
// 'customtabs' and 'webview'.
fallbackType: '<%= fallbackType %>'
]

android {
Expand Down Expand Up @@ -110,6 +113,8 @@ android {
resValue "integer", "splashScreenFadeOutDuration", twaManifest.splashScreenFadeOutDuration.toString()

resValue "string", "generatorApp", twaManifest.generatorApp

resValue "string", "fallbackType", twaManifest.fallbackType
}
buildTypes {
release {
Expand Down Expand Up @@ -161,5 +166,5 @@ preBuild.dependsOn(generateShorcutsFile)

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:1.1.0'
implementation 'com.google.androidbrowserhelper:androidbrowserhelper:1.2.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
the abbreviated format. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="<%= packageId %>">
<uses-permission android:name="android.permission.INTERNET"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this get added in by Android Studio or do we need it for WebView? It's seems a little ugly including it even if we don't need WebView, but on the other hand it's not that much overhead.

Copy link
Member Author

@andreban andreban Mar 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be added for the WebView to work on Android 9 and below. We could conditionally add it, only when the fallback is type webview

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed the "could" on the text. Fixed that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's easy enough let's do it, I don't think it's blocking though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


<application
android:allowBackup="true"
Expand Down Expand Up @@ -70,6 +71,9 @@

<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />

<meta-data android:name="android.support.customtabs.trusted.FALLBACK_STRATEGY"
android:value="@string/fallbackType" />

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -86,6 +90,9 @@

<activity android:name="com.google.androidbrowserhelper.trusted.FocusActivity" />

<activity android:name="com.google.androidbrowserhelper.trusted.WebViewFallbackActivity"
android:configChanges="orientation|screenSize" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="@string/providerAuthority"
Expand Down