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 import com.android.systemui.R
24 
25 class CameraIntents {
26     companion object {
27         val DEFAULT_SECURE_CAMERA_INTENT_ACTION = MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE
28         val DEFAULT_INSECURE_CAMERA_INTENT_ACTION = MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA
29         private val VIDEO_CAMERA_INTENT_ACTION = MediaStore.INTENT_ACTION_VIDEO_CAMERA
30         const val EXTRA_LAUNCH_SOURCE = "com.android.systemui.camera_launch_source"
31 
32         @JvmStatic
33         fun getOverrideCameraPackage(context: Context): String? {
34             context.resources.getString(R.string.config_cameraGesturePackage)?.let {
35                 if (!TextUtils.isEmpty(it)) {
36                     return it
37                 }
38             }
39             return null
40         }
41 
42         @JvmStatic
43         fun getInsecureCameraIntent(context: Context): Intent {
44             val intent = Intent(DEFAULT_INSECURE_CAMERA_INTENT_ACTION)
45             getOverrideCameraPackage(context)?.let { intent.setPackage(it) }
46             return intent
47         }
48 
49         @JvmStatic
50         fun getSecureCameraIntent(context: Context): Intent {
51             val intent = Intent(DEFAULT_SECURE_CAMERA_INTENT_ACTION)
52             getOverrideCameraPackage(context)?.let { intent.setPackage(it) }
53             return intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
54         }
55 
56         @JvmStatic
57         fun isSecureCameraIntent(intent: Intent?): Boolean {
58             return intent?.getAction()?.equals(DEFAULT_SECURE_CAMERA_INTENT_ACTION) ?: false
59         }
60 
61         @JvmStatic
62         fun isInsecureCameraIntent(intent: Intent?): Boolean {
63             return intent?.getAction()?.equals(DEFAULT_INSECURE_CAMERA_INTENT_ACTION) ?: false
64         }
65 
66         /** Returns an [Intent] that can be used to start the camera in video mode. */
67         @JvmStatic
68         fun getVideoCameraIntent(): Intent {
69             return Intent(VIDEO_CAMERA_INTENT_ACTION)
70         }
71     }
72 }
73