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.permissioncontroller.safetycenter.ui.model
18 
19 import android.app.Application
20 import android.content.Context
21 import android.os.Build
22 import android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE
23 import android.safetycenter.SafetyCenterErrorDetails
24 import android.safetycenter.SafetyCenterIssue
25 import androidx.annotation.RequiresApi
26 import androidx.lifecycle.AndroidViewModel
27 import androidx.lifecycle.LiveData
28 import com.android.permissioncontroller.safetycenter.ui.InteractionLogger
29 import com.android.permissioncontroller.safetycenter.ui.NavigationSource
30 
31 @RequiresApi(Build.VERSION_CODES.TIRAMISU)
32 abstract class SafetyCenterViewModel(protected val app: Application) : AndroidViewModel(app) {
33 
34     abstract val statusUiLiveData: LiveData<StatusUiData>
35     abstract val safetyCenterUiLiveData: LiveData<SafetyCenterUiData>
36     abstract val errorLiveData: LiveData<SafetyCenterErrorDetails>
37     abstract val interactionLogger: InteractionLogger
38 
dismissIssuenull39     abstract fun dismissIssue(issue: SafetyCenterIssue)
40 
41     /**
42      * Execute the [action] to act on the given [issue]
43      *
44      * If [launchTaskId] is provided, this should be used to force the action to be associated with
45      * a particular taskId (if applicable).
46      */
47     abstract fun executeIssueAction(
48         issue: SafetyCenterIssue,
49         action: SafetyCenterIssue.Action,
50         launchTaskId: Int?
51     )
52 
53     /**
54      * Marks a resolved [SafetyCenterIssue] as fully complete, meaning the resolution success
55      * message has been shown
56      *
57      * @param issueId Resolved issue that has completed its UI update and view can be removed
58      */
59     abstract fun markIssueResolvedUiCompleted(issueId: IssueId)
60 
61     abstract fun rescan()
62 
63     abstract fun clearError()
64 
65     abstract fun navigateToSafetyCenter(
66         context: Context,
67         navigationSource: NavigationSource? = null
68     )
69 
70     abstract fun pageOpen()
71 
72     /**
73      * Refreshes a specific subset of safety sources on page-open.
74      *
75      * This is an overload of the [pageOpen] method and is used to request data from safety sources
76      * that are part of a subpage in the Safety Center UI.
77      *
78      * @param sourceGroupId represents ID of the corresponding safety sources group
79      */
80     @RequiresApi(UPSIDE_DOWN_CAKE) abstract fun pageOpen(sourceGroupId: String)
81 
82     abstract fun changingConfigurations()
83 
84     /**
85      * Returns the [SafetyCenterData] currently stored by the Safety Center service.
86      *
87      * Note about current impl: This is drawn directly from SafetyCenterManager and will not contain
88      * any data about currently in-flight issues.
89      */
90     abstract fun getCurrentSafetyCenterDataAsUiData(): SafetyCenterUiData
91 }
92 
93 typealias IssueId = String
94 
95 typealias ActionId = String
96