Migrate "Kernel version" preference

Bug: 365886251
Flag: com.android.settings.flags.catalyst_firmware_version
Test: Unit
Change-Id: Icb50e2d5200f7de40b6f8383c114982cd45d34b5
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionScreen.kt b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionScreen.kt
index 3b70e72..401cd16 100644
--- a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionScreen.kt
+++ b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionScreen.kt
@@ -51,7 +51,7 @@
             +PreferenceWidget("security_key", R.string.security_patch)
             +PreferenceWidget("module_version", R.string.module_version)
             +BasebandVersionPreference()
-            +PreferenceWidget("kernel_version", R.string.kernel_version)
+            +KernelVersionPreference()
             +PreferenceWidget("os_build_number", R.string.build_number)
         }
 
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreference.kt b/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreference.kt
new file mode 100644
index 0000000..7891178
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreference.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2024 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.deviceinfo.firmwareversion
+
+import android.content.Context
+import androidx.preference.Preference
+import com.android.settings.R
+import com.android.settingslib.DeviceInfoUtils
+import com.android.settingslib.metadata.PreferenceMetadata
+import com.android.settingslib.metadata.PreferenceSummaryProvider
+import com.android.settingslib.preference.PreferenceBinding
+
+// LINT.IfChange
+class KernelVersionPreference : PreferenceMetadata, PreferenceSummaryProvider, PreferenceBinding {
+
+    override val key: String
+        get() = "kernel_version"
+
+    override val title: Int
+        get() = R.string.kernel_version
+
+    override fun getSummary(context: Context): CharSequence? =
+        DeviceInfoUtils.getFormattedKernelVersion(context)
+
+    override fun bind(preference: Preference, metadata: PreferenceMetadata) {
+        super.bind(preference, metadata)
+        preference.isSelectable = false
+        preference.isCopyingEnabled = true
+    }
+}
+// LINT.ThenChange(KernelVersionPreferenceController.java)
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceController.java
index 0500c893..7a3bdaf 100644
--- a/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceController.java
@@ -21,6 +21,7 @@
 import com.android.settings.core.BasePreferenceController;
 import com.android.settingslib.DeviceInfoUtils;
 
+// LINT.IfChange
 public class KernelVersionPreferenceController extends BasePreferenceController {
 
     public KernelVersionPreferenceController(Context context, String preferenceKey) {
@@ -37,3 +38,4 @@
         return DeviceInfoUtils.getFormattedKernelVersion(mContext);
     }
 }
+// LINT.ThenChange(KernelVersionPreference.kt)
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceControllerTest.java
index 9ee0bb3..1459406 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceControllerTest.java
@@ -29,6 +29,7 @@
 import org.robolectric.RobolectricTestRunner;
 import org.robolectric.RuntimeEnvironment;
 
+// LINT.IfChange
 @RunWith(RobolectricTestRunner.class)
 public class KernelVersionPreferenceControllerTest {
 
@@ -49,3 +50,4 @@
                 DeviceInfoUtils.getFormattedKernelVersion(mContext));
     }
 }
+// LINT.ThenChange(KernelVersionPreferenceTest.kt)
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceTest.kt b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceTest.kt
new file mode 100644
index 0000000..162fc15
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceTest.kt
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2024 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.deviceinfo.firmwareversion
+
+import android.content.Context
+import androidx.test.core.app.ApplicationProvider
+import com.android.settingslib.DeviceInfoUtils
+import com.google.common.truth.Truth.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+
+// LINT.IfChange
+@RunWith(RobolectricTestRunner::class)
+class KernelVersionPreferenceTest {
+    private val context: Context = ApplicationProvider.getApplicationContext()
+
+    private val kernelVersionPreference = KernelVersionPreference()
+
+    @Test
+    fun getSummary() {
+        assertThat(kernelVersionPreference.getSummary(context))
+            .isEqualTo(DeviceInfoUtils.getFormattedKernelVersion(context))
+    }
+}
+// LINT.ThenChange(KernelVersionPreferenceControllerTest.java)