1 /*
2  * Copyright (C) 2020 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.settings.users;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.pm.PackageManager;
22 import android.provider.MediaStore;
23 
24 class PhotoCapabilityUtils {
25 
26     /**
27      * Check if the current user can perform any activity for
28      * android.media.action.IMAGE_CAPTURE action.
29      */
canTakePhoto(Context context)30     static boolean canTakePhoto(Context context) {
31         return context.getPackageManager().queryIntentActivities(
32                 new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
33                 PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
34     }
35 
36     /**
37      * Check if the current user can perform any activity for
38      * android.intent.action.GET_CONTENT action for images.
39      */
canChoosePhoto(Context context)40     static boolean canChoosePhoto(Context context) {
41         Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
42         intent.setType("image/*");
43         return context.getPackageManager().queryIntentActivities(intent, 0).size() > 0;
44     }
45 
46     /**
47      * Check if the current user can perform any activity for
48      * com.android.camera.action.CROP action for images.
49      */
canCropPhoto(Context context)50     static boolean canCropPhoto(Context context) {
51         Intent intent = new Intent("com.android.camera.action.CROP");
52         intent.setType("image/*");
53         return context.getPackageManager().queryIntentActivities(intent, 0).size() > 0;
54     }
55 
56 }
57