Convert wallpaper preference to Kotlin (2/3)

Test: Build success
Bug: 307819582
Flag: NONE
Change-Id: Id26e88873e80732e522b01ffa148dd4c3d367216
diff --git a/src/com/android/customization/module/CustomizationPreferences.java b/src/com/android/customization/module/CustomizationPreferences.java
deleted file mode 100644
index 0df3ff9..0000000
--- a/src/com/android/customization/module/CustomizationPreferences.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.module;
-
-import com.android.wallpaper.module.WallpaperPreferences;
-
-public interface CustomizationPreferences extends WallpaperPreferences {
-
-    String KEY_CUSTOM_THEME= "themepicker_custom_theme";
-    String KEY_VISITED_PREFIX = "themepicker_visited_";
-    String KEY_THEMED_ICON_ENABLED = "themepicker_themed_icon_enabled";
-
-    String getSerializedCustomThemes();
-
-    void storeCustomThemes(String serializedCustomThemes);
-
-    boolean getTabVisited(String id);
-
-    void setTabVisited(String id);
-
-    boolean getThemedIconEnabled();
-
-    void setThemedIconEnabled(boolean enabled);
-}
diff --git a/src/com/android/customization/module/CustomizationPreferences.kt b/src/com/android/customization/module/CustomizationPreferences.kt
new file mode 100644
index 0000000..4148c3b
--- /dev/null
+++ b/src/com/android/customization/module/CustomizationPreferences.kt
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2019 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.customization.module
+
+import com.android.wallpaper.module.WallpaperPreferences
+
+interface CustomizationPreferences : WallpaperPreferences {
+    fun getSerializedCustomThemes(): String?
+
+    fun storeCustomThemes(serializedCustomThemes: String)
+
+    fun getTabVisited(id: String): Boolean
+
+    fun setTabVisited(id: String)
+
+    fun getThemedIconEnabled(): Boolean
+
+    fun setThemedIconEnabled(enabled: Boolean)
+
+    companion object {
+        const val KEY_CUSTOM_THEME = "themepicker_custom_theme"
+        const val KEY_VISITED_PREFIX = "themepicker_visited_"
+        const val KEY_THEMED_ICON_ENABLED = "themepicker_themed_icon_enabled"
+    }
+}
diff --git a/src/com/android/customization/module/DefaultCustomizationPreferences.java b/src/com/android/customization/module/DefaultCustomizationPreferences.java
deleted file mode 100644
index 4af402f..0000000
--- a/src/com/android/customization/module/DefaultCustomizationPreferences.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.module;
-
-import android.content.Context;
-
-import com.android.wallpaper.module.DefaultWallpaperPreferences;
-
-public class DefaultCustomizationPreferences extends DefaultWallpaperPreferences
-        implements CustomizationPreferences {
-
-    public DefaultCustomizationPreferences(Context context) {
-        super(context);
-    }
-
-
-    @Override
-    public String getSerializedCustomThemes() {
-        return mSharedPrefs.getString(KEY_CUSTOM_THEME, null);
-    }
-
-    @Override
-    public void storeCustomThemes(String serializedCustomThemes) {
-        mSharedPrefs.edit().putString(KEY_CUSTOM_THEME, serializedCustomThemes).apply();
-    }
-
-    @Override
-    public boolean getTabVisited(String id) {
-        return mSharedPrefs.getBoolean(KEY_VISITED_PREFIX + id, false);
-    }
-
-    @Override
-    public void setTabVisited(String id) {
-        mSharedPrefs.edit().putBoolean(KEY_VISITED_PREFIX + id, true).apply();
-    }
-
-    @Override
-    public boolean getThemedIconEnabled() {
-        return mSharedPrefs.getBoolean(KEY_THEMED_ICON_ENABLED, false);
-    }
-
-    @Override
-    public void setThemedIconEnabled(boolean enabled) {
-        mSharedPrefs.edit().putBoolean(KEY_THEMED_ICON_ENABLED, enabled).apply();
-    }
-}
diff --git a/src/com/android/customization/module/DefaultCustomizationPreferences.kt b/src/com/android/customization/module/DefaultCustomizationPreferences.kt
new file mode 100644
index 0000000..49fd1a9
--- /dev/null
+++ b/src/com/android/customization/module/DefaultCustomizationPreferences.kt
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2019 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.customization.module
+
+import android.content.Context
+import com.android.wallpaper.module.DefaultWallpaperPreferences
+
+open class DefaultCustomizationPreferences(context: Context) :
+    DefaultWallpaperPreferences(context), CustomizationPreferences {
+
+    override fun getSerializedCustomThemes(): String? {
+        return sharedPrefs.getString(CustomizationPreferences.KEY_CUSTOM_THEME, null)
+    }
+
+    override fun storeCustomThemes(serializedCustomThemes: String) {
+        sharedPrefs
+            .edit()
+            .putString(CustomizationPreferences.KEY_CUSTOM_THEME, serializedCustomThemes)
+            .apply()
+    }
+
+    override fun getTabVisited(id: String): Boolean {
+        return sharedPrefs.getBoolean(CustomizationPreferences.KEY_VISITED_PREFIX + id, false)
+    }
+
+    override fun setTabVisited(id: String) {
+        sharedPrefs
+            .edit()
+            .putBoolean(CustomizationPreferences.KEY_VISITED_PREFIX + id, true)
+            .apply()
+    }
+
+    override fun getThemedIconEnabled(): Boolean {
+        return sharedPrefs.getBoolean(CustomizationPreferences.KEY_THEMED_ICON_ENABLED, false)
+    }
+
+    override fun setThemedIconEnabled(enabled: Boolean) {
+        sharedPrefs
+            .edit()
+            .putBoolean(CustomizationPreferences.KEY_THEMED_ICON_ENABLED, enabled)
+            .apply()
+    }
+}
diff --git a/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt b/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt
index e4b8c8b..dd88802 100644
--- a/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt
+++ b/src/com/android/customization/module/logging/ThemesUserEventLoggerImpl.kt
@@ -49,7 +49,7 @@
             .setWallpaperIdHash(preferences.getHomeWallpaperIdHash())
             .setLockWallpaperCategoryHash(preferences.getLockCategoryHash())
             .setLockWallpaperIdHash(preferences.getLockWallpaperIdHash())
