Convert LifecycleOwner to Kotlin

Part of the kotlinification process of Lifecycle library.

RelNote: "`LifecycleOwner` is now written in Kotlin.
This is a source incompatible change for classes written
in Kotlin - they must now override the `lifecycle` property
rather than implementing the previous `getLifecycle()` function."
Test: ./gradlew checkApi
Bug: 240298691

Change-Id: I75b4b3ffc999f3f00c6ca57e027dff5e18f54146
diff --git a/lifecycle/lifecycle-common/api/current.txt b/lifecycle/lifecycle-common/api/current.txt
index a339f50..c802eec 100644
--- a/lifecycle/lifecycle-common/api/current.txt
+++ b/lifecycle/lifecycle-common/api/current.txt
@@ -64,6 +64,7 @@
 
   public interface LifecycleOwner {
     method public androidx.lifecycle.Lifecycle getLifecycle();
+    property public abstract androidx.lifecycle.Lifecycle lifecycle;
   }
 
   @Deprecated @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface OnLifecycleEvent {
diff --git a/lifecycle/lifecycle-common/api/public_plus_experimental_current.txt b/lifecycle/lifecycle-common/api/public_plus_experimental_current.txt
index a339f50..c802eec 100644
--- a/lifecycle/lifecycle-common/api/public_plus_experimental_current.txt
+++ b/lifecycle/lifecycle-common/api/public_plus_experimental_current.txt
@@ -64,6 +64,7 @@
 
   public interface LifecycleOwner {
     method public androidx.lifecycle.Lifecycle getLifecycle();
+    property public abstract androidx.lifecycle.Lifecycle lifecycle;
   }
 
   @Deprecated @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME) @java.lang.annotation.Target(java.lang.annotation.ElementType.METHOD) public @interface OnLifecycleEvent {
diff --git a/lifecycle/lifecycle-common/api/restricted_current.txt b/lifecycle/lifecycle-common/api/restricted_current.txt
index 04b9c90..2c8958d 100644
--- a/lifecycle/lifecycle-common/api/restricted_current.txt
+++ b/lifecycle/lifecycle-common/api/restricted_current.txt
@@ -71,6 +71,7 @@
 
   public interface LifecycleOwner {
     method public androidx.lifecycle.Lifecycle getLifecycle();
+    property public abstract androidx.lifecycle.Lifecycle lifecycle;
   }
 
   @RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public final class Lifecycling {
diff --git a/lifecycle/lifecycle-common/src/main/java/androidx/lifecycle/LifecycleOwner.kt b/lifecycle/lifecycle-common/src/main/java/androidx/lifecycle/LifecycleOwner.kt
index 02cc1eb..cdc18d4 100644
--- a/lifecycle/lifecycle-common/src/main/java/androidx/lifecycle/LifecycleOwner.kt
+++ b/lifecycle/lifecycle-common/src/main/java/androidx/lifecycle/LifecycleOwner.kt
@@ -13,10 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-package androidx.lifecycle;
-
-import androidx.annotation.NonNull;
+package androidx.lifecycle
 
 /**
  * A class that has an Android lifecycle. These events can be used by custom components to
@@ -25,13 +22,11 @@
  * @see Lifecycle
  * @see ViewTreeLifecycleOwner
  */
-@SuppressWarnings({"WeakerAccess", "unused"})
 public interface LifecycleOwner {
     /**
      * Returns the Lifecycle of the provider.
      *
      * @return The lifecycle of the provider.
      */
-    @NonNull
-    Lifecycle getLifecycle();
-}
+    public val lifecycle: Lifecycle
+}
\ No newline at end of file
diff --git a/lifecycle/lifecycle-runtime-ktx/src/androidTest/java/androidx/lifecycle/FakeLifecycleOwner.kt b/lifecycle/lifecycle-runtime-ktx/src/androidTest/java/androidx/lifecycle/FakeLifecycleOwner.kt
index bbf9774..10d9fd9 100644
--- a/lifecycle/lifecycle-runtime-ktx/src/androidTest/java/androidx/lifecycle/FakeLifecycleOwner.kt
+++ b/lifecycle/lifecycle-runtime-ktx/src/androidTest/java/androidx/lifecycle/FakeLifecycleOwner.kt
@@ -29,7 +29,8 @@
         }
     }
 
