Fix Launch App Links Assistant conditions
Fixes: 361392280
Test: AppLinksValidDetectorTest
Change-Id: I98470fec067d34f414dd813c11e5008393f3f014
diff --git a/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt b/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt
index c8d22b1..651ad18 100644
--- a/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt
+++ b/lint/libs/lint-checks/src/main/java/com/android/tools/lint/checks/AppLinksValidDetector.kt
@@ -1202,7 +1202,8 @@
// All schemes in the intent filter must be web schemes for domain verification to be
// requested.
// This is a bug in Android, but they have no intent to fix it.
- (!data.schemes.all { isWebScheme(it) || isSubstituted(it) }) ||
+ (data.schemes.isNotEmpty() &&
+ !data.schemes.all { isWebScheme(it) || isSubstituted(it) }) ||
data.hostPortPairs.isEmpty()))
}
diff --git a/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt b/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt
index 7b50d64..df4ae1b 100644
--- a/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt
+++ b/lint/libs/lint-tests/src/test/java/com/android/tools/lint/checks/AppLinksValidDetectorTest.kt
@@ -2025,7 +2025,7 @@
<data android:pathPrefix="/gizmos" />
</intent-filter>
- <intent-filter android:autoVerify="true"> <!-- Missing http -->
+ <intent-filter android:autoVerify="true"> <!-- Has custom scheme, but missing http -->
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
@@ -2036,6 +2036,15 @@
<data android:pathPrefix="/gizmos" />
</intent-filter>
+ <intent-filter android:autoVerify="true"> <!-- Has no scheme -->
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data android:host="example.com" />
+ <data android:pathPrefix="/gizmos" />
+ </intent-filter>
+
<intent-filter android:autoVerify="true"> <!-- Missing host -->
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
@@ -2043,11 +2052,15 @@
<data android:scheme="http" />
<data android:scheme="https" />
+ </intent-filter>
+ <intent-filter android:autoVerify="true"> <!-- No data tags at all -->
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
</application>
-
</manifest>
""",
)
@@ -2069,16 +2082,57 @@
<intent-filter android:autoVerify="true"> <!-- Missing BROWSABLE -->
^
AndroidManifest.xml:60: Error: Missing required elements/attributes for Android App Links [AppLinkUrlError]
- <intent-filter android:autoVerify="true"> <!-- Missing http -->
+ <intent-filter android:autoVerify="true"> <!-- Has custom scheme, but missing http -->
^
- AndroidManifest.xml:71: Error: Missing required elements/attributes for Android App Links [AppLinkUrlError]
+ AndroidManifest.xml:76: Error: At least one scheme must be specified [AppLinkUrlError]
+ <data android:host="example.com" />
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ AndroidManifest.xml:80: Error: Missing required elements/attributes for Android App Links [AppLinkUrlError]
<intent-filter android:autoVerify="true"> <!-- Missing host -->
^
- 6 errors, 0 warnings
+ AndroidManifest.xml:89: Error: Missing data element [AppLinkUrlError]
+ <intent-filter android:autoVerify="true"> <!-- No data tags at all -->
+ ^
+ 8 errors, 0 warnings
"""
)
}
+ fun test365376495() {
+ // Regression test for b365376495
+ lint()
+ .files(
+ xml(
+ "AndroidManifest.xml",
+ """
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.helloworld" >
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@style/AppTheme" >
+ <activity android:name=".FullscreenActivity">
+
+ <intent-filter>
+ <action android:name="com.google.android.apps.gmm.GENERIC_WEBVIEW_NOTIFICATION" />
+ <data android:scheme="http" />
+ <data android:scheme="https" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ </intent-filter>
+ </activity>
+ </application>
+ </manifest>
+ """,
+ )
+ .indented()
+ )
+ .run()
+ .expectClean()
+ }
+
fun testPathMatcherOrdering() {
lint()
.files(