1 /*
2  * Copyright (C) 2021 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.camera
18 
19 import android.content.Context
20 import android.content.Intent
21 import android.provider.MediaStore
22 import android.text.TextUtils
23 
24 import com.android.systemui.R
25 
26 class CameraIntents {
27     companion object {
28         val DEFAULT_SECURE_CAMERA_INTENT_ACTION =
29                 MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE
30         val DEFAULT_INSECURE_CAMERA_INTENT_ACTION =
31                 MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA
32 
33         @JvmStatic
34         fun getOverrideCameraPackage(context: Context): String? {
35             context.resources.getString(R.string.config_cameraGesturePackage)?.let {
36                 if (!TextUtils.isEmpty(it)) {
37                     return it
38                 }
39             }
40             return null
41         }
42 
43         @JvmStatic
44         fun getInsecureCameraIntent(context: Context): Intent {
45             val intent = Intent(DEFAULT_INSECURE_CAMERA_INTENT_ACTION)
46             getOverrideCameraPackage(context)?.let {
47                 intent.setPackage(it)
48             }
49             return intent
50         }
51 
52         @JvmStatic
53         fun getSecureCameraIntent(context: Context): Intent {
54             val intent = Intent(DEFAULT_SECURE_CAMERA_INTENT_ACTION)
55             getOverrideCameraPackage(context)?.let {
56                 intent.setPackage(it)
57             }
58             return intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
59         }
60 
61         @JvmStatic
62         fun isSecureCameraIntent(intent: Intent?): Boolean {
63             return intent?.getAction()?.equals(DEFAULT_SECURE_CAMERA_INTENT_ACTION) ?: false
64         }
65 
66         @JvmStatic
67         fun isInsecureCameraIntent(intent: Intent?): Boolean {
68             return intent?.getAction()?.equals(DEFAULT_INSECURE_CAMERA_INTENT_ACTION) ?: false
69         }
70     }
71 }
72