[go: nahoru, domu]

Update proguard to only keep classes that extend SidecarCallback.

Update proguard to only keep classes that extend SidecarCallback.
Proguard is removing these classes because the methods are called from
the framework side. These were removed because there isn't a codepath
from an app that will trigger it directly.

Bug: 165268619
Test: Manual - run on devices with and without sidecar and extensions
Test: minify the samples
Test: open the sample apk
Test: open the Display Feature sample
Test: expect no crashes
Change-Id: Ie6853cdbc9e8a7b75a173e99c7896ea4155c0376
diff --git a/window/window/proguard-rules.pro b/window/window/proguard-rules.pro
index 7120349..6e59017 100644
--- a/window/window/proguard-rules.pro
+++ b/window/window/proguard-rules.pro
@@ -12,20 +12,14 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Some methods in androidx.window.extensions are accessed through reflection and need to be kept.
-# Failure to do so can cause bugs such as b/157286362. This could be overly broad too and should
-# ideally be trimmed down to only the classes/methods that actually need to be kept. This should
-# be tracked in b/165268619.
--keep class androidx.window.extensions.** { *; }
--dontwarn androidx.window.extensions.**
--keep class androidx.window.extensions.embedding.** { *; }
--dontwarn androidx.window.extensions.embedding.**
-
-# Keep the whole library for now since there is a crash with a missing method.
-# TODO(b/165268619) Make a narrow rule
--keep class androidx.window.** { *; }
-
-# We also neep to keep sidecar.** for the same reason.
--keep class androidx.window.sidecar.** { *; }
--dontwarn androidx.window.sidecar.**
-
+# A rule that will keep classes that implement SidecarInterface$SidecarCallback if Sidecar seems
+# be used. See b/157286362 and b/165268619 for details.
+# TODO(b/208543178) investigate how to pass header jar to R8 so we don't need this rule
+-if class androidx.window.layout.SidecarCompat {
+  public setExtensionCallback(androidx.window.layout.ExtensionInterfaceCompat$ExtensionCallbackInterface);
+}
+-keep class androidx.window.layout.SidecarCompat$TranslatingCallback,
+ androidx.window.layout.SidecarCompat$DistinctSidecarElementCallback {
+  public onDeviceStateChanged(androidx.window.sidecar.SidecarDeviceState);
+  public onWindowLayoutChanged(android.os.IBinder, androidx.window.sidecar.SidecarWindowLayoutInfo);
+}
\ No newline at end of file
diff --git a/window/window/src/main/java/androidx/window/layout/SidecarCompat.kt b/window/window/src/main/java/androidx/window/layout/SidecarCompat.kt
index 4548540..22c24fb 100644
--- a/window/window/src/main/java/androidx/window/layout/SidecarCompat.kt
+++ b/window/window/src/main/java/androidx/window/layout/SidecarCompat.kt
@@ -326,6 +326,11 @@
         override fun onViewDetachedFromWindow(view: View) {}
     }
 
+    /**
+     * A callback to translate from Sidecar classes to local classes.
+     *
+     * If you change the name of this class, you must update the proguard file.
+     */
     internal inner class TranslatingCallback : SidecarCallback {
         @SuppressLint("SyntheticAccessor")
         override fun onDeviceStateChanged(newDeviceState: SidecarDeviceState) {
@@ -397,6 +402,8 @@
      * A class to record the last calculated values from [SidecarInterface] and filter out
      * duplicates. This class uses [SidecarAdapter] to compute equality since the methods
      * [Object.equals] and [Object.hashCode] may not have been overridden.
+     *
+     * If you change the name of this class, you must update the proguard file.
      */
     private class DistinctSidecarElementCallback(
         private val sidecarAdapter: SidecarAdapter,