Use FLAG_IMMUTABLE in download done notification
Without the flag, the app will crash when trying to show the
notification once its target SDK is updated to 31+.
Also update target SDK in tests, and add comments to make sure it is
kept in sync with the actual module.
Fix DownloadServiceTest to verify the change, as it verifies that "1%"
is shown in the notification, which is not necessarily true depending on
the notification UI, especially in S. Remove this assertion, which can
be wrong.
Bug: 191084568
Test: atest DownloadServiceTest
Change-Id: If97ac78d0b89f1cabec6bf5d967f71135430751f
diff --git a/Android.bp b/Android.bp
index 83bdc35..6eeca34 100644
--- a/Android.bp
+++ b/Android.bp
@@ -23,7 +23,7 @@
srcs: ["src/**/*.java"],
sdk_version: "system_current",
min_sdk_version: "29",
- target_sdk_version: "30",
+ target_sdk_version: "30", // Keep in sync with CaptivePortalLoginTests
static_libs: [
"androidx.annotation_annotation",
"androidx.legacy_legacy-support-v4",
diff --git a/src/com/android/captiveportallogin/DownloadService.java b/src/com/android/captiveportallogin/DownloadService.java
index da8eb2c..e9569db 100644
--- a/src/com/android/captiveportallogin/DownloadService.java
+++ b/src/com/android/captiveportallogin/DownloadService.java
@@ -430,7 +430,7 @@
.setIdentifier(String.valueOf(taskId));
final PendingIntent pendingIntent = PendingIntent.getActivity(
- this, 0 /* requestCode */, intent, 0 /* flags */);
+ this, 0 /* requestCode */, intent, PendingIntent.FLAG_IMMUTABLE);
return new Notification.Builder(this, CHANNEL_DOWNLOADS)
.setContentTitle(getResources().getString(R.string.download_completed))
.setContentText(displayName)
diff --git a/tests/Android.bp b/tests/Android.bp
index 78b10c3..b2fdd31 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -23,6 +23,7 @@
srcs: ["src/**/*.java", "src/**/*.kt"],
platform_apis: true,
min_sdk_version: "29",
+ target_sdk_version: "30", // Keep in sync with CaptivePortalLogin
test_suites: ["device-tests"],
static_libs: [
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
index a263944..b6f157f 100644
--- a/tests/AndroidManifest.xml
+++ b/tests/AndroidManifest.xml
@@ -18,8 +18,6 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.captiveportallogin.tests">
- <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="29" />
-
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<application android:debuggable="true">
diff --git a/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt b/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt
index 7139e7c..aba864a 100644
--- a/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt
+++ b/tests/src/com/android/captiveportallogin/DownloadServiceTest.kt
@@ -54,7 +54,6 @@
import java.net.URL
import java.net.URLConnection
import java.nio.charset.StandardCharsets
-import java.text.NumberFormat
import java.util.concurrent.SynchronousQueue
import java.util.concurrent.TimeUnit.MILLISECONDS
import kotlin.math.min
@@ -288,10 +287,6 @@
assertTrue(TEST_FILESIZE / 100 > 0)
inputStream1.setAvailable(TEST_FILESIZE / 100)
- // 1% progress should be shown in the notification
- val progressText = NumberFormat.getPercentInstance().format(.01f)
- findNotification(UiSelector().textContains(progressText))
-
// Setup the connection for the next download with indeterminate progress
val inputStream2 = TestInputStream()
doReturn(inputStream2).`when`(connection).inputStream