libutils clean-up
Change-Id: I6ff4cfc736751de2912c697f954e45e275f2d386
diff --git a/include/utils/BufferedTextOutput.h b/include/binder/BufferedTextOutput.h
similarity index 98%
rename from include/utils/BufferedTextOutput.h
rename to include/binder/BufferedTextOutput.h
index 69c6240..adf3c32 100644
--- a/include/utils/BufferedTextOutput.h
+++ b/include/binder/BufferedTextOutput.h
@@ -17,7 +17,7 @@
#ifndef ANDROID_BUFFEREDTEXTOUTPUT_H
#define ANDROID_BUFFEREDTEXTOUTPUT_H
-#include <utils/TextOutput.h>
+#include <binder/TextOutput.h>
#include <utils/threads.h>
#include <cutils/uio.h>
diff --git a/include/binder/Debug.h b/include/binder/Debug.h
new file mode 100644
index 0000000..f6a3355
--- /dev/null
+++ b/include/binder/Debug.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2005 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.
+ */
+
+#ifndef ANDROID_BINDER_DEBUG_H
+#define ANDROID_BINDER_DEBUG_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+namespace android {
+// ---------------------------------------------------------------------------
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+const char* stringForIndent(int32_t indentLevel);
+
+typedef void (*debugPrintFunc)(void* cookie, const char* txt);
+
+void printTypeCode(uint32_t typeCode,
+ debugPrintFunc func = 0, void* cookie = 0);
+
+void printHexData(int32_t indent, const void *buf, size_t length,
+ size_t bytesPerLine=16, int32_t singleLineBytesCutoff=16,
+ size_t alignment=0, bool cArrayStyle=false,
+ debugPrintFunc func = 0, void* cookie = 0);
+
+#ifdef __cplusplus
+}
+#endif
+
+// ---------------------------------------------------------------------------
+}; // namespace android
+
+#endif // ANDROID_BINDER_DEBUG_H
diff --git a/include/utils/TextOutput.h b/include/binder/TextOutput.h
similarity index 100%
rename from include/utils/TextOutput.h
rename to include/binder/TextOutput.h
diff --git a/include/private/binder/Static.h b/include/private/binder/Static.h
index 5b0f9fc..6a03594 100644
--- a/include/private/binder/Static.h
+++ b/include/private/binder/Static.h
@@ -27,6 +27,9 @@
namespace android {
+// For TextStream.cpp
+extern Vector<int32_t> gTextBuffers;
+
// For ProcessState.cpp
extern Mutex gProcessMutex;
extern sp<ProcessState> gProcess;
diff --git a/include/private/utils/Static.h b/include/private/utils/Static.h
deleted file mode 100644
index d95ae0d..0000000
--- a/include/private/utils/Static.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-// All static variables go here, to control initialization and
-// destruction order in the library.
-
-#include <utils/threads.h>
-#include <utils/KeyedVector.h>
-
-namespace android {
-// For TextStream.cpp
-extern Vector<int32_t> gTextBuffers;
-
-// For String8.cpp
-extern void initialize_string8();
-extern void terminate_string8();
-
-// For String16.cpp
-extern void initialize_string16();
-extern void terminate_string16();
-
-} // namespace android
diff --git a/include/utils/Debug.h b/include/utils/Debug.h
index d9ed32d..08893bd 100644
--- a/include/utils/Debug.h
+++ b/include/utils/Debug.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ANDROID_DEBUG_H
-#define ANDROID_DEBUG_H
+#ifndef ANDROID_UTILS_DEBUG_H
+#define ANDROID_UTILS_DEBUG_H
#include <stdint.h>
#include <sys/types.h>
@@ -43,28 +43,6 @@
#endif
// ---------------------------------------------------------------------------
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-const char* stringForIndent(int32_t indentLevel);
-
-typedef void (*debugPrintFunc)(void* cookie, const char* txt);
-
-void printTypeCode(uint32_t typeCode,
- debugPrintFunc func = 0, void* cookie = 0);
-
-void printHexData(int32_t indent, const void *buf, size_t length,
- size_t bytesPerLine=16, int32_t singleLineBytesCutoff=16,
- size_t alignment=0, bool cArrayStyle=false,
- debugPrintFunc func = 0, void* cookie = 0);
-
-#ifdef __cplusplus
-}
-#endif
-
-// ---------------------------------------------------------------------------
}; // namespace android
-#endif // ANDROID_DEBUG_H
+#endif // ANDROID_UTILS_DEBUG_H
diff --git a/include/utils/GenerationCache.h b/include/utils/GenerationCache.h
deleted file mode 100644
index 40722d1..0000000
--- a/include/utils/GenerationCache.h
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Copyright (C) 2010 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.
- */
-
-#ifndef ANDROID_UTILS_GENERATION_CACHE_H
-#define ANDROID_UTILS_GENERATION_CACHE_H
-
-#include <utils/KeyedVector.h>
-#include <utils/RefBase.h>
-
-namespace android {
-
-/**
- * GenerationCache callback used when an item is removed
- */
-template<typename EntryKey, typename EntryValue>
-class OnEntryRemoved {
-public:
- virtual ~OnEntryRemoved() { };
- virtual void operator()(EntryKey& key, EntryValue& value) = 0;
-}; // class OnEntryRemoved
-
-template<typename EntryKey, typename EntryValue>
-struct Entry: public LightRefBase<Entry<EntryKey, EntryValue> > {
- Entry(const Entry<EntryKey, EntryValue>& e) :
- key(e.key), value(e.value),
- parent(e.parent), child(e.child) { }
- Entry(const EntryKey& key, const EntryValue& value) :
- key(key), value(value) { }
-
- EntryKey key;
- EntryValue value;
-
- sp<Entry<EntryKey, EntryValue> > parent; // next older entry
- sp<Entry<EntryKey, EntryValue> > child; // next younger entry
-}; // struct Entry
-
-/**
- * A LRU type cache
- */
-template<typename K, typename V>
-class GenerationCache {
-public:
- GenerationCache(uint32_t maxCapacity);
- virtual ~GenerationCache();
-
- enum Capacity {
- kUnlimitedCapacity,
- };
-
- void setOnEntryRemovedListener(OnEntryRemoved<K, V>* listener);
-
- size_t size() const;
-
- void clear();
-
- bool contains(const K& key) const;
- const K& getKeyAt(size_t index) const;
- const V& getValueAt(size_t index) const;
-
- const V& get(const K& key);
- bool put(const K& key, const V& value);
-
- void removeAt(ssize_t index);
- bool remove(const K& key);
- bool removeOldest();
-
-private:
- KeyedVector<K, sp<Entry<K, V> > > mCache;
- uint32_t mMaxCapacity;
-
- OnEntryRemoved<K, V>* mListener;
-
- sp<Entry<K, V> > mOldest;
- sp<Entry<K, V> > mYoungest;
-
- void attachToCache(const sp<Entry<K, V> >& entry);
- void detachFromCache(const sp<Entry<K, V> >& entry);
-
- const V mNullValue;
-}; // class GenerationCache
-
-template<typename K, typename V>
-GenerationCache<K, V>::GenerationCache(uint32_t maxCapacity): mMaxCapacity(maxCapacity),
- mListener(NULL), mNullValue(NULL) {
-};
-
-template<typename K, typename V>
-GenerationCache<K, V>::~GenerationCache() {
- clear();
-};
-
-template<typename K, typename V>
-uint32_t GenerationCache<K, V>::size() const {
- return mCache.size();
-}
-
-/**
- * Should be set by the user of the Cache so that the callback is called whenever an item is
- * removed from the cache
- */
-template<typename K, typename V>
-void GenerationCache<K, V>::setOnEntryRemovedListener(OnEntryRemoved<K, V>* listener) {
- mListener = listener;
-}
-
-template<typename K, typename V>
-void GenerationCache<K, V>::clear() {
- if (mListener) {
- for (uint32_t i = 0; i < mCache.size(); i++) {
- sp<Entry<K, V> > entry = mCache.valueAt(i);
- if (mListener) {
- (*mListener)(entry->key, entry->value);
- }
- }
- }
- mCache.clear();
- mYoungest.clear();
- mOldest.clear();
-}
-
-template<typename K, typename V>
-bool GenerationCache<K, V>::contains(const K& key) const {
- return mCache.indexOfKey(key) >= 0;
-}
-
-template<typename K, typename V>
-const K& GenerationCache<K, V>::getKeyAt(size_t index) const {
- return mCache.keyAt(index);
-}
-
-template<typename K, typename V>
-const V& GenerationCache<K, V>::getValueAt(size_t index) const {
- return mCache.valueAt(index)->value;
-}
-
-template<typename K, typename V>
-const V& GenerationCache<K, V>::get(const K& key) {
- ssize_t index = mCache.indexOfKey(key);
- if (index >= 0) {
- const sp<Entry<K, V> >& entry = mCache.valueAt(index);
- detachFromCache(entry);
- attachToCache(entry);
- return entry->value;
- }
-
- return mNullValue;
-}
-
-template<typename K, typename V>
-bool GenerationCache<K, V>::put(const K& key, const V& value) {
- if (mMaxCapacity != kUnlimitedCapacity && mCache.size() >= mMaxCapacity) {
- removeOldest();
- }
-
- ssize_t index = mCache.indexOfKey(key);
- if (index < 0) {
- sp<Entry<K, V> > entry = new Entry<K, V>(key, value);
- mCache.add(key, entry);
- attachToCache(entry);
- return true;
- }
-
- return false;
-}
-
-template<typename K, typename V>
-bool GenerationCache<K, V>::remove(const K& key) {
- ssize_t index = mCache.indexOfKey(key);
- if (index >= 0) {
- removeAt(index);
- return true;
- }
-
- return false;
-}
-
-template<typename K, typename V>
-void GenerationCache<K, V>::removeAt(ssize_t index) {
- sp<Entry<K, V> > entry = mCache.valueAt(index);
- if (mListener) {
- (*mListener)(entry->key, entry->value);
- }
- mCache.removeItemsAt(index, 1);
- detachFromCache(entry);
-}
-
-template<typename K, typename V>
-bool GenerationCache<K, V>::removeOldest() {
- if (mOldest.get()) {
- ssize_t index = mCache.indexOfKey(mOldest->key);
- if (index >= 0) {
- removeAt(index);
- return true;
- }
- ALOGE("GenerationCache: removeOldest failed to find the item in the cache "
- "with the given key, but we know it must be in there. "
- "Is the key comparator kaput?");
- }
-
- return false;
-}
-
-template<typename K, typename V>
-void GenerationCache<K, V>::attachToCache(const sp<Entry<K, V> >& entry) {
- if (!mYoungest.get()) {
- mYoungest = mOldest = entry;
- } else {
- entry->parent = mYoungest;
- mYoungest->child = entry;
- mYoungest = entry;
- }
-}
-
-template<typename K, typename V>
-void GenerationCache<K, V>::detachFromCache(const sp<Entry<K, V> >& entry) {
- if (entry->parent.get()) {
- entry->parent->child = entry->child;
- } else {
- mOldest = entry->child;
- }
-
- if (entry->child.get()) {
- entry->child->parent = entry->parent;
- } else {
- mYoungest = entry->parent;
- }
-
- entry->parent.clear();
- entry->child.clear();
-}
-
-}; // namespace android
-
-#endif // ANDROID_UTILS_GENERATION_CACHE_H
diff --git a/include/utils/LruCache.h b/include/utils/LruCache.h
index 302b929..053bfaf 100644
--- a/include/utils/LruCache.h
+++ b/include/utils/LruCache.h
@@ -18,12 +18,19 @@
#define ANDROID_UTILS_LRU_CACHE_H
#include <utils/BasicHashtable.h>
-#include <utils/GenerationCache.h>
#include <utils/UniquePtr.h>
namespace android {
-// OnEntryRemoved is defined in GenerationCache.h, but maybe should move here.
+/**
+ * GenerationCache callback used when an item is removed
+ */
+template<typename EntryKey, typename EntryValue>
+class OnEntryRemoved {
+public:
+ virtual ~OnEntryRemoved() { };
+ virtual void operator()(EntryKey& key, EntryValue& value) = 0;
+}; // class OnEntryRemoved
template <typename TKey, typename TValue>
class LruCache {
diff --git a/include/utils/String16.h b/include/utils/String16.h
index fe06c57..6d4253d 100644
--- a/include/utils/String16.h
+++ b/include/utils/String16.h
@@ -117,8 +117,6 @@
// require any change to the underlying SharedBuffer contents or reference count.
ANDROID_TRIVIAL_MOVE_TRAIT(String16)
-TextOutput& operator<<(TextOutput& to, const String16& val);
-
// ---------------------------------------------------------------------------
// No user servicable parts below.
diff --git a/include/utils/String8.h b/include/utils/String8.h
index 335e7f1..9426fcf 100644
--- a/include/utils/String8.h
+++ b/include/utils/String8.h
@@ -224,8 +224,6 @@
// require any change to the underlying SharedBuffer contents or reference count.
ANDROID_TRIVIAL_MOVE_TRAIT(String8)
-TextOutput& operator<<(TextOutput& to, const String16& val);
-
// ---------------------------------------------------------------------------
// No user servicable parts below.
diff --git a/include/utils/StringArray.h b/include/utils/StringArray.h
deleted file mode 100644
index c2445871..0000000
--- a/include/utils/StringArray.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2009 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.
- */
-
-//
-// Sortable array of strings. STL-ish, but STL-free.
-//
-#ifndef _LIBS_UTILS_STRING_ARRAY_H
-#define _LIBS_UTILS_STRING_ARRAY_H
-
-#include <stdlib.h>
-#include <string.h>
-
-namespace android {
-
-//
-// An expanding array of strings. Add, get, sort, delete.
-//
-class StringArray {
-public:
- StringArray();
- virtual ~StringArray();
-
- //
- // Add a string. A copy of the string is made.
- //
- bool push_back(const char* str);
-
- //
- // Delete an entry.
- //
- void erase(int idx);
-
- //
- // Sort the array.
- //
- void sort(int (*compare)(const void*, const void*));
-
- //
- // Pass this to the sort routine to do an ascending alphabetical sort.
- //
- static int cmpAscendingAlpha(const void* pstr1, const void* pstr2);
-
- //
- // Get the #of items in the array.
- //
- inline int size(void) const { return mCurrent; }
-
- //
- // Return entry N.
- // [should use operator[] here]
- //
- const char* getEntry(int idx) const {
- return (unsigned(idx) >= unsigned(mCurrent)) ? NULL : mArray[idx];
- }
-
- //
- // Set entry N to specified string.
- // [should use operator[] here]
- //
- void setEntry(int idx, const char* str);
-
-private:
- int mMax;
- int mCurrent;
- char** mArray;
-};
-
-}; // namespace android
-
-#endif // _LIBS_UTILS_STRING_ARRAY_H
diff --git a/include/utils/StrongPointer.h b/include/utils/StrongPointer.h
index 49fa3a8..40aebfd 100644
--- a/include/utils/StrongPointer.h
+++ b/include/utils/StrongPointer.h
@@ -207,12 +207,6 @@
m_ptr = ptr;
}
-template <typename T>
-inline TextOutput& operator<<(TextOutput& to, const sp<T>& val)
-{
- return printStrongPointer(to, val.get());
-}
-
}; // namespace android
// ---------------------------------------------------------------------------
diff --git a/include/utils/SystemClock.h b/include/utils/SystemClock.h
index d75264c..01db340 100644
--- a/include/utils/SystemClock.h
+++ b/include/utils/SystemClock.h
@@ -22,7 +22,6 @@
namespace android {
-int setCurrentTimeMillis(int64_t millis);
int64_t uptimeMillis();
int64_t elapsedRealtime();
int64_t elapsedRealtimeNano();
diff --git a/include/utils/Timers.h b/include/utils/Timers.h
index 92f66c9..d015421 100644
--- a/include/utils/Timers.h
+++ b/include/utils/Timers.h
@@ -103,43 +103,4 @@
} // extern "C"
#endif
-// ------------------------------------------------------------------
-// C++ API
-
-#ifdef __cplusplus
-
-namespace android {
-/*
- * Time the duration of something.
- *
- * Includes some timeval manipulation functions.
- */
-class DurationTimer {
-public:
- DurationTimer() {}
- ~DurationTimer() {}
-
- // Start the timer.
- void start();
- // Stop the timer.
- void stop();
- // Get the duration in microseconds.
- long long durationUsecs() const;
-
- // Subtract two timevals. Returns the difference (ptv1-ptv2) in
- // microseconds.
- static long long subtractTimevals(const struct timeval* ptv1,
- const struct timeval* ptv2);
-
- // Add the specified amount of time to the timeval.
- static void addToTimeval(struct timeval* ptv, long usec);
-
-private:
- struct timeval mStartWhen;
- struct timeval mStopWhen;
-};
-
-}; // android
-#endif // def __cplusplus
-
#endif // _LIBS_UTILS_TIMERS_H
diff --git a/include/utils/WorkQueue.h b/include/utils/WorkQueue.h
deleted file mode 100644
index e3c75b2..0000000
--- a/include/utils/WorkQueue.h
+++ /dev/null
@@ -1,119 +0,0 @@
-/*]
- * Copyright (C) 2012 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.
- */
-
-#ifndef _LIBS_UTILS_WORK_QUEUE_H
-#define _LIBS_UTILS_WORK_QUEUE_H
-
-#include <utils/Errors.h>
-#include <utils/Vector.h>
-#include <utils/threads.h>
-
-namespace android {
-
-/*
- * A threaded work queue.
- *
- * This class is designed to make it easy to run a bunch of isolated work
- * units in parallel, using up to the specified number of threads.
- * To use it, write a loop to post work units to the work queue, then synchronize
- * on the queue at the end.
- */
-class WorkQueue {
-public:
- class WorkUnit {
- public:
- WorkUnit() { }
- virtual ~WorkUnit() { }
-
- /*
- * Runs the work unit.
- * If the result is 'true' then the work queue continues scheduling work as usual.
- * If the result is 'false' then the work queue is canceled.
- */
- virtual bool run() = 0;
- };
-
- /* Creates a work queue with the specified maximum number of work threads. */
- WorkQueue(size_t maxThreads, bool canCallJava = true);
-
- /* Destroys the work queue.
- * Cancels pending work and waits for all remaining threads to complete.
- */
- ~WorkQueue();
-
- /* Posts a work unit to run later.
- * If the work queue has been canceled or is already finished, returns INVALID_OPERATION
- * and does not take ownership of the work unit (caller must destroy it itself).
- * Otherwise, returns OK and takes ownership of the work unit (the work queue will
- * destroy it automatically).
- *
- * For flow control, this method blocks when the size of the pending work queue is more
- * 'backlog' times the number of threads. This condition reduces the rate of entry into
- * the pending work queue and prevents it from growing much more rapidly than the
- * work threads can actually handle.
- *
- * If 'backlog' is 0, then no throttle is applied.
- */
- status_t schedule(WorkUnit* workUnit, size_t backlog = 2);
-
- /* Cancels all pending work.
- * If the work queue is already finished, returns INVALID_OPERATION.
- * If the work queue is already canceled, returns OK and does nothing else.
- * Otherwise, returns OK, discards all pending work units and prevents additional
- * work units from being scheduled.
- *
- * Call finish() after cancel() to wait for all remaining work to complete.
- */
- status_t cancel();
-
- /* Waits for all work to complete.
- * If the work queue is already finished, returns INVALID_OPERATION.
- * Otherwise, waits for all work to complete and returns OK.
- */
- status_t finish();
-
-private:
- class WorkThread : public Thread {
- public:
- WorkThread(WorkQueue* workQueue, bool canCallJava);
- virtual ~WorkThread();
-
- private:
- virtual bool threadLoop();
-
- WorkQueue* const mWorkQueue;
- };
-
- status_t cancelLocked();
- bool threadLoop(); // called from each work thread
-
- const size_t mMaxThreads;
- const bool mCanCallJava;
-
- Mutex mLock;
- Condition mWorkChangedCondition;
- Condition mWorkDequeuedCondition;
-
- bool mCanceled;
- bool mFinished;
- size_t mIdleThreads;
- Vector<sp<WorkThread> > mWorkThreads;
- Vector<WorkUnit*> mWorkUnits;
-};
-
-}; // namespace android
-
-#endif // _LIBS_UTILS_WORK_QUEUE_H
diff --git a/include/utils/ZipFileCRO.h b/include/utils/ZipFileCRO.h
deleted file mode 100644
index 3e42a95..0000000
--- a/include/utils/ZipFileCRO.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-//
-// C API for ead-only access to Zip archives, with minimal heap allocation.
-//
-#ifndef __LIBS_ZIPFILECRO_H
-#define __LIBS_ZIPFILECRO_H
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <utils/Compat.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Trivial typedef to ensure that ZipFileCRO is not treated as a simple integer.
- */
-typedef void* ZipFileCRO;
-
-/*
- * Trivial typedef to ensure that ZipEntryCRO is not treated as a simple
- * integer. We use NULL to indicate an invalid value.
- */
-typedef void* ZipEntryCRO;
-
-extern ZipFileCRO ZipFileXRO_open(const char* path);
-
-extern void ZipFileCRO_destroy(ZipFileCRO zip);
-
-extern ZipEntryCRO ZipFileCRO_findEntryByName(ZipFileCRO zip,
- const char* fileName);
-
-extern bool ZipFileCRO_getEntryInfo(ZipFileCRO zip, ZipEntryCRO entry,
- int* pMethod, size_t* pUncompLen,
- size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32);
-
-extern bool ZipFileCRO_uncompressEntry(ZipFileCRO zip, ZipEntryCRO entry, int fd);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*__LIBS_ZIPFILECRO_H*/
diff --git a/include/utils/ZipFileRO.h b/include/utils/ZipFileRO.h
deleted file mode 100644
index 547e36a..0000000
--- a/include/utils/ZipFileRO.h
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-/*
- * Read-only access to Zip archives, with minimal heap allocation.
- *
- * This is similar to the more-complete ZipFile class, but no attempt
- * has been made to make them interchangeable. This class operates under
- * a very different set of assumptions and constraints.
- *
- * One such assumption is that if you're getting file descriptors for
- * use with this class as a child of a fork() operation, you must be on
- * a pread() to guarantee correct operation. This is because pread() can
- * atomically read at a file offset without worrying about a lock around an
- * lseek() + read() pair.
- */
-#ifndef __LIBS_ZIPFILERO_H
-#define __LIBS_ZIPFILERO_H
-
-#include <utils/Compat.h>
-#include <utils/Errors.h>
-#include <utils/FileMap.h>
-#include <utils/threads.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <time.h>
-
-namespace android {
-
-/*
- * Trivial typedef to ensure that ZipEntryRO is not treated as a simple
- * integer. We use NULL to indicate an invalid value.
- */
-typedef void* ZipEntryRO;
-
-/*
- * Open a Zip archive for reading.
- *
- * We want "open" and "find entry by name" to be fast operations, and we
- * want to use as little memory as possible. We memory-map the file,
- * and load a hash table with pointers to the filenames (which aren't
- * null-terminated). The other fields are at a fixed offset from the
- * filename, so we don't need to extract those (but we do need to byte-read
- * and endian-swap them every time we want them).
- *
- * To speed comparisons when doing a lookup by name, we could make the mapping
- * "private" (copy-on-write) and null-terminate the filenames after verifying
- * the record structure. However, this requires a private mapping of
- * every page that the Central Directory touches. Easier to tuck a copy
- * of the string length into the hash table entry.
- *
- * NOTE: If this is used on file descriptors inherited from a fork() operation,
- * you must be on a platform that implements pread() to guarantee correctness
- * on the shared file descriptors.
- */
-class ZipFileRO {
-public:
- ZipFileRO()
- : mFd(-1), mFileName(NULL), mFileLength(-1),
- mDirectoryMap(NULL),
- mNumEntries(-1), mDirectoryOffset(-1),
- mHashTableSize(-1), mHashTable(NULL)
- {}
-
- ~ZipFileRO();
-
- /*
- * Open an archive.
- */
- status_t open(const char* zipFileName);
-
- /*
- * Find an entry, by name. Returns the entry identifier, or NULL if
- * not found.
- *
- * If two entries have the same name, one will be chosen at semi-random.
- */
- ZipEntryRO findEntryByName(const char* fileName) const;
-
- /*
- * Return the #of entries in the Zip archive.
- */
- int getNumEntries(void) const {
- return mNumEntries;
- }
-
- /*
- * Return the Nth entry. Zip file entries are not stored in sorted
- * order, and updated entries may appear at the end, so anyone walking
- * the archive needs to avoid making ordering assumptions. We take
- * that further by returning the Nth non-empty entry in the hash table
- * rather than the Nth entry in the archive.
- *
- * Valid values are [0..numEntries).
- *
- * [This is currently O(n). If it needs to be fast we can allocate an
- * additional data structure or provide an iterator interface.]
- */
- ZipEntryRO findEntryByIndex(int idx) const;
-
- /*
- * Copy the filename into the supplied buffer. Returns 0 on success,
- * -1 if "entry" is invalid, or the filename length if it didn't fit. The
- * length, and the returned string, include the null-termination.
- */
- int getEntryFileName(ZipEntryRO entry, char* buffer, int bufLen) const;
-
- /*
- * Get the vital stats for an entry. Pass in NULL pointers for anything
- * you don't need.
- *
- * "*pOffset" holds the Zip file offset of the entry's data.
- *
- * Returns "false" if "entry" is bogus or if the data in the Zip file
- * appears to be bad.
- */
- bool getEntryInfo(ZipEntryRO entry, int* pMethod, size_t* pUncompLen,
- size_t* pCompLen, off64_t* pOffset, long* pModWhen, long* pCrc32) const;
-
- /*
- * Create a new FileMap object that maps a subset of the archive. For
- * an uncompressed entry this effectively provides a pointer to the
- * actual data, for a compressed entry this provides the input buffer
- * for inflate().
- */
- FileMap* createEntryFileMap(ZipEntryRO entry) const;
-
- /*
- * Uncompress the data into a buffer. Depending on the compression
- * format, this is either an "inflate" operation or a memcpy.
- *
- * Use "uncompLen" from getEntryInfo() to determine the required
- * buffer size.
- *
- * Returns "true" on success.
- */
- bool uncompressEntry(ZipEntryRO entry, void* buffer) const;
-
- /*
- * Uncompress the data to an open file descriptor.
- */
- bool uncompressEntry(ZipEntryRO entry, int fd) const;
-
- /* Zip compression methods we support */
- enum {
- kCompressStored = 0, // no compression
- kCompressDeflated = 8, // standard deflate
- };
-
- /*
- * Utility function: uncompress deflated data, buffer to buffer.
- */
- static bool inflateBuffer(void* outBuf, const void* inBuf,
- size_t uncompLen, size_t compLen);
-
- /*
- * Utility function: uncompress deflated data, buffer to fd.
- */
- static bool inflateBuffer(int fd, const void* inBuf,
- size_t uncompLen, size_t compLen);
-
- /*
- * Utility function to convert ZIP's time format to a timespec struct.
- */
- static inline void zipTimeToTimespec(long when, struct tm* timespec) {
- const long date = when >> 16;
- timespec->tm_year = ((date >> 9) & 0x7F) + 80; // Zip is years since 1980
- timespec->tm_mon = (date >> 5) & 0x0F;
- timespec->tm_mday = date & 0x1F;
-
- timespec->tm_hour = (when >> 11) & 0x1F;
- timespec->tm_min = (when >> 5) & 0x3F;
- timespec->tm_sec = (when & 0x1F) << 1;
- }
-
- /*
- * Some basic functions for raw data manipulation. "LE" means
- * Little Endian.
- */
- static inline unsigned short get2LE(const unsigned char* buf) {
- return buf[0] | (buf[1] << 8);
- }
- static inline unsigned long get4LE(const unsigned char* buf) {
- return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
- }
-
-private:
- /* these are private and not defined */
- ZipFileRO(const ZipFileRO& src);
- ZipFileRO& operator=(const ZipFileRO& src);
-
- /* locate and parse the central directory */
- bool mapCentralDirectory(void);
-
- /* parse the archive, prepping internal structures */
- bool parseZipArchive(void);
-
- /* add a new entry to the hash table */
- void addToHash(const char* str, int strLen, unsigned int hash);
-
- /* compute string hash code */
- static unsigned int computeHash(const char* str, int len);
-
- /* convert a ZipEntryRO back to a hash table index */
- int entryToIndex(const ZipEntryRO entry) const;
-
- /*
- * One entry in the hash table.
- */
- typedef struct HashEntry {
- const char* name;
- unsigned short nameLen;
- //unsigned int hash;
- } HashEntry;
-
- /* open Zip archive */
- int mFd;
-
- /* Lock for handling the file descriptor (seeks, etc) */
- mutable Mutex mFdLock;
-
- /* zip file name */
- char* mFileName;
-
- /* length of file */
- size_t mFileLength;
-
- /* mapped file */
- FileMap* mDirectoryMap;
-
- /* number of entries in the Zip archive */
- int mNumEntries;
-
- /* CD directory offset in the Zip archive */
- off64_t mDirectoryOffset;
-
- /*
- * We know how many entries are in the Zip archive, so we have a
- * fixed-size hash table. We probe for an empty slot.
- */
- int mHashTableSize;
- HashEntry* mHashTable;
-};
-
-}; // namespace android
-
-#endif /*__LIBS_ZIPFILERO_H*/
diff --git a/include/utils/ZipUtils.h b/include/utils/ZipUtils.h
deleted file mode 100644
index 42c42b6..0000000
--- a/include/utils/ZipUtils.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-//
-// Miscellaneous zip/gzip utility functions.
-//
-#ifndef __LIBS_ZIPUTILS_H
-#define __LIBS_ZIPUTILS_H
-
-#include <stdio.h>
-
-namespace android {
-
-/*
- * Container class for utility functions, primarily for namespace reasons.
- */
-class ZipUtils {
-public:
- /*
- * General utility function for uncompressing "deflate" data from a file
- * to a buffer.
- */
- static bool inflateToBuffer(int fd, void* buf, long uncompressedLen,
- long compressedLen);
- static bool inflateToBuffer(FILE* fp, void* buf, long uncompressedLen,
- long compressedLen);
-
- /*
- * Someday we might want to make this generic and handle bzip2 ".bz2"
- * files too.
- *
- * We could declare gzip to be a sub-class of zip that has exactly
- * one always-compressed entry, but we currently want to treat Zip
- * and gzip as distinct, so there's no value.
- *
- * The zlib library has some gzip utilities, but it has no interface
- * for extracting the uncompressed length of the file (you do *not*
- * want to gzseek to the end).
- *
- * Pass in a seeked file pointer for the gzip file. If this is a gzip
- * file, we set our return values appropriately and return "true" with
- * the file seeked to the start of the compressed data.
- */
- static bool examineGzip(FILE* fp, int* pCompressionMethod,
- long* pUncompressedLen, long* pCompressedLen, unsigned long* pCRC32);
-
-private:
- ZipUtils() {}
- ~ZipUtils() {}
-};
-
-}; // namespace android
-
-#endif /*__LIBS_ZIPUTILS_H*/
diff --git a/include/utils/misc.h b/include/utils/misc.h
index f1aa432..6cccec3 100644
--- a/include/utils/misc.h
+++ b/include/utils/misc.h
@@ -20,7 +20,6 @@
#ifndef _LIBS_UTILS_MISC_H
#define _LIBS_UTILS_MISC_H
-#include <sys/time.h>
#include <utils/Endian.h>
/* get #of elements in a static array */
@@ -30,26 +29,6 @@
namespace android {
-/*
- * Some utility functions for working with files. These could be made
- * part of a "File" class.
- */
-typedef enum FileType {
- kFileTypeUnknown = 0,
- kFileTypeNonexistent, // i.e. ENOENT
- kFileTypeRegular,
- kFileTypeDirectory,
- kFileTypeCharDev,
- kFileTypeBlockDev,
- kFileTypeFifo,
- kFileTypeSymlink,
- kFileTypeSocket,
-} FileType;
-/* get the file's type; follows symlinks */
-FileType getFileType(const char* fileName);
-/* get the file's modification date; returns -1 w/errno set on failure */
-time_t getFileModDate(const char* fileName);
-
typedef void (*sysprop_change_callback)(void);
void add_sysprop_change_callback(sysprop_change_callback cb, int priority);
void report_sysprop_change();