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.content.pm.PackageManager 22 import android.provider.MediaStore 23 import android.text.TextUtils 24 import com.android.systemui.res.R 25 import android.util.Log 26 27 class CameraIntents { 28 companion object { 29 val DEFAULT_SECURE_CAMERA_INTENT_ACTION = MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE 30 val DEFAULT_INSECURE_CAMERA_INTENT_ACTION = MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA 31 private val VIDEO_CAMERA_INTENT_ACTION = MediaStore.INTENT_ACTION_VIDEO_CAMERA 32 const val EXTRA_LAUNCH_SOURCE = "com.android.systemui.camera_launch_source" 33 const val TAG = "CameraIntents" 34 35 @JvmStatic getOverrideCameraPackagenull36 fun getOverrideCameraPackage(context: Context, userId: Int): String? { 37 val packageName = context.resources.getString(R.string.config_cameraGesturePackage)!! 38 try { 39 if (!TextUtils.isEmpty(packageName) 40 && context.packageManager.getApplicationInfoAsUser(packageName, 0, userId).enabled ?: false) { 41 return packageName 42 } 43 } catch (e: PackageManager.NameNotFoundException) { 44 Log.w(TAG, "Missing cameraGesturePackage $packageName", e) 45 } 46 return null 47 } 48 49 @JvmStatic getInsecureCameraIntentnull50 fun getInsecureCameraIntent(context: Context, userId: Int): Intent { 51 val intent = Intent(DEFAULT_INSECURE_CAMERA_INTENT_ACTION) 52 getOverrideCameraPackage(context, userId)?.let { intent.setPackage(it) } 53 return intent 54 } 55 56 @JvmStatic getSecureCameraIntentnull57 fun getSecureCameraIntent(context: Context, userId: Int): Intent { 58 val intent = Intent(DEFAULT_SECURE_CAMERA_INTENT_ACTION) 59 getOverrideCameraPackage(context, userId)?.let { intent.setPackage(it) } 60 return intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) 61 } 62 63 @JvmStatic isSecureCameraIntentnull64 fun isSecureCameraIntent(intent: Intent?): Boolean { 65 return intent?.getAction()?.equals(DEFAULT_SECURE_CAMERA_INTENT_ACTION) ?: false 66 } 67 68 @JvmStatic isInsecureCameraIntentnull69 fun isInsecureCameraIntent(intent: Intent?): Boolean { 70 return intent?.getAction()?.equals(DEFAULT_INSECURE_CAMERA_INTENT_ACTION) ?: false 71 } 72 73 /** Returns an [Intent] that can be used to start the camera in video mode. */ 74 @JvmStatic getVideoCameraIntentnull75 fun getVideoCameraIntent(userId: Int): Intent { 76 return Intent(VIDEO_CAMERA_INTENT_ACTION) 77 } 78 } 79 } 80