-    override fun getLifecycle(): Lifecycle = registry
+    override val lifecycle: Lifecycle
+        get() = registry
 
     fun setState(state: Lifecycle.State) {
         registry.currentState = state
diff --git a/lifecycle/lifecycle-runtime-ktx/src/androidTest/java/androidx/lifecycle/ViewTreeLifecycleOwnerTest.kt b/lifecycle/lifecycle-runtime-ktx/src/androidTest/java/androidx/lifecycle/ViewTreeLifecycleOwnerTest.kt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lifecycle/lifecycle-runtime-ktx/src/androidTest/java/androidx/lifecycle/ViewTreeLifecycleOwnerTest.kt
diff --git a/lifecycle/lifecycle-runtime-testing/api/current.txt b/lifecycle/lifecycle-runtime-testing/api/current.txt
index dc2274c..47a819e 100644
--- a/lifecycle/lifecycle-runtime-testing/api/current.txt
+++ b/lifecycle/lifecycle-runtime-testing/api/current.txt
@@ -11,6 +11,7 @@
     method public void handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event event);
     method public void setCurrentState(androidx.lifecycle.Lifecycle.State);
     property public final androidx.lifecycle.Lifecycle.State currentState;
+    property public androidx.lifecycle.LifecycleRegistry lifecycle;
     property public final int observerCount;
   }
 
diff --git a/lifecycle/lifecycle-runtime-testing/api/public_plus_experimental_current.txt b/lifecycle/lifecycle-runtime-testing/api/public_plus_experimental_current.txt
index dc2274c..47a819e 100644
--- a/lifecycle/lifecycle-runtime-testing/api/public_plus_experimental_current.txt
+++ b/lifecycle/lifecycle-runtime-testing/api/public_plus_experimental_current.txt
@@ -11,6 +11,7 @@
     method public void handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event event);
     method public void setCurrentState(androidx.lifecycle.Lifecycle.State);
     property public final androidx.lifecycle.Lifecycle.State currentState;
+    property public androidx.lifecycle.LifecycleRegistry lifecycle;
     property public final int observerCount;
   }
 
diff --git a/lifecycle/lifecycle-runtime-testing/api/restricted_current.txt b/lifecycle/lifecycle-runtime-testing/api/restricted_current.txt
index dc2274c..47a819e 100644
--- a/lifecycle/lifecycle-runtime-testing/api/restricted_current.txt
+++ b/lifecycle/lifecycle-runtime-testing/api/restricted_current.txt
@@ -11,6 +11,7 @@
     method public void handleLifecycleEvent(androidx.lifecycle.Lifecycle.Event event);
     method public void setCurrentState(androidx.lifecycle.Lifecycle.State);
     property public final androidx.lifecycle.Lifecycle.State currentState;
+    property public androidx.lifecycle.LifecycleRegistry lifecycle;
     property public final int observerCount;
   }
 
diff --git a/lifecycle/lifecycle-runtime-testing/src/main/java/androidx/lifecycle/testing/TestLifecycleOwner.kt b/lifecycle/lifecycle-runtime-testing/src/main/java/androidx/lifecycle/testing/TestLifecycleOwner.kt
index ddb193b..7e0f455 100644
--- a/lifecycle/lifecycle-runtime-testing/src/main/java/androidx/lifecycle/testing/TestLifecycleOwner.kt
+++ b/lifecycle/lifecycle-runtime-testing/src/main/java/androidx/lifecycle/testing/TestLifecycleOwner.kt
@@ -45,7 +45,9 @@
     private val lifecycleRegistry = LifecycleRegistry.createUnsafe(this).apply {
         currentState = initialState
     }
-    override fun getLifecycle(): LifecycleRegistry = lifecycleRegistry
+
+    override val lifecycle: LifecycleRegistry
+        get() = lifecycleRegistry
 
     /**
      * Update the [currentState] by moving it to the state directly after the given [event].
diff --git a/lifecycle/lifecycle-viewmodel-savedstate/src/androidTest/java/androidx/lifecycle/viewmodel/savedstate/TestComponent.kt b/lifecycle/lifecycle-viewmodel-savedstate/src/androidTest/java/androidx/lifecycle/viewmodel/savedstate/TestComponent.kt
index efdb532..a0c00510 100644
--- a/lifecycle/lifecycle-viewmodel-savedstate/src/androidTest/java/androidx/lifecycle/viewmodel/savedstate/TestComponent.kt
+++ b/lifecycle/lifecycle-viewmodel-savedstate/src/androidTest/java/androidx/lifecycle/viewmodel/savedstate/TestComponent.kt
@@ -45,7 +45,8 @@
         savedStateController.performRestore(bundle)
     }
 
-    override fun getLifecycle(): Lifecycle = lifecycleRegistry
+    override val lifecycle: Lifecycle
+        get() = lifecycleRegistry
     override val savedStateRegistry: SavedStateRegistry
         get() = savedStateController.savedStateRegistry