1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settingslib.bluetooth.devicesettings
18 
19 import android.os.Bundle
20 import android.os.Parcel
21 import android.os.Parcelable
22 
23 /**
24  * A data class representing a device settings item in bluetooth device details config.
25  *
26  * @property settingId The setting ID of the item, as defined by IntDef [DeviceSettingId].
27  * @property packageName The package name for service binding.
28  * @property className The class name for service binding.
29  * @property intentAction The intent action for service binding.
30  * @property preferenceKey The preference key if it's a built-in preference.
31  * @property extras Extra bundle
32  */
33 data class DeviceSettingItem(
34     @DeviceSettingId val settingId: Int,
35     val packageName: String? = null,
36     val className: String? = null,
37     val intentAction: String? = null,
38     val preferenceKey: String? = null,
39     val highlighted: Boolean = false,
40     val extras: Bundle = Bundle.EMPTY,
41 ) : Parcelable {
42 
describeContentsnull43     override fun describeContents(): Int = 0
44 
45     override fun writeToParcel(parcel: Parcel, flags: Int) {
46         parcel.run {
47             writeInt(settingId)
48             writeString(packageName)
49             writeString(className)
50             writeString(intentAction)
51             writeBoolean(highlighted)
52             writeString(preferenceKey)
53             writeBundle(extras)
54         }
55     }
56 
57     companion object {
58         @JvmField
59         val CREATOR: Parcelable.Creator<DeviceSettingItem> =
60             object : Parcelable.Creator<DeviceSettingItem> {
createFromParcelnull61                 override fun createFromParcel(parcel: Parcel) =
62                     parcel.run {
63                         DeviceSettingItem(
64                             settingId = readInt(),
65                             packageName = readString(),
66                             className = readString(),
67                             intentAction = readString(),
68                             highlighted = readBoolean(),
69                             preferenceKey = readString(),
70                             extras = readBundle((Bundle::class.java.classLoader)) ?: Bundle.EMPTY,
71                         )
72                     }
73 
newArraynull74                 override fun newArray(size: Int): Array<DeviceSettingItem?> {
75                     return arrayOfNulls(size)
76                 }
77             }
78     }
79 }
80