summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/private/opengles/gl_context.h3
-rw-r--r--include/tts/TtsEngine.h239
-rw-r--r--include/ui/Camera.h71
-rw-r--r--include/ui/CameraHardwareInterface.h2
-rw-r--r--include/ui/ICameraClient.h12
-rw-r--r--include/ui/Point.h21
-rw-r--r--include/ui/Rect.h40
-rw-r--r--include/utils/Asset.h12
-rw-r--r--include/utils/AssetManager.h23
-rw-r--r--include/utils/BackupHelpers.h158
-rw-r--r--include/utils/ByteOrder.h32
-rw-r--r--include/utils/Parcel.h18
-rw-r--r--include/utils/ResourceTypes.h397
-rw-r--r--include/utils/String8.h116
-rw-r--r--include/utils/TimeUtils.h89
-rw-r--r--include/utils/threads.h7
16 files changed, 940 insertions, 300 deletions
diff --git a/include/private/opengles/gl_context.h b/include/private/opengles/gl_context.h
index 0c7ad46..e32e332 100644
--- a/include/private/opengles/gl_context.h
+++ b/include/private/opengles/gl_context.h
@@ -285,6 +285,7 @@ struct light_t {
vec4_t normalizedObjPosition;
vec4_t spotDir;
vec4_t normalizedSpotDir;
+ vec4_t objViewer;
GLfixed spotExp;
GLfixed spotCutoff;
GLfixed spotCutoffCosine;
@@ -456,7 +457,7 @@ struct matrix_stack_t {
void validate();
matrixf_t& top() { return stack[depth]; }
const matrixf_t& top() const { return stack[depth]; }
- const uint32_t top_ops() const { return ops[depth]; }
+ uint32_t top_ops() const { return ops[depth]; }
inline bool isRigidBody() const {
return !(ops[depth] & ~(OP_TRANSLATE|OP_UNIFORM_SCALE|OP_ROTATE));
}
diff --git a/include/tts/TtsEngine.h b/include/tts/TtsEngine.h
new file mode 100644
index 0000000..ed084ca
--- /dev/null
+++ b/include/tts/TtsEngine.h
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) 2009 Google Inc.
+ *
+ * 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.
+ */
+#include <media/AudioSystem.h>
+
+// This header defines the interface used by the Android platform
+// to access Text-To-Speech functionality in shared libraries that implement
+// speech synthesis and the management of resources associated with the
+// synthesis.
+// An example of the implementation of this interface can be found in
+// FIXME: add path+name to implementation of default TTS engine
+// Libraries implementing this interface are used in:
+// frameworks/base/tts/jni/android_tts_SpeechSynthesis.cpp
+
+namespace android {
+
+enum tts_synth_status {
+ TTS_SYNTH_DONE = 0,
+ TTS_SYNTH_PENDING = 1
+};
+
+enum tts_callback_status {
+ TTS_CALLBACK_HALT = 0,
+ TTS_CALLBACK_CONTINUE = 1
+};
+
+// The callback is used by the implementation of this interface to notify its
+// client, the Android TTS service, that the last requested synthesis has been
+// completed. // TODO reword
+// The callback for synthesis completed takes:
+// @param [inout] void *& - The userdata pointer set in the original
+// synth call
+// @param [in] uint32_t - Track sampling rate in Hz
+// @param [in] audio_format - The AudioSystem::audio_format enum
+// @param [in] int - The number of channels
+// @param [inout] int8_t *& - A buffer of audio data only valid during the
+// execution of the callback
+// @param [inout] size_t & - The size of the buffer
+// @param [in] tts_synth_status - indicate whether the synthesis is done, or
+// if more data is to be synthesized.
+// @return TTS_CALLBACK_HALT to indicate the synthesis must stop,
+// TTS_CALLBACK_CONTINUE to indicate the synthesis must continue if
+// there is more data to produce.
+typedef tts_callback_status (synthDoneCB_t)(void *&, uint32_t,
+ AudioSystem::audio_format, int, int8_t *&, size_t&, tts_synth_status);
+
+class TtsEngine;
+extern "C" TtsEngine* getTtsEngine();
+
+enum tts_result {
+ TTS_SUCCESS = 0,
+ TTS_FAILURE = -1,
+ TTS_FEATURE_UNSUPPORTED = -2,
+ TTS_VALUE_INVALID = -3,
+ TTS_PROPERTY_UNSUPPORTED = -4,
+ TTS_PROPERTY_SIZE_TOO_SMALL = -5,
+ TTS_MISSING_RESOURCES = -6
+};
+
+enum tts_support_result {
+ TTS_LANG_COUNTRY_VAR_AVAILABLE = 2,
+ TTS_LANG_COUNTRY_AVAILABLE = 1,
+ TTS_LANG_AVAILABLE = 0,
+ TTS_LANG_MISSING_DATA = -1,
+ TTS_LANG_NOT_SUPPORTED = -2
+};
+
+class TtsEngine
+{
+public:
+ virtual ~TtsEngine() {}
+
+ // Initialize the TTS engine and returns whether initialization succeeded.
+ // @param synthDoneCBPtr synthesis callback function pointer
+ // @return TTS_SUCCESS, or TTS_FAILURE
+ virtual tts_result init(synthDoneCB_t synthDoneCBPtr);
+
+ // Shut down the TTS engine and releases all associated resources.
+ // @return TTS_SUCCESS, or TTS_FAILURE
+ virtual tts_result shutdown();
+
+ // Interrupt synthesis and flushes any synthesized data that hasn't been
+ // output yet. This will block until callbacks underway are completed.
+ // @return TTS_SUCCESS, or TTS_FAILURE
+ virtual tts_result stop();
+
+ // Returns the level of support for the language, country and variant.
+ // @return TTS_LANG_COUNTRY_VAR_AVAILABLE if the language, country and variant are supported,
+ // and the corresponding resources are correctly installed
+ // TTS_LANG_COUNTRY_AVAILABLE if the language and country are supported and the
+ // corresponding resources are correctly installed, but there is no match for
+ // the specified variant
+ // TTS_LANG_AVAILABLE if the language is supported and the
+ // corresponding resources are correctly installed, but there is no match for
+ // the specified country and variant
+ // TTS_LANG_MISSING_DATA if the required resources to provide any level of support
+ // for the language are not correctly installed
+ // TTS_LANG_NOT_SUPPORTED if the language is not supported by the TTS engine.
+ virtual tts_support_result isLanguageAvailable(const char *lang, const char *country,
+ const char *variant);
+
+ // Load the resources associated with the specified language. The loaded
+ // language will only be used once a call to setLanguage() with the same
+ // language value is issued. Language and country values are coded according to the ISO three
+ // letter codes for languages and countries, as can be retrieved from a java.util.Locale
+ // instance. The variant value is encoded as the variant string retrieved from a
+ // java.util.Locale instance built with that variant data.
+ // @param lang pointer to the ISO three letter code for the language
+ // @param country pointer to the ISO three letter code for the country
+ // @param variant pointer to the variant code
+ // @return TTS_SUCCESS, or TTS_FAILURE
+ virtual tts_result loadLanguage(const char *lang, const char *country, const char *variant);
+
+ // Load the resources associated with the specified language, country and Locale variant.
+ // The loaded language will only be used once a call to setLanguageFromLocale() with the same
+ // language value is issued. Language and country values are coded according to the ISO three
+ // letter codes for languages and countries, as can be retrieved from a java.util.Locale
+ // instance. The variant value is encoded as the variant string retrieved from a
+ // java.util.Locale instance built with that variant data.
+ // @param lang pointer to the ISO three letter code for the language
+ // @param country pointer to the ISO three letter code for the country
+ // @param variant pointer to the variant code
+ // @return TTS_SUCCESS, or TTS_FAILURE
+ virtual tts_result setLanguage(const char *lang, const char *country, const char *variant);
+
+ // Retrieve the currently set language, country and variant, or empty strings if none of
+ // parameters have been set. Language and country are represented by their 3-letter ISO code
+ // @param[out] pointer to the retrieved 3-letter code language value
+ // @param[out] pointer to the retrieved 3-letter code country value
+ // @param[out] pointer to the retrieved variant value
+ // @return TTS_SUCCESS, or TTS_FAILURE
+ virtual tts_result getLanguage(char *language, char *country, char *variant);
+
+ // Notifies the engine what audio parameters should be used for the synthesis.
+ // This is meant to be used as a hint, the engine implementation will set the output values
+ // to those of the synthesis format, based on a given hint.
+ // @param[inout] encoding in: the desired audio sample format
+ // out: the format used by the TTS engine
+ // @param[inout] rate in: the desired audio sample rate
+ // out: the sample rate used by the TTS engine
+ // @param[inout] channels in: the desired number of audio channels
+ // out: the number of channels used by the TTS engine
+ // @return TTS_SUCCESS, or TTS_FAILURE
+ virtual tts_result setAudioFormat(AudioSystem::audio_format& encoding, uint32_t& rate,
+ int& channels);
+
+ // Set a property for the the TTS engine
+ // "size" is the maximum size of "value" for properties "property"
+ // @param property pointer to the property name
+ // @param value pointer to the property value
+ // @param size maximum size required to store this type of property
+ // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS, or TTS_FAILURE,
+ // or TTS_VALUE_INVALID
+ virtual tts_result setProperty(const char *property, const char *value,
+ const size_t size);
+
+ // Retrieve a property from the TTS engine
+ // @param property pointer to the property name
+ // @param[out] value pointer to the retrieved language value
+ // @param[inout] iosize in: stores the size available to store the
+ // property value.
+ // out: stores the size required to hold the language
+ // value if getLanguage() returned
+ // TTS_PROPERTY_SIZE_TOO_SMALL, unchanged otherwise
+ // @return TTS_PROPERTY_UNSUPPORTED, or TTS_SUCCESS,
+ // or TTS_PROPERTY_SIZE_TOO_SMALL
+ virtual tts_result getProperty(const char *property, char *value,
+ size_t *iosize);
+
+ // Synthesize the text.
+ // As the synthesis is performed, the engine invokes the callback to notify
+ // the TTS framework that it has filled the given buffer, and indicates how
+ // many bytes it wrote. The callback is called repeatedly until the engine
+ // has generated all the audio data corresponding to the text.
+ // Note about the format of the input: the text parameter may use the
+ // following elements
+ // and their respective attributes as defined in the SSML 1.0 specification:
+ // * lang
+ // * say-as:
+ // o interpret-as
+ // * phoneme
+ // * voice:
+ // o gender,
+ // o age,
+ // o variant,
+ // o name
+ // * emphasis
+ // * break:
+ // o strength,
+ // o time
+ // * prosody:
+ // o pitch,
+ // o contour,
+ // o range,
+ // o rate,
+ // o duration,
+ // o volume
+ // * mark
+ // Differences between this text format and SSML are:
+ // * full SSML documents are not supported
+ // * namespaces are not supported
+ // Text is coded in UTF-8.
+ // @param text the UTF-8 text to synthesize
+ // @param userdata pointer to be returned when the call is invoked
+ // @param buffer the location where the synthesized data must be written
+ // @param bufferSize the number of bytes that can be written in buffer
+ // @return TTS_SUCCESS or TTS_FAILURE
+ virtual tts_result synthesizeText(const char *text, int8_t *buffer,
+ size_t bufferSize, void *userdata);
+
+ // Synthesize IPA text.
+ // As the synthesis is performed, the engine invokes the callback to notify
+ // the TTS framework that it has filled the given buffer, and indicates how
+ // many bytes it wrote. The callback is called repeatedly until the engine
+ // has generated all the audio data corresponding to the IPA data.
+ // @param ipa the IPA data to synthesize
+ // @param userdata pointer to be returned when the call is invoked
+ // @param buffer the location where the synthesized data must be written
+ // @param bufferSize the number of bytes that can be written in buffer
+ // @return TTS_FEATURE_UNSUPPORTED if IPA is not supported,
+ // otherwise TTS_SUCCESS or TTS_FAILURE
+ virtual tts_result synthesizeIpa(const char *ipa, int8_t *buffer,
+ size_t bufferSize, void *userdata);
+};
+
+} // namespace android
+
diff --git a/include/ui/Camera.h b/include/ui/Camera.h
index e593fea..afb07b5 100644
--- a/include/ui/Camera.h
+++ b/include/ui/Camera.h
@@ -18,6 +18,7 @@
#ifndef ANDROID_HARDWARE_CAMERA_H
#define ANDROID_HARDWARE_CAMERA_H
+#include <utils/Timers.h>
#include <ui/ICameraClient.h>
namespace android {
@@ -63,23 +64,45 @@ namespace android {
#define FRAME_CALLBACK_FLAG_CAMERA 0x05
#define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07
+// msgType in notifyCallback and dataCallback functions
+enum {
+ CAMERA_MSG_ERROR = 0,
+ CAMERA_MSG_SHUTTER,
+ CAMERA_MSG_FOCUS,
+ CAMERA_MSG_ZOOM,
+ CAMERA_MSG_PREVIEW_FRAME,
+ CAMERA_MSG_VIDEO_FRAME,
+ CAMERA_MSG_POSTVIEW_FRAME,
+ CAMERA_MSG_RAW_IMAGE,
+ CAMERA_MSG_COMPRESSED_IMAGE
+};
+
+// camera fatal errors
+enum {
+ CAMERA_ERROR_UKNOWN = 1,
+ CAMERA_ERROR_SERVER_DIED = 100
+};
+
class ICameraService;
class ICamera;
class Surface;
class Mutex;
class String8;
-typedef void (*shutter_callback)(void *cookie);
-typedef void (*frame_callback)(const sp<IMemory>& mem, void *cookie);
-typedef void (*autofocus_callback)(bool focused, void *cookie);
-typedef void (*error_callback)(status_t err, void *cookie);
+// ref-counted object for callbacks
+class CameraListener: virtual public RefBase
+{
+public:
+ virtual void notify(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
+ virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr) = 0;
+ virtual void postDataTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr) = 0;
+};
class Camera : public BnCameraClient, public IBinder::DeathRecipient
{
public:
// construct a camera client from an existing remote
- Camera(const sp<ICamera>& camera);
-
+ static sp<Camera> create(const sp<ICamera>& camera);
static sp<Camera> connect();
~Camera();
void init();
@@ -128,27 +151,20 @@ public:
// get preview/capture parameters - key/value pairs
String8 getParameters() const;
- void setShutterCallback(shutter_callback cb, void *cookie);
- void setRawCallback(frame_callback cb, void *cookie);
- void setJpegCallback(frame_callback cb, void *cookie);
- void setRecordingCallback(frame_callback cb, void *cookie);
- void setPreviewCallback(frame_callback cb, void *cookie, int preview_callback_flag = FRAME_CALLBACK_FLAG_NOOP);
- void setErrorCallback(error_callback cb, void *cookie);
- void setAutoFocusCallback(autofocus_callback cb, void *cookie);
+ void setListener(const sp<CameraListener>& listener);
+ void setPreviewCallbackFlags(int preview_callback_flag);
// ICameraClient interface
- virtual void shutterCallback();
- virtual void rawCallback(const sp<IMemory>& picture);
- virtual void jpegCallback(const sp<IMemory>& picture);
- virtual void previewCallback(const sp<IMemory>& frame);
- virtual void errorCallback(status_t error);
- virtual void autoFocusCallback(bool focused);
- virtual void recordingCallback(const sp<IMemory>& frame);
+ virtual void notifyCallback(int32_t msgType, int32_t ext, int32_t ext2);
+ virtual void dataCallback(int32_t msgType, const sp<IMemory>& dataPtr);
+ virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& dataPtr);
sp<ICamera> remote();
private:
Camera();
+ Camera(const Camera&);
+ Camera& operator=(const Camera);
virtual void binderDied(const wp<IBinder>& who);
class DeathNotifier: public IBinder::DeathRecipient
@@ -168,20 +184,7 @@ private:
sp<ICamera> mCamera;
status_t mStatus;
- shutter_callback mShutterCallback;
- void *mShutterCallbackCookie;
- frame_callback mRawCallback;
- void *mRawCallbackCookie;
- frame_callback mJpegCallback;
- void *mJpegCallbackCookie;
- frame_callback mPreviewCallback;
- void *mPreviewCallbackCookie;
- frame_callback mRecordingCallback;
- void *mRecordingCallbackCookie;
- error_callback mErrorCallback;
- void *mErrorCallbackCookie;
- autofocus_callback mAutoFocusCallback;
- void *mAutoFocusCallbackCookie;
+ sp<CameraListener> mListener;
friend class DeathNotifier;
diff --git a/include/ui/CameraHardwareInterface.h b/include/ui/CameraHardwareInterface.h
index 73036f0..822b4a8 100644
--- a/include/ui/CameraHardwareInterface.h
+++ b/include/ui/CameraHardwareInterface.h
@@ -28,7 +28,7 @@ namespace android {
typedef void (*preview_callback)(const sp<IMemory>& mem, void* user);
/** Callback for startRecord() */
-typedef void (*recording_callback)(const sp<IMemory>& mem, void* user);
+typedef void (*recording_callback)(nsecs_t timestamp, const sp<IMemory>& mem, void* user);
/** Callback for takePicture() */
typedef void (*shutter_callback)(void* user);
diff --git a/include/ui/ICameraClient.h b/include/ui/ICameraClient.h
index 73b951c..1001c71 100644
--- a/include/ui/ICameraClient.h
+++ b/include/ui/ICameraClient.h
@@ -21,6 +21,7 @@
#include <utils/IInterface.h>
#include <utils/Parcel.h>
#include <utils/IMemory.h>
+#include <utils/Timers.h>
namespace android {
@@ -29,14 +30,9 @@ class ICameraClient: public IInterface
public:
DECLARE_META_INTERFACE(CameraClient);
- virtual void shutterCallback() = 0;
- virtual void rawCallback(const sp<IMemory>& picture) = 0;
- virtual void jpegCallback(const sp<IMemory>& picture) = 0;
- virtual void previewCallback(const sp<IMemory>& frame) = 0;
- virtual void errorCallback(status_t error) = 0;
- virtual void autoFocusCallback(bool focused) = 0;
- virtual void recordingCallback(const sp<IMemory>& frame) = 0;
-
+ virtual void notifyCallback(int32_t msgType, int32_t ext1, int32_t ext2) = 0;
+ virtual void dataCallback(int32_t msgType, const sp<IMemory>& data) = 0;
+ virtual void dataCallbackTimestamp(nsecs_t timestamp, int32_t msgType, const sp<IMemory>& data) = 0;
};
// ----------------------------------------------------------------------------
diff --git a/include/ui/Point.h b/include/ui/Point.h
index dbbad1e..1653120 100644
--- a/include/ui/Point.h
+++ b/include/ui/Point.h
@@ -31,12 +31,9 @@ public:
// because we want the compiler generated versions
// Default constructor doesn't initialize the Point
- inline Point()
- {
+ inline Point() {
}
-
- inline Point(int _x, int _y) : x(_x), y(_y)
- {
+ inline Point(int x, int y) : x(x), y(y) {
}
inline bool operator == (const Point& rhs) const {
@@ -57,8 +54,8 @@ public:
}
inline Point& operator - () {
- x=-x;
- y=-y;
+ x = -x;
+ y = -y;
return *this;
}
@@ -73,11 +70,13 @@ public:
return *this;
}
- Point operator + (const Point& rhs) const {
- return Point(x+rhs.x, y+rhs.y);
+ const Point operator + (const Point& rhs) const {
+ const Point result(x+rhs.x, y+rhs.y);
+ return result;
}
- Point operator - (const Point& rhs) const {
- return Point(x-rhs.x, y-rhs.y);
+ const Point operator - (const Point& rhs) const {
+ const Point result(x-rhs.x, y-rhs.y);
+ return result;
}
};
diff --git a/include/ui/Rect.h b/include/ui/Rect.h
index d232847..da72944 100644
--- a/include/ui/Rect.h
+++ b/include/ui/Rect.h
@@ -33,23 +33,16 @@ public:
// we don't provide copy-ctor and operator= on purpose
// because we want the compiler generated versions
- inline Rect()
- {
+ inline Rect() {
}
-
inline Rect(int w, int h)
- : left(0), top(0), right(w), bottom(h)
- {
+ : left(0), top(0), right(w), bottom(h) {
}
-
inline Rect(int l, int t, int r, int b)
- : left(l), top(t), right(r), bottom(b)
- {
+ : left(l), top(t), right(r), bottom(b) {
}
-
inline Rect(const Point& lt, const Point& rb)
- : left(lt.x), top(lt.y), right(rb.x), bottom(rb.y)
- {
+ : left(lt.x), top(lt.y), right(rb.x), bottom(rb.y) {
}
void makeInvalid();
@@ -78,21 +71,22 @@ public:
return bottom-top;
}
- // returns left-top Point non-const reference, can be assigned
- inline Point& leftTop() {
- return reinterpret_cast<Point&>(left);
+ void setLeftTop(const Point& lt) {
+ left = lt.x;
+ top = lt.y;
}
- // returns right bottom non-const reference, can be assigned
- inline Point& rightBottom() {
- return reinterpret_cast<Point&>(right);
+
+ void setRightBottom(const Point& rb) {
+ right = rb.x;
+ bottom = rb.y;
}
// the following 4 functions return the 4 corners of the rect as Point
- inline const Point& leftTop() const {
- return reinterpret_cast<const Point&>(left);
+ Point leftTop() const {
+ return Point(left, top);
}
- inline const Point& rightBottom() const {
- return reinterpret_cast<const Point&>(right);
+ Point rightBottom() const {
+ return Point(right, bottom);
}
Point rightTop() const {
return Point(right, top);
@@ -133,8 +127,8 @@ public:
Rect& operator -= (const Point& rhs) {
return offsetBy(-rhs.x, -rhs.y);
}
- Rect operator + (const Point& rhs) const;
- Rect operator - (const Point& rhs) const;
+ const Rect operator + (const Point& rhs) const;
+ const Rect operator - (const Point& rhs) const;
void translate(int dx, int dy) { // legacy, don't use.
offsetBy(dx, dy);
diff --git a/include/utils/Asset.h b/include/utils/Asset.h
index 453a204..5908bcc 100644
--- a/include/utils/Asset.h
+++ b/include/utils/Asset.h
@@ -45,6 +45,7 @@ public:
virtual ~Asset(void);
static int32_t getGlobalCount();
+ static String8 getAssetAllocations();
/* used when opening an asset */
typedef enum AccessMode {
@@ -110,6 +111,12 @@ public:
virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const = 0;
/*
+ * Return whether this asset's buffer is allocated in RAM (not mmapped).
+ * Note: not virtual so it is safe to call even when being destroyed.
+ */
+ virtual bool isAllocated(void) const { return false; }
+
+ /*
* Get a string identifying the asset's source. This might be a full
* path, it might be a colon-separated list of identifiers.
*
@@ -197,6 +204,9 @@ private:
AccessMode mAccessMode; // how the asset was opened
String8 mAssetSource; // debug string
+
+ Asset* mNext; // linked list.
+ Asset* mPrev;
};
@@ -239,6 +249,7 @@ public:
virtual off_t getLength(void) const { return mLength; }
virtual off_t getRemainingLength(void) const { return mLength-mOffset; }
virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const;
+ virtual bool isAllocated(void) const { return mBuf != NULL; }
private:
off_t mStart; // absolute file offset of start of chunk
@@ -295,6 +306,7 @@ public:
virtual off_t getLength(void) const { return mUncompressedLen; }
virtual off_t getRemainingLength(void) const { return mUncompressedLen-mOffset; }
virtual int openFileDescriptor(off_t* outStart, off_t* outLength) const { return -1; }
+ virtual bool isAllocated(void) const { return mBuf != NULL; }
private:
off_t mStart; // offset to start of compressed data
diff --git a/include/utils/AssetManager.h b/include/utils/AssetManager.h
index e94c0e8..d8994e0 100644
--- a/include/utils/AssetManager.h
+++ b/include/utils/AssetManager.h
@@ -153,6 +153,18 @@ public:
AssetDir* openDir(const char* dirName);
/*
+ * Open a directory within a particular path of the asset manager.
+ *
+ * The contents of the directory are an amalgam of vendor-specific,
+ * locale-specific, and generic assets stored loosely or in asset
+ * packages. Depending on the cache setting and previous accesses,
+ * this call may incur significant disk overhead.
+ *
+ * To open the top-level directory, pass in "".
+ */
+ AssetDir* openNonAssetDir(void* cookie, const char* dirName);
+
+ /*
* Get the type of a file in the asset hierarchy. They will either
* be "regular" or "directory". [Currently only works for "regular".]
*
@@ -239,6 +251,9 @@ private:
Asset* getResourceTableAsset();
Asset* setResourceTableAsset(Asset* asset);
+ ResTable* getResourceTable();
+ ResTable* setResourceTable(ResTable* res);
+
bool isUpToDate();
protected:
@@ -253,6 +268,7 @@ private:
time_t mModWhen;
Asset* mResourceTableAsset;
+ ResTable* mResourceTable;
static Mutex gLock;
static DefaultKeyedVector<String8, wp<SharedZip> > gOpen;
@@ -276,8 +292,11 @@ private:
*/
ZipFileRO* getZip(const String8& path);
- Asset* getZipResourceTable(const String8& path);
- Asset* setZipResourceTable(const String8& path, Asset* asset);
+ Asset* getZipResourceTableAsset(const String8& path);
+ Asset* setZipResourceTableAsset(const String8& path, Asset* asset);
+
+ ResTable* getZipResourceTable(const String8& path);
+ ResTable* setZipResourceTable(const String8& path, ResTable* res);
// generate path, e.g. "common/en-US-noogle.zip"
static String8 getPathName(const char* path);
diff --git a/include/utils/BackupHelpers.h b/include/utils/BackupHelpers.h
new file mode 100644
index 0000000..b1f5045
--- /dev/null
+++ b/include/utils/BackupHelpers.h
@@ -0,0 +1,158 @@
+/*
+ * 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.
+ */
+
+#ifndef _UTILS_BACKUP_HELPERS_H
+#define _UTILS_BACKUP_HELPERS_H
+
+#include <utils/Errors.h>
+#include <utils/String8.h>
+#include <utils/KeyedVector.h>
+
+namespace android {
+
+enum {
+ BACKUP_HEADER_ENTITY_V1 = 0x61746144, // Data (little endian)
+};
+
+typedef struct {
+ int type; // BACKUP_HEADER_ENTITY_V1
+ int keyLen; // length of the key name, not including the null terminator
+ int dataSize; // size of the data, not including the padding, -1 means delete
+} entity_header_v1;
+
+struct SnapshotHeader {
+ int magic0;
+ int fileCount;
+ int magic1;
+ int totalSize;
+};
+
+struct FileState {
+ int modTime_sec;
+ int modTime_nsec;
+ int mode;
+ int size;
+ int crc32;
+ int nameLen;
+};
+
+struct FileRec {
+ String8 file;
+ bool deleted;
+ FileState s;
+};
+
+
+/**
+ * Writes the data.
+ *
+ * If an error occurs, it poisons this object and all write calls will fail
+ * with the error that occurred.
+ */
+class BackupDataWriter
+{
+public:
+ BackupDataWriter(int fd);
+ // does not close fd
+ ~BackupDataWriter();
+
+ status_t WriteEntityHeader(const String8& key, size_t dataSize);
+ status_t WriteEntityData(const void* data, size_t size);
+
+ void SetKeyPrefix(const String8& keyPrefix);
+
+private:
+ explicit BackupDataWriter();
+ status_t write_padding_for(int n);
+
+ int m_fd;
+ status_t m_status;
+ ssize_t m_pos;
+ int m_entityCount;
+ String8 m_keyPrefix;
+};
+
+/**
+ * Reads the data.
+ *
+ * If an error occurs, it poisons this object and all write calls will fail
+ * with the error that occurred.
+ */
+class BackupDataReader
+{
+public:
+ BackupDataReader(int fd);
+ // does not close fd
+ ~BackupDataReader();
+
+ status_t Status();
+ status_t ReadNextHeader(bool* done, int* type);
+
+ bool HasEntities();
+ status_t ReadEntityHeader(String8* key, size_t* dataSize);
+ status_t SkipEntityData(); // must be called with the pointer at the begining of the data.
+ ssize_t ReadEntityData(void* data, size_t size);
+
+private:
+ explicit BackupDataReader();
+ status_t skip_padding();
+
+ int m_fd;
+ bool m_done;
+ status_t m_status;
+ ssize_t m_pos;
+ ssize_t m_dataEndPos;
+ int m_entityCount;
+ union {
+ int type;
+ entity_header_v1 entity;
+ } m_header;
+ String8 m_key;
+};
+
+int back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD,
+ char const* const* files, char const* const *keys, int fileCount);
+
+class RestoreHelperBase
+{
+public:
+ RestoreHelperBase();
+ ~RestoreHelperBase();
+
+ status_t WriteFile(const String8& filename, BackupDataReader* in);
+ status_t WriteSnapshot(int fd);
+
+private:
+ void* m_buf;
+ bool m_loggedUnknownMetadata;
+ KeyedVector<String8,FileRec> m_files;
+};
+
+#define TEST_BACKUP_HELPERS 1
+
+#if TEST_BACKUP_HELPERS
+int backup_helper_test_empty();
+int backup_helper_test_four();
+int backup_helper_test_files();
+int backup_helper_test_null_base();
+int backup_helper_test_missing_file();
+int backup_helper_test_data_writer();
+int backup_helper_test_data_reader();
+#endif
+
+} // namespace android
+
+#endif // _UTILS_BACKUP_HELPERS_H
diff --git a/include/utils/ByteOrder.h b/include/utils/ByteOrder.h
index 4c06067..baa3a83 100644
--- a/include/utils/ByteOrder.h
+++ b/include/utils/ByteOrder.h
@@ -38,6 +38,16 @@
* intent is to allow us to avoid byte swapping on the device.
*/
+static inline uint32_t android_swap_long(uint32_t v)
+{
+ return (v<<24) | ((v<<8)&0x00FF0000) | ((v>>8)&0x0000FF00) | (v>>24);
+}
+
+static inline uint16_t android_swap_short(uint16_t v)
+{
+ return (v<<8) | (v>>8);
+}
+
#define DEVICE_BYTE_ORDER LITTLE_ENDIAN
#if BYTE_ORDER == DEVICE_BYTE_ORDER
@@ -49,16 +59,6 @@
#else
-static inline uint32_t android_swap_long(uint32_t v)
-{
- return (v<<24) | ((v<<8)&0x00FF0000) | ((v>>8)&0x0000FF00) | (v>>24);
-}
-
-static inline uint16_t android_swap_short(uint16_t v)
-{
- return (v<<8) | (v>>8);
-}
-
#define dtohl(x) (android_swap_long(x))
#define dtohs(x) (android_swap_short(x))
#define htodl(x) (android_swap_long(x))
@@ -66,4 +66,16 @@ static inline uint16_t android_swap_short(uint16_t v)
#endif
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define fromlel(x) (x)
+#define fromles(x) (x)
+#define tolel(x) (x)
+#define toles(x) (x)
+#else
+#define fromlel(x) (android_swap_long(x))
+#define fromles(x) (android_swap_short(x))
+#define tolel(x) (android_swap_long(x))
+#define toles(x) (android_swap_short(x))
+#endif
+
#endif // _LIBS_UTILS_BYTE_ORDER_H
diff --git a/include/utils/Parcel.h b/include/utils/Parcel.h
index 9087c44..af1490a 100644
--- a/include/utils/Parcel.h
+++ b/include/utils/Parcel.h
@@ -80,8 +80,11 @@ public:
status_t writeStrongBinder(const sp<IBinder>& val);
status_t writeWeakBinder(const wp<IBinder>& val);
- // doesn't take ownership of the native_handle
- status_t writeNativeHandle(const native_handle& handle);
+ // Place a native_handle into the parcel (the native_handle's file-
+ // descriptors are dup'ed, so it is safe to delete the native_handle
+ // when this function returns).
+ // Doesn't take ownership of the native_handle.
+ status_t writeNativeHandle(const native_handle* handle);
// Place a file descriptor into the parcel. The given fd must remain
// valid for the lifetime of the parcel.
@@ -114,12 +117,11 @@ public:
wp<IBinder> readWeakBinder() const;
- // if alloc is NULL, native_handle is allocated with malloc(), otherwise
- // alloc is used. If the function fails, the effects of alloc() must be
- // reverted by the caller.
- native_handle* readNativeHandle(
- native_handle* (*alloc)(void* cookie, int numFds, int ints),
- void* cookie) const;
+ // Retrieve native_handle from the parcel. This returns a copy of the
+ // parcel's native_handle (the caller takes ownership). The caller
+ // must free the native_handle with native_handle_close() and
+ // native_handle_delete().
+ native_handle* readNativeHandle() const;
// Retrieve a file descriptor from the parcel. This returns the raw fd
diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h
index d01d83f..e524e2a 100644
--- a/include/utils/ResourceTypes.h
+++ b/include/utils/ResourceTypes.h
@@ -71,7 +71,7 @@ namespace android {
* The relative sizes of the stretchy segments indicates the relative
* amount of stretchiness of the regions bordered by the segments. For
* example, regions 3, 7 and 11 above will take up more horizontal space
- * than regions 1, 5 and 9 since the horizonal segment associated with
+ * than regions 1, 5 and 9 since the horizontal segment associated with
* the first set of regions is larger than the other set of regions. The
* ratios of the amount of horizontal (or vertical) space taken by any
* two stretchable slices is exactly the ratio of their corresponding
@@ -87,7 +87,7 @@ namespace android {
* the leftmost slices always start at x=0 and the rightmost slices
* always end at the end of the image. So, for example, the regions 0,
* 4 and 8 (which are fixed along the X axis) start at x value 0 and
- * go to xDiv[0] amd slices 2, 6 and 10 start at xDiv[1] and end at
+ * go to xDiv[0] and slices 2, 6 and 10 start at xDiv[1] and end at
* xDiv[2].
*
* The array pointed to by the colors field lists contains hints for
@@ -626,25 +626,25 @@ public:
event_code_t next();
// These are available for all nodes:
- const int32_t getCommentID() const;
+ int32_t getCommentID() const;
const uint16_t* getComment(size_t* outLen) const;
- const uint32_t getLineNumber() const;
+ uint32_t getLineNumber() const;
// This is available for TEXT:
- const int32_t getTextID() const;
+ int32_t getTextID() const;
const uint16_t* getText(size_t* outLen) const;
ssize_t getTextValue(Res_value* outValue) const;
// These are available for START_NAMESPACE and END_NAMESPACE:
- const int32_t getNamespacePrefixID() const;
+ int32_t getNamespacePrefixID() const;
const uint16_t* getNamespacePrefix(size_t* outLen) const;
- const int32_t getNamespaceUriID() const;
+ int32_t getNamespaceUriID() const;
const uint16_t* getNamespaceUri(size_t* outLen) const;
// These are available for START_TAG and END_TAG:
- const int32_t getElementNamespaceID() const;
+ int32_t getElementNamespaceID() const;
const uint16_t* getElementNamespace(size_t* outLen) const;
- const int32_t getElementNameID() const;
+ int32_t getElementNameID() const;
const uint16_t* getElementName(size_t* outLen) const;
// Remaining methods are for retrieving information about attributes
@@ -653,14 +653,14 @@ public:
size_t getAttributeCount() const;
// Returns -1 if no namespace, -2 if idx out of range.
- const int32_t getAttributeNamespaceID(size_t idx) const;
+ int32_t getAttributeNamespaceID(size_t idx) const;
const uint16_t* getAttributeNamespace(size_t idx, size_t* outLen) const;
- const int32_t getAttributeNameID(size_t idx) const;
+ int32_t getAttributeNameID(size_t idx) const;
const uint16_t* getAttributeName(size_t idx, size_t* outLen) const;
- const uint32_t getAttributeNameResID(size_t idx) const;
+ uint32_t getAttributeNameResID(size_t idx) const;
- const int32_t getAttributeValueStringID(size_t idx) const;
+ int32_t getAttributeValueStringID(size_t idx) const;
const uint16_t* getAttributeStringValue(size_t idx, size_t* outLen) const;
int32_t getAttributeDataType(size_t idx) const;
@@ -825,7 +825,11 @@ struct ResTable_config
};
enum {
- DENSITY_ANY = 0
+ DENSITY_DEFAULT = 0,
+ DENSITY_LOW = 120,
+ DENSITY_MEDIUM = 160,
+ DENSITY_HIGH = 240,
+ DENSITY_NONE = 0xffff
};
union {
@@ -854,7 +858,6 @@ struct ResTable_config
enum {
MASK_KEYSHIDDEN = 0x0003,
- SHIFT_KEYSHIDDEN = 0,
KEYSHIDDEN_ANY = 0x0000,
KEYSHIDDEN_NO = 0x0001,
KEYSHIDDEN_YES = 0x0002,
@@ -866,7 +869,7 @@ struct ResTable_config
uint8_t keyboard;
uint8_t navigation;
uint8_t inputFlags;
- uint8_t pad0;
+ uint8_t inputPad0;
};
uint32_t input;
};
@@ -905,6 +908,31 @@ struct ResTable_config
uint32_t version;
};
+ enum {
+ // screenLayout bits for screen size class.
+ MASK_SCREENSIZE = 0x0f,
+ SCREENSIZE_ANY = 0x00,
+ SCREENSIZE_SMALL = 0x01,
+ SCREENSIZE_NORMAL = 0x02,
+ SCREENSIZE_LARGE = 0x03,
+
+ // screenLayout bits for wide/long screen variation.
+ MASK_SCREENLONG = 0x30,
+ SCREENLONG_ANY = 0x00,
+ SCREENLONG_NO = 0x10,
+ SCREENLONG_YES = 0x20,
+ };
+
+ union {
+ struct {
+ uint8_t screenLayout;
+ uint8_t screenConfigPad0;
+ uint8_t screenConfigPad1;
+ uint8_t screenConfigPad2;
+ };
+ uint32_t screenConfig;
+ };
+
inline void copyFromDeviceNoSwap(const ResTable_config& o) {
const size_t size = dtohl(o.size);
if (size >= sizeof(ResTable_config)) {
@@ -950,6 +978,8 @@ struct ResTable_config
diff = (int32_t)(screenSize - o.screenSize);
if (diff != 0) return diff;
diff = (int32_t)(version - o.version);
+ if (diff != 0) return diff;
+ diff = (int32_t)(screenLayout - o.screenLayout);
return (int)diff;
}
@@ -967,7 +997,8 @@ struct ResTable_config
CONFIG_ORIENTATION = 0x0080,
CONFIG_DENSITY = 0x0100,
CONFIG_SCREEN_SIZE = 0x0200,
- CONFIG_VERSION = 0x0400
+ CONFIG_VERSION = 0x0400,
+ CONFIG_SCREEN_LAYOUT = 0x0800
};
// Compare two configuration, returning CONFIG_* flags set for each value
@@ -985,122 +1016,251 @@ struct ResTable_config
if (navigation != o.navigation) diffs |= CONFIG_NAVIGATION;
if (screenSize != o.screenSize) diffs |= CONFIG_SCREEN_SIZE;
if (version != o.version) diffs |= CONFIG_VERSION;
+ if (screenLayout != o.screenLayout) diffs |= CONFIG_SCREEN_LAYOUT;
return diffs;
}
- // 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.
+ // Return true if 'this' is more specific than 'o'.
inline bool
- isBetterThan(const ResTable_config& o, const ResTable_config* requested = NULL) const {
+ isMoreSpecificThan(const ResTable_config& o) 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 (o.mcc == 0) {
- return true;
- }
+ if (imsi || o.imsi) {
+ if (mcc != o.mcc) {
+ if (!mcc) return false;
+ if (!o.mcc) return true;
}
- if (mnc != 0 && (!requested || requested->mnc != 0)) {
- if (o.mnc == 0) {
- return true;
- }
+
+ if (mnc != o.mnc) {
+ if (!mnc) return false;
+ if (!o.mnc) return true;
}
}
- if (locale != 0 && (!requested || requested->locale != 0)) {
- if (language[0] != 0 && (!requested || requested->language[0] != 0)) {
- if (o.language[0] == 0) {
- return true;
- }
+
+ if (locale || o.locale) {
+ if (language[0] != o.language[0]) {
+ if (!language[0]) return false;
+ if (!o.language[0]) return true;
}
- if (country[0] != 0 && (!requested || requested->country[0] != 0)) {
- if (o.country[0] == 0) {
- return true;
- }
+
+ if (country[0] != o.country[0]) {
+ if (!country[0]) return false;
+ if (!o.country[0]) return true;
}
}
- if (screenType != 0 && (!requested || requested->screenType != 0)) {
- if (orientation != 0 && (!requested || requested->orientation != 0)) {
- if (o.orientation == 0) {
- return true;
- }
+
+ if (screenConfig || o.screenConfig) {
+ if (((screenLayout^o.screenLayout) & MASK_SCREENSIZE) != 0) {
+ if (!(screenLayout & MASK_SCREENSIZE)) return false;
+ if (!(o.screenLayout & MASK_SCREENSIZE)) return true;
}
- if (density != 0 && (!requested || requested->density != 0)) {
- if (o.density == 0) {
- return true;
- }
+ if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0) {
+ if (!(screenLayout & MASK_SCREENLONG)) return false;
+ if (!(o.screenLayout & MASK_SCREENLONG)) return true;
}
- if (touchscreen != 0 && (!requested || requested->touchscreen != 0)) {
- if (o.touchscreen == 0) {
- return true;
- }
+ }
+
+ if (screenType || o.screenType) {
+ if (orientation != o.orientation) {
+ if (!orientation) return false;
+ if (!o.orientation) return true;
+ }
+
+ // density is never 'more specific'
+ // as the default just equals 160
+
+ if (touchscreen != o.touchscreen) {
+ if (!touchscreen) return false;
+ if (!o.touchscreen) return true;
}
}
- if (input != 0 && (!requested || requested->input != 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;
+
+ if (input || o.input) {
+ if (((inputFlags^o.inputFlags) & MASK_KEYSHIDDEN) != 0) {
+ if (!(inputFlags & MASK_KEYSHIDDEN)) return false;
+ if (!(o.inputFlags & MASK_KEYSHIDDEN)) return true;
+ }
+
+ if (keyboard != o.keyboard) {
+ if (!keyboard) return false;
+ if (!o.keyboard) return true;
+ }
+
+ if (navigation != o.navigation) {
+ if (!navigation) return false;
+ if (!o.navigation) return true;
+ }
+ }
+
+ if (screenSize || o.screenSize) {
+ if (screenWidth != o.screenWidth) {
+ if (!screenWidth) return false;
+ if (!o.screenWidth) return true;
+ }
+
+ if (screenHeight != o.screenHeight) {
+ if (!screenHeight) return false;
+ if (!o.screenHeight) return true;
+ }
+ }
+
+ if (version || o.version) {
+ if (sdkVersion != o.sdkVersion) {
+ if (!sdkVersion) return false;
+ if (!o.sdkVersion) return true;
+ }
+
+ if (minorVersion != o.minorVersion) {
+ if (!minorVersion) return false;
+ if (!o.minorVersion) return true;
+ }
+ }
+ return false;
+ }
+
+ // Return true if 'this' is a better match than 'o' for the 'requested'
+ // 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.
+ // The general rule per attribute: if the request cares about an attribute
+ // (it normally does), if the two (this and o) are equal it's a tie. If
+ // they are not equal then one must be generic because only generic and
+ // '==requested' will pass the match() call. So if this is not generic,
+ // it wins. If this IS generic, o wins (return false).
+ inline bool
+ isBetterThan(const ResTable_config& o,
+ const ResTable_config* requested) const {
+ if (requested) {
+ if (imsi || o.imsi) {
+ if ((mcc != o.mcc) && requested->mcc) {
+ return (mcc);
}
- // 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;
+
+ if ((mnc != o.mnc) && requested->mnc) {
+ return (mnc);
}
}
- if (keyboard != 0 && (!requested || requested->keyboard != 0)) {
- if (o.keyboard == 0) {
- return true;
+
+ if (locale || o.locale) {
+ if ((language[0] != o.language[0]) && requested->language[0]) {
+ return (language[0]);
+ }
+
+ if ((country[0] != o.country[0]) && requested->country[0]) {
+ return (country[0]);
}
}
- if (navigation != 0 && (!requested || requested->navigation != 0)) {
- if (o.navigation == 0) {
- return true;
+
+ if (screenConfig || o.screenConfig) {
+ if (((screenLayout^o.screenLayout) & MASK_SCREENSIZE) != 0
+ && (requested->screenLayout & MASK_SCREENSIZE)) {
+ return (screenLayout & MASK_SCREENSIZE);
+ }
+ if (((screenLayout^o.screenLayout) & MASK_SCREENLONG) != 0
+ && (requested->screenLayout & MASK_SCREENLONG)) {
+ return (screenLayout & MASK_SCREENLONG);
}
}
- }
- if (screenSize != 0 && (!requested || requested->screenSize != 0)) {
- if (screenWidth != 0 && (!requested || requested->screenWidth != 0)) {
- if (o.screenWidth == 0) {
- return true;
+
+ if (screenType || o.screenType) {
+ if ((orientation != o.orientation) && requested->orientation) {
+ return (orientation);
+ }
+
+ if (density != o.density) {
+ // density is tough. Any density is potentially useful
+ // because the system will scale it. Scaling down
+ // is generally better than scaling up.
+ // Default density counts as 160dpi (the system default)
+ // TODO - remove 160 constants
+ int h = (density?density:160);
+ int l = (o.density?o.density:160);
+ bool bImBigger = true;
+ if (l > h) {
+ int t = h;
+ h = l;
+ l = t;
+ bImBigger = false;
+ }
+
+ int reqValue = (requested->density?requested->density:160);
+ if (reqValue >= h) {
+ // requested value higher than both l and h, give h
+ return bImBigger;
+ }
+ if (l >= reqValue) {
+ // requested value lower than both l and h, give l
+ return !bImBigger;
+ }
+ // saying that scaling down is 2x better than up
+ if (((2 * l) - reqValue) * h > reqValue * reqValue) {
+ return !bImBigger;
+ } else {
+ return bImBigger;
+ }
+ }
+
+ if ((touchscreen != o.touchscreen) && requested->touchscreen) {
+ return (touchscreen);
}
}
- if (screenHeight != 0 && (!requested || requested->screenHeight != 0)) {
- if (o.screenHeight == 0) {
- return true;
+
+ if (input || o.input) {
+ const int keysHidden = inputFlags & MASK_KEYSHIDDEN;
+ const int oKeysHidden = o.inputFlags & MASK_KEYSHIDDEN;
+ if (keysHidden != oKeysHidden) {
+ const int reqKeysHidden =
+ requested->inputFlags & MASK_KEYSHIDDEN;
+ if (reqKeysHidden) {
+
+ if (!keysHidden) return false;
+ if (!oKeysHidden) return true;
+ // For compatibility, we count KEYSHIDDEN_NO as being
+ // the same as KEYSHIDDEN_SOFT. Here we disambiguate
+ // these by making an exact match more specific.
+ if (reqKeysHidden == keysHidden) return true;
+ if (reqKeysHidden == oKeysHidden) return false;
+ }
+ }
+
+ if ((keyboard != o.keyboard) && requested->keyboard) {
+ return (keyboard);
+ }
+
+ if ((navigation != o.navigation) && requested->navigation) {
+ return (navigation);
}
}
- }
- if (version != 0 && (!requested || requested->version != 0)) {
- if (sdkVersion != 0 && (!requested || requested->sdkVersion != 0)) {
- if (o.sdkVersion == 0) {
- return true;
+
+ if (screenSize || o.screenSize) {
+ if ((screenWidth != o.screenWidth) && requested->screenWidth) {
+ return (screenWidth);
+ }
+
+ if ((screenHeight != o.screenHeight) &&
+ requested->screenHeight) {
+ return (screenHeight);
}
}
- if (minorVersion != 0 && (!requested || requested->minorVersion != 0)) {
- if (o.minorVersion == 0) {
- return true;
+
+ if (version || o.version) {
+ if ((sdkVersion != o.sdkVersion) && requested->sdkVersion) {
+ return (sdkVersion);
+ }
+
+ if ((minorVersion != o.minorVersion) &&
+ requested->minorVersion) {
+ return (minorVersion);
}
}
+
+ return false;
}
- return false;
+ return isMoreSpecificThan(o);
}
-
+
// Return true if 'this' can be considered a match for the parameters in
// 'settings'.
// Note this is asymetric. A default piece of data will match every request
@@ -1132,13 +1292,27 @@ struct ResTable_config
return false;
}
}
+ if (screenConfig != 0) {
+ const int screenSize = screenLayout&MASK_SCREENSIZE;
+ const int setScreenSize = settings.screenLayout&MASK_SCREENSIZE;
+ if (setScreenSize != 0 && screenSize != 0
+ && screenSize != setScreenSize) {
+ return false;
+ }
+
+ const int screenLong = screenLayout&MASK_SCREENLONG;
+ const int setScreenLong = settings.screenLayout&MASK_SCREENLONG;
+ if (setScreenLong != 0 && screenLong != 0
+ && screenLong != setScreenLong) {
+ return false;
+ }
+ }
if (screenType != 0) {
if (settings.orientation != 0 && orientation != 0
&& orientation != settings.orientation) {
return false;
}
- // Density not taken into account, always match, no matter what
- // density is specified for the resource
+ // density always matches - we can scale it. See isBetterThan
if (settings.touchscreen != 0 && touchscreen != 0
&& touchscreen != settings.touchscreen) {
return false;
@@ -1205,13 +1379,15 @@ struct ResTable_config
String8 toString() const {
char buf[200];
- sprintf(buf, "imsi=%d/%d lang=%c%c reg=%c%c orient=0x%02x touch=0x%02x dens=0x%02x "
- "kbd=0x%02x nav=0x%02x input=0x%02x screenW=0x%04x screenH=0x%04x vers=%d.%d",
+ sprintf(buf, "imsi=%d/%d lang=%c%c reg=%c%c orient=%d touch=%d dens=%d "
+ "kbd=%d nav=%d input=%d scrnW=%d scrnH=%d sz=%d long=%d vers=%d.%d",
mcc, mnc,
language[0] ? language[0] : '-', language[1] ? language[1] : '-',
country[0] ? country[0] : '-', country[1] ? country[1] : '-',
orientation, touchscreen, density, keyboard, navigation, inputFlags,
- screenWidth, screenHeight, sdkVersion, minorVersion);
+ screenWidth, screenHeight,
+ screenLayout&MASK_SCREENSIZE, screenLayout&MASK_SCREENLONG,
+ sdkVersion, minorVersion);
return String8(buf);
}
};
@@ -1296,7 +1472,7 @@ struct ResTable_type
* This is the beginning of information about an entry in the resource
* table. It holds the reference to the name of this entry, and is
* immediately followed by one of:
- * * A Res_value structures, if FLAG_COMPLEX is -not- set.
+ * * A Res_value structure, if FLAG_COMPLEX is -not- set.
* * An array of ResTable_map structures, if FLAG_COMPLEX is set.
* These supply a set of name/value mappings of data.
*/
@@ -1435,6 +1611,7 @@ public:
bool copyData=false);
status_t add(Asset* asset, void* cookie,
bool copyData=false);
+ status_t add(ResTable* src);
status_t getError() const;
@@ -1478,7 +1655,8 @@ public:
ssize_t resolveReference(Res_value* inOutValue,
ssize_t blockIndex,
uint32_t* outLastRef = NULL,
- uint32_t* inoutTypeSpecFlags = NULL) const;
+ uint32_t* inoutTypeSpecFlags = NULL,
+ ResTable_config* outConfig = NULL) const;
enum {
TMP_BUFFER_SIZE = 16
@@ -1552,7 +1730,8 @@ public:
*/
ssize_t resolveAttributeReference(Res_value* inOutValue,
ssize_t blockIndex, uint32_t* outLastRef = NULL,
- uint32_t* inoutTypeSpecFlags = NULL) const;
+ uint32_t* inoutTypeSpecFlags = NULL,
+ ResTable_config* inoutConfig = NULL) const;
void dumpToLog() const;
@@ -1676,7 +1855,7 @@ public:
void getLocales(Vector<String8>* locales) const;
#ifndef HAVE_ANDROID_OS
- void print() const;
+ void print(bool inclValues) const;
#endif
private:
@@ -1698,6 +1877,8 @@ private:
status_t parsePackage(
const ResTable_package* const pkg, const Header* const header);
+ void print_value(const Package* pkg, const Res_value& value) const;
+
mutable Mutex mLock;
status_t mError;
diff --git a/include/utils/String8.h b/include/utils/String8.h
index c49faf6..ecc5774 100644
--- a/include/utils/String8.h
+++ b/include/utils/String8.h
@@ -29,11 +29,107 @@
// ---------------------------------------------------------------------------
+extern "C" {
+
+typedef uint32_t char32_t;
+
+size_t strlen32(const char32_t *);
+size_t strnlen32(const char32_t *, size_t);
+
+/*
+ * Returns the length of "src" when "src" is valid UTF-8 string.
+ * Returns 0 if src is NULL, 0-length string or non UTF-8 string.
+ * This function should be used to determine whether "src" is valid UTF-8
+ * characters with valid unicode codepoints. "src" must be null-terminated.
+ *
+ * If you are going to use other GetUtf... functions defined in this header
+ * with string which may not be valid UTF-8 with valid codepoint (form 0 to
+ * 0x10FFFF), you should use this function before calling others, since the
+ * other functions do not check whether the string is valid UTF-8 or not.
+ *
+ * If you do not care whether "src" is valid UTF-8 or not, you should use
+ * strlen() as usual, which should be much faster.
+ */
+size_t utf8_length(const char *src);
+
+/*
+ * Returns the UTF-32 length of "src".
+ */
+size_t utf32_length(const char *src, size_t src_len);
+
+/*
+ * Returns the UTF-8 length of "src".
+ */
+size_t utf8_length_from_utf32(const char32_t *src, size_t src_len);
+
+/*
+ * Returns the unicode value at "index".
+ * Returns -1 when the index is invalid (equals to or more than "src_len").
+ * If returned value is positive, it is able to be converted to char32_t, which
+ * is unsigned. Then, if "next_index" is not NULL, the next index to be used is
+ * stored in "next_index". "next_index" can be NULL.
+ */
+int32_t utf32_at(const char *src, size_t src_len,
+ size_t index, size_t *next_index);
+
+/*
+ * Stores a UTF-32 string converted from "src" in "dst", if "dst_length" is not
+ * large enough to store the string, the part of the "src" string is stored
+ * into "dst".
+ * Returns the size actually used for storing the string.
+ * "dst" is not null-terminated when dst_len is fully used (like strncpy).
+ */
+size_t utf8_to_utf32(const char* src, size_t src_len,
+ char32_t* dst, size_t dst_len);
+
+/*
+ * Stores a UTF-8 string converted from "src" in "dst", if "dst_length" is not
+ * large enough to store the string, the part of the "src" string is stored
+ * into "dst" as much as possible. See the examples for more detail.
+ * Returns the size actually used for storing the string.
+ * dst" is not null-terminated when dst_len is fully used (like strncpy).
+ *
+ * Example 1
+ * "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84)
+ * "src_len" == 2
+ * "dst_len" >= 7
+ * ->
+ * Returned value == 6
+ * "dst" becomes \xE3\x81\x82\xE3\x81\x84\0
+ * (note that "dst" is null-terminated)
+ *
+ * Example 2
+ * "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84)
+ * "src_len" == 2
+ * "dst_len" == 5
+ * ->
+ * Returned value == 3
+ * "dst" becomes \xE3\x81\x82\0
+ * (note that "dst" is null-terminated, but \u3044 is not stored in "dst"
+ * since "dst" does not have enough size to store the character)
+ *
+ * Example 3
+ * "src" == \u3042\u3044 (\xE3\x81\x82\xE3\x81\x84)
+ * "src_len" == 2
+ * "dst_len" == 6
+ * ->
+ * Returned value == 6
+ * "dst" becomes \xE3\x81\x82\xE3\x81\x84
+ * (note that "dst" is NOT null-terminated, like strncpy)
+ */
+size_t utf32_to_utf8(const char32_t* src, size_t src_len,
+ char* dst, size_t dst_len);
+
+}
+
+// ---------------------------------------------------------------------------
+
namespace android {
class TextOutput;
-//! This is a string holding UTF-8 characters.
+//! This is a string holding UTF-8 characters. Does not allow the value more
+// than 0x10FFFF, which is not valid unicode codepoint.
class String8
{
public:
@@ -45,7 +141,8 @@ public:
explicit String8(const String16& o);
explicit String8(const char16_t* o);
explicit String8(const char16_t* o, size_t numChars);
-
+ explicit String8(const char32_t* o);
+ explicit String8(const char32_t* o, size_t numChars);
~String8();
inline const char* string() const;
@@ -59,11 +156,20 @@ public:
status_t setTo(const char* other);
status_t setTo(const char* other, size_t numChars);
status_t setTo(const char16_t* other, size_t numChars);
-
+ status_t setTo(const char32_t* other,
+ size_t length);
+
status_t append(const String8& other);
status_t append(const char* other);
status_t append(const char* other, size_t numChars);
+ // Note that this function takes O(N) time to calculate the value.
+ // No cache value is stored.
+ size_t getUtf32Length() const;
+ int32_t getUtf32At(size_t index,
+ size_t *next_index) const;
+ size_t getUtf32(char32_t* dst, size_t dst_len) const;
+
inline String8& operator=(const String8& other);
inline String8& operator=(const char* other);
@@ -103,7 +209,7 @@ public:
void toLower(size_t start, size_t numChars);
void toUpper();
void toUpper(size_t start, size_t numChars);
-
+
/*
* These methods operate on the string as if it were a path name.
*/
@@ -346,7 +452,7 @@ inline String8::operator const char*() const
return mString;
}
-}; // namespace android
+} // namespace android
// ---------------------------------------------------------------------------
diff --git a/include/utils/TimeUtils.h b/include/utils/TimeUtils.h
deleted file mode 100644
index b19e021..0000000
--- a/include/utils/TimeUtils.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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_TIME_H
-#define ANDROID_TIME_H
-
-#include <time.h>
-#include <cutils/tztime.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <utils/String8.h>
-#include <utils/String16.h>
-
-namespace android {
-
-/*
- * This class is the core implementation of the android.util.Time java
- * class. It doesn't implement some of the methods that are implemented
- * in Java. They could be done here, but it's not expected that this class
- * will be used. If that assumption is incorrect, feel free to update this
- * file. The reason to do it here is to not mix the implementation of this
- * class and the jni glue code.
- */
-class Time
-{
-public:
- struct tm t;
-
- // this object doesn't own this string
- const char *timezone;
-
- enum {
- SEC = 1,
- MIN = 2,
- HOUR = 3,
- MDAY = 4,
- MON = 5,
- YEAR = 6,
- WDAY = 7,
- YDAY = 8
- };
-
- static int compare(Time& a, Time& b);
-
- Time();
-
- void switchTimezone(const char *timezone);
- String8 format(const char *format, const struct strftime_locale *locale) const;
- void format2445(short* buf, bool hasTime) const;
- String8 toString() const;
- void setToNow();
- int64_t toMillis(bool ignoreDst);
- void set(int64_t millis);
-
- inline void set(int sec, int min, int hour, int mday, int mon, int year,
- int isdst)
- {
- this->t.tm_sec = sec;
- this->t.tm_min = min;
- this->t.tm_hour = hour;
- this->t.tm_mday = mday;
- this->t.tm_mon = mon;
- this->t.tm_year = year;
- this->t.tm_isdst = isdst;
-#ifdef HAVE_TM_GMTOFF
- this->t.tm_gmtoff = 0;
-#endif
- this->t.tm_wday = 0;
- this->t.tm_yday = 0;
- }
-};
-
-}; // namespace android
-
-#endif // ANDROID_TIME_H
diff --git a/include/utils/threads.h b/include/utils/threads.h
index 8d8d46a..b320915 100644
--- a/include/utils/threads.h
+++ b/include/utils/threads.h
@@ -79,6 +79,13 @@ enum {
ANDROID_PRIORITY_LESS_FAVORABLE = +1,
};
+enum {
+ ANDROID_TGROUP_DEFAULT = 0,
+ ANDROID_TGROUP_BG_NONINTERACT = 1,
+ ANDROID_TGROUP_FG_BOOST = 2,
+ ANDROID_TGROUP_MAX = ANDROID_TGROUP_FG_BOOST,
+};
+
// Create and run a new thread.
extern int androidCreateThread(android_thread_func_t, void *);