Add a sample that does not handle Config changes.
Add a DisplayFeature sample that does not handle configuration changes.
We have a report of a leak in the library. One way to reproduce this is
to launch the DisplayFeature Activity that does not handle
configuration changes and rotate the device multiple times.
Add a dependency on leak canary so that leaks in the samples are
reported in the future.
Bug: 202250276
Bug: 202989046
Test: manual - launch display feature activity without config change
Test: rotate the device a few times and see Leak Canary report a leak.
Change-Id: Iae7a99bb689fff69366f560053ecfecd9e87a2f0
diff --git a/window/window-samples/build.gradle b/window/window-samples/build.gradle
index 1a91038..2ebcb33 100644
--- a/window/window-samples/build.gradle
+++ b/window/window-samples/build.gradle
@@ -42,6 +42,7 @@
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha02")
implementation(project(":window:window"))
+ debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.7'
}
androidx {
diff --git a/window/window-samples/src/main/AndroidManifest.xml b/window/window-samples/src/main/AndroidManifest.xml
index 12b0911..b33624f 100644
--- a/window/window-samples/src/main/AndroidManifest.xml
+++ b/window/window-samples/src/main/AndroidManifest.xml
@@ -35,11 +35,15 @@
android:exported="false"
android:label="@string/presentation" />
<activity
- android:name=".DisplayFeaturesActivity"
+ android:name=".DisplayFeaturesConfigChangeActivity"
android:exported="false"
android:configChanges=
"orientation|screenSize|screenLayout|screenSize|layoutDirection|smallestScreenSize"
- android:label="@string/display_features" />
+ android:label="@string/display_features_config_change" />
+ <activity
+ android:name=".DisplayFeaturesNoConfigChangeActivity"
+ android:exported="false"
+ android:label="@string/display_features_no_config_change" />
<activity
android:name=".SplitLayoutActivity"
android:exported="false"
diff --git a/window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesActivity.kt b/window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesConfigChangeActivity.kt
similarity index 96%
rename from window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesActivity.kt
rename to window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesConfigChangeActivity.kt
index 2621e0c8..14b55b5 100644
--- a/window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesActivity.kt
+++ b/window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesConfigChangeActivity.kt
@@ -36,14 +36,14 @@
import java.util.Locale
/** Demo activity that shows all display features and current device state on the screen. */
-class DisplayFeaturesActivity : AppCompatActivity() {
+class DisplayFeaturesConfigChangeActivity : AppCompatActivity() {
private val infoLogAdapter = InfoLogAdapter()
private val displayFeatureViews = ArrayList<View>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_display_features)
+ setContentView(R.layout.activity_display_features_config_change)
val recyclerView = findViewById<RecyclerView>(R.id.infoLogRecyclerView)
recyclerView.adapter = infoLogAdapter
diff --git a/window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesActivity.kt b/window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesNoConfigChangeActivity.kt
similarity index 93%
copy from window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesActivity.kt
copy to window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesNoConfigChangeActivity.kt
index 2621e0c8..96da16f 100644
--- a/window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesActivity.kt
+++ b/window/window-samples/src/main/java/androidx/window/sample/DisplayFeaturesNoConfigChangeActivity.kt
@@ -1,5 +1,5 @@
/*
- * Copyright 2020 The Android Open Source Project
+ * Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,15 +35,14 @@
import java.util.Date
import java.util.Locale
-/** Demo activity that shows all display features and current device state on the screen. */
-class DisplayFeaturesActivity : AppCompatActivity() {
+class DisplayFeaturesNoConfigChangeActivity : AppCompatActivity() {
private val infoLogAdapter = InfoLogAdapter()
private val displayFeatureViews = ArrayList<View>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_display_features)
+ setContentView(R.layout.activity_display_features_no_config_change)
val recyclerView = findViewById<RecyclerView>(R.id.infoLogRecyclerView)
recyclerView.adapter = infoLogAdapter
diff --git a/window/window-samples/src/main/java/androidx/window/sample/demos/WindowDemosActivity.kt b/window/window-samples/src/main/java/androidx/window/sample/demos/WindowDemosActivity.kt
index 84183a7..6b39067 100644
--- a/window/window-samples/src/main/java/androidx/window/sample/demos/WindowDemosActivity.kt
+++ b/window/window-samples/src/main/java/androidx/window/sample/demos/WindowDemosActivity.kt
@@ -19,9 +19,14 @@
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
-import androidx.window.sample.DisplayFeaturesActivity
+import androidx.window.sample.DisplayFeaturesConfigChangeActivity
+import androidx.window.sample.DisplayFeaturesNoConfigChangeActivity
import androidx.window.sample.PresentationActivity
import androidx.window.sample.R
+import androidx.window.sample.R.string.display_features_config_change
+import androidx.window.sample.R.string.display_features_no_config_change
+import androidx.window.sample.R.string.show_all_display_features_config_change_description
+import androidx.window.sample.R.string.show_all_display_features_no_config_change_description
import androidx.window.sample.SplitLayoutActivity
import androidx.window.sample.WindowMetricsActivity
@@ -35,9 +40,14 @@
setContentView(R.layout.activity_window_demos)
val demoItems = listOf(
DemoItem(
- buttonTitle = getString(R.string.display_features),
- description = getString(R.string.show_all_display_features_description),
- clazz = DisplayFeaturesActivity::class.java
+ buttonTitle = getString(display_features_config_change),
+ description = getString(show_all_display_features_config_change_description),
+ clazz = DisplayFeaturesConfigChangeActivity::class.java
+ ),
+ DemoItem(
+ buttonTitle = getString(display_features_no_config_change),
+ description = getString(show_all_display_features_no_config_change_description),
+ clazz = DisplayFeaturesNoConfigChangeActivity::class.java
),
DemoItem(
buttonTitle = getString(R.string.window_metrics),
diff --git a/window/window-samples/src/main/res/layout/activity_display_features.xml b/window/window-samples/src/main/res/layout/activity_display_features_config_change.xml
similarity index 96%
rename from window/window-samples/src/main/res/layout/activity_display_features.xml
rename to window/window-samples/src/main/res/layout/activity_display_features_config_change.xml
index 3cd059d..0e877e4 100644
--- a/window/window-samples/src/main/res/layout/activity_display_features.xml
+++ b/window/window-samples/src/main/res/layout/activity_display_features_config_change.xml
@@ -22,7 +22,7 @@
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context="androidx.window.sample.DisplayFeaturesActivity">
+ tools:context="androidx.window.sample.DisplayFeaturesConfigChangeActivity">
<FrameLayout
android:id="@+id/featureContainerLayout"
diff --git a/window/window-samples/src/main/res/layout/activity_display_features.xml b/window/window-samples/src/main/res/layout/activity_display_features_no_config_change.xml
similarity index 95%
copy from window/window-samples/src/main/res/layout/activity_display_features.xml
copy to window/window-samples/src/main/res/layout/activity_display_features_no_config_change.xml
index 3cd059d..3df64a9 100644
--- a/window/window-samples/src/main/res/layout/activity_display_features.xml
+++ b/window/window-samples/src/main/res/layout/activity_display_features_no_config_change.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
- Copyright 2020 The Android Open Source Project
+ Copyright 2021 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context="androidx.window.sample.DisplayFeaturesActivity">
+ tools:context="androidx.window.sample.DisplayFeaturesNoConfigChangeActivity">
<FrameLayout
android:id="@+id/featureContainerLayout"
diff --git a/window/window-samples/src/main/res/values/strings.xml b/window/window-samples/src/main/res/values/strings.xml
index ff0b4c0..a6e8aa3 100644
--- a/window/window-samples/src/main/res/values/strings.xml
+++ b/window/window-samples/src/main/res/values/strings.xml
@@ -24,7 +24,8 @@
<string name="legend">Legend:</string>
<string name="content_title">Content title</string>
<string name="green_droid">Green droid</string>
- <string name="display_features">Display features</string>
+ <string name="display_features_config_change">Display features handle config change</string>
+ <string name="display_features_no_config_change">Display features no config change</string>
<string name="split_layout">Split layout</string>
<string name="presentation">Presentation</string>
<string name="start_presentation">Start presentation</string>
@@ -39,7 +40,8 @@
<string name="long_dimension_fold">Fold in the middle of the window along long
dimension</string>
<string name="test_activity">Test activity</string>
- <string name="show_all_display_features_description">Show all display features of the device on the screen</string>
+ <string name="show_all_display_features_config_change_description">Show all display features of the device on the screen and handle config changes</string>
+ <string name="show_all_display_features_no_config_change_description">Show all display features of the device on the screen and do not handle config changes. The activity is recreated instead on rotation or resize</string>
<string name="split_layout_demo_description">Demo of a layout that splits the content to sides of a fold or a hinge. If not present or minimal size requirements are not meant, it behave like a FrameLayout.</string>
<string name="presentation_demo_description">Demo of using Presentation API to show content on secondary display.</string>
<string name="window_metrics">Window metrics</string>