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

Commit b126f4a7 authored by Jay Shrauner's avatar Jay Shrauner
Browse files

Fix crash in getPhotoPickSize

Handle null or empty cursors.

Bug:12619944
Change-Id: I5cae8c16e29474afbc78a172f39bbb04daec446a
parent ea1b1c62
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -101,8 +101,9 @@ public class AttachPhotoActivity extends ContactsActivity {
                    new String[]{DisplayPhoto.DISPLAY_MAX_DIM}, null, null, null);
            if (c != null) {
                try {
                    c.moveToFirst();
                    if (c.moveToFirst()) {
                        mPhotoDim = c.getInt(0);
                    }
                } finally {
                    c.close();
                }
+18 −5
Original line number Diff line number Diff line
@@ -59,6 +59,11 @@ public abstract class PhotoSelectionHandler implements OnClickListener {
    private static final int REQUEST_CODE_PHOTO_PICKED_WITH_DATA = 1002;
    private static final int REQUEST_CROP_PHOTO = 1003;

    // Height and width (in pixels) to request for the photo - queried from the provider.
    private static int mPhotoDim;
    // Default photo dimension to use if unable to query the provider.
    private static final int mDefaultPhotoDim = 720;

    protected final Context mContext;
    private final View mPhotoView;
    private final int mPhotoMode;
@@ -263,16 +268,24 @@ public abstract class PhotoSelectionHandler implements OnClickListener {
    }

    private int getPhotoPickSize() {
        if (mPhotoDim != 0) {
            return mPhotoDim;
        }

        // Note that this URI is safe to call on the UI thread.
        Cursor c = mContext.getContentResolver().query(DisplayPhoto.CONTENT_MAX_DIMENSIONS_URI,
                new String[]{DisplayPhoto.DISPLAY_MAX_DIM}, null, null, null);
        if (c != null) {
            try {
            c.moveToFirst();
            return c.getInt(0);
                if (c.moveToFirst()) {
                    mPhotoDim = c.getInt(0);
                }
            } finally {
                c.close();
            }
        }
        return mPhotoDim != 0 ? mPhotoDim : mDefaultPhotoDim;
    }

    /**
     * Constructs an intent for capturing a photo and storing it in a temporary output uri.