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

Commit 5ba6b447 authored by Raman Tenneti's avatar Raman Tenneti Committed by Mohammed Althaf T
Browse files

AOSP/Gallery2 - Updated to sdkVersion 29. Deleted usage of GROUP BY from the...

AOSP/Gallery2 - Updated to sdkVersion 29. Deleted usage of GROUP BY from the WHERE clause. Changed all COUNT(*) to COUNT(_id).

API 29 disallows SQL injection by trying to include it in a "WHERE" clause. Galley app is used for CTS testing and that doesn't require the GROUP BY clause.

BUG: 133177396
BUG: 143968106
BUG: 143667204 (verified this bug doesn't happen)

Test: manual - Ran the following on Pixel phone. Tested the gallery2 UI manually.

$ make -j 40
$ make Gallery2 -j

$ ls -l out/target/product/generic/system/product/app/Gallery2/Gallery2.apk
  ... 7608845 Nov  5 16:58 out/target/product/generic/system/product/app/Gallery2/Gallery2.apk

$ adb install -r -d -g out/target/product/generic/system/product/app/Gallery2/Gallery2.apk

Change-Id: I415a35130f017b4440b2f398bf9000d0159f30d6
parent 616d31b8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

    <original-package android:name="com.android.gallery3d" />

    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="28"/>
    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29"/>

    <permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER"
                android:protectionLevel="signatureOrSystem" />
+2 −18
Original line number Diff line number Diff line
@@ -52,17 +52,6 @@ class BucketHelper {
    private static final int INDEX_MEDIA_TYPE = 1;
    private static final int INDEX_BUCKET_NAME = 2;

    // We want to order the albums by reverse chronological order. We abuse the
    // "WHERE" parameter to insert a "GROUP BY" clause into the SQL statement.
    // The template for "WHERE" parameter is like:
    //    SELECT ... FROM ... WHERE (%s)
    // and we make it look like:
    //    SELECT ... FROM ... WHERE (1) GROUP BY 1,(2)
    // The "(1)" means true. The "1,(2)" means the first two columns specified
    // after SELECT. Note that because there is a ")" in the template, we use
    // "(2" to match it.
    private static final String BUCKET_GROUP_BY = "1) GROUP BY 1,(2";

    private static final String BUCKET_ORDER_BY = "MAX(datetaken) DESC";

    // Before HoneyComb there is no Files table. Thus, we need to query the
@@ -82,9 +71,6 @@ class BucketHelper {
    // PROJECTION_BUCKET so we can reuse the values defined before.
    private static final int INDEX_DATE_TAKEN = 1;

    // When query from the Images or Video tables, we only need to group by BUCKET_ID.
    private static final String BUCKET_GROUP_BY_IN_ONE_TABLE = "1) GROUP BY (1";

    public static BucketEntry[] loadBucketEntries(
            JobContext jc, ContentResolver resolver, int type) {
        if (ApiHelper.HAS_MEDIA_PROVIDER_FILES_TABLE) {
@@ -97,7 +83,7 @@ class BucketHelper {
    private static void updateBucketEntriesFromTable(JobContext jc,
            ContentResolver resolver, Uri tableUri, HashMap<Integer, BucketEntry> buckets) {
        Cursor cursor = resolver.query(tableUri, PROJECTION_BUCKET_IN_ONE_TABLE,
                BUCKET_GROUP_BY_IN_ONE_TABLE, null, null);
                null, null, null);
        if (cursor == null) {
            Log.w(TAG, "cannot open media database: " + tableUri);
            return;
@@ -146,9 +132,7 @@ class BucketHelper {
            JobContext jc, ContentResolver resolver, int type) {
        Uri uri = getFilesContentUri();

        Cursor cursor = resolver.query(uri,
                PROJECTION_BUCKET, BUCKET_GROUP_BY,
                null, BUCKET_ORDER_BY);
        Cursor cursor = resolver.query(uri, PROJECTION_BUCKET, null, null, null);
        if (cursor == null) {
            Log.w(TAG, "cannot open local database: " + uri);
            return new BucketEntry[0];
+1 −1
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ import java.util.ArrayList;
// The media items need to be all images or all videos, but not both.
public class LocalAlbum extends MediaSet {
    private static final String TAG = "LocalAlbum";
    private static final String[] COUNT_PROJECTION = { "count(*)" };
    private static final String[] COUNT_PROJECTION = { "COUNT(_id)" };

    private static final int INVALID_COUNT = -1;
    private final String mWhereClause;
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ public class LocalPhotoSource implements WidgetSource {
    private static final Uri CONTENT_URI = Media.EXTERNAL_CONTENT_URI;
    private static final String DATE_TAKEN = Media.DATE_TAKEN;
    private static final String[] PROJECTION = {Media._ID};
    private static final String[] COUNT_PROJECTION = {"count(*)"};
    private static final String[] COUNT_PROJECTION = {"COUNT(_id)"};
    /* We don't want to include the download directory */
    private static final String SELECTION =
            String.format("%s != %s", Media.BUCKET_ID, getDownloadBucketId());
+3 −3
Original line number Diff line number Diff line
@@ -218,16 +218,16 @@ public class PhotoProvider extends SQLiteContentProvider {
            + Albums.TABLE;
    protected static final String SELECT_PHOTO_ID = "SELECT " + Photos._ID + " FROM "
            + Photos.TABLE;
    protected static final String SELECT_PHOTO_COUNT = "SELECT COUNT(*) FROM " + Photos.TABLE;
    protected static final String SELECT_PHOTO_COUNT = "SELECT COUNT(_id) FROM " + Photos.TABLE;
    protected static final String DELETE_PHOTOS = "DELETE FROM " + Photos.TABLE;
    protected static final String DELETE_METADATA = "DELETE FROM " + Metadata.TABLE;
    protected static final String SELECT_METADATA_COUNT = "SELECT COUNT(*) FROM " + Metadata.TABLE;
    protected static final String SELECT_METADATA_COUNT = "SELECT COUNT(_id) FROM " + Metadata.TABLE;
    protected static final String WHERE = " WHERE ";
    protected static final String IN = " IN ";
    protected static final String NESTED_SELECT_START = "(";
    protected static final String NESTED_SELECT_END = ")";
    protected static final String[] PROJECTION_COUNT = {
        "COUNT(*)"
        "COUNT(_id)"
    };

    /**