From e09fd9e819c23dc90bca68375645e15544861330 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Wed, 17 Dec 2008 18:05:43 -0800 Subject: Code drop from //branches/cupcake/...@124589 --- include/utils/IPCThreadState.h | 3 +++ include/utils/MemoryHeapPmem.h | 25 ++++++++++++++++----- include/utils/ResourceTypes.h | 49 ++++++++++++++++++++++++++++++++++-------- include/utils/TimeUtils.h | 5 +++-- include/utils/string_array.h | 13 +++++++++++ 5 files changed, 79 insertions(+), 16 deletions(-) (limited to 'include/utils') diff --git a/include/utils/IPCThreadState.h b/include/utils/IPCThreadState.h index 47043b8170..0490fd3ec2 100644 --- a/include/utils/IPCThreadState.h +++ b/include/utils/IPCThreadState.h @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_WIN32_PROC typedef int uid_t; @@ -92,6 +93,8 @@ private: void* cookie); const sp mProcess; + Vector mPendingStrongDerefs; + Vector mPendingWeakDerefs; Parcel mIn; Parcel mOut; diff --git a/include/utils/MemoryHeapPmem.h b/include/utils/MemoryHeapPmem.h index b694b202ad..60335adaef 100644 --- a/include/utils/MemoryHeapPmem.h +++ b/include/utils/MemoryHeapPmem.h @@ -23,7 +23,7 @@ #include #include #include -#include +#include namespace android { @@ -31,11 +31,21 @@ class MemoryHeapBase; // --------------------------------------------------------------------------- -class SubRegionMemory; - class MemoryHeapPmem : public HeapInterface, public MemoryHeapBase { public: + class MemoryPmem : public BnMemory { + public: + MemoryPmem(const sp& heap); + ~MemoryPmem(); + protected: + const sp& getHeap() const { return mClientHeap; } + private: + friend class MemoryHeapPmem; + virtual void revoke() = 0; + sp mClientHeap; + }; + MemoryHeapPmem(const sp& pmemHeap, uint32_t flags = IMemoryHeap::MAP_ONCE); ~MemoryHeapPmem(); @@ -51,11 +61,16 @@ public: /* revoke all allocations made by this heap */ virtual void revoke(); - + +private: + /* use this to create your own IMemory for mapMemory */ + virtual sp createMemory(size_t offset, size_t size); + void remove(const wp& memory); + private: sp mParentHeap; mutable Mutex mLock; - Vector< wp > mAllocations; + SortedVector< wp > mAllocations; }; diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h index 31b9aa84ba..2d56e3e263 100644 --- a/include/utils/ResourceTypes.h +++ b/include/utils/ResourceTypes.h @@ -140,8 +140,6 @@ struct Res_png_9patch void serialize(void* outData); // Deserialize/Unmarshall the patch data static Res_png_9patch* deserialize(const void* data); - // Deserialize/Unmarshall the patch data into a newly malloc-ed block - static void deserialize(const void* data, Res_png_9patch* outData); // Compute the size of the serialized data structure size_t serializedSize(); }; @@ -860,6 +858,7 @@ struct ResTable_config KEYSHIDDEN_ANY = 0x0000, KEYSHIDDEN_NO = 0x0001, KEYSHIDDEN_YES = 0x0002, + KEYSHIDDEN_SOFT = 0x0003, }; union { @@ -989,11 +988,20 @@ struct ResTable_config return diffs; } - // Return true if 'this' is more specific than 'o'. + // Return true if 'this' is more specific than 'o'. Optionally, if + // 'requested' is null, then they will also be compared against the + // requested configuration and true will only be returned if 'this' + // is a better candidate than 'o' for the configuration. This assumes that + // match() has already been used to remove any configurations that don't + // match the requested configuration at all; if they are not first filtered, + // non-matching results can be considered better than matching ones. inline bool isBetterThan(const ResTable_config& o, const ResTable_config* requested = NULL) const { + // The order of the following tests defines the importance of one + // configuration parameter over another. Those tests first are more + // important, trumping any values in those following them. if (imsi != 0 && (!requested || requested->imsi != 0)) { - if (mcc != 0 && (!requested || requested->mcc!= 0)) { + if (mcc != 0 && (!requested || requested->mcc != 0)) { if (o.mcc == 0) { return true; } @@ -1034,9 +1042,24 @@ struct ResTable_config } } if (input != 0 && (!requested || requested->input != 0)) { - if ((inputFlags&MASK_KEYSHIDDEN) != 0 && (!requested - || (requested->inputFlags&MASK_KEYSHIDDEN) != 0)) { - if ((o.inputFlags&MASK_KEYSHIDDEN) == 0) { + const int keysHidden = inputFlags&MASK_KEYSHIDDEN; + const int reqKeysHidden = requested + ? requested->inputFlags&MASK_KEYSHIDDEN : 0; + if (keysHidden != 0 && reqKeysHidden != 0) { + const int oKeysHidden = o.inputFlags&MASK_KEYSHIDDEN; + //LOGI("isBetterThan keysHidden: cur=%d, given=%d, config=%d\n", + // keysHidden, oKeysHidden, reqKeysHidden); + if (oKeysHidden == 0) { + //LOGI("Better because 0!"); + return true; + } + // For compatibility, we count KEYSHIDDEN_NO as being + // the same as KEYSHIDDEN_SOFT. Here we disambiguate these + // may making an exact match more specific. + if (keysHidden == reqKeysHidden && oKeysHidden != reqKeysHidden) { + // The current configuration is an exact match, and + // the given one is not, so the current one is better. + //LOGI("Better because other not same!"); return true; } } @@ -1078,7 +1101,8 @@ struct ResTable_config return false; } - // Return true if 'this' matches the parameters in 'settings'. + // Return true if 'this' can be considered a match for the parameters in + // 'settings'. inline bool match(const ResTable_config& settings) const { if (imsi != 0) { if (settings.mcc != 0 && mcc != 0 @@ -1121,7 +1145,14 @@ struct ResTable_config const int setKeysHidden = settings.inputFlags&MASK_KEYSHIDDEN; if (setKeysHidden != 0 && keysHidden != 0 && keysHidden != setKeysHidden) { - return false; + // For compatibility, we count a request for KEYSHIDDEN_NO as also + // matching the more recent KEYSHIDDEN_SOFT. Basically + // KEYSHIDDEN_NO means there is some kind of keyboard available. + //LOGI("Matching keysHidden: have=%d, config=%d\n", keysHidden, setKeysHidden); + if (keysHidden != KEYSHIDDEN_NO || setKeysHidden != KEYSHIDDEN_SOFT) { + //LOGI("No match!"); + return false; + } } if (settings.keyboard != 0 && keyboard != 0 && keyboard != settings.keyboard) { diff --git a/include/utils/TimeUtils.h b/include/utils/TimeUtils.h index 30e533036c..b19e02126b 100644 --- a/include/utils/TimeUtils.h +++ b/include/utils/TimeUtils.h @@ -17,10 +17,11 @@ #ifndef ANDROID_TIME_H #define ANDROID_TIME_H +#include +#include #include #include #include -#include #include #include @@ -58,7 +59,7 @@ public: Time(); void switchTimezone(const char *timezone); - String8 format(const char *format) const; + String8 format(const char *format, const struct strftime_locale *locale) const; void format2445(short* buf, bool hasTime) const; String8 toString() const; void setToNow(); diff --git a/include/utils/string_array.h b/include/utils/string_array.h index ede0644cbc..064dda2248 100644 --- a/include/utils/string_array.h +++ b/include/utils/string_array.h @@ -111,6 +111,19 @@ public: return mArray[idx]; } + // + // Set entry N to specified string. + // [should use operator[] here] + // + void setEntry(int idx, const char* str) { + if (idx < 0 || idx >= mCurrent) + return; + delete[] mArray[idx]; + int len = strlen(str); + mArray[idx] = new char[len+1]; + memcpy(mArray[idx], str, len+1); + } + private: int mMax; int mCurrent; -- cgit v1.2.3-59-g8ed1b