Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b6892ab9 authored by Mangesh Ghiware's avatar Mangesh Ghiware
Browse files

Consider camera available only if intent resolves to an activity.

Fixes crash for restricted profiles without a camera.

Bug: 11289596
Change-Id: I3545dbeae2e4c9094746b51b770daa93e3896bb6
parent 85f460b8
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.gallery3d.common.ApiHelper;
import com.android.gallery3d.data.DataManager;
import com.android.gallery3d.data.MediaItem;
import com.android.gallery3d.ui.TiledScreenNail;
import com.android.gallery3d.util.IntentHelper;
import com.android.gallery3d.util.ThreadPool.CancelListener;
import com.android.gallery3d.util.ThreadPool.JobContext;

@@ -235,12 +236,10 @@ public class GalleryUtils {
    public static boolean isCameraAvailable(Context context) {
        if (sCameraAvailableInitialized) return sCameraAvailable;
        PackageManager pm = context.getPackageManager();
        ComponentName name = new ComponentName(context, CAMERA_LAUNCHER_NAME);
        int state = pm.getComponentEnabledSetting(name);
        Intent cameraIntent = IntentHelper.getCameraIntent(context);
        List<ResolveInfo> apps = pm.queryIntentActivities(cameraIntent, 0);
        sCameraAvailableInitialized = true;
        sCameraAvailable =
           (state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT)
           || (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
        sCameraAvailable = !apps.isEmpty();
        return sCameraAvailable;
    }

+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ public class IntentHelper {

    public static Intent getCameraIntent(Context context) {
        return new Intent(Intent.ACTION_MAIN)
            .setClassName("com.android.camera2", "com.android.camera.CameraActivity");
            .setClassName("com.android.camera2", "com.android.camera.CameraLauncher");
    }

    public static Intent getGalleryIntent(Context context) {