-            .setEffectIdHash(getIdHashCode(preferences.homeWallpaperEffects))
+            .setEffectIdHash(preferences.getHomeWallpaperEffectsIdHash())
             .log()
     }
 
@@ -235,28 +235,35 @@
 
     /** If not set, the output hash is 0. */
     private fun WallpaperPreferences.getHomeCategoryHash(): Int {
-        return getIdHashCode(homeWallpaperCollectionId)
+        return getIdHashCode(getHomeWallpaperCollectionId())
     }
 
     /** If not set, the output hash is 0. */
     private fun WallpaperPreferences.getHomeWallpaperIdHash(): Int {
-        val remoteId = homeWallpaperRemoteId
-        val wallpaperId = if (!TextUtils.isEmpty(remoteId)) remoteId else homeWallpaperServiceName
+        val remoteId = getHomeWallpaperRemoteId()
+        val wallpaperId =
+            if (!TextUtils.isEmpty(remoteId)) remoteId else getHomeWallpaperServiceName()
         return getIdHashCode(wallpaperId)
     }
 
     /** If not set, the output hash is 0. */
     private fun WallpaperPreferences.getLockCategoryHash(): Int {
-        return getIdHashCode(lockWallpaperCollectionId)
+        return getIdHashCode(getLockWallpaperCollectionId())
     }
 
     /** If not set, the output hash is 0. */
     private fun WallpaperPreferences.getLockWallpaperIdHash(): Int {
-        val remoteId = lockWallpaperRemoteId
-        val wallpaperId = if (!TextUtils.isEmpty(remoteId)) remoteId else lockWallpaperServiceName
+        val remoteId = getLockWallpaperRemoteId()
+        val wallpaperId =
+            if (!TextUtils.isEmpty(remoteId)) remoteId else getLockWallpaperServiceName()
         return getIdHashCode(wallpaperId)
     }
 
