8000 Revert "refactoed to code to use android/database/CursorWindow instea… · Sjith/android-database-sqlcipher@a486208 · GitHub
[go: up one dir, main page]

Skip to content

Commit a486208

Browse files
sjlombardodevelopernotes
authored andcommitted
Revert "refactoed to code to use android/database/CursorWindow instead of our own; solves fillWindow, CrossProcessCursor and Observable issues"
This reverts commit 4fc4c3c. Conflicts: src/info/guardianproject/database/sqlcipher/SQLiteDatabase.java
1 parent b234b5c commit a486208

25 files changed

+1085
-94
lines changed

src/info/guardianproject/database/AbstractCursor.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222

2323
import android.content.ContentResolver;
2424
import android.database.CharArrayBuffer;
25-
import android.database.ContentObservable;
26-
import android.database.ContentObserver;
27-
import android.database.CursorWindow;
28-
import android.database.DataSetObservable;
29-
import android.database.DataSetObserver;
3025
import android.net.Uri;
3126
import android.os.Bundle;
3227
import android.util.Config;
@@ -37,7 +32,7 @@
3732
* This is an abstract cursor class that handles a lot of the common code
3833
* that all cursors need to deal with and is provided for convenience reasons.
3934
*/
40-
public abstract class AbstractCursor implements android.database.CrossProcessCursor {
35+
public abstract class AbstractCursor implements CrossProcessCursor {
4136
private static final String TAG = "Cursor";
4237

4338
DataSetObservable mDataSetObservable = new DataSetObservable();
@@ -204,14 +199,11 @@ public final boolean moveToPosition(int position) {
204199
* Copy data from cursor to CursorWindow
205200
* @param position start position of data
206201
* @param window
207-
*/
208-
public void fillWindow(int position, android.database.CursorWindow window) {
209-
210-
211-
if (position < 0 || position > getCount()) {
202+
*/
203+
public void fillWindow(int position, CursorWindow window) {
204+
if (position < 0 || position > getCount()) {
212205
return;
213206
}
214-
215207
window.acquireReference();
216208
try {
217209
int oldpos = mPos;
@@ -483,7 +475,6 @@ protected DataSetObservable getDataSetObservable() {
483475
return mDataSetObservable;
484476

485477
}
486-
487478
public void registerDataSetObserver(DataSetObserver observer) {
488479
mDataSetObservable.registerObserver(observer);
489480

@@ -617,8 +608,6 @@ public void onChange(boolean selfChange) {
617608
cursor.onChange(false);
618609
}
619610
}
620-
621-
622611
}
623612

624613
/**

src/info/guardianproject/database/AbstractWindowedCursor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package info.guardianproject.database;
1818

1919
import android.database.CharArrayBuffer;
20-
import android.database.CursorWindow;
2120

2221
/**
2322
* A base class for Cursors that store their data in {@link CursorWindow}s.

src/info/guardianproject/database/BulkCursorNative.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616

1717
package info.guardianproject.database;
1818

19-
import java.util.HashMap;
20-
import java.util.Map;
21-
22-
import android.database.CursorWindow;
2319
import android.os.Binder;
24-
import android.os.Bundle;
20+
import android.os.RemoteException;
2521
import android.os.IBinder;
2622
import android.os.Parcel;
27-
import android.os.RemoteException;
23+
import android.os.Bundle;
24+
25+
import java.util.HashMap;
26+
import java.util.Map;
2827

2928
/**
3029
* Native implementation of the bulk cursor. This is only for use in implementing

src/info/guardianproject/database/BulkCursorToCursorAdaptor.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818

1919
import android.database.CharArrayBuffer;
2020
import android.database.ContentObserver;
21-
import android.database.CursorWindow;
2221
import android.database.DataSetObserver;
23-
import android.os.Bundle;
2422
import android.os.RemoteException;
23+
import android.os.Bundle;
2524
import android.util.Log;
2625

26+
import java.util.Map;
27+
2728
/**
2829
* Adapts an {@link IBulkCursor} to a {@link Cursor} for use in the local
2930
* process.
@@ -88,7 +89,7 @@ public synchronized IContentObserver getObserver() {
8889
if (mObserverBridge == null) {
8990
mObserverBridge = new SelfContentObserver(this);
9091
}
91-
return null;//mObserverBridge.getContentObserver();
92+
return mObserverBridge.getContentObserver();
9293
}
9394

9495
@Override
@@ -180,7 +181,6 @@ public boolean requery() {
180181
* @hide
181182
* @deprecated
182183
*/
183-
/*
184184
@Override
185185
public boolean deleteRow() {
186186
try {
@@ -207,7 +207,7 @@ public boolean deleteRow() {
207207
Log.e(TAG, "Unable to delete row because the remote process is dead");
208208
return false;
209209
}
210-
}*/
210+
}
211211

212212
@Override
213213
public String[] getColumnNames() {
@@ -225,7 +225,7 @@ public String[] getColumnNames() {
225225
/**
226226
* @hide
227227
* @deprecated
228-
*//*
228+
*/
229229
@Override
230230
public boolean commitUpdates(Map<? extends Long,
231231
? extends Map<String,Object>> additionalValues) {
@@ -258,7 +258,7 @@ public boolean commitUpdates(Map<? extends Long,
258258
return false;
259259
}
260260
}
261-
}*/
261+
}
262262

263263
@Override
264264
public Bundle getExtras() {
@@ -315,5 +315,4 @@ public void unregisterDataSetObserver(DataSetObserver observer) {
315315
}
316316

317317

318-
319318
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2007 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package info.guardianproject.database;
18+
19+
/**
20+
* A specialization of Observable for ContentObserver that provides methods for
21+
* invoking the various callback methods of ContentObserver.
22+
*/
23+
public class ContentObservable extends Observable<ContentObserver> {
24+
25+
@Override
26+
public void registerObserver(ContentObserver observer) {
27+
super.registerObserver(observer);
28+
}
29+
30+
/**
31+
* invokes dispatchUpdate on each observer, unless the observer doesn't want
32+
* self-notifications and the update is from a self-notification
33+
* @param selfChange
34+< F440 /span>
*/
35+
public void dispatchChange(boolean selfChange) {
36+
synchronized(mObservers) {
37+
for (ContentObserver observer : mObservers) {
38+
if (!selfChange || observer.deliverSelfNotifications()) {
39+
observer.dispatchChange(selfChange);
40+
}
41+
}
42+
}
43+
}
44+
45+
/**
46+
* invokes onChange on each observer
47+
* @param selfChange
48+
*/
49+
public void notifyChange(boolean selfChange) {
50+
synchronized(mObservers) {
51+
for (ContentObserver observer : mObservers) {
52+
observer.onChange(selfChange);
53+
}
54+
}
55+
}
56+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright (C) 2007 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package info.guardianproject.database;
18+
19+
import android.os.Handler;
20+
21+
/**
22+
* Receives call backs for changes to content. Must be implemented by objects which are added
23+
* to a {@link ContentObservable}.
24+
*/
25+
public abstract class ContentObserver extends android.database.ContentObserver {
26+
27+
private Transport mTransport;
28+
29+
// Protects mTransport
30+
private Object lock = new Object();
31+
32+
/* package */ Handler mHandler;
33+
34+
private final class NotificationRunnable implements Runnable {
35+
36+
private boolean mSelf;
37+
38+
public NotificationRunnable(boolean self) {
39+
mSelf = self;
40+
}
41+
42+
public void run() {
43+
ContentObserver.this.onChange(mSelf);
44+
}
45+
}
46+
47+
private static final class Transport extends IContentObserver.Stub {
48+
ContentObserver mContentObserver;
49+
50+
public Transport(ContentObserver contentObserver) {
51+
mContentObserver = contentObserver;
52+
}
53+
54+
public boolean deliverSelfNotifications() {
55+
ContentObserver contentObserver = mContentObserver;
56+
if (contentObserver != null) {
57+
return contentObserver.deliverSelfNotifications();
58+
}
59+
return false;
60+
}
61+
62+
public void onChange(boolean selfChange) {
63+
ContentObserver contentObserver = mContentObserver;
64+
if (contentObserver != null) {
65+
contentObserver.dispatchChange(selfChange);
66+
}
67+
}
68+
69+
public void releaseContentObserver() {
70+
mContentObserver = null;
71+
}
72+
}
73+
74+
/**
75+
* onChange() will happen on the provider Handler.
76+
*
77+
* @param handler The handler to run {@link #onChange} on.
78+
*/
79+
public ContentObserver(Handler handler) {
80+
81+
super(handler);
82+
mHandler = handler;
83+
}
84+
85+
/**
86+
* Gets access to the binder transport object. Not for public consumption.
87+
*
88+
* {@hide}
89+
*/
90+
public IContentObserver getContentObserver() {
91+
synchronized(lock) {
92+
if (mTransport == null) {
93+
mTransport = new Transport(this);
94+
}
95+
return mTransport;
96+
}
97+
}
98+
99+
/**
100+
* Gets access to the binder transport object, and unlinks the transport object
101+
* from the ContentObserver. Not for public consumption.
102+
*
103+
* {@hide}
104+
*/
105+
public IContentObserver releaseContentObserver() {
106+
synchronized(lock) {
107+
Transport oldTransport = mTransport;
10000
108+
if (oldTransport != null) {
109+
oldTransport.releaseContentObserver();
110+
mTransport = null;
111+
}
112+
return oldTransport;
113+
}
114+
}
115+
116+
/**
117+
* Returns true if this observer is interested in notifications for changes
118+
* made through the cursor the observer is registered with.
119+
*/
120+
public boolean deliverSelfNotifications() {
121+
return false;
122+
}
123+
124+
/**
125+
* This method is called when a change occurs to the cursor that
126+
* is being observed.
127+
*
128+
* @param selfChange true if the update was caused by a call to <code>commit</code> on the
129+
* cursor that is being observed.
130+
*/
131+
public void onChange(boolean selfChange) {}
132+
133+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2008 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package info.guardianproject.database;
18+
19+
public interface CrossProcessCursor extends Cursor{
20+
/**
21+
* returns a pre-filled window, return NULL if no such window
22+
*/
23+
CursorWindow getWindow();
24+
25+
/**
26+
* copies cursor data into the window start at pos
27+
*/
28+
void fillWindow(int pos, CursorWindow winow);
29+
30+
/**
31+
* This function is called every time the cursor is successfully scrolled
32+
* to a new position, giving the subclass a chance to update any state it
33+
* may have. If it returns false the move function will also do so and the
34+
* cursor will scroll to the beforeFirst position.
35+
*
36+
* @param oldPosition the position that we're moving from
37+
* @param newPosition the position that we're moving to
38+
* @return true if the move is successful, false otherwise
39+
*/
40+
boolean onMove(int oldPosition, int newPosition);
41+
42+
}

src/info/guardianproject/database/Cursor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import android.content.ContentResolver;
2222
import android.database.CharArrayBuffer;
23-
import android.database.ContentObserver;
24-
import android.database.DataSetObserver;
2523
import android.net.Uri;
2624
import android.os.Bundle;
2725

0 commit comments

Comments
 (0)
0