• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.systemui.screenshot
17 
18 import android.content.Intent
19 import android.os.IBinder
20 import android.util.Log
21 import androidx.lifecycle.LifecycleService
22 import androidx.lifecycle.lifecycleScope
23 import com.android.systemui.dagger.qualifiers.Main
24 import com.android.systemui.shade.ShadeExpansionStateManager
25 import com.android.systemui.statusbar.phone.CentralSurfaces
26 import kotlinx.coroutines.CoroutineDispatcher
27 import kotlinx.coroutines.launch
28 import kotlinx.coroutines.withContext
29 import java.util.Optional
30 import javax.inject.Inject
31 
32 /**
33  * Provides state from the main SystemUI process on behalf of the Screenshot process.
34  */
35 internal class ScreenshotProxyService @Inject constructor(
36     private val mExpansionMgr: ShadeExpansionStateManager,
37     private val mCentralSurfacesOptional: Optional<CentralSurfaces>,
38     @Main private val mMainDispatcher: CoroutineDispatcher,
39 ) : LifecycleService() {
40 
41     private val mBinder: IBinder = object : IScreenshotProxy.Stub() {
42         /**
43          * @return true when the notification shade is partially or fully expanded.
44          */
isNotificationShadeExpandednull45         override fun isNotificationShadeExpanded(): Boolean {
46             val expanded = !mExpansionMgr.isClosed()
47             Log.d(TAG, "isNotificationShadeExpanded(): $expanded")
48             return expanded
49         }
50 
dismissKeyguardnull51         override fun dismissKeyguard(callback: IOnDoneCallback) {
52             lifecycleScope.launch {
53                 executeAfterDismissing(callback)
54             }
55         }
56     }
57 
executeAfterDismissingnull58     private suspend fun executeAfterDismissing(callback: IOnDoneCallback) =
59         withContext(mMainDispatcher) {
60             mCentralSurfacesOptional.ifPresentOrElse(
61                     {
62                         it.executeRunnableDismissingKeyguard(
63                                 Runnable {
64                                     callback.onDone(true)
65                                 }, null,
66                                 true /* dismissShade */, true /* afterKeyguardGone */,
67                                 true /* deferred */
68                         )
69                     },
70                     { callback.onDone(false) }
71             )
72         }
73 
onBindnull74     override fun onBind(intent: Intent): IBinder? {
75         Log.d(TAG, "onBind: $intent")
76         return mBinder
77     }
78 
79     companion object {
80         const val TAG = "ScreenshotProxyService"
81     }
82 }
83