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

Commit 820e9b6b authored by Vasu Nori's avatar Vasu Nori
Browse files

deperecate Cursor requery() and sa, Loader should be used instead

the warning printed currently "do requery on background thread"
is not that useful in processes such as gapps, acore.
to reduce the deluge of bugs assigned to me, I think a simple
deprecation warning is better.

Change-Id: I7a1129ea889f10e72895092a3cdd48cc96d0d1f0
parent 5060309f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -20,8 +20,6 @@ import android.content.ContentResolver;
import android.net.Uri;
import android.os.Bundle;

import java.util.Map;

/**
 * This interface provides random read-write access to the result set returned
 * by a database query.
@@ -344,7 +342,10 @@ public interface Cursor {
     *
     * @return true if the requery succeeded, false if not, in which case the
     *         cursor becomes invalid.
     * @deprecated Don't use this. Just request a new cursor, so you can do this
     * asynchronously and update your list view once the new cursor comes back.
     */
    @Deprecated
    boolean requery();

    /**
+0 −29
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 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 android.database;

/**
 * An exception that indicates invoking {@link Cursor#requery()} on Main thread could cause ANR.
 * This exception should encourage apps to invoke {@link Cursor#requery()} in a background thread. 
 * @hide
 */
public class RequeryOnUiThreadException extends RuntimeException {
    public RequeryOnUiThreadException(String packageName) {
        super("In " + packageName + " Requery is executing on main (UI) thread. could cause ANR. " +
                "do it in background thread.");
    }
}
+0 −32
Original line number Diff line number Diff line
@@ -16,13 +16,10 @@

package android.database.sqlite;

import android.app.ActivityThread;
import android.database.AbstractWindowedCursor;
import android.database.CursorWindow;
import android.database.DataSetObserver;
import android.database.RequeryOnUiThreadException;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.os.StrictMode;
@@ -75,11 +72,6 @@ public class SQLiteCursor extends AbstractWindowedCursor {
    private ReentrantLock mLock = null;
    private boolean mPendingData = false;

    /**
     * Used by {@link #requery()} to remember for which database we've already shown the warning.
     */
    private static final HashMap<String, Boolean> sAlreadyWarned = new HashMap<String, Boolean>();
    
    /**
     *  support for a cursor variant that doesn't always read all results
     *  initialRead is the initial number of items that cursor window reads 
@@ -401,35 +393,11 @@ public class SQLiteCursor extends AbstractWindowedCursor {
        }
    }

    /**
     * Show a warning against the use of requery() if called on the main thread.
     * This warning is shown per database per process.
     */
    private void warnIfUiThread() {
        if (Looper.getMainLooper() == Looper.myLooper()) {
            String databasePath = getQuery().mDatabase.getPath();
            // We show the warning once per database in order not to spam logcat.
            if (!sAlreadyWarned.containsKey(databasePath)) {
                sAlreadyWarned.put(databasePath, true);
                String packageName = ActivityThread.currentPackageName();
                Throwable t = null;
                // BEGIN STOPSHIP remove the following line
                t = new RequeryOnUiThreadException(packageName);
                // END STOPSHIP
                String s = packageName == null ? "'unknown'" : packageName;
                Log.w(TAG, "should not attempt requery on main (UI) thread: app = " + s +
                        " (database: " + mQuery.mDatabase.getPath() +
                        ", query: " + mQuery.mSql + ")", t);
            }
        }
    }

    @Override
    public boolean requery() {
        if (isClosed()) {
            return false;
        }
        warnIfUiThread();
        long timeStart = 0;
        if (Config.LOGV) {
            timeStart = System.currentTimeMillis();