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
18 
19 import android.os.Build
20 import android.safetycenter.SafetyCenterStatus
21 import android.util.Log
22 import androidx.annotation.RequiresApi
23 import com.android.permissioncontroller.R
24 
25 @RequiresApi(Build.VERSION_CODES.TIRAMISU)
26 object StatusAnimationResolver {
27 
28     private val LOG_TAG = StatusAnimationResolver::class.java.simpleName
29 
30     @JvmStatic
getScanningStartAnimationnull31     fun getScanningStartAnimation(severityLevel: Int): Int {
32         return when (severityLevel) {
33             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_UNKNOWN,
34             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK -> R.drawable.status_info_to_scanning_anim
35             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_RECOMMENDATION ->
36                 R.drawable.status_recommend_to_scanning_anim
37             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_CRITICAL_WARNING ->
38                 R.drawable.status_warn_to_scanning_anim
39             else -> {
40                 Log.w(LOG_TAG, String.format("Unexpected severity level: %s", severityLevel))
41                 R.drawable.status_info_to_scanning_anim
42             }
43         }
44     }
45 
46     @JvmStatic
getScanningAnimationnull47     fun getScanningAnimation(severityLevel: Int): Int {
48         return when (severityLevel) {
49             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_UNKNOWN,
50             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK -> R.drawable.status_scanning_anim_info
51             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_RECOMMENDATION ->
52                 R.drawable.status_scanning_anim_recommend
53             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_CRITICAL_WARNING ->
54                 R.drawable.status_scanning_anim_warn
55             else -> {
56                 Log.w(LOG_TAG, String.format("Unexpected severity level: %s", severityLevel))
57                 R.drawable.status_scanning_anim_info
58             }
59         }
60     }
61 
62     @JvmStatic
getScanningEndAnimationnull63     fun getScanningEndAnimation(fromSeverityLevel: Int, toSeverityLevel: Int): Int {
64         return when (fromSeverityLevel) {
65             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_UNKNOWN,
66             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK ->
67                 getTransitionAnimationFromInfo(toSeverityLevel)
68             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_CRITICAL_WARNING ->
69                 getTransitionAnimationFromWarn(toSeverityLevel)
70             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_RECOMMENDATION ->
71                 getTransitionAnimationFromRecommend(toSeverityLevel)
72             else -> {
73                 Log.w(LOG_TAG, String.format("Unexpected severity level: %s", fromSeverityLevel))
74                 getTransitionAnimationFromInfo(toSeverityLevel)
75             }
76         }
77     }
78 
79     @JvmStatic
getTransitionAnimationFromInfonull80     private fun getTransitionAnimationFromInfo(toSeverityLevel: Int): Int {
81         return when (toSeverityLevel) {
82             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_UNKNOWN,
83             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK ->
84                 R.drawable.status_scanning_end_anim_info_to_info
85             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_CRITICAL_WARNING ->
86                 R.drawable.status_scanning_end_anim_info_to_warn
87             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_RECOMMENDATION ->
88                 R.drawable.status_scanning_end_anim_info_to_recommend
89             else -> {
90                 Log.w(LOG_TAG, String.format("Unexpected severity level: %s", toSeverityLevel))
91                 R.drawable.status_scanning_end_anim_info_to_info
92             }
93         }
94     }
95 
96     @JvmStatic
getTransitionAnimationFromRecommendnull97     private fun getTransitionAnimationFromRecommend(toSeverityLevel: Int): Int {
98         return when (toSeverityLevel) {
99             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_UNKNOWN,
100             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK ->
101                 R.drawable.status_scanning_end_anim_recommend_to_info
102             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_CRITICAL_WARNING ->
103                 R.drawable.status_scanning_end_anim_recommend_to_warn
104             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_RECOMMENDATION ->
105                 R.drawable.status_scanning_end_anim_recommend_to_recommend
106             else -> {
107                 Log.w(LOG_TAG, String.format("Unexpected severity level: %s", toSeverityLevel))
108                 R.drawable.status_scanning_end_anim_recommend_to_recommend
109             }
110         }
111     }
112 
113     @JvmStatic
getTransitionAnimationFromWarnnull114     private fun getTransitionAnimationFromWarn(toSeverityLevel: Int): Int {
115         return when (toSeverityLevel) {
116             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_UNKNOWN,
117             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK ->
118                 R.drawable.status_scanning_end_anim_warn_to_info
119             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_RECOMMENDATION ->
120                 R.drawable.status_scanning_end_anim_warn_to_recommend
121             SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_CRITICAL_WARNING ->
122                 R.drawable.status_scanning_end_anim_warn_to_warn
123             else -> {
124                 Log.w(LOG_TAG, String.format("Unexpected severity level: %s", toSeverityLevel))
125                 R.drawable.status_scanning_end_anim_warn_to_warn
126             }
127         }
128     }
129 
130     @JvmStatic
getStatusChangeAnimationnull131     fun getStatusChangeAnimation(fromSeverity: Int, toSeverity: Int): Int =
132         if (
133             fromSeverity == toSeverity &&
134                 fromSeverity != SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK
135         ) {
136             0
137         } else
138             when (fromSeverity) {
139                 SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK ->
140                     R.drawable.safety_status_info_to_info_anim
141                 SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_RECOMMENDATION ->
142                     R.drawable.safety_status_recommend_to_info_anim
143                 SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_CRITICAL_WARNING -> {
144                     if (toSeverity == SafetyCenterStatus.OVERALL_SEVERITY_LEVEL_OK) {
145                         R.drawable.safety_status_warn_to_info_anim
146                     } else {
147                         R.drawable.safety_status_warn_to_recommend_anim
148                     }
149                 }
150                 else -> 0
151             }
152 }
153