+    /** If not set, the output hash is 0. */
+    private fun WallpaperPreferences.getHomeWallpaperEffectsIdHash(): Int {
+        return getIdHashCode(getHomeWallpaperEffects())
+    }
+
     private fun getIdHashCode(id: String?): Int {
         return id?.hashCode() ?: 0
     }
diff --git a/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java b/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java
deleted file mode 100644
index c8e31a3..0000000
--- a/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2019 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.customization.testing;
-
-import android.content.Context;
-
-import com.android.customization.module.CustomizationPreferences;
-import com.android.customization.module.DefaultCustomizationPreferences;
-import com.android.wallpaper.testing.TestWallpaperPreferences;
-
-import dagger.hilt.android.qualifiers.ApplicationContext;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-/**
- * Test implementation of {@link DefaultCustomizationPreferences}.
- */
-@Singleton
-public class TestDefaultCustomizationPreferences extends TestWallpaperPreferences implements
-        CustomizationPreferences {
-
-    private String mCustomThemes;
-    private final Set<String> mTabVisited = new HashSet<>();
-    private boolean mThemedIconEnabled = false;
-
-    @Inject
-    public TestDefaultCustomizationPreferences(@ApplicationContext Context context) {
-        super();
-    }
-
-    @Override
-    public String getSerializedCustomThemes() {
-        return mCustomThemes;
-    }
-
-    @Override
-    public void storeCustomThemes(String serializedCustomThemes) {
-        mCustomThemes = serializedCustomThemes;
-    }
-
-    @Override
-    public boolean getTabVisited(String id) {
-        return mTabVisited.contains(id);
-    }
-
-    @Override
-    public void setTabVisited(String id) {
-        mTabVisited.add(id);
-    }
-
-    @Override
-    public boolean getThemedIconEnabled() {
-        return mThemedIconEnabled;
-    }
-
-    @Override
-    public void setThemedIconEnabled(boolean enabled) {
-        mThemedIconEnabled = enabled;
-    }
-}
diff --git a/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.kt b/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.kt
new file mode 100644
index 0000000..10fe5ac
--- /dev/null
+++ b/tests/common/src/com/android/customization/testing/TestDefaultCustomizationPreferences.kt
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2019 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.customization.testing
+
+import com.android.customization.module.CustomizationPreferences
+import com.android.wallpaper.testing.TestWallpaperPreferences
+import javax.inject.Inject
+import javax.inject.Singleton
+
+/** Test implementation of [CustomizationPreferences]. */
+@Singleton
+open class TestDefaultCustomizationPreferences @Inject constructor() :
+    TestWallpaperPreferences(), CustomizationPreferences {
+
+    private var customThemes: String? = null
+    private val tabVisited: MutableSet<String> = HashSet()
+    private var themedIconEnabled = false
+
+    override fun getSerializedCustomThemes(): String? {
+        return customThemes
+    }
+
+    override fun storeCustomThemes(serializedCustomThemes: String) {
+        customThemes = serializedCustomThemes
+    }
+
+    override fun getTabVisited(id: String): Boolean {
+        return tabVisited.contains(id)
+    }
+
+    override fun setTabVisited(id: String) {
+        tabVisited.add(id)
+    }
+
+    override fun getThemedIconEnabled(): Boolean {
+        return themedIconEnabled
+    }
+
+    override fun setThemedIconEnabled(enabled: Boolean) {
+        themedIconEnabled = enabled
+    }
+}