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

Commit 9bbb0002 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Using new APIs for disabling metaData table" into ub-launcher3-master

parents bb2a6054 19026b25
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ import com.android.launcher3.model.ModelWriter;
import com.android.launcher3.provider.LauncherDbUtils;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
import com.android.launcher3.provider.RestoreDbTask;
import com.android.launcher3.util.NoLocaleSqliteContext;
import com.android.launcher3.util.NoLocaleSQLiteHelper;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.Thunk;

@@ -546,7 +546,7 @@ public class LauncherProvider extends ContentProvider {
    /**
     * The class is subclassed in tests to create an in-memory db.
     */
    public static class DatabaseHelper extends SQLiteOpenHelper implements LayoutParserCallback {
    public static class DatabaseHelper extends NoLocaleSQLiteHelper implements LayoutParserCallback {
        private final Handler mWidgetHostResetHandler;
        private final Context mContext;
        private long mMaxItemId = -1;
@@ -572,7 +572,7 @@ public class LauncherProvider extends ContentProvider {
         */
        public DatabaseHelper(
                Context context, Handler widgetHostResetHandler, String tableName) {
            super(new NoLocaleSqliteContext(context), tableName, null, SCHEMA_VERSION);
            super(context, tableName, SCHEMA_VERSION);
            mContext = context;
            mWidgetHostResetHandler = widgetHostResetHandler;
        }
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3.util;

import static android.database.sqlite.SQLiteDatabase.NO_LOCALIZED_COLLATORS;

import static com.android.launcher3.Utilities.ATLEAST_P;

import android.content.Context;
import android.content.ContextWrapper;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteDatabase.OpenParams;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Extension of {@link SQLiteOpenHelper} which avoids creating default locale table by
 * A context wrapper which creates databases without support for localized collators.
 */
public abstract class NoLocaleSQLiteHelper extends SQLiteOpenHelper {

    public NoLocaleSQLiteHelper(Context context, String name, int version) {
        super(ATLEAST_P ? context : new NoLocalContext(context), name, null, version);
        if (ATLEAST_P) {
            setOpenParams(new OpenParams.Builder().addOpenFlags(NO_LOCALIZED_COLLATORS).build());
        }
    }

    private static class NoLocalContext extends ContextWrapper {
        public NoLocalContext(Context base) {
            super(base);
        }

        @Override
        public SQLiteDatabase openOrCreateDatabase(
                String name, int mode, CursorFactory factory, DatabaseErrorHandler errorHandler) {
            return super.openOrCreateDatabase(
                    name, mode | Context.MODE_NO_LOCALIZED_COLLATORS, factory, errorHandler);
        }
    }
}
+0 −24
Original line number Diff line number Diff line
package com.android.launcher3.util;

import android.content.Context;
import android.content.ContextWrapper;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

/**
 * A context wrapper which creates databases without support for localized collators.
 */
public class NoLocaleSqliteContext extends ContextWrapper {

    public NoLocaleSqliteContext(Context context) {
        super(context);
    }

    @Override
    public SQLiteDatabase openOrCreateDatabase(
            String name, int mode, CursorFactory factory, DatabaseErrorHandler errorHandler) {
        return super.openOrCreateDatabase(
                name, mode | Context.MODE_NO_LOCALIZED_COLLATORS, factory, errorHandler);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -92,10 +92,10 @@ public abstract class SQLiteCacheHelper {
    /**
     * A private inner class to prevent direct DB access.
     */
    private class MySQLiteOpenHelper extends SQLiteOpenHelper {
    private class MySQLiteOpenHelper extends NoLocaleSQLiteHelper {

        public MySQLiteOpenHelper(Context context, String name, int version) {
            super(new NoLocaleSqliteContext(context), name, null, version);
            super(context, name, version);
        }

        @Override