Merge "Remove no longer needed EventHub usleep() optimization."
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index bac3c6c..455d2f0 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -486,7 +486,6 @@
private static final String HEAP_COLUMN = "%13s %8s %8s %8s %8s %8s %8s";
private static final String ONE_COUNT_COLUMN = "%21s %8d";
private static final String TWO_COUNT_COLUMNS = "%21s %8d %21s %8d";
- private static final String TWO_COUNT_COLUMNS_DB = "%21s %8d %21s %8d";
private static final String DB_INFO_FORMAT = " %8s %8s %14s %14s %s";
// Formatting for checkin service - update version if row format changes
@@ -867,7 +866,6 @@
int binderProxyObjectCount = Debug.getBinderProxyObjectCount();
int binderDeathObjectCount = Debug.getBinderDeathObjectCount();
long openSslSocketCount = Debug.countInstancesOfClass(OpenSSLSocketImpl.class);
- long sqliteAllocated = SQLiteDebug.getHeapAllocatedSize() / 1024;
SQLiteDebug.PagerStats stats = SQLiteDebug.getDatabaseInfo();
// For checkin, we print one long comma-separated list of values
@@ -935,9 +933,9 @@
pw.print(openSslSocketCount); pw.print(',');
// SQL
- pw.print(sqliteAllocated); pw.print(',');
pw.print(stats.memoryUsed / 1024); pw.print(',');
- pw.print(stats.pageCacheOverflo / 1024); pw.print(',');
+ pw.print(stats.memoryUsed / 1024); pw.print(',');
+ pw.print(stats.pageCacheOverflow / 1024); pw.print(',');
pw.print(stats.largestMemAlloc / 1024);
for (int i = 0; i < stats.dbStats.size(); i++) {
DbStats dbStats = stats.dbStats.get(i);
@@ -1003,10 +1001,9 @@
// SQLite mem info
pw.println(" ");
pw.println(" SQL");
- printRow(pw, TWO_COUNT_COLUMNS_DB, "heap:", sqliteAllocated, "MEMORY_USED:",
- stats.memoryUsed / 1024);
- printRow(pw, TWO_COUNT_COLUMNS_DB, "PAGECACHE_OVERFLOW:",
- stats.pageCacheOverflo / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024);
+ printRow(pw, ONE_COUNT_COLUMN, "MEMORY_USED:", stats.memoryUsed / 1024);
+ printRow(pw, TWO_COUNT_COLUMNS, "PAGECACHE_OVERFLOW:",
+ stats.pageCacheOverflow / 1024, "MALLOC_SIZE:", stats.largestMemAlloc / 1024);
pw.println(" ");
int N = stats.dbStats.size();
if (N > 0) {
diff --git a/core/java/android/database/sqlite/SQLiteConnection.java b/core/java/android/database/sqlite/SQLiteConnection.java
index aeca62d..2ea936e 100644
--- a/core/java/android/database/sqlite/SQLiteConnection.java
+++ b/core/java/android/database/sqlite/SQLiteConnection.java
@@ -84,6 +84,7 @@
*/
public final class SQLiteConnection {
private static final String TAG = "SQLiteConnection";
+ private static final boolean DEBUG = false;
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
@@ -668,11 +669,12 @@
// When remove() is called, the cache will invoke its entryRemoved() callback,
// which will in turn call finalizePreparedStatement() to finalize and
// recycle the statement.
- if (SQLiteDebug.DEBUG_SQL_CACHE) {
- Log.v(TAG, "Could not reset prepared statement due to an exception. "
+ if (DEBUG) {
+ Log.d(TAG, "Could not reset prepared statement due to an exception. "
+ "Removing it from the cache. SQL: "
+ trimSqlForDisplay(statement.mSql), ex);
}
+
mPreparedStatementCache.remove(statement.mSql);
}
} else {
@@ -995,7 +997,7 @@
}
private static final class OperationLog {
- private static final int MAX_RECENT_OPERATIONS = 10;
+ private static final int MAX_RECENT_OPERATIONS = 20;
private static final int COOKIE_GENERATION_SHIFT = 8;
private static final int COOKIE_INDEX_MASK = 0xff;
diff --git a/core/java/android/database/sqlite/SQLiteCursor.java b/core/java/android/database/sqlite/SQLiteCursor.java
index 9dcb498..946300f 100644
--- a/core/java/android/database/sqlite/SQLiteCursor.java
+++ b/core/java/android/database/sqlite/SQLiteCursor.java
@@ -269,7 +269,6 @@
mStackTrace);
}
close();
- SQLiteDebug.notifyActiveCursorFinalized();
}
} finally {
super.finalize();
diff --git a/core/java/android/database/sqlite/SQLiteDebug.java b/core/java/android/database/sqlite/SQLiteDebug.java
index a64251b..3ef9b49 100644
--- a/core/java/android/database/sqlite/SQLiteDebug.java
+++ b/core/java/android/database/sqlite/SQLiteDebug.java
@@ -49,31 +49,6 @@
Log.isLoggable("SQLiteTime", Log.VERBOSE);
/**
- * Controls the printing of compiled-sql-statement cache stats.
- */
- public static final boolean DEBUG_SQL_CACHE =
- Log.isLoggable("SQLiteCompiledSql", Log.VERBOSE);
-
- /**
- * Controls the stack trace reporting of active cursors being
- * finalized.
- */
- public static final boolean DEBUG_ACTIVE_CURSOR_FINALIZATION =
- Log.isLoggable("SQLiteCursorClosing", Log.VERBOSE);
-
- /**
- * Controls the tracking of time spent holding the database lock.
- */
- public static final boolean DEBUG_LOCK_TIME_TRACKING =
- Log.isLoggable("SQLiteLockTime", Log.VERBOSE);
-
- /**
- * Controls the printing of stack traces when tracking the time spent holding the database lock.
- */
- public static final boolean DEBUG_LOCK_TIME_TRACKING_STACK_TRACE =
- Log.isLoggable("SQLiteLockStackTrace", Log.VERBOSE);
-
- /**
* True to enable database performance testing instrumentation.
* @hide
*/
@@ -101,27 +76,6 @@
* @see #getPagerStats(PagerStats)
*/
public static class PagerStats {
- /** The total number of bytes in all pagers in the current process
- * @deprecated not used any longer
- */
- @Deprecated
- public long totalBytes;
- /** The number of bytes in referenced pages in all pagers in the current process
- * @deprecated not used any longer
- * */
- @Deprecated
- public long referencedBytes;
- /** The number of bytes in all database files opened in the current process
- * @deprecated not used any longer
- */
- @Deprecated
- public long databaseBytes;
- /** The number of pagers opened in the current process
- * @deprecated not used any longer
- */
- @Deprecated
- public int numPagers;
-
/** the current amount of memory checked out by sqlite using sqlite3_malloc().
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
*/
@@ -134,7 +88,7 @@
* that overflowed because no space was left in the page cache.
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
*/
- public int pageCacheOverflo;
+ public int pageCacheOverflow;
/** records the largest memory allocation request handed to sqlite3.
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
@@ -207,43 +161,4 @@
* Gathers statistics about all pagers in the current process.
*/
public static native void getPagerStats(PagerStats stats);
-
- /**
- * Returns the size of the SQLite heap.
- * @return The size of the SQLite heap in bytes.
- */
- public static native long getHeapSize();
-
- /**
- * Returns the amount of allocated memory in the SQLite heap.
- * @return The allocated size in bytes.
- */
- public static native long getHeapAllocatedSize();
-
- /**
- * Returns the amount of free memory in the SQLite heap.
- * @return The freed size in bytes.
- */
- public static native long getHeapFreeSize();
-
- /**
- * Determines the number of dirty belonging to the SQLite
- * heap segments of this process. pages[0] returns the number of
- * shared pages, pages[1] returns the number of private pages
- */
- public static native void getHeapDirtyPages(int[] pages);
-
- private static int sNumActiveCursorsFinalized = 0;
-
- /**
- * Returns the number of active cursors that have been finalized. This depends on the GC having
- * run but is still useful for tests.
- */
- public static int getNumActiveCursorsFinalized() {
- return sNumActiveCursorsFinalized;
- }
-
- static synchronized void notifyActiveCursorFinalized() {
- sNumActiveCursorsFinalized++;
- }
}
diff --git a/core/java/android/inputmethodservice/ExtractEditText.java b/core/java/android/inputmethodservice/ExtractEditText.java
index 10c1195..23ae21b 100644
--- a/core/java/android/inputmethodservice/ExtractEditText.java
+++ b/core/java/android/inputmethodservice/ExtractEditText.java
@@ -100,6 +100,9 @@
@Override public boolean onTextContextMenuItem(int id) {
if (mIME != null && mIME.onExtractTextContextMenuItem(id)) {
+ // Mode was started on Extracted, needs to be stopped here.
+ // Cut and paste will change the text, which stops selection mode.
+ if (id == android.R.id.copy) stopSelectionActionMode();
return true;
}
return super.onTextContextMenuItem(id);
diff --git a/core/java/android/webkit/HTML5VideoFullScreen.java b/core/java/android/webkit/HTML5VideoFullScreen.java
index 21364c1a..bc0557e 100644
--- a/core/java/android/webkit/HTML5VideoFullScreen.java
+++ b/core/java/android/webkit/HTML5VideoFullScreen.java
@@ -198,6 +198,10 @@
// Call into the native to ask for the state, if still in play mode,
// this will trigger the video to play.
mProxy.dispatchOnRestoreState();
+
+ if (getStartWhenPrepared()) {
+ mPlayer.start();
+ }
}
public boolean fullScreenExited() {
diff --git a/core/java/android/webkit/HTML5VideoView.java b/core/java/android/webkit/HTML5VideoView.java
index 1d8bda7..73166cb 100644
--- a/core/java/android/webkit/HTML5VideoView.java
+++ b/core/java/android/webkit/HTML5VideoView.java
@@ -194,6 +194,25 @@
mPlayer.setOnInfoListener(proxy);
}
+ public void prepareDataCommon(HTML5VideoViewProxy proxy) {
+ try {
+ mPlayer.setDataSource(proxy.getContext(), mUri, mHeaders);
+ mPlayer.prepareAsync();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ mCurrentState = STATE_NOTPREPARED;
+ }
+
+ public void reprepareData(HTML5VideoViewProxy proxy) {
+ mPlayer.reset();
+ prepareDataCommon(proxy);
+ }
+
// Normally called immediately after setVideoURI. But for full screen,
// this should be after surface holder created
public void prepareDataAndDisplayMode(HTML5VideoViewProxy proxy) {
@@ -204,19 +223,8 @@
setOnPreparedListener(proxy);
setOnErrorListener(proxy);
setOnInfoListener(proxy);
- // When there is exception, we could just bail out silently.
- // No Video will be played though. Write the stack for debug
- try {
- mPlayer.setDataSource(mProxy.getContext(), mUri, mHeaders);
- mPlayer.prepareAsync();
- } catch (IllegalArgumentException e) {
- e.printStackTrace();
- } catch (IllegalStateException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- mCurrentState = STATE_NOTPREPARED;
+
+ prepareDataCommon(proxy);
}
@@ -324,4 +332,14 @@
return false;
}
+ private boolean m_startWhenPrepared = false;
+
+ public void setStartWhenPrepared(boolean willPlay) {
+ m_startWhenPrepared = willPlay;
+ }
+
+ public boolean getStartWhenPrepared() {
+ return m_startWhenPrepared;
+ }
+
}
diff --git a/core/java/android/webkit/HTML5VideoViewProxy.java b/core/java/android/webkit/HTML5VideoViewProxy.java
index 1c09bb9..d306c86 100644
--- a/core/java/android/webkit/HTML5VideoViewProxy.java
+++ b/core/java/android/webkit/HTML5VideoViewProxy.java
@@ -182,6 +182,21 @@
if (mHTML5VideoView != null) {
currentVideoLayerId = mHTML5VideoView.getVideoLayerId();
backFromFullScreenMode = mHTML5VideoView.fullScreenExited();
+
+ // When playing video back to back in full screen mode,
+ // javascript will switch the src and call play.
+ // In this case, we can just reuse the same full screen view,
+ // and play the video after prepared.
+ if (mHTML5VideoView.isFullScreenMode()
+ && !backFromFullScreenMode
+ && currentVideoLayerId != videoLayerId
+ && mCurrentProxy != proxy) {
+ mCurrentProxy = proxy;
+ mHTML5VideoView.setStartWhenPrepared(true);
+ mHTML5VideoView.setVideoURI(url, proxy);
+ mHTML5VideoView.reprepareData(proxy);
+ return;
+ }
}
if (backFromFullScreenMode
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 02144a8..e508e9a 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -357,7 +357,6 @@
private float mLastDownPositionX, mLastDownPositionY;
private Callback mCustomSelectionActionModeCallback;
- private final int mSquaredTouchSlopDistance;
// Set when this TextView gained focus with some text selected. Will start selection mode.
private boolean mCreatedWithASelection = false;
@@ -443,15 +442,12 @@
this(context, null);
}
- public TextView(Context context,
- AttributeSet attrs) {
+ public TextView(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.textViewStyle);
}
@SuppressWarnings("deprecation")
- public TextView(Context context,
- AttributeSet attrs,
- int defStyle) {
+ public TextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mText = "";
@@ -1134,10 +1130,6 @@
setLongClickable(longClickable);
prepareCursorControllers();
-
- final ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
- final int touchSlop = viewConfiguration.getScaledTouchSlop();
- mSquaredTouchSlopDistance = touchSlop * touchSlop;
}
private void setTypefaceByIndex(int typefaceIndex, int styleIndex) {
@@ -3202,8 +3194,7 @@
int n = mFilters.length;
for (int i = 0; i < n; i++) {
- CharSequence out = mFilters[i].filter(text, 0, text.length(),
- EMPTY_SPANNED, 0, 0);
+ CharSequence out = mFilters[i].filter(text, 0, text.length(), EMPTY_SPANNED, 0, 0);
if (out != null) {
text = out;
}
@@ -5273,10 +5264,8 @@
state.handleUpEvent(event);
}
if (event.isTracking() && !event.isCanceled()) {
- if (isInSelectionMode) {
- stopSelectionActionMode();
- return true;
- }
+ stopSelectionActionMode();
+ return true;
}
}
}
@@ -5621,11 +5610,13 @@
return super.onKeyUp(keyCode, event);
}
- @Override public boolean onCheckIsTextEditor() {
+ @Override
+ public boolean onCheckIsTextEditor() {
return mInputType != EditorInfo.TYPE_NULL;
}
- @Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
+ @Override
+ public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
if (onCheckIsTextEditor() && isEnabled()) {
if (mInputMethodState == null) {
mInputMethodState = new InputMethodState();
@@ -9248,7 +9239,6 @@
boolean vibrate = true;
if (super.performLongClick()) {
- mDiscardNextActionUp = true;
handled = true;
}
@@ -10184,7 +10174,10 @@
return false;
}
- private void stopSelectionActionMode() {
+ /**
+ * @hide
+ */
+ protected void stopSelectionActionMode() {
if (mSelectionActionMode != null) {
// This will hide the mSelectionModifierCursorController
mSelectionActionMode.finish();
@@ -10798,7 +10791,12 @@
final float deltaX = mDownPositionX - ev.getRawX();
final float deltaY = mDownPositionY - ev.getRawY();
final float distanceSquared = deltaX * deltaX + deltaY * deltaY;
- if (distanceSquared < mSquaredTouchSlopDistance) {
+
+ final ViewConfiguration viewConfiguration = ViewConfiguration.get(
+ TextView.this.getContext());
+ final int touchSlop = viewConfiguration.getScaledTouchSlop();
+
+ if (distanceSquared < touchSlop * touchSlop) {
if (mActionPopupWindow != null && mActionPopupWindow.isShowing()) {
// Tapping on the handle dismisses the displayed action popup
mActionPopupWindow.hide();
@@ -11012,7 +11010,8 @@
// Double tap detection
private long mPreviousTapUpTime = 0;
- private float mPreviousTapPositionX, mPreviousTapPositionY;
+ private float mDownPositionX, mDownPositionY;
+ private boolean mGestureStayedInTapRegion;
SelectionModifierCursorController() {
resetTouchOffsets();
@@ -11075,20 +11074,28 @@
mMinTouchOffset = mMaxTouchOffset = getOffsetForPosition(x, y);
// Double tap detection
- long duration = SystemClock.uptimeMillis() - mPreviousTapUpTime;
- if (duration <= ViewConfiguration.getDoubleTapTimeout() &&
- isPositionOnText(x, y)) {
- final float deltaX = x - mPreviousTapPositionX;
- final float deltaY = y - mPreviousTapPositionY;
- final float distanceSquared = deltaX * deltaX + deltaY * deltaY;
- if (distanceSquared < mSquaredTouchSlopDistance) {
- startSelectionActionMode();
- mDiscardNextActionUp = true;
+ if (mGestureStayedInTapRegion) {
+ long duration = SystemClock.uptimeMillis() - mPreviousTapUpTime;
+ if (duration <= ViewConfiguration.getDoubleTapTimeout()) {
+ final float deltaX = x - mDownPositionX;
+ final float deltaY = y - mDownPositionY;
+ final float distanceSquared = deltaX * deltaX + deltaY * deltaY;
+
+ ViewConfiguration viewConfiguration = ViewConfiguration.get(
+ TextView.this.getContext());
+ int doubleTapSlop = viewConfiguration.getScaledDoubleTapSlop();
+ boolean stayedInArea = distanceSquared < doubleTapSlop * doubleTapSlop;
+
+ if (stayedInArea && isPositionOnText(x, y)) {
+ startSelectionActionMode();
+ mDiscardNextActionUp = true;
+ }
}
}
- mPreviousTapPositionX = x;
- mPreviousTapPositionY = y;
+ mDownPositionX = x;
+ mDownPositionY = y;
+ mGestureStayedInTapRegion = true;
break;
case MotionEvent.ACTION_POINTER_DOWN:
@@ -11101,6 +11108,22 @@
}
break;
+ case MotionEvent.ACTION_MOVE:
+ if (mGestureStayedInTapRegion) {
+ final float deltaX = event.getX() - mDownPositionX;
+ final float deltaY = event.getY() - mDownPositionY;
+ final float distanceSquared = deltaX * deltaX + deltaY * deltaY;
+
+ final ViewConfiguration viewConfiguration = ViewConfiguration.get(
+ TextView.this.getContext());
+ int doubleTapTouchSlop = viewConfiguration.getScaledDoubleTapTouchSlop();
+
+ if (distanceSquared > doubleTapTouchSlop * doubleTapTouchSlop) {
+ mGestureStayedInTapRegion = false;
+ }
+ }
+ break;
+
case MotionEvent.ACTION_UP:
mPreviousTapUpTime = SystemClock.uptimeMillis();
break;
diff --git a/core/jni/android_database_SQLiteDebug.cpp b/core/jni/android_database_SQLiteDebug.cpp
index 20ff00b..8d4e7f9 100644
--- a/core/jni/android_database_SQLiteDebug.cpp
+++ b/core/jni/android_database_SQLiteDebug.cpp
@@ -26,13 +26,10 @@
#include <sqlite3.h>
-// From mem_mspace.c in libsqlite
-extern "C" mspace sqlite3_get_mspace();
-
namespace android {
static jfieldID gMemoryUsedField;
-static jfieldID gPageCacheOverfloField;
+static jfieldID gPageCacheOverflowField;
static jfieldID gLargestMemAllocField;
@@ -41,146 +38,18 @@
static void getPagerStats(JNIEnv *env, jobject clazz, jobject statsObj)
{
int memoryUsed;
- int pageCacheOverflo;
+ int pageCacheOverflow;
int largestMemAlloc;
int unused;
sqlite3_status(SQLITE_STATUS_MEMORY_USED, &memoryUsed, &unused, 0);
sqlite3_status(SQLITE_STATUS_MALLOC_SIZE, &unused, &largestMemAlloc, 0);
- sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflo, &unused, 0);
+ sqlite3_status(SQLITE_STATUS_PAGECACHE_OVERFLOW, &pageCacheOverflow, &unused, 0);
env->SetIntField(statsObj, gMemoryUsedField, memoryUsed);
- env->SetIntField(statsObj, gPageCacheOverfloField, pageCacheOverflo);
+ env->SetIntField(statsObj, gPageCacheOverflowField, pageCacheOverflow);
env->SetIntField(statsObj, gLargestMemAllocField, largestMemAlloc);
}
-static jlong getHeapSize(JNIEnv *env, jobject clazz)
-{
-#if !NO_MALLINFO
- struct mallinfo info = mspace_mallinfo(sqlite3_get_mspace());
- struct mallinfo info = dlmallinfo();
- return (jlong) info.usmblks;
-#elif USE_MSPACE
- mspace space = sqlite3_get_mspace();
- if (space != 0) {
- return mspace_footprint(space);
- } else {
- return 0;
- }
-#else
- return 0;
-#endif
-}
-
-static jlong getHeapAllocatedSize(JNIEnv *env, jobject clazz)
-{
-#if !NO_MALLINFO
- struct mallinfo info = mspace_mallinfo(sqlite3_get_mspace());
- return (jlong) info.uordblks;
-#else
- return sqlite3_memory_used();
-#endif
-}
-
-static jlong getHeapFreeSize(JNIEnv *env, jobject clazz)
-{
-#if !NO_MALLINFO
- struct mallinfo info = mspace_mallinfo(sqlite3_get_mspace());
- return (jlong) info.fordblks;
-#else
- return getHeapSize(env, clazz) - sqlite3_memory_used();
-#endif
-}
-
-static int read_mapinfo(FILE *fp,
- int *sharedPages, int *privatePages)
-{
- char line[1024];
- int len;
- int skip;
-
- unsigned start = 0, size = 0, resident = 0;
- unsigned shared_clean = 0, shared_dirty = 0;
- unsigned private_clean = 0, private_dirty = 0;
- unsigned referenced = 0;
-
- int isAnon = 0;
- int isHeap = 0;
-
-again:
- skip = 0;
-
- if(fgets(line, 1024, fp) == 0) return 0;
-
- len = strlen(line);
- if (len < 1) return 0;
- line[--len] = 0;
-
- /* ignore guard pages */
- if (line[18] == '-') skip = 1;
-
- start = strtoul(line, 0, 16);
-
- if (len > 50 && !strncmp(line + 49, "/tmp/sqlite-heap", strlen("/tmp/sqlite-heap"))) {
- isHeap = 1;
- }
-
- if (fgets(line, 1024, fp) == 0) return 0;
- if (sscanf(line, "Size: %d kB", &size) != 1) return 0;
- if (fgets(line, 1024, fp) == 0) return 0;
- if (sscanf(line, "Rss: %d kB", &resident) != 1) return 0;
- if (fgets(line, 1024, fp) == 0) return 0;
- if (sscanf(line, "Shared_Clean: %d kB", &shared_clean) != 1) return 0;
- if (fgets(line, 1024, fp) == 0) return 0;
- if (sscanf(line, "Shared_Dirty: %d kB", &shared_dirty) != 1) return 0;
- if (fgets(line, 1024, fp) == 0) return 0;
- if (sscanf(line, "Private_Clean: %d kB", &private_clean) != 1) return 0;
- if (fgets(line, 1024, fp) == 0) return 0;
- if (sscanf(line, "Private_Dirty: %d kB", &private_dirty) != 1) return 0;
- if (fgets(line, 1024, fp) == 0) return 0;
- if (sscanf(line, "Referenced: %d kB", &referenced) != 1) return 0;
-
- if (skip) {
- goto again;
- }
-
- if (isHeap) {
- *sharedPages += shared_dirty;
- *privatePages += private_dirty;
- }
- return 1;
-}
-
-static void load_maps(int pid, int *sharedPages, int *privatePages)
-{
- char tmp[128];
- FILE *fp;
-
- sprintf(tmp, "/proc/%d/smaps", pid);
- fp = fopen(tmp, "r");
- if (fp == 0) return;
-
- while (read_mapinfo(fp, sharedPages, privatePages) != 0) {
- // Do nothing
- }
- fclose(fp);
-}
-
-static void getHeapDirtyPages(JNIEnv *env, jobject clazz, jintArray pages)
-{
- int _pages[2];
-
- _pages[0] = 0;
- _pages[1] = 0;
-
- load_maps(getpid(), &_pages[0], &_pages[1]);
-
- // Convert from kbytes to 4K pages
- _pages[0] /= 4;
- _pages[1] /= 4;
-
- env->SetIntArrayRegion(pages, 0, 2, _pages);
-}
-
/*
* JNI registration.
*/
@@ -189,10 +58,6 @@
{
{ "getPagerStats", "(Landroid/database/sqlite/SQLiteDebug$PagerStats;)V",
(void*) getPagerStats },
- { "getHeapSize", "()J", (void*) getHeapSize },
- { "getHeapAllocatedSize", "()J", (void*) getHeapAllocatedSize },
- { "getHeapFreeSize", "()J", (void*) getHeapFreeSize },
- { "getHeapDirtyPages", "([I)V", (void*) getHeapDirtyPages },
};
int register_android_database_SQLiteDebug(JNIEnv *env)
@@ -217,9 +82,9 @@
return -1;
}
- gPageCacheOverfloField = env->GetFieldID(clazz, "pageCacheOverflo", "I");
- if (gPageCacheOverfloField == NULL) {
- ALOGE("Can't find pageCacheOverflo");
+ gPageCacheOverflowField = env->GetFieldID(clazz, "pageCacheOverflow", "I");
+ if (gPageCacheOverflowField == NULL) {
+ ALOGE("Can't find pageCacheOverflow");
return -1;
}
diff --git a/core/jni/android_media_AudioSystem.cpp b/core/jni/android_media_AudioSystem.cpp
index 8341e4c..5f61e16 100644
--- a/core/jni/android_media_AudioSystem.cpp
+++ b/core/jni/android_media_AudioSystem.cpp
@@ -28,7 +28,6 @@
#include "android_runtime/AndroidRuntime.h"
#include <media/AudioSystem.h>
-#include <media/AudioTrack.h>
#include <system/audio.h>
#include <system/audio_policy.h>
diff --git a/core/jni/android_media_AudioTrack.cpp b/core/jni/android_media_AudioTrack.cpp
index 4aa49f4..26c9435 100644
--- a/core/jni/android_media_AudioTrack.cpp
+++ b/core/jni/android_media_AudioTrack.cpp
@@ -49,14 +49,6 @@
jmethodID postNativeEventInJava; //... event post callback method
int PCM16; //... format constants
int PCM8; //... format constants
- int STREAM_VOICE_CALL; //... stream type constants
- int STREAM_SYSTEM; //... stream type constants
- int STREAM_RING; //... stream type constants
- int STREAM_MUSIC; //... stream type constants
- int STREAM_ALARM; //... stream type constants
- int STREAM_NOTIFICATION; //... stream type constants
- int STREAM_BLUETOOTH_SCO; //... stream type constants
- int STREAM_DTMF; //... stream type constants
int MODE_STREAM; //... memory mode
int MODE_STATIC; //... memory mode
jfieldID nativeTrackInJavaObj; // stores in Java the native AudioTrack object
@@ -197,23 +189,18 @@
// check the stream type
audio_stream_type_t atStreamType;
- if (streamType == javaAudioTrackFields.STREAM_VOICE_CALL) {
- atStreamType = AUDIO_STREAM_VOICE_CALL;
- } else if (streamType == javaAudioTrackFields.STREAM_SYSTEM) {
- atStreamType = AUDIO_STREAM_SYSTEM;
- } else if (streamType == javaAudioTrackFields.STREAM_RING) {
- atStreamType = AUDIO_STREAM_RING;
- } else if (streamType == javaAudioTrackFields.STREAM_MUSIC) {
- atStreamType = AUDIO_STREAM_MUSIC;
- } else if (streamType == javaAudioTrackFields.STREAM_ALARM) {
- atStreamType = AUDIO_STREAM_ALARM;
- } else if (streamType == javaAudioTrackFields.STREAM_NOTIFICATION) {
- atStreamType = AUDIO_STREAM_NOTIFICATION;
- } else if (streamType == javaAudioTrackFields.STREAM_BLUETOOTH_SCO) {
- atStreamType = AUDIO_STREAM_BLUETOOTH_SCO;
- } else if (streamType == javaAudioTrackFields.STREAM_DTMF) {
- atStreamType = AUDIO_STREAM_DTMF;
- } else {
+ switch (streamType) {
+ case AUDIO_STREAM_VOICE_CALL:
+ case AUDIO_STREAM_SYSTEM:
+ case AUDIO_STREAM_RING:
+ case AUDIO_STREAM_MUSIC:
+ case AUDIO_STREAM_ALARM:
+ case AUDIO_STREAM_NOTIFICATION:
+ case AUDIO_STREAM_BLUETOOTH_SCO:
+ case AUDIO_STREAM_DTMF:
+ atStreamType = (audio_stream_type_t) streamType;
+ break;
+ default:
ALOGE("Error creating AudioTrack: unknown stream type.");
return AUDIOTRACK_ERROR_SETUP_INVALIDSTREAMTYPE;
}
@@ -227,7 +214,7 @@
// for the moment 8bitPCM in MODE_STATIC is not supported natively in the AudioTrack C++ class
// so we declare everything as 16bitPCM, the 8->16bit conversion for MODE_STATIC will be handled
- // in android_media_AudioTrack_native_write()
+ // in android_media_AudioTrack_native_write_byte()
if ((audioFormat == javaAudioTrackFields.PCM8)
&& (memoryMode == javaAudioTrackFields.MODE_STATIC)) {
ALOGV("android_media_AudioTrack_native_setup(): requesting MODE_STATIC for 8bit \
@@ -519,13 +506,13 @@
}
// ----------------------------------------------------------------------------
-static jint android_media_AudioTrack_native_write(JNIEnv *env, jobject thiz,
+static jint android_media_AudioTrack_native_write_byte(JNIEnv *env, jobject thiz,
jbyteArray javaAudioData,
jint offsetInBytes, jint sizeInBytes,
jint javaAudioFormat) {
jbyte* cAudioData = NULL;
AudioTrack *lpTrack = NULL;
- //ALOGV("android_media_AudioTrack_native_write(offset=%d, sizeInBytes=%d) called",
+ //ALOGV("android_media_AudioTrack_native_write_byte(offset=%d, sizeInBytes=%d) called",
// offsetInBytes, sizeInBytes);
// get the audio track to load with samples
@@ -567,7 +554,7 @@
jshortArray javaAudioData,
jint offsetInShorts, jint sizeInShorts,
jint javaAudioFormat) {
- return (android_media_AudioTrack_native_write(env, thiz,
+ return (android_media_AudioTrack_native_write_byte(env, thiz,
(jbyteArray) javaAudioData,
offsetInShorts*2, sizeInShorts*2,
javaAudioFormat)
@@ -764,24 +751,20 @@
// convert the stream type from Java to native value
// FIXME: code duplication with android_media_AudioTrack_native_setup()
audio_stream_type_t nativeStreamType;
- if (javaStreamType == javaAudioTrackFields.STREAM_VOICE_CALL) {
- nativeStreamType = AUDIO_STREAM_VOICE_CALL;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_SYSTEM) {
- nativeStreamType = AUDIO_STREAM_SYSTEM;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_RING) {
- nativeStreamType = AUDIO_STREAM_RING;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_MUSIC) {
- nativeStreamType = AUDIO_STREAM_MUSIC;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_ALARM) {
- nativeStreamType = AUDIO_STREAM_ALARM;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_NOTIFICATION) {
- nativeStreamType = AUDIO_STREAM_NOTIFICATION;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_BLUETOOTH_SCO) {
- nativeStreamType = AUDIO_STREAM_BLUETOOTH_SCO;
- } else if (javaStreamType == javaAudioTrackFields.STREAM_DTMF) {
- nativeStreamType = AUDIO_STREAM_DTMF;
- } else {
+ switch (javaStreamType) {
+ case AUDIO_STREAM_VOICE_CALL:
+ case AUDIO_STREAM_SYSTEM:
+ case AUDIO_STREAM_RING:
+ case AUDIO_STREAM_MUSIC:
+ case AUDIO_STREAM_ALARM:
+ case AUDIO_STREAM_NOTIFICATION:
+ case AUDIO_STREAM_BLUETOOTH_SCO:
+ case AUDIO_STREAM_DTMF:
+ nativeStreamType = (audio_stream_type_t) javaStreamType;
+ break;
+ default:
nativeStreamType = AUDIO_STREAM_DEFAULT;
+ break;
}
if (AudioSystem::getOutputSamplingRate(&afSamplingRate, nativeStreamType) != NO_ERROR) {
@@ -851,7 +834,7 @@
(void *)android_media_AudioTrack_native_setup},
{"native_finalize", "()V", (void *)android_media_AudioTrack_native_finalize},
{"native_release", "()V", (void *)android_media_AudioTrack_native_release},
- {"native_write_byte", "([BIII)I", (void *)android_media_AudioTrack_native_write},
+ {"native_write_byte", "([BIII)I", (void *)android_media_AudioTrack_native_write_byte},
{"native_write_short", "([SIII)I", (void *)android_media_AudioTrack_native_write_short},
{"native_setVolume", "(FF)V", (void *)android_media_AudioTrack_set_volume},
{"native_get_native_frame_count",
@@ -987,41 +970,6 @@
return -1;
}
- // Get the stream types from the AudioManager class
- jclass audioManagerClass = NULL;
- audioManagerClass = env->FindClass(JAVA_AUDIOMANAGER_CLASS_NAME);
- if (audioManagerClass == NULL) {
- ALOGE("Can't find %s", JAVA_AUDIOMANAGER_CLASS_NAME);
- return -1;
- }
- if ( !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_VOICE_CALL_NAME, &(javaAudioTrackFields.STREAM_VOICE_CALL))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_MUSIC_NAME, &(javaAudioTrackFields.STREAM_MUSIC))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_SYSTEM_NAME, &(javaAudioTrackFields.STREAM_SYSTEM))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_RING_NAME, &(javaAudioTrackFields.STREAM_RING))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_ALARM_NAME, &(javaAudioTrackFields.STREAM_ALARM))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_NOTIFICATION_NAME, &(javaAudioTrackFields.STREAM_NOTIFICATION))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_BLUETOOTH_SCO_NAME, &(javaAudioTrackFields.STREAM_BLUETOOTH_SCO))
- || !android_media_getIntConstantFromClass(env, audioManagerClass,
- JAVA_AUDIOMANAGER_CLASS_NAME,
- JAVA_CONST_STREAM_DTMF_NAME, &(javaAudioTrackFields.STREAM_DTMF))) {
- // error log performed in android_media_getIntConstantFromClass()
- return -1;
- }
-
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
}
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index 84a8f1c..44925f2 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -22,7 +22,6 @@
#include <media/IAudioFlinger.h>
#include <media/IAudioRecord.h>
-#include <media/AudioTrack.h>
#include <utils/RefBase.h>
#include <utils/Errors.h>
@@ -34,6 +33,8 @@
namespace android {
+class audio_track_cblk_t;
+
// ----------------------------------------------------------------------------
class AudioRecord
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index f532d35..7379d68 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -548,6 +548,7 @@
status_t AudioSystem::setPhoneState(audio_mode_t state)
{
+ if (uint32_t(state) >= AUDIO_MODE_CNT) return BAD_VALUE;
const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
if (aps == 0) return PERMISSION_DENIED;
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index acf97a6..f1c47dd 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -30,7 +30,7 @@
#include <gui/SurfaceTextureClient.h>
#include <media/mediaplayer.h>
-#include <media/AudioTrack.h>
+#include <media/AudioSystem.h>
#include <surfaceflinger/Surface.h>
diff --git a/media/libmediaplayerservice/MediaPlayerService.h b/media/libmediaplayerservice/MediaPlayerService.h
index 6b68b87..fa71d11 100644
--- a/media/libmediaplayerservice/MediaPlayerService.h
+++ b/media/libmediaplayerservice/MediaPlayerService.h
@@ -34,6 +34,7 @@
namespace android {
+class AudioTrack;
class IMediaRecorder;
class IMediaMetadataRetriever;
class IOMX;
diff --git a/media/libmediaplayerservice/MediaRecorderClient.cpp b/media/libmediaplayerservice/MediaRecorderClient.cpp
index d219fc2..beda945 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.cpp
+++ b/media/libmediaplayerservice/MediaRecorderClient.cpp
@@ -33,8 +33,6 @@
#include <utils/String16.h>
-#include <media/AudioTrack.h>
-
#include <system/audio.h>
#include "MediaRecorderClient.h"
diff --git a/media/libmediaplayerservice/MidiFile.h b/media/libmediaplayerservice/MidiFile.h
index dfe4318..f6f8f7b 100644
--- a/media/libmediaplayerservice/MidiFile.h
+++ b/media/libmediaplayerservice/MidiFile.h
@@ -19,7 +19,6 @@
#define ANDROID_MIDIFILE_H
#include <media/MediaPlayerInterface.h>
-#include <media/AudioTrack.h>
#include <libsonivox/eas.h>
namespace android {
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index fb2a072..e2e5214 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -331,7 +331,7 @@
status_t AudioFlinger::dump(int fd, const Vector<String16>& args)
{
- if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
+ if (!checkCallingPermission(String16("android.permission.DUMP"))) {
dumpPermissionDenial(fd, args);
} else {
// get state of hardware lock
@@ -1849,7 +1849,7 @@
AudioFlinger::MixerThread::MixerThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, int id, uint32_t device)
: PlaybackThread(audioFlinger, output, id, device),
- mAudioMixer(NULL)
+ mAudioMixer(NULL), mPrevMixerStatus(MIXER_IDLE)
{
mType = ThreadBase::MIXER;
mAudioMixer = new AudioMixer(mFrameCount, mSampleRate);
@@ -1962,7 +1962,8 @@
ALOGV("MixerThread %p TID %d waking up\n", this, gettid());
acquireWakeLock_l();
- if (mMasterMute == false) {
+ mPrevMixerStatus = MIXER_IDLE;
+ if (!mMasterMute) {
char value[PROPERTY_VALUE_MAX];
property_get("ro.audio.silent", value, "0");
if (atoi(value)) {
@@ -2121,11 +2122,11 @@
// make sure that we have enough frames to mix one full buffer.
// enforce this condition only once to enable draining the buffer in case the client
// app does not call stop() and relies on underrun to stop:
- // hence the test on (track->mRetryCount >= kMaxTrackRetries) meaning the track was mixed
+ // hence the test on (mPrevMixerStatus == MIXER_TRACKS_READY) meaning the track was mixed
// during last round
uint32_t minFrames = 1;
if (!track->isStopped() && !track->isPausing() &&
- (track->mRetryCount >= kMaxTrackRetries)) {
+ (mPrevMixerStatus == MIXER_TRACKS_READY)) {
if (t->sampleRate() == (int)mSampleRate) {
minFrames = mFrameCount;
} else {
@@ -2274,7 +2275,13 @@
// reset retry count
track->mRetryCount = kMaxTrackRetries;
- mixerStatus = MIXER_TRACKS_READY;
+ // If one track is ready, set the mixer ready if:
+ // - the mixer was not ready during previous round OR
+ // - no other track is not ready
+ if (mPrevMixerStatus != MIXER_TRACKS_READY ||
+ mixerStatus != MIXER_TRACKS_ENABLED) {
+ mixerStatus = MIXER_TRACKS_READY;
+ }
} else {
//ALOGV("track %d u=%08x, s=%08x [NOT READY] on thread %p", name, cblk->user, cblk->server, this);
if (track->isStopped()) {
@@ -2292,7 +2299,11 @@
tracksToRemove->add(track);
// indicate to client process that the track was disabled because of underrun
android_atomic_or(CBLK_DISABLED_ON, &cblk->flags);
- } else if (mixerStatus != MIXER_TRACKS_READY) {
+ // If one track is not ready, mark the mixer also not ready if:
+ // - the mixer was ready during previous round OR
+ // - no other track is ready
+ } else if (mPrevMixerStatus == MIXER_TRACKS_READY ||
+ mixerStatus != MIXER_TRACKS_READY) {
mixerStatus = MIXER_TRACKS_ENABLED;
}
}
@@ -2326,6 +2337,7 @@
memset(mMixBuffer, 0, mFrameCount * mChannelCount * sizeof(int16_t));
}
+ mPrevMixerStatus = mixerStatus;
return mixerStatus;
}
@@ -2659,7 +2671,7 @@
ALOGV("DirectOutputThread %p TID %d waking up in active mode\n", this, gettid());
acquireWakeLock_l();
- if (mMasterMute == false) {
+ if (!mMasterMute) {
char value[PROPERTY_VALUE_MAX];
property_get("ro.audio.silent", value, "0");
if (atoi(value)) {
@@ -3054,7 +3066,8 @@
ALOGV("DuplicatingThread %p TID %d waking up\n", this, gettid());
acquireWakeLock_l();
- if (mMasterMute == false) {
+ mPrevMixerStatus = MIXER_IDLE;
+ if (!mMasterMute) {
char value[PROPERTY_VALUE_MAX];
property_get("ro.audio.silent", value, "0");
if (atoi(value)) {
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 275f40e..8a82bdb 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -830,7 +830,9 @@
virtual uint32_t idleSleepTimeUs();
virtual uint32_t suspendSleepTimeUs();
- AudioMixer* mAudioMixer;
+ AudioMixer* mAudioMixer;
+ uint32_t mPrevMixerStatus; // previous status (mixer_state) returned by
+ // prepareTracks_l()
};
class DirectOutputThread : public PlaybackThread {
diff --git a/services/audioflinger/AudioPolicyService.cpp b/services/audioflinger/AudioPolicyService.cpp
index fcf014f..ba9f8b0 100644
--- a/services/audioflinger/AudioPolicyService.cpp
+++ b/services/audioflinger/AudioPolicyService.cpp
@@ -43,11 +43,11 @@
namespace android {
-static const char *kDeadlockedString = "AudioPolicyService may be deadlocked\n";
-static const char *kCmdDeadlockedString = "AudioPolicyService command thread may be deadlocked\n";
+static const char kDeadlockedString[] = "AudioPolicyService may be deadlocked\n";
+static const char kCmdDeadlockedString[] = "AudioPolicyService command thread may be deadlocked\n";
static const int kDumpLockRetries = 50;
-static const int kDumpLockSleep = 20000;
+static const int kDumpLockSleepUs = 20000;
static bool checkPermission() {
if (getpid() == IPCThreadState::self()->getCallingPid()) return true;
@@ -563,7 +563,7 @@
locked = true;
break;
}
- usleep(kDumpLockSleep);
+ usleep(kDumpLockSleepUs);
}
return locked;
}
@@ -587,7 +587,7 @@
status_t AudioPolicyService::dump(int fd, const Vector<String16>& args)
{
- if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
+ if (!checkCallingPermission(String16("android.permission.DUMP"))) {
dumpPermissionDenial(fd);
} else {
bool locked = tryLock(mLock);
@@ -1069,7 +1069,7 @@
// Audio pre-processing configuration
// ----------------------------------------------------------------------------
-const char *AudioPolicyService::kInputSourceNames[AUDIO_SOURCE_CNT -1] = {
+/*static*/ const char * const AudioPolicyService::kInputSourceNames[AUDIO_SOURCE_CNT -1] = {
MIC_SRC_TAG,
VOICE_UL_SRC_TAG,
VOICE_DL_SRC_TAG,
diff --git a/services/audioflinger/AudioPolicyService.h b/services/audioflinger/AudioPolicyService.h
index 0715790..cb8c33f 100644
--- a/services/audioflinger/AudioPolicyService.h
+++ b/services/audioflinger/AudioPolicyService.h
@@ -254,7 +254,7 @@
Vector< sp<AudioEffect> >mEffects;
};
- static const char *kInputSourceNames[AUDIO_SOURCE_CNT -1];
+ static const char * const kInputSourceNames[AUDIO_SOURCE_CNT -1];
void setPreProcessorEnabled(InputDesc *inputDesc, bool enabled);
status_t loadPreProcessorConfig(const char *path);
diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
index 8e3ed93..f797836 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java
@@ -717,7 +717,7 @@
/*package*/ static void native_drawCircle(int nativeCanvas,
float cx, float cy, float radius, int paint) {
native_drawOval(nativeCanvas,
- new RectF(cx - radius, cy - radius, radius, radius),
+ new RectF(cx - radius, cy - radius, cx + radius, cy + radius),
paint);
}