Merge "Fix 5233681,5230897: Minor tweaks to lockscreen layout on tablets."
diff --git a/api/current.txt b/api/current.txt
index 70dd716..91d85a3 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -370,6 +370,7 @@
field public static final int dialogTitle = 16843250; // 0x10101f2
field public static final int digits = 16843110; // 0x1010166
field public static final int direction = 16843217; // 0x10101d1
+ field public static final int directionDescriptions = 16843695; // 0x10103af
field public static final int directionPriority = 16843218; // 0x10101d2
field public static final int disableDependentsState = 16843249; // 0x10101f1
field public static final int disabledAlpha = 16842803; // 0x1010033
@@ -938,6 +939,7 @@
field public static final int tag = 16842961; // 0x10100d1
field public static final int targetActivity = 16843266; // 0x1010202
field public static final int targetClass = 16842799; // 0x101002f
+ field public static final int targetDescriptions = 16843694; // 0x10103ae
field public static final int targetDrawables = 16843654; // 0x1010386
field public static final int targetPackage = 16842785; // 0x1010021
field public static final int targetSdkVersion = 16843376; // 0x1010270
@@ -3277,6 +3279,7 @@
method public void setArguments(android.os.Bundle);
method public void setHasOptionsMenu(boolean);
method public void setInitialSavedState(android.app.Fragment.SavedState);
+ method public void setMenuVisibility(boolean);
method public void setRetainInstance(boolean);
method public void setTargetFragment(android.app.Fragment, int);
method public void startActivity(android.content.Intent);
@@ -3342,6 +3345,7 @@
method public abstract java.lang.CharSequence getBreadCrumbTitle();
method public abstract int getBreadCrumbTitleRes();
method public abstract int getId();
+ method public abstract java.lang.String getName();
}
public static abstract interface FragmentManager.OnBackStackChangedListener {
@@ -16053,7 +16057,7 @@
public final class ContactsContract {
ctor public ContactsContract();
- field public static final java.lang.String ALLOW_PROFILE = "allow_profile";
+ method public static boolean isProfileId(long);
field public static final java.lang.String AUTHORITY = "com.android.contacts";
field public static final android.net.Uri AUTHORITY_URI;
field public static final java.lang.String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
@@ -16580,6 +16584,16 @@
field public static final android.net.Uri CONTENT_RAW_CONTACTS_URI;
field public static final android.net.Uri CONTENT_URI;
field public static final android.net.Uri CONTENT_VCARD_URI;
+ field public static final long MIN_ID = 9223372034707292160L; // 0x7fffffff80000000L
+ }
+
+ public static final class ContactsContract.ProfileSyncState implements android.provider.SyncStateContract.Columns {
+ method public static byte[] get(android.content.ContentProviderClient, android.accounts.Account) throws android.os.RemoteException;
+ method public static android.util.Pair<android.net.Uri, byte[]> getWithUri(android.content.ContentProviderClient, android.accounts.Account) throws android.os.RemoteException;
+ method public static android.content.ContentProviderOperation newSetOperation(android.accounts.Account, byte[]);
+ method public static void set(android.content.ContentProviderClient, android.accounts.Account, byte[]) throws android.os.RemoteException;
+ field public static final java.lang.String CONTENT_DIRECTORY = "syncstate";
+ field public static final android.net.Uri CONTENT_URI;
}
public static final class ContactsContract.QuickContact {
@@ -16678,6 +16692,7 @@
field public static final java.lang.String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update";
field public static final java.lang.String CONTENT_TYPE = "vnd.android.cursor.dir/status-update";
field public static final android.net.Uri CONTENT_URI;
+ field public static final android.net.Uri PROFILE_CONTENT_URI;
}
public static final class ContactsContract.StreamItemPhotos implements android.provider.BaseColumns android.provider.ContactsContract.StreamItemPhotosColumns {
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 1271ddd..0e3eaaa 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -4206,7 +4206,6 @@
fragment.mContainerId = containerId;
fragment.mTag = tag;
fragment.mInLayout = true;
- fragment.mImmediateActivity = this;
fragment.mFragmentManager = mFragments;
fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
mFragments.addFragment(fragment, true);
@@ -4222,7 +4221,6 @@
// This fragment was retained from a previous instance; get it
// going now.
fragment.mInLayout = true;
- fragment.mImmediateActivity = this;
// If this fragment is newly instantiated (either right now, or
// from last saved state), then give it the attributes to
// initialize itself.
diff --git a/core/java/android/app/BackStackRecord.java b/core/java/android/app/BackStackRecord.java
index 93330a7..e9e8e16 100644
--- a/core/java/android/app/BackStackRecord.java
+++ b/core/java/android/app/BackStackRecord.java
@@ -344,10 +344,6 @@
}
private void doAddOp(int containerViewId, Fragment fragment, String tag, int opcmd) {
- if (fragment.mImmediateActivity != null) {
- throw new IllegalStateException("Fragment already added: " + fragment);
- }
- fragment.mImmediateActivity = mManager.mActivity;
fragment.mFragmentManager = mManager;
if (tag != null) {
@@ -388,11 +384,6 @@
}
public FragmentTransaction remove(Fragment fragment) {
- if (fragment.mImmediateActivity == null) {
- throw new IllegalStateException("Fragment not added: " + fragment);
- }
- fragment.mImmediateActivity = null;
-
Op op = new Op();
op.cmd = OP_REMOVE;
op.fragment = fragment;
@@ -402,10 +393,6 @@
}
public FragmentTransaction hide(Fragment fragment) {
- if (fragment.mImmediateActivity == null) {
- throw new IllegalStateException("Fragment not added: " + fragment);
- }
-
Op op = new Op();
op.cmd = OP_HIDE;
op.fragment = fragment;
@@ -415,10 +402,6 @@
}
public FragmentTransaction show(Fragment fragment) {
- if (fragment.mImmediateActivity == null) {
- throw new IllegalStateException("Fragment not added: " + fragment);
- }
-
Op op = new Op();
op.cmd = OP_SHOW;
op.fragment = fragment;
@@ -428,10 +411,6 @@
}
public FragmentTransaction detach(Fragment fragment) {
- //if (fragment.mImmediateActivity == null) {
- // throw new IllegalStateException("Fragment not added: " + fragment);
- //}
-
Op op = new Op();
op.cmd = OP_DETACH;
op.fragment = fragment;
@@ -441,10 +420,6 @@
}
public FragmentTransaction attach(Fragment fragment) {
- //if (fragment.mImmediateActivity == null) {
- // throw new IllegalStateException("Fragment not added: " + fragment);
- //}
-
Op op = new Op();
op.cmd = OP_ATTACH;
op.fragment = fragment;
@@ -663,7 +638,6 @@
case OP_ADD: {
Fragment f = op.fragment;
f.mNextAnim = op.popExitAnim;
- f.mImmediateActivity = null;
mManager.removeFragment(f,
FragmentManagerImpl.reverseTransit(mTransition),
mTransitionStyle);
@@ -671,7 +645,6 @@
case OP_REPLACE: {
Fragment f = op.fragment;
f.mNextAnim = op.popExitAnim;
- f.mImmediateActivity = null;
mManager.removeFragment(f,
FragmentManagerImpl.reverseTransit(mTransition),
mTransitionStyle);
@@ -679,7 +652,6 @@
for (int i=0; i<op.removed.size(); i++) {
Fragment old = op.removed.get(i);
old.mNextAnim = op.popEnterAnim;
- f.mImmediateActivity = mManager.mActivity;
mManager.addFragment(old, false);
}
}
@@ -687,7 +659,6 @@
case OP_REMOVE: {
Fragment f = op.fragment;
f.mNextAnim = op.popEnterAnim;
- f.mImmediateActivity = mManager.mActivity;
mManager.addFragment(f, false);
} break;
case OP_HIDE: {
diff --git a/core/java/android/app/Fragment.java b/core/java/android/app/Fragment.java
index a8621f8..3a08e6d 100644
--- a/core/java/android/app/Fragment.java
+++ b/core/java/android/app/Fragment.java
@@ -402,10 +402,6 @@
// from all transactions.
FragmentManager mFragmentManager;
- // Set as soon as a fragment is added to a transaction (or removed),
- // to be able to do validation.
- Activity mImmediateActivity;
-
// Activity this fragment is attached to.
Activity mActivity;
@@ -438,7 +434,10 @@
// If set this fragment has menu items to contribute.
boolean mHasMenu;
-
+
+ // Set to true to allow the fragment's menu to be shown.
+ boolean mMenuVisible = true;
+
// Used to verify that subclasses call through to super class.
boolean mCalled;
@@ -888,7 +887,25 @@
}
}
}
-
+
+ /**
+ * Set a hint for whether this fragment's menu should be visible. This
+ * is useful if you know that a fragment has been placed in your view
+ * hierarchy so that the user can not currently seen it, so any menu items
+ * it has should also not be shown.
+ *
+ * @param menuVisible The default is true, meaning the fragment's menu will
+ * be shown as usual. If false, the user will not see the menu.
+ */
+ public void setMenuVisibility(boolean menuVisible) {
+ if (mMenuVisible != menuVisible) {
+ mMenuVisible = menuVisible;
+ if (mHasMenu && isAdded() && !isHidden()) {
+ mFragmentManager.invalidateOptionsMenu();
+ }
+ }
+ }
+
/**
* Return the LoaderManager for this fragment, creating it if needed.
*/
@@ -1233,7 +1250,7 @@
mRestored = false;
mBackStackNesting = 0;
mFragmentManager = null;
- mActivity = mImmediateActivity = null;
+ mActivity = null;
mFragmentId = 0;
mContainerId = 0;
mTag = null;
@@ -1421,17 +1438,14 @@
writer.print(" mInLayout="); writer.println(mInLayout);
writer.print(prefix); writer.print("mHidden="); writer.print(mHidden);
writer.print(" mDetached="); writer.print(mDetached);
- writer.print(" mRetainInstance="); writer.print(mRetainInstance);
- writer.print(" mRetaining="); writer.print(mRetaining);
+ writer.print(" mMenuVisible="); writer.print(mMenuVisible);
writer.print(" mHasMenu="); writer.println(mHasMenu);
+ writer.print(prefix); writer.print("mRetainInstance="); writer.print(mRetainInstance);
+ writer.print(" mRetaining="); writer.println(mRetaining);
if (mFragmentManager != null) {
writer.print(prefix); writer.print("mFragmentManager=");
writer.println(mFragmentManager);
}
- if (mImmediateActivity != null) {
- writer.print(prefix); writer.print("mImmediateActivity=");
- writer.println(mImmediateActivity);
- }
if (mActivity != null) {
writer.print(prefix); writer.print("mActivity=");
writer.println(mActivity);
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index 70e6866..7a6759f 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -67,6 +67,13 @@
public int getId();
/**
+ * Get the name that was supplied to
+ * {@link FragmentTransaction#addToBackStack(String)
+ * FragmentTransaction.addToBackStack(String)} when creating this entry.
+ */
+ public String getName();
+
+ /**
* Return the full bread crumb title resource identifier for the entry,
* or 0 if it does not have one.
*/
@@ -949,7 +956,6 @@
if (!f.mRetaining) {
makeInactive(f);
} else {
- f.mImmediateActivity = null;
f.mActivity = null;
f.mFragmentManager = null;
}
@@ -1037,7 +1043,7 @@
mAdded.add(fragment);
fragment.mAdded = true;
fragment.mRemoving = false;
- if (fragment.mHasMenu) {
+ if (fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
if (moveToStateNow) {
@@ -1051,7 +1057,7 @@
final boolean inactive = !fragment.isInBackStack();
if (!fragment.mDetached || inactive) {
mAdded.remove(fragment);
- if (fragment.mHasMenu) {
+ if (fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.mAdded = false;
@@ -1086,7 +1092,7 @@
fragment.mView.setVisibility(View.GONE);
}
}
- if (fragment.mAdded && fragment.mHasMenu) {
+ if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.onHiddenChanged(true);
@@ -1106,7 +1112,7 @@
}
fragment.mView.setVisibility(View.VISIBLE);
}
- if (fragment.mAdded && fragment.mHasMenu) {
+ if (fragment.mAdded && fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.onHiddenChanged(false);
@@ -1120,7 +1126,7 @@
if (fragment.mAdded) {
// We are not already in back stack, so need to remove the fragment.
mAdded.remove(fragment);
- if (fragment.mHasMenu) {
+ if (fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
fragment.mAdded = false;
@@ -1136,7 +1142,7 @@
if (!fragment.mAdded) {
mAdded.add(fragment);
fragment.mAdded = true;
- if (fragment.mHasMenu) {
+ if (fragment.mHasMenu && fragment.mMenuVisible) {
mNeedMenuInvalidate = true;
}
moveToState(fragment, mCurState, transition, transitionStyle);
@@ -1640,7 +1646,6 @@
"No instantiated fragment for index #" + fms.mAdded[i]);
}
f.mAdded = true;
- f.mImmediateActivity = mActivity;
if (DEBUG) Log.v(TAG, "restoreAllState: making added #" + i + ": " + f);
mAdded.add(f);
}
@@ -1748,7 +1753,7 @@
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
- if (f != null && !f.mHidden && f.mHasMenu) {
+ if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) {
show = true;
f.onCreateOptionsMenu(menu, inflater);
if (newMenus == null) {
@@ -1778,7 +1783,7 @@
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
- if (f != null && !f.mHidden && f.mHasMenu) {
+ if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) {
show = true;
f.onPrepareOptionsMenu(menu);
}
@@ -1791,7 +1796,7 @@
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
- if (f != null && !f.mHidden && f.mHasMenu) {
+ if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) {
if (f.onOptionsItemSelected(item)) {
return true;
}
@@ -1819,7 +1824,7 @@
if (mActive != null) {
for (int i=0; i<mAdded.size(); i++) {
Fragment f = mAdded.get(i);
- if (f != null && !f.mHidden && f.mHasMenu) {
+ if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible) {
f.onOptionsMenuClosed(menu);
}
}
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 9c96883..3441217 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -23,6 +23,7 @@
import android.os.Binder;
import android.os.Build.VERSION_CODES;
import android.os.RemoteException;
+import android.provider.Settings;
import java.net.InetAddress;
@@ -71,6 +72,15 @@
public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
/**
+ * Identical to {@link #CONNECTIVITY_ACTION} broadcast, but sent without any
+ * applicable {@link Settings.Secure#CONNECTIVITY_CHANGE_DELAY}.
+ *
+ * @hide
+ */
+ public static final String CONNECTIVITY_ACTION_IMMEDIATE =
+ "android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE";
+
+ /**
* The lookup key for a {@link NetworkInfo} object. Retrieve with
* {@link android.content.Intent#getParcelableExtra(String)}.
*
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index 5321c6a..1f2b342 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -125,19 +125,6 @@
public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
/**
- * An optional URI parameter for selection queries that instructs the
- * provider to allow the user's personal profile contact entry (if any)
- * to appear in a list of contact results. It is only useful when issuing
- * a query that may retrieve more than one contact. If present, the user's
- * profile will always be the first entry returned. The default value is
- * false.
- *
- * Specifying this parameter will result in a security error if the calling
- * application does not have android.permission.READ_PROFILE permission.
- */
- public static final String ALLOW_PROFILE = "allow_profile";
-
- /**
* Query parameter that should be used by the client to access a specific
* {@link Directory}. The parameter value should be the _ID of the corresponding
* directory, e.g.
@@ -557,7 +544,7 @@
}
/**
- * A table provided for sync adapters to use for storing private sync state data.
+ * A table provided for sync adapters to use for storing private sync state data for contacts.
*
* @see SyncStateContract
*/
@@ -608,6 +595,60 @@
}
}
+
+ /**
+ * A table provided for sync adapters to use for storing private sync state data for the
+ * user's personal profile.
+ *
+ * @see SyncStateContract
+ */
+ public static final class ProfileSyncState implements SyncStateContract.Columns {
+ /**
+ * This utility class cannot be instantiated
+ */
+ private ProfileSyncState() {}
+
+ public static final String CONTENT_DIRECTORY =
+ SyncStateContract.Constants.CONTENT_DIRECTORY;
+
+ /**
+ * The content:// style URI for this table
+ */
+ public static final Uri CONTENT_URI =
+ Uri.withAppendedPath(Profile.CONTENT_URI, CONTENT_DIRECTORY);
+
+ /**
+ * @see android.provider.SyncStateContract.Helpers#get
+ */
+ public static byte[] get(ContentProviderClient provider, Account account)
+ throws RemoteException {
+ return SyncStateContract.Helpers.get(provider, CONTENT_URI, account);
+ }
+
+ /**
+ * @see android.provider.SyncStateContract.Helpers#get
+ */
+ public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account)
+ throws RemoteException {
+ return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account);
+ }
+
+ /**
+ * @see android.provider.SyncStateContract.Helpers#set
+ */
+ public static void set(ContentProviderClient provider, Account account, byte[] data)
+ throws RemoteException {
+ SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data);
+ }
+
+ /**
+ * @see android.provider.SyncStateContract.Helpers#newSetOperation
+ */
+ public static ContentProviderOperation newSetOperation(Account account, byte[] data) {
+ return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data);
+ }
+ }
+
/**
* Generic columns for use by sync adapters. The specific functions of
* these columns are private to the sync adapter. Other clients of the API
@@ -1875,8 +1916,8 @@
* Constants for the user's profile data, which is represented as a single contact on
* the device that represents the user. The profile contact is not aggregated
* together automatically in the same way that normal contacts are; instead, each
- * account on the device may contribute a single raw contact representing the user's
- * personal profile data from that source.
+ * account (including data set, if applicable) on the device may contribute a single
+ * raw contact representing the user's personal profile data from that source.
* </p>
* <p>
* Access to the profile entry through these URIs (or incidental access to parts of
@@ -1950,6 +1991,31 @@
*/
public static final Uri CONTENT_RAW_CONTACTS_URI = Uri.withAppendedPath(CONTENT_URI,
"raw_contacts");
+
+ /**
+ * The minimum ID for any entity that belongs to the profile. This essentially
+ * defines an ID-space in which profile data is stored, and is used by the provider
+ * to determine whether a request via a non-profile-specific URI should be directed
+ * to the profile data rather than general contacts data, along with all the special
+ * permission checks that entails.
+ *
+ * Callers may use {@link #isProfileId} to check whether a specific ID falls into
+ * the set of data intended for the profile.
+ */
+ public static final long MIN_ID = Long.MAX_VALUE - (long) Integer.MAX_VALUE;
+ }
+
+ /**
+ * This method can be used to identify whether the given ID is associated with profile
+ * data. It does not necessarily indicate that the ID is tied to valid data, merely
+ * that accessing data using this ID will result in profile access checks and will only
+ * return data from the profile.
+ *
+ * @param id The ID to check.
+ * @return Whether the ID is associated with profile data.
+ */
+ public static boolean isProfileId(long id) {
+ return id >= Profile.MIN_ID;
}
protected interface RawContactsColumns {
@@ -4542,6 +4608,12 @@
* either.
* </p>
* <p>
+ * Inserting or updating a status update for the user's profile requires either using
+ * the {@link #DATA_ID} to identify the data row to attach the update to, or
+ * {@link StatusUpdates#PROFILE_CONTENT_URI} to ensure that the change is scoped to the
+ * profile.
+ * </p>
+ * <p>
* You cannot use {@link ContentResolver#update} to change a status, but
* {@link ContentResolver#insert} will replace the latests status if it already
* exists.
@@ -4687,6 +4759,12 @@
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates");
/**
+ * The content:// style URI for this table, specific to the user's profile.
+ */
+ public static final Uri PROFILE_CONTENT_URI =
+ Uri.withAppendedPath(Profile.CONTENT_URI, "status_updates");
+
+ /**
* Gets the resource ID for the proper presence icon.
*
* @param status the status to get the icon for
diff --git a/core/java/android/speech/tts/AudioPlaybackHandler.java b/core/java/android/speech/tts/AudioPlaybackHandler.java
index 89b6f32..f8d0142 100644
--- a/core/java/android/speech/tts/AudioPlaybackHandler.java
+++ b/core/java/android/speech/tts/AudioPlaybackHandler.java
@@ -390,10 +390,10 @@
audioTrack.play();
}
int count = 0;
- while (count < bufferCopy.mLength) {
+ while (count < bufferCopy.mBytes.length) {
// Note that we don't take bufferCopy.mOffset into account because
// it is guaranteed to be 0.
- int written = audioTrack.write(bufferCopy.mBytes, count, bufferCopy.mLength);
+ int written = audioTrack.write(bufferCopy.mBytes, count, bufferCopy.mBytes.length);
if (written <= 0) {
break;
}
@@ -453,7 +453,7 @@
}
final AudioTrack audioTrack = params.mAudioTrack;
- final int bytesPerFrame = getBytesPerFrame(params.mAudioFormat);
+ final int bytesPerFrame = params.mBytesPerFrame;
final int lengthInBytes = params.mBytesWritten;
final int lengthInFrames = lengthInBytes / bytesPerFrame;
@@ -511,16 +511,6 @@
return 0;
}
- static int getBytesPerFrame(int audioFormat) {
- if (audioFormat == AudioFormat.ENCODING_PCM_8BIT) {
- return 1;
- } else if (audioFormat == AudioFormat.ENCODING_PCM_16BIT) {
- return 2;
- }
-
- return -1;
- }
-
private static void setupVolume(AudioTrack audioTrack, float volume, float pan) {
float vol = clip(volume, 0.0f, 1.0f);
float panning = clip(pan, -1.0f, 1.0f);
diff --git a/core/java/android/speech/tts/PlaybackSynthesisCallback.java b/core/java/android/speech/tts/PlaybackSynthesisCallback.java
index 7dbf1ac..0cca06a 100644
--- a/core/java/android/speech/tts/PlaybackSynthesisCallback.java
+++ b/core/java/android/speech/tts/PlaybackSynthesisCallback.java
@@ -85,6 +85,7 @@
// Note that mLogger.mError might be true too at this point.
mLogger.onStopped();
+ SynthesisMessageParams token = null;
synchronized (mStateLock) {
if (mStopped) {
Log.w(TAG, "stop() called twice");
@@ -97,9 +98,19 @@
// In all other cases, mAudioTrackHandler.stop() will
// result in onComplete being called.
mLogger.onWriteData();
+ } else {
+ token = mToken;
}
mStopped = true;
}
+
+ if (token != null) {
+ // This might result in the synthesis thread being woken up, at which
+ // point it will write an additional buffer to the token - but we
+ // won't worry about that because the audio playback queue will be cleared
+ // soon after (see SynthHandler#stop(String).
+ token.clearBuffers();
+ }
}
@Override
@@ -155,18 +166,22 @@
+ length + " bytes)");
}
+ SynthesisMessageParams token = null;
synchronized (mStateLock) {
if (mToken == null || mStopped) {
return TextToSpeech.ERROR;
}
-
- // Sigh, another copy.
- final byte[] bufferCopy = new byte[length];
- System.arraycopy(buffer, offset, bufferCopy, 0, length);
- mToken.addBuffer(bufferCopy);
- mAudioTrackHandler.enqueueSynthesisDataAvailable(mToken);
+ token = mToken;
}
+ // Sigh, another copy.
+ final byte[] bufferCopy = new byte[length];
+ System.arraycopy(buffer, offset, bufferCopy, 0, length);
+ // Might block on mToken.this, if there are too many buffers waiting to
+ // be consumed.
+ token.addBuffer(bufferCopy);
+ mAudioTrackHandler.enqueueSynthesisDataAvailable(token);
+
mLogger.onEngineDataReceived();
return TextToSpeech.SUCCESS;
@@ -176,6 +191,7 @@
public int done() {
if (DBG) Log.d(TAG, "done()");
+ SynthesisMessageParams token = null;
synchronized (mStateLock) {
if (mDone) {
Log.w(TAG, "Duplicate call to done()");
@@ -188,9 +204,12 @@
return TextToSpeech.ERROR;
}
- mAudioTrackHandler.enqueueSynthesisDone(mToken);
- mLogger.onEngineComplete();
+ token = mToken;
}
+
+ mAudioTrackHandler.enqueueSynthesisDone(token);
+ mLogger.onEngineComplete();
+
return TextToSpeech.SUCCESS;
}
diff --git a/core/java/android/speech/tts/SynthesisMessageParams.java b/core/java/android/speech/tts/SynthesisMessageParams.java
index 7da5daa..3e905d6 100644
--- a/core/java/android/speech/tts/SynthesisMessageParams.java
+++ b/core/java/android/speech/tts/SynthesisMessageParams.java
@@ -15,6 +15,7 @@
*/
package android.speech.tts;
+import android.media.AudioFormat;
import android.media.AudioTrack;
import android.speech.tts.TextToSpeechService.UtteranceCompletedDispatcher;
@@ -24,6 +25,8 @@
* Params required to play back a synthesis request.
*/
final class SynthesisMessageParams extends MessageParams {
+ private static final long MAX_UNCONSUMED_AUDIO_MS = 500;
+
final int mStreamType;
final int mSampleRateInHz;
final int mAudioFormat;
@@ -32,10 +35,16 @@
final float mPan;
final EventLogger mLogger;
+ final int mBytesPerFrame;
+
volatile AudioTrack mAudioTrack;
- // Not volatile, accessed only from the synthesis thread.
- int mBytesWritten;
+ // Written by the synthesis thread, but read on the audio playback
+ // thread.
+ volatile int mBytesWritten;
+ // Not volatile, accessed only from the audio playback thread.
int mAudioBufferSize;
+ // Always synchronized on "this".
+ int mUnconsumedBytes;
private final LinkedList<ListEntry> mDataBufferList = new LinkedList<ListEntry>();
@@ -53,6 +62,8 @@
mPan = pan;
mLogger = logger;
+ mBytesPerFrame = getBytesPerFrame(mAudioFormat) * mChannelCount;
+
// initially null.
mAudioTrack = null;
mBytesWritten = 0;
@@ -64,18 +75,36 @@
return TYPE_SYNTHESIS;
}
- synchronized void addBuffer(byte[] buffer, int offset, int length) {
- mDataBufferList.add(new ListEntry(buffer, offset, length));
+ synchronized void addBuffer(byte[] buffer) {
+ long unconsumedAudioMs = 0;
+
+ while ((unconsumedAudioMs = getUnconsumedAudioLengthMs()) > MAX_UNCONSUMED_AUDIO_MS) {
+ try {
+ wait();
+ } catch (InterruptedException ie) {
+ return;
+ }
+ }
+
+ mDataBufferList.add(new ListEntry(buffer));
+ mUnconsumedBytes += buffer.length;
}
- synchronized void addBuffer(byte[] buffer) {
- mDataBufferList.add(new ListEntry(buffer, 0, buffer.length));
+ synchronized void clearBuffers() {
+ mDataBufferList.clear();
+ mUnconsumedBytes = 0;
+ notifyAll();
}
synchronized ListEntry getNextBuffer() {
- return mDataBufferList.poll();
- }
+ ListEntry entry = mDataBufferList.poll();
+ if (entry != null) {
+ mUnconsumedBytes -= entry.mBytes.length;
+ notifyAll();
+ }
+ return entry;
+ }
void setAudioTrack(AudioTrack audioTrack) {
mAudioTrack = audioTrack;
@@ -85,15 +114,29 @@
return mAudioTrack;
}
+ // Must be called synchronized on this.
+ private long getUnconsumedAudioLengthMs() {
+ final int unconsumedFrames = mUnconsumedBytes / mBytesPerFrame;
+ final long estimatedTimeMs = unconsumedFrames * 1000 / mSampleRateInHz;
+
+ return estimatedTimeMs;
+ }
+
+ private static int getBytesPerFrame(int audioFormat) {
+ if (audioFormat == AudioFormat.ENCODING_PCM_8BIT) {
+ return 1;
+ } else if (audioFormat == AudioFormat.ENCODING_PCM_16BIT) {
+ return 2;
+ }
+
+ return -1;
+ }
+
static final class ListEntry {
final byte[] mBytes;
- final int mOffset;
- final int mLength;
- ListEntry(byte[] bytes, int offset, int length) {
+ ListEntry(byte[] bytes) {
mBytes = bytes;
- mOffset = offset;
- mLength = length;
}
}
}
diff --git a/core/java/android/widget/SpellChecker.java b/core/java/android/widget/SpellChecker.java
index ff13dcb..b89b8ec 100644
--- a/core/java/android/widget/SpellChecker.java
+++ b/core/java/android/widget/SpellChecker.java
@@ -112,6 +112,8 @@
private void scheduleSpellCheck() {
if (mLength == 0) return;
+ if (spellCheckerSession == null) return;
+
if (mChecker != null) {
mTextView.removeCallbacks(mChecker);
}
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index e9662ae..94f1604 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -8928,6 +8928,7 @@
stopSelectionActionMode();
} else {
selectCurrentWord();
+ getSelectionController().show();
}
handled = true;
}
diff --git a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
index ec926e4..76bc535 100644
--- a/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
+++ b/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java
@@ -16,8 +16,6 @@
package com.android.internal.widget.multiwaveview;
-import java.util.ArrayList;
-
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.AnimatorListenerAdapter;
@@ -31,15 +29,20 @@
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Vibrator;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View;
-import android.view.View.MeasureSpec;
+import android.view.ViewConfiguration;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
import com.android.internal.R;
+import java.util.ArrayList;
+
/**
* A special widget containing a center and outer ring. Moving the center ring to the outer ring
* causes an event that can be caught by implementing OnTriggerListener.
@@ -82,6 +85,8 @@
private ArrayList<TargetDrawable> mChevronDrawables = new ArrayList<TargetDrawable>();
private ArrayList<Tweener> mChevronAnimations = new ArrayList<Tweener>();
private ArrayList<Tweener> mTargetAnimations = new ArrayList<Tweener>();
+ private ArrayList<String> mTargetDescriptions;
+ private ArrayList<String> mDirectionDescriptions;
private Tweener mHandleAnimation;
private OnTriggerListener mOnTriggerListener;
private TargetDrawable mHandleDrawable;
@@ -103,6 +108,9 @@
private boolean mDragging;
private int mNewTargetResources;
+ private boolean mWaveHovered = false;
+ private long mLastHoverExitTimeMillis = 0;
+
private AnimatorListener mResetListener = new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator animator) {
switchToState(STATE_IDLE, mWaveCenterX, mWaveCenterY);
@@ -128,6 +136,8 @@
}
};
private int mTargetResourceId;
+ private int mTargetDescriptionsResourceId;
+ private int mDirectionDescriptionsResourceId;
public MultiWaveView(Context context) {
this(context, null);
@@ -177,6 +187,25 @@
throw new IllegalStateException("Must specify at least one target drawable");
}
+ // Read array of target descriptions
+ if (a.getValue(R.styleable.MultiWaveView_targetDescriptions, outValue)) {
+ final int resourceId = outValue.resourceId;
+ if (resourceId == 0) {
+ throw new IllegalStateException("Must specify target descriptions");
+ }
+ setTargetDescriptionsResourceId(resourceId);
+ }
+
+ // Read array of direction descriptions
+ if (a.getValue(R.styleable.MultiWaveView_directionDescriptions, outValue)) {
+ final int resourceId = outValue.resourceId;
+ if (resourceId == 0) {
+ throw new IllegalStateException("Must specify direction descriptions");
+ }
+ setDirectionDescriptionsResourceId(resourceId);
+ }
+
+ a.recycle();
setVibrateEnabled(mVibrationDuration > 0);
}
@@ -247,6 +276,9 @@
showTargets(true);
mHandleDrawable.setState(TargetDrawable.STATE_ACTIVE);
setGrabbedState(OnTriggerListener.CENTER_HANDLE);
+ if (AccessibilityManager.getInstance(mContext).isEnabled()) {
+ announceTargets();
+ }
break;
case STATE_TRACKING:
@@ -347,6 +379,13 @@
}
}
+ private void dispatchGrabbedEvent(int whichHandler) {
+ vibrate();
+ if (mOnTriggerListener != null) {
+ mOnTriggerListener.onGrabbed(this, whichHandler);
+ }
+ }
+
private void doFinish() {
final int activeTarget = mActiveTarget;
boolean targetHit = activeTarget != -1;
@@ -475,6 +514,7 @@
Drawable drawable = array.getDrawable(i);
targetDrawables.add(new TargetDrawable(res, drawable));
}
+ array.recycle();
mTargetResourceId = resourceId;
mTargetDrawables = targetDrawables;
updateTargetPositions();
@@ -499,6 +539,48 @@
}
/**
+ * Sets the resource id specifying the target descriptions for accessibility.
+ *
+ * @param resourceId The resource id.
+ */
+ public void setTargetDescriptionsResourceId(int resourceId) {
+ mTargetDescriptionsResourceId = resourceId;
+ if (mTargetDescriptions != null) {
+ mTargetDescriptions.clear();
+ }
+ }
+
+ /**
+ * Gets the resource id specifying the target descriptions for accessibility.
+ *
+ * @return The resource id.
+ */
+ public int getTargetDescriptionsResourceId() {
+ return mTargetDescriptionsResourceId;
+ }
+
+ /**
+ * Sets the resource id specifying the target direction descriptions for accessibility.
+ *
+ * @param resourceId The resource id.
+ */
+ public void setDirectionDescriptionsResourceId(int resourceId) {
+ mDirectionDescriptionsResourceId = resourceId;
+ if (mDirectionDescriptions != null) {
+ mDirectionDescriptions.clear();
+ }
+ }
+
+ /**
+ * Gets the resource id specifying the target direction descriptions.
+ *
+ * @return The resource id.
+ */
+ public int getDirectionDescriptionsResourceId() {
+ return mDirectionDescriptionsResourceId;
+ }
+
+ /**
* Enable or disable vibrate on touch.
*
* @param enabled
@@ -593,6 +675,43 @@
}
}
+ @Override
+ public boolean onHoverEvent(MotionEvent event) {
+ if (AccessibilityManager.getInstance(mContext).isTouchExplorationEnabled()) {
+ final int action = event.getAction();
+ switch (action) {
+ case MotionEvent.ACTION_HOVER_ENTER:
+ case MotionEvent.ACTION_HOVER_MOVE:
+ final float dx = event.getX() - mWaveCenterX;
+ final float dy = event.getY() - mWaveCenterY;
+ if (dist2(dx,dy) <= square(mTapRadius)) {
+ if (!mWaveHovered) {
+ mWaveHovered = true;
+ final long timeSinceLastHoverExitMillis =
+ event.getEventTime() - mLastHoverExitTimeMillis;
+ final long recurringEventsInterval =
+ ViewConfiguration.getSendRecurringAccessibilityEventsInterval();
+ if (timeSinceLastHoverExitMillis > recurringEventsInterval) {
+ String text =
+ mContext.getString(R.string.content_description_sliding_handle);
+ announceText(text);
+ }
+ }
+ } else {
+ mWaveHovered = false;
+ }
+ break;
+ case MotionEvent.ACTION_HOVER_EXIT:
+ mLastHoverExitTimeMillis = event.getEventTime();
+ mWaveHovered = false;
+ break;
+ default:
+ mWaveHovered = false;
+ }
+ }
+ return super.onHoverEvent(event);
+ }
+
private void handleUp(MotionEvent event) {
if (DEBUG && mDragging) Log.v(TAG, "** Handle RELEASE");
switchToState(STATE_FINISH, event.getX(), event.getY());
@@ -663,7 +782,11 @@
invalidateGlobalRegion(mHandleDrawable);
if (mActiveTarget != activeTarget && activeTarget != -1) {
- vibrate();
+ dispatchGrabbedEvent(activeTarget);
+ if (AccessibilityManager.getInstance(mContext).isEnabled()) {
+ String targetContentDescription = getTargetDescription(activeTarget);
+ announceText(targetContentDescription);
+ }
}
mActiveTarget = activeTarget;
}
@@ -771,4 +894,62 @@
return dx*dx + dy*dy;
}
-}
\ No newline at end of file
+ private void announceTargets() {
+ StringBuilder utterance = new StringBuilder();
+ final int targetCount = mTargetDrawables.size();
+ for (int i = 0; i < targetCount; i++) {
+ String targetDescription = getTargetDescription(i);
+ String directionDescription = getDirectionDescription(i);
+ if (!TextUtils.isEmpty(targetDescription)
+ && !TextUtils.isEmpty(directionDescription)) {
+ utterance.append(targetDescription);
+ utterance.append(" ");
+ utterance.append(directionDescription);
+ utterance.append(".");
+ }
+ }
+ announceText(utterance.toString());
+ }
+
+ private void announceText(String text) {
+ setContentDescription(text);
+ sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
+ setContentDescription(null);
+ }
+
+ private String getTargetDescription(int index) {
+ if (mTargetDescriptions == null || mTargetDescriptions.isEmpty()) {
+ mTargetDescriptions = loadDescriptions(mTargetDescriptionsResourceId);
+ if (mTargetDrawables.size() != mTargetDescriptions.size()) {
+ Log.w(TAG, "The number of target drawables must be"
+ + " euqal to the number of target descriptions.");
+ return null;
+ }
+ }
+ return mTargetDescriptions.get(index);
+ }
+
+ private String getDirectionDescription(int index) {
+ if (mDirectionDescriptions == null || mDirectionDescriptions.isEmpty()) {
+ mDirectionDescriptions = loadDescriptions(mDirectionDescriptionsResourceId);
+ if (mTargetDrawables.size() != mDirectionDescriptions.size()) {
+ Log.w(TAG, "The number of target drawables must be"
+ + " euqal to the number of direction descriptions.");
+ return null;
+ }
+ }
+ return mDirectionDescriptions.get(index);
+ }
+
+ private ArrayList<String> loadDescriptions(int resourceId) {
+ TypedArray array = getContext().getResources().obtainTypedArray(resourceId);
+ final int count = array.length();
+ ArrayList<String> targetContentDescriptions = new ArrayList<String>(count);
+ for (int i = 0; i < count; i++) {
+ String contentDescription = array.getString(i);
+ targetContentDescriptions.add(contentDescription);
+ }
+ array.recycle();
+ return targetContentDescriptions;
+ }
+}
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 540c65a..01f2a8f 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -93,6 +93,9 @@
<protected-broadcast android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
<protected-broadcast android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" />
+ <protected-broadcast android:name="android.net.conn.CONNECTIVITY_CHANGE" />
+ <protected-broadcast android:name="android.net.conn.CONNECTIVITY_CHANGE_IMMEDIATE" />
+
<protected-broadcast android:name="android.nfc.action.LLCP_LINK_STATE_CHANGED" />
<protected-broadcast android:name="com.android.nfc_extras.action.RF_FIELD_ON_DETECTED" />
<protected-broadcast android:name="com.android.nfc_extras.action.RF_FIELD_OFF_DETECTED" />
diff --git a/core/res/res/layout/keyguard_screen_tab_unlock.xml b/core/res/res/layout/keyguard_screen_tab_unlock.xml
index a42d6cb..4c8c0d1 100644
--- a/core/res/res/layout/keyguard_screen_tab_unlock.xml
+++ b/core/res/res/layout/keyguard_screen_tab_unlock.xml
@@ -130,6 +130,8 @@
android:layout_alignParentBottom="true"
android:targetDrawables="@array/lockscreen_targets_with_camera"
+ android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
+ android:directionDescriptions="@array/lockscreen_direction_descriptions_with_camera"
android:handleDrawable="@drawable/ic_lockscreen_handle"
android:waveDrawable="@drawable/ic_lockscreen_outerring"
android:outerRadius="@dimen/multiwaveview_target_placement_radius"
diff --git a/core/res/res/layout/keyguard_screen_tab_unlock_land.xml b/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
index b716c29..ba55f0c0 100644
--- a/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
+++ b/core/res/res/layout/keyguard_screen_tab_unlock_land.xml
@@ -135,6 +135,8 @@
android:layout_rowSpan="7"
android:targetDrawables="@array/lockscreen_targets_with_camera"
+ android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
+ android:directionDescriptions="@array/lockscreen_direction_descriptions_with_camera"
android:handleDrawable="@drawable/ic_lockscreen_handle"
android:waveDrawable="@drawable/ic_lockscreen_outerring"
android:outerRadius="@dimen/multiwaveview_target_placement_radius"
diff --git a/core/res/res/values-land/arrays.xml b/core/res/res/values-land/arrays.xml
index fd492ec..57aafc8 100644
--- a/core/res/res/values-land/arrays.xml
+++ b/core/res/res/values-land/arrays.xml
@@ -27,13 +27,41 @@
<item>@drawable/ic_lockscreen_soundon</item>
</array>
+ <array name="lockscreen_target_descriptions_when_silent">
+ <item>@null</item>
+ <item>@string/description_target_unlock</item>
+ <item>@null</item>
+ <item>@string/description_target_soundon</item>
+ </array>
+
+ <array name="lockscreen_direction_descriptions_when_silent">
+ <item>@null</item>
+ <item>@string/description_direction_up</item>
+ <item>@null</item>
+ <item>@string/description_direction_down</item>
+ </array>
+
<array name="lockscreen_targets_when_soundon">
- <item>@null</item>"
+ <item>@null</item>
<item>@drawable/ic_lockscreen_unlock</item>
<item>@null</item>
<item>@drawable/ic_lockscreen_silent</item>
</array>
+ <array name="lockscreen_target_descriptions_when_soundon">
+ <item>@null</item>
+ <item>@string/description_target_unlock</item>
+ <item>@null</item>
+ <item>@string/description_target_silent</item>
+ </array>
+
+ <array name="lockscreen_direction_descriptions_when_soundon">
+ <item>@null</item>
+ <item>@string/description_direction_up</item>
+ <item>@null</item>
+ <item>@string/description_direction_down</item>
+ </array>
+
<array name="lockscreen_targets_with_camera">
<item>@null</item>
<item>@drawable/ic_lockscreen_unlock</item>
@@ -41,4 +69,18 @@
<item>@drawable/ic_lockscreen_camera</item>
</array>
+ <array name="lockscreen_target_descriptions_with_camera">
+ <item>@null</item>
+ <item>@string/description_target_unlock</item>
+ <item>@null</item>
+ <item>@string/description_target_camera</item>
+ </array>
+
+ <array name="lockscreen_direction_descriptions_with_camera">
+ <item>@null</item>
+ <item>@string/description_direction_up</item>
+ <item>@null</item>
+ <item>@string/description_direction_down</item>
+ </array>
+
</resources>
diff --git a/core/res/res/values/arrays.xml b/core/res/res/values/arrays.xml
index 57e9bbf..c9043ba 100644
--- a/core/res/res/values/arrays.xml
+++ b/core/res/res/values/arrays.xml
@@ -349,18 +349,60 @@
<item>@null</item>
</array>
+ <array name="lockscreen_target_descriptions_when_silent">
+ <item>@string/description_target_unlock</item>
+ <item>@null</item>
+ <item>@string/description_target_soundon</item>
+ <item>@null</item>
+ </array>
+
+ <array name="lockscreen_direction_descriptions_when_silent">
+ <item>@string/description_direction_right</item>
+ <item>@null</item>
+ <item>@string/description_direction_left</item>
+ <item>@null</item>
+ </array>
+
<array name="lockscreen_targets_when_soundon">
<item>@drawable/ic_lockscreen_unlock</item>
<item>@null</item>
<item>@drawable/ic_lockscreen_silent</item>
- <item>@null</item>"
+ <item>@null</item>
+ </array>
+
+ <array name="lockscreen_target_descriptions_when_soundon">
+ <item>@string/description_target_unlock</item>
+ <item>@null</item>
+ <item>@string/description_target_silent</item>
+ <item>@null</item>
+ </array>
+
+ <array name="lockscreen_direction_descriptions_when_soundon">
+ <item>@string/description_direction_right</item>
+ <item>@null</item>
+ <item>@string/description_direction_left</item>
+ <item>@null</item>
</array>
<array name="lockscreen_targets_with_camera">
<item>@drawable/ic_lockscreen_unlock</item>
<item>@null</item>
<item>@drawable/ic_lockscreen_camera</item>
- <item>@null</item>"
+ <item>@null</item>
+ </array>
+
+ <array name="lockscreen_target_descriptions_with_camera">
+ <item>@string/description_target_unlock</item>
+ <item>@null</item>
+ <item>@string/description_target_camera</item>
+ <item>@null</item>
+ </array>
+
+ <array name="lockscreen_direction_descriptions_with_camera">
+ <item>@string/description_direction_right</item>
+ <item>@null</item>
+ <item>@string/description_direction_left</item>
+ <item>@null</item>
</array>
</resources>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index dae9f70..8c0d826 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -5169,6 +5169,12 @@
<!-- Reference to an array resource that be shown as targets around a circle. -->
<attr name="targetDrawables" format="reference"/>
+ <!-- Reference to an array resource that be used as description for the targets around the circle. -->
+ <attr name="targetDescriptions" format="reference"/>
+
+ <!-- Reference to an array resource that be used to announce the directions with targets around the circle. -->
+ <attr name="directionDescriptions" format="reference"/>
+
<!-- Sets a drawable as the drag center. -->
<attr name="handleDrawable" format="reference" />
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index fcd3bba..6988f6b 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2006,4 +2006,8 @@
<public type="color" name="holo_orange_dark" />
<public type="color" name="holo_purple" />
<public type="color" name="holo_blue_bright" />
+
+ <public type="attr" name="targetDescriptions" />
+ <public type="attr" name="directionDescriptions" />
+
</resources>
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 8e0f300..547e1fc 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1763,7 +1763,7 @@
--> <skip />
<!-- On the keyguard screen, it shows the carrier the phone is connected to. This is displayed if the phone is not connected to a carrier.-->
- <string name="lockscreen_carrier_default">(No service)</string>
+ <string name="lockscreen_carrier_default">No service.</string>
<!-- Shown in the lock screen to tell the user that the screen is locked. -->
<string name="lockscreen_screen_locked">Screen locked.</string>
@@ -3129,6 +3129,29 @@
<!-- Description of the Enter button in a KeyboardView. [CHAR LIMIT=NONE] -->
<string name="keyboardview_keycode_enter">Enter</string>
+ <!-- Slide lock screen -->
+
+ <!-- Description of the sliding handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="content_description_sliding_handle">"Sliding handle. Tap and hold."</string>
+
+ <!-- Description of the up direction in which one can to slide the handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="description_direction_up">"Up</string>
+ <!-- Description of the down direction in which one can to slide the handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="description_direction_down">Down</string>
+ <!-- Description of the left direction in which one can to slide the handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="description_direction_left">"Left</string>
+ <!-- Description of the right direction in which one can to slide the handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="description_direction_right">Right</string>
+
+ <!-- Description of the unlock target in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="description_target_unlock">Unlock</string>
+ <!-- Description of the camera target in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="description_target_camera">Camera</string>
+ <!-- Description of the silent target in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="description_target_silent">Silent</string>
+ <!-- Description of the sound on target in the Slide unlock screen. [CHAR LIMIT=NONE] -->
+ <string name="description_target_soundon">Sound on</string>
+
<!-- Announce that a headset is required to hear keyboard keys while typing a password. [CHAR LIMIT=NONE] -->
<string name="keyboard_headset_required_to_hear_password">Key. Headset required to hear
keys while typing a password.</string>
diff --git a/docs/html/sdk/ndk/index.jd b/docs/html/sdk/ndk/index.jd
index 97df84f..f87e1f6 100644
--- a/docs/html/sdk/ndk/index.jd
+++ b/docs/html/sdk/ndk/index.jd
@@ -1,16 +1,16 @@
ndk=true
-ndk.win_download=android-ndk-r6-windows.zip
-ndk.win_bytes=67642809
-ndk.win_checksum=9c7d5ccc02151a3e5e950c70dc05ac6d
+ndk.win_download=android-ndk-r6b-windows.zip
+ndk.win_bytes=67670219
+ndk.win_checksum=f496b48fffb6d341303de170a081b812
-ndk.mac_download=android-ndk-r6-darwin-x86.tar.bz2
-ndk.mac_bytes=52682746
-ndk.mac_checksum=a154905e49a6246abd823b75b6eda738
+ndk.mac_download=android-ndk-r6b-darwin-x86.tar.bz2
+ndk.mac_bytes=52798843
+ndk.mac_checksum=65f2589ac1b08aabe3183f9ed1a8ce8e
-ndk.linux_download=android-ndk-r6-linux-x86.tar.bz2
-ndk.linux_bytes=46425290
-ndk.linux_checksum=ff0a43085fe206696d5cdcef3f4f4637
+ndk.linux_download=android-ndk-r6b-linux-x86.tar.bz2
+ndk.linux_bytes=46532436
+ndk.linux_checksum=309f35e49b64313cfb20ac428df4cec2
page.title=Android NDK
@jd:body
@@ -58,10 +58,42 @@
}
</style>
-
<div class="toggleable open">
<a href="#" onclick="return toggleDiv(this)"><img src=
"{@docRoot}assets/images/triangle-opened.png" class="toggle-img" height="9px" width="9px">
+ Android NDK, Revision 6b</a> <em>(August 2011)</em>
+
+ <div class="toggleme">
+ <p>This release of the NDK does not include any new features compared to r6. The r6b release
+ addresses the following issues in the r6 release:</p>
+ <dl>
+ <dt>Important bug fixes</dt>
+ <dd>
+ <ul>
+ <li>Fixed the build when <code>APP_ABI="armeabi x86"</code> is used for
+ multi-architecture builds.</li>
+ <li>Fixed the location of prebuilt STLport binaries in the NDK release package.
+ A bug in the packaging script placed them in the wrong location.</li>
+ <li>Fixed <code>atexit()</code> usage in shared libraries with the x86standalone
+ toolchain.</li>
+ <li>Fixed <code>make-standalone-toolchain.sh --arch=x86</code>. It used to fail
+ to copy the proper GNU libstdc++ binaries to the right location.</li>
+ <li>Fixed the standalone toolchain linker warnings about missing the definition and
+ size for the <code>__dso_handle</code> symbol (ARM only).</li>
+ <li>Fixed the inclusion order of <code>$(SYSROOT)/usr/include</code> for x86 builds.
+ See the <a href="http://code.google.com/p/android/issues/detail?id=18540">bug</a> for
+ more information.</li>
+ <li>Fixed the definitions of <code>ptrdiff_t</code> and <code>size_t</code> in
+ x86-specific systems when they are used with the x86 standalone toolchain.</li>
+ </ul>
+ </dd>
+ </dl>
+ </div>
+</div>
+
+<div class="toggleable closed">
+ <a href="#" onclick="return toggleDiv(this)"><img src=
+ "{@docRoot}assets/images/triangle-closed.png" class="toggle-img" height="9px" width="9px">
Android NDK, Revision 6</a> <em>(July 2011)</em>
<div class="toggleme">
diff --git a/docs/html/sdk/sdk_toc.cs b/docs/html/sdk/sdk_toc.cs
index 1b1fc8d..a00ca12 100644
--- a/docs/html/sdk/sdk_toc.cs
+++ b/docs/html/sdk/sdk_toc.cs
@@ -183,7 +183,7 @@
<span style="display:none" class="zh-TW"></span>
</h2>
<ul>
- <li><a href="<?cs var:toroot ?>sdk/ndk/index.html">Android NDK, r6</a>
+ <li><a href="<?cs var:toroot ?>sdk/ndk/index.html">Android NDK, r6b</a>
<span class="new">new!</span>
</li>
<li><a href="<?cs var:toroot ?>sdk/ndk/overview.html">What is the NDK?</a></li>
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index e0d7898..6a15f6e 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -185,6 +185,10 @@
static status_t unregisterEffect(int id);
static status_t setEffectEnabled(int id, bool enabled);
+ // clear stream to output mapping cache (gStreamOutputMap)
+ // and output configuration cache (gOutputs)
+ static void clearAudioConfigCache();
+
static const sp<IAudioPolicyService>& get_audio_policy_service();
// ----------------------------------------------------------------------------
@@ -236,7 +240,8 @@
// mapping between stream types and outputs
static DefaultKeyedVector<int, audio_io_handle_t> gStreamOutputMap;
- // list of output descritor containing cached parameters (sampling rate, framecount, channel count...)
+ // list of output descriptors containing cached parameters
+ // (sampling rate, framecount, channel count...)
static DefaultKeyedVector<audio_io_handle_t, OutputDescriptor *> gOutputs;
};
diff --git a/media/java/android/media/videoeditor/VideoEditorProfile.java b/media/java/android/media/videoeditor/VideoEditorProfile.java
index ecdcdfb..202a2df 100755
--- a/media/java/android/media/videoeditor/VideoEditorProfile.java
+++ b/media/java/android/media/videoeditor/VideoEditorProfile.java
@@ -91,7 +91,7 @@
case MediaProperties.VCODEC_H263:
case MediaProperties.VCODEC_H264:
case MediaProperties.VCODEC_MPEG4:
- level = native_get_videoeditor_export_profile(vidCodec);
+ level = native_get_videoeditor_export_level(vidCodec);
break;
default :
throw new IllegalArgumentException("Unsupported video codec" + vidCodec);
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index bb91fa9..853a5f6 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -727,6 +727,14 @@
}
+void AudioSystem::clearAudioConfigCache()
+{
+ Mutex::Autolock _l(gLock);
+ LOGV("clearAudioConfigCache()");
+ gStreamOutputMap.clear();
+ gOutputs.clear();
+}
+
// ---------------------------------------------------------------------------
void AudioSystem::AudioPolicyServiceClient::binderDied(const wp<IBinder>& who) {
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index cecedb5..3b6c64d 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -1164,6 +1164,10 @@
cblk->cv.broadcast();
cblk->lock.unlock();
+ // refresh the audio configuration cache in this process to make sure we get new
+ // output parameters in getOutput_l() and createTrack_l()
+ AudioSystem::clearAudioConfigCache();
+
// if the new IAudioTrack is created, createTrack_l() will modify the
// following member variables: mAudioTrack, mCblkMemory and mCblk.
// It will also delete the strong references on previous IAudioTrack and IMemory
diff --git a/media/libstagefright/AACExtractor.cpp b/media/libstagefright/AACExtractor.cpp
index a5a6b64..52b1200 100644
--- a/media/libstagefright/AACExtractor.cpp
+++ b/media/libstagefright/AACExtractor.cpp
@@ -33,8 +33,6 @@
namespace android {
-#define ADTS_HEADER_LENGTH 7
-
class AACSource : public MediaSource {
public:
AACSource(const sp<DataSource> &source,
@@ -88,7 +86,16 @@
return 0;
}
-static size_t getFrameSize(const sp<DataSource> &source, off64_t offset) {
+// Returns the frame length in bytes as described in an ADTS header starting at the given offset,
+// or 0 if the size can't be read due to an error in the header or a read failure.
+// The returned value is the AAC frame size with the ADTS header length (regardless of
+// the presence of the CRC).
+// If headerSize is non-NULL, it will be used to return the size of the header of this ADTS frame.
+static size_t getAdtsFrameLength(const sp<DataSource> &source, off64_t offset, size_t* headerSize) {
+
+ const size_t kAdtsHeaderLengthNoCrc = 7;
+ const size_t kAdtsHeaderLengthWithCrc = 9;
+
size_t frameSize = 0;
uint8_t syncword[2];
@@ -111,7 +118,15 @@
}
frameSize = (header[0] & 0x3) << 11 | header[1] << 3 | header[2] >> 5;
- frameSize += ADTS_HEADER_LENGTH + protectionAbsent ? 0 : 2;
+
+ // protectionAbsent is 0 if there is CRC
+ size_t headSize = protectionAbsent ? kAdtsHeaderLengthNoCrc : kAdtsHeaderLengthWithCrc;
+ if (headSize > frameSize) {
+ return 0;
+ }
+ if (headerSize != NULL) {
+ *headerSize = headSize;
+ }
return frameSize;
}
@@ -148,7 +163,7 @@
if (mDataSource->getSize(&streamSize) == OK) {
while (offset < streamSize) {
- if ((frameSize = getFrameSize(source, offset)) == 0) {
+ if ((frameSize = getAdtsFrameLength(source, offset, NULL)) == 0) {
return;
}
@@ -268,8 +283,8 @@
}
}
- size_t frameSize, frameSizeWithoutHeader;
- if ((frameSize = getFrameSize(mDataSource, mOffset)) == 0) {
+ size_t frameSize, frameSizeWithoutHeader, headerSize;
+ if ((frameSize = getAdtsFrameLength(mDataSource, mOffset, &headerSize)) == 0) {
return ERROR_END_OF_STREAM;
}
@@ -279,8 +294,8 @@
return err;
}
- frameSizeWithoutHeader = frameSize - ADTS_HEADER_LENGTH;
- if (mDataSource->readAt(mOffset + ADTS_HEADER_LENGTH, buffer->data(),
+ frameSizeWithoutHeader = frameSize - headerSize;
+ if (mDataSource->readAt(mOffset + headerSize, buffer->data(),
frameSizeWithoutHeader) != (ssize_t)frameSizeWithoutHeader) {
buffer->release();
buffer = NULL;
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index d617af8..94efa74 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1362,6 +1362,7 @@
for (int stream = 0; stream < AUDIO_STREAM_CNT; stream++) {
mStreamTypes[stream].volume = mAudioFlinger->streamVolumeInternal(stream);
mStreamTypes[stream].mute = mAudioFlinger->streamMute(stream);
+ mStreamTypes[stream].valid = true;
}
}
@@ -1530,6 +1531,14 @@
chain->setStrategy(AudioSystem::getStrategyForStream((audio_stream_type_t)track->type()));
chain->incTrackCnt();
}
+
+ // invalidate track immediately if the stream type was moved to another thread since
+ // createTrack() was called by the client process.
+ if (!mStreamTypes[streamType].valid) {
+ LOGW("createTrack_l() on thread %p: invalidating track on stream %d",
+ this, streamType);
+ android_atomic_or(CBLK_INVALID_ON, &track->mCblk->flags);
+ }
}
lStatus = NO_ERROR;
@@ -2219,6 +2228,14 @@
}
}
+void AudioFlinger::PlaybackThread::setStreamValid(int streamType, bool valid)
+{
+ LOGV ("PlaybackThread::setStreamValid() thread %p, streamType %d, valid %d",
+ this, streamType, valid);
+ Mutex::Autolock _l(mLock);
+
+ mStreamTypes[streamType].valid = valid;
+}
// getTrackName_l() must be called with ThreadBase::mLock held
int AudioFlinger::MixerThread::getTrackName_l()
@@ -5074,11 +5091,14 @@
LOGV("setStreamOutput() stream %d to output %d", stream, output);
audioConfigChanged_l(AudioSystem::STREAM_CONFIG_CHANGED, output, &stream);
+ dstThread->setStreamValid(stream, true);
+
for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
if (thread != dstThread &&
thread->type() != ThreadBase::DIRECT) {
MixerThread *srcThread = (MixerThread *)thread;
+ srcThread->setStreamValid(stream, false);
srcThread->invalidateTracks(stream);
}
}
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 1ceb0ec..2e05593 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -751,14 +751,18 @@
virtual uint32_t hasAudioSession(int sessionId);
virtual uint32_t getStrategyForSession_l(int sessionId);
+ void setStreamValid(int streamType, bool valid);
+
struct stream_type_t {
stream_type_t()
: volume(1.0f),
- mute(false)
+ mute(false),
+ valid(true)
{
}
float volume;
bool mute;
+ bool valid;
};
protected:
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index bfca851..3815c3b 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -17,6 +17,8 @@
package com.android.server;
import static android.Manifest.permission.MANAGE_NETWORK_POLICY;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
import static android.net.ConnectivityManager.isNetworkTypeValid;
import static android.net.NetworkPolicyManager.RULE_ALLOW_ALL;
import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
@@ -1418,6 +1420,9 @@
// do this before we broadcast the change
handleConnectivityChange(prevNetType, doReset);
+ final Intent immediateIntent = new Intent(intent);
+ immediateIntent.setAction(CONNECTIVITY_ACTION_IMMEDIATE);
+ sendStickyBroadcast(immediateIntent);
sendStickyBroadcastDelayed(intent, getConnectivityChangeDelay());
/*
* If the failover network is already connected, then immediately send
@@ -1476,11 +1481,13 @@
}
private void sendConnectedBroadcast(NetworkInfo info) {
- sendGeneralBroadcast(info, ConnectivityManager.CONNECTIVITY_ACTION);
+ sendGeneralBroadcast(info, CONNECTIVITY_ACTION_IMMEDIATE);
+ sendGeneralBroadcast(info, CONNECTIVITY_ACTION);
}
private void sendConnectedBroadcastDelayed(NetworkInfo info, int delayMs) {
- sendGeneralBroadcastDelayed(info, ConnectivityManager.CONNECTIVITY_ACTION, delayMs);
+ sendGeneralBroadcast(info, CONNECTIVITY_ACTION_IMMEDIATE);
+ sendGeneralBroadcastDelayed(info, CONNECTIVITY_ACTION, delayMs);
}
private void sendInetConditionBroadcast(NetworkInfo info) {
@@ -1559,6 +1566,10 @@
}
intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
+
+ final Intent immediateIntent = new Intent(intent);
+ immediateIntent.setAction(CONNECTIVITY_ACTION_IMMEDIATE);
+ sendStickyBroadcast(immediateIntent);
sendStickyBroadcast(intent);
/*
* If the failover network is already connected, then immediately send
@@ -1576,8 +1587,7 @@
}
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
if (DBG) {
- log("sendStickyBroadcast: NetworkInfo=" +
- intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO));
+ log("sendStickyBroadcast: action=" + intent.getAction());
}
mContext.sendStickyBroadcast(intent);
@@ -1588,7 +1598,10 @@
if (delayMs <= 0) {
sendStickyBroadcast(intent);
} else {
- if (DBG) log("sendStickyBroadcastDelayed: delayMs=" + delayMs + " intent=" + intent);
+ if (DBG) {
+ log("sendStickyBroadcastDelayed: delayMs=" + delayMs + ", action="
+ + intent.getAction());
+ }
mHandler.sendMessageDelayed(mHandler.obtainMessage(
EVENT_SEND_STICKY_BROADCAST_INTENT, intent), delayMs);
}
@@ -2281,7 +2294,6 @@
case EVENT_SEND_STICKY_BROADCAST_INTENT:
{
Intent intent = (Intent)msg.obj;
- log("EVENT_SEND_STICKY_BROADCAST_INTENT: sendStickyBroadcast intent=" + intent);
sendStickyBroadcast(intent);
break;
}
diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java
index 7a3a344..6ee20bb 100755
--- a/services/java/com/android/server/NotificationManagerService.java
+++ b/services/java/com/android/server/NotificationManagerService.java
@@ -101,6 +101,7 @@
private Vibrator mVibrator = new Vibrator();
// for enabling and disabling notification pulse behavior
+ private boolean mScreenOn = true;
private boolean mInCall = false;
private boolean mNotificationPulseEnabled;
@@ -344,9 +345,19 @@
cancelAllNotificationsInt(pkgName, 0, 0, !queryRestart);
}
}
+ } else if (action.equals(Intent.ACTION_SCREEN_ON)) {
+ // Keep track of screen on/off state, but do not turn off the notification light
+ // until user passes through the lock screen or views the notification.
+ mScreenOn = true;
+ } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
+ mScreenOn = false;
} else if (action.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
- mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_OFFHOOK));
+ mInCall = (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
+ TelephonyManager.EXTRA_STATE_OFFHOOK));
updateNotificationPulse();
+ } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
+ // turn off LED when user passes through lock screen
+ mNotificationLight.turnOff();
}
}
};
@@ -417,6 +428,7 @@
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
+ filter.addAction(Intent.ACTION_USER_PRESENT);
mContext.registerReceiver(mIntentReceiver, filter);
IntentFilter pkgFilter = new IntentFilter();
pkgFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
@@ -1057,8 +1069,8 @@
}
}
- // Don't flash while we are in a call
- if (mLedNotification == null || mInCall) {
+ // Don't flash while we are in a call or screen is on
+ if (mLedNotification == null || mInCall || mScreenOn) {
mNotificationLight.turnOff();
} else {
int ledARGB = mLedNotification.notification.ledARGB;
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java
index 77f53c2..8af90ff 100644
--- a/services/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -26,7 +26,7 @@
import static android.content.Intent.ACTION_PACKAGE_ADDED;
import static android.content.Intent.ACTION_UID_REMOVED;
import static android.content.Intent.EXTRA_UID;
-import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
import static android.net.ConnectivityManager.TYPE_ETHERNET;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_WIFI;
@@ -51,6 +51,7 @@
import static android.net.NetworkTemplate.buildTemplateMobileAll;
import static android.text.format.DateUtils.DAY_IN_MILLIS;
import static com.android.internal.util.Preconditions.checkNotNull;
+import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT;
import static com.android.server.net.NetworkPolicyManagerService.XmlUtils.readBooleanAttribute;
import static com.android.server.net.NetworkPolicyManagerService.XmlUtils.readIntAttribute;
import static com.android.server.net.NetworkPolicyManagerService.XmlUtils.readLongAttribute;
@@ -60,7 +61,6 @@
import static com.android.server.net.NetworkStatsService.ACTION_NETWORK_STATS_UPDATED;
import static org.xmlpull.v1.XmlPullParser.END_DOCUMENT;
import static org.xmlpull.v1.XmlPullParser.START_TAG;
-import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT;
import android.app.IActivityManager;
import android.app.INotificationManager;
@@ -321,7 +321,7 @@
mContext.registerReceiver(mScreenReceiver, screenFilter, null, mHandler);
// watch for network interfaces to be claimed
- final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION);
+ final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION_IMMEDIATE);
mContext.registerReceiver(mConnReceiver, connFilter, CONNECTIVITY_INTERNAL, mHandler);
// listen for package/uid changes to update policy
diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java
index bb0a0d1..e0dc96f 100644
--- a/services/java/com/android/server/net/NetworkStatsService.java
+++ b/services/java/com/android/server/net/NetworkStatsService.java
@@ -24,7 +24,7 @@
import static android.content.Intent.ACTION_SHUTDOWN;
import static android.content.Intent.ACTION_UID_REMOVED;
import static android.content.Intent.EXTRA_UID;
-import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
import static android.net.NetworkStats.IFACE_ALL;
import static android.net.NetworkStats.SET_ALL;
import static android.net.NetworkStats.SET_DEFAULT;
@@ -239,7 +239,7 @@
}
// watch for network interfaces to be claimed
- final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION);
+ final IntentFilter connFilter = new IntentFilter(CONNECTIVITY_ACTION_IMMEDIATE);
mContext.registerReceiver(mConnReceiver, connFilter, CONNECTIVITY_INTERNAL, mHandler);
// listen for periodic polling events
diff --git a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
index f67d251..e892b5e 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkPolicyManagerServiceTest.java
@@ -18,7 +18,7 @@
import static android.content.Intent.ACTION_UID_REMOVED;
import static android.content.Intent.EXTRA_UID;
-import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.NetworkPolicy.LIMIT_DISABLED;
import static android.net.NetworkPolicy.SNOOZE_NEVER;
@@ -511,7 +511,7 @@
future = expectMeteredIfacesChanged();
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
future.get();
verifyAndReset();
@@ -615,7 +615,7 @@
future = expectMeteredIfacesChanged(TEST_IFACE);
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
future.get();
verifyAndReset();
}
diff --git a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java
index 6dd8cd6..54f3bb0 100644
--- a/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/NetworkStatsServiceTest.java
@@ -18,7 +18,7 @@
import static android.content.Intent.ACTION_UID_REMOVED;
import static android.content.Intent.EXTRA_UID;
-import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
+import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE;
import static android.net.ConnectivityManager.TYPE_MOBILE;
import static android.net.ConnectivityManager.TYPE_WIFI;
import static android.net.ConnectivityManager.TYPE_WIMAX;
@@ -180,7 +180,7 @@
expectNetworkStatsSummary(buildEmptyStats());
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
// verify service has empty history for wifi
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
@@ -232,7 +232,7 @@
expectNetworkStatsSummary(buildEmptyStats());
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
// verify service has empty history for wifi
assertNetworkTotal(sTemplateWifi, 0L, 0L, 0L, 0L, 0);
@@ -322,7 +322,7 @@
expectNetworkStatsSummary(buildEmptyStats());
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
verifyAndReset();
// modify some number on wifi, and trigger poll event
@@ -372,7 +372,7 @@
expectNetworkStatsSummary(buildEmptyStats());
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
verifyAndReset();
// create some traffic on first network
@@ -410,7 +410,7 @@
expectNetworkStatsPoll();
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
verifyAndReset();
@@ -452,7 +452,7 @@
expectNetworkStatsSummary(buildEmptyStats());
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
verifyAndReset();
// create some traffic
@@ -509,7 +509,7 @@
expectNetworkStatsSummary(buildEmptyStats());
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
verifyAndReset();
// create some traffic
@@ -541,7 +541,7 @@
expectNetworkStatsPoll();
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
mServiceContext.sendBroadcast(new Intent(ACTION_NETWORK_STATS_POLL));
verifyAndReset();
@@ -575,7 +575,7 @@
expectNetworkStatsSummary(buildEmptyStats());
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
verifyAndReset();
// create some traffic for two apps
@@ -637,7 +637,7 @@
expectNetworkStatsSummary(buildEmptyStats());
replay();
- mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION));
+ mServiceContext.sendBroadcast(new Intent(CONNECTIVITY_ACTION_IMMEDIATE));
verifyAndReset();
// create some initial traffic
diff --git a/tests/BandwidthTests/Android.mk b/tests/BandwidthTests/Android.mk
new file mode 100644
index 0000000..2cc2009
--- /dev/null
+++ b/tests/BandwidthTests/Android.mk
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2011 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.
+#
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_PACKAGE_NAME := BandwidthEnforcementTest
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+include $(BUILD_PACKAGE)
\ No newline at end of file
diff --git a/tests/BandwidthTests/AndroidManifest.xml b/tests/BandwidthTests/AndroidManifest.xml
new file mode 100644
index 0000000..19f38ca
--- /dev/null
+++ b/tests/BandwidthTests/AndroidManifest.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.tests.bandwidthenforcement">
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <application>
+ <activity android:name=".BandwidthEnforcementTestActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <!-- adb shell am startservice -n com.android.tests.bandwidthenforcement/.BandwidthEnforcementTestService -->
+ <service android:name=".BandwidthEnforcementTestService" android:exported="true" />
+ </application>
+</manifest>
diff --git a/tests/BandwidthTests/res/layout/main.xml b/tests/BandwidthTests/res/layout/main.xml
new file mode 100644
index 0000000..3392b21
--- /dev/null
+++ b/tests/BandwidthTests/res/layout/main.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/app_name" />
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/app_desc" />
+</LinearLayout>
diff --git a/tests/BandwidthTests/res/values/strings.xml b/tests/BandwidthTests/res/values/strings.xml
new file mode 100644
index 0000000..a4a78c2
--- /dev/null
+++ b/tests/BandwidthTests/res/values/strings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 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.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="app_name">BandwidthEnforcementTest</string>
+ <string name="app_desc">Tries several tricks to get Internet access.</string>
+ <string name="start">Start</string>
+ <string name="stop">Stop</string>
+</resources>
diff --git a/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestActivity.java b/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestActivity.java
new file mode 100644
index 0000000..f0e43ac
--- /dev/null
+++ b/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestActivity.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+package com.android.tests.bandwidthenforcement;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class BandwidthEnforcementTestActivity extends Activity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ }
+}
diff --git a/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestService.java b/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestService.java
new file mode 100644
index 0000000..a2427f5
--- /dev/null
+++ b/tests/BandwidthTests/src/com/android/tests/bandwidthenforcement/BandwidthEnforcementTestService.java
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2011 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.
+ */
+package com.android.tests.bandwidthenforcement;
+
+import android.app.IntentService;
+import android.content.Intent;
+import android.net.SntpClient;
+import android.os.Environment;
+import android.util.Log;
+
+import java.io.BufferedWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.HttpURLConnection;
+import java.net.InetAddress;
+import java.net.URL;
+import java.util.Random;
+
+import libcore.io.Streams;
+
+/*
+ * Test Service that tries to connect to the web via different methods and outputs the results to
+ * the log and a output file.
+ */
+public class BandwidthEnforcementTestService extends IntentService {
+ private static final String TAG = "BandwidthEnforcementTestService";
+ private static final String OUTPUT_FILE = "BandwidthEnforcementTestServiceOutputFile";
+
+ public BandwidthEnforcementTestService() {
+ super(TAG);
+ }
+
+ @Override
+ protected void onHandleIntent(Intent intent) {
+ Log.d(TAG, "Trying to establish a connection.");
+ // Read output file path from intent.
+ String outputFile = intent.getStringExtra(OUTPUT_FILE);
+ dumpResult("testUrlConnection", testUrlConnection(), outputFile);
+ dumpResult("testUrlConnectionv6", testUrlConnectionv6(), outputFile);
+ dumpResult("testSntp", testSntp(), outputFile);
+ dumpResult("testDns", testDns(), outputFile);
+ }
+
+ public static void dumpResult(String tag, boolean result, String outputFile) {
+ Log.d(TAG, "Test output file: " + outputFile);
+ try {
+ if (outputFile != null){
+ File extStorage = Environment.getExternalStorageDirectory();
+ File outFile = new File(extStorage, outputFile);
+ FileWriter writer = new FileWriter(outFile, true);
+ BufferedWriter out = new BufferedWriter(writer);
+ if (result) {
+ out.append(tag + ":fail\n");
+ } else {
+ out.append(tag + ":pass\n");
+ }
+ out.close();
+ }
+ if (result) {
+ Log.e(TAG, tag + " FAILURE ====================");
+ Log.e(TAG, tag + " FAILURE was able to use data");
+ Log.e(TAG, tag + " FAILURE ====================");
+ } else {
+ Log.d(TAG, tag + " success; unable to use data");
+ }
+ } catch (IOException e) {
+ Log.e(TAG, "Could not write file " + e.getMessage());
+ }
+ }
+
+ /**
+ * Tests a normal http url connection.
+ * @return true if it was able to connect, false otherwise.
+ */
+ public static boolean testUrlConnection() {
+ try {
+ final HttpURLConnection conn = (HttpURLConnection) new URL("http://www.google.com/")
+ .openConnection();
+ try {
+ conn.connect();
+ final String content = Streams.readFully(
+ new InputStreamReader(conn.getInputStream()));
+ if (content.contains("Google")) {
+ return true;
+ }
+ } finally {
+ conn.disconnect();
+ }
+ } catch (IOException e) {
+ Log.d(TAG, "error: " + e);
+ }
+ return false;
+ }
+
+ /**
+ * Tests a ipv6 http url connection.
+ * @return true if it was able to connect, false otherwise.
+ */
+ public static boolean testUrlConnectionv6() {
+ try {
+ final HttpURLConnection conn = (HttpURLConnection) new URL("http://ipv6.google.com/")
+ .openConnection();
+ try {
+ conn.connect();
+ final String content = Streams.readFully(
+ new InputStreamReader(conn.getInputStream()));
+ if (content.contains("Google")) {
+ return true;
+ }
+ } finally {
+ conn.disconnect();
+ }
+ } catch (IOException e) {
+ Log.d(TAG, "error: " + e);
+ }
+ return false;
+ }
+
+ /**
+ * Tests to connect via sntp.
+ * @return true if it was able to connect, false otherwise.
+ */
+ public static boolean testSntp() {
+ final SntpClient client = new SntpClient();
+ if (client.requestTime("0.pool.ntp.org", 10000)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Tests dns query.
+ * @return true if it was able to connect, false otherwise.
+ */
+ public static boolean testDns() {
+ try {
+ final DatagramSocket socket = new DatagramSocket();
+ try {
+ socket.setSoTimeout(10000);
+
+ final byte[] query = buildDnsQuery("www", "android", "com");
+ final DatagramPacket queryPacket = new DatagramPacket(
+ query, query.length, InetAddress.parseNumericAddress("8.8.8.8"), 53);
+ socket.send(queryPacket);
+
+ final byte[] reply = new byte[query.length];
+ final DatagramPacket replyPacket = new DatagramPacket(reply, reply.length);
+ socket.receive(replyPacket);
+ return true;
+
+ } finally {
+ socket.close();
+ }
+ } catch (IOException e) {
+ Log.d(TAG, "error: " + e);
+ }
+ return false;
+ }
+
+ /**
+ * Helper method to build a dns query
+ * @param query the dns strings of the server
+ * @return the byte array of the dns query to send
+ * @throws IOException
+ */
+ private static byte[] buildDnsQuery(String... query) throws IOException {
+ final Random random = new Random();
+ final ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ final byte[] id = new byte[2];
+ random.nextBytes(id);
+
+ out.write(id);
+ out.write(new byte[] { 0x01, 0x00 });
+ out.write(new byte[] { 0x00, 0x01 });
+ out.write(new byte[] { 0x00, 0x00 });
+ out.write(new byte[] { 0x00, 0x00 });
+ out.write(new byte[] { 0x00, 0x00 });
+
+ for (String phrase : query) {
+ final byte[] bytes = phrase.getBytes("US-ASCII");
+ out.write(bytes.length);
+ out.write(bytes);
+ }
+ out.write(0x00);
+
+ out.write(new byte[] { 0x00, 0x01 });
+ out.write(new byte[] { 0x00, 0x01 });
+
+ return out.toByteArray();
+ }
+}