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 package com.android.permissioncontroller.safetycenter.ui 17 18 import android.safetycenter.SafetyCenterEntry 19 import android.util.Log 20 import com.android.modules.utils.build.SdkLevel 21 import com.android.permissioncontroller.R 22 import com.android.permissioncontroller.safetycenter.SafetyCenterConstants.PRIVACY_SOURCES_GROUP_ID 23 24 internal object SeverityIconPicker { 25 26 private val TAG = SeverityIconPicker::class.java.simpleName 27 28 @JvmStatic selectIconResIdOrNullnull29 fun selectIconResIdOrNull( 30 id: String, 31 severityLevel: Int, 32 severityUnspecifiedIconType: Int 33 ): Int? { 34 if (SdkLevel.isAtLeastV() && id == PRIVACY_SOURCES_GROUP_ID) { 35 return null 36 } 37 return selectIconResId(id, severityLevel, severityUnspecifiedIconType) 38 } 39 40 @JvmStatic selectIconResIdnull41 fun selectIconResId(id: String, severityLevel: Int, severityUnspecifiedIconType: Int): Int { 42 if (id == PRIVACY_SOURCES_GROUP_ID) { 43 return R.drawable.ic_privacy 44 } 45 46 when (severityLevel) { 47 SafetyCenterEntry.ENTRY_SEVERITY_LEVEL_UNKNOWN -> return R.drawable.ic_safety_null_state 48 SafetyCenterEntry.ENTRY_SEVERITY_LEVEL_UNSPECIFIED -> 49 return selectSeverityUnspecifiedIconResId(severityUnspecifiedIconType) 50 SafetyCenterEntry.ENTRY_SEVERITY_LEVEL_OK -> return R.drawable.ic_safety_info 51 SafetyCenterEntry.ENTRY_SEVERITY_LEVEL_RECOMMENDATION -> 52 return R.drawable.ic_safety_recommendation 53 SafetyCenterEntry.ENTRY_SEVERITY_LEVEL_CRITICAL_WARNING -> 54 return R.drawable.ic_safety_warn 55 } 56 Log.e( 57 TAG, 58 String.format("Unexpected SafetyCenterEntry.EntrySeverityLevel: %s", severityLevel) 59 ) 60 return R.drawable.ic_safety_null_state 61 } 62 selectSeverityUnspecifiedIconResIdnull63 private fun selectSeverityUnspecifiedIconResId(severityUnspecifiedIconType: Int): Int { 64 when (severityUnspecifiedIconType) { 65 SafetyCenterEntry.SEVERITY_UNSPECIFIED_ICON_TYPE_NO_ICON -> 66 return R.drawable.ic_safety_empty 67 SafetyCenterEntry.SEVERITY_UNSPECIFIED_ICON_TYPE_PRIVACY -> return R.drawable.ic_privacy 68 SafetyCenterEntry.SEVERITY_UNSPECIFIED_ICON_TYPE_NO_RECOMMENDATION -> 69 return R.drawable.ic_safety_null_state 70 } 71 Log.e( 72 TAG, 73 String.format( 74 "Unexpected SafetyCenterEntry.SeverityNoneIconType: %s", 75 severityUnspecifiedIconType 76 ) 77 ) 78 return R.drawable.ic_safety_null_state 79 } 80 } 81