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

Commit eb295038 authored by ztenghui's avatar ztenghui
Browse files

Fix the Google Drive issue

Here a local cache file will be downloaded and sent over to Gallery / Editor.
So we need to handle that well.

bug:9356969

Change-Id: Ic09a2f5de2c9c55ca2ed21c77ddf7517f5939bfb
parent d74271e5
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1215,6 +1215,9 @@ public abstract class PhotoPage extends ActivityState implements
                .findPathByUri(intent.getData(), intent.getType());
        if (path != null) {
            Path albumPath = mApplication.getDataManager().getDefaultSetOf(path);
            if (albumPath == null) {
                return;
            }
            if (!albumPath.equalsIgnoreCase(mOriginalSetPathString)) {
                // If the edited image is stored in a different album, we need
                // to start a new activity state to show the new image
+28 −5
Original line number Diff line number Diff line
@@ -402,7 +402,8 @@ public class SaveImage {

    /**
     *  Move the source file to auxiliary directory if needed and return the Uri
     *  pointing to this new source file.
     *  pointing to this new source file. If any file error happens, then just
     *  don't move into the auxiliary directory.
     * @param srcUri Uri to the source image.
     * @param dstFile Providing the destination file info to help to build the
     *  auxiliary directory and new source file's name.
@@ -419,7 +420,10 @@ public class SaveImage {
        // if necessary.
        File auxDiretory = getLocalAuxDirectory(dstFile);
        if (!auxDiretory.exists()) {
            auxDiretory.mkdirs();
            boolean success = auxDiretory.mkdirs();
            if (!success) {
                return srcUri;
            }
        }

        // Make sure there is a .nomedia file in the auxiliary directory, such
@@ -449,7 +453,10 @@ public class SaveImage {
        }

        if (!newSrcFile.exists()) {
            srcFile.renameTo(newSrcFile);
            boolean success = srcFile.renameTo(newSrcFile);
            if (!success) {
                return srcUri;
            }
        }

        return Uri.fromFile(newSrcFile);
@@ -634,7 +641,12 @@ public class SaveImage {
                });

        Uri result = sourceUri;
        if (oldSelectedFile == null || !deleteOriginal) {

        // In the case of incoming Uri is just a local file Uri (like a cached
        // file), we can't just update the Uri. We have to create a new Uri.
        boolean fileUri = isFileUri(sourceUri);

        if (fileUri || oldSelectedFile == null || !deleteOriginal) {
            result = context.getContentResolver().insert(
                    Images.Media.EXTERNAL_CONTENT_URI, values);
        } else {
@@ -643,8 +655,19 @@ public class SaveImage {
                oldSelectedFile.delete();
            }
        }

        return result;
    }

    /**
     * @param sourceUri
     * @return true if the sourceUri is a local file Uri.
     */
    private static boolean isFileUri(Uri sourceUri) {
        String scheme = sourceUri.getScheme();
        if (scheme != null && scheme.equals(ContentResolver.SCHEME_FILE)) {
            return true;
        }
        return false;
    }

}