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

Commit 03b1a529 authored by Oli Lan's avatar Oli Lan Committed by Automerger Merge Worker
Browse files

Merge "Revert "Prevent exfiltration of system files via user image settings.""...

Merge "Revert "Prevent exfiltration of system files via user image settings."" into qt-dev am: b9bafa0d am: 05031cc5

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/19449016



Change-Id: I5a78c2328f8c68fb5bf15799a69479a82b8e7af7
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 316cd96b 05031cc5
Loading
Loading
Loading
Loading
+13 −29
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import android.content.ClipData;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
@@ -79,7 +78,6 @@ public class EditUserPhotoController {
    private static final int REQUEST_CODE_TAKE_PHOTO   = 1002;
    private static final int REQUEST_CODE_CROP_PHOTO   = 1003;

    private static final String PRE_CROP_PICTURE_FILE_NAME = "PreCropEditUserPhoto.jpg";
    private static final String CROP_PICTURE_FILE_NAME = "CropEditUserPhoto.jpg";
    private static final String TAKE_PICTURE_FILE_NAME = "TakeEditUserPhoto2.jpg";
    private static final String NEW_USER_PHOTO_FILE_NAME = "NewUserPhoto.png";
@@ -90,7 +88,6 @@ public class EditUserPhotoController {
    private final Fragment mFragment;
    private final ImageView mImageView;

    private final Uri mPreCropPictureUri;
    private final Uri mCropPictureUri;
    private final Uri mTakePictureUri;

@@ -102,8 +99,6 @@ public class EditUserPhotoController {
        mContext = view.getContext();
        mFragment = fragment;
        mImageView = view;

        mPreCropPictureUri = createTempImageUri(mContext, PRE_CROP_PICTURE_FILE_NAME, !waiting);
        mCropPictureUri = createTempImageUri(mContext, CROP_PICTURE_FILE_NAME, !waiting);
        mTakePictureUri = createTempImageUri(mContext, TAKE_PICTURE_FILE_NAME, !waiting);
        mPhotoSize = getPhotoSize(mContext);
@@ -138,7 +133,7 @@ public class EditUserPhotoController {
            case REQUEST_CODE_TAKE_PHOTO:
            case REQUEST_CODE_CHOOSE_PHOTO:
                if (mTakePictureUri.equals(pictureUri)) {
                    cropPhoto(pictureUri);
                    cropPhoto();
                } else {
                    copyAndCropPhoto(pictureUri);
                }
@@ -234,7 +229,7 @@ public class EditUserPhotoController {
            protected Void doInBackground(Void... params) {
                final ContentResolver cr = mContext.getContentResolver();
                try (InputStream in = cr.openInputStream(pictureUri);
                        OutputStream out = cr.openOutputStream(mPreCropPictureUri)) {
                        OutputStream out = cr.openOutputStream(mTakePictureUri)) {
                    Streams.copy(in, out);
                } catch (IOException e) {
                    Log.w(TAG, "Failed to copy photo", e);
@@ -245,38 +240,27 @@ public class EditUserPhotoController {
            @Override
            protected void onPostExecute(Void result) {
                if (!mFragment.isAdded()) return;
                cropPhoto(mPreCropPictureUri);
                cropPhoto();
            }
        }.execute();
    }

    private void cropPhoto(final Uri pictureUri) {
    private void cropPhoto() {
        // TODO: Use a public intent, when there is one.
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(pictureUri, "image/*");
        intent.setDataAndType(mTakePictureUri, "image/*");
        appendOutputExtra(intent, mCropPictureUri);
        appendCropExtras(intent);
        if (intent.resolveActivity(mContext.getPackageManager()) != null) {
            try {
                StrictMode.disableDeathOnFileUriExposure();
            if (startSystemActivityForResult(intent, REQUEST_CODE_CROP_PHOTO)) {
                return;
            }
                mFragment.startActivityForResult(intent, REQUEST_CODE_CROP_PHOTO);
            } finally {
                StrictMode.enableDeathOnFileUriExposure();
            }
        } else {
            onPhotoCropped(mTakePictureUri, false);
        }

    private boolean startSystemActivityForResult(Intent intent, int code) {
        ActivityInfo info = intent.resolveActivityInfo(mContext.getPackageManager(),
                PackageManager.MATCH_SYSTEM_ONLY);
        if (info == null) {
            Log.w(TAG, "No system package activity could be found for code " + code);
            return false;
        }
        intent.setPackage(info.packageName);
        mFragment.startActivityForResult(intent, code);
        return true;
    }

    private void appendOutputExtra(Intent intent, Uri pictureUri) {