1 /* 2 * Copyright (C) 2023 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.systemui.mediaprojection.appselector 17 18 import android.content.Context 19 import android.os.UserHandle 20 import com.android.internal.R as AndroidR 21 import com.android.internal.app.AbstractMultiProfilePagerAdapter.EmptyState 22 import com.android.internal.app.AbstractMultiProfilePagerAdapter.EmptyStateProvider 23 import com.android.internal.app.ResolverListAdapter 24 import com.android.systemui.res.R 25 import com.android.systemui.mediaprojection.devicepolicy.PersonalProfile 26 import com.android.systemui.mediaprojection.devicepolicy.ScreenCaptureDevicePolicyResolver 27 import javax.inject.Inject 28 29 @MediaProjectionAppSelectorScope 30 class MediaProjectionBlockerEmptyStateProvider 31 @Inject 32 constructor( 33 @HostUserHandle private val hostAppHandle: UserHandle, 34 @PersonalProfile private val personalProfileHandle: UserHandle, 35 private val policyResolver: ScreenCaptureDevicePolicyResolver, 36 private val context: Context 37 ) : EmptyStateProvider { 38 getEmptyStatenull39 override fun getEmptyState(resolverListAdapter: ResolverListAdapter): EmptyState? { 40 val screenCaptureAllowed = 41 policyResolver.isScreenCaptureAllowed( 42 targetAppUserHandle = resolverListAdapter.userHandle, 43 hostAppUserHandle = hostAppHandle 44 ) 45 46 val isHostAppInPersonalProfile = hostAppHandle == personalProfileHandle 47 48 val subtitle = 49 if (isHostAppInPersonalProfile) { 50 AndroidR.string.resolver_cant_share_with_personal_apps_explanation 51 } else { 52 AndroidR.string.resolver_cant_share_with_work_apps_explanation 53 } 54 55 if (!screenCaptureAllowed) { 56 return object : EmptyState { 57 override fun getSubtitle(): String = context.resources.getString(subtitle) 58 override fun getTitle(): String = 59 context.resources.getString( 60 R.string.screen_capturing_disabled_by_policy_dialog_title 61 ) 62 override fun onEmptyStateShown() { 63 // TODO(b/237397740) report analytics 64 } 65 override fun shouldSkipDataRebuild(): Boolean = true 66 } 67 } 68 return null 69 } 70 } 71