[go: nahoru, domu]

Change EditorRequest.createFromIntent to set the package

Test: Presubmit
RelNote: EditorRequest now specifies package name rather than ComponentName because it was inconveniant for SysUI to look up the class name of the editor, and we only really need the package name.
Change-Id: Ib68146df783dca74b2944d60fa5e5a762a2348d9
diff --git a/wear/wear-watchface-editor/api/current.txt b/wear/wear-watchface-editor/api/current.txt
index b7b2db0..daadcc5 100644
--- a/wear/wear-watchface-editor/api/current.txt
+++ b/wear/wear-watchface-editor/api/current.txt
@@ -2,13 +2,13 @@
 package androidx.wear.watchface.editor {
 
   public final class EditorRequest {
-    ctor public EditorRequest(android.content.ComponentName watchFaceComponentName, android.content.ComponentName editorComponentName, String? watchFaceInstanceId, java.util.Map<java.lang.String,java.lang.String>? initialUserStyle);
+    ctor public EditorRequest(android.content.ComponentName watchFaceComponentName, String editorPackageName, String? watchFaceInstanceId, java.util.Map<java.lang.String,java.lang.String>? initialUserStyle);
     method public static androidx.wear.watchface.editor.EditorRequest? createFromIntent(android.content.Intent intent);
-    method public android.content.ComponentName getEditorComponentName();
+    method public String getEditorPackageName();
     method public java.util.Map<java.lang.String,java.lang.String>? getInitialUserStyle();
     method public android.content.ComponentName getWatchFaceComponentName();
     method public String? getWatchFaceInstanceId();
-    property public final android.content.ComponentName editorComponentName;
+    property public final String editorPackageName;
     property public final java.util.Map<java.lang.String,java.lang.String>? initialUserStyle;
     property public final android.content.ComponentName watchFaceComponentName;
     property public final String? watchFaceInstanceId;
diff --git a/wear/wear-watchface-editor/api/public_plus_experimental_current.txt b/wear/wear-watchface-editor/api/public_plus_experimental_current.txt
index b7b2db0..daadcc5 100644
--- a/wear/wear-watchface-editor/api/public_plus_experimental_current.txt
+++ b/wear/wear-watchface-editor/api/public_plus_experimental_current.txt
@@ -2,13 +2,13 @@
 package androidx.wear.watchface.editor {
 
   public final class EditorRequest {
-    ctor public EditorRequest(android.content.ComponentName watchFaceComponentName, android.content.ComponentName editorComponentName, String? watchFaceInstanceId, java.util.Map<java.lang.String,java.lang.String>? initialUserStyle);
+    ctor public EditorRequest(android.content.ComponentName watchFaceComponentName, String editorPackageName, String? watchFaceInstanceId, java.util.Map<java.lang.String,java.lang.String>? initialUserStyle);
     method public static androidx.wear.watchface.editor.EditorRequest? createFromIntent(android.content.Intent intent);
-    method public android.content.ComponentName getEditorComponentName();
+    method public String getEditorPackageName();
     method public java.util.Map<java.lang.String,java.lang.String>? getInitialUserStyle();
     method public android.content.ComponentName getWatchFaceComponentName();
     method public String? getWatchFaceInstanceId();
-    property public final android.content.ComponentName editorComponentName;
+    property public final String editorPackageName;
     property public final java.util.Map<java.lang.String,java.lang.String>? initialUserStyle;
     property public final android.content.ComponentName watchFaceComponentName;
     property public final String? watchFaceInstanceId;
diff --git a/wear/wear-watchface-editor/api/restricted_current.txt b/wear/wear-watchface-editor/api/restricted_current.txt
index 3213be4..9e49d3e4 100644
--- a/wear/wear-watchface-editor/api/restricted_current.txt
+++ b/wear/wear-watchface-editor/api/restricted_current.txt
@@ -19,13 +19,13 @@
   }
 
   public final class EditorRequest {
-    ctor public EditorRequest(android.content.ComponentName watchFaceComponentName, android.content.ComponentName editorComponentName, String? watchFaceInstanceId, java.util.Map<java.lang.String,java.lang.String>? initialUserStyle);
+    ctor public EditorRequest(android.content.ComponentName watchFaceComponentName, String editorPackageName, String? watchFaceInstanceId, java.util.Map<java.lang.String,java.lang.String>? initialUserStyle);
     method public static androidx.wear.watchface.editor.EditorRequest? createFromIntent(android.content.Intent intent);
-    method public android.content.ComponentName getEditorComponentName();
+    method public String getEditorPackageName();
     method public java.util.Map<java.lang.String,java.lang.String>? getInitialUserStyle();
     method public android.content.ComponentName getWatchFaceComponentName();
     method public String? getWatchFaceInstanceId();
-    property public final android.content.ComponentName editorComponentName;
+    property public final String editorPackageName;
     property public final java.util.Map<java.lang.String,java.lang.String>? initialUserStyle;
     property public final android.content.ComponentName watchFaceComponentName;
     property public final String? watchFaceInstanceId;
diff --git a/wear/wear-watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditingSessionTest.kt b/wear/wear-watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditingSessionTest.kt
index 11ec1bf..4c97c61 100644
--- a/wear/wear-watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditingSessionTest.kt
+++ b/wear/wear-watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditingSessionTest.kt
@@ -226,7 +226,7 @@
 @MediumTest
 public class EditorSessionTest {
     private val testComponentName = ComponentName("test.package", "test.class")
-    private val testEditorComponentName = ComponentName("test.package", "test.editor.class")
+    private val testEditorPackageName = "test.package"
     private val testInstanceId = "TEST_INSTANCE_ID"
     private var editorDelegate = Mockito.mock(WatchFace.EditorDelegate::class.java)
     private val screenBounds = Rect(0, 0, 400, 400)
@@ -350,7 +350,7 @@
         return ActivityScenario.launch(
             WatchFaceEditorContractForTest().createIntent(
                 ApplicationProvider.getApplicationContext<Context>(),
-                EditorRequest(testComponentName, testEditorComponentName, instanceId, null)
+                EditorRequest(testComponentName, testEditorPackageName, instanceId, null)
             ).apply {
                 component = ComponentName(
                     ApplicationProvider.getApplicationContext<Context>(),
@@ -916,12 +916,12 @@
         runBlocking {
             val intent = WatchFaceEditorContract().createIntent(
                 ApplicationProvider.getApplicationContext<Context>(),
-                EditorRequest(testComponentName, testEditorComponentName, testInstanceId, null)
+                EditorRequest(testComponentName, testEditorPackageName, testInstanceId, null)
             )
-            assertThat(intent.component).isEqualTo(testEditorComponentName)
+            assertThat(intent.getPackage()).isEqualTo(testEditorPackageName)
 
             val editorRequest = EditorRequest.createFromIntent(intent)!!
-            assertThat(editorRequest.editorComponentName).isEqualTo(testEditorComponentName)
+            assertThat(editorRequest.editorPackageName).isEqualTo(testEditorPackageName)
             assertThat(editorRequest.initialUserStyle).isNull()
             assertThat(editorRequest.watchFaceComponentName).isEqualTo(testComponentName)
             assertThat(editorRequest.watchFaceInstanceId).isEqualTo(testInstanceId)
diff --git a/wear/wear-watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditorSessionGuavaTest.kt b/wear/wear-watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditorSessionGuavaTest.kt
index ea8b0dd..db4bbf4 100644
--- a/wear/wear-watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditorSessionGuavaTest.kt
+++ b/wear/wear-watchface-editor/src/androidTest/java/androidx/wear/watchface/editor/EditorSessionGuavaTest.kt
@@ -51,7 +51,7 @@
 @MediumTest
 public class EditorSessionGuavaTest {
     private val testComponentName = ComponentName("test.package", "test.class")
-    private val testEditorComponentName = ComponentName("test.package", "test.editor.class")
+    private val testEditorPackageName = "test.package"
     private val testInstanceId = "TEST_INSTANCE_ID"
     private var editorDelegate = Mockito.mock(WatchFace.EditorDelegate::class.java)
     private val screenBounds = Rect(0, 0, 400, 400)
@@ -109,7 +109,7 @@
         return ActivityScenario.launch(
             WatchFaceEditorContractForTest().createIntent(
                 ApplicationProvider.getApplicationContext<Context>(),
-                EditorRequest(testComponentName, testEditorComponentName, instanceId, null)
+                EditorRequest(testComponentName, testEditorPackageName, instanceId, null)
             ).apply {
                 component = ComponentName(
                     ApplicationProvider.getApplicationContext<Context>(),
diff --git a/wear/wear-watchface-editor/src/main/java/androidx/wear/watchface/editor/WatchFaceEditorContract.kt b/wear/wear-watchface-editor/src/main/java/androidx/wear/watchface/editor/WatchFaceEditorContract.kt
index b6ae3a6..50792d7 100644
--- a/wear/wear-watchface-editor/src/main/java/androidx/wear/watchface/editor/WatchFaceEditorContract.kt
+++ b/wear/wear-watchface-editor/src/main/java/androidx/wear/watchface/editor/WatchFaceEditorContract.kt
@@ -33,16 +33,13 @@
 internal const val USER_STYLE_KEY: String = "USER_STYLE_KEY"
 internal const val USER_STYLE_VALUES: String = "USER_STYLE_VALUES"
 
-/**
- * The request sent by [WatchFaceEditorContract.createIntent]. The editing session's result should
- * be reported via [Activity.setWatchRequestResult].
- */
+/** The request sent by [WatchFaceEditorContract.createIntent]. */
 public class EditorRequest(
     /** The [ComponentName] of the watch face being edited. */
     public val watchFaceComponentName: ComponentName,
 
-    /** The [ComponentName] of the watch face editor. */
-    public val editorComponentName: ComponentName,
+    /** The package name of the watch face editor APK. */
+    public val editorPackageName: String,
 
     /**
      * Unique ID for the instance of the watch face being edited, only defined for Android R and
@@ -64,7 +61,7 @@
             val componentName =
                 intent.getParcelableExtra<ComponentName>(COMPONENT_NAME_KEY)
                     ?: intent.getParcelableExtra(Constants.EXTRA_WATCH_FACE_COMPONENT)
-            val editorComponentName = intent.component ?: ComponentName("?", "?")
+            val editorPackageName = intent.getPackage() ?: ""
             val instanceId = intent.getStringExtra(INSTANCE_ID_KEY)
             val userStyleKey = intent.getStringArrayExtra(USER_STYLE_KEY)
             val userStyleValue = intent.getStringArrayExtra(USER_STYLE_VALUES)
@@ -74,7 +71,7 @@
                 ) {
                     EditorRequest(
                         componentName,
-                        editorComponentName,
+                        editorPackageName,
                         instanceId,
                         HashMap<String, String>().apply {
                             for (i in userStyleKey.indices) {
@@ -83,7 +80,7 @@
                         }
                     )
                 } else {
-                    EditorRequest(componentName, editorComponentName, instanceId, null)
+                    EditorRequest(componentName, editorPackageName, instanceId, null)
                 }
             }
         }
@@ -118,7 +115,7 @@
             "watchFaceInstanceId must be set from Android R and above"
         }
         return Intent(ACTION_WATCH_FACE_EDITOR).apply {
-            component = input.editorComponentName
+            setPackage(input.editorPackageName)
             putExtra(COMPONENT_NAME_KEY, input.watchFaceComponentName)
             putExtra(INSTANCE_ID_KEY, input.watchFaceInstanceId)
             input.initialUserStyle?.let {