1 /*
2 * Copyright (C) 2022 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.statusbar.pipeline.shared.data.model
18
19 import android.net.wifi.WifiManager
20 import android.telephony.Annotation
21 import android.telephony.TelephonyManager
22 import com.android.systemui.log.table.Diffable
23 import com.android.systemui.log.table.TableRowLogger
24
25 /** Provides information about the current data activity direction */
26 data class DataActivityModel(
27 /** True if the connection has activity in (download). */
28 val hasActivityIn: Boolean,
29 /** True if the connection has activity out (upload). */
30 val hasActivityOut: Boolean,
31 ) : Diffable<DataActivityModel> {
logDiffsnull32 override fun logDiffs(prevVal: DataActivityModel, row: TableRowLogger) {
33 if (prevVal.hasActivityIn != hasActivityIn) {
34 row.logChange(COL_ACTIVITY_IN, hasActivityIn)
35 }
36 if (prevVal.hasActivityOut != hasActivityOut) {
37 row.logChange(COL_ACTIVITY_OUT, hasActivityOut)
38 }
39 }
40
logFullnull41 override fun logFull(row: TableRowLogger) {
42 row.logChange(COL_ACTIVITY_IN, hasActivityIn)
43 row.logChange(COL_ACTIVITY_OUT, hasActivityOut)
44 }
45 }
46
47 const val ACTIVITY_PREFIX = "dataActivity"
48 private const val COL_ACTIVITY_IN = "in"
49 private const val COL_ACTIVITY_OUT = "out"
50
toMobileDataActivityModelnull51 fun @receiver:Annotation.DataActivityType Int.toMobileDataActivityModel(): DataActivityModel =
52 when (this) {
53 TelephonyManager.DATA_ACTIVITY_IN ->
54 DataActivityModel(hasActivityIn = true, hasActivityOut = false)
55 TelephonyManager.DATA_ACTIVITY_OUT ->
56 DataActivityModel(hasActivityIn = false, hasActivityOut = true)
57 TelephonyManager.DATA_ACTIVITY_INOUT ->
58 DataActivityModel(hasActivityIn = true, hasActivityOut = true)
59 else -> DataActivityModel(hasActivityIn = false, hasActivityOut = false)
60 }
61
toWifiDataActivityModelnull62 fun Int.toWifiDataActivityModel(): DataActivityModel =
63 when (this) {
64 WifiManager.TrafficStateCallback.DATA_ACTIVITY_IN ->
65 DataActivityModel(hasActivityIn = true, hasActivityOut = false)
66 WifiManager.TrafficStateCallback.DATA_ACTIVITY_OUT ->
67 DataActivityModel(hasActivityIn = false, hasActivityOut = true)
68 WifiManager.TrafficStateCallback.DATA_ACTIVITY_INOUT ->
69 DataActivityModel(hasActivityIn = true, hasActivityOut = true)
70 else -> DataActivityModel(hasActivityIn = false, hasActivityOut = false)
71 }
72