1 /*
2  * Copyright (C) 2020 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.systemui.controls.controller
18 
19 import android.service.controls.Control
20 import android.service.controls.DeviceTypes
21 
22 /**
23  * Stores basic information about a [Control] to persist and keep track of favorites.
24  *
25  * The identifier of this [Control] is the [controlId], and is only unique per app. The other
26  * fields are there for persistence. In this way, basic information can be shown to the user
27  * before the service has to report on the status.
28  *
29  * @property controlId unique identifier for this [Control].
30  * @property controlTitle last title reported for this [Control].
31  * @property controlSubtitle last subtitle reported for this [Control].
32  * @property deviceType last reported type for this [Control].
33  */
34 data class ControlInfo(
35     val controlId: String,
36     val controlTitle: CharSequence,
37     val controlSubtitle: CharSequence,
38     @DeviceTypes.DeviceType val deviceType: Int
39 ) {
40 
41     companion object {
42         private const val SEPARATOR = ":"
fromControlnull43         fun fromControl(control: Control): ControlInfo {
44             return ControlInfo(
45                     control.controlId,
46                     control.title,
47                     control.subtitle,
48                     control.deviceType
49             )
50         }
51     }
52 
53     /**
54      * Returns a [String] representation of the fields separated using [SEPARATOR].
55      *
56      * @return a [String] representation of `this`
57      */
toStringnull58     override fun toString(): String {
59         return "$SEPARATOR$controlId$SEPARATOR$controlTitle$SEPARATOR$deviceType"
60     }
61 }
62