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.systemui 18 19 import android.graphics.Rect 20 import com.android.systemui.res.R 21 22 class FakeCameraProtectionLoader(private val context: SysuiTestableContext) : 23 CameraProtectionLoader { 24 25 private val realLoader = CameraProtectionLoaderImpl(context) 26 loadCameraProtectionInfoListnull27 override fun loadCameraProtectionInfoList(): List<CameraProtectionInfo> = 28 realLoader.loadCameraProtectionInfoList() 29 30 fun clearProtectionInfoList() { 31 context.orCreateTestableResources.addOverride(R.string.config_protectedCameraId, "") 32 context.orCreateTestableResources.addOverride(R.string.config_protectedInnerCameraId, "") 33 } 34 addAllProtectionsnull35 fun addAllProtections() { 36 addOuterCameraProtection() 37 addInnerCameraProtection() 38 } 39 addOuterCameraProtectionnull40 fun addOuterCameraProtection( 41 displayUniqueId: String = "111", 42 bounds: Rect = Rect(/* left = */ 0, /* top = */ 0, /* right = */ 10, /* bottom = */ 10) 43 ) { 44 context.orCreateTestableResources.addOverride(R.string.config_protectedCameraId, "1") 45 context.orCreateTestableResources.addOverride( 46 R.string.config_protectedPhysicalCameraId, 47 "11" 48 ) 49 context.orCreateTestableResources.addOverride( 50 R.string.config_frontBuiltInDisplayCutoutProtection, 51 bounds.asPath(), 52 ) 53 context.orCreateTestableResources.addOverride( 54 R.string.config_protectedScreenUniqueId, 55 displayUniqueId 56 ) 57 } 58 addInnerCameraProtectionnull59 fun addInnerCameraProtection( 60 displayUniqueId: String = "222", 61 bounds: Rect = Rect(/* left = */ 0, /* top = */ 0, /* right = */ 20, /* bottom = */ 20) 62 ) { 63 context.orCreateTestableResources.addOverride(R.string.config_protectedInnerCameraId, "2") 64 context.orCreateTestableResources.addOverride( 65 R.string.config_protectedInnerPhysicalCameraId, 66 "22" 67 ) 68 context.orCreateTestableResources.addOverride( 69 R.string.config_innerBuiltInDisplayCutoutProtection, 70 bounds.asPath(), 71 ) 72 context.orCreateTestableResources.addOverride( 73 R.string.config_protectedInnerScreenUniqueId, 74 displayUniqueId 75 ) 76 } 77 Rectnull78 private fun Rect.asPath() = "M $left, $top H $right V $bottom H $left Z" 79 } 80