* commit '86371474de700494d9b7b324c8650858d9b18b50': No longer parceling FixedSizeRemoteViewsCaches
This commit is contained in:
@@ -29,8 +29,6 @@ import android.os.HandlerThread;
|
|||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
@@ -50,7 +48,7 @@ import com.android.internal.widget.IRemoteViewsFactory;
|
|||||||
public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback {
|
public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback {
|
||||||
private static final String TAG = "RemoteViewsAdapter";
|
private static final String TAG = "RemoteViewsAdapter";
|
||||||
|
|
||||||
// The max number of items in the cache
|
// The max number of items in the cache
|
||||||
private static final int sDefaultCacheSize = 40;
|
private static final int sDefaultCacheSize = 40;
|
||||||
// The delay (in millis) to wait until attempting to unbind from a service after a request.
|
// The delay (in millis) to wait until attempting to unbind from a service after a request.
|
||||||
// This ensures that we don't stay continually bound to the service and that it can be destroyed
|
// This ensures that we don't stay continually bound to the service and that it can be destroyed
|
||||||
@@ -61,7 +59,7 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
private static final int sDefaultLoadingViewHeight = 50;
|
private static final int sDefaultLoadingViewHeight = 50;
|
||||||
|
|
||||||
// Type defs for controlling different messages across the main and worker message queues
|
// Type defs for controlling different messages across the main and worker message queues
|
||||||
private static final int sDefaultMessageType = 0;
|
private static final int sDefaultMessageType = 0;
|
||||||
private static final int sUnbindServiceMessageType = 1;
|
private static final int sUnbindServiceMessageType = 1;
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -88,9 +86,9 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
|
|
||||||
// We cache the FixedSizeRemoteViewsCaches across orientation. These are the related data
|
// We cache the FixedSizeRemoteViewsCaches across orientation. These are the related data
|
||||||
// structures;
|
// structures;
|
||||||
private static final HashMap<Pair<Intent.FilterComparison, Integer>, Parcel>
|
private static final HashMap<Pair<Intent.FilterComparison, Integer>, FixedSizeRemoteViewsCache>
|
||||||
sCachedRemoteViewsCaches = new HashMap<Pair<Intent.FilterComparison, Integer>,
|
sCachedRemoteViewsCaches = new HashMap<Pair<Intent.FilterComparison, Integer>,
|
||||||
Parcel>();
|
FixedSizeRemoteViewsCache>();
|
||||||
private static final HashMap<Pair<Intent.FilterComparison, Integer>, Runnable>
|
private static final HashMap<Pair<Intent.FilterComparison, Integer>, Runnable>
|
||||||
sRemoteViewsCacheRemoveRunnables = new HashMap<Pair<Intent.FilterComparison, Integer>,
|
sRemoteViewsCacheRemoveRunnables = new HashMap<Pair<Intent.FilterComparison, Integer>,
|
||||||
Runnable>();
|
Runnable>();
|
||||||
@@ -354,7 +352,7 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
/**
|
/**
|
||||||
* The meta-data associated with the cache in it's current state.
|
* The meta-data associated with the cache in it's current state.
|
||||||
*/
|
*/
|
||||||
private static class RemoteViewsMetaData implements Parcelable {
|
private static class RemoteViewsMetaData {
|
||||||
int count;
|
int count;
|
||||||
int viewTypeCount;
|
int viewTypeCount;
|
||||||
boolean hasStableIds;
|
boolean hasStableIds;
|
||||||
@@ -373,51 +371,6 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
public RemoteViewsMetaData(Parcel src) {
|
|
||||||
count = src.readInt();
|
|
||||||
viewTypeCount = src.readInt();
|
|
||||||
hasStableIds = src.readInt() == 0 ? false : true;
|
|
||||||
mFirstViewHeight = src.readInt();
|
|
||||||
if (src.readInt() != 0) {
|
|
||||||
mUserLoadingView = new RemoteViews(src);
|
|
||||||
}
|
|
||||||
if (src.readInt() != 0) {
|
|
||||||
mFirstView = new RemoteViews(src);
|
|
||||||
}
|
|
||||||
int count = src.readInt();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
mTypeIdIndexMap.put(src.readInt(), src.readInt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeInt(count);
|
|
||||||
dest.writeInt(viewTypeCount);
|
|
||||||
dest.writeInt(hasStableIds ? 1 : 0);
|
|
||||||
dest.writeInt(mFirstViewHeight);
|
|
||||||
dest.writeInt(mUserLoadingView != null ? 1 : 0);
|
|
||||||
if (mUserLoadingView != null) {
|
|
||||||
mUserLoadingView.writeToParcel(dest, flags);
|
|
||||||
}
|
|
||||||
dest.writeInt(mFirstView != null ? 1 : 0);
|
|
||||||
if (mFirstView != null) {
|
|
||||||
mFirstView.writeToParcel(dest, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = mTypeIdIndexMap.size();
|
|
||||||
dest.writeInt(count);
|
|
||||||
for (Integer key: mTypeIdIndexMap.keySet()) {
|
|
||||||
dest.writeInt(key);
|
|
||||||
dest.writeInt(mTypeIdIndexMap.get(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(RemoteViewsMetaData d) {
|
public void set(RemoteViewsMetaData d) {
|
||||||
synchronized (d) {
|
synchronized (d) {
|
||||||
count = d.count;
|
count = d.count;
|
||||||
@@ -528,7 +481,7 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
/**
|
/**
|
||||||
* The meta-data associated with a single item in the cache.
|
* The meta-data associated with a single item in the cache.
|
||||||
*/
|
*/
|
||||||
private static class RemoteViewsIndexMetaData implements Parcelable {
|
private static class RemoteViewsIndexMetaData {
|
||||||
int typeId;
|
int typeId;
|
||||||
long itemId;
|
long itemId;
|
||||||
|
|
||||||
@@ -536,22 +489,6 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
set(v, itemId);
|
set(v, itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RemoteViewsIndexMetaData(Parcel src) {
|
|
||||||
typeId = src.readInt();
|
|
||||||
itemId = src.readLong();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeInt(typeId);
|
|
||||||
dest.writeLong(itemId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(RemoteViews v, long id) {
|
public void set(RemoteViews v, long id) {
|
||||||
itemId = id;
|
itemId = id;
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
@@ -565,7 +502,7 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static class FixedSizeRemoteViewsCache implements Parcelable {
|
private static class FixedSizeRemoteViewsCache {
|
||||||
private static final String TAG = "FixedSizeRemoteViewsCache";
|
private static final String TAG = "FixedSizeRemoteViewsCache";
|
||||||
|
|
||||||
// The meta data related to all the RemoteViews, ie. count, is stable, etc.
|
// The meta data related to all the RemoteViews, ie. count, is stable, etc.
|
||||||
@@ -627,57 +564,6 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
mLoadIndices = new HashSet<Integer>();
|
mLoadIndices = new HashSet<Integer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FixedSizeRemoteViewsCache(Parcel src) {
|
|
||||||
mMaxCount = src.readInt();
|
|
||||||
mMaxCountSlack = src.readInt();
|
|
||||||
mPreloadLowerBound = src.readInt();
|
|
||||||
mPreloadUpperBound = src.readInt();
|
|
||||||
mMetaData = new RemoteViewsMetaData(src);
|
|
||||||
int count = src.readInt();
|
|
||||||
mIndexMetaData = new HashMap<Integer, RemoteViewsIndexMetaData>();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
mIndexMetaData.put(src.readInt(), new RemoteViewsIndexMetaData(src));
|
|
||||||
}
|
|
||||||
count = src.readInt();
|
|
||||||
mIndexRemoteViews = new HashMap<Integer, RemoteViews>();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
mIndexRemoteViews.put(src.readInt(), new RemoteViews(src));
|
|
||||||
}
|
|
||||||
|
|
||||||
mTemporaryMetaData = new RemoteViewsMetaData();
|
|
||||||
mRequestedIndices = new HashSet<Integer>();
|
|
||||||
mLastRequestedIndex = -1;
|
|
||||||
mLoadIndices = new HashSet<Integer>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeInt(mMaxCount);
|
|
||||||
dest.writeInt(mMaxCountSlack);
|
|
||||||
dest.writeInt(mPreloadLowerBound);
|
|
||||||
dest.writeInt(mPreloadUpperBound);
|
|
||||||
mMetaData.writeToParcel(dest, 0);
|
|
||||||
|
|
||||||
// We write the index data and cache
|
|
||||||
int count = mIndexMetaData.size();
|
|
||||||
dest.writeInt(count);
|
|
||||||
for (Integer key: mIndexMetaData.keySet()) {
|
|
||||||
dest.writeInt(key);
|
|
||||||
mIndexMetaData.get(key).writeToParcel(dest, flags);
|
|
||||||
}
|
|
||||||
count = mIndexRemoteViews.size();
|
|
||||||
dest.writeInt(count);
|
|
||||||
for (Integer key: mIndexRemoteViews.keySet()) {
|
|
||||||
dest.writeInt(key);
|
|
||||||
mIndexRemoteViews.get(key).writeToParcel(dest, flags);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void insert(int position, RemoteViews v, long itemId,
|
public void insert(int position, RemoteViews v, long itemId,
|
||||||
ArrayList<Integer> visibleWindow) {
|
ArrayList<Integer> visibleWindow) {
|
||||||
// Trim the cache if we go beyond the count
|
// Trim the cache if we go beyond the count
|
||||||
@@ -897,12 +783,18 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
|
|
||||||
synchronized(sCachedRemoteViewsCaches) {
|
synchronized(sCachedRemoteViewsCaches) {
|
||||||
if (sCachedRemoteViewsCaches.containsKey(key)) {
|
if (sCachedRemoteViewsCaches.containsKey(key)) {
|
||||||
Parcel src = sCachedRemoteViewsCaches.get(key);
|
mCache = sCachedRemoteViewsCaches.get(key);
|
||||||
src.setDataPosition(0);
|
synchronized (mCache.mMetaData) {
|
||||||
mCache = new FixedSizeRemoteViewsCache(src);
|
if (mCache.mMetaData.count > 0) {
|
||||||
mDataReady = true;
|
// As a precautionary measure, we verify that the meta data indicates a
|
||||||
|
// non-zero count before declaring that data is ready.
|
||||||
|
mDataReady = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mCache = new FixedSizeRemoteViewsCache(sDefaultCacheSize);
|
mCache = new FixedSizeRemoteViewsCache(sDefaultCacheSize);
|
||||||
|
}
|
||||||
|
if (!mDataReady) {
|
||||||
requestBindService();
|
requestBindService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -934,11 +826,18 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
sRemoteViewsCacheRemoveRunnables.remove(key);
|
sRemoteViewsCacheRemoveRunnables.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Parcel p = Parcel.obtain();
|
int metaDataCount = 0;
|
||||||
synchronized(mCache) {
|
int numRemoteViewsCached = 0;
|
||||||
mCache.writeToParcel(p, 0);
|
synchronized (mCache.mMetaData) {
|
||||||
|
metaDataCount = mCache.mMetaData.count;
|
||||||
}
|
}
|
||||||
sCachedRemoteViewsCaches.put(key, p);
|
synchronized (mCache) {
|
||||||
|
numRemoteViewsCached = mCache.mIndexRemoteViews.size();
|
||||||
|
}
|
||||||
|
if (metaDataCount > 0 && numRemoteViewsCached > 0) {
|
||||||
|
sCachedRemoteViewsCaches.put(key, mCache);
|
||||||
|
}
|
||||||
|
|
||||||
Runnable r = new Runnable() {
|
Runnable r = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -1332,6 +1231,12 @@ public class RemoteViewsAdapter extends BaseAdapter implements Handler.Callback
|
|||||||
|
|
||||||
private ArrayList<Integer> getVisibleWindow(int lower, int upper, int count) {
|
private ArrayList<Integer> getVisibleWindow(int lower, int upper, int count) {
|
||||||
ArrayList<Integer> window = new ArrayList<Integer>();
|
ArrayList<Integer> window = new ArrayList<Integer>();
|
||||||
|
|
||||||
|
// In the case that the window is invalid or uninitialized, return an empty window.
|
||||||
|
if ((lower == 0 && upper == 0) || lower < 0 || upper < 0) {
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
if (lower <= upper) {
|
if (lower <= upper) {
|
||||||
for (int i = lower; i <= upper; i++){
|
for (int i = lower; i <= upper; i++){
|
||||||
window.add(i);
|
window.add(i);
|
||||||
|
|||||||
Reference in New Issue
Block a user