summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/widget/ListView.java8
-rw-r--r--core/java/android/widget/RelativeLayout.java44
-rw-r--r--include/ui/Camera.h7
-rw-r--r--libs/utils/BackupHelpers.cpp100
-rw-r--r--packages/TtsService/jni/android_tts_SynthProxy.cpp14
-rwxr-xr-xpackages/TtsService/src/android/tts/TtsService.java42
6 files changed, 156 insertions, 59 deletions
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index 6532125d2b0a..f8a6f89a9880 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -3264,9 +3264,13 @@ public class ListView extends AbsListView {
if (mChoiceMode == CHOICE_MODE_MULTIPLE) {
mCheckStates.put(position, value);
} else {
- boolean oldValue = mCheckStates.get(position, false);
+ // Clear the old value: if something was selected and value == false
+ // then it is unselected
mCheckStates.clear();
- if (!oldValue) {
+ // If value == true, select the appropriate position
+ // this may end up selecting the value we just cleared but this way
+ // we don't have to first to a get(position)
+ if (value) {
mCheckStates.put(position, true);
}
}
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java
index 68dafa134d66..b2aa57420969 100644
--- a/core/java/android/widget/RelativeLayout.java
+++ b/core/java/android/widget/RelativeLayout.java
@@ -40,7 +40,6 @@ import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.LinkedList;
-import java.util.ArrayList;
import java.util.HashSet;
/**
@@ -279,6 +278,17 @@ public class RelativeLayout extends ViewGroup {
graph.getSortedViews(mSortedVerticalChildren, ABOVE, BELOW, ALIGN_BASELINE,
ALIGN_TOP, ALIGN_BOTTOM);
graph.getSortedViews(mSortedHorizontalChildren, LEFT_OF, RIGHT_OF, ALIGN_LEFT, ALIGN_RIGHT);
+
+ if (DEBUG_GRAPH) {
+ d(LOG_TAG, "=== Ordered list of vertical children");
+ for (View view : mSortedVerticalChildren) {
+ DependencyGraph.printViewId(getResources(), view);
+ }
+ d(LOG_TAG, "=== Ordered list of horizontal children");
+ for (View view : mSortedHorizontalChildren) {
+ DependencyGraph.printViewId(getResources(), view);
+ }
+ }
}
@Override
@@ -333,7 +343,6 @@ public class RelativeLayout extends ViewGroup {
ignore = findViewById(mIgnoreGravity);
}
-
View[] views = mSortedVerticalChildren;
int count = views.length;
for (int i = 0; i < count; i++) {
@@ -755,7 +764,7 @@ public class RelativeLayout extends ViewGroup {
private View getRelatedView(int[] rules, int relation) {
int id = rules[relation];
if (id != 0) {
- View v = findViewById(id);
+ View v = mGraph.mNodes.get(id).view;
if (v == null) {
return null;
}
@@ -763,7 +772,7 @@ public class RelativeLayout extends ViewGroup {
// Find the first non-GONE view up the chain
while (v.getVisibility() == View.GONE) {
rules = ((LayoutParams) v.getLayoutParams()).getRules();
- v = v.findViewById(rules[relation]);
+ v = mGraph.mNodes.get((rules[relation])).view;
if (v == null) {
return null;
}
@@ -1100,12 +1109,6 @@ public class RelativeLayout extends ViewGroup {
private static class DependencyGraph {
/**
- * List of views with no id. These views cannot be dependencies of
- * other views, so treat the apart for faster processing.
- */
- private ArrayList<View> mNakedRoots = new ArrayList<View>();
-
- /**
* List of nodes in the graph. Each node is identified by its
* view id (see View#getId()).
*/
@@ -1129,7 +1132,6 @@ public class RelativeLayout extends ViewGroup {
}
nodes.clear();
- mNakedRoots.clear();
mRoots.clear();
}
@@ -1139,13 +1141,7 @@ public class RelativeLayout extends ViewGroup {
* @param view The view to be added as a node to the graph.
*/
void add(View view) {
- final int id = view.getId();
-
- if (id != View.NO_ID) {
- mNodes.put(id, Node.acquire(view));
- } else {
- mNakedRoots.add(view);
- }
+ mNodes.put(view.getId(), Node.acquire(view));
}
/**
@@ -1162,12 +1158,6 @@ public class RelativeLayout extends ViewGroup {
final LinkedList<Node> roots = findRoots(rules);
int index = 0;
- final ArrayList<View> nakedRoots = mNakedRoots;
- final int count = nakedRoots.size();
- for ( ; index < count; index++) {
- sorted[index] = nakedRoots.get(index);
- }
-
while (roots.size() > 0) {
final Node node = roots.removeFirst();
final View view = node.view;
@@ -1259,17 +1249,13 @@ public class RelativeLayout extends ViewGroup {
* @param rules The list of rules to take into account.
*/
void log(Resources resources, int... rules) {
- for (View view : mNakedRoots) {
- printViewId(resources, view);
- }
-
final LinkedList<Node> roots = findRoots(rules);
for (Node node : roots) {
printNode(resources, node);
}
}
- private static void printViewId(Resources resources, View view) {
+ static void printViewId(Resources resources, View view) {
if (view.getId() != View.NO_ID) {
d(LOG_TAG, resources.getResourceEntryName(view.getId()));
} else {
diff --git a/include/ui/Camera.h b/include/ui/Camera.h
index 564a1db4b5dd..bbc21c4910dc 100644
--- a/include/ui/Camera.h
+++ b/include/ui/Camera.h
@@ -94,11 +94,6 @@ public:
virtual void postData(int32_t msgType, const sp<IMemory>& dataPtr) = 0;
};
-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);
-
class Camera : public BnCameraClient, public IBinder::DeathRecipient
{
public:
@@ -163,6 +158,8 @@ public:
private:
Camera();
+ Camera(const Camera&);
+ Camera& operator=(const Camera);
virtual void binderDied(const wp<IBinder>& who);
class DeathNotifier: public IBinder::DeathRecipient
diff --git a/libs/utils/BackupHelpers.cpp b/libs/utils/BackupHelpers.cpp
index 67d07fed85cf..b309dbf43e94 100644
--- a/libs/utils/BackupHelpers.cpp
+++ b/libs/utils/BackupHelpers.cpp
@@ -41,6 +41,42 @@ namespace android {
#define MAGIC0 0x70616e53 // Snap
#define MAGIC1 0x656c6946 // File
+/*
+ * File entity data format (v1):
+ *
+ * - 4-byte version number of the metadata, little endian (0x00000001 for v1)
+ * - 12 bytes of metadata
+ * - the file data itself
+ *
+ * i.e. a 16-byte metadata header followed by the raw file data. If the
+ * restore code does not recognize the metadata version, it can still
+ * interpret the file data itself correctly.
+ *
+ * file_metadata_v1:
+ *
+ * - 4 byte version number === 0x00000001 (little endian)
+ * - 4-byte access mode (little-endian)
+ * - undefined (8 bytes)
+ */
+
+struct file_metadata_v1 {
+ int version;
+ int mode;
+ int undefined_1;
+ int undefined_2;
+};
+
+const static int CURRENT_METADATA_VERSION = 1;
+
+// auto-free buffer management object
+class StAutoFree {
+public:
+ StAutoFree(void* buffer) { mBuf = buffer; }
+ ~StAutoFree() { free(mBuf); }
+private:
+ void* mBuf;
+};
+
#if 1 // TEST_BACKUP_HELPERS
#define LOGP(f, x...) printf(f "\n", x)
#else
@@ -181,29 +217,48 @@ write_delete_file(BackupDataWriter* dataStream, const String8& key)
}
static int
-write_update_file(BackupDataWriter* dataStream, int fd, const String8& key,
+write_update_file(BackupDataWriter* dataStream, int fd, int mode, const String8& key,
char const* realFilename)
{
- LOGP("write_update_file %s (%s)\n", realFilename, key.string());
+ LOGP("write_update_file %s (%s) : mode 0%o\n", realFilename, key.string(), mode);
const int bufsize = 4*1024;
int err;
int amt;
int fileSize;
int bytesLeft;
+ file_metadata_v1 metadata;
char* buf = (char*)malloc(bufsize);
+ StAutoFree _autoFree(buf);
+
int crc = crc32(0L, Z_NULL, 0);
- bytesLeft = fileSize = lseek(fd, 0, SEEK_END);
+ fileSize = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
+ if (sizeof(metadata) != 16) {
+ LOGE("ERROR: metadata block is the wrong size!");
+ }
+
+ bytesLeft = fileSize + sizeof(metadata);
err = dataStream->WriteEntityHeader(key, bytesLeft);
if (err != 0) {
return err;
}
+ // store the file metadata first
+ metadata.version = tolel(CURRENT_METADATA_VERSION);
+ metadata.mode = tolel(mode);
+ metadata.undefined_1 = metadata.undefined_2 = 0;
+ err = dataStream->WriteEntityData(&metadata, sizeof(metadata));
+ if (err != 0) {
+ return err;
+ }
+ bytesLeft -= sizeof(metadata); // bytesLeft should == fileSize now
+
+ // now store the file content
while ((amt = read(fd, buf, bufsize)) != 0 && bytesLeft > 0) {
bytesLeft -= amt;
if (bytesLeft < 0) {
@@ -232,8 +287,6 @@ write_update_file(BackupDataWriter* dataStream, int fd, const String8& key,
" You aren't doing proper locking!", realFilename, fileSize, fileSize-bytesLeft);
}
- free(buf);
-
return NO_ERROR;
}
@@ -241,11 +294,19 @@ static int
write_update_file(BackupDataWriter* dataStream, const String8& key, char const* realFilename)
{
int err;
+ struct stat st;
+
+ err = stat(realFilename, &st);
+ if (err < 0) {
+ return errno;
+ }
+
int fd = open(realFilename, O_RDONLY);
if (fd == -1) {
return errno;
}
- err = write_update_file(dataStream, fd, key, realFilename);
+
+ err = write_update_file(dataStream, fd, st.st_mode, key, realFilename);
close(fd);
return err;
}
@@ -257,6 +318,8 @@ compute_crc32(int fd)
int amt;
char* buf = (char*)malloc(bufsize);
+ StAutoFree _autoFree(buf);
+
int crc = crc32(0L, Z_NULL, 0);
lseek(fd, 0, SEEK_SET);
@@ -265,8 +328,6 @@ compute_crc32(int fd)
crc = crc32(crc, (Bytef*)buf, amt);
}
- free(buf);
-
return crc;
}
@@ -356,7 +417,7 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD
g.s.modTime_sec, g.s.modTime_nsec, g.s.mode, g.s.size, g.s.crc32);
if (f.modTime_sec != g.s.modTime_sec || f.modTime_nsec != g.s.modTime_nsec
|| f.mode != g.s.mode || f.size != g.s.size || f.crc32 != g.s.crc32) {
- write_update_file(dataStream, fd, p, g.file.string());
+ write_update_file(dataStream, fd, g.s.mode, p, g.file.string());
}
close(fd);
@@ -416,8 +477,22 @@ RestoreHelperBase::WriteFile(const String8& filename, BackupDataReader* in)
return err;
}
- // TODO: World readable/writable for now.
- mode = 0666;
+ // Get the metadata block off the head of the file entity and use that to
+ // set up the output file
+ file_metadata_v1 metadata;
+ amt = in->ReadEntityData(&metadata, sizeof(metadata));
+ if (amt != sizeof(metadata)) {
+ LOGW("Could not read metadata for %s -- %ld / %s", filename.string(),
+ (long)amt, strerror(errno));
+ return EIO;
+ }
+ metadata.version = fromlel(metadata.version);
+ metadata.mode = fromlel(metadata.mode);
+ if (metadata.version > CURRENT_METADATA_VERSION) {
+ LOGW("Restoring file with unsupported metadata version %d (currently %d)",
+ metadata.version, CURRENT_METADATA_VERSION);
+ }
+ mode = metadata.mode;
// Write the file and compute the crc
crc = crc32(0L, Z_NULL, 0);
@@ -512,6 +587,7 @@ compare_file(const char* path, const unsigned char* data, int len)
fprintf(stderr, "malloc(%d) failed\n", len);
return ENOMEM;
}
+ StAutoFree _autoFree(contents);
bool sizesMatch = true;
amt = lseek(fd, 0, SEEK_END);
@@ -843,6 +919,7 @@ test_read_header_and_entity(BackupDataReader& reader, const char* str)
int err;
int bufSize = strlen(str)+1;
char* buf = (char*)malloc(bufSize);
+ StAutoFree _autoFree(buf);
String8 string;
int cookie = 0x11111111;
size_t actualSize;
@@ -904,7 +981,6 @@ finished:
if (err != NO_ERROR) {
fprintf(stderr, "test_read_header_and_entity failed with %s\n", strerror(err));
}
- free(buf);
return err;
}
diff --git a/packages/TtsService/jni/android_tts_SynthProxy.cpp b/packages/TtsService/jni/android_tts_SynthProxy.cpp
index 0aa4fa5ec8c1..0dafcc1354dd 100644
--- a/packages/TtsService/jni/android_tts_SynthProxy.cpp
+++ b/packages/TtsService/jni/android_tts_SynthProxy.cpp
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#define LOG_NDEBUG 0
#include <stdio.h>
#include <unistd.h>
@@ -168,7 +168,7 @@ void prepAudioTrack(SynthProxyJniStorage* pJniData,
static tts_callback_status ttsSynthDoneCB(void *& userdata, uint32_t rate,
AudioSystem::audio_format format, int channel,
int8_t *&wav, size_t &bufferSize, tts_synth_status status) {
- LOGI("ttsSynthDoneCallback: %d bytes", bufferSize);
+ LOGV("ttsSynthDoneCallback: %d bytes", bufferSize);
if (userdata == NULL){
LOGE("userdata == NULL");
@@ -178,7 +178,7 @@ static tts_callback_status ttsSynthDoneCB(void *& userdata, uint32_t rate,
SynthProxyJniStorage* pJniData = (SynthProxyJniStorage*)(pForAfter->jniStorage);
if (pForAfter->usageMode == USAGEMODE_PLAY_IMMEDIATELY){
- LOGI("Direct speech");
+ LOGV("Direct speech");
if (wav == NULL) {
delete pForAfter;
@@ -189,16 +189,16 @@ static tts_callback_status ttsSynthDoneCB(void *& userdata, uint32_t rate,
prepAudioTrack(pJniData, rate, format, channel);
if (pJniData->mAudioOut) {
pJniData->mAudioOut->write(wav, bufferSize);
- LOGI("AudioTrack wrote: %d bytes", bufferSize);
+ //LOGV("AudioTrack wrote: %d bytes", bufferSize);
} else {
- LOGI("Can't play, null audiotrack");
+ LOGE("Can't play, null audiotrack");
}
}
} else if (pForAfter->usageMode == USAGEMODE_WRITE_TO_FILE) {
- LOGI("Save to file");
+ LOGV("Save to file");
if (wav == NULL) {
delete pForAfter;
- LOGI("Null: speech has completed");
+ LOGV("Null: speech has completed");
}
if (bufferSize > 0){
fwrite(wav, 1, bufferSize, pForAfter->outputFile);
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java
index 21f56f853623..a6a2dd3ac08a 100755
--- a/packages/TtsService/src/android/tts/TtsService.java
+++ b/packages/TtsService/src/android/tts/TtsService.java
@@ -170,6 +170,39 @@ public class TtsService extends Service implements OnCompletionListener {
}
+ private String getDefaultLanguage() {
+ String defaultLang = android.provider.Settings.Secure.getString(mResolver,
+ android.provider.Settings.Secure.TTS_DEFAULT_LANG);
+ if (defaultLang == null) {
+ return TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_LANG;
+ } else {
+ return defaultLang;
+ }
+ }
+
+
+ private String getDefaultCountry() {
+ String defaultCountry = android.provider.Settings.Secure.getString(mResolver,
+ android.provider.Settings.Secure.TTS_DEFAULT_COUNTRY);
+ if (defaultCountry == null) {
+ return TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_COUNTRY;
+ } else {
+ return defaultCountry;
+ }
+ }
+
+
+ private String getDefaultLocVariant() {
+ String defaultVar = android.provider.Settings.Secure.getString(mResolver,
+ android.provider.Settings.Secure.TTS_DEFAULT_VARIANT);
+ if (defaultVar == null) {
+ return TextToSpeech.Engine.FALLBACK_TTS_DEFAULT_VARIANT;
+ } else {
+ return defaultVar;
+ }
+ }
+
+
private void setSpeechRate(int rate) {
if (isDefaultEnforced()) {
nativeSynth.setSpeechRate(getDefaultRate());
@@ -185,15 +218,16 @@ public class TtsService extends Service implements OnCompletionListener {
private void setLanguage(String lang, String country, String variant) {
- Log.v("TTS", "TtsService.setLanguage("+lang+", "+country+", "+variant+")");
+ Log.v("TTS", "TtsService.setLanguage(" + lang + ", " + country + ", " + variant + ")");
if (isDefaultEnforced()) {
- nativeSynth.setLanguage(lang, country, variant);
+ nativeSynth.setLanguage(getDefaultLanguage(), getDefaultCountry(),
+ getDefaultLocVariant());
} else {
- // TODO handle default language
- nativeSynth.setLanguage("eng", "USA", "");
+ nativeSynth.setLanguage(lang, country, variant);
}
}
+
/**
* Adds a sound resource to the TTS.
*