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.permissioncontroller.permission.ui.wear.model
18 
19 import androidx.lifecycle.MutableLiveData
20 import androidx.lifecycle.ViewModel
21 import androidx.lifecycle.ViewModelProvider
22 import com.android.permissioncontroller.permission.ui.viewmodel.v31.PermissionUsageViewModel
23 import com.android.permissioncontroller.permission.ui.viewmodel.v31.PermissionUsagesUiState
24 
25 class WearPermissionUsageViewModel(
26     permissionUsagesUiState: PermissionUsagesUiState?,
27     showSystemApps: Boolean,
28     show7DaysData: Boolean
29 ) : ViewModel() {
30     val permissionUsagesUiStateLiveData = MutableLiveData(permissionUsagesUiState)
31     /** A livedata which stores [BasePermissionUsageViewModel.getShowSystemApps()]. */
32     val showSystemAppsLiveData = MutableLiveData(showSystemApps)
33 
34     /** A livedata which stores [BasePermissionUsageViewModel.getShow7DaysData()]. */
35     val show7DaysLiveData = MutableLiveData(show7DaysData)
36 
updatePermissionUsagesUiStateLiveDatanull37     fun updatePermissionUsagesUiStateLiveData(newUiData: PermissionUsagesUiState?) {
38         permissionUsagesUiStateLiveData.value = newUiData
39     }
40 }
41 
42 /** Factory for a WearPermissionsUsageViewModel */
43 class WearPermissionUsageViewModelFactory(val viewModel: PermissionUsageViewModel) :
44     ViewModelProvider.Factory {
createnull45     override fun <T : ViewModel> create(modelClass: Class<T>): T {
46         @Suppress("UNCHECKED_CAST")
47         return WearPermissionUsageViewModel(
48             viewModel.permissionUsagesUiLiveData.value,
49             viewModel.getShowSystemApps(),
50             viewModel.getShow7DaysData()
51         )
52             as T
53     }
54 }
55