Merge "Add support for paths."
diff --git a/Android.mk b/Android.mk
index e0bd348..22216b0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -100,9 +100,11 @@
core/java/android/bluetooth/IBluetoothCallback.aidl \
core/java/android/bluetooth/IBluetoothHeadset.aidl \
core/java/android/bluetooth/IBluetoothPbap.aidl \
+ core/java/android/content/IClipboard.aidl \
core/java/android/content/IContentService.aidl \
core/java/android/content/IIntentReceiver.aidl \
core/java/android/content/IIntentSender.aidl \
+ core/java/android/content/IOnPrimaryClipChangedListener.aidl \
core/java/android/content/ISyncAdapter.aidl \
core/java/android/content/ISyncContext.aidl \
core/java/android/content/ISyncStatusObserver.aidl \
@@ -132,7 +134,6 @@
core/java/android/service/wallpaper/IWallpaperConnection.aidl \
core/java/android/service/wallpaper/IWallpaperEngine.aidl \
core/java/android/service/wallpaper/IWallpaperService.aidl \
- core/java/android/text/IClipboard.aidl \
core/java/android/view/accessibility/IAccessibilityManager.aidl \
core/java/android/view/accessibility/IAccessibilityManagerClient.aidl \
core/java/android/view/IApplicationToken.aidl \
diff --git a/api/9.xml b/api/9.xml
index 12ef981..abb67f9 100644
--- a/api/9.xml
+++ b/api/9.xml
@@ -303584,8 +303584,6 @@
</implements>
<implements name="java.io.Serializable">
</implements>
-<implements name="java.util.SortedSet">
-</implements>
<constructor name="TreeSet"
type="java.util.TreeSet"
static="false"
@@ -306943,10 +306941,6 @@
deprecated="not deprecated"
visibility="public"
>
-<implements name="java.util.concurrent.Future">
-</implements>
-<implements name="java.lang.Runnable">
-</implements>
<constructor name="FutureTask"
type="java.util.concurrent.FutureTask"
static="false"
@@ -339917,32 +339911,6 @@
deprecated="not deprecated"
visibility="public"
>
-<method name="getLogWriter"
- return="java.io.PrintWriter"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<exception name="SQLException" type="java.sql.SQLException">
-</exception>
-</method>
-<method name="getLoginTimeout"
- return="int"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<exception name="SQLException" type="java.sql.SQLException">
-</exception>
-</method>
<method name="getPooledConnection"
return="javax.sql.PooledConnection"
abstract="true"
@@ -339973,36 +339941,6 @@
<exception name="SQLException" type="java.sql.SQLException">
</exception>
</method>
-<method name="setLogWriter"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="theWriter" type="java.io.PrintWriter">
-</parameter>
-<exception name="SQLException" type="java.sql.SQLException">
-</exception>
-</method>
-<method name="setLoginTimeout"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="theTimeout" type="int">
-</parameter>
-<exception name="SQLException" type="java.sql.SQLException">
-</exception>
-</method>
</interface>
<interface name="DataSource"
abstract="true"
@@ -340041,62 +339979,6 @@
<exception name="SQLException" type="java.sql.SQLException">
</exception>
</method>
-<method name="getLogWriter"
- return="java.io.PrintWriter"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<exception name="SQLException" type="java.sql.SQLException">
-</exception>
-</method>
-<method name="getLoginTimeout"
- return="int"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<exception name="SQLException" type="java.sql.SQLException">
-</exception>
-</method>
-<method name="setLogWriter"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="theWriter" type="java.io.PrintWriter">
-</parameter>
-<exception name="SQLException" type="java.sql.SQLException">
-</exception>
-</method>
-<method name="setLoginTimeout"
- return="void"
- abstract="true"
- native="false"
- synchronized="false"
- static="false"
- final="false"
- deprecated="not deprecated"
- visibility="public"
->
-<parameter name="theTimeout" type="int">
-</parameter>
-<exception name="SQLException" type="java.sql.SQLException">
-</exception>
-</method>
</interface>
<interface name="PooledConnection"
abstract="true"
diff --git a/api/current.xml b/api/current.xml
index b24ba43..767f9af 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -38810,6 +38810,336 @@
</parameter>
</method>
</class>
+<class name="ClipboardManager"
+ extends="android.text.ClipboardManager"
+ abstract="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="addPrimaryClipChangedListener"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="what" type="android.content.ClipboardManager.OnPrimaryClipChangedListener">
+</parameter>
+</method>
+<method name="getPrimaryClip"
+ return="android.content.ClippedData"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getText"
+ return="java.lang.CharSequence"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
+</method>
+<method name="hasPrimaryClip"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="hasText"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="removePrimaryClipChangedListener"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="what" type="android.content.ClipboardManager.OnPrimaryClipChangedListener">
+</parameter>
+</method>
+<method name="setPrimaryClip"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="clip" type="android.content.ClippedData">
+</parameter>
+</method>
+<method name="setText"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
+<parameter name="text" type="java.lang.CharSequence">
+</parameter>
+</method>
+</class>
+<interface name="ClipboardManager.OnPrimaryClipChangedListener"
+ abstract="true"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="onPrimaryClipChanged"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+</interface>
+<class name="ClippedData"
+ extends="java.lang.Object"
+ abstract="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<implements name="android.os.Parcelable">
+</implements>
+<constructor name="ClippedData"
+ type="android.content.ClippedData"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="label" type="java.lang.CharSequence">
+</parameter>
+<parameter name="icon" type="android.graphics.Bitmap">
+</parameter>
+<parameter name="item" type="android.content.ClippedData.Item">
+</parameter>
+</constructor>
+<method name="addItem"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="item" type="android.content.ClippedData.Item">
+</parameter>
+</method>
+<method name="describeContents"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getIcon"
+ return="android.graphics.Bitmap"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getItem"
+ return="android.content.ClippedData.Item"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="index" type="int">
+</parameter>
+</method>
+<method name="getItemCount"
+ return="int"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getLabel"
+ return="java.lang.CharSequence"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="writeToParcel"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="dest" type="android.os.Parcel">
+</parameter>
+<parameter name="flags" type="int">
+</parameter>
+</method>
+<field name="CREATOR"
+ type="android.os.Parcelable.Creator"
+ transient="false"
+ volatile="false"
+ static="true"
+ final="true"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</field>
+</class>
+<class name="ClippedData.Item"
+ extends="java.lang.Object"
+ abstract="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<constructor name="ClippedData.Item"
+ type="android.content.ClippedData.Item"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="text" type="java.lang.CharSequence">
+</parameter>
+</constructor>
+<constructor name="ClippedData.Item"
+ type="android.content.ClippedData.Item"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="intent" type="android.content.Intent">
+</parameter>
+</constructor>
+<constructor name="ClippedData.Item"
+ type="android.content.ClippedData.Item"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="uri" type="android.net.Uri">
+</parameter>
+</constructor>
+<constructor name="ClippedData.Item"
+ type="android.content.ClippedData.Item"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="text" type="java.lang.CharSequence">
+</parameter>
+<parameter name="intent" type="android.content.Intent">
+</parameter>
+<parameter name="uri" type="android.net.Uri">
+</parameter>
+</constructor>
+<method name="getIntent"
+ return="android.content.Intent"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getText"
+ return="java.lang.CharSequence"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="getUri"
+ return="android.net.Uri"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+</class>
<interface name="ComponentCallbacks"
abstract="true"
static="false"
@@ -44627,6 +44957,93 @@
>
</method>
</interface>
+<interface name="IOnPrimaryClipChangedListener"
+ abstract="true"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<implements name="android.os.IInterface">
+</implements>
+<method name="dispatchPrimaryClipChanged"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<exception name="RemoteException" type="android.os.RemoteException">
+</exception>
+</method>
+</interface>
+<class name="IOnPrimaryClipChangedListener.Stub"
+ extends="android.os.Binder"
+ abstract="true"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<implements name="android.content.IOnPrimaryClipChangedListener">
+</implements>
+<constructor name="IOnPrimaryClipChangedListener.Stub"
+ type="android.content.IOnPrimaryClipChangedListener.Stub"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</constructor>
+<method name="asBinder"
+ return="android.os.IBinder"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="asInterface"
+ return="android.content.IOnPrimaryClipChangedListener"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="obj" type="android.os.IBinder">
+</parameter>
+</method>
+<method name="onTransact"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="code" type="int">
+</parameter>
+<parameter name="data" type="android.os.Parcel">
+</parameter>
+<parameter name="reply" type="android.os.Parcel">
+</parameter>
+<parameter name="flags" type="int">
+</parameter>
+<exception name="RemoteException" type="android.os.RemoteException">
+</exception>
+</method>
+</class>
<class name="Intent"
extends="java.lang.Object"
abstract="false"
@@ -166226,15 +166643,23 @@
</class>
<class name="ClipboardManager"
extends="java.lang.Object"
- abstract="false"
+ abstract="true"
+ static="false"
+ final="false"
+ deprecated="deprecated"
+ visibility="public"
+>
+<constructor name="ClipboardManager"
+ type="android.text.ClipboardManager"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
+</constructor>
<method name="getText"
return="java.lang.CharSequence"
- abstract="false"
+ abstract="true"
native="false"
synchronized="false"
static="false"
@@ -166245,7 +166670,7 @@
</method>
<method name="hasText"
return="boolean"
- abstract="false"
+ abstract="true"
native="false"
synchronized="false"
static="false"
@@ -166256,7 +166681,7 @@
</method>
<method name="setText"
return="void"
- abstract="false"
+ abstract="true"
native="false"
synchronized="false"
static="false"
@@ -211726,6 +212151,22 @@
<parameter name="defStyle" type="int">
</parameter>
</constructor>
+<constructor name="WebView"
+ type="android.webkit.WebView"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="context" type="android.content.Context">
+</parameter>
+<parameter name="attrs" type="android.util.AttributeSet">
+</parameter>
+<parameter name="defStyle" type="int">
+</parameter>
+<parameter name="privateBrowsing" type="boolean">
+</parameter>
+</constructor>
<method name="addJavascriptInterface"
return="void"
abstract="false"
@@ -212214,6 +212655,17 @@
visibility="public"
>
</method>
+<method name="isPrivateBrowsingEnabled"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
<method name="loadData"
return="void"
abstract="false"
@@ -271738,7 +272190,7 @@
deprecated="not deprecated"
visibility="public"
>
-<parameter name="loop" type="boolean">
+<parameter name="disable" type="boolean">
</parameter>
<exception name="SocketException" type="java.net.SocketException">
</exception>
@@ -273297,7 +273749,7 @@
deprecated="not deprecated"
visibility="public"
>
-<parameter name="value" type="boolean">
+<parameter name="keepAlive" type="boolean">
</parameter>
<exception name="SocketException" type="java.net.SocketException">
</exception>
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 10ebd60..2786372 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -92,7 +92,7 @@
import android.os.FileUtils.FileStatus;
import android.os.storage.StorageManager;
import android.telephony.TelephonyManager;
-import android.text.ClipboardManager;
+import android.content.ClipboardManager;
import android.util.AndroidRuntimeException;
import android.util.Log;
import android.view.ContextThemeWrapper;
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 6fe12fc..1fae516 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -17,6 +17,7 @@
package android.app;
import android.content.Context;
+import android.os.Binder;
import android.os.RemoteException;
import android.os.Handler;
import android.os.IBinder;
diff --git a/core/java/android/content/ClipboardManager.java b/core/java/android/content/ClipboardManager.java
new file mode 100644
index 0000000..5371fa5
--- /dev/null
+++ b/core/java/android/content/ClipboardManager.java
@@ -0,0 +1,195 @@
+/**
+ * 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.
+ */
+
+package android.content;
+
+import android.content.Context;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.ServiceManager;
+import android.util.Log;
+
+import java.util.ArrayList;
+
+/**
+ * Interface to the clipboard service, for placing and retrieving text in
+ * the global clipboard.
+ *
+ * <p>
+ * You do not instantiate this class directly; instead, retrieve it through
+ * {@link android.content.Context#getSystemService}.
+ *
+ * @see android.content.Context#getSystemService
+ */
+public class ClipboardManager extends android.text.ClipboardManager {
+ private final static Object sStaticLock = new Object();
+ private static IClipboard sService;
+
+ private final Context mContext;
+
+ private final ArrayList<OnPrimaryClipChangedListener> mPrimaryClipChangedListeners
+ = new ArrayList<OnPrimaryClipChangedListener>();
+
+ private final IOnPrimaryClipChangedListener.Stub mPrimaryClipChangedServiceListener
+ = new IOnPrimaryClipChangedListener.Stub() {
+ public void dispatchPrimaryClipChanged() {
+ mHandler.sendEmptyMessage(MSG_REPORT_PRIMARY_CLIP_CHANGED);
+ }
+ };
+
+ static final int MSG_REPORT_PRIMARY_CLIP_CHANGED = 1;
+
+ private final Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_REPORT_PRIMARY_CLIP_CHANGED:
+ reportPrimaryClipChanged();
+ }
+ }
+ };
+
+ public interface OnPrimaryClipChangedListener {
+ void onPrimaryClipChanged();
+ }
+
+ static private IClipboard getService() {
+ synchronized (sStaticLock) {
+ if (sService != null) {
+ return sService;
+ }
+ IBinder b = ServiceManager.getService("clipboard");
+ sService = IClipboard.Stub.asInterface(b);
+ return sService;
+ }
+ }
+
+ /** {@hide} */
+ public ClipboardManager(Context context, Handler handler) {
+ mContext = context;
+ }
+
+ /**
+ * Sets the current primary clip on the clipboard. This is the clip that
+ * is involved in normal cut and paste operations.
+ *
+ * @param clip The clipped data item to set.
+ */
+ public void setPrimaryClip(ClippedData clip) {
+ try {
+ getService().setPrimaryClip(clip);
+ } catch (RemoteException e) {
+ }
+ }
+
+ /**
+ * Returns the current primary clip on the clipboard.
+ */
+ public ClippedData getPrimaryClip() {
+ try {
+ return getService().getPrimaryClip();
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+
+ /**
+ * Returns true if there is currently a primary clip on the clipboard.
+ */
+ public boolean hasPrimaryClip() {
+ try {
+ return getService().hasPrimaryClip();
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
+
+ public void addPrimaryClipChangedListener(OnPrimaryClipChangedListener what) {
+ synchronized (mPrimaryClipChangedListeners) {
+ if (mPrimaryClipChangedListeners.size() == 0) {
+ try {
+ getService().addPrimaryClipChangedListener(
+ mPrimaryClipChangedServiceListener);
+ } catch (RemoteException e) {
+ }
+ }
+ mPrimaryClipChangedListeners.add(what);
+ }
+ }
+
+ public void removePrimaryClipChangedListener(OnPrimaryClipChangedListener what) {
+ synchronized (mPrimaryClipChangedListeners) {
+ mPrimaryClipChangedListeners.remove(what);
+ if (mPrimaryClipChangedListeners.size() == 0) {
+ try {
+ getService().removePrimaryClipChangedListener(
+ mPrimaryClipChangedServiceListener);
+ } catch (RemoteException e) {
+ }
+ }
+ }
+ }
+
+ /**
+ * @deprecated Use {@link #getPrimaryClip()} instead. This retrieves
+ * the primary clip and tries to coerce it to a string.
+ */
+ public CharSequence getText() {
+ ClippedData clip = getPrimaryClip();
+ if (clip != null && clip.getItemCount() > 0) {
+ return clip.getItem(0).getText();
+ }
+ return null;
+ }
+
+ /**
+ * @deprecated Use {@link #setPrimaryClip(ClippedData)} instead. This
+ * creates a ClippedItem holding the given text and sets it as the
+ * primary clip. It has no label or icon.
+ */
+ public void setText(CharSequence text) {
+ setPrimaryClip(new ClippedData(null, null, new ClippedData.Item(text)));
+ }
+
+ /**
+ * Returns true if the clipboard has a primary clip containing text; false otherwise.
+ */
+ public boolean hasText() {
+ try {
+ return getService().hasClipboardText();
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
+
+ void reportPrimaryClipChanged() {
+ Object[] listeners;
+
+ synchronized (mPrimaryClipChangedListeners) {
+ final int N = mPrimaryClipChangedListeners.size();
+ if (N <= 0) {
+ return;
+ }
+ listeners = mPrimaryClipChangedListeners.toArray();
+ }
+
+ for (int i=0; i<listeners.length; i++) {
+ ((OnPrimaryClipChangedListener)listeners[i]).onPrimaryClipChanged();
+ }
+ }
+}
diff --git a/core/java/android/content/ClippedData.aidl b/core/java/android/content/ClippedData.aidl
new file mode 100644
index 0000000..5246526
--- /dev/null
+++ b/core/java/android/content/ClippedData.aidl
@@ -0,0 +1,19 @@
+/**
+ * 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.
+ */
+
+package android.content;
+
+parcelable ClippedData;
diff --git a/core/java/android/content/ClippedData.java b/core/java/android/content/ClippedData.java
new file mode 100644
index 0000000..ebb194f
--- /dev/null
+++ b/core/java/android/content/ClippedData.java
@@ -0,0 +1,189 @@
+/**
+ * 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.
+ */
+
+package android.content;
+
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.text.TextUtils;
+
+import java.util.ArrayList;
+
+/**
+ * Representation of a clipped data on the clipboard.
+ *
+ * <p>ClippedData is a complex type containing one or Item instances,
+ * each of which can hold one or more representations of an item of data.
+ * For display to the user, it also has a label and iconic representation.</p>
+ *
+ * <p>The types than an individial item can currently contain are:</p>
+ *
+ * <ul>
+ * <li> Text: a basic string of text. This is actually a CharSequence,
+ * so it can be formatted text supported by corresponding Android built-in
+ * style spans. (Custom application spans are not supported and will be
+ * stripped when transporting through the clipboard.)
+ * <li> Intent: an arbitrary Intent object. A typical use is the shortcut
+ * to create when pasting a clipped item on to the home screen.
+ * <li> Uri: a URI reference. Currently this should only be a content: URI.
+ * This representation allows an application to share complex or large clips,
+ * by providing a URI to a content provider holding the data.
+ * </ul>
+ */
+public class ClippedData implements Parcelable {
+ CharSequence mLabel;
+ Bitmap mIcon;
+
+ final ArrayList<Item> mItems = new ArrayList<Item>();
+
+ public static class Item {
+ CharSequence mText;
+ Intent mIntent;
+ Uri mUri;
+
+ public Item(CharSequence text) {
+ mText = text;
+ }
+
+ public Item(Intent intent) {
+ mIntent = intent;
+ }
+
+ public Item(Uri uri) {
+ mUri = uri;
+ }
+
+ public Item(CharSequence text, Intent intent, Uri uri) {
+ mText = text;
+ mIntent = intent;
+ mUri = uri;
+ }
+
+ public CharSequence getText() {
+ return mText;
+ }
+
+ public Intent getIntent() {
+ return mIntent;
+ }
+
+ public Uri getUri() {
+ return mUri;
+ }
+ }
+
+ /**
+ * Create a new clip.
+ *
+ * @param label Label to show to the user describing this clip.
+ * @param icon Bitmap providing the user with an iconing representation of
+ * the clip.
+ * @param item The contents of the first item in the clip.
+ */
+ public ClippedData(CharSequence label, Bitmap icon, Item item) {
+ if (item == null) {
+ throw new NullPointerException("item is null");
+ }
+ mLabel = label;
+ mIcon = icon;
+ mItems.add(item);
+ }
+
+ public void addItem(Item item) {
+ if (item == null) {
+ throw new NullPointerException("item is null");
+ }
+ mItems.add(item);
+ }
+
+ public CharSequence getLabel() {
+ return mLabel;
+ }
+
+ public Bitmap getIcon() {
+ return mIcon;
+ }
+
+ public int getItemCount() {
+ return mItems.size();
+ }
+
+ public Item getItem(int index) {
+ return mItems.get(index);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ TextUtils.writeToParcel(mLabel, dest, flags);
+ if (mIcon != null) {
+ dest.writeInt(1);
+ mIcon.writeToParcel(dest, flags);
+ } else {
+ dest.writeInt(0);
+ }
+ final int N = mItems.size();
+ dest.writeInt(N);
+ for (int i=0; i<N; i++) {
+ Item item = mItems.get(i);
+ TextUtils.writeToParcel(item.mText, dest, flags);
+ if (item.mIntent != null) {
+ dest.writeInt(1);
+ item.mIntent.writeToParcel(dest, flags);
+ } else {
+ dest.writeInt(0);
+ }
+ if (item.mUri != null) {
+ dest.writeInt(1);
+ item.mUri.writeToParcel(dest, flags);
+ } else {
+ dest.writeInt(0);
+ }
+ }
+ }
+
+ ClippedData(Parcel in) {
+ mLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
+ if (in.readInt() != 0) {
+ mIcon = Bitmap.CREATOR.createFromParcel(in);
+ }
+ final int N = in.readInt();
+ for (int i=0; i<N; i++) {
+ CharSequence text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
+ Intent intent = in.readInt() != 0 ? Intent.CREATOR.createFromParcel(in) : null;
+ Uri uri = in.readInt() != 0 ? Uri.CREATOR.createFromParcel(in) : null;
+ mItems.add(new Item(text, intent, uri));
+ }
+ }
+
+ public static final Parcelable.Creator<ClippedData> CREATOR =
+ new Parcelable.Creator<ClippedData>() {
+
+ public ClippedData createFromParcel(Parcel source) {
+ return new ClippedData(source);
+ }
+
+ public ClippedData[] newArray(int size) {
+ return new ClippedData[size];
+ }
+ };
+}
diff --git a/core/java/android/text/IClipboard.aidl b/core/java/android/content/IClipboard.aidl
similarity index 68%
rename from core/java/android/text/IClipboard.aidl
rename to core/java/android/content/IClipboard.aidl
index 4deb5c8..b4534a9 100644
--- a/core/java/android/text/IClipboard.aidl
+++ b/core/java/android/content/IClipboard.aidl
@@ -14,7 +14,10 @@
* limitations under the License.
*/
-package android.text;
+package android.content;
+
+import android.content.ClippedData;
+import android.content.IOnPrimaryClipChangedListener;
/**
* Programming interface to the clipboard, which allows copying and pasting
@@ -22,21 +25,14 @@
* {@hide}
*/
interface IClipboard {
- /**
- * Returns the text on the clipboard. It will eventually be possible
- * to store types other than text too, in which case this will return
- * null if the type cannot be coerced to text.
- */
- CharSequence getClipboardText();
-
- /**
- * Sets the contents of the clipboard to the specified text.
- */
- void setClipboardText(CharSequence text);
+ void setPrimaryClip(in ClippedData clip);
+ ClippedData getPrimaryClip();
+ boolean hasPrimaryClip();
+ void addPrimaryClipChangedListener(in IOnPrimaryClipChangedListener listener);
+ void removePrimaryClipChangedListener(in IOnPrimaryClipChangedListener listener);
/**
* Returns true if the clipboard contains text; false otherwise.
*/
boolean hasClipboardText();
}
-
diff --git a/core/java/android/content/IOnPrimaryClipChangedListener.aidl b/core/java/android/content/IOnPrimaryClipChangedListener.aidl
new file mode 100644
index 0000000..fb42a45
--- /dev/null
+++ b/core/java/android/content/IOnPrimaryClipChangedListener.aidl
@@ -0,0 +1,21 @@
+/**
+ * Copyright (c) 2008, 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;
+
+oneway interface IOnPrimaryClipChangedListener {
+ void dispatchPrimaryClipChanged();
+}
diff --git a/core/java/android/content/res/ColorStateList.java b/core/java/android/content/res/ColorStateList.java
index 70baaef..bd23db4 100644
--- a/core/java/android/content/res/ColorStateList.java
+++ b/core/java/android/content/res/ColorStateList.java
@@ -45,7 +45,6 @@
* <item android:state_focused="true" android:color="@color/testcolor1"/>
* <item android:state_pressed="true" android:state_enabled="false" android:color="@color/testcolor2" />
* <item android:state_enabled="false" android:color="@color/testcolor3" />
- * <item android:state_active="true" android:color="@color/testcolor4" />
* <item android:color="@color/testcolor5"/>
* </selector>
* </pre>
@@ -56,6 +55,9 @@
* An item with no state spec is considered to match any set of states and is generally useful as
* a final item to be used as a default. Note that if you have such an item before any other items
* in the list then any subsequent items will end up being ignored.
+ * <p>For more information, see the guide to <a
+ * href="{@docRoot}guide/topics/resources/color-list-resource.html">Color State
+ * List Resource</a>.</p>
*/
public class ColorStateList implements Parcelable {
diff --git a/core/java/android/net/Proxy.java b/core/java/android/net/Proxy.java
index 02ec137..e2e4d2c 100644
--- a/core/java/android/net/Proxy.java
+++ b/core/java/android/net/Proxy.java
@@ -150,30 +150,14 @@
// Return no proxy
retval = java.net.Proxy.NO_PROXY;
} else {
- java.net.Proxy retProxy =
+ retval =
new java.net.Proxy(java.net.Proxy.Type.HTTP, sGlobalProxySpec.proxyAddress);
- sProxyInfoLock.readLock().unlock();
- if (isLocalHost(url)) {
- sProxyInfoLock.readLock().lock();
- retval = java.net.Proxy.NO_PROXY;
- } else {
- sProxyInfoLock.readLock().lock();
- retval = retProxy;
- }
}
} else {
// If network is WiFi, return no proxy.
// Otherwise, return the Mobile Operator proxy.
if (!isNetworkWifi(ctx)) {
- java.net.Proxy retProxy = getDefaultProxy(url);
- sProxyInfoLock.readLock().unlock();
- if (isLocalHost(url)) {
- sProxyInfoLock.readLock().lock();
- retval = java.net.Proxy.NO_PROXY;
- } else {
- sProxyInfoLock.readLock().lock();
- retval = retProxy;
- }
+ retval = getDefaultProxy(url);
} else {
retval = java.net.Proxy.NO_PROXY;
}
@@ -181,6 +165,9 @@
} finally {
sProxyInfoLock.readLock().unlock();
}
+ if ((retval != java.net.Proxy.NO_PROXY) && (isLocalHost(url))) {
+ retval = java.net.Proxy.NO_PROXY;
+ }
return retval;
}
@@ -348,7 +335,7 @@
private Context mContext;
SettingsObserver(Context ctx) {
- super(new Handler());
+ super(new Handler(ctx.getMainLooper()));
mContext = ctx;
}
@@ -368,10 +355,13 @@
// No lock upgrading (from read to write) allowed
sProxyInfoLock.readLock().unlock();
sProxyInfoLock.writeLock().lock();
- sGlobalProxyChangedObserver = new SettingsObserver(ctx);
- // Downgrading locks (from write to read) is allowed
- sProxyInfoLock.readLock().lock();
- sProxyInfoLock.writeLock().unlock();
+ try {
+ sGlobalProxyChangedObserver = new SettingsObserver(ctx);
+ } finally {
+ // Downgrading locks (from write to read) is allowed
+ sProxyInfoLock.readLock().lock();
+ sProxyInfoLock.writeLock().unlock();
+ }
ctx.getContentResolver().registerContentObserver(uriGlobalProxy, false,
sGlobalProxyChangedObserver);
ctx.getContentResolver().registerContentObserver(uriGlobalExclList, false,
diff --git a/core/java/android/text/ClipboardManager.java b/core/java/android/text/ClipboardManager.java
index 52039af..0b239cf 100644
--- a/core/java/android/text/ClipboardManager.java
+++ b/core/java/android/text/ClipboardManager.java
@@ -16,73 +16,26 @@
package android.text;
-import android.content.Context;
-import android.os.RemoteException;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.ServiceManager;
-import android.util.Log;
-
/**
- * Interface to the clipboard service, for placing and retrieving text in
- * the global clipboard.
- *
- * <p>
- * You do not instantiate this class directly; instead, retrieve it through
- * {@link android.content.Context#getSystemService}.
- *
- * @see android.content.Context#getSystemService
+ * @deprecated Old text-only interace to the clipboard. See
+ * {@link android.content.ClipboardManager} for the modern API.
*/
-public class ClipboardManager {
- private static IClipboard sService;
-
- private Context mContext;
-
- static private IClipboard getService() {
- if (sService != null) {
- return sService;
- }
- IBinder b = ServiceManager.getService("clipboard");
- sService = IClipboard.Stub.asInterface(b);
- return sService;
- }
-
- /** {@hide} */
- public ClipboardManager(Context context, Handler handler) {
- mContext = context;
- }
-
+@Deprecated
+public abstract class ClipboardManager {
/**
* Returns the text on the clipboard. It will eventually be possible
* to store types other than text too, in which case this will return
* null if the type cannot be coerced to text.
*/
- public CharSequence getText() {
- try {
- return getService().getClipboardText();
- } catch (RemoteException e) {
- return null;
- }
- }
+ public abstract CharSequence getText();
/**
* Sets the contents of the clipboard to the specified text.
*/
- public void setText(CharSequence text) {
- try {
- getService().setClipboardText(text);
- } catch (RemoteException e) {
- }
- }
+ public abstract void setText(CharSequence text);
/**
* Returns true if the clipboard contains text; false otherwise.
*/
- public boolean hasText() {
- try {
- return getService().hasClipboardText();
- } catch (RemoteException e) {
- return false;
- }
- }
+ public abstract boolean hasText();
}
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index f533944..0466c69 100644
--- a/core/java/android/text/Layout.java
+++ b/core/java/android/text/Layout.java
@@ -234,7 +234,7 @@
LineBackgroundSpan.class);
// All LineBackgroundSpans on a line contribute to its
// background.
- spans = sp.getSpans(start, end, LineBackgroundSpan.class);
+ spans = getParagraphSpans(sp, start, end, LineBackgroundSpan.class);
}
for (int n = 0; n < spans.length; n++) {
@@ -309,7 +309,7 @@
if (start >= spanEnd && (i == first || isFirstParaLine)) {
spanEnd = sp.nextSpanTransition(start, textLength,
ParagraphStyle.class);
- spans = sp.getSpans(start, spanEnd, ParagraphStyle.class);
+ spans = getParagraphSpans(sp, start, spanEnd, ParagraphStyle.class);
align = mAlignment;
for (int n = spans.length-1; n >= 0; n--) {
@@ -425,7 +425,7 @@
int start = getLineStart(line);
int spanEnd = spanned.nextSpanTransition(start, spanned.length(),
TabStopSpan.class);
- TabStopSpan[] tabSpans = spanned.getSpans(start, spanEnd, TabStopSpan.class);
+ TabStopSpan[] tabSpans = getParagraphSpans(spanned, start, spanEnd, TabStopSpan.class);
if (tabSpans.length > 0) {
tabStops = new TabStops(TAB_INCREMENT, tabSpans);
}
@@ -713,7 +713,7 @@
if (hasTabOrEmoji && mText instanceof Spanned) {
// Just checking this line should be good enough, tabs should be
// consistent across all lines in a paragraph.
- TabStopSpan[] tabs = ((Spanned) mText).getSpans(start, end, TabStopSpan.class);
+ TabStopSpan[] tabs = getParagraphSpans((Spanned) mText, start, end, TabStopSpan.class);
if (tabs.length > 0) {
tabStops = new TabStops(TAB_INCREMENT, tabs); // XXX should reuse
}
@@ -820,7 +820,7 @@
if (hasTabsOrEmoji && mText instanceof Spanned) {
// Just checking this line should be good enough, tabs should be
// consistent across all lines in a paragraph.
- TabStopSpan[] tabs = ((Spanned) mText).getSpans(start, end, TabStopSpan.class);
+ TabStopSpan[] tabs = getParagraphSpans((Spanned) mText, start, end, TabStopSpan.class);
if (tabs.length > 0) {
tabStops = new TabStops(TAB_INCREMENT, tabs); // XXX should reuse
}
@@ -1308,7 +1308,7 @@
if (mSpannedText) {
Spanned sp = (Spanned) mText;
- AlignmentSpan[] spans = sp.getSpans(getLineStart(line),
+ AlignmentSpan[] spans = getParagraphSpans(sp, getLineStart(line),
getLineEnd(line),
AlignmentSpan.class);
@@ -1361,7 +1361,7 @@
int lineEnd = getLineEnd(line);
int spanEnd = spanned.nextSpanTransition(lineStart, lineEnd,
LeadingMarginSpan.class);
- LeadingMarginSpan[] spans = spanned.getSpans(lineStart, spanEnd,
+ LeadingMarginSpan[] spans = getParagraphSpans(spanned, lineStart, spanEnd,
LeadingMarginSpan.class);
if (spans.length == 0) {
return 0; // no leading margin span;
@@ -1416,7 +1416,7 @@
Spanned spanned = (Spanned) text;
int spanEnd = spanned.nextSpanTransition(start, end,
TabStopSpan.class);
- TabStopSpan[] spans = spanned.getSpans(start, spanEnd,
+ TabStopSpan[] spans = getParagraphSpans(spanned, start, spanEnd,
TabStopSpan.class);
if (spans.length > 0) {
tabStops = new TabStops(TAB_INCREMENT, spans);
@@ -1513,7 +1513,7 @@
if (text instanceof Spanned) {
if (tabs == null) {
- tabs = ((Spanned) text).getSpans(start, end, TabStopSpan.class);
+ tabs = getParagraphSpans((Spanned) text, start, end, TabStopSpan.class);
alltabs = true;
}
@@ -1540,6 +1540,38 @@
return mSpannedText;
}
+ /**
+ * Returns the same as <code>text.getSpans()</code>, except where
+ * <code>start</code> and <code>end</code> are the same and are not
+ * at the very beginning of the text, in which case an empty array
+ * is returned instead.
+ * <p>
+ * This is needed because of the special case that <code>getSpans()</code>
+ * on an empty range returns the spans adjacent to that range, which is
+ * primarily for the sake of <code>TextWatchers</code> so they will get
+ * notifications when text goes from empty to non-empty. But it also
+ * has the unfortunate side effect that if the text ends with an empty
+ * paragraph, that paragraph accidentally picks up the styles of the
+ * preceding paragraph (even though those styles will not be picked up
+ * by new text that is inserted into the empty paragraph).
+ * <p>
+ * The reason it just checks whether <code>start</code> and <code>end</code>
+ * is the same is that the only time a line can contain 0 characters
+ * is if it is the final paragraph of the Layout; otherwise any line will
+ * contain at least one printing or newline character. The reason for the
+ * additional check if <code>start</code> is greater than 0 is that
+ * if the empty paragraph is the entire content of the buffer, paragraph
+ * styles that are already applied to the buffer will apply to text that
+ * is inserted into it.
+ */
+ /* package */ static <T> T[] getParagraphSpans(Spanned text, int start, int end, Class<T> type) {
+ if (start == end && start > 0) {
+ return (T[]) ArrayUtils.emptyArray(type);
+ }
+
+ return text.getSpans(start, end, type);
+ }
+
private void ellipsize(int start, int end, int line,
char[] dest, int destoff) {
int ellipsisCount = getEllipsisCount(line);
diff --git a/core/java/android/text/StaticLayout.java b/core/java/android/text/StaticLayout.java
index 44157de..cc969cb 100644
--- a/core/java/android/text/StaticLayout.java
+++ b/core/java/android/text/StaticLayout.java
@@ -155,7 +155,7 @@
LineHeightSpan[] chooseht = null;
if (spanned != null) {
- LeadingMarginSpan[] sp = spanned.getSpans(paraStart, paraEnd,
+ LeadingMarginSpan[] sp = getParagraphSpans(spanned, paraStart, paraEnd,
LeadingMarginSpan.class);
for (int i = 0; i < sp.length; i++) {
LeadingMarginSpan lms = sp[i];
@@ -174,7 +174,7 @@
}
}
- chooseht = spanned.getSpans(paraStart, paraEnd, LineHeightSpan.class);
+ chooseht = getParagraphSpans(spanned, paraStart, paraEnd, LineHeightSpan.class);
if (chooseht.length != 0) {
if (choosehtv == null ||
@@ -267,7 +267,7 @@
hasTabOrEmoji = true;
if (spanned != null) {
// First tab this para, check for tabstops
- TabStopSpan[] spans = spanned.getSpans(paraStart,
+ TabStopSpan[] spans = getParagraphSpans(spanned, paraStart,
paraEnd, TabStopSpan.class);
if (spans.length > 0) {
tabStops = new TabStops(TAB_INCREMENT, spans);
diff --git a/core/java/android/webkit/WebSettings.java b/core/java/android/webkit/WebSettings.java
index 681ef70..6e89a8b 100644
--- a/core/java/android/webkit/WebSettings.java
+++ b/core/java/android/webkit/WebSettings.java
@@ -179,6 +179,7 @@
private boolean mSupportMultipleWindows = false;
private boolean mShrinksStandaloneImagesToFit = false;
private long mMaximumDecodedImageSize = 0; // 0 means default
+ private boolean mPrivateBrowsingEnabled = false;
// HTML5 API flags
private boolean mAppCacheEnabled = false;
private boolean mDatabaseEnabled = false;
@@ -1468,6 +1469,24 @@
}
}
+ /**
+ * Returns whether private browsing is enabled.
+ */
+ /* package */ boolean isPrivateBrowsingEnabled() {
+ return mPrivateBrowsingEnabled;
+ }
+
+ /**
+ * Sets whether private browsing is enabled.
+ * @param flag Whether private browsing should be enabled.
+ */
+ /* package */ synchronized void setPrivateBrowsingEnabled(boolean flag) {
+ if (mPrivateBrowsingEnabled != flag) {
+ mPrivateBrowsingEnabled = flag;
+ postSync();
+ }
+ }
+
int getDoubleTapToastCount() {
return mDoubleTapToastCount;
}
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 03382c3b..43a3e04 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -18,6 +18,7 @@
import android.annotation.Widget;
import android.app.AlertDialog;
+import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -45,7 +46,6 @@
import android.os.ServiceManager;
import android.os.SystemClock;
import android.speech.tts.TextToSpeech;
-import android.text.IClipboard;
import android.text.Selection;
import android.text.Spannable;
import android.util.AttributeSet;
@@ -86,6 +86,8 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashMap;
@@ -825,7 +827,18 @@
* @param defStyle The default style resource ID.
*/
public WebView(Context context, AttributeSet attrs, int defStyle) {
- this(context, attrs, defStyle, null);
+ this(context, attrs, defStyle, false);
+ }
+
+ /**
+ * Construct a new WebView with layout parameters and a default style.
+ * @param context A Context object used to access application assets.
+ * @param attrs An AttributeSet passed to our parent.
+ * @param defStyle The default style resource ID.
+ */
+ public WebView(Context context, AttributeSet attrs, int defStyle,
+ boolean privateBrowsing) {
+ this(context, attrs, defStyle, null, privateBrowsing);
}
/**
@@ -841,7 +854,7 @@
* @hide pending API council approval.
*/
protected WebView(Context context, AttributeSet attrs, int defStyle,
- Map<String, Object> javascriptInterfaces) {
+ Map<String, Object> javascriptInterfaces, boolean privateBrowsing) {
super(context, attrs, defStyle);
if (AccessibilityManager.getInstance(context).isEnabled()) {
@@ -863,6 +876,10 @@
*/
init();
updateMultiTouchSupport(context);
+
+ if (privateBrowsing) {
+ startPrivateBrowsing();
+ }
}
void updateMultiTouchSupport(Context context) {
@@ -1668,6 +1685,34 @@
}
}
+ /**
+ * Returns true if private browsing is enabled in this WebView.
+ */
+ public boolean isPrivateBrowsingEnabled () {
+ return getSettings().isPrivateBrowsingEnabled();
+ }
+
+ private void startPrivateBrowsing () {
+ boolean wasPrivateBrowsingEnabled = isPrivateBrowsingEnabled();
+
+ getSettings().setPrivateBrowsingEnabled(true);
+
+ if (!wasPrivateBrowsingEnabled) {
+ StringBuilder data = new StringBuilder(1024);
+ try {
+ InputStreamReader file = new InputStreamReader(mContext.getResources().openRawResource(com.android.internal.R.raw.incognito_mode_start_page));
+ int size;
+ char[] buffer = new char[1024];
+ while ((size = file.read(buffer)) != -1) {
+ data.append(buffer, 0, size);
+ }
+ } catch (IOException e) {
+ // This should never happen since this is a static resource.
+ }
+ loadDataWithBaseURL(null, data.toString(), "text/html", "utf-8", null);
+ }
+ }
+
private boolean extendScroll(int y) {
int finalY = mScroller.getFinalY();
int newY = pinLocY(finalY + y);
@@ -4053,13 +4098,9 @@
, com.android.internal.R.string.text_copied
, Toast.LENGTH_SHORT).show();
copiedSomething = true;
- try {
- IClipboard clip = IClipboard.Stub.asInterface(
- ServiceManager.getService("clipboard"));
- clip.setClipboardText(selection);
- } catch (android.os.RemoteException e) {
- Log.e(LOGTAG, "Clipboard failed", e);
- }
+ ClipboardManager cm = (ClipboardManager)getContext()
+ .getSystemService(Context.CLIPBOARD_SERVICE);
+ cm.setText(selection);
}
invalidate(); // remove selection region and pointer
return copiedSomething;
diff --git a/core/jni/android_database_SQLiteDatabase.cpp b/core/jni/android_database_SQLiteDatabase.cpp
index 45d2e1e..4b3f1c0 100644
--- a/core/jni/android_database_SQLiteDatabase.cpp
+++ b/core/jni/android_database_SQLiteDatabase.cpp
@@ -63,6 +63,7 @@
static jfieldID offset_db_handle;
static jmethodID method_custom_function_callback;
+static jclass string_class = NULL;
static char *createStr(const char *path, short extra) {
int len = strlen(path) + extra;
@@ -394,27 +395,36 @@
LOGE("custom_function_callback cannot call into Java on this thread");
return;
}
+ // get global ref to CustomFunction object from our user data
+ jobject function = (jobject)sqlite3_user_data(context);
// pack up the arguments into a string array
- jobjectArray strArray = env->NewObjectArray(argc, env->FindClass("java/lang/String"), NULL);
- if (!strArray) {
- jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
- return;
- }
+ if (!string_class)
+ string_class = (jclass)env->NewGlobalRef(env->FindClass("java/lang/String"));
+ jobjectArray strArray = env->NewObjectArray(argc, string_class, NULL);
+ if (!strArray)
+ goto done;
for (int i = 0; i < argc; i++) {
char* arg = (char *)sqlite3_value_text(argv[i]);
- jobject obj = env->NewStringUTF(arg);
- if (!obj) {
- jniThrowException(env, "java/lang/OutOfMemoryError", NULL);
+ if (!arg) {
+ LOGE("NULL argument in custom_function_callback. This should not happen.");
return;
}
+ jobject obj = env->NewStringUTF(arg);
+ if (!obj)
+ goto done;
env->SetObjectArrayElement(strArray, i, obj);
env->DeleteLocalRef(obj);
}
- // get global ref to CustomFunction object from our user data
- jobject function = (jobject)sqlite3_user_data(context);
env->CallVoidMethod(function, method_custom_function_callback, strArray);
+
+done:
+ if (env->ExceptionCheck()) {
+ LOGE("An exception was thrown by custom sqlite3 function.");
+ LOGE_EX(env);
+ env->ExceptionClear();
+ }
}
static jint native_addCustomFunction(JNIEnv* env, jobject object,
@@ -423,7 +433,7 @@
sqlite3 * handle = (sqlite3 *)env->GetIntField(object, offset_db_handle);
char const *nameStr = env->GetStringUTFChars(name, NULL);
jobject ref = env->NewGlobalRef(function);
- LOGD("native_addCustomFunction %s ref: %d", nameStr, ref);
+ LOGD("native_addCustomFunction %s ref: %p", nameStr, ref);
int err = sqlite3_create_function(handle, nameStr, numArgs, SQLITE_UTF8,
(void *)ref, custom_function_callback, NULL, NULL);
env->ReleaseStringUTFChars(name, nameStr);
diff --git a/core/res/res/raw/incognito_mode_start_page.html b/core/res/res/raw/incognito_mode_start_page.html
new file mode 100644
index 0000000..b070c6d
--- /dev/null
+++ b/core/res/res/raw/incognito_mode_start_page.html
@@ -0,0 +1,24 @@
+<html>
+ <head>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"/>
+ <title>New incognito window</title>
+ </head>
+ <body>
+ <p><strong>You've gone incognito</strong>. Pages you view in this window
+ won't appear in your browser history or search history, and they won't
+ leave other traces, like cookies, on your computer after you close the
+ incognito window. Any files you download or bookmarks you create will be
+ preserved, however.</p>
+
+ <p><strong>Going incognito doesn't affect the behavior of other people,
+ servers, or software. Be wary of:</strong></p>
+
+ <ul>
+ <li>Websites that collect or share information about you</li>
+ <li>Internet service providers or employers that track the pages you visit</li>
+ <li>Malicious software that tracks your keystrokes in exchange for free smileys</li>
+ <li>Surveillance by secret agents</li>
+ <li>People standing behind you</li>
+ </ul>
+ </body>
+</html>
diff --git a/core/tests/coretests/AndroidManifest.xml b/core/tests/coretests/AndroidManifest.xml
index a77717f..036da95 100644
--- a/core/tests/coretests/AndroidManifest.xml
+++ b/core/tests/coretests/AndroidManifest.xml
@@ -36,6 +36,8 @@
android:description="@string/permdesc_testDenied" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.BLUETOOTH" />
+ <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CLEAR_APP_CACHE" />
<uses-permission android:name="android.permission.CLEAR_APP_USER_DATA" />
diff --git a/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java b/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java
new file mode 100644
index 0000000..0fe83e1
--- /dev/null
+++ b/core/tests/coretests/src/android/bluetooth/BluetoothStressTest.java
@@ -0,0 +1,440 @@
+/*
+ * 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.
+ */
+
+package android.bluetooth;
+
+import android.app.Instrumentation;
+import android.bluetooth.BluetoothAdapter;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.test.InstrumentationTestCase;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.util.Log;
+
+public class BluetoothStressTest extends InstrumentationTestCase {
+ private static final String TAG = "BluetoothEnablerStressTest";
+
+ /**
+ * Timeout for {@link BluetoothAdapter#disable()} in ms.
+ */
+ private static final int DISABLE_TIMEOUT = 5000;
+
+ /**
+ * Timeout for {@link BluetoothAdapter#enable()} in ms.
+ */
+ private static final int ENABLE_TIMEOUT = 20000;
+
+ /**
+ * Timeout for {@link BluetoothAdapter#setScanMode(int)} in ms.
+ */
+ private static final int SET_SCAN_MODE_TIMEOUT = 5000;
+
+ /**
+ * Timeout for {@link BluetoothAdapter#startDiscovery()} in ms.
+ */
+ private static final int START_DISCOVERY_TIMEOUT = 5000;
+
+ /**
+ * Timeout for {@link BluetoothAdapter#cancelDiscovery()} in ms.
+ */
+ private static final int CANCEL_DISCOVERY_TIMEOUT = 5000;
+
+ private static final int DISCOVERY_STARTED_FLAG = 1;
+ private static final int DISCOVERY_FINISHED_FLAG = 1 << 1;
+ private static final int SCAN_MODE_NONE_FLAG = 1 << 2;
+ private static final int SCAN_MODE_CONNECTABLE_FLAG = 1 << 3;
+ private static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG = 1 << 4;
+ private static final int STATE_OFF_FLAG = 1 << 5;
+ private static final int STATE_TURNING_ON_FLAG = 1 << 6;
+ private static final int STATE_ON_FLAG = 1 << 7;
+ private static final int STATE_TURNING_OFF_FLAG = 1 << 8;
+
+ /**
+ * Time between polls in ms.
+ */
+ private static final int POLL_TIME = 100;
+
+ private static final int ENABLE_ITERATIONS = 100;
+ private static final int DISCOVERABLE_ITERATIONS = 1000;
+ private static final int SCAN_ITERATIONS = 1000;
+
+ private Context mContext;
+
+ private Instrumentation mInstrumentation;
+
+ private class BluetoothReceiver extends BroadcastReceiver {
+ private int mFiredFlags = 0;
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ synchronized (this) {
+ if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(intent.getAction())) {
+ mFiredFlags |= DISCOVERY_STARTED_FLAG;
+ } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(intent.getAction())) {
+ mFiredFlags |= DISCOVERY_FINISHED_FLAG;
+ } else if (BluetoothAdapter.ACTION_SCAN_MODE_CHANGED.equals(intent.getAction())) {
+ int mode = intent.getIntExtra(BluetoothAdapter.EXTRA_SCAN_MODE,
+ BluetoothAdapter.ERROR);
+ assertNotSame(mode, BluetoothAdapter.ERROR);
+ switch (mode) {
+ case BluetoothAdapter.SCAN_MODE_NONE:
+ mFiredFlags |= SCAN_MODE_NONE_FLAG;
+ break;
+ case BluetoothAdapter.SCAN_MODE_CONNECTABLE:
+ mFiredFlags |= SCAN_MODE_CONNECTABLE_FLAG;
+ break;
+ case BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE:
+ mFiredFlags |= SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG;
+ break;
+ }
+ } else if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) {
+ int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
+ BluetoothAdapter.ERROR);
+ assertNotSame(state, BluetoothAdapter.ERROR);
+ switch (state) {
+ case BluetoothAdapter.STATE_OFF:
+ mFiredFlags |= STATE_OFF_FLAG;
+ break;
+ case BluetoothAdapter.STATE_TURNING_ON:
+ mFiredFlags |= STATE_TURNING_ON_FLAG;
+ break;
+ case BluetoothAdapter.STATE_ON:
+ mFiredFlags |= STATE_ON_FLAG;
+ break;
+ case BluetoothAdapter.STATE_TURNING_OFF:
+ mFiredFlags |= STATE_TURNING_OFF_FLAG;
+ break;
+ }
+ }
+ }
+ }
+
+ public int getFiredFlags() {
+ synchronized (this) {
+ return mFiredFlags;
+ }
+ }
+
+ public void resetFiredFlags() {
+ synchronized (this) {
+ mFiredFlags = 0;
+ }
+ }
+ }
+
+ private BluetoothReceiver mReceiver = new BluetoothReceiver();
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ mInstrumentation = getInstrumentation();
+ mContext = mInstrumentation.getTargetContext();
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
+ filter.addAction(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
+ filter.addAction(BluetoothAdapter.ACTION_SCAN_MODE_CHANGED);
+ filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
+ mContext.registerReceiver(mReceiver, filter);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ mContext.unregisterReceiver(mReceiver);
+ }
+
+ @LargeTest
+ public void testEnableDisable() {
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+
+ for (int i = 0; i < ENABLE_ITERATIONS; i++) {
+ Log.i(TAG, "Enable iteration " + (i + 1) + " of " + ENABLE_ITERATIONS);
+ enable(adapter);
+ disable(adapter);
+ }
+ }
+
+ @LargeTest
+ public void testDiscoverable() {
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ enable(adapter);
+
+ for (int i = 0; i < DISCOVERABLE_ITERATIONS; i++) {
+ Log.i(TAG, "Discoverable iteration " + (i + 1) + " of " + DISCOVERABLE_ITERATIONS);
+ discoverable(adapter);
+ undiscoverable(adapter);
+ }
+
+ disable(adapter);
+ }
+
+ @LargeTest
+ public void testScan() {
+ BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
+ enable(adapter);
+
+ for (int i = 0; i < SCAN_ITERATIONS; i++) {
+ Log.i(TAG, "Scan iteration " + (i + 1) + " of " + SCAN_ITERATIONS);
+ startScan(adapter);
+ stopScan(adapter);
+ }
+
+ disable(adapter);
+ }
+
+ private void disable(BluetoothAdapter adapter) {
+ int mask = STATE_TURNING_OFF_FLAG | STATE_OFF_FLAG | SCAN_MODE_NONE_FLAG;
+ mReceiver.resetFiredFlags();
+
+ int state = adapter.getState();
+ switch (state) {
+ case BluetoothAdapter.STATE_OFF:
+ assertFalse(adapter.isEnabled());
+ return;
+ case BluetoothAdapter.STATE_ON:
+ assertTrue(adapter.isEnabled());
+ assertTrue(adapter.disable());
+ break;
+ case BluetoothAdapter.STATE_TURNING_ON:
+ assertFalse(adapter.isEnabled());
+ assertTrue(adapter.disable());
+ break;
+ case BluetoothAdapter.STATE_TURNING_OFF:
+ assertFalse(adapter.isEnabled());
+ mask = 0; // Don't check for received intents since we might have missed them.
+ break;
+ default:
+ fail("disable() invalid state: " + state);
+ }
+
+ long s = System.currentTimeMillis();
+ while (System.currentTimeMillis() - s < DISABLE_TIMEOUT) {
+ state = adapter.getState();
+ if (state == BluetoothAdapter.STATE_OFF) {
+ assertFalse(adapter.isEnabled());
+ if ((mReceiver.getFiredFlags() & mask) == mask) {
+ mReceiver.resetFiredFlags();
+ return;
+ }
+ } else {
+ assertFalse(adapter.isEnabled());
+ assertEquals(BluetoothAdapter.STATE_TURNING_OFF, state);
+ }
+ sleep(POLL_TIME);
+ }
+
+ int firedFlags = mReceiver.getFiredFlags();
+ mReceiver.resetFiredFlags();
+ fail("disable() timeout: " +
+ "state=" + state + " (expected " + BluetoothAdapter.STATE_OFF + ") " +
+ "flags=" + firedFlags + " (expected " + mask + ")");
+ }
+
+ private void enable(BluetoothAdapter adapter) {
+ int mask = STATE_TURNING_ON_FLAG | STATE_ON_FLAG | SCAN_MODE_CONNECTABLE_FLAG;
+ mReceiver.resetFiredFlags();
+
+ int state = adapter.getState();
+ switch (state) {
+ case BluetoothAdapter.STATE_ON:
+ assertTrue(adapter.isEnabled());
+ return;
+ case BluetoothAdapter.STATE_OFF:
+ case BluetoothAdapter.STATE_TURNING_OFF:
+ assertFalse(adapter.isEnabled());
+ assertTrue(adapter.enable());
+ break;
+ case BluetoothAdapter.STATE_TURNING_ON:
+ assertFalse(adapter.isEnabled());
+ mask = 0; // Don't check for received intents since we might have missed them.
+ break;
+ default:
+ fail("enable() invalid state: state=" + state);
+ }
+
+ long s = System.currentTimeMillis();
+ while (System.currentTimeMillis() - s < ENABLE_TIMEOUT) {
+ state = adapter.getState();
+ if (state == BluetoothAdapter.STATE_ON) {
+ assertTrue(adapter.isEnabled());
+ if ((mReceiver.getFiredFlags() & mask) == mask) {
+ mReceiver.resetFiredFlags();
+ return;
+ }
+ } else {
+ assertFalse(adapter.isEnabled());
+ assertEquals(BluetoothAdapter.STATE_TURNING_ON, state);
+ }
+ sleep(POLL_TIME);
+ }
+
+ int firedFlags = mReceiver.getFiredFlags();
+ mReceiver.resetFiredFlags();
+ fail("enable() timeout: " +
+ "state=" + state + " (expected " + BluetoothAdapter.STATE_OFF + ") " +
+ "flags=" + firedFlags + " (expected " + mask + ")");
+ }
+
+ private void discoverable(BluetoothAdapter adapter) {
+ int mask = SCAN_MODE_CONNECTABLE_DISCOVERABLE_FLAG;
+ mReceiver.resetFiredFlags();
+
+ if (!adapter.isEnabled()) {
+ fail("discoverable() bluetooth not enabled");
+ }
+
+ int scanMode = adapter.getScanMode();
+ if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
+ return;
+ }
+
+ assertEquals(scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE);
+ assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE));
+
+ long s = System.currentTimeMillis();
+ while (System.currentTimeMillis() - s < SET_SCAN_MODE_TIMEOUT) {
+ scanMode = adapter.getScanMode();
+ if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
+ if ((mReceiver.getFiredFlags() & mask) == mask) {
+ mReceiver.resetFiredFlags();
+ return;
+ }
+ } else {
+ assertEquals(scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE);
+ }
+ sleep(POLL_TIME);
+ }
+
+ int firedFlags = mReceiver.getFiredFlags();
+ mReceiver.resetFiredFlags();
+ fail("discoverable() timeout: " +
+ "scanMode=" + scanMode + " (expected " +
+ BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE + ") " +
+ "flags=" + firedFlags + " (expected " + mask + ")");
+ }
+
+ private void undiscoverable(BluetoothAdapter adapter) {
+ int mask = SCAN_MODE_CONNECTABLE_FLAG;
+ mReceiver.resetFiredFlags();
+
+ if (!adapter.isEnabled()) {
+ fail("undiscoverable(): bluetooth not enabled");
+ }
+
+ int scanMode = adapter.getScanMode();
+ if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
+ return;
+ }
+
+ assertEquals(scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
+ assertTrue(adapter.setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE));
+
+ long s = System.currentTimeMillis();
+ while (System.currentTimeMillis() - s < SET_SCAN_MODE_TIMEOUT) {
+ scanMode = adapter.getScanMode();
+ if (scanMode == BluetoothAdapter.SCAN_MODE_CONNECTABLE) {
+ if ((mReceiver.getFiredFlags() & mask) == mask) {
+ mReceiver.resetFiredFlags();
+ return;
+ }
+ } else {
+ assertEquals(scanMode, BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE);
+ }
+ sleep(POLL_TIME);
+ }
+
+ int firedFlags = mReceiver.getFiredFlags();
+ mReceiver.resetFiredFlags();
+ fail("undiscoverable() timeout: " +
+ "scanMode=" + scanMode + " (expected " +
+ BluetoothAdapter.SCAN_MODE_CONNECTABLE + ") " +
+ "flags=" + firedFlags + " (expected " + mask + ")");
+ }
+
+ private void startScan(BluetoothAdapter adapter) {
+ int mask = DISCOVERY_STARTED_FLAG;
+ mReceiver.resetFiredFlags();
+
+ if (!adapter.isEnabled()) {
+ fail("startScan(): bluetooth not enabled");
+ }
+
+ if (adapter.isDiscovering()) {
+ return;
+ }
+
+ assertTrue(adapter.startDiscovery());
+
+ long s = System.currentTimeMillis();
+ while (System.currentTimeMillis() - s < START_DISCOVERY_TIMEOUT) {
+ if (adapter.isDiscovering() && ((mReceiver.getFiredFlags() & mask) == mask)) {
+ mReceiver.resetFiredFlags();
+ return;
+ }
+ sleep(POLL_TIME);
+ }
+
+ int firedFlags = mReceiver.getFiredFlags();
+ mReceiver.resetFiredFlags();
+ fail("startScan() timeout: " +
+ "isDiscovering=" + adapter.isDiscovering() + " " +
+ "flags=" + firedFlags + " (expected " + mask + ")");
+ }
+
+ private void stopScan(BluetoothAdapter adapter) {
+ int mask = DISCOVERY_FINISHED_FLAG;
+ mReceiver.resetFiredFlags();
+
+ if (!adapter.isEnabled()) {
+ fail("stopScan(): bluetooth not enabled");
+ }
+
+ if (!adapter.isDiscovering()) {
+ return;
+ }
+
+ // TODO: put assertTrue() around cancelDiscovery() once it starts
+ // returning true.
+ adapter.cancelDiscovery();
+
+ long s = System.currentTimeMillis();
+ while (System.currentTimeMillis() - s < CANCEL_DISCOVERY_TIMEOUT) {
+ if (!adapter.isDiscovering() && ((mReceiver.getFiredFlags() & mask) == mask)) {
+ mReceiver.resetFiredFlags();
+ return;
+ }
+ sleep(POLL_TIME);
+ }
+
+ int firedFlags = mReceiver.getFiredFlags();
+ mReceiver.resetFiredFlags();
+ fail("stopScan() timeout: " +
+ "isDiscovering=" + adapter.isDiscovering() + " " +
+ "flags=" + firedFlags + " (expected " + mask + ")");
+ }
+
+ private void sleep(long time) {
+ try {
+ Thread.sleep(time);
+ } catch (InterruptedException e) {
+ }
+ }
+}
diff --git a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
index 7c28516..cbf8c87 100755
--- a/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
+++ b/core/tests/coretests/src/android/content/pm/PackageManagerTests.java
@@ -69,7 +69,7 @@
@Override
protected void setUp() throws Exception {
super.setUp();
- mOrigState = getMediaState();
+ mOrigState = checkMediaState(Environment.MEDIA_MOUNTED);
if (!mountMedia()) {
Log.i(TAG, "sdcard not mounted? Some of these tests might fail");
}
@@ -78,12 +78,12 @@
@Override
protected void tearDown() throws Exception {
// Restore media state.
- boolean newState = getMediaState();
+ boolean newState = checkMediaState(Environment.MEDIA_MOUNTED);
if (newState != mOrigState) {
if (mOrigState) {
- getMs().mountVolume(Environment.getExternalStorageDirectory().getPath());
+ mountMedia();
} else {
- getMs().unmountVolume(Environment.getExternalStorageDirectory().getPath(), true);
+ unmountMedia();
}
}
super.tearDown();
@@ -576,6 +576,7 @@
@LargeTest
public void testInstallSdcard() {
+ mountMedia();
sampleInstallFromRawResource(PackageManager.INSTALL_EXTERNAL, true);
}
@@ -913,41 +914,62 @@
return null;
}
- boolean getMediaState() {
+ boolean checkMediaState(String desired) {
try {
- String mPath = Environment.getExternalStorageDirectory().getPath();
- String state = getMs().getVolumeState(mPath);
- return Environment.MEDIA_MOUNTED.equals(state);
+ String mPath = Environment.getExternalStorageDirectory().getPath();
+ String actual = getMs().getVolumeState(mPath);
+ if (desired.equals(actual)) {
+ return true;
+ } else {
+ return false;
+ }
} catch (RemoteException e) {
+ Log.e(TAG, "Exception while checking media state", e);
return false;
}
}
boolean mountMedia() {
- if (getMediaState()) {
+ if (checkMediaState(Environment.MEDIA_MOUNTED)) {
return true;
}
+
+ final String path = Environment.getExternalStorageDirectory().toString();
+ StorageListener observer = new StorageListener(Environment.MEDIA_MOUNTED);
+ StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
+ sm.registerListener(observer);
try {
- String mPath = Environment.getExternalStorageDirectory().toString();
- int ret = getMs().mountVolume(mPath);
- return ret == StorageResultCode.OperationSucceeded;
- } catch (RemoteException e) {
+ // Wait on observer
+ synchronized (observer) {
+ int ret = getMs().mountVolume(path);
+ if (ret != StorageResultCode.OperationSucceeded) {
+ throw new Exception("Could not mount the media");
+ }
+ long waitTime = 0;
+ while ((!observer.isDone()) && (waitTime < MAX_WAIT_TIME)) {
+ observer.wait(WAIT_TIME_INCR);
+ waitTime += WAIT_TIME_INCR;
+ }
+ if (!observer.isDone()) {
+ throw new Exception("Timed out waiting for unmount media notification");
+ }
+ return true;
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Exception : " + e);
return false;
+ } finally {
+ sm.unregisterListener(observer);
}
}
private boolean unmountMedia() {
- String path = Environment.getExternalStorageDirectory().getPath();
- try {
- String state = getMs().getVolumeState(path);
- if (Environment.MEDIA_UNMOUNTED.equals(state)) {
- return true;
- }
- } catch (RemoteException e) {
- failStr(e);
+ if (checkMediaState(Environment.MEDIA_UNMOUNTED)) {
+ return true;
}
- StorageListener observer = new StorageListener();
+ final String path = Environment.getExternalStorageDirectory().getPath();
+ StorageListener observer = new StorageListener(Environment.MEDIA_UNMOUNTED);
StorageManager sm = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
sm.registerListener(observer);
try {
@@ -976,7 +998,7 @@
// Install pkg on sdcard
InstallParams ip = sampleInstallFromRawResource(PackageManager.INSTALL_EXTERNAL, false);
if (localLOGV) Log.i(TAG, "Installed pkg on sdcard");
- boolean origState = getMediaState();
+ boolean origState = checkMediaState(Environment.MEDIA_MOUNTED);
boolean registeredReceiver = false;
SdMountReceiver receiver = new SdMountReceiver(new String[]{ip.pkg.packageName});
try {
@@ -1468,7 +1490,7 @@
*/
@LargeTest
public void testInstallSdcardUnmount() {
- boolean origState = getMediaState();
+ boolean origState = checkMediaState(Environment.MEDIA_MOUNTED);
try {
// Unmount sdcard
assertTrue(unmountMedia());
@@ -1493,22 +1515,22 @@
*/
@LargeTest
public void testInstallManifestSdcardUnmount() {
- boolean origState = getMediaState();
- try {
- // Unmount sdcard
- assertTrue(unmountMedia());
- InstallParams ip = new InstallParams("install.apk", R.raw.install_loc_sdcard);
- installFromRawResource(ip, 0, true, false, -1,
- PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
- } finally {
- // Restore original media state
- if (origState) {
- mountMedia();
- } else {
- unmountMedia();
- }
- }
- }
+ boolean origState = checkMediaState(Environment.MEDIA_MOUNTED);
+ try {
+ // Unmount sdcard
+ assertTrue(unmountMedia());
+ InstallParams ip = new InstallParams("install.apk", R.raw.install_loc_sdcard);
+ installFromRawResource(ip, 0, true, false, -1,
+ PackageInfo.INSTALL_LOCATION_INTERNAL_ONLY);
+ } finally {
+ // Restore original media state
+ if (origState) {
+ mountMedia();
+ } else {
+ unmountMedia();
+ }
+ }
+ }
/*---------- Recommended install location tests ----*/
/* Precedence: FlagManifestExistingUser
@@ -2269,7 +2291,7 @@
@LargeTest
public void testInstallOnSdPermissionsUnmount() {
InstallParams ip = null;
- boolean origMediaState = getMediaState();
+ boolean origMediaState = checkMediaState(Environment.MEDIA_MOUNTED);
try {
// **: Upon installing a package, are its declared permissions published?
int iFlags = PackageManager.INSTALL_INTERNAL;
@@ -2300,8 +2322,10 @@
*/
@LargeTest
public void testInstallSdcardStaleContainer() {
- boolean origMediaState = getMediaState();
+ boolean origMediaState = checkMediaState(Environment.MEDIA_MOUNTED);
try {
+ // Mount media first
+ mountMedia();
String outFileName = "install.apk";
int rawResId = R.raw.install;
PackageManager pm = mContext.getPackageManager();
@@ -2342,7 +2366,7 @@
*/
@LargeTest
public void testInstallSdcardStaleContainerReinstall() {
- boolean origMediaState = getMediaState();
+ boolean origMediaState = checkMediaState(Environment.MEDIA_MOUNTED);
try {
// Mount media first
mountMedia();
@@ -2375,7 +2399,6 @@
} else {
unmountMedia();
}
-
}
}
/*
diff --git a/core/tests/coretests/src/android/os/storage/StorageListener.java b/core/tests/coretests/src/android/os/storage/StorageListener.java
index d6dae22..6a26b88 100644
--- a/core/tests/coretests/src/android/os/storage/StorageListener.java
+++ b/core/tests/coretests/src/android/os/storage/StorageListener.java
@@ -21,21 +21,24 @@
public class StorageListener extends StorageEventListener {
private static final boolean localLOGV = true;
- public static final String TAG="StorageListener";
+ public static final String TAG = "StorageListener";
- String oldState;
- String newState;
- String path;
+ private String mTargetState;
private boolean doneFlag = false;
+
+ public StorageListener(String targetState) {
+ mTargetState = targetState;
+ }
+
@Override
public void onStorageStateChanged(String path, String oldState, String newState) {
if (localLOGV) Log.i(TAG, "Storage state changed from " + oldState + " to " + newState);
+
synchronized (this) {
- this.oldState = oldState;
- this.newState = newState;
- this.path = path;
- doneFlag = true;
- notifyAll();
+ if (mTargetState.equals(newState)) {
+ doneFlag = true;
+ notifyAll();
+ }
}
}
diff --git a/docs/html/guide/topics/resources/color-list-resource.jd b/docs/html/guide/topics/resources/color-list-resource.jd
index 449b66f..b20915c 100644
--- a/docs/html/guide/topics/resources/color-list-resource.jd
+++ b/docs/html/guide/topics/resources/color-list-resource.jd
@@ -55,7 +55,6 @@
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_selected=["true" | "false"]
- android:state_active=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
diff --git a/docs/html/guide/topics/resources/drawable-resource.jd b/docs/html/guide/topics/resources/drawable-resource.jd
index 1c3cc4d..035ddb9 100644
--- a/docs/html/guide/topics/resources/drawable-resource.jd
+++ b/docs/html/guide/topics/resources/drawable-resource.jd
@@ -638,7 +638,6 @@
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_selected=["true" | "false"]
- android:state_active=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
diff --git a/docs/html/guide/topics/resources/more-resources.jd b/docs/html/guide/topics/resources/more-resources.jd
index 1f03446..a647571 100644
--- a/docs/html/guide/topics/resources/more-resources.jd
+++ b/docs/html/guide/topics/resources/more-resources.jd
@@ -310,7 +310,7 @@
<TextView
android:layout_height="@dimen/textview_height"
android:layout_width="@dimen/textview_width"
- android:textSize="@dimen/sixteen_sp"/>
+ android:textSize="@dimen/font_size"/>
</pre>
</dl>
</dd> <!-- end example -->
diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h
index 6c6949b..010ded1 100644
--- a/include/media/stagefright/OMXCodec.h
+++ b/include/media/stagefright/OMXCodec.h
@@ -181,6 +181,11 @@
status_t setupH263EncoderParameters(const sp<MetaData>& meta);
status_t setupMPEG4EncoderParameters(const sp<MetaData>& meta);
status_t setupAVCEncoderParameters(const sp<MetaData>& meta);
+ status_t findTargetColorFormat(
+ const sp<MetaData>& meta, OMX_COLOR_FORMATTYPE *colorFormat);
+
+ status_t isColorFormatSupported(
+ OMX_COLOR_FORMATTYPE colorFormat, int portIndex);
// If profile/level is set in the meta data, its value in the meta
// data will be used; otherwise, the default value will be used.
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index dfdeb98..2a94651 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -798,7 +798,7 @@
return false;
}
if (!waitForSpace) {
- if (mIO.mToClient.getFreeSpace() < len) {
+ if (mIO.mToClient.getFreeSpace() <= (len + 8)) {
// Not enough room, and not waiting.
return false;
}
diff --git a/libs/utils/ZipFileRO.cpp b/libs/utils/ZipFileRO.cpp
index 28dc512..a4c3500 100644
--- a/libs/utils/ZipFileRO.cpp
+++ b/libs/utils/ZipFileRO.cpp
@@ -253,21 +253,21 @@
/*
* Grab the CD offset and size, and the number of entries in the
- * archive. Verify that they look reasonable.
+ * archive. After that, we can release our EOCD hunt buffer.
*/
unsigned int numEntries = get2LE(eocdPtr + kEOCDNumEntries);
unsigned int dirSize = get4LE(eocdPtr + kEOCDSize);
unsigned int dirOffset = get4LE(eocdPtr + kEOCDFileOffset);
+ free(scanBuf);
+ // Verify that they look reasonable.
if ((long long) dirOffset + (long long) dirSize > (long long) eocdOffset) {
LOGW("bad offsets (dir %ld, size %u, eocd %ld)\n",
(long) dirOffset, dirSize, (long) eocdOffset);
- free(scanBuf);
return false;
}
if (numEntries == 0) {
LOGW("empty archive?\n");
- free(scanBuf);
return false;
}
@@ -277,14 +277,12 @@
mDirectoryMap = new FileMap();
if (mDirectoryMap == NULL) {
LOGW("Unable to create directory map: %s", strerror(errno));
- free(scanBuf);
return false;
}
if (!mDirectoryMap->create(mFileName, mFd, dirOffset, dirSize, true)) {
LOGW("Unable to map '%s' (%zd to %zd): %s\n", mFileName,
dirOffset, dirOffset + dirSize, strerror(errno));
- free(scanBuf);
return false;
}
@@ -683,7 +681,7 @@
goto bail;
} else if ((size_t) actual != uncompLen) {
LOGE("Partial write during uncompress (%zd of %zd)\n",
- actual, uncompLen);
+ (size_t)actual, (size_t)uncompLen);
goto bail;
} else {
LOGI("+++ successful write\n");
diff --git a/media/java/android/media/AudioFormat.java b/media/java/android/media/AudioFormat.java
index 403a68e..31e4631 100644
--- a/media/java/android/media/AudioFormat.java
+++ b/media/java/android/media/AudioFormat.java
@@ -19,7 +19,7 @@
/**
* The AudioFormat class is used to access a number of audio format and
* channel configuration constants. They are for instance used
- * in __link AudioTrack} and __link AudioRecord}.
+ * in {@link AudioTrack} and {@link AudioRecord}.
*
*/
public class AudioFormat {
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index 436f098..e426fca 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -854,7 +854,7 @@
status_t AwesomePlayer::initVideoDecoder() {
uint32_t flags = 0;
-#if 1
+#if 0
if (mRTPSession != NULL) {
// XXX hack.
@@ -1225,7 +1225,10 @@
} else if (!strcmp("rtsp://gtalk", mUri.string())) {
if (mLooper == NULL) {
mLooper = new ALooper;
- mLooper->start();
+ mLooper->start(
+ false /* runOnCallingThread */,
+ false /* canCallJava */,
+ PRIORITY_HIGHEST);
}
#if 0
@@ -1240,39 +1243,6 @@
mLooper->registerHandler(mRTPSession);
#if 0
- // My H264 SDP
- static const char *raw =
- "v=0\r\n"
- "o=- 64 233572944 IN IP4 127.0.0.0\r\n"
- "s=QuickTime\r\n"
- "t=0 0\r\n"
- "a=range:npt=0-315\r\n"
- "a=isma-compliance:2,2.0,2\r\n"
- "m=video 5434 RTP/AVP 97\r\n"
- "c=IN IP4 127.0.0.1\r\n"
- "b=AS:30\r\n"
- "a=rtpmap:97 H264/90000\r\n"
- "a=fmtp:97 packetization-mode=1;profile-level-id=42000C;"
- "sprop-parameter-sets=Z0IADJZUCg+I,aM44gA==\r\n"
- "a=mpeg4-esid:201\r\n"
- "a=cliprect:0,0,240,320\r\n"
- "a=framesize:97 320-240\r\n";
-#elif 0
- // My H263 SDP
- static const char *raw =
- "v=0\r\n"
- "o=- 64 233572944 IN IP4 127.0.0.0\r\n"
- "s=QuickTime\r\n"
- "t=0 0\r\n"
- "a=range:npt=0-315\r\n"
- "a=isma-compliance:2,2.0,2\r\n"
- "m=video 5434 RTP/AVP 97\r\n"
- "c=IN IP4 127.0.0.1\r\n"
- "b=AS:30\r\n"
- "a=rtpmap:97 H263-1998/90000\r\n"
- "a=cliprect:0,0,240,320\r\n"
- "a=framesize:97 320-240\r\n";
-#elif 0
// My AMR SDP
static const char *raw =
"v=0\r\n"
@@ -1299,12 +1269,9 @@
"c=IN IP4 127.0.0.1\r\n"
"b=AS:30\r\n"
"a=rtpmap:97 H264/90000\r\n"
- "a=fmtp:97 packetization-mode=1;profile-level-id=42E00D;"
- "sprop-parameter-sets=J0LgDZWgUG/lQA==,KM4DnoA=\r\n"
- "a=mpeg4-esid:201\r\n"
"a=cliprect:0,0,200,320\r\n"
"a=framesize:97 320-200\r\n";
-#elif 0
+#else
// GTalk H263 SDP
static const char *raw =
"v=0\r\n"
@@ -1319,22 +1286,6 @@
"a=rtpmap:98 H263-1998/90000\r\n"
"a=cliprect:0,0,200,320\r\n"
"a=framesize:98 320-200\r\n";
-#else
- // sholes H264 SDP
- static const char *raw =
- "v=0\r\n"
- "o=- 64 233572944 IN IP4 127.0.0.0\r\n"
- "s=QuickTime\r\n"
- "t=0 0\r\n"
- "a=range:npt=now-\r\n"
- "m=video 5434 RTP/AVP 96\r\n"
- "c=IN IP4 127.0.0.1\r\n"
- "b=AS:320000\r\n"
- "a=rtpmap:96 H264/90000\r\n"
- "a=fmtp:96 packetization-mode=1;profile-level-id=42001E;"
- "sprop-parameter-sets=Z0KACukCg+QgAAB9AAAOpgCA,aM48gA==\r\n"
- "a=cliprect:0,0,240,320\r\n"
- "a=framesize:96 320-240\r\n";
#endif
sp<ASessionDescription> desc = new ASessionDescription;
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 4928951..0d8c3c6 100644
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -68,7 +68,7 @@
bool mIsAvc;
bool mIsAudio;
bool mIsMPEG4;
- int64_t mMaxTimeStampUs;
+ int64_t mTrackDurationUs;
int64_t mEstimatedTrackSizeBytes;
int64_t mMaxWriteTimeUs;
int32_t mTimeScale;
@@ -711,7 +711,7 @@
mDone(false),
mPaused(false),
mResumed(false),
- mMaxTimeStampUs(0),
+ mTrackDurationUs(0),
mEstimatedTrackSizeBytes(0),
mSamplesHaveSameSize(true),
mCodecSpecificData(NULL),
@@ -958,7 +958,7 @@
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
mDone = false;
- mMaxTimeStampUs = 0;
+ mTrackDurationUs = 0;
mReachedEOS = false;
mEstimatedTrackSizeBytes = 0;
@@ -1300,15 +1300,15 @@
}
if (mResumed) {
- previousPausedDurationUs += (timestampUs - mMaxTimeStampUs - lastDurationUs);
+ previousPausedDurationUs += (timestampUs - mTrackDurationUs - lastDurationUs);
mResumed = false;
}
timestampUs -= previousPausedDurationUs;
LOGV("time stamp: %lld and previous paused duration %lld",
timestampUs, previousPausedDurationUs);
- if (timestampUs > mMaxTimeStampUs) {
- mMaxTimeStampUs = timestampUs;
+ if (timestampUs > mTrackDurationUs) {
+ mTrackDurationUs = timestampUs;
}
mSampleSizes.push_back(sampleSize);
@@ -1407,6 +1407,7 @@
}
SttsTableEntry sttsEntry(sampleCount, lastDurationUs);
mSttsTableEntries.push_back(sttsEntry);
+ mTrackDurationUs += lastDurationUs;
mReachedEOS = true;
LOGI("Received total/0-length (%d/%d) buffers and encoded %d frames. Max write time: %lld us - %s",
count, nZeroLengthFrames, mNumSamples, mMaxWriteTimeUs, mIsAudio? "audio": "video");
@@ -1472,7 +1473,7 @@
void MPEG4Writer::Track::findMinAvgMaxSampleDurationMs(
int32_t *min, int32_t *avg, int32_t *max) {
CHECK(!mSampleSizes.empty());
- int32_t avgSampleDurationMs = mMaxTimeStampUs / 1000 / mNumSamples;
+ int32_t avgSampleDurationMs = mTrackDurationUs / 1000 / mNumSamples;
int32_t minSampleDurationMs = 0x7FFFFFFF;
int32_t maxSampleDurationMs = 0;
for (List<SttsTableEntry>::iterator it = mSttsTableEntries.begin();
@@ -1514,7 +1515,7 @@
}
void MPEG4Writer::Track::logStatisticalData(bool isAudio) {
- if (mMaxTimeStampUs <= 0 || mSampleSizes.empty()) {
+ if (mTrackDurationUs <= 0 || mSampleSizes.empty()) {
LOGI("nothing is recorded");
return;
}
@@ -1523,7 +1524,7 @@
if (collectStats) {
LOGI("%s track - duration %lld us, total %d frames",
- isAudio? "audio": "video", mMaxTimeStampUs,
+ isAudio? "audio": "video", mTrackDurationUs,
mNumSamples);
int32_t min, avg, max;
findMinAvgMaxSampleDurationMs(&min, &avg, &max);
@@ -1541,7 +1542,7 @@
it != mSampleSizes.end(); ++it) {
totalBytes += (*it);
}
- float bitRate = (totalBytes * 8000000.0) / mMaxTimeStampUs;
+ float bitRate = (totalBytes * 8000000.0) / mTrackDurationUs;
LOGI("avg bit rate (bps): %.2f", bitRate);
int64_t duration = mOwner->interleaveDuration();
@@ -1568,7 +1569,7 @@
}
int64_t MPEG4Writer::Track::getDurationUs() const {
- return mMaxTimeStampUs;
+ return mTrackDurationUs;
}
int64_t MPEG4Writer::Track::getEstimatedTrackSizeBytes() const {
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index d19fbe5..4f3bffd 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -762,6 +762,65 @@
}
}
+status_t OMXCodec::findTargetColorFormat(
+ const sp<MetaData>& meta, OMX_COLOR_FORMATTYPE *colorFormat) {
+ LOGV("findTargetColorFormat");
+ CHECK(mIsEncoder);
+
+ *colorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
+ int32_t targetColorFormat;
+ if (meta->findInt32(kKeyColorFormat, &targetColorFormat)) {
+ *colorFormat = (OMX_COLOR_FORMATTYPE) targetColorFormat;
+ } else {
+ if (!strcasecmp("OMX.TI.Video.encoder", mComponentName)) {
+ *colorFormat = OMX_COLOR_FormatYCbYCr;
+ }
+ }
+
+ // Check whether the target color format is supported.
+ return isColorFormatSupported(*colorFormat, kPortIndexInput);
+}
+
+status_t OMXCodec::isColorFormatSupported(
+ OMX_COLOR_FORMATTYPE colorFormat, int portIndex) {
+ LOGV("isColorFormatSupported: %d", static_cast<int>(colorFormat));
+
+ // Enumerate all the color formats supported by
+ // the omx component to see whether the given
+ // color format is supported.
+ OMX_VIDEO_PARAM_PORTFORMATTYPE portFormat;
+ InitOMXParams(&portFormat);
+ portFormat.nPortIndex = portIndex;
+ OMX_U32 index = 0;
+ portFormat.nIndex = index;
+ while (true) {
+ if (OMX_ErrorNone != mOMX->getParameter(
+ mNode, OMX_IndexParamVideoPortFormat,
+ &portFormat, sizeof(portFormat))) {
+
+ return UNKNOWN_ERROR;
+ }
+ // Make sure that omx component does not overwrite
+ // the incremented index (bug 2897413).
+ CHECK_EQ(index, portFormat.nIndex);
+ if ((portFormat.eColorFormat == colorFormat)) {
+ LOGV("Found supported color format: %d", portFormat.eColorFormat);
+ return OK; // colorFormat is supported!
+ }
+ ++index;
+ portFormat.nIndex = index;
+
+ // OMX Spec defines less than 50 color formats
+ // 1000 is more than enough for us to tell whether the omx
+ // component in question is buggy or not.
+ if (index >= 1000) {
+ LOGE("More than %ld color formats are supported???", index);
+ break;
+ }
+ }
+ return UNKNOWN_ERROR;
+}
+
void OMXCodec::setVideoInputFormat(
const char *mime, const sp<MetaData>& meta) {
@@ -787,10 +846,8 @@
CHECK(!"Should not be here. Not a supported video mime type.");
}
- OMX_COLOR_FORMATTYPE colorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
- if (!strcasecmp("OMX.TI.Video.encoder", mComponentName)) {
- colorFormat = OMX_COLOR_FormatYCbYCr;
- }
+ OMX_COLOR_FORMATTYPE colorFormat;
+ CHECK_EQ(OK, findTargetColorFormat(meta, &colorFormat));
status_t err;
OMX_PARAM_PORTDEFINITIONTYPE def;
diff --git a/media/libstagefright/OggExtractor.cpp b/media/libstagefright/OggExtractor.cpp
index 16f094b..641a876 100644
--- a/media/libstagefright/OggExtractor.cpp
+++ b/media/libstagefright/OggExtractor.cpp
@@ -361,11 +361,17 @@
memcpy(tmp->data(), buffer->data(), buffer->range_length());
tmp->set_range(0, buffer->range_length());
buffer->release();
- } else if (mVi.rate) {
+ } else {
// XXX Not only is this not technically the correct time for
// this packet, we also stamp every packet in this page
// with the same time. This needs fixing later.
- timeUs = mCurrentPage.mGranulePosition * 1000000ll / mVi.rate;
+
+ if (mVi.rate) {
+ // Rate may not have been initialized yet if we're currently
+ // reading the configuration packets...
+ // Fortunately, the timestamp doesn't matter for those.
+ timeUs = mCurrentPage.mGranulePosition * 1000000ll / mVi.rate;
+ }
tmp->set_range(0, 0);
}
buffer = tmp;
diff --git a/media/libstagefright/rtsp/APacketSource.cpp b/media/libstagefright/rtsp/APacketSource.cpp
index 88336ba..a577704 100644
--- a/media/libstagefright/rtsp/APacketSource.cpp
+++ b/media/libstagefright/rtsp/APacketSource.cpp
@@ -92,7 +92,9 @@
static sp<ABuffer> MakeAVCCodecSpecificData(const char *params) {
AString val;
- CHECK(GetAttribute(params, "profile-level-id", &val));
+ if (!GetAttribute(params, "profile-level-id", &val)) {
+ return NULL;
+ }
sp<ABuffer> profileLevelID = decodeHex(val);
CHECK(profileLevelID != NULL);
@@ -105,7 +107,10 @@
size_t numPicParameterSets = 0;
size_t totalPicParameterSetSize = 0;
- CHECK(GetAttribute(params, "sprop-parameter-sets", &val));
+ if (!GetAttribute(params, "sprop-parameter-sets", &val)) {
+ return NULL;
+ }
+
size_t start = 0;
for (;;) {
ssize_t commaPos = val.find(",", start);
@@ -256,9 +261,11 @@
sp<ABuffer> codecSpecificData =
MakeAVCCodecSpecificData(params.c_str());
- mFormat->setData(
- kKeyAVCC, 0,
- codecSpecificData->data(), codecSpecificData->size());
+ if (codecSpecificData != NULL) {
+ mFormat->setData(
+ kKeyAVCC, 0,
+ codecSpecificData->data(), codecSpecificData->size());
+ }
} else if (!strncmp(desc.c_str(), "H263-2000/", 10)
|| !strncmp(desc.c_str(), "H263-1998/", 10)) {
mFormat->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_H263);
diff --git a/media/libstagefright/rtsp/ARTPConnection.cpp b/media/libstagefright/rtsp/ARTPConnection.cpp
index 9abdab4..5bd306b 100644
--- a/media/libstagefright/rtsp/ARTPConnection.cpp
+++ b/media/libstagefright/rtsp/ARTPConnection.cpp
@@ -405,6 +405,14 @@
buffer->setInt32Data(u16at(&data[2]));
buffer->setRange(payloadOffset, size - payloadOffset);
+#if IGNORE_RTCP_TIME
+ if (!source->timeEstablished()) {
+ source->timeUpdate(rtpTime, 0);
+ source->timeUpdate(rtpTime + 20, 0x100000000ll);
+ CHECK(source->timeEstablished());
+ }
+#endif
+
source->processRTPPacket(buffer);
return OK;
@@ -541,12 +549,6 @@
source = new ARTPSource(
srcId, info->mSessionDesc, info->mIndex, info->mNotifyMsg);
-#if IGNORE_RTCP_TIME
- // For H.263 gtalk to work...
- source->timeUpdate(0, 0);
- source->timeUpdate(30, 0x100000000ll);
-#endif
-
info->mSources.add(srcId, source);
} else {
source = info->mSources.valueAt(index);
diff --git a/media/libstagefright/rtsp/ARTPSource.cpp b/media/libstagefright/rtsp/ARTPSource.cpp
index 2aa0c1f..e08183e 100644
--- a/media/libstagefright/rtsp/ARTPSource.cpp
+++ b/media/libstagefright/rtsp/ARTPSource.cpp
@@ -58,6 +58,7 @@
} else if (!strncmp(desc.c_str(), "H263-1998/", 10)
|| !strncmp(desc.c_str(), "H263-2000/", 10)) {
mAssembler = new AH263Assembler(notify);
+ mIssueFIRRequests = true;
} else if (!strncmp(desc.c_str(), "AMR/", 4)) {
mAssembler = new AAMRAssembler(notify, false /* isWide */, params);
} else if (!strncmp(desc.c_str(), "AMR-WB/", 7)) {
diff --git a/media/libstagefright/rtsp/ARTPSource.h b/media/libstagefright/rtsp/ARTPSource.h
index 8e483a8..252d6d6 100644
--- a/media/libstagefright/rtsp/ARTPSource.h
+++ b/media/libstagefright/rtsp/ARTPSource.h
@@ -46,6 +46,10 @@
void addReceiverReport(const sp<ABuffer> &buffer);
void addFIR(const sp<ABuffer> &buffer);
+ bool timeEstablished() const {
+ return mNumTimes == 2;
+ }
+
private:
uint32_t mID;
uint32_t mHighestSeqNumber;
diff --git a/preloaded-classes b/preloaded-classes
index 6a10bb3..33dba37 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -697,8 +697,6 @@
com.ibm.icu4jni.charset.CharsetICU
com.ibm.icu4jni.charset.NativeConverter
com.ibm.icu4jni.common.ErrorCode
-com.ibm.icu4jni.lang.UCharacter
-com.ibm.icu4jni.regex.NativeRegEx
com.ibm.icu4jni.text.Collator
com.ibm.icu4jni.text.NativeBreakIterator
com.ibm.icu4jni.text.NativeCollation
@@ -1168,7 +1166,6 @@
org.apache.harmony.security.x509.TBSCertificate
org.apache.harmony.security.x509.Time
org.apache.harmony.security.x509.Validity
-org.apache.harmony.text.BidiWrapper
org.apache.harmony.xml.ExpatAttributes
org.apache.harmony.xml.ExpatParser
org.apache.harmony.xml.ExpatPullParser
diff --git a/services/java/com/android/server/ClipboardService.java b/services/java/com/android/server/ClipboardService.java
index aa8cded..4e4fc0c 100644
--- a/services/java/com/android/server/ClipboardService.java
+++ b/services/java/com/android/server/ClipboardService.java
@@ -16,42 +16,77 @@
package com.android.server;
-import android.text.IClipboard;
+import android.content.ClippedData;
+import android.content.IClipboard;
+import android.content.IOnPrimaryClipChangedListener;
import android.content.Context;
+import android.os.RemoteCallbackList;
+import android.os.RemoteException;
/**
* Implementation of the clipboard for copy and paste.
*/
public class ClipboardService extends IClipboard.Stub {
- private CharSequence mClipboard = "";
+ private ClippedData mPrimaryClip;
+ private final RemoteCallbackList<IOnPrimaryClipChangedListener> mPrimaryClipListeners
+ = new RemoteCallbackList<IOnPrimaryClipChangedListener>();
/**
* Instantiates the clipboard.
*/
public ClipboardService(Context context) { }
- // javadoc from interface
- public void setClipboardText(CharSequence text) {
+ public void setPrimaryClip(ClippedData clip) {
synchronized (this) {
- if (text == null) {
- text = "";
+ if (clip != null && clip.getItemCount() <= 0) {
+ throw new IllegalArgumentException("No items");
}
+ mPrimaryClip = clip;
+ final int n = mPrimaryClipListeners.beginBroadcast();
+ for (int i = 0; i < n; i++) {
+ try {
+ mPrimaryClipListeners.getBroadcastItem(i).dispatchPrimaryClipChanged();
+ } catch (RemoteException e) {
+
+ // The RemoteCallbackList will take care of removing
+ // the dead object for us.
+ }
+ }
+ mPrimaryClipListeners.finishBroadcast();
+ }
+ }
- mClipboard = text;
- }
- }
-
- // javadoc from interface
- public CharSequence getClipboardText() {
+ public ClippedData getPrimaryClip() {
synchronized (this) {
- return mClipboard;
+ return mPrimaryClip;
}
}
- // javadoc from interface
+ public boolean hasPrimaryClip() {
+ synchronized (this) {
+ return mPrimaryClip != null;
+ }
+ }
+
+ public void addPrimaryClipChangedListener(IOnPrimaryClipChangedListener listener) {
+ synchronized (this) {
+ mPrimaryClipListeners.register(listener);
+ }
+ }
+
+ public void removePrimaryClipChangedListener(IOnPrimaryClipChangedListener listener) {
+ synchronized (this) {
+ mPrimaryClipListeners.unregister(listener);
+ }
+ }
+
public boolean hasClipboardText() {
synchronized (this) {
- return mClipboard.length() > 0;
+ if (mPrimaryClip != null) {
+ CharSequence text = mPrimaryClip.getItem(0).getText();
+ return text != null && text.length() > 0;
+ }
+ return false;
}
}
}
diff --git a/services/java/com/android/server/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java
index 4f11231..67796c6 100755
--- a/services/java/com/android/server/NotificationManagerService.java
+++ b/services/java/com/android/server/NotificationManagerService.java
@@ -68,7 +68,8 @@
import java.util.ArrayList;
import java.util.Arrays;
-class NotificationManagerService extends INotificationManager.Stub
+/** {@hide} */
+public class NotificationManagerService extends INotificationManager.Stub
{
private static final String TAG = "NotificationService";
private static final boolean DBG = false;
@@ -316,7 +317,8 @@
public void onNotificationError(String pkg, String tag, int id,
int uid, int initialPid, String message) {
- Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id);
+ Slog.d(TAG, "onNotification error pkg=" + pkg + " tag=" + tag + " id=" + id
+ + "; will crashApplication(uid=" + uid + ", pid=" + initialPid + ")");
cancelNotification(pkg, tag, id, 0, 0);
long ident = Binder.clearCallingIdentity();
try {
@@ -671,11 +673,20 @@
enqueueNotificationWithTag(pkg, null /* tag */, id, notification, idOut);
}
- public void enqueueNotificationWithTag(String pkg, String tag, int id,
- Notification notification, int[] idOut)
+ public void enqueueNotificationWithTag(String pkg, String tag, int id, Notification notification,
+ int[] idOut)
{
- final int callingUid = Binder.getCallingUid();
- final int callingPid = Binder.getCallingPid();
+ enqueueNotificationInternal(pkg, Binder.getCallingUid(), Binder.getCallingPid(),
+ tag, id, notification, idOut);
+ }
+
+ // Not exposed via Binder; for system use only (otherwise malicious apps could spoof the
+ // uid/pid of another application)
+ public void enqueueNotificationInternal(String pkg, int callingUid, int callingPid,
+ String tag, int id, Notification notification, int[] idOut)
+ {
+ Slog.d(TAG, "enqueueNotificationWithTag: calling uid=" + callingUid
+ + ", pid=" + callingPid);
checkIncomingCall(pkg);
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 415073e..a32cd4c 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -2359,6 +2359,10 @@
}
if (proc.thread != null) {
+ if (proc.pid == Process.myPid()) {
+ Log.w(TAG, "crashApplication: trying to crash self!");
+ return;
+ }
long ident = Binder.clearCallingIdentity();
try {
proc.thread.scheduleCrash(message);
diff --git a/services/java/com/android/server/am/ServiceRecord.java b/services/java/com/android/server/am/ServiceRecord.java
index 0542497..75365ad 100644
--- a/services/java/com/android/server/am/ServiceRecord.java
+++ b/services/java/com/android/server/am/ServiceRecord.java
@@ -17,6 +17,7 @@
package com.android.server.am;
import com.android.internal.os.BatteryStatsImpl;
+import com.android.server.NotificationManagerService;
import android.app.INotificationManager;
import android.app.Notification;
@@ -252,6 +253,8 @@
}
public void postNotification() {
+ final int appUid = appInfo.uid;
+ final int appPid = app.pid;
if (foregroundId != 0 && foregroundNoti != null) {
// Do asynchronous communication with notification manager to
// avoid deadlocks.
@@ -260,14 +263,15 @@
final Notification localForegroundNoti = foregroundNoti;
ams.mHandler.post(new Runnable() {
public void run() {
- INotificationManager inm = NotificationManager.getService();
- if (inm == null) {
+ NotificationManagerService nm =
+ (NotificationManagerService) NotificationManager.getService();
+ if (nm == null) {
return;
}
try {
int[] outId = new int[1];
- inm.enqueueNotification(localPackageName, localForegroundId,
- localForegroundNoti, outId);
+ nm.enqueueNotificationInternal(localPackageName, appUid, appPid,
+ null, localForegroundId, localForegroundNoti, outId);
} catch (RuntimeException e) {
Slog.w(ActivityManagerService.TAG,
"Error showing notification for service", e);
@@ -275,7 +279,6 @@
// get to be foreground.
ams.setServiceForeground(name, ServiceRecord.this,
localForegroundId, null, true);
- } catch (RemoteException e) {
}
}
});
diff --git a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
index f4773b5..8c7254c 100644
--- a/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
+++ b/tests/DumpRenderTree/src/com/android/dumprendertree/TestShellActivity.java
@@ -754,7 +754,7 @@
private static class NewWindowWebView extends WebView {
public NewWindowWebView(Context context, Map<String, Object> jsIfaces) {
- super(context, null, 0, jsIfaces);
+ super(context, null, 0, jsIfaces, false);
}
}
diff --git a/voip/java/android/net/rtp/AudioCodec.java b/voip/java/android/net/rtp/AudioCodec.java
new file mode 100644
index 0000000..89e6aa9
--- /dev/null
+++ b/voip/java/android/net/rtp/AudioCodec.java
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+package android.net.rtp;
+
+/** @hide */
+public class AudioCodec {
+ public static final AudioCodec ULAW = new AudioCodec("PCMU", 8000, 160, 0);
+ public static final AudioCodec ALAW = new AudioCodec("PCMA", 8000, 160, 8);
+
+ /**
+ * Returns system supported codecs.
+ */
+ public static AudioCodec[] getSystemSupportedCodecs() {
+ return new AudioCodec[] {AudioCodec.ULAW, AudioCodec.ALAW};
+ }
+
+ /**
+ * Returns the codec instance if it is supported by the system.
+ *
+ * @param name name of the codec
+ * @return the matched codec or null if the codec name is not supported by
+ * the system
+ */
+ public static AudioCodec getSystemSupportedCodec(String name) {
+ for (AudioCodec codec : getSystemSupportedCodecs()) {
+ if (codec.name.equals(name)) return codec;
+ }
+ return null;
+ }
+
+ public final String name;
+ public final int sampleRate;
+ public final int sampleCount;
+ public final int defaultType;
+
+ private AudioCodec(String name, int sampleRate, int sampleCount, int defaultType) {
+ this.name = name;
+ this.sampleRate = sampleRate;
+ this.sampleCount = sampleCount;
+ this.defaultType = defaultType;
+ }
+}
diff --git a/voip/java/android/net/rtp/AudioGroup.java b/voip/java/android/net/rtp/AudioGroup.java
new file mode 100644
index 0000000..dc86082
--- /dev/null
+++ b/voip/java/android/net/rtp/AudioGroup.java
@@ -0,0 +1,91 @@
+/*
+ * 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.
+ */
+
+package android.net.rtp;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ */
+/** @hide */
+public class AudioGroup {
+ public static final int MODE_ON_HOLD = 0;
+ public static final int MODE_MUTED = 1;
+ public static final int MODE_NORMAL = 2;
+ public static final int MODE_EC_ENABLED = 3;
+
+ private final Map<AudioStream, Integer> mStreams;
+ private int mMode = MODE_ON_HOLD;
+
+ private int mNative;
+ static {
+ System.loadLibrary("rtp_jni");
+ }
+
+ public AudioGroup() {
+ mStreams = new HashMap<AudioStream, Integer>();
+ }
+
+ public int getMode() {
+ return mMode;
+ }
+
+ public synchronized native void setMode(int mode);
+
+ synchronized void add(AudioStream stream, AudioCodec codec, int codecType, int dtmfType) {
+ if (!mStreams.containsKey(stream)) {
+ try {
+ int id = add(stream.getMode(), stream.dup(),
+ stream.getRemoteAddress().getHostAddress(), stream.getRemotePort(),
+ codec.name, codec.sampleRate, codec.sampleCount, codecType, dtmfType);
+ mStreams.put(stream, id);
+ } catch (NullPointerException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ private native int add(int mode, int socket, String remoteAddress, int remotePort,
+ String codecName, int sampleRate, int sampleCount, int codecType, int dtmfType);
+
+ synchronized void remove(AudioStream stream) {
+ Integer id = mStreams.remove(stream);
+ if (id != null) {
+ remove(id);
+ }
+ }
+
+ private native void remove(int id);
+
+ /**
+ * Sends a DTMF digit to every {@link AudioStream} in this group. Currently
+ * only event {@code 0} to {@code 15} are supported.
+ *
+ * @throws IllegalArgumentException if the event is invalid.
+ */
+ public native synchronized void sendDtmf(int event);
+
+ public synchronized void reset() {
+ remove(-1);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ reset();
+ super.finalize();
+ }
+}
diff --git a/voip/java/android/net/rtp/AudioStream.java b/voip/java/android/net/rtp/AudioStream.java
new file mode 100644
index 0000000..a955fd2
--- /dev/null
+++ b/voip/java/android/net/rtp/AudioStream.java
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
+
+package android.net.rtp;
+
+import java.net.InetAddress;
+import java.net.SocketException;
+
+/**
+ * AudioStream represents a RTP stream carrying audio payloads.
+ */
+/** @hide */
+public class AudioStream extends RtpStream {
+ private AudioCodec mCodec;
+ private int mCodecType = -1;
+ private int mDtmfType = -1;
+ private AudioGroup mGroup;
+
+ /**
+ * Creates an AudioStream on the given local address. Note that the local
+ * port is assigned automatically to conform with RFC 3550.
+ *
+ * @param address The network address of the local host to bind to.
+ * @throws SocketException if the address cannot be bound or a problem
+ * occurs during binding.
+ */
+ public AudioStream(InetAddress address) throws SocketException {
+ super(address);
+ }
+
+ /**
+ * Returns {@code true} if the stream already joined an {@link AudioGroup}.
+ */
+ @Override
+ public final boolean isBusy() {
+ return mGroup != null;
+ }
+
+ /**
+ * Returns the joined {@link AudioGroup}.
+ */
+ public AudioGroup getAudioGroup() {
+ return mGroup;
+ }
+
+ /**
+ * Joins an {@link AudioGroup}. Each stream can join only one group at a
+ * time. The group can be changed by passing a different one or removed
+ * by calling this method with {@code null}.
+ *
+ * @param group The AudioGroup to join or {@code null} to leave.
+ * @throws IllegalStateException if the stream is not properly configured.
+ * @see AudioGroup
+ */
+ public void join(AudioGroup group) {
+ if (mGroup == group) {
+ return;
+ }
+ if (mGroup != null) {
+ mGroup.remove(this);
+ mGroup = null;
+ }
+ if (group != null) {
+ group.add(this, mCodec, mCodecType, mDtmfType);
+ mGroup = group;
+ }
+ }
+
+ /**
+ * Sets the {@link AudioCodec} and its RTP payload type. According to RFC
+ * 3551, the type must be in the range of 0 and 127, where 96 and above are
+ * dynamic types. For codecs with static mappings (non-negative
+ * {@link AudioCodec#defaultType}), assigning a different non-dynamic type
+ * is disallowed.
+ *
+ * @param codec The AudioCodec to be used.
+ * @param type The RTP payload type.
+ * @throws IllegalArgumentException if the type is invalid or used by DTMF.
+ * @throws IllegalStateException if the stream is busy.
+ */
+ public void setCodec(AudioCodec codec, int type) {
+ if (isBusy()) {
+ throw new IllegalStateException("Busy");
+ }
+ if (type < 0 || type > 127 || (type != codec.defaultType && type < 96)) {
+ throw new IllegalArgumentException("Invalid type");
+ }
+ if (type == mDtmfType) {
+ throw new IllegalArgumentException("The type is used by DTMF");
+ }
+ mCodec = codec;
+ mCodecType = type;
+ }
+
+ /**
+ * Sets the RTP payload type for dual-tone multi-frequency (DTMF) digits.
+ * The primary usage is to send digits to the remote gateway to perform
+ * certain tasks, such as second-stage dialing. According to RFC 2833, the
+ * RTP payload type for DTMF is assigned dynamically, so it must be in the
+ * range of 96 and 127. One can use {@code -1} to disable DTMF and free up
+ * the previous assigned value. This method cannot be called when the stream
+ * already joined an {@link AudioGroup}.
+ *
+ * @param type The RTP payload type to be used or {@code -1} to disable it.
+ * @throws IllegalArgumentException if the type is invalid or used by codec.
+ * @throws IllegalStateException if the stream is busy.
+ * @see AudioGroup#sendDtmf(int)
+ */
+ public void setDtmfType(int type) {
+ if (isBusy()) {
+ throw new IllegalStateException("Busy");
+ }
+ if (type != -1) {
+ if (type < 96 || type > 127) {
+ throw new IllegalArgumentException("Invalid type");
+ }
+ if (type == mCodecType) {
+ throw new IllegalArgumentException("The type is used by codec");
+ }
+ }
+ mDtmfType = type;
+ }
+}
diff --git a/voip/java/android/net/rtp/RtpStream.java b/voip/java/android/net/rtp/RtpStream.java
new file mode 100644
index 0000000..ef5ca17
--- /dev/null
+++ b/voip/java/android/net/rtp/RtpStream.java
@@ -0,0 +1,173 @@
+/*
+ * 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.
+ */
+
+package android.net.rtp;
+
+import java.net.InetAddress;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.SocketException;
+
+/**
+ * RtpStream represents a base class of media streams running over
+ * Real-time Transport Protocol (RTP).
+ */
+/** @hide */
+public class RtpStream {
+ public static final int MODE_NORMAL = 0;
+ public static final int MODE_SEND_ONLY = 1;
+ public static final int MODE_RECEIVE_ONLY = 2;
+
+ private final InetAddress mLocalAddress;
+ private final int mLocalPort;
+
+ private InetAddress mRemoteAddress;
+ private int mRemotePort = -1;
+ private int mMode = MODE_NORMAL;
+
+ private int mNative;
+ static {
+ System.loadLibrary("rtp_jni");
+ }
+
+ /**
+ * Creates a RtpStream on the given local address. Note that the local
+ * port is assigned automatically to conform with RFC 3550.
+ *
+ * @param address The network address of the local host to bind to.
+ * @throws SocketException if the address cannot be bound or a problem
+ * occurs during binding.
+ */
+ RtpStream(InetAddress address) throws SocketException {
+ mLocalPort = create(address.getHostAddress());
+ mLocalAddress = address;
+ }
+
+ private native int create(String address) throws SocketException;
+
+ /**
+ * Returns the network address of the local host.
+ */
+ public InetAddress getLocalAddress() {
+ return mLocalAddress;
+ }
+
+ /**
+ * Returns the network port of the local host.
+ */
+ public int getLocalPort() {
+ return mLocalPort;
+ }
+
+ /**
+ * Returns the network address of the remote host or {@code null} if the
+ * stream is not associated.
+ */
+ public InetAddress getRemoteAddress() {
+ return mRemoteAddress;
+ }
+
+ /**
+ * Returns the network port of the remote host or {@code -1} if the stream
+ * is not associated.
+ */
+ public int getRemotePort() {
+ return mRemotePort;
+ }
+
+ /**
+ * Returns {@code true} if the stream is busy. This method is intended to be
+ * overridden by subclasses.
+ */
+ public boolean isBusy() {
+ return false;
+ }
+
+ /**
+ * Returns the current mode. The initial mode is {@link #MODE_NORMAL}.
+ */
+ public int getMode() {
+ return mMode;
+ }
+
+ /**
+ * Changes the current mode. It must be one of {@link #MODE_NORMAL},
+ * {@link #MODE_SEND_ONLY}, and {@link #MODE_RECEIVE_ONLY}.
+ *
+ * @param mode The mode to change to.
+ * @throws IllegalArgumentException if the mode is invalid.
+ * @throws IllegalStateException if the stream is busy.
+ * @see #isBusy()
+ */
+ public void setMode(int mode) {
+ if (isBusy()) {
+ throw new IllegalStateException("Busy");
+ }
+ if (mode != MODE_NORMAL && mode != MODE_SEND_ONLY && mode != MODE_RECEIVE_ONLY) {
+ throw new IllegalArgumentException("Invalid mode");
+ }
+ mMode = mode;
+ }
+
+ /**
+ * Associates with a remote host.
+ *
+ * @param address The network address of the remote host.
+ * @param port The network port of the remote host.
+ * @throws IllegalArgumentException if the address is not supported or the
+ * port is invalid.
+ * @throws IllegalStateException if the stream is busy.
+ * @see #isBusy()
+ */
+ public void associate(InetAddress address, int port) {
+ if (isBusy()) {
+ throw new IllegalStateException("Busy");
+ }
+ if (!(address instanceof Inet4Address && mLocalAddress instanceof Inet4Address) &&
+ !(address instanceof Inet6Address && mLocalAddress instanceof Inet6Address)) {
+ throw new IllegalArgumentException("Unsupported address");
+ }
+ if (port < 0 || port > 65535) {
+ throw new IllegalArgumentException("Invalid port");
+ }
+ mRemoteAddress = address;
+ mRemotePort = port;
+ }
+
+ synchronized native int dup();
+
+ /**
+ * Releases allocated resources. The stream becomes inoperable after calling
+ * this method.
+ *
+ * @throws IllegalStateException if the stream is busy.
+ * @see #isBusy()
+ */
+ public void release() {
+ if (isBusy()) {
+ throw new IllegalStateException("Busy");
+ }
+ close();
+ }
+
+ private synchronized native void close();
+
+ @Override
+ protected void finalize() throws Throwable {
+ close();
+ super.finalize();
+ }
+}
diff --git a/voip/java/android/net/sip/BinderHelper.java b/voip/java/android/net/sip/BinderHelper.java
new file mode 100644
index 0000000..bd3da32
--- /dev/null
+++ b/voip/java/android/net/sip/BinderHelper.java
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.ConditionVariable;
+import android.os.IBinder;
+import android.os.IInterface;
+import android.os.Looper;
+import android.util.Log;
+
+// TODO: throw away this class after moving SIP classes to framework
+// This class helps to get IBinder instance of a service in a blocking call.
+// The method cannot be called in app's main thread as the ServiceConnection
+// callback will.
+class BinderHelper<T extends IInterface> {
+ private Context mContext;
+ private IBinder mBinder;
+ private Class<T> mClass;
+
+ BinderHelper(Context context, Class<T> klass) {
+ mContext = context;
+ mClass = klass;
+ }
+
+ void startService() {
+ mContext.startService(new Intent(mClass.getName()));
+ }
+
+ void stopService() {
+ mContext.stopService(new Intent(mClass.getName()));
+ }
+
+ IBinder getBinder() {
+ // cannot call this method in app's main thread
+ if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
+ throw new RuntimeException(
+ "This method cannot be called in app's main thread");
+ }
+
+ final ConditionVariable cv = new ConditionVariable();
+ cv.close();
+ ServiceConnection c = new ServiceConnection() {
+ public synchronized void onServiceConnected(
+ ComponentName className, IBinder binder) {
+ Log.v("BinderHelper", "service connected!");
+ mBinder = binder;
+ cv.open();
+ mContext.unbindService(this);
+ }
+
+ public void onServiceDisconnected(ComponentName className) {
+ cv.open();
+ mContext.unbindService(this);
+ }
+ };
+ if (mContext.bindService(new Intent(mClass.getName()), c, 0)) {
+ cv.block(4500);
+ }
+ return mBinder;
+ }
+}
diff --git a/voip/java/android/net/sip/ISipService.aidl b/voip/java/android/net/sip/ISipService.aidl
new file mode 100644
index 0000000..6c68213
--- /dev/null
+++ b/voip/java/android/net/sip/ISipService.aidl
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import android.net.sip.ISipSession;
+import android.net.sip.ISipSessionListener;
+import android.net.sip.SipProfile;
+
+/**
+ * {@hide}
+ */
+interface ISipService {
+ void open(in SipProfile localProfile);
+ void open3(in SipProfile localProfile,
+ String incomingCallBroadcastAction,
+ in ISipSessionListener listener);
+ void close(in String localProfileUri);
+ boolean isOpened(String localProfileUri);
+ boolean isRegistered(String localProfileUri);
+ void setRegistrationListener(String localProfileUri,
+ ISipSessionListener listener);
+
+ ISipSession createSession(in SipProfile localProfile,
+ in ISipSessionListener listener);
+ ISipSession getPendingSession(String callId);
+
+ SipProfile[] getListOfProfiles();
+}
diff --git a/voip/java/android/net/sip/ISipSession.aidl b/voip/java/android/net/sip/ISipSession.aidl
new file mode 100644
index 0000000..fbcb056
--- /dev/null
+++ b/voip/java/android/net/sip/ISipSession.aidl
@@ -0,0 +1,147 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import android.net.sip.ISipSessionListener;
+import android.net.sip.SessionDescription;
+import android.net.sip.SipProfile;
+
+/**
+ * A SIP session that is associated with a SIP dialog or a transaction
+ * (e.g., registration) not within a dialog.
+ * @hide
+ */
+interface ISipSession {
+ /**
+ * Gets the IP address of the local host on which this SIP session runs.
+ *
+ * @return the IP address of the local host
+ */
+ String getLocalIp();
+
+ /**
+ * Gets the SIP profile that this session is associated with.
+ *
+ * @return the SIP profile that this session is associated with
+ */
+ SipProfile getLocalProfile();
+
+ /**
+ * Gets the SIP profile that this session is connected to. Only available
+ * when the session is associated with a SIP dialog.
+ *
+ * @return the SIP profile that this session is connected to
+ */
+ SipProfile getPeerProfile();
+
+ /**
+ * Gets the session state. The value returned must be one of the states in
+ * {@link SipSessionState}. One may convert it to {@link SipSessionState} by
+ * <code>
+ * Enum.valueOf(SipSessionState.class, session.getState());
+ * </code>
+ *
+ * @return the session state
+ */
+ String getState();
+
+ /**
+ * Checks if the session is in a call.
+ *
+ * @return true if the session is in a call
+ */
+ boolean isInCall();
+
+ /**
+ * Gets the call ID of the session.
+ *
+ * @return the call ID
+ */
+ String getCallId();
+
+
+ /**
+ * Sets the listener to listen to the session events. A {@link ISipSession}
+ * can only hold one listener at a time. Subsequent calls to this method
+ * override the previous listener.
+ *
+ * @param listener to listen to the session events of this object
+ */
+ void setListener(in ISipSessionListener listener);
+
+
+ /**
+ * Performs registration to the server specified by the associated local
+ * profile. The session listener is called back upon success or failure of
+ * registration. The method is only valid to call when the session state is
+ * in {@link SipSessionState#READY_TO_CALL}.
+ *
+ * @param duration duration in second before the registration expires
+ * @see ISipSessionListener
+ */
+ void register(int duration);
+
+ /**
+ * Performs unregistration to the server specified by the associated local
+ * profile. Unregistration is technically the same as registration with zero
+ * expiration duration. The session listener is called back upon success or
+ * failure of unregistration. The method is only valid to call when the
+ * session state is in {@link SipSessionState#READY_TO_CALL}.
+ *
+ * @see ISipSessionListener
+ */
+ void unregister();
+
+ /**
+ * Initiates a call to the specified profile. The session listener is called
+ * back upon defined session events. The method is only valid to call when
+ * the session state is in {@link SipSessionState#READY_TO_CALL}.
+ *
+ * @param callee the SIP profile to make the call to
+ * @param sessionDescription the session description of this call
+ * @see ISipSessionListener
+ */
+ void makeCall(in SipProfile callee,
+ in SessionDescription sessionDescription);
+
+ /**
+ * Answers an incoming call with the specified session description. The
+ * method is only valid to call when the session state is in
+ * {@link SipSessionState#INCOMING_CALL}.
+ *
+ * @param sessionDescription the session description to answer this call
+ */
+ void answerCall(in SessionDescription sessionDescription);
+
+ /**
+ * Ends an established call, terminates an outgoing call or rejects an
+ * incoming call. The method is only valid to call when the session state is
+ * in {@link SipSessionState#IN_CALL},
+ * {@link SipSessionState#INCOMING_CALL},
+ * {@link SipSessionState#OUTGOING_CALL} or
+ * {@link SipSessionState#OUTGOING_CALL_RING_BACK}.
+ */
+ void endCall();
+
+ /**
+ * Changes the session description during a call. The method is only valid
+ * to call when the session state is in {@link SipSessionState#IN_CALL}.
+ *
+ * @param sessionDescription the new session description
+ */
+ void changeCall(in SessionDescription sessionDescription);
+}
diff --git a/voip/java/android/net/sip/ISipSessionListener.aidl b/voip/java/android/net/sip/ISipSessionListener.aidl
new file mode 100644
index 0000000..8570958
--- /dev/null
+++ b/voip/java/android/net/sip/ISipSessionListener.aidl
@@ -0,0 +1,126 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import android.net.sip.ISipSession;
+import android.net.sip.SipProfile;
+
+/**
+ * Listener class to listen to SIP session events.
+ * @hide
+ */
+interface ISipSessionListener {
+ /**
+ * Called when an INVITE request is sent to initiate a new call.
+ *
+ * @param session the session object that carries out the transaction
+ */
+ void onCalling(in ISipSession session);
+
+ /**
+ * Called when an INVITE request is received.
+ *
+ * @param session the session object that carries out the transaction
+ * @param caller the SIP profile of the caller
+ * @param sessionDescription the caller's session description
+ */
+ void onRinging(in ISipSession session, in SipProfile caller,
+ in byte[] sessionDescription);
+
+ /**
+ * Called when a RINGING response is received for the INVITE request sent
+ *
+ * @param session the session object that carries out the transaction
+ */
+ void onRingingBack(in ISipSession session);
+
+ /**
+ * Called when the session is established.
+ *
+ * @param session the session object that is associated with the dialog
+ * @param sessionDescription the peer's session description
+ */
+ void onCallEstablished(in ISipSession session,
+ in byte[] sessionDescription);
+
+ /**
+ * Called when the session is terminated.
+ *
+ * @param session the session object that is associated with the dialog
+ */
+ void onCallEnded(in ISipSession session);
+
+ /**
+ * Called when the peer is busy during session initialization.
+ *
+ * @param session the session object that carries out the transaction
+ */
+ void onCallBusy(in ISipSession session);
+
+ /**
+ * Called when an error occurs during session initialization and
+ * termination.
+ *
+ * @param session the session object that carries out the transaction
+ * @param errorClass name of the exception class
+ * @param errorMessage error message
+ */
+ void onError(in ISipSession session, String errorClass,
+ String errorMessage);
+
+ /**
+ * Called when an error occurs during session modification negotiation.
+ *
+ * @param session the session object that carries out the transaction
+ * @param errorClass name of the exception class
+ * @param errorMessage error message
+ */
+ void onCallChangeFailed(in ISipSession session, String errorClass,
+ String errorMessage);
+
+ /**
+ * Called when a registration request is sent.
+ *
+ * @param session the session object that carries out the transaction
+ */
+ void onRegistering(in ISipSession session);
+
+ /**
+ * Called when registration is successfully done.
+ *
+ * @param session the session object that carries out the transaction
+ * @param duration duration in second before the registration expires
+ */
+ void onRegistrationDone(in ISipSession session, int duration);
+
+ /**
+ * Called when the registration fails.
+ *
+ * @param session the session object that carries out the transaction
+ * @param errorClass name of the exception class
+ * @param errorMessage error message
+ */
+ void onRegistrationFailed(in ISipSession session, String errorClass,
+ String errorMessage);
+
+ /**
+ * Called when the registration gets timed out.
+ *
+ * @param session the session object that carries out the transaction
+ */
+ void onRegistrationTimeout(in ISipSession session);
+}
diff --git a/voip/java/android/net/sip/SdpSessionDescription.java b/voip/java/android/net/sip/SdpSessionDescription.java
new file mode 100644
index 0000000..0c29935
--- /dev/null
+++ b/voip/java/android/net/sip/SdpSessionDescription.java
@@ -0,0 +1,428 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import gov.nist.javax.sdp.SessionDescriptionImpl;
+import gov.nist.javax.sdp.fields.AttributeField;
+import gov.nist.javax.sdp.fields.ConnectionField;
+import gov.nist.javax.sdp.fields.MediaField;
+import gov.nist.javax.sdp.fields.OriginField;
+import gov.nist.javax.sdp.fields.ProtoVersionField;
+import gov.nist.javax.sdp.fields.SessionNameField;
+import gov.nist.javax.sdp.fields.TimeField;
+import gov.nist.javax.sdp.parser.SDPAnnounceParser;
+
+import android.util.Log;
+
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Vector;
+import javax.sdp.Connection;
+import javax.sdp.MediaDescription;
+import javax.sdp.SdpException;
+
+/**
+ * A session description that follows SDP (Session Description Protocol).
+ * Refer to <a href="http://tools.ietf.org/html/rfc4566">RFC 4566</a>.
+ * @hide
+ */
+public class SdpSessionDescription extends SessionDescription {
+ private static final String TAG = "SDP";
+ private static final String AUDIO = "audio";
+ private static final String RTPMAP = "rtpmap";
+ private static final String PTIME = "ptime";
+ private static final String SENDONLY = "sendonly";
+ private static final String RECVONLY = "recvonly";
+ private static final String INACTIVE = "inactive";
+
+ private SessionDescriptionImpl mSessionDescription;
+
+ /**
+ * The audio codec information parsed from "rtpmap".
+ */
+ public static class AudioCodec {
+ public final int payloadType;
+ public final String name;
+ public final int sampleRate;
+ public final int sampleCount;
+
+ public AudioCodec(int payloadType, String name, int sampleRate,
+ int sampleCount) {
+ this.payloadType = payloadType;
+ this.name = name;
+ this.sampleRate = sampleRate;
+ this.sampleCount = sampleCount;
+ }
+ }
+
+ /**
+ * The builder class used to create an {@link SdpSessionDescription} object.
+ */
+ public static class Builder {
+ private SdpSessionDescription mSdp = new SdpSessionDescription();
+ private SessionDescriptionImpl mSessionDescription;
+
+ public Builder(String sessionName) throws SdpException {
+ mSessionDescription = new SessionDescriptionImpl();
+ mSdp.mSessionDescription = mSessionDescription;
+ try {
+ ProtoVersionField proto = new ProtoVersionField();
+ proto.setVersion(0);
+ mSessionDescription.addField(proto);
+
+ TimeField time = new TimeField();
+ time.setZero();
+ mSessionDescription.addField(time);
+
+ SessionNameField session = new SessionNameField();
+ session.setValue(sessionName);
+ mSessionDescription.addField(session);
+ } catch (Exception e) {
+ throwSdpException(e);
+ }
+ }
+
+ public Builder setConnectionInfo(String networkType, String addressType,
+ String addr) throws SdpException {
+ try {
+ ConnectionField connection = new ConnectionField();
+ connection.setNetworkType(networkType);
+ connection.setAddressType(addressType);
+ connection.setAddress(addr);
+ mSessionDescription.addField(connection);
+ } catch (Exception e) {
+ throwSdpException(e);
+ }
+ return this;
+ }
+
+ public Builder setOrigin(SipProfile user, long sessionId,
+ long sessionVersion, String networkType, String addressType,
+ String address) throws SdpException {
+ try {
+ OriginField origin = new OriginField();
+ origin.setUsername(user.getUserName());
+ origin.setSessionId(sessionId);
+ origin.setSessionVersion(sessionVersion);
+ origin.setAddressType(addressType);
+ origin.setNetworkType(networkType);
+ origin.setAddress(address);
+ mSessionDescription.addField(origin);
+ } catch (Exception e) {
+ throwSdpException(e);
+ }
+ return this;
+ }
+
+ public Builder addMedia(String media, int port, int numPorts,
+ String transport, Integer... types) throws SdpException {
+ MediaField field = new MediaField();
+ Vector<Integer> typeVector = new Vector<Integer>();
+ Collections.addAll(typeVector, types);
+ try {
+ field.setMediaType(media);
+ field.setMediaPort(port);
+ field.setPortCount(numPorts);
+ field.setProtocol(transport);
+ field.setMediaFormats(typeVector);
+ mSessionDescription.addField(field);
+ } catch (Exception e) {
+ throwSdpException(e);
+ }
+ return this;
+ }
+
+ public Builder addMediaAttribute(String type, String name, String value)
+ throws SdpException {
+ try {
+ MediaDescription md = mSdp.getMediaDescription(type);
+ if (md == null) {
+ throw new SdpException("Should add media first!");
+ }
+ AttributeField attribute = new AttributeField();
+ attribute.setName(name);
+ attribute.setValueAllowNull(value);
+ mSessionDescription.addField(attribute);
+ } catch (Exception e) {
+ throwSdpException(e);
+ }
+ return this;
+ }
+
+ public Builder addSessionAttribute(String name, String value)
+ throws SdpException {
+ try {
+ AttributeField attribute = new AttributeField();
+ attribute.setName(name);
+ attribute.setValueAllowNull(value);
+ mSessionDescription.addField(attribute);
+ } catch (Exception e) {
+ throwSdpException(e);
+ }
+ return this;
+ }
+
+ private void throwSdpException(Exception e) throws SdpException {
+ if (e instanceof SdpException) {
+ throw (SdpException) e;
+ } else {
+ throw new SdpException(e.toString(), e);
+ }
+ }
+
+ public SdpSessionDescription build() {
+ return mSdp;
+ }
+ }
+
+ private SdpSessionDescription() {
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param sdpString an SDP session description to parse
+ */
+ public SdpSessionDescription(String sdpString) throws SdpException {
+ try {
+ mSessionDescription = new SDPAnnounceParser(sdpString).parse();
+ } catch (ParseException e) {
+ throw new SdpException(e.toString(), e);
+ }
+ verify();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param content a raw SDP session description to parse
+ */
+ public SdpSessionDescription(byte[] content) throws SdpException {
+ this(new String(content));
+ }
+
+ private void verify() throws SdpException {
+ // make sure the syntax is correct over the fields we're interested in
+ Vector<MediaDescription> descriptions = (Vector<MediaDescription>)
+ mSessionDescription.getMediaDescriptions(false);
+ for (MediaDescription md : descriptions) {
+ md.getMedia().getMediaPort();
+ Connection connection = md.getConnection();
+ if (connection != null) connection.getAddress();
+ md.getMedia().getFormats();
+ }
+ Connection connection = mSessionDescription.getConnection();
+ if (connection != null) connection.getAddress();
+ }
+
+ /**
+ * Gets the connection address of the media.
+ *
+ * @param type the media type; e.g., "AUDIO"
+ * @return the media connection address of the peer
+ */
+ public String getPeerMediaAddress(String type) {
+ try {
+ MediaDescription md = getMediaDescription(type);
+ Connection connection = md.getConnection();
+ if (connection == null) {
+ connection = mSessionDescription.getConnection();
+ }
+ return ((connection == null) ? null : connection.getAddress());
+ } catch (SdpException e) {
+ // should not occur
+ return null;
+ }
+ }
+
+ /**
+ * Gets the connection port number of the media.
+ *
+ * @param type the media type; e.g., "AUDIO"
+ * @return the media connection port number of the peer
+ */
+ public int getPeerMediaPort(String type) {
+ try {
+ MediaDescription md = getMediaDescription(type);
+ return md.getMedia().getMediaPort();
+ } catch (SdpException e) {
+ // should not occur
+ return -1;
+ }
+ }
+
+ private boolean containsAttribute(String type, String name) {
+ if (name == null) return false;
+ MediaDescription md = getMediaDescription(type);
+ Vector<AttributeField> v = (Vector<AttributeField>)
+ md.getAttributeFields();
+ for (AttributeField field : v) {
+ if (name.equals(field.getAttribute().getName())) return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks if the media is "sendonly".
+ *
+ * @param type the media type; e.g., "AUDIO"
+ * @return true if the media is "sendonly"
+ */
+ public boolean isSendOnly(String type) {
+ boolean answer = containsAttribute(type, SENDONLY);
+ Log.d(TAG, " sendonly? " + answer);
+ return answer;
+ }
+
+ /**
+ * Checks if the media is "recvonly".
+ *
+ * @param type the media type; e.g., "AUDIO"
+ * @return true if the media is "recvonly"
+ */
+ public boolean isReceiveOnly(String type) {
+ boolean answer = containsAttribute(type, RECVONLY);
+ Log.d(TAG, " recvonly? " + answer);
+ return answer;
+ }
+
+ /**
+ * Checks if the media is in sending; i.e., not "recvonly" and not
+ * "inactive".
+ *
+ * @param type the media type; e.g., "AUDIO"
+ * @return true if the media is sending
+ */
+ public boolean isSending(String type) {
+ boolean answer = !containsAttribute(type, RECVONLY)
+ && !containsAttribute(type, INACTIVE);
+
+ Log.d(TAG, " sending? " + answer);
+ return answer;
+ }
+
+ /**
+ * Checks if the media is in receiving; i.e., not "sendonly" and not
+ * "inactive".
+ *
+ * @param type the media type; e.g., "AUDIO"
+ * @return true if the media is receiving
+ */
+ public boolean isReceiving(String type) {
+ boolean answer = !containsAttribute(type, SENDONLY)
+ && !containsAttribute(type, INACTIVE);
+ Log.d(TAG, " receiving? " + answer);
+ return answer;
+ }
+
+ private AudioCodec parseAudioCodec(String rtpmap, int ptime) {
+ String[] ss = rtpmap.split(" ");
+ int payloadType = Integer.parseInt(ss[0]);
+
+ ss = ss[1].split("/");
+ String name = ss[0];
+ int sampleRate = Integer.parseInt(ss[1]);
+ int channelCount = 1;
+ if (ss.length > 2) channelCount = Integer.parseInt(ss[2]);
+ int sampleCount = sampleRate / (1000 / ptime) * channelCount;
+ return new AudioCodec(payloadType, name, sampleRate, sampleCount);
+ }
+
+ /**
+ * Gets the list of audio codecs in this session description.
+ *
+ * @return the list of audio codecs in this session description
+ */
+ public List<AudioCodec> getAudioCodecs() {
+ MediaDescription md = getMediaDescription(AUDIO);
+ if (md == null) return new ArrayList<AudioCodec>();
+
+ // FIXME: what happens if ptime is missing
+ int ptime = 20;
+ try {
+ String value = md.getAttribute(PTIME);
+ if (value != null) ptime = Integer.parseInt(value);
+ } catch (Throwable t) {
+ Log.w(TAG, "getCodecs(): ignored: " + t);
+ }
+
+ List<AudioCodec> codecs = new ArrayList<AudioCodec>();
+ Vector<AttributeField> v = (Vector<AttributeField>)
+ md.getAttributeFields();
+ for (AttributeField field : v) {
+ try {
+ if (RTPMAP.equals(field.getName())) {
+ AudioCodec codec = parseAudioCodec(field.getValue(), ptime);
+ if (codec != null) codecs.add(codec);
+ }
+ } catch (Throwable t) {
+ Log.w(TAG, "getCodecs(): ignored: " + t);
+ }
+ }
+ return codecs;
+ }
+
+ /**
+ * Gets the media description of the specified type.
+ *
+ * @param type the media type; e.g., "AUDIO"
+ * @return the media description of the specified type
+ */
+ public MediaDescription getMediaDescription(String type) {
+ MediaDescription[] all = getMediaDescriptions();
+ if ((all == null) || (all.length == 0)) return null;
+ for (MediaDescription md : all) {
+ String t = md.getMedia().getMedia();
+ if (t.equalsIgnoreCase(type)) return md;
+ }
+ return null;
+ }
+
+ /**
+ * Gets all the media descriptions in this session description.
+ *
+ * @return all the media descriptions in this session description
+ */
+ public MediaDescription[] getMediaDescriptions() {
+ try {
+ Vector<MediaDescription> descriptions = (Vector<MediaDescription>)
+ mSessionDescription.getMediaDescriptions(false);
+ MediaDescription[] all = new MediaDescription[descriptions.size()];
+ return descriptions.toArray(all);
+ } catch (SdpException e) {
+ Log.e(TAG, "getMediaDescriptions", e);
+ }
+ return null;
+ }
+
+ @Override
+ public String getType() {
+ return "sdp";
+ }
+
+ @Override
+ public byte[] getContent() {
+ return mSessionDescription.toString().getBytes();
+ }
+
+ @Override
+ public String toString() {
+ return mSessionDescription.toString();
+ }
+}
diff --git a/voip/java/android/net/sip/SessionDescription.aidl b/voip/java/android/net/sip/SessionDescription.aidl
new file mode 100644
index 0000000..a120d16
--- /dev/null
+++ b/voip/java/android/net/sip/SessionDescription.aidl
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+parcelable SessionDescription;
diff --git a/voip/java/android/net/sip/SessionDescription.java b/voip/java/android/net/sip/SessionDescription.java
new file mode 100644
index 0000000..d476f0b
--- /dev/null
+++ b/voip/java/android/net/sip/SessionDescription.java
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * Abstract class of a session description.
+ * @hide
+ */
+public abstract class SessionDescription implements Parcelable {
+ /** @hide */
+ public static final Parcelable.Creator<SessionDescription> CREATOR =
+ new Parcelable.Creator<SessionDescription>() {
+ public SessionDescription createFromParcel(Parcel in) {
+ return new SessionDescriptionImpl(in);
+ }
+
+ public SessionDescription[] newArray(int size) {
+ return new SessionDescriptionImpl[size];
+ }
+ };
+
+ /**
+ * Gets the type of the session description; e.g., "SDP".
+ *
+ * @return the session description type
+ */
+ public abstract String getType();
+
+ /**
+ * Gets the raw content of the session description.
+ *
+ * @return the content of the session description
+ */
+ public abstract byte[] getContent();
+
+ /** @hide */
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeString(getType());
+ out.writeByteArray(getContent());
+ }
+
+ /** @hide */
+ public int describeContents() {
+ return 0;
+ }
+
+ private static class SessionDescriptionImpl extends SessionDescription {
+ private String mType;
+ private byte[] mContent;
+
+ SessionDescriptionImpl(Parcel in) {
+ mType = in.readString();
+ mContent = in.createByteArray();
+ }
+
+ @Override
+ public String getType() {
+ return mType;
+ }
+
+ @Override
+ public byte[] getContent() {
+ return mContent;
+ }
+ }
+}
diff --git a/voip/java/android/net/sip/SipAudioCall.java b/voip/java/android/net/sip/SipAudioCall.java
new file mode 100644
index 0000000..abdc9d7
--- /dev/null
+++ b/voip/java/android/net/sip/SipAudioCall.java
@@ -0,0 +1,306 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import android.net.rtp.AudioGroup;
+import android.net.rtp.AudioStream;
+import android.os.Message;
+
+import javax.sip.SipException;
+
+/**
+ * Interface for making audio calls over SIP.
+ * @hide
+ */
+public interface SipAudioCall {
+ /** Listener class for all event callbacks. */
+ public interface Listener {
+ /**
+ * Called when the call object is ready to make another call.
+ *
+ * @param call the call object that is ready to make another call
+ */
+ void onReadyToCall(SipAudioCall call);
+
+ /**
+ * Called when a request is sent out to initiate a new call.
+ *
+ * @param call the call object that carries out the audio call
+ */
+ void onCalling(SipAudioCall call);
+
+ /**
+ * Called when a new call comes in.
+ *
+ * @param call the call object that carries out the audio call
+ * @param caller the SIP profile of the caller
+ */
+ void onRinging(SipAudioCall call, SipProfile caller);
+
+ /**
+ * Called when a RINGING response is received for the INVITE request sent
+ *
+ * @param call the call object that carries out the audio call
+ */
+ void onRingingBack(SipAudioCall call);
+
+ /**
+ * Called when the session is established.
+ *
+ * @param call the call object that carries out the audio call
+ */
+ void onCallEstablished(SipAudioCall call);
+
+ /**
+ * Called when the session is terminated.
+ *
+ * @param call the call object that carries out the audio call
+ */
+ void onCallEnded(SipAudioCall call);
+
+ /**
+ * Called when the peer is busy during session initialization.
+ *
+ * @param call the call object that carries out the audio call
+ */
+ void onCallBusy(SipAudioCall call);
+
+ /**
+ * Called when the call is on hold.
+ *
+ * @param call the call object that carries out the audio call
+ */
+ void onCallHeld(SipAudioCall call);
+
+ /**
+ * Called when an error occurs.
+ *
+ * @param call the call object that carries out the audio call
+ * @param errorMessage error message
+ */
+ void onError(SipAudioCall call, String errorMessage);
+ }
+
+ /**
+ * The adapter class for {@link SipAudioCall#Listener}. The default
+ * implementation of all callback methods is no-op.
+ */
+ public class Adapter implements Listener {
+ protected void onChanged(SipAudioCall call) {
+ }
+ public void onReadyToCall(SipAudioCall call) {
+ onChanged(call);
+ }
+ public void onCalling(SipAudioCall call) {
+ onChanged(call);
+ }
+ public void onRinging(SipAudioCall call, SipProfile caller) {
+ onChanged(call);
+ }
+ public void onRingingBack(SipAudioCall call) {
+ onChanged(call);
+ }
+ public void onCallEstablished(SipAudioCall call) {
+ onChanged(call);
+ }
+ public void onCallEnded(SipAudioCall call) {
+ onChanged(call);
+ }
+ public void onCallBusy(SipAudioCall call) {
+ onChanged(call);
+ }
+ public void onCallHeld(SipAudioCall call) {
+ onChanged(call);
+ }
+ public void onError(SipAudioCall call, String errorMessage) {
+ onChanged(call);
+ }
+ }
+
+ /**
+ * Sets the listener to listen to the audio call events. The method calls
+ * {@link #setListener(Listener, false)}.
+ *
+ * @param listener to listen to the audio call events of this object
+ * @see #setListener(Listener, boolean)
+ */
+ void setListener(Listener listener);
+
+ /**
+ * Sets the listener to listen to the audio call events. A
+ * {@link SipAudioCall} can only hold one listener at a time. Subsequent
+ * calls to this method override the previous listener.
+ *
+ * @param listener to listen to the audio call events of this object
+ * @param callbackImmediately set to true if the caller wants to be called
+ * back immediately on the current state
+ */
+ void setListener(Listener listener, boolean callbackImmediately);
+
+ /**
+ * Closes this object. The object is not usable after being closed.
+ */
+ void close();
+
+ /**
+ * Initiates an audio call to the specified profile.
+ *
+ * @param callee the SIP profile to make the call to
+ * @param sipManager the {@link SipManager} object to help make call with
+ */
+ void makeCall(SipProfile callee, SipManager sipManager) throws SipException;
+
+ /**
+ * Attaches an incoming call to this call object.
+ *
+ * @param session the session that receives the incoming call
+ * @param sdp the session description of the incoming call
+ */
+ void attachCall(ISipSession session, SdpSessionDescription sdp)
+ throws SipException;
+
+ /** Ends a call. */
+ void endCall() throws SipException;
+
+ /**
+ * Puts a call on hold. When succeeds,
+ * {@link #Listener#onCallHeld(SipAudioCall)} is called.
+ */
+ void holdCall() throws SipException;
+
+ /** Answers a call. */
+ void answerCall() throws SipException;
+
+ /**
+ * Continues a call that's on hold. When succeeds,
+ * {@link #Listener#onCallEstablished(SipAudioCall)} is called.
+ */
+ void continueCall() throws SipException;
+
+ /** Puts the device to in-call mode. */
+ void setInCallMode();
+
+ /** Puts the device to speaker mode. */
+ void setSpeakerMode();
+
+ /** Toggles mute. */
+ void toggleMute();
+
+ /**
+ * Checks if the call is on hold.
+ *
+ * @return true if the call is on hold
+ */
+ boolean isOnHold();
+
+ /**
+ * Checks if the call is muted.
+ *
+ * @return true if the call is muted
+ */
+ boolean isMuted();
+
+ /**
+ * Sends a DTMF code.
+ *
+ * @param code the DTMF code to send
+ */
+ void sendDtmf(int code);
+
+ /**
+ * Sends a DTMF code.
+ *
+ * @param code the DTMF code to send
+ * @param result the result message to send when done
+ */
+ void sendDtmf(int code, Message result);
+
+ /**
+ * Gets the {@link AudioStream} object used in this call. The object
+ * represents the RTP stream that carries the audio data to and from the
+ * peer. The object may not be created before the call is established. And
+ * it is undefined after the call ends or the {@link #close} method is
+ * called.
+ *
+ * @return the {@link AudioStream} object or null if the RTP stream has not
+ * yet been set up
+ */
+ AudioStream getAudioStream();
+
+ /**
+ * Gets the {@link AudioGroup} object which the {@link AudioStream} object
+ * joins. The group object may not exist before the call is established.
+ * Also, the {@code AudioStream} may change its group during a call (e.g.,
+ * after the call is held/un-held). Finally, the {@code AudioGroup} object
+ * returned by this method is undefined after the call ends or the
+ * {@link #close} method is called.
+ *
+ * @return the {@link AudioGroup} object or null if the RTP stream has not
+ * yet been set up
+ * @see #getAudioStream
+ */
+ AudioGroup getAudioGroup();
+
+ /**
+ * Checks if the call is established.
+ *
+ * @return true if the call is established
+ */
+ boolean isInCall();
+
+ /**
+ * Gets the local SIP profile.
+ *
+ * @return the local SIP profile
+ */
+ SipProfile getLocalProfile();
+
+ /**
+ * Gets the peer's SIP profile.
+ *
+ * @return the peer's SIP profile
+ */
+ SipProfile getPeerProfile();
+
+ /**
+ * Gets the state of the {@link ISipSession} that carries this call.
+ *
+ * @return the session state
+ */
+ SipSessionState getState();
+
+ /**
+ * Gets the {@link ISipSession} that carries this call.
+ *
+ * @return the session object that carries this call
+ */
+ ISipSession getSipSession();
+
+ /**
+ * Enables/disables the ring-back tone.
+ *
+ * @param enabled true to enable; false to disable
+ */
+ void setRingbackToneEnabled(boolean enabled);
+
+ /**
+ * Enables/disables the ring tone.
+ *
+ * @param enabled true to enable; false to disable
+ */
+ void setRingtoneEnabled(boolean enabled);
+}
diff --git a/voip/java/android/net/sip/SipAudioCallImpl.java b/voip/java/android/net/sip/SipAudioCallImpl.java
new file mode 100644
index 0000000..57e0bd2
--- /dev/null
+++ b/voip/java/android/net/sip/SipAudioCallImpl.java
@@ -0,0 +1,701 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import gov.nist.javax.sdp.fields.SDPKeywords;
+
+import android.content.Context;
+import android.media.AudioManager;
+import android.media.Ringtone;
+import android.media.RingtoneManager;
+import android.media.ToneGenerator;
+import android.net.Uri;
+import android.net.rtp.AudioCodec;
+import android.net.rtp.AudioGroup;
+import android.net.rtp.AudioStream;
+import android.net.rtp.RtpStream;
+import android.net.sip.ISipSession;
+import android.net.sip.SdpSessionDescription;
+import android.net.sip.SessionDescription;
+import android.net.sip.SipAudioCall;
+import android.net.sip.SipManager;
+import android.net.sip.SipProfile;
+import android.net.sip.SipSessionAdapter;
+import android.net.sip.SipSessionState;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.Vibrator;
+import android.provider.Settings;
+import android.util.Log;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.sdp.SdpException;
+import javax.sip.SipException;
+
+/**
+ * Class that handles an audio call over SIP.
+ */
+/** @hide */
+public class SipAudioCallImpl extends SipSessionAdapter
+ implements SipAudioCall {
+ private static final String TAG = SipAudioCallImpl.class.getSimpleName();
+ private static final boolean RELEASE_SOCKET = true;
+ private static final boolean DONT_RELEASE_SOCKET = false;
+ private static final String AUDIO = "audio";
+ private static final int DTMF = 101;
+
+ private Context mContext;
+ private SipProfile mLocalProfile;
+ private SipAudioCall.Listener mListener;
+ private ISipSession mSipSession;
+ private SdpSessionDescription mPeerSd;
+
+ private AudioStream mRtpSession;
+ private SdpSessionDescription.AudioCodec mCodec;
+ private long mSessionId = -1L; // SDP session ID
+ private boolean mInCall = false;
+ private boolean mMuted = false;
+ private boolean mHold = false;
+
+ private boolean mRingbackToneEnabled = true;
+ private boolean mRingtoneEnabled = true;
+ private Ringtone mRingtone;
+ private ToneGenerator mRingbackTone;
+
+ private SipProfile mPendingCallRequest;
+
+ public SipAudioCallImpl(Context context, SipProfile localProfile) {
+ mContext = context;
+ mLocalProfile = localProfile;
+ }
+
+ public void setListener(SipAudioCall.Listener listener) {
+ setListener(listener, false);
+ }
+
+ public void setListener(SipAudioCall.Listener listener,
+ boolean callbackImmediately) {
+ mListener = listener;
+ if ((listener == null) || !callbackImmediately) return;
+ try {
+ SipSessionState state = getState();
+ switch (state) {
+ case READY_TO_CALL:
+ listener.onReadyToCall(this);
+ break;
+ case INCOMING_CALL:
+ listener.onRinging(this, getPeerProfile(mSipSession));
+ startRinging();
+ break;
+ case OUTGOING_CALL:
+ listener.onCalling(this);
+ break;
+ default:
+ listener.onError(this, "wrong state to attach call: " + state);
+ }
+ } catch (Throwable t) {
+ Log.e(TAG, "setListener()", t);
+ }
+ }
+
+ public synchronized boolean isInCall() {
+ return mInCall;
+ }
+
+ public synchronized boolean isOnHold() {
+ return mHold;
+ }
+
+ public void close() {
+ close(true);
+ }
+
+ private synchronized void close(boolean closeRtp) {
+ if (closeRtp) stopCall(RELEASE_SOCKET);
+ stopRingbackTone();
+ stopRinging();
+ mSipSession = null;
+ mInCall = false;
+ mHold = false;
+ mSessionId = -1L;
+ }
+
+ public synchronized SipProfile getLocalProfile() {
+ return mLocalProfile;
+ }
+
+ public synchronized SipProfile getPeerProfile() {
+ try {
+ return (mSipSession == null) ? null : mSipSession.getPeerProfile();
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+
+ public synchronized SipSessionState getState() {
+ if (mSipSession == null) return SipSessionState.READY_TO_CALL;
+ try {
+ return Enum.valueOf(SipSessionState.class, mSipSession.getState());
+ } catch (RemoteException e) {
+ return SipSessionState.REMOTE_ERROR;
+ }
+ }
+
+
+ public synchronized ISipSession getSipSession() {
+ return mSipSession;
+ }
+
+ @Override
+ public void onCalling(ISipSession session) {
+ Log.d(TAG, "calling... " + session);
+ Listener listener = mListener;
+ if (listener != null) {
+ try {
+ listener.onCalling(SipAudioCallImpl.this);
+ } catch (Throwable t) {
+ Log.e(TAG, "onCalling()", t);
+ }
+ }
+ }
+
+ @Override
+ public void onRingingBack(ISipSession session) {
+ Log.d(TAG, "sip call ringing back: " + session);
+ if (!mInCall) startRingbackTone();
+ Listener listener = mListener;
+ if (listener != null) {
+ try {
+ listener.onRingingBack(SipAudioCallImpl.this);
+ } catch (Throwable t) {
+ Log.e(TAG, "onRingingBack()", t);
+ }
+ }
+ }
+
+ @Override
+ public synchronized void onRinging(ISipSession session,
+ SipProfile peerProfile, byte[] sessionDescription) {
+ try {
+ if ((mSipSession == null) || !mInCall
+ || !session.getCallId().equals(mSipSession.getCallId())) {
+ // should not happen
+ session.endCall();
+ return;
+ }
+
+ // session changing request
+ try {
+ mPeerSd = new SdpSessionDescription(sessionDescription);
+ answerCall();
+ } catch (Throwable e) {
+ Log.e(TAG, "onRinging()", e);
+ session.endCall();
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "onRinging()", e);
+ }
+ }
+
+ private synchronized void establishCall(byte[] sessionDescription) {
+ stopRingbackTone();
+ stopRinging();
+ try {
+ SdpSessionDescription sd =
+ new SdpSessionDescription(sessionDescription);
+ Log.d(TAG, "sip call established: " + sd);
+ startCall(sd);
+ mInCall = true;
+ } catch (SdpException e) {
+ Log.e(TAG, "createSessionDescription()", e);
+ }
+ }
+
+ @Override
+ public void onCallEstablished(ISipSession session,
+ byte[] sessionDescription) {
+ establishCall(sessionDescription);
+ Listener listener = mListener;
+ if (listener != null) {
+ try {
+ if (mHold) {
+ listener.onCallHeld(SipAudioCallImpl.this);
+ } else {
+ listener.onCallEstablished(SipAudioCallImpl.this);
+ }
+ } catch (Throwable t) {
+ Log.e(TAG, "onCallEstablished()", t);
+ }
+ }
+ }
+
+ @Override
+ public void onCallEnded(ISipSession session) {
+ Log.d(TAG, "sip call ended: " + session);
+ close();
+ Listener listener = mListener;
+ if (listener != null) {
+ try {
+ listener.onCallEnded(SipAudioCallImpl.this);
+ } catch (Throwable t) {
+ Log.e(TAG, "onCallEnded()", t);
+ }
+ }
+ }
+
+ @Override
+ public void onCallBusy(ISipSession session) {
+ Log.d(TAG, "sip call busy: " + session);
+ close(false);
+ Listener listener = mListener;
+ if (listener != null) {
+ try {
+ listener.onCallBusy(SipAudioCallImpl.this);
+ } catch (Throwable t) {
+ Log.e(TAG, "onCallBusy()", t);
+ }
+ }
+ }
+
+ @Override
+ public void onCallChangeFailed(ISipSession session,
+ String className, String message) {
+ Log.d(TAG, "sip call change failed: " + message);
+ Listener listener = mListener;
+ if (listener != null) {
+ try {
+ listener.onError(SipAudioCallImpl.this,
+ className + ": " + message);
+ } catch (Throwable t) {
+ Log.e(TAG, "onCallBusy()", t);
+ }
+ }
+ }
+
+ @Override
+ public void onError(ISipSession session, String className,
+ String message) {
+ Log.d(TAG, "sip session error: " + className + ": " + message);
+ synchronized (this) {
+ if (!isInCall()) close(true);
+ }
+ Listener listener = mListener;
+ if (listener != null) {
+ try {
+ listener.onError(SipAudioCallImpl.this,
+ className + ": " + message);
+ } catch (Throwable t) {
+ Log.e(TAG, "onError()", t);
+ }
+ }
+ }
+
+ public synchronized void attachCall(ISipSession session,
+ SdpSessionDescription sdp) throws SipException {
+ mSipSession = session;
+ mPeerSd = sdp;
+ try {
+ session.setListener(this);
+ } catch (Throwable e) {
+ Log.e(TAG, "attachCall()", e);
+ throwSipException(e);
+ }
+ }
+
+ public synchronized void makeCall(SipProfile peerProfile,
+ SipManager sipManager) throws SipException {
+ try {
+ mSipSession = sipManager.createSipSession(mLocalProfile, this);
+ if (mSipSession == null) {
+ throw new SipException(
+ "Failed to create SipSession; network available?");
+ }
+ mSipSession.makeCall(peerProfile, createOfferSessionDescription());
+ } catch (Throwable e) {
+ if (e instanceof SipException) {
+ throw (SipException) e;
+ } else {
+ throwSipException(e);
+ }
+ }
+ }
+
+ public synchronized void endCall() throws SipException {
+ try {
+ stopRinging();
+ if (mSipSession != null) mSipSession.endCall();
+ stopCall(true);
+ } catch (Throwable e) {
+ throwSipException(e);
+ }
+ }
+
+ public synchronized void holdCall() throws SipException {
+ if (mHold) return;
+ try {
+ mSipSession.changeCall(createHoldSessionDescription());
+ mHold = true;
+ } catch (Throwable e) {
+ throwSipException(e);
+ }
+
+ AudioGroup audioGroup = getAudioGroup();
+ if (audioGroup != null) audioGroup.setMode(AudioGroup.MODE_ON_HOLD);
+ }
+
+ public synchronized void answerCall() throws SipException {
+ try {
+ stopRinging();
+ mSipSession.answerCall(createAnswerSessionDescription());
+ } catch (Throwable e) {
+ Log.e(TAG, "answerCall()", e);
+ throwSipException(e);
+ }
+ }
+
+ public synchronized void continueCall() throws SipException {
+ if (!mHold) return;
+ try {
+ mHold = false;
+ mSipSession.changeCall(createContinueSessionDescription());
+ } catch (Throwable e) {
+ throwSipException(e);
+ }
+
+ AudioGroup audioGroup = getAudioGroup();
+ if (audioGroup != null) audioGroup.setMode(AudioGroup.MODE_NORMAL);
+ }
+
+ private SessionDescription createOfferSessionDescription() {
+ AudioCodec[] codecs = AudioCodec.getSystemSupportedCodecs();
+ return createSdpBuilder(true, convert(codecs)).build();
+ }
+
+ private SessionDescription createAnswerSessionDescription() {
+ try {
+ // choose an acceptable media from mPeerSd to answer
+ SdpSessionDescription.AudioCodec codec = getCodec(mPeerSd);
+ SdpSessionDescription.Builder sdpBuilder =
+ createSdpBuilder(false, codec);
+ if (mPeerSd.isSendOnly(AUDIO)) {
+ sdpBuilder.addMediaAttribute(AUDIO, "recvonly", (String) null);
+ } else if (mPeerSd.isReceiveOnly(AUDIO)) {
+ sdpBuilder.addMediaAttribute(AUDIO, "sendonly", (String) null);
+ }
+ return sdpBuilder.build();
+ } catch (SdpException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private SessionDescription createHoldSessionDescription() {
+ try {
+ return createSdpBuilder(false, mCodec)
+ .addMediaAttribute(AUDIO, "sendonly", (String) null)
+ .build();
+ } catch (SdpException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private SessionDescription createContinueSessionDescription() {
+ return createSdpBuilder(true, mCodec).build();
+ }
+
+ private String getMediaDescription(SdpSessionDescription.AudioCodec codec) {
+ return String.format("%d %s/%d", codec.payloadType, codec.name,
+ codec.sampleRate);
+ }
+
+ private long getSessionId() {
+ if (mSessionId < 0) {
+ mSessionId = System.currentTimeMillis();
+ }
+ return mSessionId;
+ }
+
+ private SdpSessionDescription.Builder createSdpBuilder(
+ boolean addTelephoneEvent,
+ SdpSessionDescription.AudioCodec... codecs) {
+ String localIp = getLocalIp();
+ SdpSessionDescription.Builder sdpBuilder;
+ try {
+ long sessionVersion = System.currentTimeMillis();
+ sdpBuilder = new SdpSessionDescription.Builder("SIP Call")
+ .setOrigin(mLocalProfile, getSessionId(), sessionVersion,
+ SDPKeywords.IN, SDPKeywords.IPV4, localIp)
+ .setConnectionInfo(SDPKeywords.IN, SDPKeywords.IPV4,
+ localIp);
+ List<Integer> codecIds = new ArrayList<Integer>();
+ for (SdpSessionDescription.AudioCodec codec : codecs) {
+ codecIds.add(codec.payloadType);
+ }
+ if (addTelephoneEvent) codecIds.add(DTMF);
+ sdpBuilder.addMedia(AUDIO, getLocalMediaPort(), 1, "RTP/AVP",
+ codecIds.toArray(new Integer[codecIds.size()]));
+ for (SdpSessionDescription.AudioCodec codec : codecs) {
+ sdpBuilder.addMediaAttribute(AUDIO, "rtpmap",
+ getMediaDescription(codec));
+ }
+ if (addTelephoneEvent) {
+ sdpBuilder.addMediaAttribute(AUDIO, "rtpmap",
+ DTMF + " telephone-event/8000");
+ }
+ // FIXME: deal with vbr codec
+ sdpBuilder.addMediaAttribute(AUDIO, "ptime", "20");
+ } catch (SdpException e) {
+ throw new RuntimeException(e);
+ }
+ return sdpBuilder;
+ }
+
+ public synchronized void toggleMute() {
+ AudioGroup audioGroup = getAudioGroup();
+ if (audioGroup != null) {
+ audioGroup.setMode(
+ mMuted ? AudioGroup.MODE_NORMAL : AudioGroup.MODE_MUTED);
+ mMuted = !mMuted;
+ }
+ }
+
+ public synchronized boolean isMuted() {
+ return mMuted;
+ }
+
+ public synchronized void setInCallMode() {
+ ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE))
+ .setSpeakerphoneOn(false);
+ ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE))
+ .setMode(AudioManager.MODE_NORMAL);
+ }
+
+ public synchronized void setSpeakerMode() {
+ ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE))
+ .setSpeakerphoneOn(true);
+ }
+
+ public void sendDtmf(int code) {
+ sendDtmf(code, null);
+ }
+
+ public synchronized void sendDtmf(int code, Message result) {
+ AudioGroup audioGroup = getAudioGroup();
+ if ((audioGroup != null) && (mSipSession != null)
+ && (SipSessionState.IN_CALL == getState())) {
+ Log.v(TAG, "send DTMF: " + code);
+ audioGroup.sendDtmf(code);
+ }
+ if (result != null) result.sendToTarget();
+ }
+
+ public synchronized AudioStream getAudioStream() {
+ return mRtpSession;
+ }
+
+ public synchronized AudioGroup getAudioGroup() {
+ return ((mRtpSession == null) ? null : mRtpSession.getAudioGroup());
+ }
+
+ private SdpSessionDescription.AudioCodec getCodec(SdpSessionDescription sd) {
+ HashMap<String, AudioCodec> acceptableCodecs =
+ new HashMap<String, AudioCodec>();
+ for (AudioCodec codec : AudioCodec.getSystemSupportedCodecs()) {
+ acceptableCodecs.put(codec.name, codec);
+ }
+ for (SdpSessionDescription.AudioCodec codec : sd.getAudioCodecs()) {
+ AudioCodec matchedCodec = acceptableCodecs.get(codec.name);
+ if (matchedCodec != null) return codec;
+ }
+ Log.w(TAG, "no common codec is found, use PCM/0");
+ return convert(AudioCodec.ULAW);
+ }
+
+ private AudioCodec convert(SdpSessionDescription.AudioCodec codec) {
+ AudioCodec c = AudioCodec.getSystemSupportedCodec(codec.name);
+ return ((c == null) ? AudioCodec.ULAW : c);
+ }
+
+ private SdpSessionDescription.AudioCodec convert(AudioCodec codec) {
+ return new SdpSessionDescription.AudioCodec(codec.defaultType,
+ codec.name, codec.sampleRate, codec.sampleCount);
+ }
+
+ private SdpSessionDescription.AudioCodec[] convert(AudioCodec[] codecs) {
+ SdpSessionDescription.AudioCodec[] copies =
+ new SdpSessionDescription.AudioCodec[codecs.length];
+ for (int i = 0, len = codecs.length; i < len; i++) {
+ copies[i] = convert(codecs[i]);
+ }
+ return copies;
+ }
+
+ private void startCall(SdpSessionDescription peerSd) {
+ stopCall(DONT_RELEASE_SOCKET);
+
+ mPeerSd = peerSd;
+ String peerMediaAddress = peerSd.getPeerMediaAddress(AUDIO);
+ // TODO: handle multiple media fields
+ int peerMediaPort = peerSd.getPeerMediaPort(AUDIO);
+ Log.i(TAG, "start audiocall " + peerMediaAddress + ":" + peerMediaPort);
+
+ int localPort = getLocalMediaPort();
+ int sampleRate = 8000;
+ int frameSize = sampleRate / 50; // 160
+ try {
+ // TODO: get sample rate from sdp
+ mCodec = getCodec(peerSd);
+
+ AudioStream audioStream = mRtpSession;
+ audioStream.associate(InetAddress.getByName(peerMediaAddress),
+ peerMediaPort);
+ audioStream.setCodec(convert(mCodec), mCodec.payloadType);
+ audioStream.setDtmfType(DTMF);
+ Log.d(TAG, "start media: localPort=" + localPort + ", peer="
+ + peerMediaAddress + ":" + peerMediaPort);
+
+ audioStream.setMode(RtpStream.MODE_NORMAL);
+ if (!mHold) {
+ // FIXME: won't work if peer is not sending nor receiving
+ if (!peerSd.isSending(AUDIO)) {
+ Log.d(TAG, " not receiving");
+ audioStream.setMode(RtpStream.MODE_SEND_ONLY);
+ }
+ if (!peerSd.isReceiving(AUDIO)) {
+ Log.d(TAG, " not sending");
+ audioStream.setMode(RtpStream.MODE_RECEIVE_ONLY);
+ }
+ }
+ setInCallMode();
+
+ AudioGroup audioGroup = new AudioGroup();
+ audioStream.join(audioGroup);
+ if (mHold) {
+ audioGroup.setMode(AudioGroup.MODE_ON_HOLD);
+ } else if (mMuted) {
+ audioGroup.setMode(AudioGroup.MODE_MUTED);
+ } else {
+ audioGroup.setMode(AudioGroup.MODE_NORMAL);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "call()", e);
+ }
+ }
+
+ private void stopCall(boolean releaseSocket) {
+ Log.d(TAG, "stop audiocall");
+ if (mRtpSession != null) {
+ mRtpSession.join(null);
+
+ if (releaseSocket) {
+ mRtpSession.release();
+ mRtpSession = null;
+ }
+ }
+ setInCallMode();
+ }
+
+ private int getLocalMediaPort() {
+ if (mRtpSession != null) return mRtpSession.getLocalPort();
+ try {
+ AudioStream s = mRtpSession =
+ new AudioStream(InetAddress.getByName(getLocalIp()));
+ return s.getLocalPort();
+ } catch (IOException e) {
+ Log.w(TAG, "getLocalMediaPort(): " + e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String getLocalIp() {
+ try {
+ return mSipSession.getLocalIp();
+ } catch (RemoteException e) {
+ // FIXME
+ return "127.0.0.1";
+ }
+ }
+
+ public synchronized void setRingbackToneEnabled(boolean enabled) {
+ mRingbackToneEnabled = enabled;
+ }
+
+ public synchronized void setRingtoneEnabled(boolean enabled) {
+ mRingtoneEnabled = enabled;
+ }
+
+ private void startRingbackTone() {
+ if (!mRingbackToneEnabled) return;
+ if (mRingbackTone == null) {
+ // The volume relative to other sounds in the stream
+ int toneVolume = 80;
+ mRingbackTone = new ToneGenerator(
+ AudioManager.STREAM_VOICE_CALL, toneVolume);
+ }
+ mRingbackTone.startTone(ToneGenerator.TONE_CDMA_LOW_PBX_L);
+ }
+
+ private void stopRingbackTone() {
+ if (mRingbackTone != null) {
+ mRingbackTone.stopTone();
+ mRingbackTone.release();
+ mRingbackTone = null;
+ }
+ }
+
+ private void startRinging() {
+ if (!mRingtoneEnabled) return;
+ ((Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE))
+ .vibrate(new long[] {0, 1000, 1000}, 1);
+ AudioManager am = (AudioManager)
+ mContext.getSystemService(Context.AUDIO_SERVICE);
+ if (am.getStreamVolume(AudioManager.STREAM_RING) > 0) {
+ String ringtoneUri =
+ Settings.System.DEFAULT_RINGTONE_URI.toString();
+ mRingtone = RingtoneManager.getRingtone(mContext,
+ Uri.parse(ringtoneUri));
+ mRingtone.play();
+ }
+ }
+
+ private void stopRinging() {
+ ((Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE))
+ .cancel();
+ if (mRingtone != null) mRingtone.stop();
+ }
+
+ private void throwSipException(Throwable throwable) throws SipException {
+ if (throwable instanceof SipException) {
+ throw (SipException) throwable;
+ } else {
+ throw new SipException("", throwable);
+ }
+ }
+
+ private SipProfile getPeerProfile(ISipSession session) {
+ try {
+ return session.getPeerProfile();
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+}
diff --git a/voip/java/android/net/sip/SipManager.java b/voip/java/android/net/sip/SipManager.java
new file mode 100644
index 0000000..f28b41c
--- /dev/null
+++ b/voip/java/android/net/sip/SipManager.java
@@ -0,0 +1,499 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import android.content.Context;
+import android.content.Intent;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+
+import java.text.ParseException;
+import javax.sip.SipException;
+
+/**
+ * The class provides API for various SIP related tasks. Specifically, the API
+ * allows the application to:
+ * <ul>
+ * <li>register a {@link SipProfile} to have the background SIP service listen
+ * to incoming calls and broadcast them with registered command string. See
+ * {@link #open(SipProfile, String, SipRegistrationListener)},
+ * {@link #open(SipProfile)}, {@link #close(String)},
+ * {@link #isOpened(String)} and {@link isRegistered(String)}. It also
+ * facilitates handling of the incoming call broadcast intent. See
+ * {@link #isIncomingCallIntent(Intent)}, {@link #getCallId(Intent)},
+ * {@link #getOfferSessionDescription(Intent)} and
+ * {@link #takeAudioCall(Context, Intent, SipAudioCall.Listener)}.</li>
+ * <li>make/take SIP-based audio calls. See
+ * {@link #makeAudioCall(Context, SipProfile, SipProfile, SipAudioCall.Listener)}
+ * and {@link #takeAudioCall(Context, Intent, SipAudioCall.Listener}.</li>
+ * <li>register/unregister with a SIP service provider. See
+ * {@link #register(SipProfile, int, ISipSessionListener)} and
+ * {@link #unregister(SipProfile, ISipSessionListener)}.</li>
+ * <li>process SIP events directly with a {@link ISipSession} created by
+ * {@link createSipSession(SipProfile, ISipSessionListener)}.</li>
+ * </ul>
+ * @hide
+ */
+public class SipManager {
+ /** @hide */
+ public static final String SIP_INCOMING_CALL_ACTION =
+ "com.android.phone.SIP_INCOMING_CALL";
+ /** @hide */
+ public static final String SIP_ADD_PHONE_ACTION =
+ "com.android.phone.SIP_ADD_PHONE";
+ /** @hide */
+ public static final String SIP_REMOVE_PHONE_ACTION =
+ "com.android.phone.SIP_REMOVE_PHONE";
+ /** @hide */
+ public static final String LOCAL_URI_KEY = "LOCAL SIPURI";
+
+ private static final String CALL_ID_KEY = "CallID";
+ private static final String OFFER_SD_KEY = "OfferSD";
+
+ private ISipService mSipService;
+
+ // Will be removed once the SIP service is integrated into framework
+ private BinderHelper<ISipService> mBinderHelper;
+
+ /**
+ * Creates a manager instance and initializes the background SIP service.
+ * Will be removed once the SIP service is integrated into framework.
+ *
+ * @param context context to start the SIP service
+ * @return the manager instance
+ */
+ public static SipManager getInstance(final Context context) {
+ final SipManager manager = new SipManager();
+ manager.createSipService(context);
+ return manager;
+ }
+
+ private SipManager() {
+ }
+
+ private void createSipService(Context context) {
+ if (mSipService != null) return;
+ IBinder b = ServiceManager.getService(Context.SIP_SERVICE);
+ mSipService = ISipService.Stub.asInterface(b);
+ }
+
+ /**
+ * Opens the profile for making calls and/or receiving calls. Subsequent
+ * SIP calls can be made through the default phone UI. The caller may also
+ * make subsequent calls through
+ * {@link #makeAudioCall(Context, String, String, SipAudioCall.Listener)}.
+ * If the receiving-call option is enabled in the profile, the SIP service
+ * will register the profile to the corresponding server periodically in
+ * order to receive calls from the server.
+ *
+ * @param localProfile the SIP profile to make calls from
+ * @throws SipException if the profile contains incorrect settings or
+ * calling the SIP service results in an error
+ */
+ public void open(SipProfile localProfile) throws SipException {
+ try {
+ mSipService.open(localProfile);
+ } catch (RemoteException e) {
+ throw new SipException("open()", e);
+ }
+ }
+
+ /**
+ * Opens the profile for making calls and/or receiving calls. Subsequent
+ * SIP calls can be made through the default phone UI. The caller may also
+ * make subsequent calls through
+ * {@link #makeAudioCall(Context, String, String, SipAudioCall.Listener)}.
+ * If the receiving-call option is enabled in the profile, the SIP service
+ * will register the profile to the corresponding server periodically in
+ * order to receive calls from the server.
+ *
+ * @param localProfile the SIP profile to receive incoming calls for
+ * @param incomingCallBroadcastAction the action to be broadcast when an
+ * incoming call is received
+ * @param listener to listen to registration events; can be null
+ * @throws SipException if the profile contains incorrect settings or
+ * calling the SIP service results in an error
+ */
+ public void open(SipProfile localProfile,
+ String incomingCallBroadcastAction,
+ SipRegistrationListener listener) throws SipException {
+ try {
+ mSipService.open3(localProfile, incomingCallBroadcastAction,
+ createRelay(listener));
+ } catch (RemoteException e) {
+ throw new SipException("open()", e);
+ }
+ }
+
+ /**
+ * Sets the listener to listen to registration events. No effect if the
+ * profile has not been opened to receive calls
+ * (see {@link #open(SipProfile, String, SipRegistrationListener)} and
+ * {@link #open(SipProfile)}).
+ *
+ * @param localProfileUri the URI of the profile
+ * @param listener to listen to registration events; can be null
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public void setRegistrationListener(String localProfileUri,
+ SipRegistrationListener listener) throws SipException {
+ try {
+ mSipService.setRegistrationListener(
+ localProfileUri, createRelay(listener));
+ } catch (RemoteException e) {
+ throw new SipException("setRegistrationListener()", e);
+ }
+ }
+
+ /**
+ * Closes the specified profile to not make/receive calls. All the resources
+ * that were allocated to the profile are also released.
+ *
+ * @param localProfileUri the URI of the profile to close
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public void close(String localProfileUri) throws SipException {
+ try {
+ mSipService.close(localProfileUri);
+ } catch (RemoteException e) {
+ throw new SipException("close()", e);
+ }
+ }
+
+ /**
+ * Checks if the specified profile is enabled to receive calls.
+ *
+ * @param localProfileUri the URI of the profile in question
+ * @return true if the profile is enabled to receive calls
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public boolean isOpened(String localProfileUri) throws SipException {
+ try {
+ return mSipService.isOpened(localProfileUri);
+ } catch (RemoteException e) {
+ throw new SipException("isOpened()", e);
+ }
+ }
+
+ /**
+ * Checks if the specified profile is registered to the server for
+ * receiving calls.
+ *
+ * @param localProfileUri the URI of the profile in question
+ * @return true if the profile is registered to the server
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public boolean isRegistered(String localProfileUri) throws SipException {
+ try {
+ return mSipService.isRegistered(localProfileUri);
+ } catch (RemoteException e) {
+ throw new SipException("isRegistered()", e);
+ }
+ }
+
+ /**
+ * Creates a {@link SipAudioCall} to make a call.
+ *
+ * @param context context to create a {@link SipAudioCall} object
+ * @param localProfile the SIP profile to make the call from
+ * @param peerProfile the SIP profile to make the call to
+ * @param listener to listen to the call events from {@link SipAudioCall};
+ * can be null
+ * @return a {@link SipAudioCall} object
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public SipAudioCall makeAudioCall(Context context, SipProfile localProfile,
+ SipProfile peerProfile, SipAudioCall.Listener listener)
+ throws SipException {
+ SipAudioCall call = new SipAudioCallImpl(context, localProfile);
+ call.setListener(listener);
+ call.makeCall(peerProfile, this);
+ return call;
+ }
+
+ /**
+ * Creates a {@link SipAudioCall} to make a call. To use this method, one
+ * must call {@link #open(SipProfile)} first.
+ *
+ * @param context context to create a {@link SipAudioCall} object
+ * @param localProfileUri URI of the SIP profile to make the call from
+ * @param peerProfileUri URI of the SIP profile to make the call to
+ * @param listener to listen to the call events from {@link SipAudioCall};
+ * can be null
+ * @return a {@link SipAudioCall} object
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public SipAudioCall makeAudioCall(Context context, String localProfileUri,
+ String peerProfileUri, SipAudioCall.Listener listener)
+ throws SipException {
+ try {
+ return makeAudioCall(context,
+ new SipProfile.Builder(localProfileUri).build(),
+ new SipProfile.Builder(peerProfileUri).build(), listener);
+ } catch (ParseException e) {
+ throw new SipException("build SipProfile", e);
+ }
+ }
+
+ /**
+ * The method calls {@code takeAudioCall(context, incomingCallIntent,
+ * listener, true}.
+ *
+ * @see #takeAudioCall(Context, Intent, SipAudioCall.Listener, boolean)
+ */
+ public SipAudioCall takeAudioCall(Context context,
+ Intent incomingCallIntent, SipAudioCall.Listener listener)
+ throws SipException {
+ return takeAudioCall(context, incomingCallIntent, listener, true);
+ }
+
+ /**
+ * Creates a {@link SipAudioCall} to take an incoming call. Before the call
+ * is returned, the listener will receive a
+ * {@link SipAudioCall#Listener.onRinging(SipAudioCall, SipProfile)}
+ * callback.
+ *
+ * @param context context to create a {@link SipAudioCall} object
+ * @param incomingCallIntent the incoming call broadcast intent
+ * @param listener to listen to the call events from {@link SipAudioCall};
+ * can be null
+ * @return a {@link SipAudioCall} object
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public SipAudioCall takeAudioCall(Context context,
+ Intent incomingCallIntent, SipAudioCall.Listener listener,
+ boolean ringtoneEnabled) throws SipException {
+ if (incomingCallIntent == null) return null;
+
+ String callId = getCallId(incomingCallIntent);
+ if (callId == null) {
+ throw new SipException("Call ID missing in incoming call intent");
+ }
+
+ byte[] offerSd = getOfferSessionDescription(incomingCallIntent);
+ if (offerSd == null) {
+ throw new SipException("Session description missing in incoming "
+ + "call intent");
+ }
+
+ try {
+ SdpSessionDescription sdp = new SdpSessionDescription(offerSd);
+
+ ISipSession session = mSipService.getPendingSession(callId);
+ if (session == null) return null;
+ SipAudioCall call = new SipAudioCallImpl(
+ context, session.getLocalProfile());
+ call.setRingtoneEnabled(ringtoneEnabled);
+ call.attachCall(session, sdp);
+ call.setListener(listener);
+ return call;
+ } catch (Throwable t) {
+ throw new SipException("takeAudioCall()", t);
+ }
+ }
+
+ /**
+ * Checks if the intent is an incoming call broadcast intent.
+ *
+ * @param intent the intent in question
+ * @return true if the intent is an incoming call broadcast intent
+ */
+ public static boolean isIncomingCallIntent(Intent intent) {
+ if (intent == null) return false;
+ String callId = getCallId(intent);
+ byte[] offerSd = getOfferSessionDescription(intent);
+ return ((callId != null) && (offerSd != null));
+ }
+
+ /**
+ * Gets the call ID from the specified incoming call broadcast intent.
+ *
+ * @param incomingCallIntent the incoming call broadcast intent
+ * @return the call ID or null if the intent does not contain it
+ */
+ public static String getCallId(Intent incomingCallIntent) {
+ return incomingCallIntent.getStringExtra(CALL_ID_KEY);
+ }
+
+ /**
+ * Gets the offer session description from the specified incoming call
+ * broadcast intent.
+ *
+ * @param incomingCallIntent the incoming call broadcast intent
+ * @return the offer session description or null if the intent does not
+ * have it
+ */
+ public static byte[] getOfferSessionDescription(Intent incomingCallIntent) {
+ return incomingCallIntent.getByteArrayExtra(OFFER_SD_KEY);
+ }
+
+ /**
+ * Creates an incoming call broadcast intent.
+ *
+ * @param action the action string to broadcast
+ * @param callId the call ID of the incoming call
+ * @param sessionDescription the session description of the incoming call
+ * @return the incoming call intent
+ * @hide
+ */
+ public static Intent createIncomingCallBroadcast(String action,
+ String callId, byte[] sessionDescription) {
+ Intent intent = new Intent(action);
+ intent.putExtra(CALL_ID_KEY, callId);
+ intent.putExtra(OFFER_SD_KEY, sessionDescription);
+ return intent;
+ }
+
+ /**
+ * Registers the profile to the corresponding server for receiving calls.
+ * {@link #open(SipProfile, String, SipRegistrationListener)} is still
+ * needed to be called at least once in order for the SIP service to
+ * broadcast an intent when an incoming call is received.
+ *
+ * @param localProfile the SIP profile to register with
+ * @param expiryTime registration expiration time (in second)
+ * @param listener to listen to the registration events
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public void register(SipProfile localProfile, int expiryTime,
+ SipRegistrationListener listener) throws SipException {
+ try {
+ ISipSession session = mSipService.createSession(
+ localProfile, createRelay(listener));
+ session.register(expiryTime);
+ } catch (RemoteException e) {
+ throw new SipException("register()", e);
+ }
+ }
+
+ /**
+ * Unregisters the profile from the corresponding server for not receiving
+ * further calls.
+ *
+ * @param localProfile the SIP profile to register with
+ * @param listener to listen to the registration events
+ * @throws SipException if calling the SIP service results in an error
+ */
+ public void unregister(SipProfile localProfile,
+ SipRegistrationListener listener) throws SipException {
+ try {
+ ISipSession session = mSipService.createSession(
+ localProfile, createRelay(listener));
+ session.unregister();
+ } catch (RemoteException e) {
+ throw new SipException("unregister()", e);
+ }
+ }
+
+ /**
+ * Gets the {@link ISipSession} that handles the incoming call. For audio
+ * calls, consider to use {@link SipAudioCall} to handle the incoming call.
+ * See {@link #takeAudioCall(Context, Intent, SipAudioCall.Listener)}.
+ * Note that the method may be called only once for the same intent. For
+ * subsequent calls on the same intent, the method returns null.
+ *
+ * @param incomingCallIntent the incoming call broadcast intent
+ * @return the session object that handles the incoming call
+ */
+ public ISipSession getSessionFor(Intent incomingCallIntent)
+ throws SipException {
+ try {
+ String callId = getCallId(incomingCallIntent);
+ return mSipService.getPendingSession(callId);
+ } catch (RemoteException e) {
+ throw new SipException("getSessionFor()", e);
+ }
+ }
+
+ private static ISipSessionListener createRelay(
+ SipRegistrationListener listener) {
+ return ((listener == null) ? null : new ListenerRelay(listener));
+ }
+
+ /**
+ * Creates a {@link ISipSession} with the specified profile. Use other
+ * methods, if applicable, instead of interacting with {@link ISipSession}
+ * directly.
+ *
+ * @param localProfile the SIP profile the session is associated with
+ * @param listener to listen to SIP session events
+ */
+ public ISipSession createSipSession(SipProfile localProfile,
+ ISipSessionListener listener) throws SipException {
+ try {
+ return mSipService.createSession(localProfile, listener);
+ } catch (RemoteException e) {
+ throw new SipException("createSipSession()", e);
+ }
+ }
+
+ /**
+ * Gets the list of profiles hosted by the SIP service. The user information
+ * (username, password and display name) are crossed out.
+ * @hide
+ */
+ public SipProfile[] getListOfProfiles() {
+ try {
+ return mSipService.getListOfProfiles();
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+
+ private static class ListenerRelay extends SipSessionAdapter {
+ private SipRegistrationListener mListener;
+
+ // listener must not be null
+ public ListenerRelay(SipRegistrationListener listener) {
+ mListener = listener;
+ }
+
+ private String getUri(ISipSession session) {
+ try {
+ return session.getLocalProfile().getUriString();
+ } catch (RemoteException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void onRegistering(ISipSession session) {
+ mListener.onRegistering(getUri(session));
+ }
+
+ @Override
+ public void onRegistrationDone(ISipSession session, int duration) {
+ long expiryTime = duration;
+ if (duration > 0) expiryTime += System.currentTimeMillis();
+ mListener.onRegistrationDone(getUri(session), expiryTime);
+ }
+
+ @Override
+ public void onRegistrationFailed(ISipSession session, String className,
+ String message) {
+ mListener.onRegistrationFailed(getUri(session), className, message);
+ }
+
+ @Override
+ public void onRegistrationTimeout(ISipSession session) {
+ mListener.onRegistrationFailed(getUri(session),
+ SipException.class.getName(), "registration timed out");
+ }
+ }
+}
diff --git a/voip/java/android/net/sip/SipProfile.aidl b/voip/java/android/net/sip/SipProfile.aidl
new file mode 100644
index 0000000..3b6f68f
--- /dev/null
+++ b/voip/java/android/net/sip/SipProfile.aidl
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+parcelable SipProfile;
diff --git a/voip/java/android/net/sip/SipProfile.java b/voip/java/android/net/sip/SipProfile.java
new file mode 100644
index 0000000..e71c293
--- /dev/null
+++ b/voip/java/android/net/sip/SipProfile.java
@@ -0,0 +1,401 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.text.TextUtils;
+
+import java.io.Serializable;
+import java.text.ParseException;
+import javax.sip.InvalidArgumentException;
+import javax.sip.ListeningPoint;
+import javax.sip.PeerUnavailableException;
+import javax.sip.SipFactory;
+import javax.sip.address.Address;
+import javax.sip.address.AddressFactory;
+import javax.sip.address.SipURI;
+import javax.sip.address.URI;
+
+/**
+ * Class containing a SIP account, domain and server information.
+ * @hide
+ */
+public class SipProfile implements Parcelable, Serializable {
+ private static final long serialVersionUID = 1L;
+ private static final int DEFAULT_PORT = 5060;
+ private Address mAddress;
+ private String mProxyAddress;
+ private String mPassword;
+ private String mDomain;
+ private String mProtocol = ListeningPoint.UDP;
+ private String mProfileName;
+ private boolean mSendKeepAlive = false;
+ private boolean mAutoRegistration = true;
+
+ /** @hide */
+ public static final Parcelable.Creator<SipProfile> CREATOR =
+ new Parcelable.Creator<SipProfile>() {
+ public SipProfile createFromParcel(Parcel in) {
+ return new SipProfile(in);
+ }
+
+ public SipProfile[] newArray(int size) {
+ return new SipProfile[size];
+ }
+ };
+
+ /**
+ * Class to help create a {@link SipProfile}.
+ */
+ public static class Builder {
+ private AddressFactory mAddressFactory;
+ private SipProfile mProfile = new SipProfile();
+ private SipURI mUri;
+ private String mDisplayName;
+ private String mProxyAddress;
+
+ {
+ try {
+ mAddressFactory =
+ SipFactory.getInstance().createAddressFactory();
+ } catch (PeerUnavailableException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param uriString the URI string as "sip:<user_name>@<domain>"
+ * @throws ParseException if the string is not a valid URI
+ */
+ public Builder(String uriString) throws ParseException {
+ if (uriString == null) {
+ throw new NullPointerException("uriString cannot be null");
+ }
+ URI uri = mAddressFactory.createURI(fix(uriString));
+ if (uri instanceof SipURI) {
+ mUri = (SipURI) uri;
+ } else {
+ throw new ParseException(uriString + " is not a SIP URI", 0);
+ }
+ mProfile.mDomain = mUri.getHost();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param username username of the SIP account
+ * @param serverDomain the SIP server domain; if the network address
+ * is different from the domain, use
+ * {@link #setOutboundProxy(String)} to set server address
+ * @throws ParseException if the parameters are not valid
+ */
+ public Builder(String username, String serverDomain)
+ throws ParseException {
+ if ((username == null) || (serverDomain == null)) {
+ throw new NullPointerException(
+ "username and serverDomain cannot be null");
+ }
+ mUri = mAddressFactory.createSipURI(username, serverDomain);
+ mProfile.mDomain = serverDomain;
+ }
+
+ private String fix(String uriString) {
+ return (uriString.trim().toLowerCase().startsWith("sip:")
+ ? uriString
+ : "sip:" + uriString);
+ }
+
+ /**
+ * Sets the name of the profile. This name is given by user.
+ *
+ * @param name name of the profile
+ * @return this builder object
+ */
+ public Builder setProfileName(String name) {
+ mProfile.mProfileName = name;
+ return this;
+ }
+
+ /**
+ * Sets the password of the SIP account
+ *
+ * @param password password of the SIP account
+ * @return this builder object
+ */
+ public Builder setPassword(String password) {
+ mUri.setUserPassword(password);
+ return this;
+ }
+
+ /**
+ * Sets the port number of the server. By default, it is 5060.
+ *
+ * @param port port number of the server
+ * @return this builder object
+ * @throws InvalidArgumentException if the port number is out of range
+ */
+ public Builder setPort(int port) throws InvalidArgumentException {
+ mUri.setPort(port);
+ return this;
+ }
+
+ /**
+ * Sets the protocol used to connect to the SIP server. Currently,
+ * only "UDP" and "TCP" are supported.
+ *
+ * @param protocol the protocol string
+ * @return this builder object
+ * @throws InvalidArgumentException if the protocol is not recognized
+ */
+ public Builder setProtocol(String protocol)
+ throws InvalidArgumentException {
+ if (protocol == null) {
+ throw new NullPointerException("protocol cannot be null");
+ }
+ protocol = protocol.toUpperCase();
+ if (!protocol.equals("UDP") && !protocol.equals("TCP")) {
+ throw new InvalidArgumentException(
+ "unsupported protocol: " + protocol);
+ }
+ mProfile.mProtocol = protocol;
+ return this;
+ }
+
+ /**
+ * Sets the outbound proxy of the SIP server.
+ *
+ * @param outboundProxy the network address of the outbound proxy
+ * @return this builder object
+ */
+ public Builder setOutboundProxy(String outboundProxy) {
+ mProxyAddress = outboundProxy;
+ return this;
+ }
+
+ /**
+ * Sets the display name of the user.
+ *
+ * @param displayName display name of the user
+ * @return this builder object
+ */
+ public Builder setDisplayName(String displayName) {
+ mDisplayName = displayName;
+ return this;
+ }
+
+ /**
+ * Sets the send keep-alive flag.
+ *
+ * @param flag true if sending keep-alive message is required,
+ * false otherwise
+ * @return this builder object
+ */
+ public Builder setSendKeepAlive(boolean flag) {
+ mProfile.mSendKeepAlive = flag;
+ return this;
+ }
+
+
+ /**
+ * Sets the auto. registration flag.
+ *
+ * @param flag true if the profile will be registered automatically,
+ * false otherwise
+ * @return this builder object
+ */
+ public Builder setAutoRegistration(boolean flag) {
+ mProfile.mAutoRegistration = flag;
+ return this;
+ }
+
+ /**
+ * Builds and returns the SIP profile object.
+ *
+ * @return the profile object created
+ */
+ public SipProfile build() {
+ // remove password from URI
+ mProfile.mPassword = mUri.getUserPassword();
+ mUri.setUserPassword(null);
+ try {
+ mProfile.mAddress = mAddressFactory.createAddress(
+ mDisplayName, mUri);
+ if (!TextUtils.isEmpty(mProxyAddress)) {
+ SipURI uri = (SipURI)
+ mAddressFactory.createURI(fix(mProxyAddress));
+ mProfile.mProxyAddress = uri.getHost();
+ }
+ } catch (ParseException e) {
+ // must not occur
+ throw new RuntimeException(e);
+ }
+ return mProfile;
+ }
+ }
+
+ private SipProfile() {
+ }
+
+ private SipProfile(Parcel in) {
+ mAddress = (Address) in.readSerializable();
+ mProxyAddress = in.readString();
+ mPassword = in.readString();
+ mDomain = in.readString();
+ mProtocol = in.readString();
+ mProfileName = in.readString();
+ mSendKeepAlive = (in.readInt() == 0) ? false : true;
+ mAutoRegistration = (in.readInt() == 0) ? false : true;
+ }
+
+ /** @hide */
+ public void writeToParcel(Parcel out, int flags) {
+ out.writeSerializable(mAddress);
+ out.writeString(mProxyAddress);
+ out.writeString(mPassword);
+ out.writeString(mDomain);
+ out.writeString(mProtocol);
+ out.writeString(mProfileName);
+ out.writeInt(mSendKeepAlive ? 1 : 0);
+ out.writeInt(mAutoRegistration ? 1 : 0);
+ }
+
+ /** @hide */
+ public int describeContents() {
+ return 0;
+ }
+
+ /**
+ * Gets the SIP URI of this profile.
+ *
+ * @return the SIP URI of this profile
+ */
+ public SipURI getUri() {
+ return (SipURI) mAddress.getURI();
+ }
+
+ /**
+ * Gets the SIP URI string of this profile.
+ *
+ * @return the SIP URI string of this profile
+ */
+ public String getUriString() {
+ return mAddress.getURI().toString();
+ }
+
+ /**
+ * Gets the SIP address of this profile.
+ *
+ * @return the SIP address of this profile
+ */
+ public Address getSipAddress() {
+ return mAddress;
+ }
+
+ /**
+ * Gets the display name of the user.
+ *
+ * @return the display name of the user
+ */
+ public String getDisplayName() {
+ return mAddress.getDisplayName();
+ }
+
+ /**
+ * Gets the username.
+ *
+ * @return the username
+ */
+ public String getUserName() {
+ return getUri().getUser();
+ }
+
+ /**
+ * Gets the password.
+ *
+ * @return the password
+ */
+ public String getPassword() {
+ return mPassword;
+ }
+
+ /**
+ * Gets the SIP domain.
+ *
+ * @return the SIP domain
+ */
+ public String getSipDomain() {
+ return mDomain;
+ }
+
+ /**
+ * Gets the port number of the SIP server.
+ *
+ * @return the port number of the SIP server
+ */
+ public int getPort() {
+ int port = getUri().getPort();
+ return (port == -1) ? DEFAULT_PORT : port;
+ }
+
+ /**
+ * Gets the protocol used to connect to the server.
+ *
+ * @return the protocol
+ */
+ public String getProtocol() {
+ return mProtocol;
+ }
+
+ /**
+ * Gets the network address of the server outbound proxy.
+ *
+ * @return the network address of the server outbound proxy
+ */
+ public String getProxyAddress() {
+ return mProxyAddress;
+ }
+
+ /**
+ * Gets the (user-defined) name of the profile.
+ *
+ * @return name of the profile
+ */
+ public String getProfileName() {
+ return mProfileName;
+ }
+
+ /**
+ * Gets the flag of 'Sending keep-alive'.
+ *
+ * @return the flag of sending SIP keep-alive messages.
+ */
+ public boolean getSendKeepAlive() {
+ return mSendKeepAlive;
+ }
+
+ /**
+ * Gets the flag of 'Auto Registration'.
+ *
+ * @return the flag of registering the profile automatically.
+ */
+ public boolean getAutoRegistration() {
+ return mAutoRegistration;
+ }
+}
diff --git a/voip/java/android/net/sip/SipRegistrationListener.java b/voip/java/android/net/sip/SipRegistrationListener.java
new file mode 100644
index 0000000..63faaf8
--- /dev/null
+++ b/voip/java/android/net/sip/SipRegistrationListener.java
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+/**
+ * Listener class to listen to SIP registration events.
+ * @hide
+ */
+public interface SipRegistrationListener {
+ /**
+ * Called when a registration request is sent.
+ *
+ * @param localProfileUri the URI string of the SIP profile to register with
+ */
+ void onRegistering(String localProfileUri);
+
+ /**
+ * Called when registration is successfully done.
+ *
+ * @param localProfileUri the URI string of the SIP profile to register with
+ * @param expiryTime duration in second before the registration expires
+ */
+ void onRegistrationDone(String localProfileUri, long expiryTime);
+
+ /**
+ * Called when the registration fails.
+ *
+ * @param localProfileUri the URI string of the SIP profile to register with
+ * @param errorClass name of the exception class
+ * @param errorMessage error message
+ */
+ void onRegistrationFailed(String localProfileUri, String errorClass,
+ String errorMessage);
+}
diff --git a/voip/java/android/net/sip/SipSessionAdapter.java b/voip/java/android/net/sip/SipSessionAdapter.java
new file mode 100644
index 0000000..cfb71d7
--- /dev/null
+++ b/voip/java/android/net/sip/SipSessionAdapter.java
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+/**
+ * Adapter class for {@link ISipSessionListener}. Default implementation of all
+ * callback methods is no-op.
+ * @hide
+ */
+public class SipSessionAdapter extends ISipSessionListener.Stub {
+ public void onCalling(ISipSession session) {
+ }
+
+ public void onRinging(ISipSession session, SipProfile caller,
+ byte[] sessionDescription) {
+ }
+
+ public void onRingingBack(ISipSession session) {
+ }
+
+ public void onCallEstablished(
+ ISipSession session, byte[] sessionDescription) {
+ }
+
+ public void onCallEnded(ISipSession session) {
+ }
+
+ public void onCallBusy(ISipSession session) {
+ }
+
+ public void onCallChanged(ISipSession session, byte[] sessionDescription) {
+ }
+
+ public void onCallChangeFailed(ISipSession session, String className,
+ String message) {
+ }
+
+ public void onError(ISipSession session, String className, String message) {
+ }
+
+ public void onRegistering(ISipSession session) {
+ }
+
+ public void onRegistrationDone(ISipSession session, int duration) {
+ }
+
+ public void onRegistrationFailed(ISipSession session, String className,
+ String message) {
+ }
+
+ public void onRegistrationTimeout(ISipSession session) {
+ }
+}
diff --git a/voip/java/android/net/sip/SipSessionState.java b/voip/java/android/net/sip/SipSessionState.java
new file mode 100644
index 0000000..5bab112
--- /dev/null
+++ b/voip/java/android/net/sip/SipSessionState.java
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+package android.net.sip;
+
+/**
+ * Defines {@link ISipSession} states.
+ * @hide
+ */
+public enum SipSessionState {
+ /** When session is ready to initiate a call or transaction. */
+ READY_TO_CALL,
+
+ /** When the registration request is sent out. */
+ REGISTERING,
+
+ /** When the unregistration request is sent out. */
+ DEREGISTERING,
+
+ /** When an INVITE request is received. */
+ INCOMING_CALL,
+
+ /** When an OK response is sent for the INVITE request received. */
+ INCOMING_CALL_ANSWERING,
+
+ /** When an INVITE request is sent. */
+ OUTGOING_CALL,
+
+ /** When a RINGING response is received for the INVITE request sent. */
+ OUTGOING_CALL_RING_BACK,
+
+ /** When a CANCEL request is sent for the INVITE request sent. */
+ OUTGOING_CALL_CANCELING,
+
+ /** When a call is established. */
+ IN_CALL,
+
+ /** Some error occurs when making a remote call to {@link ISipSession}. */
+ REMOTE_ERROR,
+
+ /** When an OPTIONS request is sent. */
+ PINGING;
+
+ /**
+ * Checks if the specified string represents the same state as this object.
+ *
+ * @return true if the specified string represents the same state as this
+ * object
+ */
+ public boolean equals(String state) {
+ return toString().equals(state);
+ }
+}