Merge "New broadcast telling when an app is fully removed."
diff --git a/api/current.txt b/api/current.txt
index 759e069..b291e4d 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -23,6 +23,7 @@
field public static final java.lang.String BIND_INPUT_METHOD = "android.permission.BIND_INPUT_METHOD";
field public static final java.lang.String BIND_REMOTEVIEWS = "android.permission.BIND_REMOTEVIEWS";
field public static final java.lang.String BIND_TEXT_SERVICE = "android.permission.BIND_TEXT_SERVICE";
+ field public static final java.lang.String BIND_VPN_SERVICE = "android.permission.BIND_VPN_SERVICE";
field public static final java.lang.String BIND_WALLPAPER = "android.permission.BIND_WALLPAPER";
field public static final java.lang.String BLUETOOTH = "android.permission.BLUETOOTH";
field public static final java.lang.String BLUETOOTH_ADMIN = "android.permission.BLUETOOTH_ADMIN";
@@ -3726,6 +3727,7 @@
field public static final java.lang.String EXTRA_DATA_KEY = "intent_extra_data_key";
field public static final java.lang.String EXTRA_NEW_SEARCH = "new_search";
field public static final java.lang.String EXTRA_SELECT_QUERY = "select_query";
+ field public static final java.lang.String EXTRA_WEB_SEARCH_PENDINGINTENT = "web_search_pendingintent";
field public static final int FLAG_QUERY_REFINEMENT = 1; // 0x1
field public static final java.lang.String INTENT_ACTION_GLOBAL_SEARCH = "android.search.action.GLOBAL_SEARCH";
field public static final java.lang.String INTENT_ACTION_SEARCHABLES_CHANGED = "android.search.action.SEARCHABLES_CHANGED";
@@ -11758,6 +11760,32 @@
method public abstract java.lang.String sanitize(java.lang.String);
}
+ public class VpnService extends android.app.Service {
+ ctor public VpnService();
+ method public android.os.IBinder onBind(android.content.Intent);
+ method public void onRevoke();
+ method public static android.content.Intent prepare(android.content.Context);
+ method public boolean protect(int);
+ method public boolean protect(java.net.Socket);
+ method public boolean protect(java.net.DatagramSocket);
+ field public static final java.lang.String SERVICE_INTERFACE = "android.net.VpnService";
+ }
+
+ public class VpnService.Builder {
+ ctor public VpnService.Builder();
+ method public android.net.VpnService.Builder addAddress(java.net.InetAddress, int);
+ method public android.net.VpnService.Builder addAddress(java.lang.String, int);
+ method public android.net.VpnService.Builder addDnsServer(java.net.InetAddress);
+ method public android.net.VpnService.Builder addDnsServer(java.lang.String);
+ method public android.net.VpnService.Builder addRoute(java.net.InetAddress, int);
+ method public android.net.VpnService.Builder addRoute(java.lang.String, int);
+ method public android.net.VpnService.Builder addSearchDomain(java.lang.String);
+ method public android.os.ParcelFileDescriptor establish();
+ method public android.net.VpnService.Builder setConfigureIntent(android.app.PendingIntent);
+ method public android.net.VpnService.Builder setMtu(int);
+ method public android.net.VpnService.Builder setSession(java.lang.String);
+ }
+
}
package android.net.http {
diff --git a/core/java/android/app/SearchManager.java b/core/java/android/app/SearchManager.java
index 7274362..5c4cc87 100644
--- a/core/java/android/app/SearchManager.java
+++ b/core/java/android/app/SearchManager.java
@@ -145,6 +145,14 @@
public final static String EXTRA_NEW_SEARCH = "new_search";
/**
+ * Extra data key for {@link Intent#ACTION_WEB_SEARCH}. If set, the value must be a
+ * {@link PendingIntent}. The search activity handling the {@link Intent#ACTION_WEB_SEARCH}
+ * intent will fill in and launch the pending intent. The data URI will be filled in with an
+ * http or https URI, and {@link android.provider.Browser#EXTRA_HEADERS} may be filled in.
+ */
+ public static final String EXTRA_WEB_SEARCH_PENDINGINTENT = "web_search_pendingintent";
+
+ /**
* Boolean extra data key for a suggestion provider to return in {@link Cursor#getExtras} to
* indicate that the search is not complete yet. This can be used by the search UI
* to indicate that a search is in progress. The suggestion provider can return partial results
diff --git a/core/java/android/content/pm/ManifestDigest.aidl b/core/java/android/content/pm/ManifestDigest.aidl
new file mode 100755
index 0000000..ebabab0
--- /dev/null
+++ b/core/java/android/content/pm/ManifestDigest.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright 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 android.content.pm;
+
+parcelable ManifestDigest;
diff --git a/core/java/android/content/pm/ManifestDigest.java b/core/java/android/content/pm/ManifestDigest.java
new file mode 100644
index 0000000..f5e72e0
--- /dev/null
+++ b/core/java/android/content/pm/ManifestDigest.java
@@ -0,0 +1,114 @@
+package android.content.pm;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.Base64;
+
+import java.util.Arrays;
+import java.util.jar.Attributes;
+
+/**
+ * Represents the manifest digest for a package. This is suitable for comparison
+ * of two packages to know whether the manifests are identical.
+ *
+ * @hide
+ */
+public class ManifestDigest implements Parcelable {
+ /** The digest of the manifest in our preferred order. */
+ private final byte[] mDigest;
+
+ /** Digest field names to look for in preferred order. */
+ private static final String[] DIGEST_TYPES = {
+ "SHA1-Digest", "SHA-Digest", "MD5-Digest",
+ };
+
+ /** What we print out first when toString() is called. */
+ private static final String TO_STRING_PREFIX = "ManifestDigest {mDigest=";
+
+ ManifestDigest(byte[] digest) {
+ mDigest = digest;
+ }
+
+ private ManifestDigest(Parcel source) {
+ mDigest = source.createByteArray();
+ }
+
+ static ManifestDigest fromAttributes(Attributes attributes) {
+ if (attributes == null) {
+ return null;
+ }
+
+ String encodedDigest = null;
+
+ for (int i = 0; i < DIGEST_TYPES.length; i++) {
+ final String value = attributes.getValue(DIGEST_TYPES[i]);
+ if (value != null) {
+ encodedDigest = value;
+ break;
+ }
+ }
+
+ if (encodedDigest == null) {
+ return null;
+ }
+
+ final byte[] digest = Base64.decode(encodedDigest, Base64.DEFAULT);
+ return new ManifestDigest(digest);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (!(o instanceof ManifestDigest)) {
+ return false;
+ }
+
+ final ManifestDigest other = (ManifestDigest) o;
+
+ return this == other || Arrays.equals(mDigest, other.mDigest);
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(mDigest);
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder(TO_STRING_PREFIX.length()
+ + (mDigest.length * 3) + 1);
+
+ sb.append(TO_STRING_PREFIX);
+
+ final int N = mDigest.length;
+ for (int i = 0; i < N; i++) {
+ final byte b = mDigest[i];
+ IntegralToString.appendByteAsHex(sb, b, false);
+ sb.append(',');
+ }
+ sb.append('}');
+
+ return sb.toString();
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeByteArray(mDigest);
+ }
+
+ public static final Parcelable.Creator<ManifestDigest> CREATOR
+ = new Parcelable.Creator<ManifestDigest>() {
+ public ManifestDigest createFromParcel(Parcel source) {
+ return new ManifestDigest(source);
+ }
+
+ public ManifestDigest[] newArray(int size) {
+ return new ManifestDigest[size];
+ }
+ };
+
+}
\ No newline at end of file
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 5f4625b..c61e32f 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
+import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
@@ -59,6 +60,9 @@
private static final boolean DEBUG_PARSER = false;
private static final boolean DEBUG_BACKUP = false;
+ /** File name in an APK for the Android manifest. */
+ private static final String ANDROID_MANIFEST_FILENAME = "AndroidManifest.xml";
+
/** @hide */
public static class NewPermissionInfo {
public final String name;
@@ -402,7 +406,7 @@
res = new Resources(assmgr, metrics, null);
assmgr.setConfiguration(0, 0, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Build.VERSION.RESOURCES_SDK_INT);
- parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
+ parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
assetError = false;
} else {
Slog.w(TAG, "Failed adding asset path:"+mArchiveSourcePath);
@@ -484,7 +488,7 @@
// can trust it... we'll just use the AndroidManifest.xml
// to retrieve its signatures, not validating all of the
// files.
- JarEntry jarEntry = jarFile.getJarEntry("AndroidManifest.xml");
+ JarEntry jarEntry = jarFile.getJarEntry(ANDROID_MANIFEST_FILENAME);
certs = loadCertificates(jarFile, jarEntry, readBuffer);
if (certs == null) {
Slog.e(TAG, "Package " + pkg.packageName
@@ -506,21 +510,30 @@
}
}
}
-
} else {
Enumeration<JarEntry> entries = jarFile.entries();
+ final Manifest manifest = jarFile.getManifest();
while (entries.hasMoreElements()) {
final JarEntry je = entries.nextElement();
if (je.isDirectory()) continue;
- if (je.getName().startsWith("META-INF/")) continue;
- final Certificate[] localCerts = loadCertificates(jarFile, je,
- readBuffer);
+ final String name = je.getName();
+
+ if (name.startsWith("META-INF/"))
+ continue;
+
+ if (ANDROID_MANIFEST_FILENAME.equals(name)) {
+ final Attributes attributes = manifest.getAttributes(name);
+ pkg.manifestDigest = ManifestDigest.fromAttributes(attributes);
+ }
+
+ final Certificate[] localCerts = loadCertificates(jarFile, je, readBuffer);
if (DEBUG_JAR) {
Slog.i(TAG, "File " + mArchiveSourcePath + " entry " + je.getName()
+ ": certs=" + certs + " ("
+ (certs != null ? certs.length : 0) + ")");
}
+
if (localCerts == null) {
Slog.e(TAG, "Package " + pkg.packageName
+ " has no certificates at entry "
@@ -609,7 +622,7 @@
return null;
}
- parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
+ parser = assmgr.openXmlResourceParser(cookie, ANDROID_MANIFEST_FILENAME);
} catch (Exception e) {
if (assmgr != null) assmgr.close();
Slog.w(TAG, "Unable to read AndroidManifest.xml of "
@@ -2884,6 +2897,12 @@
public int installLocation;
+ /**
+ * Digest suitable for comparing whether this package's manifest is the
+ * same as another.
+ */
+ public ManifestDigest manifestDigest;
+
public Package(String _name) {
packageName = _name;
applicationInfo.packageName = _name;
diff --git a/core/java/android/net/VpnService.java b/core/java/android/net/VpnService.java
index 3e1b512..fb5263d 100644
--- a/core/java/android/net/VpnService.java
+++ b/core/java/android/net/VpnService.java
@@ -101,7 +101,6 @@
* </service></pre>
*
* @see Builder
- * @hide
*/
public class VpnService extends Service {
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl
index 9ffc52a..0440923 100644
--- a/core/java/android/os/INetworkManagementService.aidl
+++ b/core/java/android/os/INetworkManagementService.aidl
@@ -64,6 +64,16 @@
void clearInterfaceAddresses(String iface);
/**
+ * Set interface down
+ */
+ void setInterfaceDown(String iface);
+
+ /**
+ * Set interface up
+ */
+ void setInterfaceUp(String iface);
+
+ /**
* Retrieves the network routes currently configured on the specified
* interface
*/
diff --git a/core/java/android/preference/RingtonePreference.java b/core/java/android/preference/RingtonePreference.java
index cf14097..2ebf294 100644
--- a/core/java/android/preference/RingtonePreference.java
+++ b/core/java/android/preference/RingtonePreference.java
@@ -164,6 +164,7 @@
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent);
ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, mRingtoneType);
+ ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getTitle());
}
/**
diff --git a/core/java/android/view/VolumePanel.java b/core/java/android/view/VolumePanel.java
index 662137a..cb85e5f 100644
--- a/core/java/android/view/VolumePanel.java
+++ b/core/java/android/view/VolumePanel.java
@@ -35,6 +35,8 @@
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
+import android.provider.Settings;
+import android.provider.Settings.System;
import android.util.Log;
import android.widget.ImageView;
import android.widget.SeekBar;
@@ -233,6 +235,10 @@
}
private void createSliders() {
+ final int silentableStreams = System.getInt(mContext.getContentResolver(),
+ System.MODE_RINGER_STREAMS_AFFECTED,
+ ((1 << AudioSystem.STREAM_NOTIFICATION) | (1 << AudioSystem.STREAM_RING)));
+
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mStreamControls = new HashMap<Integer,StreamControl>(STREAM_TYPES.length);
@@ -243,7 +249,9 @@
sc.group = (ViewGroup) inflater.inflate(R.layout.volume_adjust_item, null);
sc.group.setTag(sc);
sc.icon = (ImageView) sc.group.findViewById(R.id.stream_icon);
- sc.icon.setOnClickListener(this);
+ if ((silentableStreams & (1 << sc.streamType)) != 0) {
+ sc.icon.setOnClickListener(this);
+ }
sc.icon.setTag(sc);
sc.icon.setContentDescription(res.getString(CONTENT_DESCRIPTIONS[i]));
sc.iconRes = STREAM_ICONS_NORMAL[i];
diff --git a/core/java/android/webkit/WebTextView.java b/core/java/android/webkit/WebTextView.java
index b8c4e22..2a79caa 100644
--- a/core/java/android/webkit/WebTextView.java
+++ b/core/java/android/webkit/WebTextView.java
@@ -1023,7 +1023,8 @@
break;
case NUMBER:
// inputType needs to be overwritten because of the different class.
- inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL;
+ inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL
+ | InputType.TYPE_NUMBER_FLAG_SIGNED | InputType.TYPE_NUMBER_FLAG_DECIMAL;
// Number and telephone do not have both a Tab key and an
// action, so set the action to NEXT
imeOptions |= EditorInfo.IME_ACTION_NEXT;
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index cec3fda..b95fa1b 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -16,6 +16,11 @@
package android.widget;
+import com.android.internal.util.FastMath;
+import com.android.internal.widget.EditableInputConnection;
+
+import org.xmlpull.v1.XmlPullParserException;
+
import android.R;
import android.content.ClipData;
import android.content.ClipData.Item;
@@ -134,11 +139,6 @@
import android.view.inputmethod.InputMethodManager;
import android.widget.RemoteViews.RemoteView;
-import com.android.internal.util.FastMath;
-import com.android.internal.widget.EditableInputConnection;
-
-import org.xmlpull.v1.XmlPullParserException;
-
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.text.BreakIterator;
@@ -9693,6 +9693,10 @@
@Override
public void show() {
mPasteTextView.setVisibility(canPaste() ? View.VISIBLE : View.GONE);
+ mReplaceTextView.setVisibility(mSuggestionsEnabled ? View.VISIBLE : View.GONE);
+
+ if (!canPaste() && !mSuggestionsEnabled) return;
+
super.show();
}
diff --git a/core/java/com/android/internal/app/ActionBarImpl.java b/core/java/com/android/internal/app/ActionBarImpl.java
index 008f400..0df7bcc 100644
--- a/core/java/com/android/internal/app/ActionBarImpl.java
+++ b/core/java/com/android/internal/app/ActionBarImpl.java
@@ -156,8 +156,6 @@
"with a compatible window decor layout");
}
- mHasEmbeddedTabs = mContext.getResources().getBoolean(
- com.android.internal.R.bool.action_bar_embed_tabs);
mActionView.setContextView(mContextView);
mContextDisplayMode = mActionView.isSplitActionBar() ?
CONTEXT_DISPLAY_SPLIT : CONTEXT_DISPLAY_NORMAL;
@@ -166,25 +164,31 @@
// Newer apps need to enable it explicitly.
setHomeButtonEnabled(mContext.getApplicationInfo().targetSdkVersion <
Build.VERSION_CODES.ICE_CREAM_SANDWICH);
+
+ setHasEmbeddedTabs(mContext.getResources().getBoolean(
+ com.android.internal.R.bool.action_bar_embed_tabs));
}
public void onConfigurationChanged(Configuration newConfig) {
- mHasEmbeddedTabs = mContext.getResources().getBoolean(
- com.android.internal.R.bool.action_bar_embed_tabs);
+ setHasEmbeddedTabs(mContext.getResources().getBoolean(
+ com.android.internal.R.bool.action_bar_embed_tabs));
+ }
+ private void setHasEmbeddedTabs(boolean hasEmbeddedTabs) {
+ mHasEmbeddedTabs = hasEmbeddedTabs;
// Switch tab layout configuration if needed
if (!mHasEmbeddedTabs) {
mActionView.setEmbeddedTabView(null);
mContainerView.setTabContainer(mTabScrollView);
} else {
mContainerView.setTabContainer(null);
- if (mTabScrollView != null) {
- mTabScrollView.setVisibility(View.VISIBLE);
- }
mActionView.setEmbeddedTabView(mTabScrollView);
}
- mActionView.setCollapsable(!mHasEmbeddedTabs &&
- getNavigationMode() == NAVIGATION_MODE_TABS);
+ final boolean isInTabMode = getNavigationMode() == NAVIGATION_MODE_TABS;
+ if (mTabScrollView != null) {
+ mTabScrollView.setVisibility(isInTabMode ? View.VISIBLE : View.GONE);
+ }
+ mActionView.setCollapsable(!mHasEmbeddedTabs && isInTabMode);
}
private void ensureTabsExist() {
@@ -192,7 +196,7 @@
return;
}
- ScrollingTabContainerView tabScroller = mActionView.createTabContainer();
+ ScrollingTabContainerView tabScroller = new ScrollingTabContainerView(mContext);
if (mHasEmbeddedTabs) {
tabScroller.setVisibility(View.VISIBLE);
@@ -925,18 +929,14 @@
case NAVIGATION_MODE_TABS:
mSavedTabPosition = getSelectedNavigationIndex();
selectTab(null);
- if (!mActionView.hasEmbeddedTabs()) {
- mTabScrollView.setVisibility(View.GONE);
- }
+ mTabScrollView.setVisibility(View.GONE);
break;
}
mActionView.setNavigationMode(mode);
switch (mode) {
case NAVIGATION_MODE_TABS:
ensureTabsExist();
- if (!mActionView.hasEmbeddedTabs()) {
- mTabScrollView.setVisibility(View.VISIBLE);
- }
+ mTabScrollView.setVisibility(View.VISIBLE);
if (mSavedTabPosition != INVALID_POSITION) {
setSelectedNavigationItem(mSavedTabPosition);
mSavedTabPosition = INVALID_POSITION;
diff --git a/core/java/com/android/internal/widget/ActionBarContainer.java b/core/java/com/android/internal/widget/ActionBarContainer.java
index a2d492b..b4d2d72 100644
--- a/core/java/com/android/internal/widget/ActionBarContainer.java
+++ b/core/java/com/android/internal/widget/ActionBarContainer.java
@@ -102,7 +102,7 @@
return true;
}
- public void setTabContainer(View tabView) {
+ public void setTabContainer(ScrollingTabContainerView tabView) {
if (mTabContainer != null) {
removeView(mTabContainer);
}
@@ -110,6 +110,7 @@
if (tabView != null) {
addView(tabView);
tabView.getLayoutParams().width = LayoutParams.MATCH_PARENT;
+ tabView.setAllowCollapse(false);
}
}
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 61df5c7..181958c 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -332,7 +332,10 @@
mIncludeTabs = tabs != null;
if (mIncludeTabs && mNavigationMode == ActionBar.NAVIGATION_MODE_TABS) {
addView(mTabScrollView);
- mTabScrollView.getLayoutParams().width = LayoutParams.WRAP_CONTENT;
+ ViewGroup.LayoutParams lp = mTabScrollView.getLayoutParams();
+ lp.width = LayoutParams.WRAP_CONTENT;
+ lp.height = LayoutParams.MATCH_PARENT;
+ tabs.setAllowCollapse(true);
}
}
@@ -649,18 +652,6 @@
}
}
- public ScrollingTabContainerView createTabContainer() {
- final LinearLayout tabLayout = new LinearLayout(getContext(), null,
- com.android.internal.R.attr.actionBarTabBarStyle);
- tabLayout.setMeasureWithLargestChildEnabled(true);
- tabLayout.setLayoutParams(new LinearLayout.LayoutParams(
- LinearLayout.LayoutParams.WRAP_CONTENT, mContentHeight));
-
- final ScrollingTabContainerView scroller = new ScrollingTabContainerView(mContext);
- scroller.setTabLayout(tabLayout);
- return scroller;
- }
-
public void setDropdownAdapter(SpinnerAdapter adapter) {
mSpinnerAdapter = adapter;
if (mSpinner != null) {
diff --git a/core/java/com/android/internal/widget/ScrollingTabContainerView.java b/core/java/com/android/internal/widget/ScrollingTabContainerView.java
index 718d249..0e4c9ef 100644
--- a/core/java/com/android/internal/widget/ScrollingTabContainerView.java
+++ b/core/java/com/android/internal/widget/ScrollingTabContainerView.java
@@ -30,18 +30,32 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.Spinner;
import android.widget.TextView;
-public class ScrollingTabContainerView extends HorizontalScrollView {
+/**
+ * This widget implements the dynamic action bar tab behavior that can change
+ * across different configurations or circumstances.
+ */
+public class ScrollingTabContainerView extends HorizontalScrollView
+ implements AdapterView.OnItemSelectedListener {
+ private static final String TAG = "ScrollingTabContainerView";
Runnable mTabSelector;
private TabClickListener mTabClickListener;
private LinearLayout mTabLayout;
+ private Spinner mTabSpinner;
+ private boolean mAllowCollapse;
int mMaxTabWidth;
+ private int mContentHeight;
+ private int mSelectedTabIndex;
protected Animator mVisibilityAnim;
protected final VisibilityAnimListener mVisAnimListener = new VisibilityAnimListener();
@@ -53,14 +67,19 @@
public ScrollingTabContainerView(Context context) {
super(context);
setHorizontalScrollBarEnabled(false);
+
+ mTabLayout = createTabLayout();
+ addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
- setFillViewport(widthMode == MeasureSpec.EXACTLY);
+ final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY;
+ setFillViewport(lockedExpanded);
- final int childCount = getChildCount();
+ final int childCount = mTabLayout.getChildCount();
if (childCount > 1 &&
(widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) {
if (childCount > 2) {
@@ -72,14 +91,85 @@
mMaxTabWidth = -1;
}
+ int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+ int heightSize = MeasureSpec.getSize(heightMeasureSpec);
+ if (heightMode != MeasureSpec.UNSPECIFIED) {
+ if (mContentHeight == 0 && heightMode == MeasureSpec.EXACTLY) {
+ // Use this as our content height.
+ mContentHeight = heightSize;
+ }
+ heightSize = Math.min(heightSize, mContentHeight);
+ heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
+ }
+
+ final boolean canCollapse = !lockedExpanded && mAllowCollapse;
+
+ if (canCollapse) {
+ // See if we should expand
+ mTabLayout.measure(MeasureSpec.UNSPECIFIED, heightMeasureSpec);
+ if (mTabLayout.getMeasuredWidth() > MeasureSpec.getSize(widthMeasureSpec)) {
+ performCollapse();
+ } else {
+ performExpand();
+ }
+ } else {
+ performExpand();
+ }
+
+ final int oldWidth = getMeasuredWidth();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ final int newWidth = getMeasuredWidth();
+
+ if (lockedExpanded && oldWidth != newWidth) {
+ // Recenter the tab display if we're at a new (scrollable) size.
+ setTabSelected(mSelectedTabIndex);
+ }
+ }
+
+ /**
+ * Indicates whether this view is collapsed into a dropdown menu instead
+ * of traditional tabs.
+ * @return true if showing as a spinner
+ */
+ private boolean isCollapsed() {
+ return mTabSpinner != null && mTabSpinner.getParent() == this;
+ }
+
+ public void setAllowCollapse(boolean allowCollapse) {
+ mAllowCollapse = allowCollapse;
+ }
+
+ private void performCollapse() {
+ if (isCollapsed()) return;
+
+ if (mTabSpinner == null) {
+ mTabSpinner = createSpinner();
+ }
+ removeView(mTabLayout);
+ addView(mTabSpinner, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ if (mTabSpinner.getAdapter() == null) {
+ mTabSpinner.setAdapter(new TabAdapter());
+ }
+ if (mTabSelector != null) {
+ removeCallbacks(mTabSelector);
+ mTabSelector = null;
+ }
+ mTabSpinner.setSelection(mSelectedTabIndex);
+ }
+
+ private boolean performExpand() {
+ if (!isCollapsed()) return false;
+
+ removeView(mTabSpinner);
+ addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.MATCH_PARENT));
+ setTabSelected(mTabSpinner.getSelectedItemPosition());
+ return false;
}
public void setTabSelected(int position) {
- if (mTabLayout == null) {
- return;
- }
-
+ mSelectedTabIndex = position;
final int tabCount = mTabLayout.getChildCount();
for (int i = 0; i < tabCount; i++) {
final View child = mTabLayout.getChildAt(i);
@@ -92,10 +182,28 @@
}
public void setContentHeight(int contentHeight) {
- mTabLayout.getLayoutParams().height = contentHeight;
+ mContentHeight = contentHeight;
requestLayout();
}
+ private LinearLayout createTabLayout() {
+ final LinearLayout tabLayout = new LinearLayout(getContext(), null,
+ com.android.internal.R.attr.actionBarTabBarStyle);
+ tabLayout.setMeasureWithLargestChildEnabled(true);
+ tabLayout.setLayoutParams(new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
+ return tabLayout;
+ }
+
+ private Spinner createSpinner() {
+ final Spinner spinner = new Spinner(getContext(), null,
+ com.android.internal.R.attr.actionDropDownStyle);
+ spinner.setLayoutParams(new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT));
+ spinner.setOnItemSelectedListener(this);
+ return spinner;
+ }
+
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
@@ -132,7 +240,7 @@
}
}
- public void animateToTab(int position) {
+ public void animateToTab(final int position) {
final View tabView = mTabLayout.getChildAt(position);
if (mTabSelector != null) {
removeCallbacks(mTabSelector);
@@ -147,22 +255,15 @@
post(mTabSelector);
}
- public void setTabLayout(LinearLayout tabLayout) {
- if (mTabLayout != tabLayout) {
- if (mTabLayout != null) {
- ((ViewGroup) mTabLayout.getParent()).removeView(mTabLayout);
- }
- if (tabLayout != null) {
- addView(tabLayout);
- }
- mTabLayout = tabLayout;
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ if (mTabSelector != null) {
+ // Re-post the selector we saved
+ post(mTabSelector);
}
}
- public LinearLayout getTabLayout() {
- return mTabLayout;
- }
-
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
@@ -171,49 +272,91 @@
}
}
- private TabView createTabView(ActionBar.Tab tab) {
- final TabView tabView = new TabView(getContext(), tab);
- tabView.setFocusable(true);
+ private TabView createTabView(ActionBar.Tab tab, boolean forAdapter) {
+ final TabView tabView = new TabView(getContext(), tab, forAdapter);
+ if (forAdapter) {
+ tabView.setBackgroundDrawable(null);
+ tabView.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
+ mContentHeight));
+ } else {
+ tabView.setFocusable(true);
- if (mTabClickListener == null) {
- mTabClickListener = new TabClickListener();
+ if (mTabClickListener == null) {
+ mTabClickListener = new TabClickListener();
+ }
+ tabView.setOnClickListener(mTabClickListener);
}
- tabView.setOnClickListener(mTabClickListener);
return tabView;
}
public void addTab(ActionBar.Tab tab, boolean setSelected) {
- View tabView = createTabView(tab);
+ TabView tabView = createTabView(tab, false);
mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0,
LayoutParams.MATCH_PARENT, 1));
+ if (mTabSpinner != null) {
+ ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged();
+ }
if (setSelected) {
tabView.setSelected(true);
}
+ if (mAllowCollapse) {
+ requestLayout();
+ }
}
public void addTab(ActionBar.Tab tab, int position, boolean setSelected) {
- final TabView tabView = createTabView(tab);
+ final TabView tabView = createTabView(tab, false);
mTabLayout.addView(tabView, position, new LinearLayout.LayoutParams(
0, LayoutParams.MATCH_PARENT, 1));
+ if (mTabSpinner != null) {
+ ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged();
+ }
if (setSelected) {
tabView.setSelected(true);
}
+ if (mAllowCollapse) {
+ requestLayout();
+ }
}
public void updateTab(int position) {
((TabView) mTabLayout.getChildAt(position)).update();
+ if (mTabSpinner != null) {
+ ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged();
+ }
+ if (mAllowCollapse) {
+ requestLayout();
+ }
}
public void removeTabAt(int position) {
- if (mTabLayout != null) {
- mTabLayout.removeViewAt(position);
+ mTabLayout.removeViewAt(position);
+ if (mTabSpinner != null) {
+ ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged();
+ }
+ if (mAllowCollapse) {
+ requestLayout();
}
}
public void removeAllTabs() {
- if (mTabLayout != null) {
- mTabLayout.removeAllViews();
+ mTabLayout.removeAllViews();
+ if (mTabSpinner != null) {
+ ((TabAdapter) mTabSpinner.getAdapter()).notifyDataSetChanged();
}
+ if (mAllowCollapse) {
+ requestLayout();
+ }
+ }
+
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ TabView tabView = (TabView) view;
+ tabView.getTab().select();
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
}
private class TabView extends LinearLayout {
@@ -222,10 +365,19 @@
private ImageView mIconView;
private View mCustomView;
- public TabView(Context context, ActionBar.Tab tab) {
+ public TabView(Context context, ActionBar.Tab tab, boolean forList) {
super(context, null, com.android.internal.R.attr.actionBarTabStyle);
mTab = tab;
+ if (forList) {
+ setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
+ }
+
+ update();
+ }
+
+ public void bindTab(ActionBar.Tab tab) {
+ mTab = tab;
update();
}
@@ -303,6 +455,33 @@
}
}
+ private class TabAdapter extends BaseAdapter {
+ @Override
+ public int getCount() {
+ return mTabLayout.getChildCount();
+ }
+
+ @Override
+ public Object getItem(int position) {
+ return ((TabView) mTabLayout.getChildAt(position)).getTab();
+ }
+
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = createTabView((ActionBar.Tab) getItem(position), true);
+ } else {
+ ((TabView) convertView).bindTab((ActionBar.Tab) getItem(position));
+ }
+ return convertView;
+ }
+ }
+
private class TabClickListener implements OnClickListener {
public void onClick(View view) {
TabView tabView = (TabView) view;
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index f5dcec4..dc0106c 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -92,8 +92,6 @@
<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.vpn.action.REVOKED" />
-
<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" />
@@ -1120,8 +1118,7 @@
android:protectionLevel="signature" />
<!-- Must be required by an {@link android.net.VpnService},
- to ensure that only the system can bind to it.
- @hide -->
+ to ensure that only the system can bind to it. -->
<permission android:name="android.permission.BIND_VPN_SERVICE"
android:label="@string/permlab_bindVpnService"
android:description="@string/permdesc_bindVpnService"
diff --git a/core/res/res/layout/text_edit_no_paste_window.xml b/core/res/res/layout/text_edit_no_paste_window.xml
index 5e9acc2..c4c0b8a 100644
--- a/core/res/res/layout/text_edit_no_paste_window.xml
+++ b/core/res/res/layout/text_edit_no_paste_window.xml
@@ -30,7 +30,6 @@
android:textAppearance="?android:attr/textAppearanceMediumInverse"
android:textColor="@android:color/dim_foreground_dark_inverse_disabled"
android:background="@android:drawable/text_edit_paste_window"
- android:text="@android:string/pasteDisabled"
android:layout_marginBottom="12dip"
/>
diff --git a/core/res/res/layout/text_edit_side_no_paste_window.xml b/core/res/res/layout/text_edit_side_no_paste_window.xml
index dc411a1..78423a7 100644
--- a/core/res/res/layout/text_edit_side_no_paste_window.xml
+++ b/core/res/res/layout/text_edit_side_no_paste_window.xml
@@ -30,7 +30,6 @@
android:textAppearance="?android:attr/textAppearanceMediumInverse"
android:textColor="@android:color/dim_foreground_dark_inverse_disabled"
android:background="@android:drawable/text_edit_side_paste_window"
- android:text="@android:string/pasteDisabled"
android:layout_marginBottom="12dip"
/>
diff --git a/core/res/res/layout/volume_adjust.xml b/core/res/res/layout/volume_adjust.xml
index 8c580c2..7303003 100644
--- a/core/res/res/layout/volume_adjust.xml
+++ b/core/res/res/layout/volume_adjust.xml
@@ -54,7 +54,6 @@
android:padding="16dip"
android:background="?attr/selectableItemBackground"
android:src="@drawable/ic_sysbar_quicksettings"
- android:contentDescription="@string/volume_panel_more_description"
/>
</LinearLayout>
diff --git a/core/res/res/layout/volume_adjust_item.xml b/core/res/res/layout/volume_adjust_item.xml
index beb511d..fb900f7 100644
--- a/core/res/res/layout/volume_adjust_item.xml
+++ b/core/res/res/layout/volume_adjust_item.xml
@@ -38,7 +38,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="16dip"
- android:layout_marginLeft="8dip"
android:layout_marginRight="8dip" />
</LinearLayout>
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index e534e9b..829f757 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -32,8 +32,12 @@
<dimen name="toast_y_offset">64dip</dimen>
<!-- Height of the status bar -->
<dimen name="status_bar_height">25dip</dimen>
- <!-- Height of the system bar -->
+ <!-- Height of the system bar (combined status + navigation, used on large screens) -->
<dimen name="system_bar_height">48dip</dimen>
+ <!-- Height of the horizontal navigation bar on devices that require it -->
+ <dimen name="navigation_bar_height">48dp</dimen>
+ <!-- Width of the vertical navigation bar on devices that require it -->
+ <dimen name="navigation_bar_width">42dp</dimen>
<!-- Height of notification icons in the status bar -->
<dimen name="status_bar_icon_size">24dip</dimen>
<!-- Size of the giant number (unread count) in the notifications -->
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 4aa8ba2..583310d 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -2403,9 +2403,6 @@
<!-- Item on EditText context menu. This action is used to paste from the clipboard into the eidt field -->
<string name="paste">Paste</string>
- <!-- Text displayed in a popup dialog in TextEdit when the clipboard is empty. 'paste' is used otherwise. [CHAR LIMIT=20] -->
- <string name="pasteDisabled">Nothing to paste</string>
-
<!-- Item on EditText context menu. This action is used to replace the current word by other suggested words, suggested by the IME or the spell checker -->
<string name="replace">Replace</string>
@@ -2553,17 +2550,15 @@
<string name="volume_unknown">Volume</string>
<!-- Content description for bluetooth volume icon [CHAR LIMIT=100] -->
- <string name="volume_icon_description_bluetooth">Bluetooth volume. Tap to toggle silent mode.</string>
+ <string name="volume_icon_description_bluetooth">Bluetooth volume</string>
<!-- Content description for ringer volume icon [CHAR LIMIT=100] -->
- <string name="volume_icon_description_ringer">Ringtone volume. Tap to toggle silent mode.</string>
+ <string name="volume_icon_description_ringer">Ringtone volume</string>
<!-- Content description for in-call volume icon [CHAR LIMIT=100] -->
- <string name="volume_icon_description_incall">Call volume. Tap to toggle silent mode.</string>
+ <string name="volume_icon_description_incall">Call volume</string>
<!-- Content description for media volume icon [CHAR LIMIT=100] -->
- <string name="volume_icon_description_media">Media volume. Tap to toggle silent mode.</string>
+ <string name="volume_icon_description_media">Media volume</string>
<!-- Content description for notification volume icon [CHAR LIMIT=100] -->
- <string name="volume_icon_description_notification">Notification volume. Tap to toggle silent mode.</string>
- <!-- Content description for volume settings expansion button [CHAR LIMIT=100] -->
- <string name="volume_panel_more_description">Tap to show more audio stream volumes.</string>
+ <string name="volume_icon_description_notification">Notification volume</string>
<!-- Ringtone picker strings --> <skip />
<!-- Choice in the ringtone picker. If chosen, the default ringtone will be used. -->
diff --git a/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java
new file mode 100644
index 0000000..8922f27
--- /dev/null
+++ b/core/tests/coretests/src/android/content/pm/ManifestDigestTest.java
@@ -0,0 +1,74 @@
+package android.content.pm;
+
+import android.os.Parcel;
+import android.test.AndroidTestCase;
+import android.util.Base64;
+
+import java.util.jar.Attributes;
+
+public class ManifestDigestTest extends AndroidTestCase {
+ private static final byte[] DIGEST_1 = {
+ (byte) 0x00, (byte) 0xAA, (byte) 0x55, (byte) 0xFF
+ };
+
+ private static final String DIGEST_1_STR = Base64.encodeToString(DIGEST_1, Base64.DEFAULT);
+
+ private static final byte[] DIGEST_2 = {
+ (byte) 0x0A, (byte) 0xA5, (byte) 0xF0, (byte) 0x5A
+ };
+
+ private static final String DIGEST_2_STR = Base64.encodeToString(DIGEST_2, Base64.DEFAULT);
+
+ private static final Attributes.Name SHA1_DIGEST = new Attributes.Name("SHA1-Digest");
+
+ private static final Attributes.Name MD5_DIGEST = new Attributes.Name("MD5-Digest");
+
+ public void testManifestDigest_FromAttributes_Null() {
+ assertNull("Attributes were null, so ManifestDigest.fromAttributes should return null",
+ ManifestDigest.fromAttributes(null));
+ }
+
+ public void testManifestDigest_FromAttributes_NoAttributes() {
+ Attributes a = new Attributes();
+
+ assertNull("There were no attributes to extract, so ManifestDigest should be null",
+ ManifestDigest.fromAttributes(a));
+ }
+
+ public void testManifestDigest_FromAttributes_SHA1PreferredOverMD5() {
+ Attributes a = new Attributes();
+ a.put(SHA1_DIGEST, DIGEST_1_STR);
+
+ a.put(MD5_DIGEST, DIGEST_2_STR);
+
+ ManifestDigest fromAttributes = ManifestDigest.fromAttributes(a);
+
+ assertNotNull("A valid ManifestDigest should be returned", fromAttributes);
+
+ ManifestDigest created = new ManifestDigest(DIGEST_1);
+
+ assertEquals("SHA-1 should be preferred over MD5: " + created.toString() + " vs. "
+ + fromAttributes.toString(), created, fromAttributes);
+
+ assertEquals("Hash codes should be the same: " + created.toString() + " vs. "
+ + fromAttributes.toString(), created.hashCode(), fromAttributes
+ .hashCode());
+ }
+
+ public void testManifestDigest_Parcel() {
+ Attributes a = new Attributes();
+ a.put(SHA1_DIGEST, DIGEST_1_STR);
+
+ ManifestDigest digest = ManifestDigest.fromAttributes(a);
+
+ Parcel p = Parcel.obtain();
+ digest.writeToParcel(p, 0);
+ p.setDataPosition(0);
+
+ ManifestDigest fromParcel = ManifestDigest.CREATOR.createFromParcel(p);
+
+ assertEquals("ManifestDigest going through parceling should be the same as before: "
+ + digest.toString() + " and " + fromParcel.toString(), digest,
+ fromParcel);
+ }
+}
diff --git a/data/keyboards/Generic.kl b/data/keyboards/Generic.kl
index 68a158e..10de6ac 100644
--- a/data/keyboards/Generic.kl
+++ b/data/keyboards/Generic.kl
@@ -105,7 +105,7 @@
key 83 NUMPAD_DOT
# key 84 (undefined)
# key 85 "KEY_ZENKAKUHANKAKU"
-# key 86 "KEY_102ND"
+key 86 BACKSLASH
key 87 F11
key 88 F12
# key 89 "KEY_RO"
@@ -161,8 +161,8 @@
key 139 MENU WAKE_DROPPED
# key 140 "KEY_CALC"
# key 141 "KEY_SETUP"
-# key 142 "KEY_SLEEP"
-# key 143 "KEY_WAKEUP"
+key 142 POWER WAKE
+key 143 POWER WAKE
# key 144 "KEY_FILE"
# key 145 "KEY_SENDFILE"
# key 146 "KEY_DELETEFILE"
@@ -171,7 +171,7 @@
# key 149 "KEY_PROG2"
key 150 EXPLORER
# key 151 "KEY_MSDOS"
-# key 152 "KEY_COFFEE"
+key 152 POWER WAKE
# key 153 "KEY_DIRECTION"
# key 154 "KEY_CYCLEWINDOWS"
key 155 ENVELOPE
@@ -246,20 +246,6 @@
# key 224 "KEY_BRIGHTNESSDOWN"
# key 225 "KEY_BRIGHTNESSUP"
key 226 HEADSETHOOK
-key 227 STAR
-key 228 POUND
-key 229 SOFT_LEFT
-key 230 SOFT_RIGHT
-key 231 CALL
-key 232 DPAD_CENTER
-key 233 HEADSETHOOK
-# key 234 "KEY_0_5" or "KEY_SAVE"
-# key 235 "KEY_2_5" or "KEY_DOCUMENTS"
-# key 236 "KEY_SWITCHVIDEOMODE" or "KEY_BATTERY"
-# key 237 "KEY_KBDILLUMTOGGLE"
-# key 238 "KEY_KBDILLUMDOWN"
-# key 239 "KEY_KBDILLUMUP"
-# key 240 "KEY_UNKNOWN"
key 256 BUTTON_1
key 257 BUTTON_2
diff --git a/include/gui/SurfaceTexture.h b/include/gui/SurfaceTexture.h
index 3f9e68d..a6fb12e 100644
--- a/include/gui/SurfaceTexture.h
+++ b/include/gui/SurfaceTexture.h
@@ -208,9 +208,28 @@
protected:
- // freeAllBuffers frees the resources (both GraphicBuffer and EGLImage) for
- // all slots.
- void freeAllBuffers();
+ // freeBufferLocked frees the resources (both GraphicBuffer and EGLImage)
+ // for the given slot.
+ void freeBufferLocked(int index);
+
+ // freeAllBuffersLocked frees the resources (both GraphicBuffer and
+ // EGLImage) for all slots.
+ void freeAllBuffersLocked();
+
+ // freeAllBuffersExceptHeadLocked frees the resources (both GraphicBuffer
+ // and EGLImage) for all slots except the head of mQueue
+ void freeAllBuffersExceptHeadLocked();
+
+ // drainQueueLocked drains the buffer queue if we're in synchronous mode
+ // returns immediately otherwise. return NO_INIT if SurfaceTexture
+ // became abandoned or disconnected during this call.
+ status_t drainQueueLocked();
+
+ // drainQueueAndFreeBuffersLocked drains the buffer queue if we're in
+ // synchronous mode and free all buffers. In asynchronous mode, all buffers
+ // are freed except the current buffer.
+ status_t drainQueueAndFreeBuffersLocked();
+
static bool isExternalFormat(uint32_t format);
private:
diff --git a/include/utils/threads.h b/include/utils/threads.h
index c8e9c04..c84a9b4 100644
--- a/include/utils/threads.h
+++ b/include/utils/threads.h
@@ -20,6 +20,7 @@
#include <stdint.h>
#include <sys/types.h>
#include <time.h>
+#include <system/graphics.h>
#if defined(HAVE_PTHREADS)
# include <pthread.h>
@@ -42,8 +43,8 @@
* ** Keep in sync with android.os.Process.java **
* ***********************************************
*
- * This maps directly to the "nice" priorites we use in Android.
- * A thread priority should be chosen inverse-proportinally to
+ * This maps directly to the "nice" priorities we use in Android.
+ * A thread priority should be chosen inverse-proportionally to
* the amount of work the thread is expected to do. The more work
* a thread will do, the less favorable priority it should get so that
* it doesn't starve the system. Threads not behaving properly might
@@ -66,7 +67,7 @@
ANDROID_PRIORITY_DISPLAY = -4,
/* ui service treads might want to run at a urgent display (uncommon) */
- ANDROID_PRIORITY_URGENT_DISPLAY = -8,
+ ANDROID_PRIORITY_URGENT_DISPLAY = HAL_PRIORITY_URGENT_DISPLAY,
/* all normal audio threads */
ANDROID_PRIORITY_AUDIO = -16,
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index ccf98e5..2c70251 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -277,6 +277,11 @@
if (surface == 0) {
surface = new Surface(data, binder);
sCachedSurfaces.add(binder, surface);
+ } else {
+ // The Surface was found in the cache, but we still should clear any
+ // remaining data from the parcel.
+ data.readStrongBinder(); // ISurfaceTexture
+ data.readInt32(); // identity
}
if (surface->mSurface == NULL && surface->getISurfaceTexture() == NULL) {
surface = 0;
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp
index 4bbf7eb..7ac4343 100644
--- a/libs/gui/SurfaceTexture.cpp
+++ b/libs/gui/SurfaceTexture.cpp
@@ -104,7 +104,7 @@
SurfaceTexture::~SurfaceTexture() {
LOGV("SurfaceTexture::~SurfaceTexture");
- freeAllBuffers();
+ freeAllBuffersLocked();
}
status_t SurfaceTexture::setBufferCountServerLocked(int bufferCount) {
@@ -154,7 +154,6 @@
LOGE("setBufferCount: SurfaceTexture has been abandoned!");
return NO_INIT;
}
-
if (bufferCount > NUM_BUFFER_SLOTS) {
LOGE("setBufferCount: bufferCount larger than slots available");
return BAD_VALUE;
@@ -185,7 +184,7 @@
// here we're guaranteed that the client doesn't have dequeued buffers
// and will release all of its buffer references.
- freeAllBuffers();
+ freeAllBuffersLocked();
mBufferCount = bufferCount;
mClientBufferCount = bufferCount;
mCurrentTexture = INVALID_BUFFER_SLOT;
@@ -228,11 +227,6 @@
uint32_t format, uint32_t usage) {
LOGV("SurfaceTexture::dequeueBuffer");
- if (mAbandoned) {
- LOGE("dequeueBuffer: SurfaceTexture has been abandoned!");
- return NO_INIT;
- }
-
if ((w && !h) || (!w && h)) {
LOGE("dequeueBuffer: invalid size: w=%u, h=%u", w, h);
return BAD_VALUE;
@@ -246,10 +240,15 @@
int dequeuedCount = 0;
bool tryAgain = true;
while (tryAgain) {
+ if (mAbandoned) {
+ LOGE("dequeueBuffer: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+
// We need to wait for the FIFO to drain if the number of buffer
// needs to change.
//
- // The condition "number of buffer needs to change" is true if
+ // The condition "number of buffers needs to change" is true if
// - the client doesn't care about how many buffers there are
// - AND the actual number of buffer is different from what was
// set in the last setBufferCountServer()
@@ -261,31 +260,24 @@
// As long as this condition is true AND the FIFO is not empty, we
// wait on mDequeueCondition.
- int minBufferCountNeeded = mSynchronousMode ?
+ const int minBufferCountNeeded = mSynchronousMode ?
MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
- if (!mClientBufferCount &&
+ const bool numberOfBuffersNeedsToChange = !mClientBufferCount &&
((mServerBufferCount != mBufferCount) ||
- (mServerBufferCount < minBufferCountNeeded))) {
+ (mServerBufferCount < minBufferCountNeeded));
+
+ if (!mQueue.isEmpty() && numberOfBuffersNeedsToChange) {
// wait for the FIFO to drain
- while (!mQueue.isEmpty()) {
- mDequeueCondition.wait(mMutex);
- if (mAbandoned) {
- LOGE("dequeueBuffer: SurfaceTexture was abandoned while "
- "blocked!");
- return NO_INIT;
- }
- }
- minBufferCountNeeded = mSynchronousMode ?
- MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
+ mDequeueCondition.wait(mMutex);
+ // NOTE: we continue here because we need to reevaluate our
+ // whole state (eg: we could be abandoned or disconnected)
+ continue;
}
-
- if (!mClientBufferCount &&
- ((mServerBufferCount != mBufferCount) ||
- (mServerBufferCount < minBufferCountNeeded))) {
+ if (numberOfBuffersNeedsToChange) {
// here we're guaranteed that mQueue is empty
- freeAllBuffers();
+ freeAllBuffersLocked();
mBufferCount = mServerBufferCount;
if (mBufferCount < minBufferCountNeeded)
mBufferCount = minBufferCountNeeded;
@@ -414,9 +406,9 @@
if (!enabled) {
// going to asynchronous mode, drain the queue
- while (mSynchronousMode != enabled && !mQueue.isEmpty()) {
- mDequeueCondition.wait(mMutex);
- }
+ err = drainQueueLocked();
+ if (err != NO_ERROR)
+ return err;
}
if (mSynchronousMode != enabled) {
@@ -598,8 +590,9 @@
case NATIVE_WINDOW_API_MEDIA:
case NATIVE_WINDOW_API_CAMERA:
if (mConnectedApi == api) {
+ drainQueueAndFreeBuffersLocked();
mConnectedApi = NO_CONNECTED_API;
- freeAllBuffers();
+ mDequeueCondition.signal();
} else {
LOGE("disconnect: connected to another api (cur=%d, req=%d)",
mConnectedApi, api);
@@ -635,7 +628,7 @@
if (mAbandoned) {
LOGE("calling updateTexImage() on an abandoned SurfaceTexture");
- //return NO_INIT;
+ return NO_INIT;
}
// In asynchronous mode the list is guaranteed to be one buffer
@@ -644,21 +637,14 @@
Fifo::iterator front(mQueue.begin());
int buf = *front;
- if (uint32_t(buf) >= NUM_BUFFER_SLOTS) {
- LOGE("buffer index out of range (index=%d)", buf);
- //return BAD_VALUE;
- }
-
// Update the GL texture object.
EGLImageKHR image = mSlots[buf].mEglImage;
if (image == EGL_NO_IMAGE_KHR) {
EGLDisplay dpy = eglGetCurrentDisplay();
-
if (mSlots[buf].mGraphicBuffer == 0) {
LOGE("buffer at slot %d is null", buf);
- //return BAD_VALUE;
+ return BAD_VALUE;
}
-
image = createImage(dpy, mSlots[buf].mGraphicBuffer);
mSlots[buf].mEglImage = image;
mSlots[buf].mEglDisplay = dpy;
@@ -848,18 +834,66 @@
mFrameAvailableListener = listener;
}
-void SurfaceTexture::freeAllBuffers() {
+void SurfaceTexture::freeBufferLocked(int i) {
+ mSlots[i].mGraphicBuffer = 0;
+ mSlots[i].mBufferState = BufferSlot::FREE;
+ if (mSlots[i].mEglImage != EGL_NO_IMAGE_KHR) {
+ eglDestroyImageKHR(mSlots[i].mEglDisplay, mSlots[i].mEglImage);
+ mSlots[i].mEglImage = EGL_NO_IMAGE_KHR;
+ mSlots[i].mEglDisplay = EGL_NO_DISPLAY;
+ }
+}
+
+void SurfaceTexture::freeAllBuffersLocked() {
+ LOGW_IF(!mQueue.isEmpty(),
+ "freeAllBuffersLocked called but mQueue is not empty");
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
- mSlots[i].mGraphicBuffer = 0;
- mSlots[i].mBufferState = BufferSlot::FREE;
- if (mSlots[i].mEglImage != EGL_NO_IMAGE_KHR) {
- eglDestroyImageKHR(mSlots[i].mEglDisplay, mSlots[i].mEglImage);
- mSlots[i].mEglImage = EGL_NO_IMAGE_KHR;
- mSlots[i].mEglDisplay = EGL_NO_DISPLAY;
+ freeBufferLocked(i);
+ }
+}
+
+void SurfaceTexture::freeAllBuffersExceptHeadLocked() {
+ LOGW_IF(!mQueue.isEmpty(),
+ "freeAllBuffersExceptCurrentLocked called but mQueue is not empty");
+ int head = -1;
+ if (!mQueue.empty()) {
+ Fifo::iterator front(mQueue.begin());
+ head = *front;
+ }
+ for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
+ if (i != head) {
+ freeBufferLocked(i);
}
}
}
+status_t SurfaceTexture::drainQueueLocked() {
+ while (mSynchronousMode && !mQueue.isEmpty()) {
+ mDequeueCondition.wait(mMutex);
+ if (mAbandoned) {
+ LOGE("drainQueueLocked: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+ if (mConnectedApi == NO_CONNECTED_API) {
+ LOGE("drainQueueLocked: SurfaceTexture is not connected!");
+ return NO_INIT;
+ }
+ }
+ return NO_ERROR;
+}
+
+status_t SurfaceTexture::drainQueueAndFreeBuffersLocked() {
+ status_t err = drainQueueLocked();
+ if (err == NO_ERROR) {
+ if (mSynchronousMode) {
+ freeAllBuffersLocked();
+ } else {
+ freeAllBuffersExceptHeadLocked();
+ }
+ }
+ return err;
+}
+
EGLImageKHR SurfaceTexture::createImage(EGLDisplay dpy,
const sp<GraphicBuffer>& graphicBuffer) {
EGLClientBuffer cbuf = (EGLClientBuffer)graphicBuffer->getNativeBuffer();
@@ -929,9 +963,10 @@
void SurfaceTexture::abandon() {
Mutex::Autolock lock(mMutex);
- freeAllBuffers();
+ mQueue.clear();
mAbandoned = true;
mCurrentTextureBuf.clear();
+ freeAllBuffersLocked();
mDequeueCondition.signal();
}
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 9bf8b2d..b1b11a2 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -752,10 +752,12 @@
private class SetModeDeathHandler implements IBinder.DeathRecipient {
private IBinder mCb; // To be notified of client's death
+ private int mPid;
private int mMode = AudioSystem.MODE_NORMAL; // Current mode set by this client
SetModeDeathHandler(IBinder cb) {
mCb = cb;
+ mPid = Binder.getCallingPid();
}
public void binderDied() {
@@ -786,6 +788,10 @@
}
}
+ public int getPid() {
+ return mPid;
+ }
+
public void setMode(int mode) {
mMode = mode;
}
@@ -1227,10 +1233,12 @@
private class ScoClient implements IBinder.DeathRecipient {
private IBinder mCb; // To be notified of client's death
+ private int mCreatorPid;
private int mStartcount; // number of SCO connections started by this client
ScoClient(IBinder cb) {
mCb = cb;
+ mCreatorPid = Binder.getCallingPid();
mStartcount = 0;
}
@@ -1323,9 +1331,9 @@
// the connection.
broadcastScoConnectionState(AudioManager.SCO_AUDIO_STATE_CONNECTING);
// Accept SCO audio activation only in NORMAL audio mode or if the mode is
- // currently controlled by the same client.
+ // currently controlled by the same client process.
if ((AudioService.this.mMode == AudioSystem.MODE_NORMAL ||
- mSetModeDeathHandlers.get(0).getBinder() == mCb) &&
+ mSetModeDeathHandlers.get(0).getPid() == mCreatorPid) &&
mBluetoothHeadsetDevice != null &&
(mScoAudioState == SCO_STATE_INACTIVE ||
mScoAudioState == SCO_STATE_DEACTIVATE_REQ)) {
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
index 3f4dace..b9e4f9f 100644
--- a/media/libstagefright/Android.mk
+++ b/media/libstagefright/Android.mk
@@ -133,8 +133,9 @@
LOCAL_STATIC_LIBRARIES += \
libstagefright_chromium_http \
libwebcore \
+ libchromium_net \
-LOCAL_SHARED_LIBRARIES += libstlport libchromium_net
+LOCAL_SHARED_LIBRARIES += libstlport
include external/stlport/libstlport.mk
LOCAL_CPPFLAGS += -DCHROMIUM_AVAILABLE=1
diff --git a/media/tests/ScoAudioTest/Android.mk b/media/tests/ScoAudioTest/Android.mk
new file mode 100755
index 0000000..ab12865
--- /dev/null
+++ b/media/tests/ScoAudioTest/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+#LOCAL_SDK_VERSION := current
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := scoaudiotest
+
+include $(BUILD_PACKAGE)
diff --git a/media/tests/ScoAudioTest/AndroidManifest.xml b/media/tests/ScoAudioTest/AndroidManifest.xml
new file mode 100755
index 0000000..8ff973e
--- /dev/null
+++ b/media/tests/ScoAudioTest/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2010 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.scoaudiotest">
+
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.BROADCAST_STICKY" />
+ <uses-permission android:name="android.permission.BLUETOOTH" />
+
+ <application>
+ <activity android:label="@string/app_name"
+ android:name="ScoAudioTest">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ </activity>
+
+ </application>
+</manifest>
diff --git a/media/tests/ScoAudioTest/res/drawable/icon.png b/media/tests/ScoAudioTest/res/drawable/icon.png
new file mode 100755
index 0000000..64e3601
--- /dev/null
+++ b/media/tests/ScoAudioTest/res/drawable/icon.png
Binary files differ
diff --git a/media/tests/ScoAudioTest/res/drawable/record.png b/media/tests/ScoAudioTest/res/drawable/record.png
new file mode 100755
index 0000000..ae518d5
--- /dev/null
+++ b/media/tests/ScoAudioTest/res/drawable/record.png
Binary files differ
diff --git a/media/tests/ScoAudioTest/res/drawable/stop.png b/media/tests/ScoAudioTest/res/drawable/stop.png
new file mode 100755
index 0000000..83f012c
--- /dev/null
+++ b/media/tests/ScoAudioTest/res/drawable/stop.png
Binary files differ
diff --git a/media/tests/ScoAudioTest/res/layout/scoaudiotest.xml b/media/tests/ScoAudioTest/res/layout/scoaudiotest.xml
new file mode 100755
index 0000000..b769a0c
--- /dev/null
+++ b/media/tests/ScoAudioTest/res/layout/scoaudiotest.xml
@@ -0,0 +1,181 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <LinearLayout android:id="@+id/playPause1Frame"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginTop="3dip"
+ android:layout_marginRight="10dip"
+ android:layout_marginBottom="3dip" >
+
+ <TextView android:id="@+id/playPause1Text"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1.0"
+ android:text="@string/playback_name"
+ android:layout_gravity="center_vertical|left"
+ style="@android:style/TextAppearance.Medium" />
+
+ <ImageButton android:id="@+id/stop1"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_vertical|right"
+ android:layout_weight="0.0"
+ android:src="@drawable/stop"/>
+
+ <ImageButton android:id="@+id/playPause1"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_vertical|right"
+ android:layout_weight="0.0"
+ android:src="@android:drawable/ic_media_play"/>
+
+ </LinearLayout>
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <LinearLayout android:id="@+id/record1Frame"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginTop="3dip"
+ android:layout_marginRight="10dip"
+ android:layout_marginBottom="3dip" >
+
+ <TextView android:id="@+id/record1Text"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1.0"
+ android:text="@string/record_name"
+ android:layout_gravity="center_vertical|left"
+ style="@android:style/TextAppearance.Medium" />
+
+ <ImageButton android:id="@+id/recStop1"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_vertical|right"
+ android:layout_weight="0.0"
+ android:src="@drawable/record"/>
+ </LinearLayout>
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <LinearLayout android:id="@+id/forceFrame"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginTop="3dip"
+ android:layout_marginRight="10dip"
+ android:layout_marginBottom="3dip" >
+
+ <ToggleButton android:id="@+id/ForceScoButton"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_vertical|left"
+ android:layout_weight="0.0"
+ android:textOff="@string/force_sco_off"
+ android:textOn="@string/force_sco_on" />
+
+ <TextView android:id="@+id/scoStateTxt"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1.0"
+ android:layout_gravity="center_vertical|right"
+ style="@android:style/TextAppearance.Medium" />
+ </LinearLayout>
+ <CheckBox
+ android:id="@+id/useSecondAudioManager"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/audiomanagertwo" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <LinearLayout android:id="@+id/voiceDialerFrame"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="10dip"
+ android:layout_marginTop="3dip"
+ android:layout_marginRight="10dip"
+ android:layout_marginBottom="3dip" >
+
+ <ToggleButton android:id="@+id/VoiceDialerButton"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_gravity="center_vertical|left"
+ android:layout_weight="0.0"
+ android:textOff="@string/vd_off"
+ android:textOn="@string/vd_on" />
+
+ <TextView android:id="@+id/vdStateTxt"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="1.0"
+ android:layout_gravity="center_vertical|right"
+ style="@android:style/TextAppearance.Medium" />
+
+ </LinearLayout>
+
+ </LinearLayout>
+
+ <EditText android:id="@+id/speakTextEdit"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <ToggleButton android:id="@+id/TtsToFileButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textOff="@string/tts_speak"
+ android:textOn="@string/tts_to_file" />
+
+
+ <Spinner android:id="@+id/modeSpinner"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:drawSelectorOnTop="true"
+ />
+
+</LinearLayout>
diff --git a/media/tests/ScoAudioTest/res/raw/sine440_mo_16b_16k.wav b/media/tests/ScoAudioTest/res/raw/sine440_mo_16b_16k.wav
new file mode 100644
index 0000000..2538b4d6
--- /dev/null
+++ b/media/tests/ScoAudioTest/res/raw/sine440_mo_16b_16k.wav
Binary files differ
diff --git a/media/tests/ScoAudioTest/res/values/strings.xml b/media/tests/ScoAudioTest/res/values/strings.xml
new file mode 100755
index 0000000..c3ff6d5
--- /dev/null
+++ b/media/tests/ScoAudioTest/res/values/strings.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Sco Audio Test</string>
+ <string name="playback_name">Playback</string>
+ <string name="record_name">Record</string>
+ <string name="force_sco_off">NO SCO</string>
+ <string name="force_sco_on">USE SCO</string>
+ <string name="vd_off">Start Voice Dialer</string>
+ <string name="vd_on">Voice Dialer On</string>
+ <string name="tts_speak">Speak TTS</string>
+ <string name="tts_to_file">TTS to file</string>
+ <string name="audiomanagertwo">Use different AudioManager for starting SCO</string>
+
+</resources>
diff --git a/media/tests/ScoAudioTest/src/com/android/scoaudiotest/ScoAudioTest.java b/media/tests/ScoAudioTest/src/com/android/scoaudiotest/ScoAudioTest.java
new file mode 100644
index 0000000..fe3929d
--- /dev/null
+++ b/media/tests/ScoAudioTest/src/com/android/scoaudiotest/ScoAudioTest.java
@@ -0,0 +1,700 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.scoaudiotest;
+
+import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothHeadset;
+import android.bluetooth.BluetoothProfile;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.AssetFileDescriptor;
+import android.media.AudioManager;
+import android.media.MediaPlayer;
+import android.media.MediaRecorder;
+import android.os.Bundle;
+import android.os.Environment;
+import android.os.Handler;
+import android.speech.tts.TextToSpeech;
+import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.ArrayAdapter;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.EditText;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.Spinner;
+import android.widget.TextView;
+import android.widget.ToggleButton;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+
+public class ScoAudioTest extends Activity {
+
+ final static String TAG = "ScoAudioTest";
+
+ AudioManager mAudioManager;
+ AudioManager mAudioManager2;
+ boolean mForceScoOn;
+ ToggleButton mScoButton;
+ ToggleButton mVoiceDialerButton;
+ boolean mVoiceDialerOn;
+ String mLastRecordedFile;
+ SimpleMediaController mMediaControllers[] = new SimpleMediaController[2];
+ private TextToSpeech mTts;
+ private HashMap<String, String> mTtsParams;
+ private int mOriginalVoiceVolume;
+ EditText mSpeakText;
+ boolean mTtsInited;
+ private Handler mHandler;
+ private static final String UTTERANCE = "utterance";
+ private static Intent sVoiceCommandIntent;
+ private File mSampleFile;
+ ToggleButton mTtsToFileButton;
+ private boolean mTtsToFile;
+ private int mCurrentMode;
+ Spinner mModeSpinner;
+ private BluetoothHeadset mBluetoothHeadset;
+ private BluetoothDevice mBluetoothHeadsetDevice;
+ TextView mScoStateTxt;
+ TextView mVdStateTxt;
+
+ private final BroadcastReceiver mReceiver = new ScoBroadcastReceiver();
+
+ public ScoAudioTest() {
+ Log.e(TAG, "contructor");
+ }
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ setContentView(R.layout.scoaudiotest);
+
+ mScoStateTxt = (TextView) findViewById(R.id.scoStateTxt);
+ mVdStateTxt = (TextView) findViewById(R.id.vdStateTxt);
+
+ IntentFilter intentFilter =
+ new IntentFilter(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED);
+ intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED);
+ intentFilter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED);
+ registerReceiver(mReceiver, intentFilter);
+
+ mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
+ mAudioManager2 = (AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
+ mHandler = new Handler();
+
+ mMediaControllers[0] = new SimplePlayerController(this, R.id.playPause1, R.id.stop1,
+ R.raw.sine440_mo_16b_16k, AudioManager.STREAM_BLUETOOTH_SCO);
+ TextView name = (TextView) findViewById(R.id.playPause1Text);
+ name.setText("VOICE_CALL stream");
+
+ mScoButton = (ToggleButton)findViewById(R.id.ForceScoButton);
+ mScoButton.setOnCheckedChangeListener(mForceScoChanged);
+ mForceScoOn = false;
+ mScoButton.setChecked(mForceScoOn);
+
+ mVoiceDialerButton = (ToggleButton)findViewById(R.id.VoiceDialerButton);
+ mVoiceDialerButton.setOnCheckedChangeListener(mVoiceDialerChanged);
+ mVoiceDialerOn = false;
+ mVoiceDialerButton.setChecked(mVoiceDialerOn);
+
+
+ mMediaControllers[1] = new SimpleRecordController(this, R.id.recStop1, 0, "Sco_record_");
+ mTtsInited = false;
+ mTts = new TextToSpeech(this, new TtsInitListener());
+ mTtsParams = new HashMap<String, String>();
+ mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
+ String.valueOf(AudioManager.STREAM_BLUETOOTH_SCO));
+ mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
+ UTTERANCE);
+
+ mSpeakText = (EditText) findViewById(R.id.speakTextEdit);
+ mSpeakText.setOnKeyListener(mSpeakKeyListener);
+ mSpeakText.setText("sco audio test sentence");
+ mTtsToFileButton = (ToggleButton)findViewById(R.id.TtsToFileButton);
+ mTtsToFileButton.setOnCheckedChangeListener(mTtsToFileChanged);
+ mTtsToFile = true;
+ mTtsToFileButton.setChecked(mTtsToFile);
+
+ mModeSpinner = (Spinner) findViewById(R.id.modeSpinner);
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
+ android.R.layout.simple_spinner_item, mModeStrings);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ mModeSpinner.setAdapter(adapter);
+ mModeSpinner.setOnItemSelectedListener(mModeChanged);
+ mCurrentMode = mAudioManager.getMode();
+ mModeSpinner.setSelection(mCurrentMode);
+
+ mBluetoothHeadsetDevice = null;
+ BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (btAdapter != null) {
+ btAdapter.getProfileProxy(this, mBluetoothProfileServiceListener,
+ BluetoothProfile.HEADSET);
+ }
+
+ sVoiceCommandIntent = new Intent(Intent.ACTION_VOICE_COMMAND);
+ sVoiceCommandIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mTts.shutdown();
+ unregisterReceiver(mReceiver);
+ if (mBluetoothHeadset != null) {
+ BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
+ if (btAdapter != null) {
+ btAdapter.closeProfileProxy(BluetoothProfile.HEADSET, mBluetoothHeadset);
+ }
+ }
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+// mForceScoOn = false;
+// mScoButton.setChecked(mForceScoOn);
+ mMediaControllers[0].stop();
+ mMediaControllers[1].stop();
+ mAudioManager.setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO,
+ mOriginalVoiceVolume, 0);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mLastRecordedFile = "";
+ mMediaControllers[0].mFileName = "";
+ mOriginalVoiceVolume = mAudioManager.getStreamVolume(
+ AudioManager.STREAM_BLUETOOTH_SCO);
+ setVolumeControlStream(AudioManager.STREAM_BLUETOOTH_SCO);
+ mCurrentMode = mAudioManager.getMode();
+ mModeSpinner.setSelection(mCurrentMode);
+ }
+
+ private OnCheckedChangeListener mForceScoChanged
+ = new OnCheckedChangeListener(){
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView,
+ boolean isChecked) {
+ if (mForceScoOn != isChecked) {
+ mForceScoOn = isChecked;
+ AudioManager mngr = mAudioManager;
+ CheckBox box = (CheckBox) findViewById(R.id.useSecondAudioManager);
+ if (box.isChecked()) {
+ Log.i(TAG, "Using 2nd audio manager");
+ mngr = mAudioManager2;
+ }
+
+ if (mForceScoOn) {
+ Log.e(TAG, "startBluetoothSco() IN");
+ mngr.startBluetoothSco();
+ Log.e(TAG, "startBluetoothSco() OUT");
+ } else {
+ Log.e(TAG, "stopBluetoothSco() IN");
+ mngr.stopBluetoothSco();
+ Log.e(TAG, "stopBluetoothSco() OUT");
+ }
+ }
+ }
+ };
+
+ private OnCheckedChangeListener mVoiceDialerChanged
+ = new OnCheckedChangeListener(){
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView,
+ boolean isChecked) {
+ if (mVoiceDialerOn != isChecked) {
+ mVoiceDialerOn = isChecked;
+ if (mBluetoothHeadset != null && mBluetoothHeadsetDevice != null) {
+ if (mVoiceDialerOn) {
+ mBluetoothHeadset.startVoiceRecognition(mBluetoothHeadsetDevice);
+ } else {
+ mBluetoothHeadset.stopVoiceRecognition(mBluetoothHeadsetDevice);
+ }
+ }
+ }
+ }
+ };
+
+ private OnCheckedChangeListener mTtsToFileChanged
+ = new OnCheckedChangeListener(){
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView,
+ boolean isChecked) {
+ mTtsToFile = isChecked;
+ }
+ };
+
+ private class SimpleMediaController implements OnClickListener {
+ int mPlayPauseButtonId;
+ int mStopButtonId;
+ Context mContext;
+ ImageView mPlayPauseButton;
+ int mPlayImageResource;
+ int mPauseImageResource;
+ String mFileNameBase;
+ String mFileName;
+ int mFileResId;
+
+ SimpleMediaController(Context context, int playPausebuttonId, int stopButtonId, String fileName) {
+ mContext = context;
+ mPlayPauseButtonId = playPausebuttonId;
+ mStopButtonId = stopButtonId;
+ mFileNameBase = fileName;
+ mPlayPauseButton = (ImageButton) findViewById(playPausebuttonId);
+ ImageButton stop = (ImageButton) findViewById(stopButtonId);
+
+ mPlayPauseButton.setOnClickListener(this);
+ mPlayPauseButton.requestFocus();
+ if (stop != null) {
+ stop.setOnClickListener(this);
+ }
+ }
+
+ SimpleMediaController(Context context, int playPausebuttonId, int stopButtonId, int fileResId) {
+ mContext = context;
+ mPlayPauseButtonId = playPausebuttonId;
+ mStopButtonId = stopButtonId;
+ mFileNameBase = "";
+ mFileResId = fileResId;
+ mPlayPauseButton = (ImageButton) findViewById(playPausebuttonId);
+ ImageButton stop = (ImageButton) findViewById(stopButtonId);
+
+ mPlayPauseButton.setOnClickListener(this);
+ mPlayPauseButton.requestFocus();
+ if (stop != null) {
+ stop.setOnClickListener(this);
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == mPlayPauseButtonId) {
+ playOrPause();
+ } else if (v.getId() == mStopButtonId) {
+ stop();
+ }
+ }
+
+ public void playOrPause() {
+ }
+
+ public void stop() {
+ }
+
+ public boolean isPlaying() {
+ return false;
+ }
+
+ public void updatePlayPauseButton() {
+ mPlayPauseButton.setImageResource(isPlaying() ? mPauseImageResource : mPlayImageResource);
+ }
+ }
+
+ private class SimplePlayerController extends SimpleMediaController {
+ private MediaPlayer mMediaPlayer;
+ private int mStreamType;
+ SimplePlayerController(Context context, int playPausebuttonId, int stopButtonId, String fileName, int stream) {
+ super(context, playPausebuttonId, stopButtonId, fileName);
+
+ mPlayImageResource = android.R.drawable.ic_media_play;
+ mPauseImageResource = android.R.drawable.ic_media_pause;
+ mStreamType = stream;
+ mFileName = Environment.getExternalStorageDirectory().toString() + "/music/" +
+ mFileNameBase + "_" + ".wav";
+ }
+
+ SimplePlayerController(Context context, int playPausebuttonId, int stopButtonId, int fileResId, int stream) {
+ super(context, playPausebuttonId, stopButtonId, fileResId);
+
+ mPlayImageResource = android.R.drawable.ic_media_play;
+ mPauseImageResource = android.R.drawable.ic_media_pause;
+ mStreamType = stream;
+ mFileName = "";
+ }
+
+ @Override
+ public void playOrPause() {
+ Log.e(TAG, "playOrPause playing: "+((mMediaPlayer == null)?false:!mMediaPlayer.isPlaying())+
+ " mMediaPlayer: "+mMediaPlayer+
+ " mFileName: "+mFileName+
+ " mLastRecordedFile: "+mLastRecordedFile);
+ if (mMediaPlayer == null || !mMediaPlayer.isPlaying()){
+ if (mMediaPlayer == null) {
+ if (mFileName != mLastRecordedFile) {
+ mFileName = mLastRecordedFile;
+ Log.e(TAG, "new recorded file: "+mFileName);
+ }
+ try {
+ mMediaPlayer = new MediaPlayer();
+ if (mFileName.equals("")) {
+ Log.e(TAG, "Playing from resource");
+ AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(mFileResId);
+ mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
+ afd.close();
+ } else {
+ Log.e(TAG, "Playing file: "+mFileName);
+ mMediaPlayer.setDataSource(mFileName);
+ }
+ mMediaPlayer.setAudioStreamType(mStreamType);
+ mMediaPlayer.prepare();
+ mMediaPlayer.setLooping(true);
+ } catch (Exception ex) {
+ Log.e(TAG, "mMediaPlayercreate failed:", ex);
+ mMediaPlayer.release();
+ mMediaPlayer = null;
+ }
+
+ if (mMediaPlayer != null) {
+ mMediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
+ @Override
+ public void onCompletion(MediaPlayer mp) {
+ updatePlayPauseButton();
+ }
+ });
+ }
+ }
+ if (mMediaPlayer != null) {
+ mMediaPlayer.start();
+ }
+ } else {
+ mMediaPlayer.pause();
+ }
+ updatePlayPauseButton();
+ }
+ @Override
+ public void stop() {
+ if (mMediaPlayer != null) {
+ mMediaPlayer.stop();
+ mMediaPlayer.release();
+ mMediaPlayer = null;
+ }
+ updatePlayPauseButton();
+ }
+
+ @Override
+ public boolean isPlaying() {
+ if (mMediaPlayer != null) {
+ return mMediaPlayer.isPlaying();
+ } else {
+ return false;
+ }
+ }
+ }
+
+ private class SimpleRecordController extends SimpleMediaController {
+ private MediaRecorder mMediaRecorder;
+ private int mFileCount = 0;
+ private int mState = 0;
+ SimpleRecordController(Context context, int playPausebuttonId, int stopButtonId, String fileName) {
+ super(context, playPausebuttonId, stopButtonId, fileName);
+ Log.e(TAG, "SimpleRecordController cstor");
+ mPlayImageResource = R.drawable.record;
+ mPauseImageResource = R.drawable.stop;
+ }
+
+ @Override
+ public void playOrPause() {
+ if (mState == 0) {
+ setup();
+ try {
+ mMediaRecorder.start();
+ mState = 1;
+ } catch (Exception e) {
+ Log.e(TAG, "Could start MediaRecorder: " + e.toString());
+ mMediaRecorder.release();
+ mMediaRecorder = null;
+ mState = 0;
+ }
+ } else {
+ try {
+ mMediaRecorder.stop();
+ mMediaRecorder.reset();
+ } catch (Exception e) {
+ Log.e(TAG, "Could not stop MediaRecorder: " + e.toString());
+ mMediaRecorder.release();
+ mMediaRecorder = null;
+ } finally {
+ mState = 0;
+ }
+ }
+ updatePlayPauseButton();
+ }
+
+ public void setup() {
+ Log.e(TAG, "SimpleRecordController setup()");
+ if (mMediaRecorder == null) {
+ mMediaRecorder = new MediaRecorder();
+ }
+ mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+ mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+ mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
+ mFileName = Environment.getExternalStorageDirectory().toString() + "/music/" +
+ mFileNameBase + "_" + ++mFileCount + ".amr";
+ mLastRecordedFile = mFileName;
+ Log.e(TAG, "recording to file: "+mLastRecordedFile);
+ mMediaRecorder.setOutputFile(mFileName);
+ try {
+ mMediaRecorder.prepare();
+ }
+ catch (Exception e) {
+ Log.e(TAG, "Could not prepare MediaRecorder: " + e.toString());
+ mMediaRecorder.release();
+ mMediaRecorder = null;
+ }
+ }
+
+ @Override
+ public void stop() {
+ if (mMediaRecorder != null) {
+ mMediaRecorder.stop();
+ mMediaRecorder.release();
+ mMediaRecorder = null;
+ }
+ updatePlayPauseButton();
+ }
+
+ @Override
+ public boolean isPlaying() {
+ if (mState == 1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+
+ class TtsInitListener implements TextToSpeech.OnInitListener {
+ @Override
+ public void onInit(int status) {
+ // status can be either TextToSpeech.SUCCESS or TextToSpeech.ERROR.
+ Log.e(TAG, "onInit for tts");
+ if (status != TextToSpeech.SUCCESS) {
+ // Initialization failed.
+ Log.e(TAG, "Could not initialize TextToSpeech.");
+ return;
+ }
+
+ if (mTts == null) {
+ Log.e(TAG, "null tts");
+ return;
+ }
+
+ int result = mTts.setLanguage(Locale.US);
+ if (result == TextToSpeech.LANG_MISSING_DATA ||
+ result == TextToSpeech.LANG_NOT_SUPPORTED) {
+ // Lanuage data is missing or the language is not supported.
+ Log.e(TAG, "Language is not available.");
+ return;
+ }
+ mTts.setOnUtteranceCompletedListener(new MyUtteranceCompletedListener(UTTERANCE));
+ mTtsInited = true;
+ }
+ }
+
+ class MyUtteranceCompletedListener implements OnUtteranceCompletedListener {
+ private final String mExpectedUtterance;
+
+ public MyUtteranceCompletedListener(String expectedUtteranceId) {
+ mExpectedUtterance = expectedUtteranceId;
+ }
+
+ @Override
+ public void onUtteranceCompleted(String utteranceId) {
+ Log.e(TAG, "onUtteranceCompleted " + utteranceId);
+ if (mTtsToFile) {
+ if (mSampleFile != null && mSampleFile.exists()) {
+ MediaPlayer mediaPlayer = new MediaPlayer();
+ try {
+ mediaPlayer.setDataSource(mSampleFile.getPath());
+ mediaPlayer.setAudioStreamType(AudioManager.STREAM_BLUETOOTH_SCO);
+ mediaPlayer.prepare();
+ } catch (Exception ex) {
+ Log.e(TAG, "mMediaPlayercreate failed:", ex);
+ mediaPlayer.release();
+ mediaPlayer = null;
+ }
+
+ if (mediaPlayer != null) {
+ mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
+ @Override
+ public void onCompletion(MediaPlayer mp) {
+ mp.release();
+ if (mSampleFile != null && mSampleFile.exists()) {
+ mSampleFile.delete();
+ mSampleFile = null;
+ }
+ mAudioManager.setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO,
+ mOriginalVoiceVolume, 0);
+// Debug.stopMethodTracing();
+ }
+ });
+ mediaPlayer.start();
+ }
+ } else {
+ Log.e(TAG, "synthesizeToFile did not create file");
+ }
+ } else {
+ mAudioManager.setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO,
+ mOriginalVoiceVolume, 0);
+// Debug.stopMethodTracing();
+ }
+
+ Log.e(TAG, "end speak, volume: "+mOriginalVoiceVolume);
+ }
+ }
+
+
+ private View.OnKeyListener mSpeakKeyListener
+ = new View.OnKeyListener() {
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ case KeyEvent.KEYCODE_ENTER:
+ if (!mTtsInited) {
+ Log.e(TAG, "Tts not inited ");
+ return false;
+ }
+ mOriginalVoiceVolume = mAudioManager.getStreamVolume(
+ AudioManager.STREAM_BLUETOOTH_SCO);
+ Log.e(TAG, "start speak, volume: "+mOriginalVoiceVolume);
+ mAudioManager.setStreamVolume(AudioManager.STREAM_BLUETOOTH_SCO,
+ mOriginalVoiceVolume/2, 0);
+
+ // we now have SCO connection and TTS, so we can start.
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+// Debug.startMethodTracing("tts");
+
+ if (mTtsToFile) {
+ if (mSampleFile != null && mSampleFile.exists()) {
+ mSampleFile.delete();
+ mSampleFile = null;
+ }
+ mSampleFile = new File(Environment.getExternalStorageDirectory(), "mytts.wav");
+ mTts.synthesizeToFile(mSpeakText.getText().toString(), mTtsParams, mSampleFile.getPath());
+ } else {
+ mTts.speak(mSpeakText.getText().toString(),
+ TextToSpeech.QUEUE_FLUSH,
+ mTtsParams);
+ }
+ }
+ });
+ return true;
+ }
+ }
+ return false;
+ }
+ };
+
+ private static final String[] mModeStrings = {
+ "NORMAL", "RINGTONE", "IN_CALL", "IN_COMMUNICATION"
+ };
+
+ private Spinner.OnItemSelectedListener mModeChanged
+ = new Spinner.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(android.widget.AdapterView av, View v,
+ int position, long id) {
+ if (mCurrentMode != position) {
+ mCurrentMode = position;
+ mAudioManager.setMode(mCurrentMode);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(android.widget.AdapterView av) {
+ }
+ };
+
+ private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
+ new BluetoothProfile.ServiceListener() {
+ @Override
+ public void onServiceConnected(int profile, BluetoothProfile proxy) {
+ mBluetoothHeadset = (BluetoothHeadset) proxy;
+ List<BluetoothDevice> deviceList = mBluetoothHeadset.getConnectedDevices();
+ if (deviceList.size() > 0) {
+ mBluetoothHeadsetDevice = deviceList.get(0);
+ } else {
+ mBluetoothHeadsetDevice = null;
+ }
+ }
+ @Override
+ public void onServiceDisconnected(int profile) {
+ if (mBluetoothHeadset != null) {
+ List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices();
+ if (devices.size() == 0) {
+ mBluetoothHeadsetDevice = null;
+ }
+ mBluetoothHeadset = null;
+ }
+ }
+ };
+
+ private int mChangedState = -1;
+ private int mUpdatedState = -1;
+ private int mUpdatedPrevState = -1;
+
+ private class ScoBroadcastReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+
+ if (action.equals(BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED)) {
+ int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE, -1);
+ mVdStateTxt.setText(Integer.toString(state));
+ Log.e(TAG, "BluetoothHeadset.ACTION_AUDIO_STATE_CHANGED: "+state);
+ } else if (action.equals(AudioManager.ACTION_SCO_AUDIO_STATE_CHANGED)) {
+ mChangedState = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
+ Log.e(TAG, "ACTION_SCO_AUDIO_STATE_CHANGED: "+mChangedState);
+ mScoStateTxt.setText("changed: "+Integer.toString(mChangedState)+
+ " updated: "+Integer.toString(mUpdatedState)+
+ " prev updated: "+Integer.toString(mUpdatedPrevState));
+ } else if (action.equals(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)) {
+ mUpdatedState = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
+ mUpdatedPrevState = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_PREVIOUS_STATE, -1);
+ Log.e(TAG, "ACTION_SCO_AUDIO_STATE_UPDATED, state: "+mUpdatedState+" prev state: "+mUpdatedPrevState);
+ mScoStateTxt.setText("changed: "+Integer.toString(mChangedState)+
+ " updated: "+Integer.toString(mUpdatedState)+
+ " prev updated: "+Integer.toString(mUpdatedPrevState));
+ if (mForceScoOn && mUpdatedState == AudioManager.SCO_AUDIO_STATE_DISCONNECTED) {
+ mForceScoOn = false;
+ mScoButton.setChecked(mForceScoOn);
+ mAudioManager.stopBluetoothSco();
+ }
+ }
+ }
+ }
+
+}
diff --git a/packages/SystemUI/res/drawable-hdpi/notify_panel_bg.9.png b/packages/SystemUI/res/drawable-hdpi/notify_panel_bg.9.png
deleted file mode 100644
index d5503f7..0000000
--- a/packages/SystemUI/res/drawable-hdpi/notify_panel_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/notify_panel_bg_protect.png b/packages/SystemUI/res/drawable-hdpi/notify_panel_bg_protect.png
deleted file mode 100644
index a8f2236..0000000
--- a/packages/SystemUI/res/drawable-hdpi/notify_panel_bg_protect.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/notify_panel_bg.9.png b/packages/SystemUI/res/drawable-mdpi/notify_panel_bg.9.png
deleted file mode 100644
index 8725e58..0000000
--- a/packages/SystemUI/res/drawable-mdpi/notify_panel_bg.9.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/notify_panel_bg_protect.png b/packages/SystemUI/res/drawable-mdpi/notify_panel_bg_protect.png
deleted file mode 100644
index f7225ed..0000000
--- a/packages/SystemUI/res/drawable-mdpi/notify_panel_bg_protect.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable-nodpi/notify_panel_bg.png b/packages/SystemUI/res/drawable-nodpi/notify_panel_bg.png
deleted file mode 100644
index 1ea924f..0000000
--- a/packages/SystemUI/res/drawable-nodpi/notify_panel_bg.png
+++ /dev/null
Binary files differ
diff --git a/packages/SystemUI/res/drawable/notify_panel_bg_protect_tiled.xml b/packages/SystemUI/res/drawable/notify_panel_bg_protect_tiled.xml
deleted file mode 100644
index 0371322..0000000
--- a/packages/SystemUI/res/drawable/notify_panel_bg_protect_tiled.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?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.
--->
-
-<bitmap
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:src="@drawable/notify_panel_bg_protect"
- android:tileMode="repeat"
- />
-
diff --git a/packages/SystemUI/res/layout/status_bar_expanded.xml b/packages/SystemUI/res/layout/status_bar_expanded.xml
index dbbaf96..b63afbe 100644
--- a/packages/SystemUI/res/layout/status_bar_expanded.xml
+++ b/packages/SystemUI/res/layout/status_bar_expanded.xml
@@ -86,6 +86,16 @@
android:layout_height="wrap_content"
android:layout_weight="1"
>
+ <TextView android:id="@+id/noNotificationsTitle"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="@android:style/TextAppearance.Large"
+ android:padding="8dp"
+ android:layout_gravity="top"
+ android:gravity="center"
+ android:text="@string/status_bar_no_notifications_title"
+ />
+
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
@@ -93,29 +103,12 @@
android:fadingEdge="none"
android:overScrollMode="ifContentScrolls"
>
- <LinearLayout
- android:id="@+id/notificationLinearLayout"
+ <com.android.systemui.statusbar.policy.NotificationRowLayout
+ android:id="@+id/latestItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical"
- >
-
- <TextView android:id="@+id/noNotificationsTitle"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="@android:style/TextAppearance.Large"
- android:padding="8dp"
- android:gravity="center"
- android:text="@string/status_bar_no_notifications_title"
- />
-
- <com.android.systemui.statusbar.policy.NotificationRowLayout
- android:id="@+id/latestItems"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- systemui:rowHeight="@dimen/notification_height"
- />
- </LinearLayout>
+ systemui:rowHeight="@dimen/notification_height"
+ />
</ScrollView>
<ImageView
diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml
index 0219a77..3919685 100644
--- a/packages/SystemUI/res/values-land/dimens.xml
+++ b/packages/SystemUI/res/values-land/dimens.xml
@@ -17,7 +17,7 @@
-->
<resources>
<!-- thickness (width) of the navigation bar on phones that require it -->
- <dimen name="navigation_bar_size">42dp</dimen>
+ <dimen name="navigation_bar_size">@*android:dimen/navigation_bar_width</dimen>
<!-- Recent Applications parameters -->
<!-- Width of a recent app view, including all content -->
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index ba1aea3..ef9b8dd 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -40,7 +40,7 @@
<dimen name="peek_window_y_offset">-12dp</dimen>
<!-- thickness (height) of the navigation bar on phones that require it -->
- <dimen name="navigation_bar_size">48dp</dimen>
+ <dimen name="navigation_bar_size">@*android:dimen/navigation_bar_height</dimen>
<!-- thickness (height) of the dead zone at the top of the navigation bar,
reducing false presses on navbar buttons; approx 2mm -->
diff --git a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
index 6ecfd94..2818f87 100644
--- a/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
@@ -43,6 +43,7 @@
private float SWIPE_ESCAPE_VELOCITY = 100f; // dp/sec
private int MAX_ESCAPE_ANIMATION_DURATION = 500; // ms
+ private int MAX_DISMISS_VELOCITY = 1000; // dp/sec
private static final int SNAP_ANIM_LEN = SLOW_ANIMATIONS ? 1000 : 250; // ms
public static float ALPHA_FADE_START = 0.8f; // fraction of thumbnail width
@@ -281,7 +282,7 @@
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (mCurrView != null) {
- float maxVelocity = 1000; // px/sec
+ float maxVelocity = MAX_DISMISS_VELOCITY * mDensityScale;
mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, maxVelocity);
float escapeVelocity = SWIPE_ESCAPE_VELOCITY * mDensityScale;
float velocity = getVelocity(mVelocityTracker);
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
index 14efdd0..36f1659 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
@@ -165,6 +165,13 @@
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
+
+ // Skip this work if a transition is running; it sets the scroll values independently
+ // and should not have those animated values clobbered by this logic
+ LayoutTransition transition = mLinearLayout.getLayoutTransition();
+ if (transition != null && transition.isRunning()) {
+ return;
+ }
// Keep track of the last visible item in the list so we can restore it
// to the bottom when the orientation changes.
mLastScrollPosition = scrollPositionOfMostRecent();
@@ -172,7 +179,12 @@
// This has to happen post-layout, so run it "in the future"
post(new Runnable() {
public void run() {
- scrollTo(mLastScrollPosition, 0);
+ // Make sure we're still not clobbering the transition-set values, since this
+ // runnable launches asynchronously
+ LayoutTransition transition = mLinearLayout.getLayoutTransition();
+ if (transition == null || !transition.isRunning()) {
+ scrollTo(mLastScrollPosition, 0);
+ }
}
});
}
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
index 1bcc413..89900a1 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
@@ -166,6 +166,13 @@
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
+
+ // Skip this work if a transition is running; it sets the scroll values independently
+ // and should not have those animated values clobbered by this logic
+ LayoutTransition transition = mLinearLayout.getLayoutTransition();
+ if (transition != null && transition.isRunning()) {
+ return;
+ }
// Keep track of the last visible item in the list so we can restore it
// to the bottom when the orientation changes.
mLastScrollPosition = scrollPositionOfMostRecent();
@@ -173,7 +180,12 @@
// This has to happen post-layout, so run it "in the future"
post(new Runnable() {
public void run() {
- scrollTo(0, mLastScrollPosition);
+ // Make sure we're still not clobbering the transition-set values, since this
+ // runnable launches asynchronously
+ LayoutTransition transition = mLinearLayout.getLayoutTransition();
+ if (transition == null || !transition.isRunning()) {
+ scrollTo(0, mLastScrollPosition);
+ }
}
});
}
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
index fc21929..86dc9a6 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
@@ -91,7 +91,7 @@
try {
long currentTime = System.currentTimeMillis();
- String date = new SimpleDateFormat("yyyy-MM-dd-kk-mm-ss").format(new Date(currentTime));
+ String date = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date(currentTime));
String imageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).getAbsolutePath();
String imageFileName = String.format(SCREENSHOT_FILE_NAME_TEMPLATE, date);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index 2740898..abf505c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -112,7 +112,7 @@
public void onAnimationEnd(Animator _a) {
mLastAnimator = null;
if (hide) {
- setVisibility(View.INVISIBLE);
+ setVisibility(View.GONE);
}
}
});
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index e14317b..a54c5c2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.phone;
+import android.animation.ObjectAnimator;
import android.app.ActivityManagerNative;
import android.app.Dialog;
import android.app.Notification;
@@ -42,6 +43,7 @@
import android.os.SystemClock;
import android.provider.Settings;
import android.text.TextUtils;
+import android.util.DisplayMetrics;
import android.util.Slog;
import android.util.Log;
import android.view.Display;
@@ -85,8 +87,8 @@
public class PhoneStatusBar extends StatusBar {
static final String TAG = "PhoneStatusBar";
- static final boolean SPEW = false;
public static final boolean DEBUG = false;
+ public static final boolean SPEW = false;
// additional instrumentation for testing purposes; intended to be left on during development
public static final boolean CHATTY = DEBUG || true;
@@ -136,7 +138,6 @@
ExpandedView mExpandedView;
WindowManager.LayoutParams mExpandedParams;
ScrollView mScrollView;
- View mNotificationLinearLayout;
View mExpandedContents;
// top bar
TextView mNoNotificationsTitle;
@@ -201,11 +202,11 @@
// tracking calls to View.setSystemUiVisibility()
int mSystemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
- final Point mDisplaySize = new Point();
+ DisplayMetrics mDisplayMetrics = new DisplayMetrics();
private class ExpandedDialog extends Dialog {
ExpandedDialog(Context context) {
- super(context, com.android.internal.R.style.Theme_Light_NoTitleBar);
+ super(context, com.android.internal.R.style.Theme_Translucent_NoTitleBar);
}
@Override
@@ -248,7 +249,12 @@
Resources res = context.getResources();
- mDisplay.getSize(mDisplaySize);
+ mDisplay.getMetrics(mDisplayMetrics);
+ if (DEBUG) {
+ Slog.d(TAG, "makeStatusBarView: mDisplayMetrics=" + mDisplayMetrics);
+ mDisplayMetrics = res.getDisplayMetrics();
+ Slog.d(TAG, "makeStatusBarView: mDisplayMetrics2=" + mDisplayMetrics);
+ }
loadDimens();
mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size);
@@ -305,16 +311,18 @@
mExpandedDialog = new ExpandedDialog(context);
mExpandedView = expanded;
- mExpandedContents = expanded.findViewById(R.id.notificationLinearLayout);
mPile = (ViewGroup)expanded.findViewById(R.id.latestItems);
+ mExpandedContents = mPile; // was: expanded.findViewById(R.id.notificationLinearLayout);
mNoNotificationsTitle = (TextView)expanded.findViewById(R.id.noNotificationsTitle);
+ mNoNotificationsTitle.setAlpha(0f);
+ mNoNotificationsTitle.setVisibility(View.VISIBLE);
mClearButton = expanded.findViewById(R.id.clear_all_button);
mClearButton.setOnClickListener(mClearButtonListener);
+ mClearButton.setAlpha(0f);
mDateView = (DateView)expanded.findViewById(R.id.date);
mSettingsButton = expanded.findViewById(R.id.settings_button);
mSettingsButton.setOnClickListener(mSettingsButtonListener);
mScrollView = (ScrollView)expanded.findViewById(R.id.scroll);
- mNotificationLinearLayout = expanded.findViewById(R.id.notificationLinearLayout);
mTicker = new MyTicker(context, sb);
@@ -549,7 +557,9 @@
boolean immersive = false;
try {
immersive = ActivityManagerNative.getDefault().isTopActivityImmersive();
- Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive"));
+ if (DEBUG) {
+ Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive"));
+ }
} catch (RemoteException ex) {
}
if (immersive) {
@@ -579,8 +589,7 @@
}
} else if (notification.notification.fullScreenIntent != null) {
// not immersive & a full-screen alert should be shown
- Slog.d(TAG, "Notification has fullScreenIntent and activity is not immersive;"
- + " sending fullScreenIntent");
+ Slog.d(TAG, "Notification has fullScreenIntent; sending fullScreenIntent");
try {
notification.notification.fullScreenIntent.send();
} catch (PendingIntent.CanceledException e) {
@@ -701,9 +710,10 @@
mTicker.removeEntry(old);
// Recalculate the position of the sliding windows and the titles.
- setAreThereNotifications();
updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
}
+
+ setAreThereNotifications();
}
@Override
@@ -1008,13 +1018,37 @@
}
private void setAreThereNotifications() {
- mClearButton.setVisibility(mNotificationData.hasClearableItems()
- ? View.VISIBLE
- : View.INVISIBLE);
+ final boolean any = mNotificationData.size() > 0;
- mNoNotificationsTitle.setVisibility(mNotificationData.size() > 0
- ? View.GONE
- : View.VISIBLE);
+ final boolean clearable = any && mNotificationData.hasClearableItems();
+
+ if (DEBUG) {
+ Slog.d(TAG, "setAreThereNotifications: N=" + mNotificationData.size()
+ + " any=" + any + " clearable=" + clearable);
+ }
+
+ if (mClearButton.isShown()) {
+ if (clearable != (mClearButton.getAlpha() == 1.0f)) {
+ ObjectAnimator.ofFloat(mClearButton, "alpha",
+ clearable ? 1.0f : 0.0f)
+ .setDuration(250)
+ .start();
+ }
+ } else {
+ mClearButton.setAlpha(clearable ? 1.0f : 0.0f);
+ }
+
+ if (mNoNotificationsTitle.isShown()) {
+ if (any != (mNoNotificationsTitle.getAlpha() == 0.0f)) {
+ ObjectAnimator a = ObjectAnimator.ofFloat(mNoNotificationsTitle, "alpha",
+ (any ? 0.0f : 0.75f));
+ a.setDuration(any ? 0 : 500);
+ a.setStartDelay(any ? 250 : 1000);
+ a.start();
+ }
+ } else {
+ mNoNotificationsTitle.setAlpha(any ? 0.0f : 0.75f);
+ }
}
@@ -1110,6 +1144,9 @@
updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
mExpandedParams.flags &= ~WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
mExpandedParams.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
+ if (DEBUG) {
+ Slog.d(TAG, "makeExpandedVisible: expanded params = " + mExpandedParams);
+ }
mExpandedDialog.getWindow().setAttributes(mExpandedParams);
mExpandedView.requestFocus(View.FOCUS_FORWARD);
mTrackingView.setVisibility(View.VISIBLE);
@@ -1155,7 +1192,7 @@
if (mAnimating) {
y = (int)mAnimY;
} else {
- y = mDisplaySize.y-1;
+ y = mDisplayMetrics.heightPixels-1;
}
// Let the fling think that we're open so it goes in the right direction
// and doesn't try to re-open the windowshade.
@@ -1210,7 +1247,7 @@
if (SPEW) Slog.d(TAG, "doAnimation before mAnimY=" + mAnimY);
incrementAnim();
if (SPEW) Slog.d(TAG, "doAnimation after mAnimY=" + mAnimY);
- if (mAnimY >= mDisplaySize.y-1) {
+ if (mAnimY >= mDisplayMetrics.heightPixels-1) {
if (SPEW) Slog.d(TAG, "Animation completed to expanded state.");
mAnimating = false;
updateExpandedViewPos(EXPANDED_FULL_OPEN);
@@ -1317,7 +1354,7 @@
if (mExpanded) {
if (!always && (
vel > 200.0f
- || (y > (mDisplaySize.y-25) && vel > -200.0f))) {
+ || (y > (mDisplayMetrics.heightPixels-25) && vel > -200.0f))) {
// We are expanded, but they didn't move sufficiently to cause
// us to retract. Animate back to the expanded position.
mAnimAccel = 2000.0f;
@@ -1335,7 +1372,7 @@
} else {
if (always || (
vel > 200.0f
- || (y > (mDisplaySize.y/2) && vel > -200.0f))) {
+ || (y > (mDisplayMetrics.heightPixels/2) && vel > -200.0f))) {
// We are collapsed, and they moved enough to allow us to
// expand. Animate in the notifications.
mAnimAccel = 2000.0f;
@@ -1393,14 +1430,14 @@
mViewDelta = mAbsPos[1] + mTrackingView.getHeight() - y;
}
if ((!mExpanded && y < hitSize) ||
- (mExpanded && y > (mDisplaySize.y-hitSize))) {
+ (mExpanded && y > (mDisplayMetrics.heightPixels-hitSize))) {
// We drop events at the edge of the screen to make the windowshade come
// down by accident less, especially when pushing open a device with a keyboard
// that rotates (like g1 and droid)
int x = (int)event.getRawX();
final int edgeBorder = mEdgeBorder;
- if (x >= edgeBorder && x < mDisplaySize.x - edgeBorder) {
+ if (x >= edgeBorder && x < mDisplayMetrics.widthPixels - edgeBorder) {
prepareTracking(y, !mExpanded);// opening if we're not already fully visible
mVelocityTracker.addMovement(event);
}
@@ -1641,7 +1678,7 @@
+ " mAnimLastTime=" + mAnimLastTime);
pw.println(" mAnimatingReveal=" + mAnimatingReveal
+ " mViewDelta=" + mViewDelta);
- pw.println(" mDisplaySize=" + mDisplaySize);
+ pw.println(" mDisplayMetrics=" + mDisplayMetrics);
pw.println(" mExpandedParams: " + mExpandedParams);
pw.println(" mExpandedView: " + viewInfo(mExpandedView));
pw.println(" mExpandedDialog: " + mExpandedDialog);
@@ -1653,7 +1690,6 @@
pw.println(" mTickerView: " + viewInfo(mTickerView));
pw.println(" mScrollView: " + viewInfo(mScrollView)
+ " scroll " + mScrollView.getScrollX() + "," + mScrollView.getScrollY());
- pw.println("mNotificationLinearLayout: " + viewInfo(mNotificationLinearLayout));
}
/*
synchronized (mNotificationData) {
@@ -1717,7 +1753,8 @@
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL,
- WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+ 0
+ | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
pixelFormat);
@@ -1739,9 +1776,10 @@
lp = mExpandedDialog.getWindow().getAttributes();
lp.x = 0;
- mTrackingPosition = lp.y = mDisplaySize.y; // sufficiently large negative
+ mTrackingPosition = lp.y = mDisplayMetrics.heightPixels; // sufficiently large negative
lp.type = WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
- lp.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+ lp.flags = 0
+ | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_DITHER
@@ -1772,14 +1810,14 @@
void updateExpandedInvisiblePosition() {
if (mTrackingView != null) {
- mTrackingPosition = -mDisplaySize.y;
+ mTrackingPosition = -mDisplayMetrics.heightPixels;
if (mTrackingParams != null) {
mTrackingParams.y = mTrackingPosition;
WindowManagerImpl.getDefault().updateViewLayout(mTrackingView, mTrackingParams);
}
}
if (mExpandedParams != null) {
- mExpandedParams.y = -mDisplaySize.y;
+ mExpandedParams.y = -mDisplayMetrics.heightPixels;
mExpandedDialog.getWindow().setAttributes(mExpandedParams);
}
}
@@ -1792,7 +1830,7 @@
}
int h = mStatusBarView.getHeight();
- int disph = mDisplaySize.y;
+ int disph = mDisplayMetrics.heightPixels;
// If the expanded view is not visible, make sure they're still off screen.
// Maybe the view was resized.
@@ -1845,7 +1883,7 @@
// If the tracking view is not yet visible, then we can't have
// a good value of the close view location. We need to wait for
// it to be visible to do a layout.
- mExpandedParams.y = -mDisplaySize.y;
+ mExpandedParams.y = -mDisplayMetrics.heightPixels;
}
int max = h;
if (mExpandedParams.y > max) {
@@ -1891,7 +1929,10 @@
}
void updateDisplaySize() {
- mDisplay.getSize(mDisplaySize);
+ mDisplay.getMetrics(mDisplayMetrics);
+ if (DEBUG) {
+ Slog.d(TAG, "updateDisplaySize: " + mDisplayMetrics);
+ }
updateExpandedSize();
}
@@ -1899,9 +1940,9 @@
if (DEBUG) {
Slog.d(TAG, "updateExpandedSize()");
}
- if (mExpandedDialog != null && mExpandedParams != null && mDisplaySize != null) {
- mExpandedParams.width = mDisplaySize.x;
- mExpandedParams.height = getExpandedHeight(mDisplaySize.y);
+ if (mExpandedDialog != null && mExpandedParams != null && mDisplayMetrics != null) {
+ mExpandedParams.width = mDisplayMetrics.widthPixels;
+ mExpandedParams.height = getExpandedHeight(mDisplayMetrics.heightPixels);
if (!mExpandedVisible) {
updateExpandedInvisiblePosition();
} else {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/TrackingView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/TrackingView.java
index fc0f332..cc23afc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/TrackingView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/TrackingView.java
@@ -26,7 +26,6 @@
public class TrackingView extends LinearLayout {
- final Display mDisplay;
PhoneStatusBar mService;
boolean mTracking;
int mStartX, mStartY;
@@ -34,8 +33,6 @@
public TrackingView(Context context, AttributeSet attrs) {
super(context, attrs);
- mDisplay = ((WindowManager)context.getSystemService(
- Context.WINDOW_SERVICE)).getDefaultDisplay();
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java
index 2a0dfb5..469b462 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java
@@ -166,20 +166,16 @@
mAppearingViews.add(child);
child.setPivotY(0);
- AnimatorSet a = new AnimatorSet();
- a.playTogether(
- ObjectAnimator.ofFloat(child, "alpha", 0f, 1f)
-// ,ObjectAnimator.ofFloat(child, "scaleY", 0f, 1f)
- );
- a.setDuration(APPEAR_ANIM_LEN);
- a.addListener(new AnimatorListenerAdapter() {
+ final ObjectAnimator alphaFade = ObjectAnimator.ofFloat(child, "alpha", 0f, 1f);
+ alphaFade.setDuration(APPEAR_ANIM_LEN);
+ alphaFade.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mAppearingViews.remove(childF);
requestLayout(); // pick up any final changes in position
}
});
- a.start();
+ alphaFade.start();
requestLayout(); // start the container animation
}
}
@@ -195,23 +191,10 @@
child.setPivotY(0);
- //final float velocity = (mSlidingChild == child)
- // ? Math.min(mLiftoffVelocity, SWIPE_ANIM_VELOCITY_MIN)
- // : SWIPE_ESCAPE_VELOCITY;
- final float velocity = 0f;
- final TimeAnimator zoom = new TimeAnimator();
- zoom.setTimeListener(new TimeAnimator.TimeListener() {
- @Override
- public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
- childF.setTranslationX(childF.getTranslationX() + deltaTime / 1000f * velocity);
- }
- });
-
final ObjectAnimator alphaFade = ObjectAnimator.ofFloat(child, "alpha", 0f);
alphaFade.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- zoom.cancel(); // it won't end on its own
if (DEBUG) Slog.d(TAG, "actually removing child: " + childF);
NotificationRowLayout.super.removeView(childF);
childF.setAlpha(1f);
@@ -220,14 +203,8 @@
}
});
- AnimatorSet a = new AnimatorSet();
- a.playTogether(alphaFade, zoom);
-
-// ,ObjectAnimator.ofFloat(child, "scaleY", 0f)
-// ,ObjectAnimator.ofFloat(child, "translationX", child.getTranslationX() + 300f)
-
- a.setDuration(DISAPPEAR_ANIM_LEN);
- a.start();
+ alphaFade.setDuration(DISAPPEAR_ANIM_LEN);
+ alphaFade.start();
requestLayout(); // start the container animation
} else {
super.removeView(child);
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index a2dbb78..ff8dc92 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -243,6 +243,8 @@
int mStatusBarHeight;
final ArrayList<WindowState> mStatusBarPanels = new ArrayList<WindowState>();
WindowState mNavigationBar = null;
+ boolean mHasNavigationBar = false;
+ int mNavigationBarWidth = 0, mNavigationBarHeight = 0;
WindowState mKeyguard = null;
KeyguardViewMediator mKeyguardMediator;
@@ -796,6 +798,17 @@
mStatusBarCanHide
? com.android.internal.R.dimen.status_bar_height
: com.android.internal.R.dimen.system_bar_height);
+
+ mHasNavigationBar = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_showNavigationBar);
+ mNavigationBarHeight = mHasNavigationBar
+ ? mContext.getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.navigation_bar_height)
+ : 0;
+ mNavigationBarWidth = mHasNavigationBar
+ ? mContext.getResources().getDimensionPixelSize(
+ com.android.internal.R.dimen.navigation_bar_width)
+ : 0;
}
public void updateSettings() {
@@ -1110,19 +1123,26 @@
}
public int getNonDecorDisplayWidth(int rotation, int fullWidth) {
- return fullWidth;
+ // Assumes that the navigation bar appears on the side of the display in landscape.
+ final boolean horizontal
+ = (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90);
+ return fullWidth - (horizontal ? mNavigationBarWidth : 0);
}
public int getNonDecorDisplayHeight(int rotation, int fullHeight) {
- return mStatusBarCanHide ? fullHeight : (fullHeight - mStatusBarHeight);
+ final boolean horizontal
+ = (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90);
+ return fullHeight
+ - (mStatusBarCanHide ? 0 : mStatusBarHeight)
+ - (horizontal ? 0 : mNavigationBarHeight);
}
public int getConfigDisplayWidth(int rotation, int fullWidth) {
- return fullWidth;
+ return getNonDecorDisplayWidth(rotation, fullWidth);
}
public int getConfigDisplayHeight(int rotation, int fullHeight) {
- return fullHeight - mStatusBarHeight;
+ return getNonDecorDisplayHeight(rotation, fullHeight);
}
public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
@@ -1851,7 +1871,8 @@
final Rect cf = mTmpContentFrame;
final Rect vf = mTmpVisibleFrame;
- final boolean hasNavBar = (mNavigationBar != null && mNavigationBar.isVisibleLw());
+ final boolean hasNavBar = (mHasNavigationBar
+ && mNavigationBar != null && mNavigationBar.isVisibleLw());
if (attrs.type == TYPE_INPUT_METHOD) {
pf.left = df.left = cf.left = vf.left = mDockLeft;
@@ -1943,6 +1964,11 @@
? mRestrictedScreenTop+mRestrictedScreenHeight
: mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
+ if (DEBUG_LAYOUT) {
+ Log.v(TAG, String.format(
+ "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
+ pf.left, pf.top, pf.right, pf.bottom));
+ }
} else if (attrs.type == TYPE_NAVIGATION_BAR) {
// The navigation bar has Real Ultimate Power.
pf.left = df.left = mUnrestrictedScreenLeft;
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
index 7ea3de2..960e414 100644
--- a/services/input/EventHub.cpp
+++ b/services/input/EventHub.cpp
@@ -205,27 +205,30 @@
RawAbsoluteAxisInfo* outAxisInfo) const {
outAxisInfo->clear();
- AutoMutex _l(mLock);
- Device* device = getDeviceLocked(deviceId);
- if (device == NULL) return -1;
+ if (axis >= 0 && axis <= ABS_MAX) {
+ AutoMutex _l(mLock);
- struct input_absinfo info;
+ Device* device = getDeviceLocked(deviceId);
+ if (device && test_bit(axis, device->absBitmask)) {
+ struct input_absinfo info;
+ if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
+ LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
+ axis, device->identifier.name.string(), device->fd, errno);
+ return -errno;
+ }
- if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
- LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
- axis, device->identifier.name.string(), device->fd, errno);
- return -errno;
+ if (info.minimum != info.maximum) {
+ outAxisInfo->valid = true;
+ outAxisInfo->minValue = info.minimum;
+ outAxisInfo->maxValue = info.maximum;
+ outAxisInfo->flat = info.flat;
+ outAxisInfo->fuzz = info.fuzz;
+ outAxisInfo->resolution = info.resolution;
+ }
+ return OK;
+ }
}
-
- if (info.minimum != info.maximum) {
- outAxisInfo->valid = true;
- outAxisInfo->minValue = info.minimum;
- outAxisInfo->maxValue = info.maximum;
- outAxisInfo->flat = info.flat;
- outAxisInfo->fuzz = info.fuzz;
- outAxisInfo->resolution = info.resolution;
- }
- return OK;
+ return -1;
}
bool EventHub::hasRelativeAxis(int32_t deviceId, int axis) const {
@@ -233,7 +236,7 @@
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device && device->relBitmask) {
+ if (device) {
return test_bit(axis, device->relBitmask);
}
}
@@ -245,7 +248,7 @@
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device && device->propBitmask) {
+ if (device) {
return test_bit(property, device->propBitmask);
}
}
@@ -257,58 +260,37 @@
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device != NULL) {
- return getScanCodeStateLocked(device, scanCode);
+ if (device && test_bit(scanCode, device->keyBitmask)) {
+ uint8_t keyState[sizeof_bit_array(KEY_MAX + 1)];
+ memset(keyState, 0, sizeof(keyState));
+ if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
+ return test_bit(scanCode, keyState) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
+ }
}
}
return AKEY_STATE_UNKNOWN;
}
-int32_t EventHub::getScanCodeStateLocked(Device* device, int32_t scanCode) const {
- uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)];
- memset(key_bitmask, 0, sizeof(key_bitmask));
- if (ioctl(device->fd,
- EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
- return test_bit(scanCode, key_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
- }
- return AKEY_STATE_UNKNOWN;
-}
-
int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device != NULL) {
- return getKeyCodeStateLocked(device, keyCode);
- }
- return AKEY_STATE_UNKNOWN;
-}
-
-int32_t EventHub::getKeyCodeStateLocked(Device* device, int32_t keyCode) const {
- if (!device->keyMap.haveKeyLayout()) {
- return AKEY_STATE_UNKNOWN;
- }
-
- Vector<int32_t> scanCodes;
- device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes);
-
- uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)];
- memset(key_bitmask, 0, sizeof(key_bitmask));
- if (ioctl(device->fd, EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
- #if 0
- for (size_t i=0; i<=KEY_MAX; i++) {
- LOGI("(Scan code %d: down=%d)", i, test_bit(i, key_bitmask));
- }
- #endif
- const size_t N = scanCodes.size();
- for (size_t i=0; i<N && i<=KEY_MAX; i++) {
- int32_t sc = scanCodes.itemAt(i);
- //LOGI("Code %d: down=%d", sc, test_bit(sc, key_bitmask));
- if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, key_bitmask)) {
- return AKEY_STATE_DOWN;
+ if (device && device->keyMap.haveKeyLayout()) {
+ Vector<int32_t> scanCodes;
+ device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes);
+ if (scanCodes.size() != 0) {
+ uint8_t keyState[sizeof_bit_array(KEY_MAX + 1)];
+ memset(keyState, 0, sizeof(keyState));
+ if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
+ for (size_t i = 0; i < scanCodes.size(); i++) {
+ int32_t sc = scanCodes.itemAt(i);
+ if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, keyState)) {
+ return AKEY_STATE_DOWN;
+ }
+ }
+ return AKEY_STATE_UP;
}
}
- return AKEY_STATE_UP;
}
return AKEY_STATE_UNKNOWN;
}
@@ -318,85 +300,64 @@
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device != NULL) {
- return getSwitchStateLocked(device, sw);
+ if (device && test_bit(sw, device->swBitmask)) {
+ uint8_t swState[sizeof_bit_array(SW_MAX + 1)];
+ memset(swState, 0, sizeof(swState));
+ if (ioctl(device->fd, EVIOCGSW(sizeof(swState)), swState) >= 0) {
+ return test_bit(sw, swState) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
+ }
}
}
return AKEY_STATE_UNKNOWN;
}
-int32_t EventHub::getSwitchStateLocked(Device* device, int32_t sw) const {
- uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)];
- memset(sw_bitmask, 0, sizeof(sw_bitmask));
- if (ioctl(device->fd,
- EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) {
- return test_bit(sw, sw_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
- }
- return AKEY_STATE_UNKNOWN;
-}
-
status_t EventHub::getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const {
if (axis >= 0 && axis <= ABS_MAX) {
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device != NULL) {
- return getAbsoluteAxisValueLocked(device, axis, outValue);
+ if (device && test_bit(axis, device->absBitmask)) {
+ struct input_absinfo info;
+ if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
+ LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
+ axis, device->identifier.name.string(), device->fd, errno);
+ return -errno;
+ }
+
+ *outValue = info.value;
+ return OK;
}
}
*outValue = 0;
return -1;
}
-status_t EventHub::getAbsoluteAxisValueLocked(Device* device, int32_t axis,
- int32_t* outValue) const {
- struct input_absinfo info;
-
- if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
- LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
- axis, device->identifier.name.string(), device->fd, errno);
- return -errno;
- }
-
- *outValue = info.value;
- return OK;
-}
-
bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
const int32_t* keyCodes, uint8_t* outFlags) const {
AutoMutex _l(mLock);
Device* device = getDeviceLocked(deviceId);
- if (device != NULL) {
- return markSupportedKeyCodesLocked(device, numCodes, keyCodes, outFlags);
- }
- return false;
-}
+ if (device && device->keyMap.haveKeyLayout()) {
+ Vector<int32_t> scanCodes;
+ for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) {
+ scanCodes.clear();
-bool EventHub::markSupportedKeyCodesLocked(Device* device, size_t numCodes,
- const int32_t* keyCodes, uint8_t* outFlags) const {
- if (!device->keyMap.haveKeyLayout()) {
- return false;
- }
-
- Vector<int32_t> scanCodes;
- for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) {
- scanCodes.clear();
-
- status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey(
- keyCodes[codeIndex], &scanCodes);
- if (! err) {
- // check the possible scan codes identified by the layout map against the
- // map of codes actually emitted by the driver
- for (size_t sc = 0; sc < scanCodes.size(); sc++) {
- if (test_bit(scanCodes[sc], device->keyBitmask)) {
- outFlags[codeIndex] = 1;
- break;
+ status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey(
+ keyCodes[codeIndex], &scanCodes);
+ if (! err) {
+ // check the possible scan codes identified by the layout map against the
+ // map of codes actually emitted by the driver
+ for (size_t sc = 0; sc < scanCodes.size(); sc++) {
+ if (test_bit(scanCodes[sc], device->keyBitmask)) {
+ outFlags[codeIndex] = 1;
+ break;
+ }
}
}
}
+ return true;
}
- return true;
+ return false;
}
status_t EventHub::mapKey(int32_t deviceId, int scancode,
@@ -1333,4 +1294,11 @@
} // release lock
}
+void EventHub::monitor() {
+ // Acquire and release the lock to ensure that the event hub has not deadlocked.
+ mLock.lock();
+ mLock.unlock();
+}
+
+
}; // namespace android
diff --git a/services/input/EventHub.h b/services/input/EventHub.h
index 293a1a0..fae5d4f 100644
--- a/services/input/EventHub.h
+++ b/services/input/EventHub.h
@@ -208,7 +208,11 @@
/* Wakes up getEvents() if it is blocked on a read. */
virtual void wake() = 0;
+ /* Dump EventHub state to a string. */
virtual void dump(String8& dump) = 0;
+
+ /* Called by the heatbeat to ensures that the reader has not deadlocked. */
+ virtual void monitor() = 0;
};
class EventHub : public EventHubInterface
@@ -259,6 +263,7 @@
virtual void wake();
virtual void dump(String8& dump);
+ virtual void monitor();
protected:
virtual ~EventHub();
@@ -307,13 +312,6 @@
bool hasKeycodeLocked(Device* device, int keycode) const;
- int32_t getScanCodeStateLocked(Device* device, int32_t scanCode) const;
- int32_t getKeyCodeStateLocked(Device* device, int32_t keyCode) const;
- int32_t getSwitchStateLocked(Device* device, int32_t sw) const;
- int32_t getAbsoluteAxisValueLocked(Device* device, int32_t axis, int32_t* outValue) const;
- bool markSupportedKeyCodesLocked(Device* device, size_t numCodes,
- const int32_t* keyCodes, uint8_t* outFlags) const;
-
void loadConfigurationLocked(Device* device);
status_t loadVirtualKeyMapLocked(Device* device);
status_t loadKeyMapLocked(Device* device);
diff --git a/services/input/InputDispatcher.cpp b/services/input/InputDispatcher.cpp
index ce9e14f..22372cf 100644
--- a/services/input/InputDispatcher.cpp
+++ b/services/input/InputDispatcher.cpp
@@ -3919,6 +3919,8 @@
}
void InputDispatcher::dump(String8& dump) {
+ AutoMutex _l(mLock);
+
dump.append("Input Dispatcher State:\n");
dumpDispatchStateLocked(dump);
@@ -3928,6 +3930,12 @@
dump.appendFormat(INDENT2 "KeyRepeatTimeout: %0.1fms\n", mConfig.keyRepeatTimeout * 0.000001f);
}
+void InputDispatcher::monitor() {
+ // Acquire and release the lock to ensure that the dispatcher has not deadlocked.
+ mLock.lock();
+ mLock.unlock();
+}
+
// --- InputDispatcher::Queue ---
diff --git a/services/input/InputDispatcher.h b/services/input/InputDispatcher.h
index 01c7b35..cae1610 100644
--- a/services/input/InputDispatcher.h
+++ b/services/input/InputDispatcher.h
@@ -282,6 +282,9 @@
* This method may be called on any thread (usually by the input manager). */
virtual void dump(String8& dump) = 0;
+ /* Called by the heatbeat to ensures that the dispatcher has not deadlocked. */
+ virtual void monitor() = 0;
+
/* Runs a single iteration of the dispatch loop.
* Nominally processes one queued event, a timeout, or a response from an input consumer.
*
@@ -370,6 +373,7 @@
explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy);
virtual void dump(String8& dump);
+ virtual void monitor();
virtual void dispatchOnce();
diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp
index 8786c24..2eacbeb 100644
--- a/services/input/InputReader.cpp
+++ b/services/input/InputReader.cpp
@@ -731,6 +731,15 @@
mConfig.pointerGestureZoomSpeedRatio);
}
+void InputReader::monitor() {
+ // Acquire and release the lock to ensure that the reader has not deadlocked.
+ mLock.lock();
+ mLock.unlock();
+
+ // Check the EventHub
+ mEventHub->monitor();
+}
+
// --- InputReader::ContextImpl ---
@@ -1170,9 +1179,8 @@
return AMOTION_EVENT_TOOL_TYPE_UNKNOWN;
}
-bool TouchButtonAccumulator::isActive() const {
- return mBtnTouch || mBtnToolFinger || mBtnToolPen
- || mBtnToolRubber || mBtnStylus || mBtnStylus2;
+bool TouchButtonAccumulator::isToolActive() const {
+ return mBtnTouch || mBtnToolFinger || mBtnToolPen || mBtnToolRubber;
}
bool TouchButtonAccumulator::isHovering() const {
@@ -5144,7 +5152,7 @@
mCurrentRawPointerData.clear();
mCurrentButtonState = 0;
- if (mTouchButtonAccumulator.isActive()) {
+ if (mTouchButtonAccumulator.isToolActive()) {
mCurrentRawPointerData.pointerCount = 1;
mCurrentRawPointerData.idToIndex[0] = 0;
@@ -5168,11 +5176,11 @@
outPointer.toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
}
outPointer.isHovering = isHovering;
-
- mCurrentButtonState = mTouchButtonAccumulator.getButtonState()
- | mCursorButtonAccumulator.getButtonState();
}
+ mCurrentButtonState = mTouchButtonAccumulator.getButtonState()
+ | mCursorButtonAccumulator.getButtonState();
+
syncTouch(when, true);
}
diff --git a/services/input/InputReader.h b/services/input/InputReader.h
index f5d095d..e9daef5 100644
--- a/services/input/InputReader.h
+++ b/services/input/InputReader.h
@@ -210,6 +210,9 @@
* This method may be called on any thread (usually by the input manager). */
virtual void dump(String8& dump) = 0;
+ /* Called by the heatbeat to ensures that the reader has not deadlocked. */
+ virtual void monitor() = 0;
+
/* Runs a single iteration of the processing loop.
* Nominally reads and processes one incoming message from the EventHub.
*
@@ -297,6 +300,7 @@
virtual ~InputReader();
virtual void dump(String8& dump);
+ virtual void monitor();
virtual void loopOnce();
@@ -526,7 +530,7 @@
uint32_t getButtonState() const;
int32_t getToolType() const;
- bool isActive() const;
+ bool isToolActive() const;
bool isHovering() const;
private:
diff --git a/services/input/tests/InputReader_test.cpp b/services/input/tests/InputReader_test.cpp
index 4a866a8..87f212b 100644
--- a/services/input/tests/InputReader_test.cpp
+++ b/services/input/tests/InputReader_test.cpp
@@ -631,6 +631,9 @@
virtual void dump(String8& dump) {
}
+ virtual void monitor() {
+ }
+
virtual void requestReopenDevices() {
}
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 3ae7a3f..acfc7a4 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -1831,6 +1831,19 @@
for (RouteInfo r : routeDiff.added) {
if (isLinkDefault || ! r.isDefaultRoute()) {
addRoute(newLp, r);
+ } else {
+ // many radios add a default route even when we don't want one.
+ // remove the default route unless somebody else has asked for it
+ String ifaceName = newLp.getInterfaceName();
+ if (TextUtils.isEmpty(ifaceName) == false && mAddedRoutes.contains(r) == false) {
+ if (DBG) log("Removing " + r + " for interface " + ifaceName);
+ try {
+ mNetd.removeRoute(ifaceName, r);
+ } catch (Exception e) {
+ // never crash - catch them all
+ loge("Exception trying to remove a route: " + e);
+ }
+ }
}
}
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index 4b7256a..782e7d7 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -446,6 +446,28 @@
}
}
+ public void setInterfaceDown(String iface) throws IllegalStateException {
+ try {
+ InterfaceConfiguration ifcg = getInterfaceConfig(iface);
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace("up", "down");
+ setInterfaceConfig(iface, ifcg);
+ } catch (NativeDaemonConnectorException e) {
+ throw new IllegalStateException(
+ "Unable to communicate with native daemon for interface down - " + e);
+ }
+ }
+
+ public void setInterfaceUp(String iface) throws IllegalStateException {
+ try {
+ InterfaceConfiguration ifcg = getInterfaceConfig(iface);
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
+ setInterfaceConfig(iface, ifcg);
+ } catch (NativeDaemonConnectorException e) {
+ throw new IllegalStateException(
+ "Unable to communicate with native daemon for interface up - " + e);
+ }
+ }
+
/* TODO: This is right now a IPv4 only function. Works for wifi which loses its
IPv6 addresses on interface down, but we need to do full clean up here */
public void clearInterfaceAddresses(String iface) throws IllegalStateException {
diff --git a/services/java/com/android/server/wm/InputManager.java b/services/java/com/android/server/wm/InputManager.java
index 1d0857b..c8b18c8 100644
--- a/services/java/com/android/server/wm/InputManager.java
+++ b/services/java/com/android/server/wm/InputManager.java
@@ -17,6 +17,7 @@
package com.android.server.wm;
import com.android.internal.util.XmlUtils;
+import com.android.server.Watchdog;
import org.xmlpull.v1.XmlPullParser;
@@ -52,7 +53,7 @@
/*
* Wraps the C++ InputManager and provides its callbacks.
*/
-public class InputManager {
+public class InputManager implements Watchdog.Monitor {
static final String TAG = "InputManager";
private static final boolean DEBUG = false;
@@ -94,6 +95,7 @@
InputChannel toChannel);
private static native void nativeSetPointerSpeed(int speed);
private static native String nativeDump();
+ private static native void nativeMonitor();
// Input event injection constants defined in InputDispatcher.h.
static final int INPUT_EVENT_INJECTION_SUCCEEDED = 0;
@@ -135,6 +137,9 @@
Slog.i(TAG, "Initializing input manager");
nativeInit(mContext, mCallbacks, looper.getQueue());
+
+ // Add ourself to the Watchdog monitors.
+ Watchdog.getInstance().addMonitor(this);
}
public void start() {
@@ -456,6 +461,12 @@
}
}
+ // Called by the heartbeat to ensure locks are not held indefnitely (for deadlock detection).
+ public void monitor() {
+ synchronized (mInputFilterLock) { }
+ nativeMonitor();
+ }
+
private final class InputFilterHost implements InputFilter.Host {
private boolean mDisconnected;
diff --git a/services/jni/com_android_server_InputManager.cpp b/services/jni/com_android_server_InputManager.cpp
index 3414eea..7c84e43 100644
--- a/services/jni/com_android_server_InputManager.cpp
+++ b/services/jni/com_android_server_InputManager.cpp
@@ -1288,6 +1288,15 @@
return env->NewStringUTF(dump.string());
}
+static void android_server_InputManager_nativeMonitor(JNIEnv* env, jclass clazz) {
+ if (checkInputManagerUnitialized(env)) {
+ return;
+ }
+
+ gNativeInputManager->getInputManager()->getReader()->monitor();
+ gNativeInputManager->getInputManager()->getDispatcher()->monitor();
+}
+
// ----------------------------------------------------------------------------
static JNINativeMethod gInputManagerMethods[] = {
@@ -1338,6 +1347,8 @@
(void*) android_server_InputManager_nativeSetPointerSpeed },
{ "nativeDump", "()Ljava/lang/String;",
(void*) android_server_InputManager_nativeDump },
+ { "nativeMonitor", "()V",
+ (void*) android_server_InputManager_nativeMonitor },
};
#define FIND_CLASS(var, className) \
diff --git a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
index da5f488..ad3073a 100644
--- a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
+++ b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
@@ -167,10 +167,13 @@
},
new Test("Priority notification") {
public void run() {
- Notification not = new Notification(
- R.drawable.stat_sys_phone,
- "Incoming call from: Imperious Leader",
- System.currentTimeMillis()-(1000*60*60*24)
+ Notification not = new Notification();
+ not.icon = R.drawable.stat_sys_phone;
+ not.when = System.currentTimeMillis()-(1000*60*60*24);
+ not.setLatestEventInfo(StatusBarTest.this,
+ "Incoming call",
+ "from: Imperious Leader",
+ null
);
not.flags |= Notification.FLAG_HIGH_PRIORITY;
Intent fullScreenIntent = new Intent(StatusBarTest.this, TestAlertActivity.class);
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 8be5363..c6f7da2 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -1911,6 +1911,17 @@
transitionTo(mDriverUnloadingState);
break;
case CMD_START_SUPPLICANT:
+ //A runtime crash can leave the interface up and
+ //this affects connectivity when supplicant starts up.
+ //Ensure interface is down before a supplicant start.
+ try {
+ mNwService.setInterfaceDown(mInterfaceName);
+ } catch (RemoteException re) {
+ if (DBG) Log.w(TAG, "Unable to bring down wlan interface: " + re);
+ } catch (IllegalStateException ie) {
+ if (DBG) Log.w(TAG, "Unable to bring down wlan interface: " + ie);
+ }
+
if(WifiNative.startSupplicant()) {
Log.d(TAG, "Supplicant start successful");
mWifiMonitor.startMonitoring();