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

Commit 7f40699e authored by Momoko Hattori's avatar Momoko Hattori
Browse files

Add closeDatabase method to classes owning SQLiteOpenHelper instance

CTS often calls `pm clear com.android.documentsui` to clear the app's
local data, including the database file of LastAccessedProvider. In ARC,
this causes inconsistency between the actual database status and the
database status managed by the instance of LastAccessedProvider, because
DocumentsUI is persistent only in ARC and `pm clear` doesn't kill ARC's
DocumentsUI like it does in Android phones.

This CL introduces closeDatabase to the instances of SQLiteOpenHelper in
DocumentsUI. These will be called from ARC's DocumentsUI (ag/26552505)
to prevent the inconsistent state described above.

Bug: 304373253
Test: Same as ag/26552505.

Change-Id: I95ea5bc5aee91f0bf70b4ece2941d2f9007df84c
parent 1b2c512c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ public class LastAccessedProvider extends ContentProvider {

    private static final int URI_LAST_ACCESSED = 1;

    public static final String METHOD_CLOSE_DATABASE = "closeDatabase";
    public static final String METHOD_PURGE = "purge";
    public static final String METHOD_PURGE_PACKAGE = "purgePackage";

@@ -236,6 +237,9 @@ public class LastAccessedProvider extends ContentProvider {

            return null;

        } else if (METHOD_CLOSE_DATABASE.equals(method)) {
            mHelper.close();
            return null;
        } else {
            return super.call(method, arg, extras);
        }
+13 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class PickCountRecordProvider extends ContentProvider {
@@ -40,6 +41,8 @@ public class PickCountRecordProvider extends ContentProvider {

    static final String AUTHORITY = "com.android.documentsui.pickCountRecord";

    public static final String METHOD_CLOSE_DATABASE = "closeDatabase";

    static {
        MATCHER.addURI(AUTHORITY, "pickCountRecord/*", URI_PICK_RECORD);
    }
@@ -148,4 +151,14 @@ public class PickCountRecordProvider extends ContentProvider {
    public String getType(Uri uri) {
        return null;
    }

    @Override
    public Bundle call(String method, String arg, Bundle extras) {
        if (METHOD_CLOSE_DATABASE.equals(method)) {
            mHelper.close();
            return null;
        } else {
            return super.call(method, arg, extras);
        }
    }
}
 No newline at end of file
+7 −0
Original line number Diff line number Diff line
@@ -175,6 +175,13 @@ public class SearchHistoryManager {
        }
    }

    /**
     * Closes the database.
     */
    public void closeDatabase() {
        mHelper.close();
    }

    private class DatabaseTask extends AsyncTask<Object, Void, Object> {
        private final String mKeyword;
        private final DATABASE_OPERATION mOperation;