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

Commit 20f549fd authored by Vasu Nori's avatar Vasu Nori
Browse files

several minor bugs and things listed below

bug:1648729
   print warning if a requery is attemped on main thread
bug:2459293
   browser death because of NoSuchElementException. don't use iterator
   to march thru the ArrayList. use old style for() loop.
bug:1609474
   don't allow downgrades of databases
other stuff
   use LRUcache to maintain statement-cache in SQLiteDatabase
Change-Id: I3a42022162f4dfcc75f7d0cfcad8f20f1d193249
parent 0d8d70bb
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -16,15 +16,14 @@

package android.database;

import android.app.ActivityThread;
import android.content.ContentResolver;
import android.net.Uri;
import android.util.Config;
import android.util.Log;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.Process;

import java.lang.ref.WeakReference;
import java.lang.UnsupportedOperationException;
@@ -90,6 +89,14 @@ public abstract class AbstractCursor implements CrossProcessCursor {
    }

    public boolean requery() {
        // print a warning if this method is being called from Main (UI) thread
        if (Looper.getMainLooper() == Looper.myLooper()) {
            // yes this is UI thread.
            String packageName = ActivityThread.currentPackageName();
            Log.w(TAG, "should not attempt requery on main (UI) thread: app = " +
                    packageName == null ? "'unknown'" : packageName,
                    new RequeryOnUiThreadException(packageName));
        }
        if (mSelfObserver != null && mSelfObserverRegistered == false) {
            mContentResolver.registerContentObserver(mNotifyUri, true, mSelfObserver);
            mSelfObserverRegistered = true;
+4 −0
Original line number Diff line number Diff line
@@ -493,6 +493,10 @@ public interface Cursor {
     * contents. This may be done at any time, including after a call to {@link
     * #deactivate}.
     *
     * Since this method could execute a query on the database and potentially take
     * a while, it could cause ANR if it is called on Main (UI) thread.
     * A warning is printed if this method is being executed on Main thread.
     *
     * @return true if the requery succeeded, false if not, in which case the
     *         cursor becomes invalid.
     */
+8 −4
Original line number Diff line number Diff line
@@ -27,8 +27,12 @@ public class DataSetObservable extends Observable<DataSetObserver> {
     */
    public void notifyChanged() {
        synchronized(mObservers) {
            for (DataSetObserver observer : mObservers) {
                observer.onChanged();
            // since onChanged() is implemented by the app, it could do anything, including
            // removing itself from {@link mObservers} - and that could cause problems if
            // an iterator is used on the ArrayList {@link mObservers}.
            // to avoid such problems, just march thru the list in the reverse order.
            for (int i = mObservers.size() - 1; i >= 0; i--) {
                mObservers.get(i).onChanged();
            }
        }
    }
@@ -39,8 +43,8 @@ public class DataSetObservable extends Observable<DataSetObserver> {
     */
    public void notifyInvalidated() {
        synchronized (mObservers) {
            for (DataSetObserver observer : mObservers) {
                observer.onInvalidated();
            for (int i = mObservers.size() - 1; i >= 0; i--) {
                mObservers.get(i).onInvalidated();
            }
        }
    }
+29 −0
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.");
    }
}
+2 −4
Original line number Diff line number Diff line
@@ -21,13 +21,11 @@ package android.database.sqlite;
 * that is not explicitly closed
 * @hide
 */
public class DatabaseObjectNotClosedException extends RuntimeException
{
public class DatabaseObjectNotClosedException extends RuntimeException {
    private static final String s = "Application did not close the cursor or database object " +
            "that was opened here";

    public DatabaseObjectNotClosedException()
    {
    public DatabaseObjectNotClosedException() {
        super(s);
    }
}
Loading