summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Android.mk11
-rw-r--r--api/current.txt88
-rw-r--r--cmds/stagefright/stagefright.cpp2
-rw-r--r--core/java/android/accessibilityservice/AccessibilityServiceInfo.java11
-rw-r--r--core/java/android/app/ContextImpl.java15
-rw-r--r--core/java/android/app/FragmentManager.java1
-rw-r--r--core/java/android/appwidget/AppWidgetManager.java8
-rw-r--r--core/java/android/appwidget/AppWidgetProviderInfo.java4
-rw-r--r--core/java/android/content/Context.java20
-rw-r--r--core/java/android/content/pm/Signature.java25
-rw-r--r--core/java/android/net/ConnectivityManager.java11
-rw-r--r--core/java/android/net/IConnectivityManager.aidl2
-rw-r--r--core/java/android/net/LinkProperties.java4
-rw-r--r--core/java/android/os/Handler.java9
-rw-r--r--core/java/android/os/INetworkManagementService.aidl2
-rw-r--r--core/java/android/preference/CheckBoxPreference.java4
-rw-r--r--core/java/android/preference/SwitchPreference.java4
-rw-r--r--core/java/android/preference/TwoStatePreference.java45
-rw-r--r--core/java/android/provider/CallLog.java10
-rw-r--r--core/java/android/provider/ContactsContract.java33
-rw-r--r--core/java/android/provider/Settings.java22
-rw-r--r--core/java/android/provider/VoicemailContract.java6
-rw-r--r--core/java/android/server/BluetoothAdapterStateMachine.java513
-rw-r--r--core/java/android/server/BluetoothEventLoop.java18
-rwxr-xr-xcore/java/android/server/BluetoothService.java304
-rw-r--r--core/java/android/service/textservice/SpellCheckerService.java141
-rw-r--r--core/java/android/service/textservice/SpellCheckerSession.java284
-rw-r--r--core/java/android/util/JsonReader.java6
-rw-r--r--core/java/android/view/Surface.java18
-rw-r--r--core/java/android/view/View.java43
-rw-r--r--core/java/android/view/ViewGroup.java2
-rw-r--r--core/java/android/view/accessibility/AccessibilityManager.java44
-rw-r--r--core/java/android/view/accessibility/AccessibilityNodeInfo.java4
-rw-r--r--core/java/android/view/accessibility/IAccessibilityManager.aidl2
-rw-r--r--core/java/android/view/accessibility/IAccessibilityManagerClient.aidl4
-rw-r--r--core/java/android/view/animation/AlphaAnimation.java8
-rw-r--r--core/java/android/view/animation/Animation.java9
-rw-r--r--core/java/android/view/animation/AnimationSet.java26
-rw-r--r--core/java/android/view/textservice/SpellCheckerInfo.aidl19
-rw-r--r--core/java/android/view/textservice/SpellCheckerInfo.java132
-rw-r--r--core/java/android/view/textservice/SuggestionsInfo.aidl19
-rw-r--r--core/java/android/view/textservice/SuggestionsInfo.java186
-rw-r--r--core/java/android/view/textservice/TextInfo.aidl19
-rw-r--r--core/java/android/view/textservice/TextInfo.java117
-rw-r--r--core/java/android/view/textservice/TextServicesManager.java123
-rw-r--r--core/java/android/webkit/JniUtil.java15
-rw-r--r--core/java/android/webkit/WebView.java5
-rw-r--r--core/java/android/widget/PopupWindow.java21
-rw-r--r--core/java/android/widget/SearchView.java47
-rw-r--r--core/java/android/widget/Switch.java8
-rw-r--r--core/java/com/android/internal/textservice/ISpellCheckerService.aidl29
-rw-r--r--core/java/com/android/internal/textservice/ISpellCheckerSession.aidl28
-rw-r--r--core/java/com/android/internal/textservice/ISpellCheckerSessionListener.aidl26
-rw-r--r--core/java/com/android/internal/textservice/ITextServicesManager.aidl36
-rw-r--r--core/java/com/android/internal/textservice/ITextServicesSessionListener.aidl29
-rw-r--r--core/java/com/android/internal/util/Protocol.java3
-rw-r--r--core/java/com/android/internal/widget/ActionBarView.java18
-rw-r--r--core/jni/android_net_wifi_Wifi.cpp35
-rw-r--r--core/jni/android_view_Surface.cpp36
-rw-r--r--core/res/AndroidManifest.xml7
-rw-r--r--core/res/res/anim/screen_rotate_minus_90_enter.xml5
-rw-r--r--core/res/res/anim/screen_rotate_plus_90_enter.xml5
-rw-r--r--core/res/res/layout/wifi_p2p_go_negotiation_request_alert.xml26
-rwxr-xr-xcore/res/res/values/attrs.xml2
-rwxr-xr-xcore/res/res/values/config.xml7
-rwxr-xr-xcore/res/res/values/strings.xml14
-rw-r--r--core/tests/coretests/src/android/view/accessibility/RecycleAccessibilityEventTest.java8
-rw-r--r--docs/html/guide/developing/tools/adb.jd2
-rw-r--r--docs/html/guide/topics/intents/intents-filters.jd2
-rw-r--r--docs/html/guide/topics/manifest/activity-element.jd4
-rw-r--r--docs/html/guide/topics/providers/content-providers.jd2
-rw-r--r--graphics/jni/android_renderscript_RenderScript.cpp1
-rw-r--r--include/gui/ISurfaceTexture.h8
-rw-r--r--include/gui/SurfaceTexture.h28
-rw-r--r--include/gui/SurfaceTextureClient.h4
-rw-r--r--include/media/IMediaRecorder.h2
-rw-r--r--include/media/MediaRecorderBase.h2
-rw-r--r--include/media/mediarecorder.h10
-rw-r--r--include/media/stagefright/DataSource.h5
-rw-r--r--include/media/stagefright/HardwareAPI.h7
-rw-r--r--include/media/stagefright/MediaSource.h2
-rw-r--r--include/media/stagefright/OMXCodec.h8
-rw-r--r--include/media/stagefright/SurfaceMediaSource.h350
-rw-r--r--include/surfaceflinger/Surface.h7
-rw-r--r--include/ui/PixelFormat.h10
-rw-r--r--libs/gui/ISurfaceTexture.cpp28
-rw-r--r--libs/gui/Surface.cpp56
-rw-r--r--libs/gui/SurfaceTexture.cpp118
-rw-r--r--libs/gui/SurfaceTextureClient.cpp15
-rw-r--r--libs/gui/tests/SurfaceTexture_test.cpp183
-rw-r--r--libs/ui/FramebufferNativeWindow.cpp28
-rw-r--r--media/java/android/media/AudioFormat.java28
-rw-r--r--media/java/android/media/MediaPlayer.java29
-rw-r--r--media/java/android/media/MediaRecorder.java97
-rw-r--r--media/jni/android_media_MediaRecorder.cpp17
-rw-r--r--media/libmedia/IMediaRecorder.cpp30
-rw-r--r--media/libmedia/mediaplayer.cpp2
-rw-r--r--media/libmedia/mediarecorder.cpp33
-rw-r--r--media/libmediaplayerservice/MediaRecorderClient.cpp15
-rw-r--r--media/libmediaplayerservice/MediaRecorderClient.h68
-rw-r--r--media/libmediaplayerservice/StagefrightRecorder.cpp109
-rw-r--r--media/libmediaplayerservice/StagefrightRecorder.h18
-rw-r--r--media/libstagefright/Android.mk1
-rw-r--r--media/libstagefright/NuCachedSource2.cpp61
-rwxr-xr-xmedia/libstagefright/OMXCodec.cpp40
-rw-r--r--media/libstagefright/SurfaceMediaSource.cpp756
-rw-r--r--media/libstagefright/WAVExtractor.cpp4
-rw-r--r--media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp34
-rw-r--r--media/libstagefright/include/ChromiumHTTPDataSource.h2
-rw-r--r--media/libstagefright/include/NuCachedSource2.h6
-rw-r--r--media/libstagefright/tests/Android.mk53
-rw-r--r--media/libstagefright/tests/DummyRecorder.cpp91
-rw-r--r--media/libstagefright/tests/DummyRecorder.h58
-rw-r--r--media/libstagefright/tests/SurfaceMediaSource_test.cpp349
-rw-r--r--packages/SystemUI/res/values/config.xml2
-rw-r--r--packages/SystemUI/res/values/strings.xml5
-rw-r--r--packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java6
-rw-r--r--policy/src/com/android/internal/policy/impl/PhoneWindow.java3
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java49
-rw-r--r--services/audioflinger/AudioFlinger.cpp40
-rw-r--r--services/audioflinger/AudioFlinger.h2
-rw-r--r--services/java/com/android/server/AppWidgetService.java6
-rw-r--r--services/java/com/android/server/ConnectivityService.java95
-rw-r--r--services/java/com/android/server/InputMethodManagerService.java22
-rw-r--r--services/java/com/android/server/NetworkManagementService.java5
-rw-r--r--services/java/com/android/server/SystemServer.java21
-rw-r--r--services/java/com/android/server/TextServicesManagerService.java357
-rw-r--r--services/java/com/android/server/accessibility/AccessibilityManagerService.java95
-rw-r--r--services/java/com/android/server/accessibility/TouchExplorer.java166
-rw-r--r--services/java/com/android/server/connectivity/Tethering.java175
-rw-r--r--services/java/com/android/server/connectivity/Vpn.java2
-rw-r--r--services/java/com/android/server/pm/PackageManagerService.java11
-rw-r--r--services/java/com/android/server/wm/BlackFrame.java4
-rw-r--r--services/surfaceflinger/SurfaceTextureLayer.cpp6
-rw-r--r--services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java26
-rw-r--r--services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java16
-rw-r--r--telephony/java/com/android/internal/telephony/DataConnectionTracker.java22
-rw-r--r--telephony/java/com/android/internal/telephony/RILConstants.java2
-rw-r--r--telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java11
-rw-r--r--telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java35
-rw-r--r--tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java2
-rw-r--r--wifi/java/android/net/wifi/StateChangeResult.java34
-rw-r--r--wifi/java/android/net/wifi/SupplicantStateTracker.java10
-rw-r--r--wifi/java/android/net/wifi/WifiMonitor.java296
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java151
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java411
-rw-r--r--wifi/java/android/net/wifi/WifiWatchdogStateMachine.java2
-rw-r--r--wifi/java/android/net/wifi/WpsConfiguration.java13
-rw-r--r--wifi/java/android/net/wifi/WpsStateMachine.java10
-rw-r--r--wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl31
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pConfig.aidl19
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pConfig.java161
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDevice.aidl19
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDevice.java312
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.aidl19
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java111
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pGroup.aidl19
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pGroup.java224
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pManager.java344
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pService.java880
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pStatus.aidl19
-rw-r--r--wifi/java/android/net/wifi/p2p/WifiP2pStatus.java82
162 files changed, 8668 insertions, 1256 deletions
diff --git a/Android.mk b/Android.mk
index 335fb73..7b8d0bc 100644
--- a/Android.mk
+++ b/Android.mk
@@ -158,6 +158,11 @@ LOCAL_SRC_FILES += \
core/java/com/android/internal/os/IResultReceiver.aidl \
core/java/com/android/internal/statusbar/IStatusBar.aidl \
core/java/com/android/internal/statusbar/IStatusBarService.aidl \
+ core/java/com/android/internal/textservice/ISpellCheckerService.aidl \
+ core/java/com/android/internal/textservice/ISpellCheckerSession.aidl \
+ core/java/com/android/internal/textservice/ISpellCheckerSessionListener.aidl \
+ core/java/com/android/internal/textservice/ITextServicesManager.aidl \
+ core/java/com/android/internal/textservice/ITextServicesSessionListener.aidl \
core/java/com/android/internal/view/IInputContext.aidl \
core/java/com/android/internal/view/IInputContextCallback.aidl \
core/java/com/android/internal/view/IInputMethod.aidl \
@@ -190,6 +195,7 @@ LOCAL_SRC_FILES += \
telephony/java/com/android/internal/telephony/ISms.aidl \
telephony/java/com/android/internal/telephony/IWapPushManager.aidl \
wifi/java/android/net/wifi/IWifiManager.aidl \
+ wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl \
telephony/java/com/android/internal/telephony/IExtendedNetworkService.aidl \
voip/java/android/net/sip/ISipSession.aidl \
voip/java/android/net/sip/ISipSessionListener.aidl \
@@ -266,6 +272,11 @@ aidl_files := \
frameworks/base/core/java/android/view/Surface.aidl \
frameworks/base/core/java/android/view/WindowManager.aidl \
frameworks/base/core/java/android/widget/RemoteViews.aidl \
+ frameworks/base/core/java/com/android/internal/textservice/ISpellCheckerService.aidl \
+ frameworks/base/core/java/com/android/internal/textservice/ISpellCheckerSession.aidl \
+ frameworks/base/core/java/com/android/internal/textservice/ISpellCheckerSessionListener.aidl \
+ frameworks/base/core/java/com/android/internal/textservice/ITextServicesManager.aidl \
+ frameworks/base/core/java/com/android/internal/textservice/ITextServicesSessionListener.aidl \
frameworks/base/core/java/com/android/internal/view/IInputContext.aidl \
frameworks/base/core/java/com/android/internal/view/IInputMethod.aidl \
frameworks/base/core/java/com/android/internal/view/IInputMethodCallback.aidl \
diff --git a/api/current.txt b/api/current.txt
index a499cee..a71c866 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -21,6 +21,7 @@ package android {
field public static final java.lang.String BIND_DEVICE_ADMIN = "android.permission.BIND_DEVICE_ADMIN";
field public static final java.lang.String BIND_INPUT_METHOD = "android.permission.BIND_INPUT_METHOD";
field public static final java.lang.String BIND_REMOTEVIEWS = "android.permission.BIND_REMOTEVIEWS";
+ field public static final java.lang.String BIND_TEXT_SERVICE = "android.permission.BIND_TEXT_SERVICE";
field public static final java.lang.String BIND_WALLPAPER = "android.permission.BIND_WALLPAPER";
field public static final java.lang.String BLUETOOTH = "android.permission.BLUETOOTH";
field public static final java.lang.String BLUETOOTH_ADMIN = "android.permission.BLUETOOTH_ADMIN";
@@ -1827,6 +1828,7 @@ package android.accessibilityservice {
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator CREATOR;
field public static final int DEFAULT = 1; // 0x1
+ field public static final int FEEDBACK_ALL_MASK = -1; // 0xffffffff
field public static final int FEEDBACK_AUDIBLE = 4; // 0x4
field public static final int FEEDBACK_GENERIC = 16; // 0x10
field public static final int FEEDBACK_HAPTIC = 2; // 0x2
@@ -4783,6 +4785,7 @@ package android.content {
field public static final java.lang.String SENSOR_SERVICE = "sensor";
field public static final java.lang.String STORAGE_SERVICE = "storage";
field public static final java.lang.String TELEPHONY_SERVICE = "phone";
+ field public static final java.lang.String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
field public static final java.lang.String UI_MODE_SERVICE = "uimode";
field public static final java.lang.String USB_SERVICE = "usb";
field public static final java.lang.String VIBRATOR_SERVICE = "vibrator";
@@ -10404,8 +10407,8 @@ package android.media {
method public void setAudioEncodingBitRate(int);
method public void setAudioSamplingRate(int);
method public void setAudioSource(int) throws java.lang.IllegalStateException;
- method public void setAuxiliaryOutputFile(java.io.FileDescriptor);
- method public void setAuxiliaryOutputFile(java.lang.String);
+ method public deprecated void setAuxiliaryOutputFile(java.io.FileDescriptor);
+ method public deprecated void setAuxiliaryOutputFile(java.lang.String);
method public void setCamera(android.hardware.Camera);
method public void setCaptureRate(double);
method public void setLocation(float, float);
@@ -16708,7 +16711,7 @@ package android.provider {
field public static final java.lang.String SELECTED_INPUT_METHOD_SUBTYPE = "selected_input_method_subtype";
field public static final java.lang.String SETTINGS_CLASSNAME = "settings_classname";
field public static final java.lang.String SYS_PROP_SETTING_VERSION = "sys.settings_secure_version";
- field public static final java.lang.String TOUCH_EXPLORATION_REQUESTED = "touch_exploration_requested";
+ field public static final java.lang.String TOUCH_EXPLORATION_ENABLED = "touch_exploration_enabled";
field public static final java.lang.String TTS_DEFAULT_COUNTRY = "tts_default_country";
field public static final java.lang.String TTS_DEFAULT_LANG = "tts_default_lang";
field public static final java.lang.String TTS_DEFAULT_PITCH = "tts_default_pitch";
@@ -17941,6 +17944,31 @@ package android.security {
}
+package android.service.textservice {
+
+ public abstract class SpellCheckerService extends android.app.Service {
+ ctor public SpellCheckerService();
+ method public void cancel();
+ method public abstract android.view.textservice.SuggestionsInfo getSuggestions(android.view.textservice.TextInfo, int, java.lang.String);
+ method public android.view.textservice.SuggestionsInfo[] getSuggestionsMultiple(android.view.textservice.TextInfo[], java.lang.String, int, boolean);
+ method public final android.os.IBinder onBind(android.content.Intent);
+ field public static final java.lang.String SERVICE_INTERFACE = "android.service.textservice.SpellCheckerService";
+ }
+
+ public class SpellCheckerSession {
+ method public void close();
+ method public android.view.textservice.SpellCheckerInfo getSpellChecker();
+ method public void getSuggestions(android.view.textservice.TextInfo, int);
+ method public void getSuggestions(android.view.textservice.TextInfo[], int, boolean);
+ method public boolean isSessionDisconnected();
+ }
+
+ public static abstract interface SpellCheckerSession.SpellCheckerSessionListener {
+ method public abstract void onGetSuggestions(android.view.textservice.SuggestionsInfo[]);
+ }
+
+}
+
package android.service.wallpaper {
public abstract class WallpaperService extends android.app.Service {
@@ -22205,6 +22233,7 @@ package android.view {
method public final android.view.View findViewWithTag(java.lang.Object);
method public void findViewsWithText(java.util.ArrayList<android.view.View>, java.lang.CharSequence);
method protected boolean fitSystemWindows(android.graphics.Rect);
+ method public boolean fitsSystemWindows();
method public android.view.View focusSearch(int);
method public void forceLayout();
method public float getAlpha();
@@ -22446,6 +22475,7 @@ package android.view {
method public void setEnabled(boolean);
method public void setFadingEdgeLength(int);
method public void setFilterTouchesWhenObscured(boolean);
+ method public void setFitsSystemWindows(boolean);
method public void setFocusable(boolean);
method public void setFocusableInTouchMode(boolean);
method public void setHapticFeedbackEnabled(boolean);
@@ -24021,6 +24051,54 @@ package android.view.inputmethod {
}
+package android.view.textservice {
+
+ public final class SpellCheckerInfo implements android.os.Parcelable {
+ method public int describeContents();
+ method public android.content.ComponentName getComponent();
+ method public java.lang.String getId();
+ method public java.lang.String getPackageName();
+ method public android.graphics.drawable.Drawable loadIcon(android.content.pm.PackageManager);
+ method public java.lang.CharSequence loadLabel(android.content.pm.PackageManager);
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator CREATOR;
+ }
+
+ public final class SuggestionsInfo implements android.os.Parcelable {
+ ctor public SuggestionsInfo(int, java.lang.String[]);
+ ctor public SuggestionsInfo(int, java.lang.String[], int, int);
+ ctor public SuggestionsInfo(android.os.Parcel);
+ method public int describeContents();
+ method public int getCookie();
+ method public int getSequence();
+ method public java.lang.String getSuggestionAt(int);
+ method public int getSuggestionsAttributes();
+ method public int getSuggestionsCount();
+ method public void setCookieAndSequence(int, int);
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator CREATOR;
+ field public static final int RESULT_ATTR_IN_THE_DICTIONARY = 1; // 0x1
+ field public static final int RESULT_ATTR_LOOKS_TYPO = 2; // 0x2
+ }
+
+ public final class TextInfo implements android.os.Parcelable {
+ ctor public TextInfo(java.lang.String);
+ ctor public TextInfo(java.lang.String, int, int);
+ ctor public TextInfo(android.os.Parcel);
+ method public int describeContents();
+ method public int getCookie();
+ method public int getSequence();
+ method public java.lang.String getText();
+ method public void writeToParcel(android.os.Parcel, int);
+ field public static final android.os.Parcelable.Creator CREATOR;
+ }
+
+ public final class TextServicesManager {
+ method public android.service.textservice.SpellCheckerSession newSpellCheckerSession(java.util.Locale, android.service.textservice.SpellCheckerSession.SpellCheckerSessionListener, boolean);
+ }
+
+}
+
package android.webkit {
public final deprecated class CacheManager {
@@ -26123,7 +26201,7 @@ package android.widget {
method public int timePassed();
}
- public class SearchView extends android.widget.LinearLayout {
+ public class SearchView extends android.widget.LinearLayout implements android.view.CollapsibleActionView {
ctor public SearchView(android.content.Context);
ctor public SearchView(android.content.Context, android.util.AttributeSet);
method public java.lang.CharSequence getQuery();
@@ -26132,6 +26210,8 @@ package android.widget {
method public boolean isIconified();
method public boolean isQueryRefinementEnabled();
method public boolean isSubmitButtonEnabled();
+ method public void onActionViewCollapsed();
+ method public void onActionViewExpanded();
method public void setIconified(boolean);
method public void setIconifiedByDefault(boolean);
method public void setMaxWidth(int);
diff --git a/cmds/stagefright/stagefright.cpp b/cmds/stagefright/stagefright.cpp
index b42f1c5..34f0a64 100644
--- a/cmds/stagefright/stagefright.cpp
+++ b/cmds/stagefright/stagefright.cpp
@@ -803,9 +803,9 @@ int main(int argc, char **argv) {
printf("type '%s':\n", kMimeTypes[k]);
Vector<CodecCapabilities> results;
+ // will retrieve hardware and software codecs
CHECK_EQ(QueryCodecs(omx, kMimeTypes[k],
true, // queryDecoders
- false, // hwCodecOnly
&results), (status_t)OK);
for (size_t i = 0; i < results.size(); ++i) {
diff --git a/core/java/android/accessibilityservice/AccessibilityServiceInfo.java b/core/java/android/accessibilityservice/AccessibilityServiceInfo.java
index a09607a..41a3eac 100644
--- a/core/java/android/accessibilityservice/AccessibilityServiceInfo.java
+++ b/core/java/android/accessibilityservice/AccessibilityServiceInfo.java
@@ -75,6 +75,17 @@ public class AccessibilityServiceInfo implements Parcelable {
public static final int FEEDBACK_GENERIC = 0x0000010;
/**
+ * Mask for all feedback types.
+ *
+ * @see #FEEDBACK_SPOKEN
+ * @see #FEEDBACK_HAPTIC
+ * @see #FEEDBACK_AUDIBLE
+ * @see #FEEDBACK_VISUAL
+ * @see #FEEDBACK_GENERIC
+ */
+ public static final int FEEDBACK_ALL_MASK = 0xFFFFFFFF;
+
+ /**
* If an {@link AccessibilityService} is the default for a given type.
* Default service is invoked only if no package specific one exists. In case of
* more than one package specific service only the earlier registered is notified.
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index d2323e7..a99cec2 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -59,6 +59,8 @@ import android.net.IThrottleManager;
import android.net.Uri;
import android.net.wifi.IWifiManager;
import android.net.wifi.WifiManager;
+import android.net.wifi.p2p.IWifiP2pManager;
+import android.net.wifi.p2p.WifiP2pManager;
import android.nfc.NfcManager;
import android.os.Binder;
import android.os.Bundle;
@@ -83,6 +85,7 @@ import android.view.ContextThemeWrapper;
import android.view.WindowManagerImpl;
import android.view.accessibility.AccessibilityManager;
import android.view.inputmethod.InputMethodManager;
+import android.view.textservice.TextServicesManager;
import android.accounts.AccountManager;
import android.accounts.IAccountManager;
import android.app.admin.DevicePolicyManager;
@@ -320,6 +323,11 @@ class ContextImpl extends Context {
return InputMethodManager.getInstance(ctx);
}});
+ registerService(TEXT_SERVICES_MANAGER_SERVICE, new ServiceFetcher() {
+ public Object createService(ContextImpl ctx) {
+ return TextServicesManager.getInstance();
+ }});
+
registerService(KEYGUARD_SERVICE, new ServiceFetcher() {
public Object getService(ContextImpl ctx) {
// TODO: why isn't this caching it? It wasn't
@@ -432,6 +440,13 @@ class ContextImpl extends Context {
return new WifiManager(service, ctx.mMainThread.getHandler());
}});
+ registerService(WIFI_P2P_SERVICE, new ServiceFetcher() {
+ public Object createService(ContextImpl ctx) {
+ IBinder b = ServiceManager.getService(WIFI_P2P_SERVICE);
+ IWifiP2pManager service = IWifiP2pManager.Stub.asInterface(b);
+ return new WifiP2pManager(service);
+ }});
+
registerService(WINDOW_SERVICE, new ServiceFetcher() {
public Object getService(ContextImpl ctx) {
return WindowManagerImpl.getDefault(ctx.mPackageInfo.mCompatibilityInfo);
diff --git a/core/java/android/app/FragmentManager.java b/core/java/android/app/FragmentManager.java
index c82c9ec..789d3a6 100644
--- a/core/java/android/app/FragmentManager.java
+++ b/core/java/android/app/FragmentManager.java
@@ -1695,6 +1695,7 @@ final class FragmentManagerImpl extends FragmentManager {
public void dispatchDestroy() {
mDestroyed = true;
+ execPendingActions();
moveToState(Fragment.INITIALIZING, false);
mActivity = null;
}
diff --git a/core/java/android/appwidget/AppWidgetManager.java b/core/java/android/appwidget/AppWidgetManager.java
index 019652c..1ef99a1 100644
--- a/core/java/android/appwidget/AppWidgetManager.java
+++ b/core/java/android/appwidget/AppWidgetManager.java
@@ -388,6 +388,10 @@ public class AppWidgetManager {
TypedValue.complexToDimensionPixelSize(info.minWidth, mDisplayMetrics);
info.minHeight =
TypedValue.complexToDimensionPixelSize(info.minHeight, mDisplayMetrics);
+ info.minResizeWidth =
+ TypedValue.complexToDimensionPixelSize(info.minResizeWidth, mDisplayMetrics);
+ info.minResizeHeight =
+ TypedValue.complexToDimensionPixelSize(info.minResizeHeight, mDisplayMetrics);
}
return providers;
}
@@ -411,6 +415,10 @@ public class AppWidgetManager {
TypedValue.complexToDimensionPixelSize(info.minWidth, mDisplayMetrics);
info.minHeight =
TypedValue.complexToDimensionPixelSize(info.minHeight, mDisplayMetrics);
+ info.minResizeWidth =
+ TypedValue.complexToDimensionPixelSize(info.minResizeWidth, mDisplayMetrics);
+ info.minResizeHeight =
+ TypedValue.complexToDimensionPixelSize(info.minResizeHeight, mDisplayMetrics);
}
return info;
}
diff --git a/core/java/android/appwidget/AppWidgetProviderInfo.java b/core/java/android/appwidget/AppWidgetProviderInfo.java
index b8c5b02..9c352d5 100644
--- a/core/java/android/appwidget/AppWidgetProviderInfo.java
+++ b/core/java/android/appwidget/AppWidgetProviderInfo.java
@@ -187,6 +187,8 @@ public class AppWidgetProviderInfo implements Parcelable {
}
this.minWidth = in.readInt();
this.minHeight = in.readInt();
+ this.minResizeWidth = in.readInt();
+ this.minResizeHeight = in.readInt();
this.updatePeriodMillis = in.readInt();
this.initialLayout = in.readInt();
if (0 != in.readInt()) {
@@ -208,6 +210,8 @@ public class AppWidgetProviderInfo implements Parcelable {
}
out.writeInt(this.minWidth);
out.writeInt(this.minHeight);
+ out.writeInt(this.minResizeWidth);
+ out.writeInt(this.minResizeHeight);
out.writeInt(this.updatePeriodMillis);
out.writeInt(this.initialLayout);
if (this.configure != null) {
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index fed6d81..cdda910 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -1572,6 +1572,17 @@ public abstract class Context {
public static final String WIFI_SERVICE = "wifi";
/**
+ * Use with {@link #getSystemService} to retrieve a {@link
+ * android.net.wifi.p2p.WifiP2pManager} for handling management of
+ * Wi-Fi p2p.
+ *
+ * @see #getSystemService
+ * @see android.net.wifi.p2p.WifiP2pManager
+ * @hide
+ */
+ public static final String WIFI_P2P_SERVICE = "wifip2p";
+
+ /**
* Use with {@link #getSystemService} to retrieve a
* {@link android.media.AudioManager} for handling management of volume,
* ringer modes and audio routing.
@@ -1612,6 +1623,15 @@ public abstract class Context {
/**
* Use with {@link #getSystemService} to retrieve a
+ * {@link android.view.textservice.TextServicesManager} for accessing
+ * text services.
+ *
+ * @see #getSystemService
+ */
+ public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
+
+ /**
+ * Use with {@link #getSystemService} to retrieve a
* {@link android.appwidget.AppWidgetManager} for accessing AppWidgets.
*
* @hide
diff --git a/core/java/android/content/pm/Signature.java b/core/java/android/content/pm/Signature.java
index d4e5cc1..b32664e 100644
--- a/core/java/android/content/pm/Signature.java
+++ b/core/java/android/content/pm/Signature.java
@@ -45,16 +45,23 @@ public class Signature implements Parcelable {
* {@link #toChars} or {@link #toCharsString()}.
*/
public Signature(String text) {
- final int N = text.length()/2;
- byte[] sig = new byte[N];
- for (int i=0; i<N; i++) {
- char c = text.charAt(i*2);
- byte b = (byte)(
- (c >= 'a' ? (c - 'a' + 10) : (c - '0'))<<4);
- c = text.charAt(i*2 + 1);
- b |= (byte)(c >= 'a' ? (c - 'a' + 10) : (c - '0'));
- sig[i] = b;
+ final byte[] input = text.getBytes();
+ final int N = input.length;
+ final byte[] sig = new byte[N / 2];
+ int sigIndex = 0;
+
+ for (int i = 0; i < N;) {
+ int b;
+
+ final int hi = input[i++];
+ b = (hi >= 'a' ? (hi - 'a' + 10) : (hi - '0')) << 4;
+
+ final int lo = input[i++];
+ b |= (lo >= 'a' ? (lo - 'a' + 10) : (lo - '0')) & 0x0F;
+
+ sig[sigIndex++] = (byte) (b & 0xFF);
}
+
mSignature = sig;
}
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index ce6f697..a564d97 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -653,6 +653,17 @@ public class ConnectivityManager {
}
}
+ /**
+ * {@hide}
+ */
+ public int setUsbTethering(boolean enable) {
+ try {
+ return mService.setUsbTethering(enable);
+ } catch (RemoteException e) {
+ return TETHER_ERROR_SERVICE_UNAVAIL;
+ }
+ }
+
/** {@hide} */
public static final int TETHER_ERROR_NO_ERROR = 0;
/** {@hide} */
diff --git a/core/java/android/net/IConnectivityManager.aidl b/core/java/android/net/IConnectivityManager.aidl
index d95fc8d..b1d99a4 100644
--- a/core/java/android/net/IConnectivityManager.aidl
+++ b/core/java/android/net/IConnectivityManager.aidl
@@ -88,6 +88,8 @@ interface IConnectivityManager
String[] getTetherableBluetoothRegexs();
+ int setUsbTethering(boolean enable);
+
void requestNetworkTransitionWakelock(in String forWhom);
void reportInetCondition(int networkType, int percentage);
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java
index 9826bec..132f3ba 100644
--- a/core/java/android/net/LinkProperties.java
+++ b/core/java/android/net/LinkProperties.java
@@ -58,8 +58,8 @@ public class LinkProperties implements Parcelable {
private ProxyProperties mHttpProxy;
public static class CompareResult<T> {
- public ArrayList<T> removed = new ArrayList<T>();
- public ArrayList<T> added = new ArrayList<T>();
+ public Collection<T> removed = new ArrayList<T>();
+ public Collection<T> added = new ArrayList<T>();
@Override
public String toString() {
diff --git a/core/java/android/os/Handler.java b/core/java/android/os/Handler.java
index cd39d5c..bc37244 100644
--- a/core/java/android/os/Handler.java
+++ b/core/java/android/os/Handler.java
@@ -361,7 +361,8 @@ public class Handler {
/**
* Remove any pending posts of Runnable <var>r</var> with Object
- * <var>token</var> that are in the message queue.
+ * <var>token</var> that are in the message queue. If <var>token</var> is null,
+ * all callbacks will be removed.
*/
public final void removeCallbacks(Runnable r, Object token)
{
@@ -517,7 +518,8 @@ public class Handler {
/**
* Remove any pending posts of messages with code 'what' and whose obj is
- * 'object' that are in the message queue.
+ * 'object' that are in the message queue. If <var>token</var> is null,
+ * all messages will be removed.
*/
public final void removeMessages(int what, Object object) {
mQueue.removeMessages(this, what, object, true);
@@ -525,7 +527,8 @@ public class Handler {
/**
* Remove any pending posts of callbacks and sent messages whose
- * <var>obj</var> is <var>token</var>.
+ * <var>obj</var> is <var>token</var>. If <var>token</var> is null,
+ * all callbacks and messages will be removed.
*/
public final void removeCallbacksAndMessages(Object token) {
mQueue.removeCallbacksAndMessages(this, token);
diff --git a/core/java/android/os/INetworkManagementService.aidl b/core/java/android/os/INetworkManagementService.aidl
index f230526..1174e3b 100644
--- a/core/java/android/os/INetworkManagementService.aidl
+++ b/core/java/android/os/INetworkManagementService.aidl
@@ -180,7 +180,7 @@ interface INetworkManagementService
/**
* Stop Wifi Access Point
*/
- void stopAccessPoint();
+ void stopAccessPoint(String wlanIface);
/**
* Set Access Point config
diff --git a/core/java/android/preference/CheckBoxPreference.java b/core/java/android/preference/CheckBoxPreference.java
index 437e553..166b21b 100644
--- a/core/java/android/preference/CheckBoxPreference.java
+++ b/core/java/android/preference/CheckBoxPreference.java
@@ -61,8 +61,8 @@ public class CheckBoxPreference extends TwoStatePreference {
View checkboxView = view.findViewById(com.android.internal.R.id.checkbox);
if (checkboxView != null && checkboxView instanceof Checkable) {
((Checkable) checkboxView).setChecked(mChecked);
-
- sendAccessibilityEventForView(checkboxView);
+ // Post this so this view is bound and attached when firing the event.
+ postSendAccessibilityEventForView(checkboxView);
}
syncSummaryView(view);
diff --git a/core/java/android/preference/SwitchPreference.java b/core/java/android/preference/SwitchPreference.java
index f681526..3dbd522 100644
--- a/core/java/android/preference/SwitchPreference.java
+++ b/core/java/android/preference/SwitchPreference.java
@@ -102,8 +102,8 @@ public class SwitchPreference extends TwoStatePreference {
View checkableView = view.findViewById(com.android.internal.R.id.switchWidget);
if (checkableView != null && checkableView instanceof Checkable) {
((Checkable) checkableView).setChecked(mChecked);
-
- sendAccessibilityEventForView(checkableView);
+ // Post this so this view is bound and attached when firing the event.
+ postSendAccessibilityEventForView(checkableView);
if (checkableView instanceof Switch) {
final Switch switchView = (Switch) checkableView;
diff --git a/core/java/android/preference/TwoStatePreference.java b/core/java/android/preference/TwoStatePreference.java
index 8e21c4c..55ef108 100644
--- a/core/java/android/preference/TwoStatePreference.java
+++ b/core/java/android/preference/TwoStatePreference.java
@@ -16,7 +16,6 @@
package android.preference;
-import android.app.Service;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
@@ -39,28 +38,20 @@ public abstract class TwoStatePreference extends Preference {
private CharSequence mSummaryOff;
boolean mChecked;
private boolean mSendAccessibilityEventViewClickedType;
- private AccessibilityManager mAccessibilityManager;
private boolean mDisableDependentsState;
+ private SendAccessibilityEventTypeViewClicked mSendAccessibilityEventTypeViewClicked;
+
public TwoStatePreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
-
- mAccessibilityManager =
- (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
}
public TwoStatePreference(Context context, AttributeSet attrs) {
- super(context, attrs);
-
- mAccessibilityManager =
- (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
+ this(context, attrs, 0);
}
public TwoStatePreference(Context context) {
- super(context);
-
- mAccessibilityManager =
- (AccessibilityManager) getContext().getSystemService(Service.ACCESSIBILITY_SERVICE);
+ this(context, null);
}
@Override
@@ -198,20 +189,23 @@ public abstract class TwoStatePreference extends Preference {
}
/**
- * Send an accessibility event for the given view if appropriate
+ * Post send an accessibility event for the given view if appropriate.
+ *
* @param view View that should send the event
*/
- void sendAccessibilityEventForView(View view) {
+ void postSendAccessibilityEventForView(View view) {
// send an event to announce the value change of the state. It is done here
// because clicking a preference does not immediately change the checked state
// for example when enabling the WiFi
- if (mSendAccessibilityEventViewClickedType &&
- mAccessibilityManager.isEnabled() &&
- view.isEnabled()) {
+ if (mSendAccessibilityEventViewClickedType
+ && AccessibilityManager.getInstance(getContext()).isEnabled()
+ && view.isEnabled()) {
mSendAccessibilityEventViewClickedType = false;
-
- int eventType = AccessibilityEvent.TYPE_VIEW_CLICKED;
- view.sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType));
+ if (mSendAccessibilityEventTypeViewClicked == null) {
+ mSendAccessibilityEventTypeViewClicked = new SendAccessibilityEventTypeViewClicked();
+ }
+ mSendAccessibilityEventTypeViewClicked.mView = view;
+ view.post(mSendAccessibilityEventTypeViewClicked);
}
}
@@ -306,4 +300,13 @@ public abstract class TwoStatePreference extends Preference {
}
};
}
+
+ private final class SendAccessibilityEventTypeViewClicked implements Runnable {
+ private View mView;
+
+ @Override
+ public void run() {
+ mView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
+ }
+ }
}
diff --git a/core/java/android/provider/CallLog.java b/core/java/android/provider/CallLog.java
index 382fcf3..e23d6f3 100644
--- a/core/java/android/provider/CallLog.java
+++ b/core/java/android/provider/CallLog.java
@@ -184,6 +184,16 @@ public class CallLog {
public static final String VOICEMAIL_URI = "voicemail_uri";
/**
+ * Whether this item has been read or otherwise consumed by the user.
+ * <p>
+ * Unlike the {@link #NEW} field, which requires the user to have acknowledged the
+ * existence of the entry, this implies the user has interacted with the entry.
+ * <P>Type: INTEGER (boolean)</P>
+ * @hide
+ */
+ public static final String IS_READ = "is_read";
+
+ /**
* Adds a call to the call log.
*
* @param ci the CallerInfo object to get the target contact from. Can be null
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index c299891..a0f1eec 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -1439,6 +1439,13 @@ public final class ContactsContract {
CONTENT_URI, "strequent");
/**
+ * The content:// style URI for showing frequently contacted person listing.
+ * @hide
+ */
+ public static final Uri CONTENT_FREQUENT_URI = Uri.withAppendedPath(
+ CONTENT_URI, "frequent");
+
+ /**
* The content:// style URI used for "type-to-filter" functionality on the
* {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match
* various parts of the contact name. The filter argument should be passed
@@ -6507,6 +6514,32 @@ public final class ContactsContract {
public static final String SUMMARY_COUNT = "summ_count";
/**
+ * A boolean query parameter that can be used with {@link Groups#CONTENT_SUMMARY_URI}.
+ * It will additionally return {@link #SUMMARY_GROUP_COUNT_PER_ACCOUNT}.
+ *
+ * @hide
+ */
+ public static final String PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT =
+ "return_group_count_per_account";
+
+ /**
+ * The total number of groups of the account that a group belongs to.
+ * This column is available only when the parameter
+ * {@link #PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT} is specified in
+ * {@link Groups#CONTENT_SUMMARY_URI}.
+ *
+ * For example, when the account "A" has two groups "group1" and "group2", and the account
+ * "B" has a group "group3", the rows for "group1" and "group2" return "2" and the row for
+ * "group3" returns "1" for this column.
+ *
+ * Note: This counts only non-favorites, non-auto-add, and not deleted groups.
+ *
+ * Type: INTEGER
+ * @hide
+ */
+ public static final String SUMMARY_GROUP_COUNT_PER_ACCOUNT = "group_count_per_account";
+
+ /**
* The total number of {@link Contacts} that have both
* {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
* Read-only value that is only present when querying
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index cb87e94..cd4e32e 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -16,8 +16,6 @@
package android.provider;
-
-
import android.annotation.SdkConstant;
import android.annotation.SdkConstant.SdkConstantType;
import android.app.SearchManager;
@@ -48,7 +46,6 @@ import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.HashSet;
-
/**
* The Settings provider contains global system-level device preferences.
*/
@@ -2691,11 +2688,9 @@ public final class Settings {
public static final String ACCESSIBILITY_ENABLED = "accessibility_enabled";
/**
- * If touch exploration is requested. Touch exploration is enabled if it is
- * requested by this setting, accessibility is enabled and there is at least
- * one enabled accessibility serivce that provides spoken feedback.
+ * If touch exploration is enabled.
*/
- public static final String TOUCH_EXPLORATION_REQUESTED = "touch_exploration_requested";
+ public static final String TOUCH_EXPLORATION_ENABLED = "touch_exploration_enabled";
/**
* List of the enabled accessibility providers.
@@ -3737,6 +3732,15 @@ public final class Settings {
*/
public static final String VOICE_RECOGNITION_SERVICE = "voice_recognition_service";
+
+ /**
+ * The {@link ComponentName} string of the service to be used as the spell checker
+ * service which is one of the services managed by the text service manager.
+ *
+ * @hide
+ */
+ public static final String SPELL_CHECKER_SERVICE = "spell_checker_service";
+
/**
* What happens when the user presses the Power button while in-call
* and the screen is on.<br/>
@@ -3929,6 +3933,10 @@ public final class Settings {
/** Timeout in milliseconds to wait for NTP server. {@hide} */
public static final String NTP_TIMEOUT = "ntp_timeout";
+ /** Autofill server address (Used in WebView/browser). {@hide} */
+ public static final String WEB_AUTOFILL_QUERY_URL =
+ "web_autofill_query_url";
+
/**
* @hide
*/
diff --git a/core/java/android/provider/VoicemailContract.java b/core/java/android/provider/VoicemailContract.java
index 2ad7395..2e5a495 100644
--- a/core/java/android/provider/VoicemailContract.java
+++ b/core/java/android/provider/VoicemailContract.java
@@ -128,6 +128,12 @@ public class VoicemailContract {
*/
public static final String NEW = Calls.NEW;
/**
+ * Whether this item has been read or otherwise consumed by the user.
+ * <P>Type: INTEGER (boolean)</P>
+ * @hide
+ */
+ public static final String IS_READ = Calls.IS_READ;
+ /**
* The mail box state of the voicemail. This field is currently not used by the system.
* <P> Possible values: {@link #STATE_INBOX}, {@link #STATE_DELETED},
* {@link #STATE_UNDELETED}.
diff --git a/core/java/android/server/BluetoothAdapterStateMachine.java b/core/java/android/server/BluetoothAdapterStateMachine.java
new file mode 100644
index 0000000..ae91465
--- /dev/null
+++ b/core/java/android/server/BluetoothAdapterStateMachine.java
@@ -0,0 +1,513 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.server;
+
+import android.bluetooth.BluetoothAdapter;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Binder;
+import android.os.Message;
+import android.provider.Settings;
+import android.util.Log;
+
+import com.android.internal.util.IState;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
+
+import java.io.PrintWriter;
+
+/**
+ * Bluetooth Adapter StateMachine
+ * All the states are at the same level, ie, no hierarchy.
+ * (BluetootOn)
+ * | ^
+ * TURN_OFF | | BECOME_PAIRABLE
+ * AIRPLANE_MODE_ON | |
+ * V |
+ * (Switching)
+ * | ^
+ * BECOME_NON_PAIRABLE& | | TURN_ON(_CONTINUE)/TURN_ON_FOR_PRIVILEGED
+ * ALL_DEVICES_DISCONNECTED | |
+ * V |
+ * (HotOff)
+ * / ^
+ * / | SERVICE_RECORD_LOADED
+ * | |
+ * TURN_COLD | (Warmup)
+ * \ ^
+ * \ | TURN_HOT/TURN_ON
+ * | | AIRPLANE_MODE_OFF(when Bluetooth was on before)
+ * V |
+ * (PowerOff) <----- initial state
+ *
+ */
+final class BluetoothAdapterStateMachine extends StateMachine {
+ private static final String TAG = "BluetoothAdapterStateMachine";
+ private static final boolean DBG = false;
+
+ // Message(what) to take an action
+ //
+ // We get this message when user tries to turn on BT
+ public static final int USER_TURN_ON = 1;
+ // We get this message when user tries to turn off BT
+ public static final int USER_TURN_OFF = 2;
+
+ // Message(what) to report a event that the state machine need to respond to
+ //
+ // Event indicates sevice records have been loaded
+ public static final int SERVICE_RECORD_LOADED = 51;
+ // Event indicates all the remote Bluetooth devices has been disconnected
+ public static final int ALL_DEVICES_DISCONNECTED = 52;
+ // Event indicates the Bluetooth is connectable
+ public static final int BECOME_PAIRABLE = 53;
+ // Event indicates the Bluetooth is non-connectable.
+ public static final int BECOME_NON_PAIRABLE = 54;
+ // Event indicates airplane mode is turned on
+ public static final int AIRPLANE_MODE_ON = 55;
+ // Event indicates airplane mode is turned off
+ public static final int AIRPLANE_MODE_OFF = 56;
+
+ // private internal messages
+ //
+ // Turn on Bluetooth Module, Load firmware, and do all the preparation
+ // needed to get the Bluetooth Module ready but keep it not discoverable
+ // and not connectable. This way the Bluetooth Module can be quickly
+ // switched on if needed
+ private static final int TURN_HOT = 101;
+ // USER_TURN_ON is changed to TURN_ON_CONTINUE after we broadcast the
+ // state change intent so that we will not broadcast the intent again in
+ // other state
+ private static final int TURN_ON_CONTINUE = 102;
+ // Unload firmware, turning off Bluetooth module power
+ private static final int TURN_COLD = 103;
+ // For NFC, turn on bluetooth for certain process
+ private static final int TURN_ON_FOR_PRIVILEGED = 104;
+
+ private Context mContext;
+ private BluetoothService mBluetoothService;
+ private BluetoothEventLoop mEventLoop;
+
+ private BluetoothOn mBluetoothOn;
+ private Switching mSwitching;
+ private HotOff mHotOff;
+ private WarmUp mWarmUp;
+ private PowerOff mPowerOff;
+
+ // this is the BluetoothAdapter state that reported externally
+ private int mPublicState;
+
+ BluetoothAdapterStateMachine(Context context, BluetoothService bluetoothService,
+ BluetoothAdapter bluetoothAdapter) {
+ super(TAG);
+ mContext = context;
+ mBluetoothService = bluetoothService;
+ mEventLoop = new BluetoothEventLoop(context, bluetoothAdapter, bluetoothService, this);
+
+ mBluetoothOn = new BluetoothOn();
+ mSwitching = new Switching();
+ mHotOff = new HotOff();
+ mWarmUp = new WarmUp();
+ mPowerOff = new PowerOff();
+
+ addState(mBluetoothOn);
+ addState(mSwitching);
+ addState(mHotOff);
+ addState(mWarmUp);
+ addState(mPowerOff);
+ setInitialState(mPowerOff);
+ mPublicState = BluetoothAdapter.STATE_OFF;
+
+ if (mContext.getResources().getBoolean
+ (com.android.internal.R.bool.config_bluetooth_adapter_quick_switch)) {
+ sendMessage(TURN_HOT);
+ }
+ }
+
+ /**
+ * Bluetooth module's power is off, firmware is not loaded.
+ */
+ private class PowerOff extends State {
+ private boolean mPersistSwitchOn = false;
+
+ @Override
+ public void enter() {
+ if (DBG) log("Enter PowerOff: " + mPersistSwitchOn);
+ mPersistSwitchOn = false;
+ }
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) log("PowerOff process message: " + message.what);
+
+ boolean retValue = HANDLED;
+ switch(message.what) {
+ case USER_TURN_ON:
+ // starts turning on BT module, broadcast this out
+ transitionTo(mWarmUp);
+ broadcastState(BluetoothAdapter.STATE_TURNING_ON);
+ if (prepareBluetooth()) {
+ // this is user request, save the setting
+ if ((Boolean) message.obj) {
+ mPersistSwitchOn = true;
+ }
+ // We will continue turn the BT on all the way to the BluetoothOn state
+ deferMessage(obtainMessage(TURN_ON_CONTINUE));
+ } else {
+ Log.e(TAG, "failed to prepare bluetooth, abort turning on");
+ transitionTo(mPowerOff);
+ broadcastState(BluetoothAdapter.STATE_OFF);
+ }
+ break;
+ case TURN_HOT:
+ if (prepareBluetooth()) {
+ transitionTo(mWarmUp);
+ }
+ break;
+ case AIRPLANE_MODE_OFF:
+ if (getBluetoothPersistedSetting()) {
+ // starts turning on BT module, broadcast this out
+ transitionTo(mWarmUp);
+ broadcastState(BluetoothAdapter.STATE_TURNING_ON);
+ if (prepareBluetooth()) {
+ // We will continue turn the BT on all the way to the BluetoothOn state
+ deferMessage(obtainMessage(TURN_ON_CONTINUE));
+ transitionTo(mWarmUp);
+ } else {
+ Log.e(TAG, "failed to prepare bluetooth, abort turning on");
+ transitionTo(mPowerOff);
+ broadcastState(BluetoothAdapter.STATE_OFF);
+ }
+ }
+ break;
+ case AIRPLANE_MODE_ON: // ignore
+ case USER_TURN_OFF: // ignore
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return retValue;
+ }
+
+ /**
+ * Turn on Bluetooth Module, Load firmware, and do all the preparation
+ * needed to get the Bluetooth Module ready but keep it not discoverable
+ * and not connectable.
+ * The last step of this method sets up the local service record DB.
+ * There will be a event reporting the status of the SDP setup.
+ */
+ private boolean prepareBluetooth() {
+ if (mBluetoothService.enableNative() != 0) {
+ return false;
+ }
+
+ // try to start event loop, give 2 attempts
+ int retryCount = 2;
+ boolean eventLoopStarted = false;
+ while ((retryCount-- > 0) && !eventLoopStarted) {
+ mEventLoop.start();
+ // it may take a moment for the other thread to do its
+ // thing. Check periodically for a while.
+ int pollCount = 5;
+ while ((pollCount-- > 0) && !eventLoopStarted) {
+ if (mEventLoop.isEventLoopRunning()) {
+ eventLoopStarted = true;
+ break;
+ }
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+ }
+
+ if (!eventLoopStarted) {
+ mBluetoothService.disableNative();
+ return false;
+ }
+
+ // get BluetoothService ready
+ if (!mBluetoothService.prepareBluetooth()) {
+ mEventLoop.stop();
+ mBluetoothService.disableNative();
+ return false;
+ }
+
+ return true;
+ }
+ }
+
+ /**
+ * Turning on Bluetooth module's power, loading firmware, starting
+ * event loop thread to listen on Bluetooth module event changes.
+ */
+ private class WarmUp extends State {
+
+ @Override
+ public void enter() {
+ if (DBG) log("Enter WarmUp");
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) log("WarmUp process message: " + message.what);
+
+ boolean retValue = HANDLED;
+ switch(message.what) {
+ case SERVICE_RECORD_LOADED:
+ transitionTo(mHotOff);
+ break;
+ case USER_TURN_ON: // handle this at HotOff state
+ case TURN_ON_CONTINUE: // Once in HotOff state, continue turn bluetooth
+ // on to the BluetoothOn state
+ case AIRPLANE_MODE_ON:
+ case AIRPLANE_MODE_OFF:
+ deferMessage(message);
+ break;
+ case USER_TURN_OFF: // ignore
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return retValue;
+ }
+
+ }
+
+ /**
+ * Bluetooth Module has powered, firmware loaded, event loop started,
+ * SDP loaded, but the modules stays non-discoverable and
+ * non-connectable.
+ */
+ private class HotOff extends State {
+ private boolean mPersistSwitchOn = false;
+
+ @Override
+ public void enter() {
+ if (DBG) log("Enter HotOff: " + mPersistSwitchOn);
+ mPersistSwitchOn = false;
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) log("HotOff process message: " + message.what);
+
+ boolean retValue = HANDLED;
+ switch(message.what) {
+ case USER_TURN_ON:
+ if ((Boolean) message.obj) {
+ mPersistSwitchOn = true;
+ }
+ // let it fall to TURN_ON_CONTINUE:
+ case TURN_ON_CONTINUE:
+ mBluetoothService.switchConnectable(true);
+ transitionTo(mSwitching);
+ broadcastState(BluetoothAdapter.STATE_TURNING_ON);
+ break;
+ case AIRPLANE_MODE_ON:
+ case TURN_COLD:
+ mBluetoothService.shutoffBluetooth();
+ mEventLoop.stop();
+ transitionTo(mPowerOff);
+ // ASSERT no support of config_bluetooth_adapter_quick_switch
+ broadcastState(BluetoothAdapter.STATE_OFF);
+ break;
+ case AIRPLANE_MODE_OFF:
+ if (getBluetoothPersistedSetting()) {
+ mBluetoothService.switchConnectable(true);
+ transitionTo(mSwitching);
+ broadcastState(BluetoothAdapter.STATE_TURNING_ON);
+ }
+ break;
+ case USER_TURN_OFF: // ignore
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return retValue;
+ }
+
+ }
+
+ private class Switching extends State {
+
+ @Override
+ public void enter() {
+ int what = getCurrentMessage().what;
+ if (DBG) log("Enter Switching: " + what);
+ }
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) log("Switching process message: " + message.what);
+
+ boolean retValue = HANDLED;
+ switch(message.what) {
+ case BECOME_PAIRABLE:
+ if (mPowerOff.mPersistSwitchOn || mHotOff.mPersistSwitchOn) {
+ persistSwitchSetting(true);
+ mPowerOff.mPersistSwitchOn = mHotOff.mPersistSwitchOn = false;
+ }
+ String[] propVal = {"Pairable", mBluetoothService.getProperty("Pairable")};
+ mEventLoop.onPropertyChanged(propVal);
+
+ // run bluetooth now that it's turned on
+ mBluetoothService.runBluetooth();
+ transitionTo(mBluetoothOn);
+ broadcastState(BluetoothAdapter.STATE_ON);
+ break;
+ case BECOME_NON_PAIRABLE:
+ if (mBluetoothService.getAdapterConnectionState() ==
+ BluetoothAdapter.STATE_DISCONNECTED) {
+ transitionTo(mHotOff);
+ finishSwitchingOff();
+ }
+ break;
+ case ALL_DEVICES_DISCONNECTED:
+ if (mBluetoothService.getScanMode() == BluetoothAdapter.SCAN_MODE_NONE) {
+ transitionTo(mHotOff);
+ finishSwitchingOff();
+ }
+ break;
+ case USER_TURN_ON:
+ case AIRPLANE_MODE_OFF:
+ case AIRPLANE_MODE_ON:
+ case USER_TURN_OFF:
+ deferMessage(message);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return retValue;
+ }
+
+ private void finishSwitchingOff() {
+ if (mBluetoothOn.mPersistBluetoothOff) {
+ persistSwitchSetting(false);
+ mBluetoothOn.mPersistBluetoothOff = false;
+ }
+ mBluetoothService.finishDisable();
+ if (mContext.getResources().getBoolean
+ (com.android.internal.R.bool.config_bluetooth_adapter_quick_switch)) {
+ broadcastState(BluetoothAdapter.STATE_OFF);
+ } else {
+ deferMessage(obtainMessage(TURN_COLD));
+ }
+ }
+ }
+
+ private class BluetoothOn extends State {
+ private boolean mPersistBluetoothOff = false;
+
+ @Override
+ public void enter() {
+ if (DBG) log("Enter BluetoothOn: " + mPersistBluetoothOff);
+ mPersistBluetoothOff = false;
+ }
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) log("BluetoothOn process message: " + message.what);
+
+ boolean retValue = HANDLED;
+ switch(message.what) {
+ case USER_TURN_OFF:
+ if ((Boolean) message.obj) {
+ mPersistBluetoothOff = true;
+ }
+ // let it fall through to AIRPLANE_MODE_ON
+ case AIRPLANE_MODE_ON:
+ transitionTo(mSwitching);
+ broadcastState(BluetoothAdapter.STATE_TURNING_OFF);
+ mBluetoothService.switchConnectable(false);
+ mBluetoothService.disconnectDevices();
+ // we turn all the way to PowerOff with AIRPLANE_MODE_ON
+ if (message.what == AIRPLANE_MODE_ON) {
+ deferMessage(obtainMessage(AIRPLANE_MODE_ON));
+ }
+ break;
+ case AIRPLANE_MODE_OFF: // ignore
+ case USER_TURN_ON: // ignore
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return retValue;
+ }
+
+ }
+
+ /**
+ * Return the public BluetoothAdapter state
+ */
+ int getBluetoothAdapterState() {
+ return mPublicState;
+ }
+
+ BluetoothEventLoop getBluetoothEventLoop() {
+ return mEventLoop;
+ }
+
+ private void persistSwitchSetting(boolean setOn) {
+ long origCallerIdentityToken = Binder.clearCallingIdentity();
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.BLUETOOTH_ON,
+ setOn ? 1 : 0);
+ Binder.restoreCallingIdentity(origCallerIdentityToken);
+ }
+
+ private boolean getBluetoothPersistedSetting() {
+ ContentResolver contentResolver = mContext.getContentResolver();
+ return (Settings.Secure.getInt(contentResolver,
+ Settings.Secure.BLUETOOTH_ON, 0) > 0);
+ }
+
+ private void broadcastState(int newState) {
+
+ if (DBG) log("Bluetooth state " + mPublicState + " -> " + newState);
+ if (mPublicState == newState) {
+ return;
+ }
+
+ Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
+ intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, mPublicState);
+ intent.putExtra(BluetoothAdapter.EXTRA_STATE, newState);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ mPublicState = newState;
+
+ mContext.sendBroadcast(intent, BluetoothService.BLUETOOTH_PERM);
+ }
+
+ private void dump(PrintWriter pw) {
+ IState currentState = getCurrentState();
+ if (currentState == mPowerOff) {
+ pw.println("Bluetooth OFF - power down\n");
+ } else if (currentState == mWarmUp) {
+ pw.println("Bluetooth OFF - warm up\n");
+ } else if (currentState == mHotOff) {
+ pw.println("Bluetooth OFF - hot but off\n");
+ } else if (currentState == mSwitching) {
+ pw.println("Bluetooth Switching\n");
+ } else if (currentState == mBluetoothOn) {
+ pw.println("Bluetooth ON\n");
+ } else {
+ pw.println("ERROR: Bluetooth UNKNOWN STATE ");
+ }
+ }
+
+ private static void log(String msg) {
+ Log.d(TAG, msg);
+ }
+}
diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java
index f345a6a..107a2a9 100644
--- a/core/java/android/server/BluetoothEventLoop.java
+++ b/core/java/android/server/BluetoothEventLoop.java
@@ -52,6 +52,7 @@ class BluetoothEventLoop {
private final HashMap<String, Integer> mAuthorizationAgentRequestData;
private final BluetoothService mBluetoothService;
private final BluetoothAdapter mAdapter;
+ private final BluetoothAdapterStateMachine mBluetoothState;
private BluetoothA2dp mA2dp;
private BluetoothInputDevice mInputDevice;
private final Context mContext;
@@ -107,9 +108,11 @@ class BluetoothEventLoop {
private static native void classInitNative();
/* package */ BluetoothEventLoop(Context context, BluetoothAdapter adapter,
- BluetoothService bluetoothService) {
+ BluetoothService bluetoothService,
+ BluetoothAdapterStateMachine bluetoothState) {
mBluetoothService = bluetoothService;
mContext = context;
+ mBluetoothState = bluetoothState;
mPasskeyAgentRequestData = new HashMap<String, Integer>();
mAuthorizationAgentRequestData = new HashMap<String, Integer>();
mAdapter = adapter;
@@ -299,8 +302,8 @@ class BluetoothEventLoop {
/**
* Called by native code on a PropertyChanged signal from
- * org.bluez.Adapter. This method is also called from Java at
- * {@link BluetoothService.EnableThread#run()} to set the "Pairable"
+ * org.bluez.Adapter. This method is also called from
+ * {@link BluetoothAdapterStateMachine} to set the "Pairable"
* property when Bluetooth is enabled.
*
* @param propValues a string array containing the key and one or more
@@ -334,6 +337,15 @@ class BluetoothEventLoop {
return;
adapterProperties.setProperty(name, propValues[1]);
+
+ if (name.equals("Pairable")) {
+ if (pairable.equals("true")) {
+ mBluetoothState.sendMessage(BluetoothAdapterStateMachine.BECOME_PAIRABLE);
+ } else {
+ mBluetoothState.sendMessage(BluetoothAdapterStateMachine.BECOME_NON_PAIRABLE);
+ }
+ }
+
int mode = BluetoothService.bluezStringToScanMode(
pairable.equals("true"),
discoverable.equals("true"));
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index d68d8ba..34f1971 100755
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -91,7 +91,7 @@ public class BluetoothService extends IBluetooth.Stub {
private BluetoothPan mPan;
private boolean mIsAirplaneSensitive;
private boolean mIsAirplaneToggleable;
- private int mBluetoothState;
+ private BluetoothAdapterStateMachine mBluetoothState;
private boolean mRestart = false; // need to call enable() after disable()
private boolean mIsDiscovering;
private int[] mAdapterSdpHandles;
@@ -111,9 +111,8 @@ public class BluetoothService extends IBluetooth.Stub {
private static final String SHARED_PREFERENCE_DOCK_ADDRESS = "dock_bluetooth_address";
private static final String SHARED_PREFERENCES_NAME = "bluetooth_service_settings";
- private static final int MESSAGE_FINISH_DISABLE = 1;
- private static final int MESSAGE_UUID_INTENT = 2;
- private static final int MESSAGE_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY = 3;
+ private static final int MESSAGE_UUID_INTENT = 1;
+ private static final int MESSAGE_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY = 2;
// The time (in millisecs) to delay the pairing attempt after the first
// auto pairing attempt fails. We use an exponential delay with
@@ -206,7 +205,6 @@ public class BluetoothService extends IBluetooth.Stub {
disableNative();
}
- mBluetoothState = BluetoothAdapter.STATE_OFF;
mIsDiscovering = false;
mBondState = new BluetoothBondState(context, this);
@@ -306,7 +304,9 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized void initAfterRegistration() {
mAdapter = BluetoothAdapter.getDefaultAdapter();
- mEventLoop = new BluetoothEventLoop(mContext, mAdapter, this);
+ mBluetoothState = new BluetoothAdapterStateMachine(mContext, this, mAdapter);
+ mBluetoothState.start();
+ mEventLoop = mBluetoothState.getBluetoothEventLoop();
}
public synchronized void initAfterA2dpRegistration() {
@@ -329,16 +329,16 @@ public class BluetoothService extends IBluetooth.Stub {
}
private boolean isEnabledInternal() {
- return mBluetoothState == BluetoothAdapter.STATE_ON;
+ return (getBluetoothStateInternal() == BluetoothAdapter.STATE_ON);
}
public int getBluetoothState() {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
- return mBluetoothState;
+ return getBluetoothStateInternal();
}
int getBluetoothStateInternal() {
- return mBluetoothState;
+ return mBluetoothState.getBluetoothAdapterState();
}
/**
@@ -356,7 +356,9 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean disable(boolean saveSetting) {
mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission");
- switch (mBluetoothState) {
+ int adapterState = getBluetoothStateInternal();
+
+ switch (adapterState) {
case BluetoothAdapter.STATE_OFF:
return true;
case BluetoothAdapter.STATE_ON:
@@ -364,27 +366,12 @@ public class BluetoothService extends IBluetooth.Stub {
default:
return false;
}
- if (mEnableThread != null && mEnableThread.isAlive()) {
- return false;
- }
-
- setBluetoothState(BluetoothAdapter.STATE_TURNING_OFF);
-
- if (mAdapterSdpHandles != null) removeReservedServiceRecordsNative(mAdapterSdpHandles);
- setBluetoothTetheringNative(false, BluetoothPanProfileHandler.NAP_ROLE,
- BluetoothPanProfileHandler.NAP_BRIDGE);
-
- // Allow 3 seconds for profiles to gracefully disconnect
- // TODO: Introduce a callback mechanism so that each profile can notify
- // BluetoothService when it is done shutting down
- disconnectDevices();
- mHandler.sendMessageDelayed(
- mHandler.obtainMessage(MESSAGE_FINISH_DISABLE, saveSetting ? 1 : 0, 0), 3000);
+ mBluetoothState.sendMessage(BluetoothAdapterStateMachine.USER_TURN_OFF, saveSetting);
return true;
}
- private synchronized void disconnectDevices() {
+ synchronized void disconnectDevices() {
// Disconnect devices handled by BluetoothService.
for (BluetoothDevice device: getConnectedInputDevices()) {
disconnectInputDevice(device);
@@ -395,14 +382,11 @@ public class BluetoothService extends IBluetooth.Stub {
}
}
- private synchronized void finishDisable(boolean saveSetting) {
- if (mBluetoothState != BluetoothAdapter.STATE_TURNING_OFF) {
- return;
- }
- mEventLoop.stop();
- tearDownNativeDataNative();
- disableNative();
-
+ /**
+ * The Bluetooth has been turned off, but hot. Do bonding, profile,
+ * and internal cleanup
+ */
+ synchronized void finishDisable() {
// mark in progress bondings as cancelled
for (String address : mBondState.listInState(BluetoothDevice.BOND_BONDING)) {
mBondState.setBondState(address, BluetoothDevice.BOND_NONE,
@@ -430,12 +414,6 @@ public class BluetoothService extends IBluetooth.Stub {
mAdapterUuids = null;
mAdapterSdpHandles = null;
- if (saveSetting) {
- persistBluetoothOnSetting(false);
- }
-
- setBluetoothState(BluetoothAdapter.STATE_OFF);
-
// Log bluetooth off to battery stats.
long ident = Binder.clearCallingIdentity();
try {
@@ -451,6 +429,18 @@ public class BluetoothService extends IBluetooth.Stub {
}
}
+ /**
+ * power off Bluetooth
+ */
+ synchronized void shutoffBluetooth() {
+ tearDownNativeDataNative();
+ disableNative();
+ if (mRestart) {
+ mRestart = false;
+ enable();
+ }
+ }
+
/** Bring up BT and persist BT on in settings */
public boolean enable() {
return enable(true);
@@ -471,21 +461,29 @@ public class BluetoothService extends IBluetooth.Stub {
if (mIsAirplaneSensitive && isAirplaneModeOn() && !mIsAirplaneToggleable) {
return false;
}
- if (mBluetoothState != BluetoothAdapter.STATE_OFF) {
- return false;
- }
- if (mEnableThread != null && mEnableThread.isAlive()) {
+ mBluetoothState.sendMessage(BluetoothAdapterStateMachine.USER_TURN_ON, saveSetting);
+ return true;
+ }
+
+ /**
+ * Turn on Bluetooth Module, Load firmware, and do all the preparation
+ * needed to get the Bluetooth Module ready but keep it not discoverable
+ * and not connectable.
+ */
+ /* package */ synchronized boolean prepareBluetooth() {
+ if (!setupNativeDataNative()) {
return false;
}
- setBluetoothState(BluetoothAdapter.STATE_TURNING_ON);
- mEnableThread = new EnableThread(saveSetting);
- mEnableThread.start();
+ mIsDiscovering = false;
+
+ switchConnectable(false);
+ updateSdpRecords();
return true;
}
/** Forcibly restart Bluetooth if it is on */
/* package */ synchronized void restart() {
- if (mBluetoothState != BluetoothAdapter.STATE_ON) {
+ if (getBluetoothStateInternal() != BluetoothAdapter.STATE_ON) {
return;
}
mRestart = true;
@@ -494,30 +492,10 @@ public class BluetoothService extends IBluetooth.Stub {
}
}
- private synchronized void setBluetoothState(int state) {
- if (state == mBluetoothState) {
- return;
- }
-
- if (DBG) Log.d(TAG, "Bluetooth state " + mBluetoothState + " -> " + state);
-
- Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
- intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, mBluetoothState);
- intent.putExtra(BluetoothAdapter.EXTRA_STATE, state);
- intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
-
- mBluetoothState = state;
-
- mContext.sendBroadcast(intent, BLUETOOTH_PERM);
- }
-
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
- case MESSAGE_FINISH_DISABLE:
- finishDisable(msg.arg1 != 0);
- break;
case MESSAGE_UUID_INTENT:
String address = (String)msg.obj;
if (address != null) {
@@ -545,65 +523,6 @@ public class BluetoothService extends IBluetooth.Stub {
}
};
- private EnableThread mEnableThread;
-
- private class EnableThread extends Thread {
- private final boolean mSaveSetting;
- public EnableThread(boolean saveSetting) {
- mSaveSetting = saveSetting;
- }
- public void run() {
- boolean res = (enableNative() == 0);
- if (res) {
- int retryCount = 2;
- boolean running = false;
- while ((retryCount-- > 0) && !running) {
- mEventLoop.start();
- // it may take a moment for the other thread to do its
- // thing. Check periodically for a while.
- int pollCount = 5;
- while ((pollCount-- > 0) && !running) {
- if (mEventLoop.isEventLoopRunning()) {
- running = true;
- break;
- }
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {}
- }
- }
- if (!running) {
- Log.e(TAG, "bt EnableThread giving up");
- res = false;
- disableNative();
- }
- }
-
- if (res) {
- if (!setupNativeDataNative()) {
- return;
- }
- if (mSaveSetting) {
- persistBluetoothOnSetting(true);
- }
-
- mIsDiscovering = false;
- mBondState.readAutoPairingData();
- mBondState.initBondState();
- initProfileState();
-
- // This should be the last step of the the enable thread.
- // Because this adds SDP records which asynchronously
- // broadcasts the Bluetooth On State in updateBluetoothState.
- // So we want all internal state setup before this.
- updateSdpRecords();
- } else {
- setBluetoothState(BluetoothAdapter.STATE_OFF);
- }
- mEnableThread = null;
- }
- }
-
private synchronized void addReservedSdpRecords(final ArrayList<ParcelUuid> uuids) {
//Register SDP records.
int[] svcIdentifiers = new int[uuids.size()];
@@ -650,38 +569,37 @@ public class BluetoothService extends IBluetooth.Stub {
* for adapter comes in with UUID property.
* @param uuidsThe uuids of adapter as reported by Bluez.
*/
- synchronized void updateBluetoothState(String uuids) {
- if (mBluetoothState == BluetoothAdapter.STATE_TURNING_ON) {
- ParcelUuid[] adapterUuids = convertStringToParcelUuid(uuids);
-
- if (mAdapterUuids != null &&
- BluetoothUuid.containsAllUuids(adapterUuids, mAdapterUuids)) {
- setBluetoothState(BluetoothAdapter.STATE_ON);
- autoConnect();
- String[] propVal = {"Pairable", getProperty("Pairable")};
- mEventLoop.onPropertyChanged(propVal);
-
- // Log bluetooth on to battery stats.
- long ident = Binder.clearCallingIdentity();
- try {
- mBatteryStats.noteBluetoothOn();
- } catch (RemoteException e) {
- } finally {
- Binder.restoreCallingIdentity(ident);
- }
+ /*package*/ synchronized void updateBluetoothState(String uuids) {
+ ParcelUuid[] adapterUuids = convertStringToParcelUuid(uuids);
- if (mIsAirplaneSensitive && isAirplaneModeOn() && !mIsAirplaneToggleable) {
- disable(false);
- }
- }
+ if (mAdapterUuids != null &&
+ BluetoothUuid.containsAllUuids(adapterUuids, mAdapterUuids)) {
+ mBluetoothState.sendMessage(BluetoothAdapterStateMachine.SERVICE_RECORD_LOADED);
}
}
- private void persistBluetoothOnSetting(boolean bluetoothOn) {
- long origCallerIdentityToken = Binder.clearCallingIdentity();
- Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.BLUETOOTH_ON,
- bluetoothOn ? 1 : 0);
- Binder.restoreCallingIdentity(origCallerIdentityToken);
+ /**
+ * This method is called immediately after Bluetooth module is turned on.
+ * It starts auto-connection and places bluetooth on sign onto the battery
+ * stats
+ */
+ /*package*/ void runBluetooth() {
+ mIsDiscovering = false;
+ mBondState.readAutoPairingData();
+ mBondState.initBondState();
+ initProfileState();
+
+ autoConnect();
+
+ // Log bluetooth on to battery stats.
+ long ident = Binder.clearCallingIdentity();
+ try {
+ mBatteryStats.noteBluetoothOn();
+ } catch (RemoteException e) {
+ Log.e(TAG, "", e);
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
}
/*package*/ synchronized boolean attemptAutoPair(String address) {
@@ -818,6 +736,26 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized boolean setScanMode(int mode, int duration) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS,
"Need WRITE_SECURE_SETTINGS permission");
+ return setScanMode(mode, duration, true);
+ }
+
+ /**
+ * @param on true set the local Bluetooth module to be connectable
+ * but not dicoverable
+ * false set the local Bluetooth module to be not connectable
+ * and not dicoverable
+ */
+ /*package*/ synchronized void switchConnectable(boolean on) {
+ if (on) {
+ // 0 is a dummy value, does not apply for SCAN_MODE_CONNECTABLE
+ setScanMode(BluetoothAdapter.SCAN_MODE_CONNECTABLE, 0, false);
+ } else {
+ // 0 is a dummy value, does not apply for SCAN_MODE_NONE
+ setScanMode(BluetoothAdapter.SCAN_MODE_NONE, 0, false);
+ }
+ }
+
+ private synchronized boolean setScanMode(int mode, int duration, boolean allowOnlyInOnState) {
boolean pairable;
boolean discoverable;
@@ -839,9 +777,15 @@ public class BluetoothService extends IBluetooth.Stub {
Log.w(TAG, "Requested invalid scan mode " + mode);
return false;
}
- setPropertyBoolean("Pairable", pairable);
- setPropertyBoolean("Discoverable", discoverable);
+ if (allowOnlyInOnState) {
+ setPropertyBoolean("Pairable", pairable);
+ setPropertyBoolean("Discoverable", discoverable);
+ } else {
+ // allowed to set the property through native layer directly
+ setAdapterPropertyBooleanNative("Pairable", pairable ? 1 : 0);
+ setAdapterPropertyBooleanNative("Discoverable", discoverable ? 1 : 0);
+ }
return true;
}
@@ -1569,14 +1513,10 @@ public class BluetoothService extends IBluetooth.Stub {
ContentResolver resolver = context.getContentResolver();
// Query the airplane mode from Settings.System just to make sure that
// some random app is not sending this intent and disabling bluetooth
- boolean enabled = !isAirplaneModeOn();
- // If bluetooth is currently expected to be on, then enable or disable bluetooth
- if (Settings.Secure.getInt(resolver, Settings.Secure.BLUETOOTH_ON, 0) > 0) {
- if (enabled) {
- enable(false);
- } else {
- disable(false);
- }
+ if (isAirplaneModeOn()) {
+ mBluetoothState.sendMessage(BluetoothAdapterStateMachine.AIRPLANE_MODE_ON);
+ } else {
+ mBluetoothState.sendMessage(BluetoothAdapterStateMachine.AIRPLANE_MODE_OFF);
}
} else if (Intent.ACTION_DOCK_EVENT.equals(action)) {
int state = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
@@ -1650,8 +1590,7 @@ public class BluetoothService extends IBluetooth.Stub {
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
- dumpBluetoothState(pw);
- if (mBluetoothState != BluetoothAdapter.STATE_ON) {
+ if (getBluetoothStateInternal() != BluetoothAdapter.STATE_ON) {
return;
}
@@ -1840,25 +1779,6 @@ public class BluetoothService extends IBluetooth.Stub {
}
}
- private void dumpBluetoothState(PrintWriter pw) {
- switch(mBluetoothState) {
- case BluetoothAdapter.STATE_OFF:
- pw.println("Bluetooth OFF\n");
- break;
- case BluetoothAdapter.STATE_TURNING_ON:
- pw.println("Bluetooth TURNING ON\n");
- break;
- case BluetoothAdapter.STATE_TURNING_OFF:
- pw.println("Bluetooth TURNING OFF\n");
- break;
- case BluetoothAdapter.STATE_ON:
- pw.println("Bluetooth ON\n");
- break;
- default:
- pw.println("Bluetooth UNKNOWN STATE " + mBluetoothState);
- }
- }
-
private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
new BluetoothProfile.ServiceListener() {
public void onServiceConnected(int profile, BluetoothProfile proxy) {
@@ -2389,7 +2309,7 @@ public class BluetoothService extends IBluetooth.Stub {
public synchronized void sendConnectionStateChange(BluetoothDevice device, int state,
int prevState) {
// Since this is a binder call check if Bluetooth is on still
- if (mBluetoothState == BluetoothAdapter.STATE_OFF) return;
+ if (getBluetoothStateInternal() == BluetoothAdapter.STATE_OFF) return;
if (updateCountersAndCheckForConnectionStateChange(state, prevState)) {
if (!validateProfileConnectionState(state) ||
@@ -2405,6 +2325,10 @@ public class BluetoothService extends IBluetooth.Stub {
mAdapterConnectionState = state;
+ if (state == BluetoothProfile.STATE_DISCONNECTED) {
+ mBluetoothState.sendMessage(BluetoothAdapterStateMachine.ALL_DEVICES_DISCONNECTED);
+ }
+
Intent intent = new Intent(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);
intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
intent.putExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
@@ -2598,8 +2522,8 @@ public class BluetoothService extends IBluetooth.Stub {
/*package*/ native String getAdapterPathNative();
private native int isEnabledNative();
- private native int enableNative();
- private native int disableNative();
+ /*package*/ native int enableNative();
+ /*package*/ native int disableNative();
/*package*/ native Object[] getAdapterPropertiesNative();
private native Object[] getDevicePropertiesNative(String objectPath);
diff --git a/core/java/android/service/textservice/SpellCheckerService.java b/core/java/android/service/textservice/SpellCheckerService.java
new file mode 100644
index 0000000..270f512
--- /dev/null
+++ b/core/java/android/service/textservice/SpellCheckerService.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package android.service.textservice;
+
+import com.android.internal.textservice.ISpellCheckerService;
+import com.android.internal.textservice.ISpellCheckerSession;
+import com.android.internal.textservice.ISpellCheckerSessionListener;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.view.textservice.SuggestionsInfo;
+import android.view.textservice.TextInfo;
+
+import java.lang.ref.WeakReference;
+
+/**
+ * SpellCheckerService provides an abstract base class for a spell checker.
+ * This class combines a service to the system with the spell checker service interface that
+ * spell checker must implement.
+ */
+public abstract class SpellCheckerService extends Service {
+ private static final String TAG = SpellCheckerService.class.getSimpleName();
+ public static final String SERVICE_INTERFACE =
+ "android.service.textservice.SpellCheckerService";
+
+ private final SpellCheckerServiceBinder mBinder = new SpellCheckerServiceBinder(this);
+
+ /**
+ * Get suggestions for specified text in TextInfo.
+ * This function will run on the incoming IPC thread. So, this is not called on the main thread,
+ * but will be called in series on another thread.
+ * @param textInfo the text metadata
+ * @param suggestionsLimit the number of limit of suggestions returned
+ * @param locale the locale for getting suggestions
+ * @return SuggestionInfo which contains suggestions for textInfo
+ */
+ public abstract SuggestionsInfo getSuggestions(
+ TextInfo textInfo, int suggestionsLimit, String locale);
+
+ /**
+ * A batch process of onGetSuggestions.
+ * This function will run on the incoming IPC thread. So, this is not called on the main thread,
+ * but will be called in series on another thread.
+ * @param textInfos an array of the text metadata
+ * @param locale the locale for getting suggestions
+ * @param suggestionsLimit the number of limit of suggestions returned
+ * @param sequentialWords true if textInfos can be treated as sequential words.
+ * @return an array of SuggestionInfo of onGetSuggestions
+ */
+ public SuggestionsInfo[] getSuggestionsMultiple(
+ TextInfo[] textInfos, String locale, int suggestionsLimit, boolean sequentialWords) {
+ final int length = textInfos.length;
+ final SuggestionsInfo[] retval = new SuggestionsInfo[length];
+ for (int i = 0; i < length; ++i) {
+ retval[i] = getSuggestions(textInfos[i], suggestionsLimit, locale);
+ retval[i].setCookieAndSequence(textInfos[i].getCookie(), textInfos[i].getSequence());
+ }
+ return retval;
+ }
+
+ /**
+ * Request to abort all tasks executed in SpellChecker.
+ * This function will run on the incoming IPC thread. So, this is not called on the main thread,
+ * but will be called in series on another thread.
+ */
+ public void cancel() {}
+
+ /**
+ * Implement to return the implementation of the internal spell checker
+ * service interface. Subclasses should not override.
+ */
+ @Override
+ public final IBinder onBind(final Intent intent) {
+ return mBinder;
+ }
+
+ private static class SpellCheckerSessionImpl extends ISpellCheckerSession.Stub {
+ private final WeakReference<SpellCheckerService> mInternalServiceRef;
+ private final String mLocale;
+ private final ISpellCheckerSessionListener mListener;
+
+ public SpellCheckerSessionImpl(
+ SpellCheckerService service, String locale, ISpellCheckerSessionListener listener) {
+ mInternalServiceRef = new WeakReference<SpellCheckerService>(service);
+ mLocale = locale;
+ mListener = listener;
+ }
+
+ @Override
+ public void getSuggestionsMultiple(
+ TextInfo[] textInfos, int suggestionsLimit, boolean sequentialWords) {
+ final SpellCheckerService service = mInternalServiceRef.get();
+ if (service == null) return;
+ try {
+ mListener.onGetSuggestions(
+ service.getSuggestionsMultiple(textInfos, mLocale,
+ suggestionsLimit, sequentialWords));
+ } catch (RemoteException e) {
+ }
+ }
+
+ @Override
+ public void cancel() {
+ final SpellCheckerService service = mInternalServiceRef.get();
+ if (service == null) return;
+ service.cancel();
+ }
+ }
+
+ private static class SpellCheckerServiceBinder extends ISpellCheckerService.Stub {
+ private final WeakReference<SpellCheckerService> mInternalServiceRef;
+
+ public SpellCheckerServiceBinder(SpellCheckerService service) {
+ mInternalServiceRef = new WeakReference<SpellCheckerService>(service);
+ }
+
+ @Override
+ public ISpellCheckerSession getISpellCheckerSession(
+ String locale, ISpellCheckerSessionListener listener) {
+ final SpellCheckerService service = mInternalServiceRef.get();
+ if (service == null) return null;
+ return new SpellCheckerSessionImpl(service, locale, listener);
+ }
+ }
+}
diff --git a/core/java/android/service/textservice/SpellCheckerSession.java b/core/java/android/service/textservice/SpellCheckerSession.java
new file mode 100644
index 0000000..400454d
--- /dev/null
+++ b/core/java/android/service/textservice/SpellCheckerSession.java
@@ -0,0 +1,284 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.service.textservice;
+
+import com.android.internal.textservice.ISpellCheckerSession;
+import com.android.internal.textservice.ISpellCheckerSessionListener;
+import com.android.internal.textservice.ITextServicesManager;
+import com.android.internal.textservice.ITextServicesSessionListener;
+
+import android.os.Handler;
+import android.os.Message;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.textservice.SpellCheckerInfo;
+import android.view.textservice.SuggestionsInfo;
+import android.view.textservice.TextInfo;
+
+import java.util.LinkedList;
+import java.util.Locale;
+import java.util.Queue;
+
+/**
+ * The SpellCheckerSession interface provides the per client functionality of SpellCheckerService.
+ */
+public class SpellCheckerSession {
+ private static final String TAG = SpellCheckerSession.class.getSimpleName();
+ private static final boolean DBG = false;
+
+ private static final int MSG_ON_GET_SUGGESTION_MULTIPLE = 1;
+
+ private final InternalListener mInternalListener;
+ private final ITextServicesManager mTextServicesManager;
+ private final SpellCheckerInfo mSpellCheckerInfo;
+ private final SpellCheckerSessionListenerImpl mSpellCheckerSessionListenerImpl;
+
+ private boolean mIsUsed;
+ private SpellCheckerSessionListener mSpellCheckerSessionListener;
+
+ /** Handler that will execute the main tasks */
+ private final Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ switch (msg.what) {
+ case MSG_ON_GET_SUGGESTION_MULTIPLE:
+ handleOnGetSuggestionsMultiple((SuggestionsInfo[]) msg.obj);
+ break;
+ }
+ }
+ };
+
+ /**
+ * Constructor
+ * @hide
+ */
+ public SpellCheckerSession(
+ SpellCheckerInfo info, ITextServicesManager tsm, SpellCheckerSessionListener listener) {
+ if (info == null || listener == null || tsm == null) {
+ throw new NullPointerException();
+ }
+ mSpellCheckerInfo = info;
+ mSpellCheckerSessionListenerImpl = new SpellCheckerSessionListenerImpl(mHandler);
+ mInternalListener = new InternalListener();
+ mTextServicesManager = tsm;
+ mIsUsed = true;
+ mSpellCheckerSessionListener = listener;
+ }
+
+ /**
+ * @return true if the connection to a text service of this session is disconnected and not
+ * alive.
+ */
+ public boolean isSessionDisconnected() {
+ return mSpellCheckerSessionListenerImpl.isDisconnected();
+ }
+
+ /**
+ * Get the spell checker service info this spell checker session has.
+ * @return SpellCheckerInfo for the specified locale.
+ */
+ public SpellCheckerInfo getSpellChecker() {
+ return mSpellCheckerInfo;
+ }
+
+ /**
+ * Finish this session and allow TextServicesManagerService to disconnect the bound spell
+ * checker.
+ */
+ public void close() {
+ mIsUsed = false;
+ try {
+ mTextServicesManager.finishSpellCheckerService(mSpellCheckerSessionListenerImpl);
+ } catch (RemoteException e) {
+ // do nothing
+ }
+ }
+
+ /**
+ * Get candidate strings for a substring of the specified text.
+ * @param textInfo text metadata for a spell checker
+ * @param suggestionsLimit the number of limit of suggestions returned
+ */
+ public void getSuggestions(TextInfo textInfo, int suggestionsLimit) {
+ getSuggestions(new TextInfo[] {textInfo}, suggestionsLimit, false);
+ }
+
+ /**
+ * A batch process of getSuggestions
+ * @param textInfos an array of text metadata for a spell checker
+ * @param suggestionsLimit the number of limit of suggestions returned
+ * @param sequentialWords true if textInfos can be treated as sequential words.
+ */
+ public void getSuggestions(
+ TextInfo[] textInfos, int suggestionsLimit, boolean sequentialWords) {
+ // TODO: Handle multiple words suggestions by using WordBreakIterator
+ mSpellCheckerSessionListenerImpl.getSuggestionsMultiple(
+ textInfos, suggestionsLimit, sequentialWords);
+ }
+
+ private void handleOnGetSuggestionsMultiple(SuggestionsInfo[] suggestionInfos) {
+ mSpellCheckerSessionListener.onGetSuggestions(suggestionInfos);
+ }
+
+ private static class SpellCheckerSessionListenerImpl extends ISpellCheckerSessionListener.Stub {
+ private static final int TASK_CANCEL = 1;
+ private static final int TASK_GET_SUGGESTIONS_MULTIPLE = 2;
+ private final Queue<SpellCheckerParams> mPendingTasks =
+ new LinkedList<SpellCheckerParams>();
+ private final Handler mHandler;
+
+ private boolean mOpened;
+ private ISpellCheckerSession mISpellCheckerSession;
+
+ public SpellCheckerSessionListenerImpl(Handler handler) {
+ mOpened = false;
+ mHandler = handler;
+ }
+
+ private static class SpellCheckerParams {
+ public final int mWhat;
+ public final TextInfo[] mTextInfos;
+ public final int mSuggestionsLimit;
+ public final boolean mSequentialWords;
+ public SpellCheckerParams(int what, TextInfo[] textInfos, int suggestionsLimit,
+ boolean sequentialWords) {
+ mWhat = what;
+ mTextInfos = textInfos;
+ mSuggestionsLimit = suggestionsLimit;
+ mSequentialWords = sequentialWords;
+ }
+ }
+
+ private void processTask(SpellCheckerParams scp) {
+ switch (scp.mWhat) {
+ case TASK_CANCEL:
+ processCancel();
+ break;
+ case TASK_GET_SUGGESTIONS_MULTIPLE:
+ processGetSuggestionsMultiple(scp);
+ break;
+ }
+ }
+
+ public synchronized void onServiceConnected(ISpellCheckerSession session) {
+ mISpellCheckerSession = session;
+ mOpened = true;
+ if (DBG)
+ Log.d(TAG, "onServiceConnected - Success");
+ while (!mPendingTasks.isEmpty()) {
+ processTask(mPendingTasks.poll());
+ }
+ }
+
+ public void getSuggestionsMultiple(
+ TextInfo[] textInfos, int suggestionsLimit, boolean sequentialWords) {
+ processOrEnqueueTask(
+ new SpellCheckerParams(TASK_GET_SUGGESTIONS_MULTIPLE, textInfos,
+ suggestionsLimit, sequentialWords));
+ }
+
+ public boolean isDisconnected() {
+ return mOpened && mISpellCheckerSession == null;
+ }
+
+ public boolean checkOpenConnection() {
+ if (mISpellCheckerSession != null) {
+ return true;
+ }
+ Log.e(TAG, "not connected to the spellchecker service.");
+ return false;
+ }
+
+ private void processOrEnqueueTask(SpellCheckerParams scp) {
+ if (mISpellCheckerSession == null) {
+ mPendingTasks.offer(scp);
+ } else {
+ processTask(scp);
+ }
+ }
+
+ private void processCancel() {
+ if (!checkOpenConnection()) {
+ return;
+ }
+ try {
+ mISpellCheckerSession.cancel();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to cancel " + e);
+ }
+ }
+
+ private void processGetSuggestionsMultiple(SpellCheckerParams scp) {
+ if (!checkOpenConnection()) {
+ return;
+ }
+ try {
+ mISpellCheckerSession.getSuggestionsMultiple(
+ scp.mTextInfos, scp.mSuggestionsLimit, scp.mSequentialWords);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to get suggestions " + e);
+ }
+ }
+
+ @Override
+ public void onGetSuggestions(SuggestionsInfo[] results) {
+ mHandler.sendMessage(Message.obtain(mHandler, MSG_ON_GET_SUGGESTION_MULTIPLE, results));
+ }
+ }
+
+ /**
+ * Callback for getting results from text services
+ */
+ public interface SpellCheckerSessionListener {
+ /**
+ * Callback for "getSuggestions"
+ * @param results an array of results of getSuggestions
+ */
+ public void onGetSuggestions(SuggestionsInfo[] results);
+ }
+
+ private class InternalListener extends ITextServicesSessionListener.Stub {
+ @Override
+ public void onServiceConnected(ISpellCheckerSession session) {
+ mSpellCheckerSessionListenerImpl.onServiceConnected(session);
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ if (mIsUsed) {
+ Log.e(TAG, "SpellCheckerSession was not finished properly." +
+ "You should call finishShession() when you finished to use a spell checker.");
+ close();
+ }
+ }
+
+ /**
+ * @hide
+ */
+ public ITextServicesSessionListener getTextServicesSessionListener() {
+ return mInternalListener;
+ }
+
+ /**
+ * @hide
+ */
+ public ISpellCheckerSessionListener getSpellCheckerSessionListener() {
+ return mSpellCheckerSessionListenerImpl;
+ }
+}
diff --git a/core/java/android/util/JsonReader.java b/core/java/android/util/JsonReader.java
index f139372..f2a86c9 100644
--- a/core/java/android/util/JsonReader.java
+++ b/core/java/android/util/JsonReader.java
@@ -740,8 +740,8 @@ public final class JsonReader implements Closeable {
limit += total;
// if this is the first read, consume an optional byte order mark (BOM) if it exists
- if (bufferStartLine == 1 && bufferStartColumn == 1
- && limit > 0 && buffer[0] == '\ufeff') {
+ if (bufferStartLine == 1 && bufferStartColumn == 1
+ && limit > 0 && buffer[0] == '\ufeff') {
pos++;
bufferStartColumn--;
}
@@ -852,7 +852,7 @@ public final class JsonReader implements Closeable {
private boolean skipTo(String toFind) throws IOException {
outer:
- for (; pos + toFind.length() < limit || fillBuffer(toFind.length()); pos++) {
+ for (; pos + toFind.length() <= limit || fillBuffer(toFind.length()); pos++) {
for (int c = 0; c < toFind.length(); c++) {
if (buffer[pos + c] != toFind.charAt(c)) {
continue outer;
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index c913bb3..836867b 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -161,6 +161,9 @@ public class Surface implements Parcelable {
*/
public static final int FLAGS_ORIENTATION_ANIMATION_DISABLE = 0x000000001;
+ // The mSurfaceControl will only be present for Surfaces used by the window
+ // server or system processes. When this class is parceled we defer to the
+ // mSurfaceControl to do the parceling. Otherwise we parcel the mNativeSurface.
@SuppressWarnings("unused")
private int mSurfaceControl;
@SuppressWarnings("unused")
@@ -202,6 +205,19 @@ public class Surface implements Parcelable {
native private static void nativeClassInit();
static { nativeClassInit(); }
+ /**
+ * Create Surface from a SurfaceTexture.
+ *
+ * @param surfaceTexture The {@link SurfaceTexture} that is updated by this Surface.
+ * @hide
+ */
+ public Surface(SurfaceTexture surfaceTexture) {
+ if (DEBUG_RELEASE) {
+ mCreationStack = new Exception();
+ }
+ mCanvas = new CompatibleCanvas();
+ initFromSurfaceTexture(surfaceTexture);
+ }
/**
* create a surface
@@ -505,5 +521,7 @@ public class Surface implements Parcelable {
private native void init(Parcel source);
+ private native void initFromSurfaceTexture(SurfaceTexture surfaceTexture);
+
private native int getIdentity();
}
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index ecb391d..dbb19e4 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -4280,6 +4280,36 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
}
/**
+ * Set whether or not this view should account for system screen decorations
+ * such as the status bar and inset its content. This allows this view to be
+ * positioned in absolute screen coordinates and remain visible to the user.
+ *
+ * <p>This should only be used by top-level window decor views.
+ *
+ * @param fitSystemWindows true to inset content for system screen decorations, false for
+ * default behavior.
+ *
+ * @attr ref android.R.styleable#View_fitsSystemWindows
+ */
+ public void setFitsSystemWindows(boolean fitSystemWindows) {
+ setFlags(fitSystemWindows ? FITS_SYSTEM_WINDOWS : 0, FITS_SYSTEM_WINDOWS);
+ }
+
+ /**
+ * Check for the FITS_SYSTEM_WINDOWS flag. If this method returns true, this view
+ * will account for system screen decorations such as the status bar and inset its
+ * content. This allows the view to be positioned in absolute screen coordinates
+ * and remain visible to the user.
+ *
+ * @return true if this view will adjust its content bounds for system screen decorations.
+ *
+ * @attr ref android.R.styleable#View_fitsSystemWindows
+ */
+ public boolean fitsSystemWindows() {
+ return (mViewFlags & FITS_SYSTEM_WINDOWS) == FITS_SYSTEM_WINDOWS;
+ }
+
+ /**
* Returns the visibility status for this view.
*
* @return One of {@link #VISIBLE}, {@link #INVISIBLE}, or {@link #GONE}.
@@ -12028,12 +12058,13 @@ public class View implements Drawable.Callback2, KeyEvent.Callback, Accessibilit
mPrivateFlags |= FORCE_LAYOUT;
mPrivateFlags |= INVALIDATED;
- if (mLayoutParams != null && mParent != null) {
- mLayoutParams.resolveWithDirection(getResolvedLayoutDirection());
- }
-
- if (mParent != null && !mParent.isLayoutRequested()) {
- mParent.requestLayout();
+ if (mParent != null) {
+ if (mLayoutParams != null) {
+ mLayoutParams.resolveWithDirection(getResolvedLayoutDirection());
+ }
+ if (!mParent.isLayoutRequested()) {
+ mParent.requestLayout();
+ }
}
}
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 92a8ce7..6f90971 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -2854,7 +2854,7 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
// display lists to render, force an invalidate to allow the animation to
// continue drawing another frame
invalidate(true);
- if (a instanceof AlphaAnimation) {
+ if (a.hasAlpha()) {
// alpha animations should cause the child to recreate its display list
child.invalidate(true);
}
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index 83c73cb..a80c2a7 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -67,13 +67,17 @@ public final class AccessibilityManager {
private static final String LOG_TAG = "AccessibilityManager";
+ /** @hide */
+ public static final int STATE_FLAG_ACCESSIBILITY_ENABLED = 0x00000001;
+
+ /** @hide */
+ public static final int STATE_FLAG_TOUCH_EXPLORATION_ENABLED = 0x00000002;
+
static final Object sInstanceSync = new Object();
private static AccessibilityManager sInstance;
- private static final int DO_SET_ACCESSIBILITY_ENABLED = 10;
-
- private static final int DO_SET_TOUCH_EXPLORATION_ENABLED = 20;
+ private static final int DO_SET_STATE = 10;
final IAccessibilityManager mService;
@@ -100,13 +104,8 @@ public final class AccessibilityManager {
}
final IAccessibilityManagerClient.Stub mClient = new IAccessibilityManagerClient.Stub() {
- public void setEnabled(boolean enabled) {
- mHandler.obtainMessage(DO_SET_ACCESSIBILITY_ENABLED, enabled ? 1 : 0, 0).sendToTarget();
- }
-
- public void setTouchExplorationEnabled(boolean enabled) {
- mHandler.obtainMessage(DO_SET_TOUCH_EXPLORATION_ENABLED,
- enabled ? 1 : 0, 0).sendToTarget();
+ public void setState(int state) {
+ mHandler.obtainMessage(DO_SET_STATE, state, 0).sendToTarget();
}
};
@@ -119,14 +118,8 @@ public final class AccessibilityManager {
@Override
public void handleMessage(Message message) {
switch (message.what) {
- case DO_SET_ACCESSIBILITY_ENABLED :
- final boolean isAccessibilityEnabled = (message.arg1 == 1);
- setAccessibilityState(isAccessibilityEnabled);
- return;
- case DO_SET_TOUCH_EXPLORATION_ENABLED :
- synchronized (mHandler) {
- mIsTouchExplorationEnabled = (message.arg1 == 1);
- }
+ case DO_SET_STATE :
+ setState(message.arg1);
return;
default :
Log.w(LOG_TAG, "Unknown message type: " + message.what);
@@ -163,8 +156,8 @@ public final class AccessibilityManager {
mService = service;
try {
- final boolean isEnabled = mService.addClient(mClient);
- setAccessibilityState(isEnabled);
+ final int stateFlags = mService.addClient(mClient);
+ setState(stateFlags);
} catch (RemoteException re) {
Log.e(LOG_TAG, "AccessibilityManagerService is dead", re);
}
@@ -341,6 +334,17 @@ public final class AccessibilityManager {
}
/**
+ * Sets the current state.
+ *
+ * @param stateFlags The state flags.
+ */
+ private void setState(int stateFlags) {
+ final boolean accessibilityEnabled = (stateFlags & STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
+ setAccessibilityState(accessibilityEnabled);
+ mIsTouchExplorationEnabled = (stateFlags & STATE_FLAG_TOUCH_EXPLORATION_ENABLED) != 0;
+ }
+
+ /**
* Sets the enabled state.
*
* @param isEnabled The accessibility state.
diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java
index 0e04471..6469b35 100644
--- a/core/java/android/view/accessibility/AccessibilityNodeInfo.java
+++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java
@@ -294,14 +294,14 @@ public class AccessibilityNodeInfo implements Parcelable {
}
/**
- * Gets the unique id identifying this node's parent.
+ * Gets the parent.
* <p>
* <strong>Note:</strong> It is a client responsibility to recycle the
* received info by calling {@link AccessibilityNodeInfo#recycle()}
* to avoid creating of multiple instances.
* </p>
*
- * @return The node's patent id.
+ * @return The parent.
*/
public AccessibilityNodeInfo getParent() {
enforceSealed();
diff --git a/core/java/android/view/accessibility/IAccessibilityManager.aidl b/core/java/android/view/accessibility/IAccessibilityManager.aidl
index b14f02a..c621ff6 100644
--- a/core/java/android/view/accessibility/IAccessibilityManager.aidl
+++ b/core/java/android/view/accessibility/IAccessibilityManager.aidl
@@ -34,7 +34,7 @@ import android.view.IWindow;
*/
interface IAccessibilityManager {
- boolean addClient(IAccessibilityManagerClient client);
+ int addClient(IAccessibilityManagerClient client);
boolean sendAccessibilityEvent(in AccessibilityEvent uiEvent);
diff --git a/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl b/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl
index 4e69692..5e7e813 100644
--- a/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl
+++ b/core/java/android/view/accessibility/IAccessibilityManagerClient.aidl
@@ -24,7 +24,5 @@ package android.view.accessibility;
*/
oneway interface IAccessibilityManagerClient {
- void setEnabled(boolean enabled);
-
- void setTouchExplorationEnabled(boolean enabled);
+ void setState(int stateFlags);
}
diff --git a/core/java/android/view/animation/AlphaAnimation.java b/core/java/android/view/animation/AlphaAnimation.java
index 651fe45..c4d9afc 100644
--- a/core/java/android/view/animation/AlphaAnimation.java
+++ b/core/java/android/view/animation/AlphaAnimation.java
@@ -78,4 +78,12 @@ public class AlphaAnimation extends Animation {
public boolean willChangeBounds() {
return false;
}
+
+ /**
+ * @hide
+ */
+ @Override
+ public boolean hasAlpha() {
+ return true;
+ }
}
diff --git a/core/java/android/view/animation/Animation.java b/core/java/android/view/animation/Animation.java
index 87c759c..b7dfabc 100644
--- a/core/java/android/view/animation/Animation.java
+++ b/core/java/android/view/animation/Animation.java
@@ -1001,6 +1001,15 @@ public abstract class Animation implements Cloneable {
}
/**
+ * Return true if this animation changes the view's alpha property.
+ *
+ * @hide
+ */
+ public boolean hasAlpha() {
+ return false;
+ }
+
+ /**
* Utility class to parse a string description of a size.
*/
protected static class Description {
diff --git a/core/java/android/view/animation/AnimationSet.java b/core/java/android/view/animation/AnimationSet.java
index 873ce53..4f2542b 100644
--- a/core/java/android/view/animation/AnimationSet.java
+++ b/core/java/android/view/animation/AnimationSet.java
@@ -43,6 +43,8 @@ public class AnimationSet extends Animation {
private static final int PROPERTY_CHANGE_BOUNDS_MASK = 0x80;
private int mFlags = 0;
+ private boolean mDirty;
+ private boolean mHasAlpha;
private ArrayList<Animation> mAnimations = new ArrayList<Animation>();
@@ -138,6 +140,28 @@ public class AnimationSet extends Animation {
}
/**
+ * @hide
+ */
+ @Override
+ public boolean hasAlpha() {
+ if (mDirty) {
+ mDirty = mHasAlpha = false;
+
+ final int count = mAnimations.size();
+ final ArrayList<Animation> animations = mAnimations;
+
+ for (int i = 0; i < count; i++) {
+ if (animations.get(i).hasAlpha()) {
+ mHasAlpha = true;
+ break;
+ }
+ }
+ }
+
+ return mHasAlpha;
+ }
+
+ /**
* <p>Sets the duration of every child animation.</p>
*
* @param durationMillis the duration of the animation, in milliseconds, for
@@ -175,6 +199,8 @@ public class AnimationSet extends Animation {
mLastEnd = Math.max(mLastEnd, a.getStartOffset() + a.getDuration());
mDuration = mLastEnd - mStartOffset;
}
+
+ mDirty = true;
}
/**
diff --git a/core/java/android/view/textservice/SpellCheckerInfo.aidl b/core/java/android/view/textservice/SpellCheckerInfo.aidl
new file mode 100644
index 0000000..eb5dfcc
--- /dev/null
+++ b/core/java/android/view/textservice/SpellCheckerInfo.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.textservice;
+
+parcelable SpellCheckerInfo;
diff --git a/core/java/android/view/textservice/SpellCheckerInfo.java b/core/java/android/view/textservice/SpellCheckerInfo.java
new file mode 100644
index 0000000..d88a39f
--- /dev/null
+++ b/core/java/android/view/textservice/SpellCheckerInfo.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package android.view.textservice;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.graphics.drawable.Drawable;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * This class is used to specify meta information of an spell checker.
+ */
+public final class SpellCheckerInfo implements Parcelable {
+ private final ResolveInfo mService;
+ private final String mId;
+
+ /**
+ * Constructor.
+ * @hide
+ */
+ public SpellCheckerInfo(Context context, ResolveInfo service) {
+ mService = service;
+ ServiceInfo si = service.serviceInfo;
+ mId = new ComponentName(si.packageName, si.name).flattenToShortString();
+ }
+
+ /**
+ * Constructor.
+ * @hide
+ */
+ public SpellCheckerInfo(Parcel source) {
+ mId = source.readString();
+ mService = ResolveInfo.CREATOR.createFromParcel(source);
+ }
+
+ /**
+ * Return a unique ID for this spell checker. The ID is generated from
+ * the package and class name implementing the method.
+ */
+ public String getId() {
+ return mId;
+ }
+
+
+ /**
+ * Return the component of the service that implements.
+ */
+ public ComponentName getComponent() {
+ return new ComponentName(
+ mService.serviceInfo.packageName, mService.serviceInfo.name);
+ }
+
+ /**
+ * Return the .apk package that implements this input method.
+ */
+ public String getPackageName() {
+ return mService.serviceInfo.packageName;
+ }
+
+ /**
+ * Used to package this object into a {@link Parcel}.
+ *
+ * @param dest The {@link Parcel} to be written.
+ * @param flags The flags used for parceling.
+ */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(mId);
+ mService.writeToParcel(dest, flags);
+ }
+
+
+ /**
+ * Used to make this class parcelable.
+ */
+ public static final Parcelable.Creator<SpellCheckerInfo> CREATOR
+ = new Parcelable.Creator<SpellCheckerInfo>() {
+ @Override
+ public SpellCheckerInfo createFromParcel(Parcel source) {
+ return new SpellCheckerInfo(source);
+ }
+
+ @Override
+ public SpellCheckerInfo[] newArray(int size) {
+ return new SpellCheckerInfo[size];
+ }
+ };
+
+ /**
+ * Load the user-displayed label for this spell checker.
+ *
+ * @param pm Supply a PackageManager used to load the spell checker's resources.
+ */
+ public CharSequence loadLabel(PackageManager pm) {
+ return mService.loadLabel(pm);
+ }
+
+ /**
+ * Load the user-displayed icon for this spell checker.
+ *
+ * @param pm Supply a PackageManager used to load the spell checker's resources.
+ */
+ public Drawable loadIcon(PackageManager pm) {
+ return mService.loadIcon(pm);
+ }
+
+ /**
+ * Used to make this class parcelable.
+ */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
diff --git a/core/java/android/view/textservice/SuggestionsInfo.aidl b/core/java/android/view/textservice/SuggestionsInfo.aidl
new file mode 100644
index 0000000..66e20d2
--- /dev/null
+++ b/core/java/android/view/textservice/SuggestionsInfo.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.textservice;
+
+parcelable SuggestionsInfo;
diff --git a/core/java/android/view/textservice/SuggestionsInfo.java b/core/java/android/view/textservice/SuggestionsInfo.java
new file mode 100644
index 0000000..3332f1e
--- /dev/null
+++ b/core/java/android/view/textservice/SuggestionsInfo.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package android.view.textservice;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * This class contains a metadata of suggestions from the text service
+ */
+public final class SuggestionsInfo implements Parcelable {
+ private static final String[] EMPTY = new String[0];
+
+ /**
+ * Flag of the attributes of the suggestions that can be obtained by
+ * {@link #getSuggestionsAttributes}: this tells that the requested word was found
+ * in the dictionary in the text service.
+ */
+ public static final int RESULT_ATTR_IN_THE_DICTIONARY = 0x0001;
+ /**
+ * Flag of the attributes of the suggestions that can be obtained by
+ * {@link #getSuggestionsAttributes}: this tells that the text service thinks the requested
+ * word looks a typo.
+ */
+ public static final int RESULT_ATTR_LOOKS_TYPO = 0x0002;
+ private final int mSuggestionsAttributes;
+ private final String[] mSuggestions;
+ private final boolean mSuggestionsAvailable;
+ private int mCookie;
+ private int mSequence;
+
+ /**
+ * Constructor.
+ * @param suggestionsAttributes from the text service
+ * @param suggestions from the text service
+ */
+ public SuggestionsInfo(int suggestionsAttributes, String[] suggestions) {
+ mSuggestionsAttributes = suggestionsAttributes;
+ if (suggestions == null) {
+ mSuggestions = EMPTY;
+ mSuggestionsAvailable = false;
+ } else {
+ mSuggestions = suggestions;
+ mSuggestionsAvailable = true;
+ }
+ mCookie = 0;
+ mSequence = 0;
+ }
+
+ /**
+ * Constructor.
+ * @param suggestionsAttributes from the text service
+ * @param suggestions from the text service
+ * @param cookie the cookie of the input TextInfo
+ * @param sequence the cookie of the input TextInfo
+ */
+ public SuggestionsInfo(
+ int suggestionsAttributes, String[] suggestions, int cookie, int sequence) {
+ if (suggestions == null) {
+ mSuggestions = EMPTY;
+ mSuggestionsAvailable = false;
+ } else {
+ mSuggestions = suggestions;
+ mSuggestionsAvailable = true;
+ }
+ mSuggestionsAttributes = suggestionsAttributes;
+ mCookie = cookie;
+ mSequence = sequence;
+ }
+
+ public SuggestionsInfo(Parcel source) {
+ mSuggestionsAttributes = source.readInt();
+ mSuggestions = source.readStringArray();
+ mCookie = source.readInt();
+ mSequence = source.readInt();
+ mSuggestionsAvailable = source.readInt() == 1;
+ }
+
+ /**
+ * Used to package this object into a {@link Parcel}.
+ *
+ * @param dest The {@link Parcel} to be written.
+ * @param flags The flags used for parceling.
+ */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mSuggestionsAttributes);
+ dest.writeStringArray(mSuggestions);
+ dest.writeInt(mCookie);
+ dest.writeInt(mSequence);
+ dest.writeInt(mSuggestionsAvailable ? 1 : 0);
+ }
+
+ /**
+ * Set the cookie and the sequence of SuggestionsInfo which are set to TextInfo from a client
+ * application
+ * @param cookie the cookie of an input TextInfo
+ * @param sequence the cookie of an input TextInfo
+ */
+ public void setCookieAndSequence(int cookie, int sequence) {
+ mCookie = cookie;
+ mSequence = sequence;
+ }
+
+ /**
+ * @return the cookie which may be set by a client application
+ */
+ public int getCookie() {
+ return mCookie;
+ }
+
+ /**
+ * @return the sequence which may be set by a client application
+ */
+ public int getSequence() {
+ return mSequence;
+ }
+
+ /**
+ * @return the attributes of suggestions. This includes whether the spell checker has the word
+ * in its dictionary or not and whether the spell checker has confident suggestions for the
+ * word or not.
+ */
+ public int getSuggestionsAttributes() {
+ return mSuggestionsAttributes;
+ }
+
+ /**
+ * @return the count of the suggestions. If there's no suggestions at all, this method returns
+ * -1. Even if this method returns 0, it doesn't necessarily mean that there are no suggestions
+ * for the requested word. For instance, the caller could have been asked to limit the maximum
+ * number of suggestions returned.
+ */
+ public int getSuggestionsCount() {
+ if (!mSuggestionsAvailable) {
+ return -1;
+ }
+ return mSuggestions.length;
+ }
+
+ /**
+ * @param i the id of suggestions
+ * @return the suggestion at the specified id
+ */
+ public String getSuggestionAt(int i) {
+ return mSuggestions[i];
+ }
+
+ /**
+ * Used to make this class parcelable.
+ */
+ public static final Parcelable.Creator<SuggestionsInfo> CREATOR
+ = new Parcelable.Creator<SuggestionsInfo>() {
+ @Override
+ public SuggestionsInfo createFromParcel(Parcel source) {
+ return new SuggestionsInfo(source);
+ }
+
+ @Override
+ public SuggestionsInfo[] newArray(int size) {
+ return new SuggestionsInfo[size];
+ }
+ };
+
+ /**
+ * Used to make this class parcelable.
+ */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
diff --git a/core/java/android/view/textservice/TextInfo.aidl b/core/java/android/view/textservice/TextInfo.aidl
new file mode 100644
index 0000000..d231d76
--- /dev/null
+++ b/core/java/android/view/textservice/TextInfo.aidl
@@ -0,0 +1,19 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.textservice;
+
+parcelable TextInfo;
diff --git a/core/java/android/view/textservice/TextInfo.java b/core/java/android/view/textservice/TextInfo.java
new file mode 100644
index 0000000..b534eb0
--- /dev/null
+++ b/core/java/android/view/textservice/TextInfo.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package android.view.textservice;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.text.TextUtils;
+
+/**
+ * This class contains a metadata of the input of TextService
+ */
+public final class TextInfo implements Parcelable {
+ private final String mText;
+ private final int mCookie;
+ private final int mSequence;
+
+ /**
+ * Constructor.
+ * @param text the text which will be input to TextService
+ */
+ public TextInfo(String text) {
+ this(text, 0, 0);
+ }
+
+ /**
+ * Constructor.
+ * @param text the text which will be input to TextService
+ * @param cookie the cookie for this TextInfo
+ * @param sequence the sequence number for this TextInfo
+ */
+ public TextInfo(String text, int cookie, int sequence) {
+ if (TextUtils.isEmpty(text)) {
+ throw new IllegalArgumentException(text);
+ }
+ mText = text;
+ mCookie = cookie;
+ mSequence = sequence;
+ }
+
+ public TextInfo(Parcel source) {
+ mText = source.readString();
+ mCookie = source.readInt();
+ mSequence = source.readInt();
+ }
+
+ /**
+ * Used to package this object into a {@link Parcel}.
+ *
+ * @param dest The {@link Parcel} to be written.
+ * @param flags The flags used for parceling.
+ */
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(mText);
+ dest.writeInt(mCookie);
+ dest.writeInt(mSequence);
+ }
+
+ /**
+ * @return the text which is an input of a text service
+ */
+ public String getText() {
+ return mText;
+ }
+
+ /**
+ * @return the cookie of TextInfo
+ */
+ public int getCookie() {
+ return mCookie;
+ }
+
+ /**
+ * @return the sequence of TextInfo
+ */
+ public int getSequence() {
+ return mSequence;
+ }
+
+ /**
+ * Used to make this class parcelable.
+ */
+ public static final Parcelable.Creator<TextInfo> CREATOR
+ = new Parcelable.Creator<TextInfo>() {
+ @Override
+ public TextInfo createFromParcel(Parcel source) {
+ return new TextInfo(source);
+ }
+
+ @Override
+ public TextInfo[] newArray(int size) {
+ return new TextInfo[size];
+ }
+ };
+
+ /**
+ * Used to make this class parcelable.
+ */
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+}
diff --git a/core/java/android/view/textservice/TextServicesManager.java b/core/java/android/view/textservice/TextServicesManager.java
new file mode 100644
index 0000000..229b414
--- /dev/null
+++ b/core/java/android/view/textservice/TextServicesManager.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package android.view.textservice;
+
+import com.android.internal.textservice.ITextServicesManager;
+
+import android.content.Context;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.view.textservice.SpellCheckerInfo;
+import android.service.textservice.SpellCheckerSession;
+import android.service.textservice.SpellCheckerSession.SpellCheckerSessionListener;
+
+import java.util.Locale;
+
+/**
+ * System API to the overall text services, which arbitrates interaction between applications
+ * and text services. You can retrieve an instance of this interface with
+ * {@link Context#getSystemService(String) Context.getSystemService()}.
+ *
+ * The user can change the current text services in Settings. And also applications can specify
+ * the target text services.
+ */
+public final class TextServicesManager {
+ private static final String TAG = TextServicesManager.class.getSimpleName();
+
+ private static TextServicesManager sInstance;
+ private static ITextServicesManager sService;
+
+ private TextServicesManager() {
+ if (sService == null) {
+ IBinder b = ServiceManager.getService(Context.TEXT_SERVICES_MANAGER_SERVICE);
+ sService = ITextServicesManager.Stub.asInterface(b);
+ }
+ }
+
+ /**
+ * Retrieve the global TextServicesManager instance, creating it if it doesn't already exist.
+ * @hide
+ */
+ public static TextServicesManager getInstance() {
+ synchronized (TextServicesManager.class) {
+ if (sInstance != null) {
+ return sInstance;
+ }
+ sInstance = new TextServicesManager();
+ }
+ return sInstance;
+ }
+
+ /**
+ * Get a spell checker session for the specified spell checker
+ * @param locale the locale for the spell checker
+ * @param listener a spell checker session lister for getting results from a spell checker.
+ * @param referToSpellCheckerLanguageSettings if true, the session for one of enabled
+ * languages in settings will be returned.
+ * @return the spell checker session of the spell checker
+ */
+ // TODO: Add a method to get enabled spell checkers.
+ // TODO: Handle referToSpellCheckerLanguageSettings
+ public SpellCheckerSession newSpellCheckerSession(Locale locale,
+ SpellCheckerSessionListener listener, boolean referToSpellCheckerLanguageSettings) {
+ if (locale == null || listener == null) {
+ throw new NullPointerException();
+ }
+ final SpellCheckerInfo info;
+ try {
+ info = sService.getCurrentSpellChecker(locale.toString());
+ } catch (RemoteException e) {
+ return null;
+ }
+ if (info == null) {
+ return null;
+ }
+ final SpellCheckerSession session = new SpellCheckerSession(info, sService, listener);
+ try {
+ sService.getSpellCheckerService(
+ info, locale.toString(), session.getTextServicesSessionListener(),
+ session.getSpellCheckerSessionListener());
+ } catch (RemoteException e) {
+ return null;
+ }
+ return session;
+ }
+
+ /**
+ * @hide
+ */
+ public SpellCheckerInfo[] getEnabledSpellCheckers() {
+ try {
+ return sService.getEnabledSpellCheckers();
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+
+ /**
+ * @hide
+ */
+ public SpellCheckerInfo getCurrentSpellChecker() {
+ try {
+ // Passing null as a locale for ICS
+ return sService.getCurrentSpellChecker(null);
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+}
diff --git a/core/java/android/webkit/JniUtil.java b/core/java/android/webkit/JniUtil.java
index bb4d192..620973e 100644
--- a/core/java/android/webkit/JniUtil.java
+++ b/core/java/android/webkit/JniUtil.java
@@ -18,6 +18,7 @@ package android.webkit;
import android.content.Context;
import android.net.Uri;
+import android.provider.Settings;
import android.util.Log;
import java.io.InputStream;
@@ -38,7 +39,7 @@ class JniUtil {
private static boolean initialized = false;
- private static void checkIntialized() {
+ private static void checkInitialized() {
if (!initialized) {
throw new IllegalStateException("Call CookieSyncManager::createInstance() or create a webview before using this class");
}
@@ -63,7 +64,7 @@ class JniUtil {
* @return String The application's database directory
*/
private static synchronized String getDatabaseDirectory() {
- checkIntialized();
+ checkInitialized();
if (sDatabaseDirectory == null)
sDatabaseDirectory = sContext.getDatabasePath("dummy").getParent();
@@ -76,7 +77,7 @@ class JniUtil {
* @return String The application's cache directory
*/
private static synchronized String getCacheDirectory() {
- checkIntialized();
+ checkInitialized();
if (sCacheDirectory == null)
sCacheDirectory = sContext.getCacheDir().getAbsolutePath();
@@ -166,5 +167,13 @@ class JniUtil {
return sUseChromiumHttpStack;
}
+ private static synchronized String getAutofillQueryUrl() {
+ checkInitialized();
+ // If the device has not checked in it won't have pulled down the system setting for the
+ // Autofill Url. In that case we will not make autofill server requests.
+ return Settings.Secure.getString(sContext.getContentResolver(),
+ Settings.Secure.WEB_AUTOFILL_QUERY_URL);
+ }
+
private static native boolean nativeUseChromiumHttpStack();
}
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 6a3b2ff..e24ab58 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -4701,6 +4701,7 @@ public class WebView extends AbsoluteLayout
private Message mUpdateMessage;
private boolean mAutoFillable;
private boolean mAutoComplete;
+ private WebSettings mWebSettings;
public RequestFormData(String name, String url, Message msg,
boolean autoFillable, boolean autoComplete) {
@@ -4709,6 +4710,7 @@ public class WebView extends AbsoluteLayout
mUpdateMessage = msg;
mAutoFillable = autoFillable;
mAutoComplete = autoComplete;
+ mWebSettings = getSettings();
}
public void run() {
@@ -4718,8 +4720,7 @@ public class WebView extends AbsoluteLayout
// Note that code inside the adapter click handler in WebTextView depends
// on the AutoFill item being at the top of the drop down list. If you change
// the order, make sure to do it there too!
- WebSettings settings = getSettings();
- if (settings != null && settings.getAutoFillProfile() != null) {
+ if (mWebSettings != null && mWebSettings.getAutoFillProfile() != null) {
pastEntries.add(getResources().getText(
com.android.internal.R.string.autofill_this_form).toString() +
" " +
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java
index 563fc26..36927ca 100644
--- a/core/java/android/widget/PopupWindow.java
+++ b/core/java/android/widget/PopupWindow.java
@@ -91,6 +91,7 @@ public class PopupWindow {
private boolean mLayoutInScreen;
private boolean mClipToScreen;
private boolean mAllowScrollingAnchorParent = true;
+ private boolean mLayoutInsetDecor = false;
private OnTouchListener mTouchInterceptor;
@@ -658,6 +659,22 @@ public class PopupWindow {
}
/**
+ * Allows the popup window to force the flag
+ * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}, overriding default behavior.
+ * This will cause the popup to inset its content to account for system windows overlaying
+ * the screen, such as the status bar.
+ *
+ * <p>This will often be combined with {@link #setLayoutInScreenEnabled(boolean)}.
+ *
+ * @param enabled true if the popup's views should inset content to account for system windows,
+ * the way that decor views behave for full-screen windows.
+ * @hide
+ */
+ public void setLayoutInsetDecor(boolean enabled) {
+ mLayoutInsetDecor = enabled;
+ }
+
+ /**
* Set the layout type for this window. Should be one of the TYPE constants defined in
* {@link WindowManager.LayoutParams}.
*
@@ -942,6 +959,7 @@ public class PopupWindow {
if (mContext != null) {
p.packageName = mContext.getPackageName();
}
+ mPopupView.setFitsSystemWindows(mLayoutInsetDecor);
mWindowManager.addView(mPopupView, p);
}
@@ -1012,6 +1030,9 @@ public class PopupWindow {
if (mLayoutInScreen) {
curFlags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
}
+ if (mLayoutInsetDecor) {
+ curFlags |= WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
+ }
return curFlags;
}
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java
index b2d1a1e..55b73df 100644
--- a/core/java/android/widget/SearchView.java
+++ b/core/java/android/widget/SearchView.java
@@ -45,6 +45,7 @@ import android.text.style.ImageSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
+import android.view.CollapsibleActionView;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@@ -58,18 +59,30 @@ import com.android.internal.R;
import java.util.WeakHashMap;
/**
- * A widget that provides a user interface for the user to enter a search query and submit a
- * request to a search provider. Shows a list of query suggestions or results, if
- * available, and allows the user to pick a suggestion or result to launch into.
+ * A widget that provides a user interface for the user to enter a search query and submit a request
+ * to a search provider. Shows a list of query suggestions or results, if available, and allows the
+ * user to pick a suggestion or result to launch into.
*
- * <p>For more information, see the <a href="{@docRoot}guide/topics/search/index.html">Search</a>
- * documentation.<p>
+ * <p>
+ * When the SearchView is used in an ActionBar as an action view for a collapsible menu item, it
+ * needs to be set to iconified by default using {@link #setIconifiedByDefault(boolean)
+ * setIconifiedByDefault(true)}. This is the default, so nothing needs to be done.
+ * </p>
+ * <p>
+ * If you want the search field to always be visible, then call setIconifiedByDefault(false).
+ * </p>
*
+ * <p>
+ * For more information, see the <a href="{@docRoot}guide/topics/search/index.html">Search</a>
+ * documentation.
+ * <p>
+ *
+ * @see android.view.MenuItem#SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
* @attr ref android.R.styleable#SearchView_iconifiedByDefault
* @attr ref android.R.styleable#SearchView_maxWidth
* @attr ref android.R.styleable#SearchView_queryHint
*/
-public class SearchView extends LinearLayout {
+public class SearchView extends LinearLayout implements CollapsibleActionView {
private static final boolean DBG = false;
private static final String LOG_TAG = "SearchView";
@@ -100,6 +113,7 @@ public class SearchView extends LinearLayout {
private int mMaxWidth;
private boolean mVoiceButtonEnabled;
private CharSequence mUserQuery;
+ private boolean mExpandedInActionView;
private SearchableInfo mSearchable;
private Bundle mAppSearchData;
@@ -623,7 +637,7 @@ public class SearchView extends LinearLayout {
final boolean hasText = !TextUtils.isEmpty(mQueryTextView.getText());
// Should we show the close button? It is not shown if there's no focus,
// field is not iconified by default and there is no text in it.
- final boolean showClose = hasText || mIconifiedByDefault;
+ final boolean showClose = hasText || (mIconifiedByDefault && !mExpandedInActionView);
mCloseButton.setVisibility(showClose ? VISIBLE : INVISIBLE);
mCloseButton.getDrawable().setState(hasText ? ENABLED_STATE_SET : EMPTY_STATE_SET);
}
@@ -1022,6 +1036,25 @@ public class SearchView extends LinearLayout {
super.onAttachedToWindow();
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onActionViewCollapsed() {
+ mQueryTextView.setText("");
+ setIconified(true);
+ mExpandedInActionView = false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onActionViewExpanded() {
+ mExpandedInActionView = true;
+ setIconified(false);
+ }
+
private void adjustDropDownSizeAndPosition() {
if (mDropDownAnchor.getWidth() > 1) {
Resources res = getContext().getResources();
diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java
index b7565f3..0c80a11 100644
--- a/core/java/android/widget/Switch.java
+++ b/core/java/android/widget/Switch.java
@@ -34,6 +34,7 @@ import android.view.Gravity;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
+import android.view.accessibility.AccessibilityEvent;
import com.android.internal.R;
@@ -360,6 +361,13 @@ public class Switch extends CompoundButton {
}
}
+ @Override
+ public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
+ super.onPopulateAccessibilityEvent(event);
+ Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
+ event.getText().add(switchText.getText());
+ }
+
private Layout makeLayout(CharSequence text) {
return new StaticLayout(text, mTextPaint,
(int) Math.ceil(Layout.getDesiredWidth(text, mTextPaint)),
diff --git a/core/java/com/android/internal/textservice/ISpellCheckerService.aidl b/core/java/com/android/internal/textservice/ISpellCheckerService.aidl
new file mode 100644
index 0000000..ff00492
--- /dev/null
+++ b/core/java/com/android/internal/textservice/ISpellCheckerService.aidl
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.textservice;
+
+import com.android.internal.textservice.ISpellCheckerSession;
+import com.android.internal.textservice.ISpellCheckerSessionListener;
+
+/**
+ * Public interface to the global spell checker.
+ * @hide
+ */
+interface ISpellCheckerService {
+ ISpellCheckerSession getISpellCheckerSession(
+ String locale, ISpellCheckerSessionListener listener);
+}
diff --git a/core/java/com/android/internal/textservice/ISpellCheckerSession.aidl b/core/java/com/android/internal/textservice/ISpellCheckerSession.aidl
new file mode 100644
index 0000000..79e43510c0
--- /dev/null
+++ b/core/java/com/android/internal/textservice/ISpellCheckerSession.aidl
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.textservice;
+
+import android.view.textservice.TextInfo;
+
+/**
+ * @hide
+ */
+oneway interface ISpellCheckerSession {
+ void getSuggestionsMultiple(
+ in TextInfo[] textInfos, int suggestionsLimit, boolean multipleWords);
+ void cancel();
+}
diff --git a/core/java/com/android/internal/textservice/ISpellCheckerSessionListener.aidl b/core/java/com/android/internal/textservice/ISpellCheckerSessionListener.aidl
new file mode 100644
index 0000000..796b06e
--- /dev/null
+++ b/core/java/com/android/internal/textservice/ISpellCheckerSessionListener.aidl
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.textservice;
+
+import android.view.textservice.SuggestionsInfo;
+
+/**
+ * @hide
+ */
+oneway interface ISpellCheckerSessionListener {
+ void onGetSuggestions(in SuggestionsInfo[] results);
+}
diff --git a/core/java/com/android/internal/textservice/ITextServicesManager.aidl b/core/java/com/android/internal/textservice/ITextServicesManager.aidl
new file mode 100644
index 0000000..2a045e3
--- /dev/null
+++ b/core/java/com/android/internal/textservice/ITextServicesManager.aidl
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.textservice;
+
+import com.android.internal.textservice.ISpellCheckerSessionListener;
+import com.android.internal.textservice.ITextServicesSessionListener;
+
+import android.content.ComponentName;
+import android.view.textservice.SpellCheckerInfo;
+
+/**
+ * Interface to the text service manager.
+ * @hide
+ */
+interface ITextServicesManager {
+ SpellCheckerInfo getCurrentSpellChecker(String locale);
+ oneway void getSpellCheckerService(in SpellCheckerInfo info, in String locale,
+ in ITextServicesSessionListener tsListener,
+ in ISpellCheckerSessionListener scListener);
+ oneway void finishSpellCheckerService(in ISpellCheckerSessionListener listener);
+ SpellCheckerInfo[] getEnabledSpellCheckers();
+}
diff --git a/core/java/com/android/internal/textservice/ITextServicesSessionListener.aidl b/core/java/com/android/internal/textservice/ITextServicesSessionListener.aidl
new file mode 100644
index 0000000..ecb6cd0
--- /dev/null
+++ b/core/java/com/android/internal/textservice/ITextServicesSessionListener.aidl
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.textservice;
+
+import com.android.internal.textservice.ISpellCheckerSession;
+
+import android.view.textservice.SpellCheckerInfo;
+
+/**
+ * Interface to the text service session.
+ * @hide
+ */
+interface ITextServicesSessionListener {
+ oneway void onServiceConnected(in ISpellCheckerSession spellCheckerSession);
+}
diff --git a/core/java/com/android/internal/util/Protocol.java b/core/java/com/android/internal/util/Protocol.java
index 69b80d9..9ecd29f 100644
--- a/core/java/com/android/internal/util/Protocol.java
+++ b/core/java/com/android/internal/util/Protocol.java
@@ -41,6 +41,9 @@ public class Protocol {
/** Non system protocols */
public static final int BASE_WIFI = 0x00020000;
public static final int BASE_WIFI_WATCHDOG = 0x00021000;
+ public static final int BASE_WIFI_P2P_MANAGER = 0x00022000;
+ public static final int BASE_WIFI_P2P_SERVICE = 0x00023000;
+ public static final int BASE_WIFI_MONITOR = 0x00024000;
public static final int BASE_DHCP = 0x00030000;
public static final int BASE_DATA_CONNECTION = 0x00040000;
public static final int BASE_DATA_CONNECTION_AC = 0x00041000;
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index 8b74f3d..09262e0 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -286,8 +286,11 @@ public class ActionBarView extends AbsActionBarView {
public void setSplitActionBar(boolean splitActionBar) {
if (mSplitActionBar != splitActionBar) {
if (mMenuView != null) {
+ final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
+ if (oldParent != null) {
+ oldParent.removeView(mMenuView);
+ }
if (splitActionBar) {
- removeView(mMenuView);
if (mSplitView != null) {
mSplitView.addView(mMenuView);
}
@@ -333,7 +336,10 @@ public class ActionBarView extends AbsActionBarView {
MenuBuilder builder = (MenuBuilder) menu;
mOptionsMenu = builder;
if (mMenuView != null) {
- removeView(mMenuView);
+ final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
+ if (oldParent != null) {
+ oldParent.removeView(mMenuView);
+ }
}
if (mActionMenuPresenter == null) {
mActionMenuPresenter = new ActionMenuPresenter();
@@ -352,6 +358,10 @@ public class ActionBarView extends AbsActionBarView {
builder.addMenuPresenter(mActionMenuPresenter);
builder.addMenuPresenter(mExpandedMenuPresenter);
menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
+ final ViewGroup oldParent = (ViewGroup) menuView.getParent();
+ if (oldParent != null && oldParent != this) {
+ oldParent.removeView(menuView);
+ }
addView(menuView, layoutParams);
} else {
mActionMenuPresenter.setExpandedActionViewsExclusive(false);
@@ -366,6 +376,10 @@ public class ActionBarView extends AbsActionBarView {
builder.addMenuPresenter(mExpandedMenuPresenter);
menuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
if (mSplitView != null) {
+ final ViewGroup oldParent = (ViewGroup) menuView.getParent();
+ if (oldParent != null && oldParent != mSplitView) {
+ oldParent.removeView(menuView);
+ }
mSplitView.addView(menuView, layoutParams);
} else {
// We'll add this later if we missed it this time.
diff --git a/core/jni/android_net_wifi_Wifi.cpp b/core/jni/android_net_wifi_Wifi.cpp
index 0c81634..3cbd912 100644
--- a/core/jni/android_net_wifi_Wifi.cpp
+++ b/core/jni/android_net_wifi_Wifi.cpp
@@ -28,6 +28,9 @@
#define WIFI_PKG_NAME "android/net/wifi/WifiNative"
#define BUF_SIZE 256
+//TODO: This file can be refactored to push a lot of the functionality to java
+//with just a few JNI calls - doBoolean/doInt/doString
+
namespace android {
static jboolean sScanModeActive = false;
@@ -537,6 +540,35 @@ static void android_net_wifi_setScanIntervalCommand(JNIEnv* env, jobject, jint s
}
+static jboolean android_net_wifi_doBooleanCommand(JNIEnv* env, jobject, jstring javaCommand)
+{
+ ScopedUtfChars command(env, javaCommand);
+ if (command.c_str() == NULL) {
+ return JNI_FALSE;
+ }
+ return doBooleanCommand("OK", "%s", command.c_str());
+}
+
+static jint android_net_wifi_doIntCommand(JNIEnv* env, jobject, jstring javaCommand)
+{
+ ScopedUtfChars command(env, javaCommand);
+ if (command.c_str() == NULL) {
+ return -1;
+ }
+ return doIntCommand("%s", command.c_str());
+}
+
+static jstring android_net_wifi_doStringCommand(JNIEnv* env, jobject, jstring javaCommand)
+{
+ ScopedUtfChars command(env, javaCommand);
+ if (command.c_str() == NULL) {
+ return NULL;
+ }
+ return doStringCommand(env, "%s", command.c_str());
+}
+
+
+
// ----------------------------------------------------------------------------
/*
@@ -608,6 +640,9 @@ static JNINativeMethod gWifiMethods[] = {
(void*) android_net_wifi_setCountryCodeCommand},
{ "enableBackgroundScanCommand", "(Z)V", (void*) android_net_wifi_enableBackgroundScanCommand},
{ "setScanIntervalCommand", "(I)V", (void*) android_net_wifi_setScanIntervalCommand},
+ { "doBooleanCommand", "(Ljava/lang/String;)Z", (void*) android_net_wifi_doBooleanCommand},
+ { "doIntCommand", "(Ljava/lang/String;)I", (void*) android_net_wifi_doIntCommand},
+ { "doStringCommand", "(Ljava/lang/String;)Ljava/lang/String;", (void*) android_net_wifi_doStringCommand},
};
int register_android_net_wifi_WifiManager(JNIEnv* env)
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 0dc9293..4c1ca31 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -22,6 +22,7 @@
#include "android/graphics/GraphicsJNI.h"
#include <binder/IMemory.h>
+#include <gui/SurfaceTexture.h>
#include <surfaceflinger/SurfaceComposerClient.h>
#include <surfaceflinger/Surface.h>
#include <ui/Region.h>
@@ -38,6 +39,7 @@
#include "JNIHelp.h"
#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/android_view_Surface.h>
+#include <android_runtime/android_graphics_SurfaceTexture.h>
#include <utils/misc.h>
@@ -244,6 +246,19 @@ static void Surface_init(
setSurfaceControl(env, clazz, surface);
}
+static void Surface_initFromSurfaceTexture(
+ JNIEnv* env, jobject clazz, jobject jst)
+{
+ sp<ISurfaceTexture> st(SurfaceTexture_getSurfaceTexture(env, jst));
+ sp<Surface> surface(new Surface(st));
+ if (surface == NULL) {
+ jniThrowException(env, OutOfResourcesException, NULL);
+ return;
+ }
+ setSurfaceControl(env, clazz, NULL);
+ setSurface(env, clazz, surface);
+}
+
static void Surface_initParcel(JNIEnv* env, jobject clazz, jobject argParcel)
{
Parcel* parcel = (Parcel*)env->GetIntField(argParcel, no.native_parcel);
@@ -761,10 +776,26 @@ static void Surface_writeToParcel(
return;
}
+ // The Java instance may have a SurfaceControl (in the case of the
+ // WindowManager or a system app). In that case, we defer to the
+ // SurfaceControl to send its ISurface. Otherwise, if the Surface is
+ // available we let it parcel itself. Finally, if the Surface is also
+ // NULL we fall back to using the SurfaceControl path which sends an
+ // empty surface; this matches legacy behavior.
const sp<SurfaceControl>& control(getSurfaceControl(env, clazz));
- SurfaceControl::writeSurfaceToParcel(control, parcel);
+ if (control != NULL) {
+ SurfaceControl::writeSurfaceToParcel(control, parcel);
+ } else {
+ sp<Surface> surface(Surface_getSurface(env, clazz));
+ if (surface != NULL) {
+ Surface::writeToParcel(surface, parcel);
+ } else {
+ SurfaceControl::writeSurfaceToParcel(NULL, parcel);
+ }
+ }
if (flags & PARCELABLE_WRITE_RETURN_VALUE) {
- setSurfaceControl(env, clazz, 0);
+ setSurfaceControl(env, clazz, NULL);
+ setSurface(env, clazz, NULL);
}
}
@@ -784,6 +815,7 @@ static JNINativeMethod gSurfaceMethods[] = {
{"nativeClassInit", "()V", (void*)nativeClassInit },
{"init", "(Landroid/view/SurfaceSession;ILjava/lang/String;IIIII)V", (void*)Surface_init },
{"init", "(Landroid/os/Parcel;)V", (void*)Surface_initParcel },
+ {"initFromSurfaceTexture", "(Landroid/graphics/SurfaceTexture;)V", (void*)Surface_initFromSurfaceTexture },
{"getIdentity", "()I", (void*)Surface_getIdentity },
{"destroy", "()V", (void*)Surface_destroy },
{"release", "()V", (void*)Surface_release },
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index c67b625..91003d1 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1120,6 +1120,13 @@
android:description="@string/permdesc_bindInputMethod"
android:protectionLevel="signature" />
+ <!-- Must be required by a TextService (e.g. SpellCheckerService)
+ to ensure that only the system can bind to it. -->
+ <permission android:name="android.permission.BIND_TEXT_SERVICE"
+ android:label="@string/permlab_bindTextService"
+ android:description="@string/permdesc_bindTextService"
+ android:protectionLevel="signature" />
+
<!-- Must be required by a {@link android.service.wallpaper.WallpaperService},
to ensure that only the system can bind to it. -->
<permission android:name="android.permission.BIND_WALLPAPER"
diff --git a/core/res/res/anim/screen_rotate_minus_90_enter.xml b/core/res/res/anim/screen_rotate_minus_90_enter.xml
index 30518e0..61aa72a 100644
--- a/core/res/res/anim/screen_rotate_minus_90_enter.xml
+++ b/core/res/res/anim/screen_rotate_minus_90_enter.xml
@@ -19,11 +19,6 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
- <scale android:fromXScale="100%p" android:toXScale="100%"
- android:fromYScale="100%p" android:toYScale="100%"
- android:pivotX="50%" android:pivotY="50%"
- android:interpolator="@interpolator/decelerate_quint"
- android:duration="@android:integer/config_mediumAnimTime" />
<rotate android:fromDegrees="-90" android:toDegrees="0"
android:pivotX="50%" android:pivotY="50%"
android:interpolator="@interpolator/decelerate_quint"
diff --git a/core/res/res/anim/screen_rotate_plus_90_enter.xml b/core/res/res/anim/screen_rotate_plus_90_enter.xml
index 20943c8..53b0ccd 100644
--- a/core/res/res/anim/screen_rotate_plus_90_enter.xml
+++ b/core/res/res/anim/screen_rotate_plus_90_enter.xml
@@ -19,11 +19,6 @@
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
- <scale android:fromXScale="100%p" android:toXScale="100%"
- android:fromYScale="100%p" android:toYScale="100%"
- android:pivotX="50%" android:pivotY="50%"
- android:interpolator="@interpolator/decelerate_quint"
- android:duration="@android:integer/config_mediumAnimTime" />
<rotate android:fromDegrees="90" android:toDegrees="0"
android:pivotX="50%" android:pivotY="50%"
android:interpolator="@interpolator/decelerate_quint"
diff --git a/core/res/res/layout/wifi_p2p_go_negotiation_request_alert.xml b/core/res/res/layout/wifi_p2p_go_negotiation_request_alert.xml
new file mode 100644
index 0000000..41ca657
--- /dev/null
+++ b/core/res/res/layout/wifi_p2p_go_negotiation_request_alert.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2011 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+
+ <EditText android:id="@+id/wifi_p2p_wps_pin"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:inputType="textPassword"
+ />
+</LinearLayout>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 7d7aea9..b5fc55e 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2278,6 +2278,8 @@
<flag name="feedbackVisual" value="0x00000008" />
<!-- Provides {@link android.accessibilityservice.AccessibilityServiceInfo#FEEDBACK_GENERIC} feedback. -->
<flag name="feedbackGeneric" value="0x00000010" />
+ <!-- Provides {@link android.accessibilityservice.AccessibilityServiceInfo#FEEDBACK_ALL_MASK} feedback. -->
+ <flag name="feedbackAllMask" value="0xffffffff" />
</attr>
<!-- The minimal period in milliseconds between two accessibility events of the same type
are sent to this serivce. This setting can be changed at runtime by calling
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 215700c..65dce49 100755
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -182,6 +182,9 @@
<!-- Boolean indicating whether the wifi chipset has dual frequency band support -->
<bool translatable="false" name="config_wifi_dual_band_support">false</bool>
+ <!-- Boolean indicating whether the wifi chipset has p2p support -->
+ <bool translatable="false" name="config_wifi_p2p_support">false</bool>
+
<!-- Boolean indicating whether the wifi chipset supports background scanning mechanism.
This mechanism allows the host to remain in suspend state and the dongle to actively
scan and wake the host when a configured SSID is detected by the dongle. This chipset
@@ -466,6 +469,10 @@
speech -->
<bool name="config_bluetooth_wide_band_speech">true</bool>
+ <!-- Boolean indicating if current platform supports quick switch-on/off of
+ Bluetooth Module -->
+ <bool name="config_bluetooth_adapter_quick_switch">true</bool>
+
<!-- The default data-use polling period. -->
<integer name="config_datause_polling_period_sec">600</integer>
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 5b25e2d..e1a31f4 100755
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -705,6 +705,12 @@
interface of an input method. Should never be needed for normal applications.</string>
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+ <string name="permlab_bindTextService">bind to a text service</string>
+ <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
+ <string name="permdesc_bindTextService">Allows the holder to bind to the top-level
+ interface of a text service(e.g. SpellCheckerService). Should never be needed for normal applications.</string>
+
+ <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permlab_bindWallpaper">bind to a wallpaper</string>
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permdesc_bindWallpaper">Allows the holder to bind to the top-level
@@ -2577,6 +2583,14 @@
<!-- Do not translate. Default access point SSID used for tethering -->
<string name="wifi_tether_configure_ssid_default" translatable="false">AndroidAP</string>
+ <!-- Wi-Fi p2p dialog title-->
+ <string name="wifi_p2p_dialog_title">Wi-Fi Direct</string>
+ <string name="wifi_p2p_turnon_message">Start Wi-Fi Direct operation. This will turn off Wi-Fi client/hotspot operation.</string>
+ <string name="wifi_p2p_failed_message">Failed to start Wi-Fi Direct</string>
+ <string name="wifi_p2p_pbc_go_negotiation_request_message">Wi-Fi Direct connection setup request from <xliff:g id="p2p_device_address">%1$s</xliff:g>. Click OK to accept. </string>
+ <string name="wifi_p2p_pin_go_negotiation_request_message">Wi-Fi Direct connection setup request from <xliff:g id="p2p_device_address">%1$s</xliff:g>. Enter pin to proceed. </string>
+ <string name="wifi_p2p_pin_display_message">WPS pin <xliff:g id="p2p_wps_pin">%1$s</xliff:g> needs to be entered on the peer device <xliff:g id="p2p_client_address">%2$s</xliff:g> for connection setup to proceed </string>
+
<!-- Name of the dialog that lets the user choose an accented character to insert -->
<string name="select_character">Insert character</string>
diff --git a/core/tests/coretests/src/android/view/accessibility/RecycleAccessibilityEventTest.java b/core/tests/coretests/src/android/view/accessibility/RecycleAccessibilityEventTest.java
index bbf1696..4814c61 100644
--- a/core/tests/coretests/src/android/view/accessibility/RecycleAccessibilityEventTest.java
+++ b/core/tests/coretests/src/android/view/accessibility/RecycleAccessibilityEventTest.java
@@ -65,13 +65,13 @@ public class RecycleAccessibilityEventTest extends TestCase {
assertEquals(0, first.getText().size());
assertFalse(first.isChecked());
assertNull(first.getContentDescription());
- assertEquals(0, first.getItemCount());
+ assertEquals(-1, first.getItemCount());
assertEquals(AccessibilityEvent.INVALID_POSITION, first.getCurrentItemIndex());
assertFalse(first.isEnabled());
assertFalse(first.isPassword());
- assertEquals(0, first.getFromIndex());
- assertEquals(0, first.getAddedCount());
- assertEquals(0, first.getRemovedCount());
+ assertEquals(-1, first.getFromIndex());
+ assertEquals(-1, first.getAddedCount());
+ assertEquals(-1, first.getRemovedCount());
// get another event from the pool (this must be the recycled first)
AccessibilityEvent second = AccessibilityEvent.obtain();
diff --git a/docs/html/guide/developing/tools/adb.jd b/docs/html/guide/developing/tools/adb.jd
index 78d12ef..d32cf66 100644
--- a/docs/html/guide/developing/tools/adb.jd
+++ b/docs/html/guide/developing/tools/adb.jd
@@ -280,7 +280,7 @@ instance, see <a href="{@docRoot}guide/developing/building/index.html">Building
<td>Run PPP over USB.
<ul>
<li><code>&lt;tty&gt;</code> &mdash; the tty for PPP stream. For example <code>dev:/dev/omap_csmi_ttyl</code>. </li>
-<li><code>[parm]... </code> &mdash zero or more PPP/PPPD options, such as <code>defaultroute</code>, <code>local</code>, <code>notty</code>, etc.</li></ul>
+<li><code>[parm]... </code> &mdash; zero or more PPP/PPPD options, such as <code>defaultroute</code>, <code>local</code>, <code>notty</code>, etc.</li></ul>
<p>Note that you should not automatically start a PPP connection. </p></td>
<td></td>
diff --git a/docs/html/guide/topics/intents/intents-filters.jd b/docs/html/guide/topics/intents/intents-filters.jd
index 5905214..3f94553 100644
--- a/docs/html/guide/topics/intents/intents-filters.jd
+++ b/docs/html/guide/topics/intents/intents-filters.jd
@@ -927,7 +927,7 @@ as described by its two intent filters:
<p>
The first, primary, purpose of this activity is to enable the user to
-interact with a single note &mdash to either {@code VIEW} the note or
+interact with a single note &mdash; to either {@code VIEW} the note or
{@code EDIT} it. (The {@code EDIT_NOTE} category is a synonym for
{@code EDIT}.) The intent would contain the URI for data matching the
MIME type <code>vnd.android.cursor.item/vnd.google.note</code> &mdash;
diff --git a/docs/html/guide/topics/manifest/activity-element.jd b/docs/html/guide/topics/manifest/activity-element.jd
index 3486212..743832c 100644
--- a/docs/html/guide/topics/manifest/activity-element.jd
+++ b/docs/html/guide/topics/manifest/activity-element.jd
@@ -710,7 +710,7 @@ the soft keyboard.</li>
The setting must be one of the values listed in the following table, or a
combination of one "{@code state...}" value plus one "{@code adjust...}"
value. Setting multiple values in either group &mdash; multiple
-"{@code state...}" values, for example &mdash has undefined results.
+"{@code state...}" values, for example &mdash; has undefined results.
Individual values are separated by a vertical bar ({@code |}). For example:
</p>
@@ -801,4 +801,4 @@ Level 3.</dd>
<dt>see also:</dt>
<dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html">&lt;application&gt;</a></code>
<br/><code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html">&lt;activity-alias&gt;</a></code></dd>
-</dl> \ No newline at end of file
+</dl>
diff --git a/docs/html/guide/topics/providers/content-providers.jd b/docs/html/guide/topics/providers/content-providers.jd
index 2a84c26..513886a 100644
--- a/docs/html/guide/topics/providers/content-providers.jd
+++ b/docs/html/guide/topics/providers/content-providers.jd
@@ -277,7 +277,7 @@ are returned. All the content providers that come with the platform define
constants for their columns. For example, the
{@link android.provider.Contacts.Phones android.provider.Contacts.Phones} class
defines constants for the names of the columns in the phone table illustrated
-earlier &mdash {@code _ID}, {@code NUMBER}, {@code NUMBER_KEY}, {@code NAME},
+earlier &mdash; {@code _ID}, {@code NUMBER}, {@code NUMBER_KEY}, {@code NAME},
and so on.</li>
<li><p>A filter detailing which rows to return, formatted as an SQL {@code WHERE}
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 4a85faf..3476bd5 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -504,6 +504,7 @@ nAllocationCopyToBitmap(JNIEnv *_env, jobject _this, RsContext con, jint alloc,
void* ptr = bitmap.getPixels();
rsAllocationCopyToBitmap(con, (RsAllocation)alloc, ptr, bitmap.getSize());
bitmap.unlockPixels();
+ bitmap.notifyPixelsChanged();
}
static void ReleaseBitmapCallback(void *bmp)
diff --git a/include/gui/ISurfaceTexture.h b/include/gui/ISurfaceTexture.h
index bc630ae..1eda646 100644
--- a/include/gui/ISurfaceTexture.h
+++ b/include/gui/ISurfaceTexture.h
@@ -51,7 +51,7 @@ protected:
// the given slot index, and the client is expected to mirror the
// slot->buffer mapping so that it's not necessary to transfer a
// GraphicBuffer for every dequeue operation.
- virtual sp<GraphicBuffer> requestBuffer(int slot) = 0;
+ virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) = 0;
// setBufferCount sets the number of buffer slots available. Calling this
// will also cause all buffer slots to be emptied. The caller should empty
@@ -94,12 +94,6 @@ protected:
virtual status_t setTransform(uint32_t transform) = 0;
virtual status_t setScalingMode(int mode) = 0;
- // getAllocator retrieves the binder object that must be referenced as long
- // as the GraphicBuffers dequeued from this ISurfaceTexture are referenced.
- // Holding this binder reference prevents SurfaceFlinger from freeing the
- // buffers before the client is done with them.
- virtual sp<IBinder> getAllocator() = 0;
-
// query retrieves some information for this surface
// 'what' tokens allowed are that of android_natives.h
virtual int query(int what, int* value) = 0;
diff --git a/include/gui/SurfaceTexture.h b/include/gui/SurfaceTexture.h
index 945f4bc..2a8e725 100644
--- a/include/gui/SurfaceTexture.h
+++ b/include/gui/SurfaceTexture.h
@@ -69,7 +69,7 @@ public:
// SurfaceTexture object (i.e. they are not owned by the client).
virtual status_t setBufferCount(int bufferCount);
- virtual sp<GraphicBuffer> requestBuffer(int buf);
+ virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
// dequeueBuffer gets the next buffer slot index for the client to use. If a
// buffer slot is available then that slot index is written to the location
@@ -190,6 +190,17 @@ public:
// getCurrentScalingMode returns the scaling mode of the current buffer
uint32_t getCurrentScalingMode() const;
+ // abandon frees all the buffers and puts the SurfaceTexture into the
+ // 'abandoned' state. Once put in this state the SurfaceTexture can never
+ // leave it. When in the 'abandoned' state, all methods of the
+ // ISurfaceTexture interface will fail with the NO_INIT error.
+ //
+ // Note that while calling this method causes all the buffers to be freed
+ // from the perspective of the the SurfaceTexture, if there are additional
+ // references on the buffers (e.g. if a buffer is referenced by a client or
+ // by OpenGL ES as a texture) then those buffer will remain allocated.
+ void abandon();
+
// dump our state in a String
void dump(String8& result) const;
void dump(String8& result, const char* prefix, char* buffer, size_t SIZE) const;
@@ -200,7 +211,6 @@ protected:
// all slots.
void freeAllBuffers();
static bool isExternalFormat(uint32_t format);
- static GLenum getTextureTarget(uint32_t format);
private:
@@ -337,14 +347,9 @@ private:
// reset mCurrentTexture to INVALID_BUFFER_SLOT.
int mCurrentTexture;
- // mCurrentTextureTarget is the GLES texture target to be used with the
- // current texture.
- GLenum mCurrentTextureTarget;
-
// mCurrentTextureBuf is the graphic buffer of the current texture. It's
// possible that this buffer is not associated with any buffer slot, so we
- // must track it separately in order to properly use
- // IGraphicBufferAlloc::freeAllGraphicBuffersExcept.
+ // must track it separately in order to support the getCurrentBuffer method.
sp<GraphicBuffer> mCurrentTextureBuf;
// mCurrentCrop is the crop rectangle that applies to the current texture.
@@ -412,6 +417,13 @@ private:
typedef Vector<int> Fifo;
Fifo mQueue;
+ // mAbandoned indicates that the SurfaceTexture will no longer be used to
+ // consume images buffers pushed to it using the ISurfaceTexture interface.
+ // It is initialized to false, and set to true in the abandon method. A
+ // SurfaceTexture that has been abandoned will return the NO_INIT error from
+ // all ISurfaceTexture methods capable of returning an error.
+ bool mAbandoned;
+
// mMutex is the mutex used to prevent concurrent access to the member
// variables of SurfaceTexture objects. It must be locked whenever the
// member variables are accessed.
diff --git a/include/gui/SurfaceTextureClient.h b/include/gui/SurfaceTextureClient.h
index 829d8ab..56f029f 100644
--- a/include/gui/SurfaceTextureClient.h
+++ b/include/gui/SurfaceTextureClient.h
@@ -106,10 +106,6 @@ private:
// interactions with the server using this interface.
sp<ISurfaceTexture> mSurfaceTexture;
- // mAllocator is the binder object that is referenced to prevent the
- // dequeued buffers from being freed prematurely.
- sp<IBinder> mAllocator;
-
// mSlots stores the buffers that have been allocated for each buffer slot.
// It is initialized to null pointers, and gets filled in with the result of
// ISurfaceTexture::requestBuffer when the client dequeues a buffer from a
diff --git a/include/media/IMediaRecorder.h b/include/media/IMediaRecorder.h
index a73267d..007aea6 100644
--- a/include/media/IMediaRecorder.h
+++ b/include/media/IMediaRecorder.h
@@ -26,6 +26,7 @@ class Surface;
class ICamera;
class ICameraRecordingProxy;
class IMediaRecorderClient;
+class ISurfaceTexture;
class IMediaRecorder: public IInterface
{
@@ -55,6 +56,7 @@ public:
virtual status_t init() = 0;
virtual status_t close() = 0;
virtual status_t release() = 0;
+ virtual sp<ISurfaceTexture> querySurfaceMediaSource() = 0;
};
// ----------------------------------------------------------------------------
diff --git a/include/media/MediaRecorderBase.h b/include/media/MediaRecorderBase.h
index 1c08969..ef799f5 100644
--- a/include/media/MediaRecorderBase.h
+++ b/include/media/MediaRecorderBase.h
@@ -26,6 +26,7 @@ namespace android {
class ICameraRecordingProxy;
class Surface;
+class ISurfaceTexture;
struct MediaRecorderBase {
MediaRecorderBase() {}
@@ -54,6 +55,7 @@ struct MediaRecorderBase {
virtual status_t reset() = 0;
virtual status_t getMaxAmplitude(int *max) = 0;
virtual status_t dump(int fd, const Vector<String16>& args) const = 0;
+ virtual sp<ISurfaceTexture> querySurfaceMediaSource() const = 0;
private:
MediaRecorderBase(const MediaRecorderBase &);
diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h
index af12d3c..72d3736 100644
--- a/include/media/mediarecorder.h
+++ b/include/media/mediarecorder.h
@@ -31,12 +31,15 @@ class Surface;
class IMediaRecorder;
class ICamera;
class ICameraRecordingProxy;
+class ISurfaceTexture;
+class SurfaceTextureClient;
typedef void (*media_completion_f)(status_t status, void *cookie);
enum video_source {
VIDEO_SOURCE_DEFAULT = 0,
VIDEO_SOURCE_CAMERA = 1,
+ VIDEO_SOURCE_GRALLOC_BUFFER = 2,
VIDEO_SOURCE_LIST_END // must be last - used to validate audio source type
};
@@ -226,6 +229,7 @@ public:
status_t close();
status_t release();
void notify(int msg, int ext1, int ext2);
+ sp<ISurfaceTexture> querySurfaceMediaSourceFromMediaServer();
private:
void doCleanUp();
@@ -233,6 +237,12 @@ private:
sp<IMediaRecorder> mMediaRecorder;
sp<MediaRecorderListener> mListener;
+
+ // Reference toISurfaceTexture
+ // for encoding GL Frames. That is useful only when the
+ // video source is set to VIDEO_SOURCE_GRALLOC_BUFFER
+ sp<ISurfaceTexture> mSurfaceMediaSource;
+
media_recorder_states mCurrentState;
bool mIsAudioSourceSet;
bool mIsVideoSourceSet;
diff --git a/include/media/stagefright/DataSource.h b/include/media/stagefright/DataSource.h
index 48d1464..713af92 100644
--- a/include/media/stagefright/DataSource.h
+++ b/include/media/stagefright/DataSource.h
@@ -20,6 +20,7 @@
#include <sys/types.h>
+#include <media/stagefright/MediaErrors.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/List.h>
@@ -61,6 +62,10 @@ public:
return 0;
}
+ virtual status_t reconnectAtOffset(off64_t offset) {
+ return ERROR_UNSUPPORTED;
+ }
+
////////////////////////////////////////////////////////////////////////////
bool sniff(String8 *mimeType, float *confidence, sp<AMessage> *meta);
diff --git a/include/media/stagefright/HardwareAPI.h b/include/media/stagefright/HardwareAPI.h
index 946a0aa..32eed3f 100644
--- a/include/media/stagefright/HardwareAPI.h
+++ b/include/media/stagefright/HardwareAPI.h
@@ -99,6 +99,13 @@ struct GetAndroidNativeBufferUsageParams {
OMX_U32 nUsage; // OUT
};
+// An enum OMX_COLOR_FormatAndroidOpaque to indicate an opaque colorformat
+// is declared in media/stagefright/openmax/OMX_IVCommon.h
+// This will inform the encoder that the actual
+// colorformat will be relayed by the GRalloc Buffers.
+// OMX_COLOR_FormatAndroidOpaque = 0x7F000001,
+
+
} // namespace android
extern android::OMXPluginBase *createOMXPlugin();
diff --git a/include/media/stagefright/MediaSource.h b/include/media/stagefright/MediaSource.h
index 37dbcd8..3818e63 100644
--- a/include/media/stagefright/MediaSource.h
+++ b/include/media/stagefright/MediaSource.h
@@ -29,7 +29,7 @@ namespace android {
class MediaBuffer;
class MetaData;
-struct MediaSource : public RefBase {
+struct MediaSource : public virtual RefBase {
MediaSource();
// To be called before any other methods on this object, except
diff --git a/include/media/stagefright/OMXCodec.h b/include/media/stagefright/OMXCodec.h
index 20fcde5..2932744 100644
--- a/include/media/stagefright/OMXCodec.h
+++ b/include/media/stagefright/OMXCodec.h
@@ -329,6 +329,7 @@ private:
void restorePatchedDataPointer(BufferInfo *info);
status_t applyRotation();
+ status_t waitForBufferFilled_l();
int64_t retrieveDecodingTimeUs(bool isCodecSpecific);
@@ -348,6 +349,8 @@ struct CodecCapabilities {
// that encode content of the given type.
// profile and level indications only make sense for h.263, mpeg4 and avc
// video.
+// If hwCodecOnly==true, only returns hardware-based components, software and
+// hardware otherwise.
// The profile/level values correspond to
// OMX_VIDEO_H263PROFILETYPE, OMX_VIDEO_MPEG4PROFILETYPE,
// OMX_VIDEO_AVCPROFILETYPE, OMX_VIDEO_H263LEVELTYPE, OMX_VIDEO_MPEG4LEVELTYPE
@@ -358,6 +361,11 @@ status_t QueryCodecs(
const char *mimeType, bool queryDecoders, bool hwCodecOnly,
Vector<CodecCapabilities> *results);
+status_t QueryCodecs(
+ const sp<IOMX> &omx,
+ const char *mimeType, bool queryDecoders,
+ Vector<CodecCapabilities> *results);
+
} // namespace android
#endif // OMX_CODEC_H_
diff --git a/include/media/stagefright/SurfaceMediaSource.h b/include/media/stagefright/SurfaceMediaSource.h
new file mode 100644
index 0000000..56bd9c3
--- /dev/null
+++ b/include/media/stagefright/SurfaceMediaSource.h
@@ -0,0 +1,350 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_GUI_SURFACEMEDIASOURCE_H
+#define ANDROID_GUI_SURFACEMEDIASOURCE_H
+
+#include <gui/ISurfaceTexture.h>
+
+#include <utils/threads.h>
+#include <utils/Vector.h>
+#include <media/stagefright/MediaSource.h>
+#include <media/stagefright/MediaBuffer.h>
+
+namespace android {
+// ----------------------------------------------------------------------------
+
+class IGraphicBufferAlloc;
+class String8;
+class GraphicBuffer;
+
+class SurfaceMediaSource : public BnSurfaceTexture, public MediaSource,
+ public MediaBufferObserver {
+public:
+ enum { MIN_UNDEQUEUED_BUFFERS = 3 };
+ enum {
+ MIN_ASYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS + 1,
+ MIN_SYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS
+ };
+ enum { NUM_BUFFER_SLOTS = 32 };
+ enum { NO_CONNECTED_API = 0 };
+
+ struct FrameAvailableListener : public virtual RefBase {
+ // onFrameAvailable() is called from queueBuffer() is the FIFO is
+ // empty. You can use SurfaceMediaSource::getQueuedCount() to
+ // figure out if there are more frames waiting.
+ // This is called without any lock held can be called concurrently by
+ // multiple threads.
+ virtual void onFrameAvailable() = 0;
+ };
+
+ SurfaceMediaSource(uint32_t bufW, uint32_t bufH);
+
+ virtual ~SurfaceMediaSource();
+
+
+ // For the MediaSource interface for use by StageFrightRecorder:
+ virtual status_t start(MetaData *params = NULL);
+ virtual status_t stop();
+ virtual status_t read(
+ MediaBuffer **buffer, const ReadOptions *options = NULL);
+ virtual sp<MetaData> getFormat();
+
+ // Get / Set the frame rate used for encoding. Default fps = 30
+ status_t setFrameRate(int32_t fps) ;
+ int32_t getFrameRate( ) const;
+
+ // The call for the StageFrightRecorder to tell us that
+ // it is done using the MediaBuffer data so that its state
+ // can be set to FREE for dequeuing
+ virtual void signalBufferReturned(MediaBuffer* buffer);
+ // end of MediaSource interface
+
+ uint32_t getBufferCount( ) const { return mBufferCount;}
+
+
+ // setBufferCount updates the number of available buffer slots. After
+ // calling this all buffer slots are both unallocated and owned by the
+ // SurfaceMediaSource object (i.e. they are not owned by the client).
+ virtual status_t setBufferCount(int bufferCount);
+
+ virtual status_t requestBuffer(int slot, sp<GraphicBuffer>* buf);
+
+ // dequeueBuffer gets the next buffer slot index for the client to use. If a
+ // buffer slot is available then that slot index is written to the location
+ // pointed to by the buf argument and a status of OK is returned. If no
+ // slot is available then a status of -EBUSY is returned and buf is
+ // unmodified.
+ virtual status_t dequeueBuffer(int *buf, uint32_t w, uint32_t h,
+ uint32_t format, uint32_t usage);
+
+ // queueBuffer returns a filled buffer to the SurfaceMediaSource. In addition, a
+ // timestamp must be provided for the buffer. The timestamp is in
+ // nanoseconds, and must be monotonically increasing. Its other semantics
+ // (zero point, etc) are client-dependent and should be documented by the
+ // client.
+ virtual status_t queueBuffer(int buf, int64_t timestamp,
+ uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform);
+ virtual void cancelBuffer(int buf);
+
+ // onFrameReceivedLocked informs the buffer consumers (StageFrightRecorder)
+ // or listeners that a frame has been received
+ // The buffer is not made available for dequeueing immediately. We need to
+ // wait to hear from StageFrightRecorder to set the buffer FREE
+ // Make sure this is called when the mutex is locked
+ virtual status_t onFrameReceivedLocked();
+
+ virtual status_t setScalingMode(int mode) { } // no op for encoding
+ virtual int query(int what, int* value);
+
+ // Just confirming to the ISurfaceTexture interface as of now
+ virtual status_t setCrop(const Rect& reg) { return OK; }
+ virtual status_t setTransform(uint32_t transform) {return OK;}
+
+ // setSynchronousMode set whether dequeueBuffer is synchronous or
+ // asynchronous. In synchronous mode, dequeueBuffer blocks until
+ // a buffer is available, the currently bound buffer can be dequeued and
+ // queued buffers will be retired in order.
+ // The default mode is synchronous.
+ // TODO: Clarify the minute differences bet sycn /async
+ // modes (S.Encoder vis-a-vis SurfaceTexture)
+ virtual status_t setSynchronousMode(bool enabled);
+
+ // connect attempts to connect a client API to the SurfaceMediaSource. This
+ // must be called before any other ISurfaceTexture methods are called except
+ // for getAllocator.
+ //
+ // This method will fail if the connect was previously called on the
+ // SurfaceMediaSource and no corresponding disconnect call was made.
+ virtual status_t connect(int api);
+
+ // disconnect attempts to disconnect a client API from the SurfaceMediaSource.
+ // Calling this method will cause any subsequent calls to other
+ // ISurfaceTexture methods to fail except for getAllocator and connect.
+ // Successfully calling connect after this will allow the other methods to
+ // succeed again.
+ //
+ // This method will fail if the the SurfaceMediaSource is not currently
+ // connected to the specified client API.
+ virtual status_t disconnect(int api);
+
+ // getqueuedCount returns the number of queued frames waiting in the
+ // FIFO. In asynchronous mode, this always returns 0 or 1 since
+ // frames are not accumulating in the FIFO.
+ size_t getQueuedCount() const;
+
+ // setBufferCountServer set the buffer count. If the client has requested
+ // a buffer count using setBufferCount, the server-buffer count will
+ // take effect once the client sets the count back to zero.
+ status_t setBufferCountServer(int bufferCount);
+
+ // getTimestamp retrieves the timestamp associated with the image
+ // set by the most recent call to updateFrameInfoLocked().
+ //
+ // The timestamp is in nanoseconds, and is monotonically increasing. Its
+ // other semantics (zero point, etc) are source-dependent and should be
+ // documented by the source.
+ int64_t getTimestamp();
+
+ // setFrameAvailableListener sets the listener object that will be notified
+ // when a new frame becomes available.
+ void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
+
+ // getCurrentBuffer returns the buffer associated with the current image.
+ sp<GraphicBuffer> getCurrentBuffer() const;
+
+ // dump our state in a String
+ void dump(String8& result) const;
+ void dump(String8& result, const char* prefix, char* buffer,
+ size_t SIZE) const;
+
+ // isMetaDataStoredInVideoBuffers tells the encoder whether we will
+ // pass metadata through the buffers. Currently, it is force set to true
+ bool isMetaDataStoredInVideoBuffers() const;
+
+protected:
+
+ // freeAllBuffers frees the resources (both GraphicBuffer and EGLImage) for
+ // all slots.
+ void freeAllBuffers();
+ static bool isExternalFormat(uint32_t format);
+
+private:
+
+ status_t setBufferCountServerLocked(int bufferCount);
+
+ enum { INVALID_BUFFER_SLOT = -1 };
+
+ struct BufferSlot {
+
+ BufferSlot()
+ : mBufferState(BufferSlot::FREE),
+ mRequestBufferCalled(false),
+ mTimestamp(0) {
+ }
+
+ // mGraphicBuffer points to the buffer allocated for this slot or is
+ // NULL if no buffer has been allocated.
+ sp<GraphicBuffer> mGraphicBuffer;
+
+ // BufferState represents the different states in which a buffer slot
+ // can be.
+ enum BufferState {
+ // FREE indicates that the buffer is not currently being used and
+ // will not be used in the future until it gets dequeued and
+ // subseqently queued by the client.
+ FREE = 0,
+
+ // DEQUEUED indicates that the buffer has been dequeued by the
+ // client, but has not yet been queued or canceled. The buffer is
+ // considered 'owned' by the client, and the server should not use
+ // it for anything.
+ //
+ // Note that when in synchronous-mode (mSynchronousMode == true),
+ // the buffer that's currently attached to the texture may be
+ // dequeued by the client. That means that the current buffer can
+ // be in either the DEQUEUED or QUEUED state. In asynchronous mode,
+ // however, the current buffer is always in the QUEUED state.
+ DEQUEUED = 1,
+
+ // QUEUED indicates that the buffer has been queued by the client,
+ // and has not since been made available for the client to dequeue.
+ // Attaching the buffer to the texture does NOT transition the
+ // buffer away from the QUEUED state. However, in Synchronous mode
+ // the current buffer may be dequeued by the client under some
+ // circumstances. See the note about the current buffer in the
+ // documentation for DEQUEUED.
+ QUEUED = 2,
+ };
+
+ // mBufferState is the current state of this buffer slot.
+ BufferState mBufferState;
+
+ // mRequestBufferCalled is used for validating that the client did
+ // call requestBuffer() when told to do so. Technically this is not
+ // needed but useful for debugging and catching client bugs.
+ bool mRequestBufferCalled;
+
+ // mTimestamp is the current timestamp for this buffer slot. This gets
+ // to set by queueBuffer each time this slot is queued.
+ int64_t mTimestamp;
+ };
+
+ // mSlots is the array of buffer slots that must be mirrored on the client
+ // side. This allows buffer ownership to be transferred between the client
+ // and server without sending a GraphicBuffer over binder. The entire array
+ // is initialized to NULL at construction time, and buffers are allocated
+ // for a slot when requestBuffer is called with that slot's index.
+ BufferSlot mSlots[NUM_BUFFER_SLOTS];
+
+ // mDefaultWidth holds the default width of allocated buffers. It is used
+ // in requestBuffers() if a width and height of zero is specified.
+ uint32_t mDefaultWidth;
+
+ // mDefaultHeight holds the default height of allocated buffers. It is used
+ // in requestBuffers() if a width and height of zero is specified.
+ uint32_t mDefaultHeight;
+
+ // mPixelFormat holds the pixel format of allocated buffers. It is used
+ // in requestBuffers() if a format of zero is specified.
+ uint32_t mPixelFormat;
+
+ // mBufferCount is the number of buffer slots that the client and server
+ // must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
+ // by calling setBufferCount or setBufferCountServer
+ int mBufferCount;
+
+ // mClientBufferCount is the number of buffer slots requested by the
+ // client. The default is zero, which means the client doesn't care how
+ // many buffers there are
+ int mClientBufferCount;
+
+ // mServerBufferCount buffer count requested by the server-side
+ int mServerBufferCount;
+
+ // mCurrentSlot is the buffer slot index of the buffer that is currently
+ // being used by buffer consumer
+ // (e.g. StageFrightRecorder in the case of SurfaceMediaSource or GLTexture
+ // in the case of SurfaceTexture).
+ // It is initialized to INVALID_BUFFER_SLOT,
+ // indicating that no buffer slot is currently bound to the texture. Note,
+ // however, that a value of INVALID_BUFFER_SLOT does not necessarily mean
+ // that no buffer is bound to the texture. A call to setBufferCount will
+ // reset mCurrentTexture to INVALID_BUFFER_SLOT.
+ int mCurrentSlot;
+
+
+ // mCurrentBuf is the graphic buffer of the current slot to be used by
+ // buffer consumer. It's possible that this buffer is not associated
+ // with any buffer slot, so we must track it separately in order to
+ // properly use IGraphicBufferAlloc::freeAllGraphicBuffersExcept.
+ sp<GraphicBuffer> mCurrentBuf;
+
+
+ // mCurrentTimestamp is the timestamp for the current texture. It
+ // gets set to mLastQueuedTimestamp each time updateTexImage is called.
+ int64_t mCurrentTimestamp;
+
+ // mGraphicBufferAlloc is the connection to SurfaceFlinger that is used to
+ // allocate new GraphicBuffer objects.
+ sp<IGraphicBufferAlloc> mGraphicBufferAlloc;
+
+ // mFrameAvailableListener is the listener object that will be called when a
+ // new frame becomes available. If it is not NULL it will be called from
+ // queueBuffer.
+ sp<FrameAvailableListener> mFrameAvailableListener;
+
+ // mSynchronousMode whether we're in synchronous mode or not
+ bool mSynchronousMode;
+
+ // mConnectedApi indicates the API that is currently connected to this
+ // SurfaceTexture. It defaults to NO_CONNECTED_API (= 0), and gets updated
+ // by the connect and disconnect methods.
+ int mConnectedApi;
+
+ // mDequeueCondition condition used for dequeueBuffer in synchronous mode
+ mutable Condition mDequeueCondition;
+
+
+ // mQueue is a FIFO of queued buffers used in synchronous mode
+ typedef Vector<int> Fifo;
+ Fifo mQueue;
+
+ // mMutex is the mutex used to prevent concurrent access to the member
+ // variables of SurfaceMediaSource objects. It must be locked whenever the
+ // member variables are accessed.
+ mutable Mutex mMutex;
+
+ ////////////////////////// For MediaSource
+ // Set to a default of 30 fps if not specified by the client side
+ int32_t mFrameRate;
+
+ // mStarted is a flag to check if the recording has started
+ bool mStarted;
+
+ // mFrameAvailableCondition condition used to indicate whether there
+ // is a frame available for dequeuing
+ Condition mFrameAvailableCondition;
+ Condition mFrameCompleteCondition;
+
+ // Avoid copying and equating and default constructor
+ DISALLOW_IMPLICIT_CONSTRUCTORS(SurfaceMediaSource);
+};
+
+// ----------------------------------------------------------------------------
+}; // namespace android
+
+#endif // ANDROID_GUI_SURFACEMEDIASOURCE_H
diff --git a/include/surfaceflinger/Surface.h b/include/surfaceflinger/Surface.h
index 9c352ad..0460bbd 100644
--- a/include/surfaceflinger/Surface.h
+++ b/include/surfaceflinger/Surface.h
@@ -122,7 +122,10 @@ public:
uint32_t reserved[2];
};
+ explicit Surface(const sp<ISurfaceTexture>& st);
+
static status_t writeToParcel(const sp<Surface>& control, Parcel* parcel);
+
static sp<Surface> readFromParcel(const Parcel& data);
static bool isValid(const sp<Surface>& surface) {
return (surface != 0) && surface->isValid();
@@ -147,14 +150,14 @@ private:
Surface& operator = (Surface& rhs);
Surface(const Surface& rhs);
- Surface(const sp<SurfaceControl>& control);
+ explicit Surface(const sp<SurfaceControl>& control);
Surface(const Parcel& data, const sp<IBinder>& ref);
~Surface();
/*
* private stuff...
*/
- void init();
+ void init(const sp<ISurfaceTexture>& surfaceTexture);
static void cleanCachedSurfacesLocked();
diff --git a/include/ui/PixelFormat.h b/include/ui/PixelFormat.h
index f46f25c..848c5a1 100644
--- a/include/ui/PixelFormat.h
+++ b/include/ui/PixelFormat.h
@@ -55,7 +55,7 @@ enum {
PIXEL_FORMAT_OPAQUE = -1,
// System chooses an opaque format (no alpha bits required)
-
+
// real pixel formats supported for rendering -----------------------------
PIXEL_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, // 4x8-bit RGBA
@@ -84,7 +84,7 @@ struct PixelFormatInfo
INDEX_GREEN = 2,
INDEX_BLUE = 3
};
-
+
enum { // components
ALPHA = 1,
RGB = 2,
@@ -98,10 +98,10 @@ struct PixelFormatInfo
uint8_t h;
uint8_t l;
};
-
+
inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { }
size_t getScanlineSize(unsigned int width) const;
- size_t getSize(size_t ci) const {
+ size_t getSize(size_t ci) const {
return (ci <= 3) ? (cinfo[ci].h - cinfo[ci].l) : 0;
}
size_t version;
@@ -112,7 +112,7 @@ struct PixelFormatInfo
szinfo cinfo[4];
struct {
uint8_t h_alpha;
- uint8_t l_alpha;
+ uint8_t l_alpha;
uint8_t h_red;
uint8_t l_red;
uint8_t h_green;
diff --git a/libs/gui/ISurfaceTexture.cpp b/libs/gui/ISurfaceTexture.cpp
index be90e2e..55246dc 100644
--- a/libs/gui/ISurfaceTexture.cpp
+++ b/libs/gui/ISurfaceTexture.cpp
@@ -38,7 +38,6 @@ enum {
CANCEL_BUFFER,
SET_CROP,
SET_TRANSFORM,
- GET_ALLOCATOR,
QUERY,
SET_SYNCHRONOUS_MODE,
CONNECT,
@@ -55,18 +54,18 @@ public:
{
}
- virtual sp<GraphicBuffer> requestBuffer(int bufferIdx) {
+ virtual status_t requestBuffer(int bufferIdx, sp<GraphicBuffer>* buf) {
Parcel data, reply;
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
data.writeInt32(bufferIdx);
remote()->transact(REQUEST_BUFFER, data, &reply);
- sp<GraphicBuffer> buffer;
bool nonNull = reply.readInt32();
if (nonNull) {
- buffer = new GraphicBuffer();
- reply.read(*buffer);
+ *buf = new GraphicBuffer();
+ reply.read(**buf);
}
- return buffer;
+ status_t result = reply.readInt32();
+ return result;
}
virtual status_t setBufferCount(int bufferCount)
@@ -144,13 +143,6 @@ public:
return result;
}
- virtual sp<IBinder> getAllocator() {
- Parcel data, reply;
- data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
- remote()->transact(GET_ALLOCATOR, data, &reply);
- return reply.readStrongBinder();
- }
-
virtual int query(int what, int* value) {
Parcel data, reply;
data.writeInterfaceToken(ISurfaceTexture::getInterfaceDescriptor());
@@ -200,11 +192,13 @@ status_t BnSurfaceTexture::onTransact(
case REQUEST_BUFFER: {
CHECK_INTERFACE(ISurfaceTexture, data, reply);
int bufferIdx = data.readInt32();
- sp<GraphicBuffer> buffer(requestBuffer(bufferIdx));
+ sp<GraphicBuffer> buffer;
+ int result = requestBuffer(bufferIdx, &buffer);
reply->writeInt32(buffer != 0);
if (buffer != 0) {
reply->write(*buffer);
}
+ reply->writeInt32(result);
return NO_ERROR;
} break;
case SET_BUFFER_COUNT: {
@@ -270,12 +264,6 @@ status_t BnSurfaceTexture::onTransact(
reply->writeInt32(result);
return NO_ERROR;
} break;
- case GET_ALLOCATOR: {
- CHECK_INTERFACE(ISurfaceTexture, data, reply);
- sp<IBinder> result = getAllocator();
- reply->writeStrongBinder(result);
- return NO_ERROR;
- } break;
case QUERY: {
CHECK_INTERFACE(ISurfaceTexture, data, reply);
int value;
diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp
index c4f9e53..ccf98e5 100644
--- a/libs/gui/Surface.cpp
+++ b/libs/gui/Surface.cpp
@@ -184,6 +184,7 @@ status_t SurfaceControl::writeSurfaceToParcel(
identity = control->mIdentity;
}
parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
+ parcel->writeStrongBinder(NULL); // NULL ISurfaceTexture in this case.
parcel->writeInt32(identity);
return NO_ERROR;
}
@@ -192,7 +193,8 @@ sp<Surface> SurfaceControl::getSurface() const
{
Mutex::Autolock _l(mLock);
if (mSurfaceData == 0) {
- mSurfaceData = new Surface(const_cast<SurfaceControl*>(this));
+ sp<SurfaceControl> surface_control(const_cast<SurfaceControl*>(this));
+ mSurfaceData = new Surface(surface_control);
}
return mSurfaceData;
}
@@ -208,31 +210,58 @@ Surface::Surface(const sp<SurfaceControl>& surface)
mSurface(surface->mSurface),
mIdentity(surface->mIdentity)
{
- init();
+ sp<ISurfaceTexture> st;
+ if (mSurface != NULL) {
+ st = mSurface->getSurfaceTexture();
+ }
+ init(st);
}
Surface::Surface(const Parcel& parcel, const sp<IBinder>& ref)
: SurfaceTextureClient()
{
- mSurface = interface_cast<ISurface>(ref);
+ mSurface = interface_cast<ISurface>(ref);
+ sp<IBinder> st_binder(parcel.readStrongBinder());
+ sp<ISurfaceTexture> st;
+ if (st_binder != NULL) {
+ st = interface_cast<ISurfaceTexture>(st_binder);
+ } else if (mSurface != NULL) {
+ st = mSurface->getSurfaceTexture();
+ }
+
mIdentity = parcel.readInt32();
- init();
+ init(st);
+}
+
+Surface::Surface(const sp<ISurfaceTexture>& st)
+ : SurfaceTextureClient(),
+ mSurface(NULL),
+ mIdentity(0)
+{
+ init(st);
}
status_t Surface::writeToParcel(
const sp<Surface>& surface, Parcel* parcel)
{
sp<ISurface> sur;
+ sp<ISurfaceTexture> st;
uint32_t identity = 0;
if (Surface::isValid(surface)) {
sur = surface->mSurface;
+ st = surface->getISurfaceTexture();
identity = surface->mIdentity;
- } else if (surface != 0 && surface->mSurface != 0) {
- LOGW("Parceling invalid surface with non-NULL ISurface as NULL: "
- "mSurface = %p, mIdentity = %d",
- surface->mSurface.get(), surface->mIdentity);
+ } else if (surface != 0 &&
+ (surface->mSurface != NULL ||
+ surface->getISurfaceTexture() != NULL)) {
+ LOGE("Parceling invalid surface with non-NULL ISurface/ISurfaceTexture as NULL: "
+ "mSurface = %p, surfaceTexture = %p, mIdentity = %d, ",
+ surface->mSurface.get(), surface->getISurfaceTexture().get(),
+ surface->mIdentity);
}
- parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
+
+ parcel->writeStrongBinder(sur != NULL ? sur->asBinder() : NULL);
+ parcel->writeStrongBinder(st != NULL ? st->asBinder() : NULL);
parcel->writeInt32(identity);
return NO_ERROR;
@@ -249,8 +278,8 @@ sp<Surface> Surface::readFromParcel(const Parcel& data) {
surface = new Surface(data, binder);
sCachedSurfaces.add(binder, surface);
}
- if (surface->mSurface == 0) {
- surface = 0;
+ if (surface->mSurface == NULL && surface->getISurfaceTexture() == NULL) {
+ surface = 0;
}
cleanCachedSurfacesLocked();
return surface;
@@ -267,10 +296,9 @@ void Surface::cleanCachedSurfacesLocked() {
}
}
-void Surface::init()
+void Surface::init(const sp<ISurfaceTexture>& surfaceTexture)
{
- if (mSurface != NULL) {
- sp<ISurfaceTexture> surfaceTexture(mSurface->getSurfaceTexture());
+ if (mSurface != NULL || surfaceTexture != NULL) {
LOGE_IF(surfaceTexture==0, "got a NULL ISurfaceTexture from ISurface");
if (surfaceTexture != NULL) {
setISurfaceTexture(surfaceTexture);
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp
index 0f08570..8d19957 100644
--- a/libs/gui/SurfaceTexture.cpp
+++ b/libs/gui/SurfaceTexture.cpp
@@ -86,7 +86,6 @@ SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode) :
mClientBufferCount(0),
mServerBufferCount(MIN_ASYNC_BUFFER_SLOTS),
mCurrentTexture(INVALID_BUFFER_SLOT),
- mCurrentTextureTarget(GL_TEXTURE_EXTERNAL_OES),
mCurrentTransform(0),
mCurrentTimestamp(0),
mNextTransform(0),
@@ -94,7 +93,8 @@ SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode) :
mTexName(tex),
mSynchronousMode(false),
mAllowSynchronousMode(allowSynchronousMode),
- mConnectedApi(NO_CONNECTED_API) {
+ mConnectedApi(NO_CONNECTED_API),
+ mAbandoned(false) {
LOGV("SurfaceTexture::SurfaceTexture");
sp<ISurfaceComposer> composer(ComposerService::getComposerService());
mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
@@ -150,6 +150,11 @@ status_t SurfaceTexture::setBufferCount(int bufferCount) {
LOGV("SurfaceTexture::setBufferCount");
Mutex::Autolock lock(mMutex);
+ if (mAbandoned) {
+ LOGE("setBufferCount: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+
if (bufferCount > NUM_BUFFER_SLOTS) {
LOGE("setBufferCount: bufferCount larger than slots available");
return BAD_VALUE;
@@ -199,22 +204,32 @@ status_t SurfaceTexture::setDefaultBufferSize(uint32_t w, uint32_t h)
return OK;
}
-sp<GraphicBuffer> SurfaceTexture::requestBuffer(int buf) {
+status_t SurfaceTexture::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
LOGV("SurfaceTexture::requestBuffer");
Mutex::Autolock lock(mMutex);
- if (buf < 0 || mBufferCount <= buf) {
+ if (mAbandoned) {
+ LOGE("requestBuffer: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+ if (slot < 0 || mBufferCount <= slot) {
LOGE("requestBuffer: slot index out of range [0, %d]: %d",
- mBufferCount, buf);
- return 0;
+ mBufferCount, slot);
+ return BAD_VALUE;
}
- mSlots[buf].mRequestBufferCalled = true;
- return mSlots[buf].mGraphicBuffer;
+ mSlots[slot].mRequestBufferCalled = true;
+ *buf = mSlots[slot].mGraphicBuffer;
+ return NO_ERROR;
}
status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
uint32_t format, uint32_t usage) {
LOGV("SurfaceTexture::dequeueBuffer");
+ if (mAbandoned) {
+ LOGE("dequeueBuffer: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+
if ((w && !h) || (!w && h)) {
LOGE("dequeueBuffer: invalid size: w=%u, h=%u", w, h);
return BAD_VALUE;
@@ -252,6 +267,11 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
// wait for the FIFO to drain
while (!mQueue.isEmpty()) {
mDequeueCondition.wait(mMutex);
+ if (mAbandoned) {
+ LOGE("dequeueBuffer: SurfaceTexture was abandoned while "
+ "blocked!");
+ return NO_INIT;
+ }
}
minBufferCountNeeded = mSynchronousMode ?
MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
@@ -380,6 +400,11 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
status_t SurfaceTexture::setSynchronousMode(bool enabled) {
Mutex::Autolock lock(mMutex);
+ if (mAbandoned) {
+ LOGE("setSynchronousMode: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+
status_t err = OK;
if (!mAllowSynchronousMode && enabled)
return err;
@@ -410,6 +435,10 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp,
{ // scope for the lock
Mutex::Autolock lock(mMutex);
+ if (mAbandoned) {
+ LOGE("queueBuffer: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
if (buf < 0 || buf >= mBufferCount) {
LOGE("queueBuffer: slot index out of range [0, %d]: %d",
mBufferCount, buf);
@@ -475,6 +504,12 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp,
void SurfaceTexture::cancelBuffer(int buf) {
LOGV("SurfaceTexture::cancelBuffer");
Mutex::Autolock lock(mMutex);
+
+ if (mAbandoned) {
+ LOGW("cancelBuffer: SurfaceTexture has been abandoned!");
+ return;
+ }
+
if (buf < 0 || buf >= mBufferCount) {
LOGE("cancelBuffer: slot index out of range [0, %d]: %d",
mBufferCount, buf);
@@ -491,6 +526,10 @@ void SurfaceTexture::cancelBuffer(int buf) {
status_t SurfaceTexture::setCrop(const Rect& crop) {
LOGV("SurfaceTexture::setCrop");
Mutex::Autolock lock(mMutex);
+ if (mAbandoned) {
+ LOGE("setCrop: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
mNextCrop = crop;
return OK;
}
@@ -498,6 +537,10 @@ status_t SurfaceTexture::setCrop(const Rect& crop) {
status_t SurfaceTexture::setTransform(uint32_t transform) {
LOGV("SurfaceTexture::setTransform");
Mutex::Autolock lock(mMutex);
+ if (mAbandoned) {
+ LOGE("setTransform: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
mNextTransform = transform;
return OK;
}
@@ -505,6 +548,12 @@ status_t SurfaceTexture::setTransform(uint32_t transform) {
status_t SurfaceTexture::connect(int api) {
LOGV("SurfaceTexture::connect(this=%p, %d)", this, api);
Mutex::Autolock lock(mMutex);
+
+ if (mAbandoned) {
+ LOGE("connect: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+
int err = NO_ERROR;
switch (api) {
case NATIVE_WINDOW_API_EGL:
@@ -529,6 +578,12 @@ status_t SurfaceTexture::connect(int api) {
status_t SurfaceTexture::disconnect(int api) {
LOGV("SurfaceTexture::disconnect(this=%p, %d)", this, api);
Mutex::Autolock lock(mMutex);
+
+ if (mAbandoned) {
+ LOGE("connect: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+
int err = NO_ERROR;
switch (api) {
case NATIVE_WINDOW_API_EGL:
@@ -595,12 +650,8 @@ status_t SurfaceTexture::updateTexImage() {
LOGW("updateTexImage: clearing GL error: %#04x", error);
}
- GLenum target = getTextureTarget(mSlots[buf].mGraphicBuffer->format);
- if (target != mCurrentTextureTarget) {
- glDeleteTextures(1, &mTexName);
- }
- glBindTexture(target, mTexName);
- glEGLImageTargetTexture2DOES(target, (GLeglImageOES)image);
+ glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexName);
+ glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)image);
bool failed = false;
while ((error = glGetError()) != GL_NO_ERROR) {
@@ -622,7 +673,6 @@ status_t SurfaceTexture::updateTexImage() {
// Update the SurfaceTexture state.
mCurrentTexture = buf;
- mCurrentTextureTarget = target;
mCurrentTextureBuf = mSlots[buf].mGraphicBuffer;
mCurrentCrop = mSlots[buf].mCrop;
mCurrentTransform = mSlots[buf].mTransform;
@@ -636,7 +686,7 @@ status_t SurfaceTexture::updateTexImage() {
mDequeueCondition.signal();
} else {
// We always bind the texture even if we don't update its contents.
- glBindTexture(mCurrentTextureTarget, mTexName);
+ glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexName);
}
return OK;
@@ -661,20 +711,8 @@ bool SurfaceTexture::isExternalFormat(uint32_t format)
return false;
}
-GLenum SurfaceTexture::getTextureTarget(uint32_t format)
-{
- GLenum target = GL_TEXTURE_2D;
-#if defined(GL_OES_EGL_image_external)
- if (isExternalFormat(format)) {
- target = GL_TEXTURE_EXTERNAL_OES;
- }
-#endif
- return target;
-}
-
GLenum SurfaceTexture::getCurrentTextureTarget() const {
- Mutex::Autolock lock(mMutex);
- return mCurrentTextureTarget;
+ return GL_TEXTURE_EXTERNAL_OES;
}
void SurfaceTexture::getTransformMatrix(float mtx[16]) {
@@ -786,11 +824,6 @@ void SurfaceTexture::setFrameAvailableListener(
mFrameAvailableListener = listener;
}
-sp<IBinder> SurfaceTexture::getAllocator() {
- LOGV("SurfaceTexture::getAllocator");
- return mGraphicBufferAlloc->asBinder();
-}
-
void SurfaceTexture::freeAllBuffers() {
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
mSlots[i].mGraphicBuffer = 0;
@@ -842,6 +875,12 @@ uint32_t SurfaceTexture::getCurrentScalingMode() const {
int SurfaceTexture::query(int what, int* outValue)
{
Mutex::Autolock lock(mMutex);
+
+ if (mAbandoned) {
+ LOGE("query: SurfaceTexture has been abandoned!");
+ return NO_INIT;
+ }
+
int value;
switch (what) {
case NATIVE_WINDOW_WIDTH:
@@ -868,6 +907,13 @@ int SurfaceTexture::query(int what, int* outValue)
return NO_ERROR;
}
+void SurfaceTexture::abandon() {
+ Mutex::Autolock lock(mMutex);
+ freeAllBuffers();
+ mAbandoned = true;
+ mDequeueCondition.signal();
+}
+
void SurfaceTexture::dump(String8& result) const
{
char buffer[1024];
@@ -895,12 +941,12 @@ void SurfaceTexture::dump(String8& result, const char* prefix,
}
snprintf(buffer, SIZE,
- "%scurrent: {crop=[%d,%d,%d,%d], transform=0x%02x, current=%d, target=0x%04x}\n"
+ "%scurrent: {crop=[%d,%d,%d,%d], transform=0x%02x, current=%d}\n"
"%snext : {crop=[%d,%d,%d,%d], transform=0x%02x, FIFO(%d)={%s}}\n"
,
prefix, mCurrentCrop.left,
mCurrentCrop.top, mCurrentCrop.right, mCurrentCrop.bottom,
- mCurrentTransform, mCurrentTexture, mCurrentTextureTarget,
+ mCurrentTransform, mCurrentTexture,
prefix, mNextCrop.left, mNextCrop.top, mNextCrop.right, mNextCrop.bottom,
mCurrentTransform, fifoSize, fifo.string()
);
diff --git a/libs/gui/SurfaceTextureClient.cpp b/libs/gui/SurfaceTextureClient.cpp
index 1dc6cd2..df0ad5a 100644
--- a/libs/gui/SurfaceTextureClient.cpp
+++ b/libs/gui/SurfaceTextureClient.cpp
@@ -55,6 +55,9 @@ void SurfaceTextureClient::init() {
mQueryWidth = 0;
mQueryHeight = 0;
mQueryFormat = 0;
+ mDefaultWidth = 0;
+ mDefaultHeight = 0;
+ mTransformHint = 0;
mConnectedToCpu = false;
}
@@ -62,9 +65,6 @@ void SurfaceTextureClient::setISurfaceTexture(
const sp<ISurfaceTexture>& surfaceTexture)
{
mSurfaceTexture = surfaceTexture;
-
- // Get a reference to the allocator.
- mAllocator = mSurfaceTexture->getAllocator();
}
sp<ISurfaceTexture> SurfaceTextureClient::getISurfaceTexture() const {
@@ -148,10 +148,11 @@ int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer) {
}
if ((result & ISurfaceTexture::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
- gbuf = mSurfaceTexture->requestBuffer(buf);
- if (gbuf == 0) {
- LOGE("dequeueBuffer: ISurfaceTexture::requestBuffer failed");
- return NO_MEMORY;
+ result = mSurfaceTexture->requestBuffer(buf, &gbuf);
+ if (result != NO_ERROR) {
+ LOGE("dequeueBuffer: ISurfaceTexture::requestBuffer failed: %d",
+ result);
+ return result;
}
mQueryWidth = gbuf->width;
mQueryHeight = gbuf->height;
diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp
index 9abe89d..44babcf 100644
--- a/libs/gui/tests/SurfaceTexture_test.cpp
+++ b/libs/gui/tests/SurfaceTexture_test.cpp
@@ -832,9 +832,7 @@ TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledYV12BuffersRepeatedly) {
pt->requestExitAndWait();
}
-// XXX: This test is disabled because there are currently no drivers that can
-// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
-TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferNpot) {
+TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledRGBABufferNpot) {
const int texWidth = 64;
const int texHeight = 66;
@@ -871,26 +869,24 @@ TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferNpot) {
EXPECT_TRUE(checkPixel( 0, 65, 35, 35, 35, 35));
EXPECT_TRUE(checkPixel(15, 10, 35, 231, 231, 231));
- EXPECT_TRUE(checkPixel(24, 63, 38, 228, 231, 35));
+ EXPECT_TRUE(checkPixel(23, 65, 231, 35, 231, 35));
EXPECT_TRUE(checkPixel(19, 40, 35, 231, 35, 35));
EXPECT_TRUE(checkPixel(38, 30, 231, 35, 35, 35));
EXPECT_TRUE(checkPixel(42, 54, 35, 35, 35, 231));
- EXPECT_TRUE(checkPixel(37, 33, 228, 38, 38, 38));
+ EXPECT_TRUE(checkPixel(37, 34, 35, 231, 231, 231));
EXPECT_TRUE(checkPixel(31, 8, 231, 35, 35, 231));
- EXPECT_TRUE(checkPixel(36, 47, 228, 35, 231, 231));
- EXPECT_TRUE(checkPixel(24, 63, 38, 228, 231, 35));
- EXPECT_TRUE(checkPixel(48, 3, 228, 228, 38, 35));
+ EXPECT_TRUE(checkPixel(37, 47, 231, 35, 231, 231));
+ EXPECT_TRUE(checkPixel(25, 38, 35, 35, 35, 35));
+ EXPECT_TRUE(checkPixel(49, 6, 35, 231, 35, 35));
EXPECT_TRUE(checkPixel(54, 50, 35, 231, 231, 231));
- EXPECT_TRUE(checkPixel(24, 25, 41, 41, 231, 231));
- EXPECT_TRUE(checkPixel(10, 9, 38, 38, 231, 231));
+ EXPECT_TRUE(checkPixel(27, 26, 231, 231, 231, 231));
+ EXPECT_TRUE(checkPixel(10, 6, 35, 35, 231, 231));
EXPECT_TRUE(checkPixel(29, 4, 35, 35, 35, 231));
- EXPECT_TRUE(checkPixel(56, 31, 38, 228, 231, 35));
+ EXPECT_TRUE(checkPixel(55, 28, 35, 35, 231, 35));
EXPECT_TRUE(checkPixel(58, 55, 35, 35, 231, 231));
}
-// XXX: This test is disabled because there are currently no drivers that can
-// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
-TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferPow2) {
+TEST_F(SurfaceTextureGLTest, TexturingFromCpuFilledRGBABufferPow2) {
const int texWidth = 64;
const int texHeight = 64;
@@ -944,9 +940,7 @@ TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromCpuFilledRGBABufferPow2) {
EXPECT_TRUE(checkPixel( 3, 52, 35, 231, 35, 35));
}
-// XXX: This test is disabled because there are currently no drivers that can
-// handle RGBA textures with the GL_TEXTURE_EXTERNAL_OES target.
-TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromGLFilledRGBABufferPow2) {
+TEST_F(SurfaceTextureGLTest, TexturingFromGLFilledRGBABufferPow2) {
const int texWidth = 64;
const int texHeight = 64;
@@ -956,7 +950,7 @@ TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromGLFilledRGBABufferPow2) {
EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
mANW.get(), NULL);
ASSERT_EQ(EGL_SUCCESS, eglGetError());
- ASSERT_NE(EGL_NO_SURFACE, mEglSurface);
+ ASSERT_NE(EGL_NO_SURFACE, stcEglSurface);
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface,
mEglContext));
@@ -980,6 +974,8 @@ TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromGLFilledRGBABufferPow2) {
eglSwapBuffers(mEglDisplay, stcEglSurface);
+ eglDestroySurface(mEglDisplay, stcEglSurface);
+
// Do the consumer side of things
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
mEglContext));
@@ -1018,6 +1014,83 @@ TEST_F(SurfaceTextureGLTest, DISABLED_TexturingFromGLFilledRGBABufferPow2) {
EXPECT_TRUE(checkPixel( 3, 52, 153, 153, 153, 153));
}
+TEST_F(SurfaceTextureGLTest, AbandonUnblocksDequeueBuffer) {
+ class ProducerThread : public Thread {
+ public:
+ ProducerThread(const sp<ANativeWindow>& anw):
+ mANW(anw),
+ mDequeueError(NO_ERROR) {
+ }
+
+ virtual ~ProducerThread() {
+ }
+
+ virtual bool threadLoop() {
+ Mutex::Autolock lock(mMutex);
+ ANativeWindowBuffer* anb;
+
+ // Frame 1
+ if (mANW->dequeueBuffer(mANW.get(), &anb) != NO_ERROR) {
+ return false;
+ }
+ if (anb == NULL) {
+ return false;
+ }
+ if (mANW->queueBuffer(mANW.get(), anb)
+ != NO_ERROR) {
+ return false;
+ }
+
+ // Frame 2
+ if (mANW->dequeueBuffer(mANW.get(), &anb) != NO_ERROR) {
+ return false;
+ }
+ if (anb == NULL) {
+ return false;
+ }
+ if (mANW->queueBuffer(mANW.get(), anb)
+ != NO_ERROR) {
+ return false;
+ }
+
+ // Frame 3 - error expected
+ mDequeueError = mANW->dequeueBuffer(mANW.get(), &anb);
+ return false;
+ }
+
+ status_t getDequeueError() {
+ Mutex::Autolock lock(mMutex);
+ return mDequeueError;
+ }
+
+ private:
+ sp<ANativeWindow> mANW;
+ status_t mDequeueError;
+ Mutex mMutex;
+ };
+
+ sp<FrameWaiter> fw(new FrameWaiter);
+ mST->setFrameAvailableListener(fw);
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, mST->setBufferCountServer(2));
+
+ sp<Thread> pt(new ProducerThread(mANW));
+ pt->run();
+
+ fw->waitForFrame();
+ fw->waitForFrame();
+
+ // Sleep for 100ms to allow the producer thread's dequeueBuffer call to
+ // block waiting for a buffer to become available.
+ usleep(100000);
+
+ mST->abandon();
+
+ pt->requestExitAndWait();
+ ASSERT_EQ(NO_INIT,
+ reinterpret_cast<ProducerThread*>(pt.get())->getDequeueError());
+}
+
/*
* This test is for testing GL -> GL texture streaming via SurfaceTexture. It
* contains functionality to create a producer thread that will perform GL
@@ -1205,7 +1278,7 @@ protected:
sp<FrameCondition> mFC;
};
-TEST_F(SurfaceTextureGLToGLTest, UpdateTexImageBeforeFrameFinishedWorks) {
+TEST_F(SurfaceTextureGLToGLTest, UpdateTexImageBeforeFrameFinishedCompletes) {
class PT : public ProducerThread {
virtual void render() {
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
@@ -1223,7 +1296,7 @@ TEST_F(SurfaceTextureGLToGLTest, UpdateTexImageBeforeFrameFinishedWorks) {
// TODO: Add frame verification once RGB TEX_EXTERNAL_OES is supported!
}
-TEST_F(SurfaceTextureGLToGLTest, UpdateTexImageAfterFrameFinishedWorks) {
+TEST_F(SurfaceTextureGLToGLTest, UpdateTexImageAfterFrameFinishedCompletes) {
class PT : public ProducerThread {
virtual void render() {
glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
@@ -1241,7 +1314,7 @@ TEST_F(SurfaceTextureGLToGLTest, UpdateTexImageAfterFrameFinishedWorks) {
// TODO: Add frame verification once RGB TEX_EXTERNAL_OES is supported!
}
-TEST_F(SurfaceTextureGLToGLTest, RepeatedUpdateTexImageBeforeFrameFinishedWorks) {
+TEST_F(SurfaceTextureGLToGLTest, RepeatedUpdateTexImageBeforeFrameFinishedCompletes) {
enum { NUM_ITERATIONS = 1024 };
class PT : public ProducerThread {
@@ -1269,7 +1342,7 @@ TEST_F(SurfaceTextureGLToGLTest, RepeatedUpdateTexImageBeforeFrameFinishedWorks)
}
}
-TEST_F(SurfaceTextureGLToGLTest, RepeatedUpdateTexImageAfterFrameFinishedWorks) {
+TEST_F(SurfaceTextureGLToGLTest, RepeatedUpdateTexImageAfterFrameFinishedCompletes) {
enum { NUM_ITERATIONS = 1024 };
class PT : public ProducerThread {
@@ -1297,4 +1370,70 @@ TEST_F(SurfaceTextureGLToGLTest, RepeatedUpdateTexImageAfterFrameFinishedWorks)
}
}
+// XXX: This test is disabled because it is currently hanging on some devices.
+TEST_F(SurfaceTextureGLToGLTest, DISABLED_RepeatedSwapBuffersWhileDequeueStalledCompletes) {
+ enum { NUM_ITERATIONS = 64 };
+
+ class PT : public ProducerThread {
+ virtual void render() {
+ for (int i = 0; i < NUM_ITERATIONS; i++) {
+ glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT);
+ LOGV("+swapBuffers");
+ swapBuffers();
+ LOGV("-swapBuffers");
+ }
+ }
+ };
+
+ ASSERT_EQ(OK, mST->setSynchronousMode(true));
+ ASSERT_EQ(OK, mST->setBufferCountServer(2));
+
+ runProducerThread(new PT());
+
+ // Allow three frames to be rendered and queued before starting the
+ // rendering in this thread. For the latter two frames we don't call
+ // updateTexImage so the next dequeue from the producer thread will block
+ // waiting for a frame to become available.
+ mFC->waitForFrame();
+ mFC->finishFrame();
+
+ // We must call updateTexImage to consume the first frame so that the
+ // SurfaceTexture is able to reduce the buffer count to 2. This is because
+ // the GL driver may dequeue a buffer when the EGLSurface is created, and
+ // that happens before we call setBufferCountServer. It's possible that the
+ // driver does not dequeue a buffer at EGLSurface creation time, so we
+ // cannot rely on this to cause the second dequeueBuffer call to block.
+ mST->updateTexImage();
+
+ mFC->waitForFrame();
+ mFC->finishFrame();
+ mFC->waitForFrame();
+ mFC->finishFrame();
+
+ // Sleep for 100ms to allow the producer thread's dequeueBuffer call to
+ // block waiting for a buffer to become available.
+ usleep(100000);
+
+ // Render and present a number of images. This thread should not be blocked
+ // by the fact that the producer thread is blocking in dequeue.
+ for (int i = 0; i < NUM_ITERATIONS; i++) {
+ glClear(GL_COLOR_BUFFER_BIT);
+ eglSwapBuffers(mEglDisplay, mEglSurface);
+ }
+
+ // Consume the two pending buffers to unblock the producer thread.
+ mST->updateTexImage();
+ mST->updateTexImage();
+
+ // Consume the remaining buffers from the producer thread.
+ for (int i = 0; i < NUM_ITERATIONS-3; i++) {
+ mFC->waitForFrame();
+ mFC->finishFrame();
+ LOGV("+updateTexImage");
+ mST->updateTexImage();
+ LOGV("-updateTexImage");
+ }
+}
+
} // namespace android
diff --git a/libs/ui/FramebufferNativeWindow.cpp b/libs/ui/FramebufferNativeWindow.cpp
index 412552e..0e8ae61 100644
--- a/libs/ui/FramebufferNativeWindow.cpp
+++ b/libs/ui/FramebufferNativeWindow.cpp
@@ -310,35 +310,21 @@ int FramebufferNativeWindow::perform(ANativeWindow* window,
int operation, ...)
{
switch (operation) {
- case NATIVE_WINDOW_SET_USAGE:
- // TODO: we should implement this
- return NO_ERROR;
case NATIVE_WINDOW_CONNECT:
- // TODO: we should implement this
- return NO_ERROR;
case NATIVE_WINDOW_DISCONNECT:
- // TODO: we should implement this
+ case NATIVE_WINDOW_SET_USAGE:
+ case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
+ case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
+ case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
+ case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
+ // TODO: we should implement these
return NO_ERROR;
+
case NATIVE_WINDOW_LOCK:
- return INVALID_OPERATION;
case NATIVE_WINDOW_UNLOCK_AND_POST:
- return INVALID_OPERATION;
case NATIVE_WINDOW_SET_CROP:
- return INVALID_OPERATION;
case NATIVE_WINDOW_SET_BUFFER_COUNT:
- // TODO: we should implement this
- return INVALID_OPERATION;
- case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
- return INVALID_OPERATION;
- case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
- return INVALID_OPERATION;
case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
- return INVALID_OPERATION;
- case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
- return INVALID_OPERATION;
- case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
- // TODO: we should implement this
- return NO_ERROR;
case NATIVE_WINDOW_SET_SCALING_MODE:
return INVALID_OPERATION;
}
diff --git a/media/java/android/media/AudioFormat.java b/media/java/android/media/AudioFormat.java
index 31e4631..82e8d77 100644
--- a/media/java/android/media/AudioFormat.java
+++ b/media/java/android/media/AudioFormat.java
@@ -54,7 +54,8 @@ public class AudioFormat {
/** Default audio channel mask */
public static final int CHANNEL_OUT_DEFAULT = 1;
- // Channel mask definitions must be kept in sync with native values in include/media/AudioSystem.h
+ // Channel mask definitions must be kept in sync with native values
+ // in /system/core/include/system/audio.h
public static final int CHANNEL_OUT_FRONT_LEFT = 0x4;
public static final int CHANNEL_OUT_FRONT_RIGHT = 0x8;
public static final int CHANNEL_OUT_FRONT_CENTER = 0x10;
@@ -64,6 +65,25 @@ public class AudioFormat {
public static final int CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100;
public static final int CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200;
public static final int CHANNEL_OUT_BACK_CENTER = 0x400;
+ /** @hide */
+ public static final int CHANNEL_OUT_SIDE_LEFT = 0x800;
+ /** @hide */
+ public static final int CHANNEL_OUT_SIDE_RIGHT = 0x1000;
+ /** @hide */
+ public static final int CHANNEL_OUT_TOP_CENTER = 0x2000;
+ /** @hide */
+ public static final int CHANNEL_OUT_TOP_FRONT_LEFT = 0x4000;
+ /** @hide */
+ public static final int CHANNEL_OUT_TOP_FRONT_CENTER = 0x8000;
+ /** @hide */
+ public static final int CHANNEL_OUT_TOP_FRONT_RIGHT = 0x10000;
+ /** @hide */
+ public static final int CHANNEL_OUT_TOP_BACK_LEFT = 0x20000;
+ /** @hide */
+ public static final int CHANNEL_OUT_TOP_BACK_CENTER = 0x40000;
+ /** @hide */
+ public static final int CHANNEL_OUT_TOP_BACK_RIGHT = 0x80000;
+
public static final int CHANNEL_OUT_MONO = CHANNEL_OUT_FRONT_LEFT;
public static final int CHANNEL_OUT_STEREO = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT);
public static final int CHANNEL_OUT_QUAD = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
@@ -75,6 +95,12 @@ public class AudioFormat {
public static final int CHANNEL_OUT_7POINT1 = (CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_RIGHT |
CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_LOW_FREQUENCY | CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
CHANNEL_OUT_FRONT_LEFT_OF_CENTER | CHANNEL_OUT_FRONT_RIGHT_OF_CENTER);
+ /** @hide */
+ public static final int CHANNEL_OUT_7POINT1_SURROUND = (
+ CHANNEL_OUT_FRONT_LEFT | CHANNEL_OUT_FRONT_CENTER | CHANNEL_OUT_FRONT_RIGHT |
+ CHANNEL_OUT_SIDE_LEFT | CHANNEL_OUT_SIDE_RIGHT |
+ CHANNEL_OUT_BACK_LEFT | CHANNEL_OUT_BACK_RIGHT |
+ CHANNEL_OUT_LOW_FREQUENCY);
public static final int CHANNEL_IN_DEFAULT = 1;
public static final int CHANNEL_IN_LEFT = 0x4;
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index 482b437..95671bc 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -611,7 +611,7 @@ public class MediaPlayer
* needed. Not calling this method when playing back a video will
* result in only the audio track being played.
*
- * Either a surface or surface texture must be set if a display or video sink
+ * Either a surface holder or surface must be set if a display or video sink
* is needed. Not calling this method or {@link #setTexture(SurfaceTexture)}
* when playing back a video will result in only the audio track being played.
*
@@ -630,6 +630,27 @@ public class MediaPlayer
}
/**
+ * Sets the {@link Surface} to be used as the sink for the video portion of
+ * the media. This is similar to {@link #setDisplay(SurfaceHolder)}, but does not
+ * support {@link #setScreenOnWhilePlaying(boolean)} or {@link #updateSurfaceScreenOn()}.
+ * Setting a Surface will un-set any Surface or SurfaceHolder that was previously set.
+ *
+ * @param surface The {@link Surface} to be used for the video portion of the media.
+ *
+ * @hide Pending review by API council.
+ */
+ public void setSurface(Surface surface) {
+ if (mScreenOnWhilePlaying && surface != null && mSurface != null) {
+ Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for Surface");
+ }
+ mSurfaceHolder = null;
+ mSurface = surface;
+ mParcelSurfaceTexture = null; // TODO(tedbo): Remove.
+ _setVideoSurfaceOrSurfaceTexture();
+ updateSurfaceScreenOn();
+ }
+
+ /**
* Sets the {@link SurfaceTexture} to be used as the sink for the
* video portion of the media. Either a surface or surface texture
* must be set if a video sink is needed. The same surface texture
@@ -665,7 +686,7 @@ public class MediaPlayer
* @param pst The {@link ParcelSurfaceTexture} to be used as the sink for
* the video portion of the media.
*
- * @hide Pending review by API council.
+ * @hide Pending removal when there are no more callers.
*/
public void setParcelSurfaceTexture(ParcelSurfaceTexture pst) {
if (mScreenOnWhilePlaying && pst != null && mParcelSurfaceTexture == null) {
@@ -1000,8 +1021,8 @@ public class MediaPlayer
*/
public void setScreenOnWhilePlaying(boolean screenOn) {
if (mScreenOnWhilePlaying != screenOn) {
- if (screenOn && mParcelSurfaceTexture != null) {
- Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective for SurfaceTexture");
+ if (screenOn && mSurfaceHolder == null) {
+ Log.w(TAG, "setScreenOnWhilePlaying(true) is ineffective without a SurfaceHolder");
}
mScreenOnWhilePlaying = screenOn;
updateSurfaceScreenOn();
diff --git a/media/java/android/media/MediaRecorder.java b/media/java/android/media/MediaRecorder.java
index e3cbd57..72069ac 100644
--- a/media/java/android/media/MediaRecorder.java
+++ b/media/java/android/media/MediaRecorder.java
@@ -81,9 +81,6 @@ public class MediaRecorder
private String mPath;
private FileDescriptor mFd;
- private boolean mPrepareAuxiliaryFile = false;
- private String mPathAux;
- private FileDescriptor mFdAux;
private EventHandler mEventHandler;
private OnErrorListener mOnErrorListener;
private OnInfoListener mOnInfoListener;
@@ -557,84 +554,23 @@ public class MediaRecorder
}
/**
- * Sets the auxiliary time lapse video's resolution and bitrate.
- *
- * The auxiliary video's resolution and bitrate are determined by the CamcorderProfile
- * quality level {@link android.media.CamcorderProfile#QUALITY_HIGH}.
- */
- private void setAuxVideoParameters() {
- CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
- setParameter(String.format("video-aux-param-width=%d", profile.videoFrameWidth));
- setParameter(String.format("video-aux-param-height=%d", profile.videoFrameHeight));
- setParameter(String.format("video-aux-param-encoding-bitrate=%d", profile.videoBitRate));
- }
-
- /**
- * Pass in the file descriptor for the auxiliary time lapse video. Call this before
- * prepare().
- *
- * Sets file descriptor and parameters for auxiliary time lapse video. Time lapse mode
- * can capture video (using the still camera) at resolutions higher than that can be
- * played back on the device. This function or
- * {@link #setAuxiliaryOutputFile(String)} enable capture of a smaller video in
- * parallel with the main time lapse video, which can be used to play back on the
- * device. The smaller video is created by downsampling the main video. This call is
- * optional and does not have to be called if parallel capture of a downsampled video
- * is not desired.
- *
- * Note that while the main video resolution and bitrate is determined from the
- * CamcorderProfile in {@link #setProfile(CamcorderProfile)}, the auxiliary video's
- * resolution and bitrate are determined by the CamcorderProfile quality level
- * {@link android.media.CamcorderProfile#QUALITY_HIGH}. All other encoding parameters
- * remain the same for the main video and the auxiliary video.
- *
- * E.g. if the device supports the time lapse profile quality level
- * {@link android.media.CamcorderProfile#QUALITY_TIME_LAPSE_1080P} but can playback at
- * most 480p, the application might want to capture an auxiliary video of resolution
- * 480p using this call.
- *
- * @param fd an open file descriptor to be written into.
+ * Currently not implemented. It does nothing.
+ * @deprecated Time lapse mode video recording using camera still image capture
+ * is not desirable, and will not be supported.
*/
public void setAuxiliaryOutputFile(FileDescriptor fd)
{
- mPrepareAuxiliaryFile = true;
- mPathAux = null;
- mFdAux = fd;
- setAuxVideoParameters();
+ Log.w(TAG, "setAuxiliaryOutputFile(FileDescriptor) is no longer supported.");
}
/**
- * Pass in the file path for the auxiliary time lapse video. Call this before
- * prepare().
- *
- * Sets file path and parameters for auxiliary time lapse video. Time lapse mode can
- * capture video (using the still camera) at resolutions higher than that can be
- * played back on the device. This function or
- * {@link #setAuxiliaryOutputFile(FileDescriptor)} enable capture of a smaller
- * video in parallel with the main time lapse video, which can be used to play back on
- * the device. The smaller video is created by downsampling the main video. This call
- * is optional and does not have to be called if parallel capture of a downsampled
- * video is not desired.
- *
- * Note that while the main video resolution and bitrate is determined from the
- * CamcorderProfile in {@link #setProfile(CamcorderProfile)}, the auxiliary video's
- * resolution and bitrate are determined by the CamcorderProfile quality level
- * {@link android.media.CamcorderProfile#QUALITY_HIGH}. All other encoding parameters
- * remain the same for the main video and the auxiliary video.
- *
- * E.g. if the device supports the time lapse profile quality level
- * {@link android.media.CamcorderProfile#QUALITY_TIME_LAPSE_1080P} but can playback at
- * most 480p, the application might want to capture an auxiliary video of resolution
- * 480p using this call.
- *
- * @param path The pathname to use.
+ * Currently not implemented. It does nothing.
+ * @deprecated Time lapse mode video recording using camera still image capture
+ * is not desirable, and will not be supported.
*/
public void setAuxiliaryOutputFile(String path)
{
- mPrepareAuxiliaryFile = true;
- mFdAux = null;
- mPathAux = path;
- setAuxVideoParameters();
+ Log.w(TAG, "setAuxiliaryOutputFile(String) is no longer supported.");
}
/**
@@ -668,8 +604,6 @@ public class MediaRecorder
// native implementation
private native void _setOutputFile(FileDescriptor fd, long offset, long length)
throws IllegalStateException, IOException;
- private native void _setOutputFileAux(FileDescriptor fd)
- throws IllegalStateException, IOException;
private native void _prepare() throws IllegalStateException, IOException;
/**
@@ -696,21 +630,6 @@ public class MediaRecorder
throw new IOException("No valid output file");
}
- if (mPrepareAuxiliaryFile) {
- if (mPathAux != null) {
- FileOutputStream fos = new FileOutputStream(mPathAux);
- try {
- _setOutputFileAux(fos.getFD());
- } finally {
- fos.close();
- }
- } else if (mFdAux != null) {
- _setOutputFileAux(mFdAux);
- } else {
- throw new IOException("No valid output file");
- }
- }
-
_prepare();
}
diff --git a/media/jni/android_media_MediaRecorder.cpp b/media/jni/android_media_MediaRecorder.cpp
index 12391c8..922f7ed 100644
--- a/media/jni/android_media_MediaRecorder.cpp
+++ b/media/jni/android_media_MediaRecorder.cpp
@@ -127,7 +127,7 @@ static bool process_media_recorder_call(JNIEnv *env, status_t opStatus, const ch
return false;
}
-static sp<MediaRecorder> getMediaRecorder(JNIEnv* env, jobject thiz)
+sp<MediaRecorder> getMediaRecorder(JNIEnv* env, jobject thiz)
{
Mutex::Autolock l(sLock);
MediaRecorder* const p = (MediaRecorder*)env->GetIntField(thiz, fields.context);
@@ -261,20 +261,6 @@ android_media_MediaRecorder_setOutputFileFD(JNIEnv *env, jobject thiz, jobject f
}
static void
-android_media_MediaRecorder_setOutputFileAuxFD(JNIEnv *env, jobject thiz, jobject fileDescriptor)
-{
- LOGV("setOutputFile");
- if (fileDescriptor == NULL) {
- jniThrowException(env, "java/lang/IllegalArgumentException", NULL);
- return;
- }
- int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
- sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
- status_t opStatus = mr->setOutputFileAuxiliary(fd);
- process_media_recorder_call(env, opStatus, "java/io/IOException", "setOutputFile failed.");
-}
-
-static void
android_media_MediaRecorder_setVideoSize(JNIEnv *env, jobject thiz, jint width, jint height)
{
LOGV("setVideoSize(%d, %d)", width, height);
@@ -475,7 +461,6 @@ static JNINativeMethod gMethods[] = {
{"setAudioEncoder", "(I)V", (void *)android_media_MediaRecorder_setAudioEncoder},
{"setParameter", "(Ljava/lang/String;)V", (void *)android_media_MediaRecorder_setParameter},
{"_setOutputFile", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaRecorder_setOutputFileFD},
- {"_setOutputFileAux", "(Ljava/io/FileDescriptor;)V", (void *)android_media_MediaRecorder_setOutputFileAuxFD},
{"setVideoSize", "(II)V", (void *)android_media_MediaRecorder_setVideoSize},
{"setVideoFrameRate", "(I)V", (void *)android_media_MediaRecorder_setVideoFrameRate},
{"setMaxDuration", "(I)V", (void *)android_media_MediaRecorder_setMaxDuration},
diff --git a/media/libmedia/IMediaRecorder.cpp b/media/libmedia/IMediaRecorder.cpp
index a44ef5a..7e44c29 100644
--- a/media/libmedia/IMediaRecorder.cpp
+++ b/media/libmedia/IMediaRecorder.cpp
@@ -23,14 +23,17 @@
#include <camera/ICamera.h>
#include <media/IMediaRecorderClient.h>
#include <media/IMediaRecorder.h>
+#include <gui/ISurfaceTexture.h>
#include <unistd.h>
+
namespace android {
enum {
RELEASE = IBinder::FIRST_CALL_TRANSACTION,
INIT,
CLOSE,
+ QUERY_SURFACE_MEDIASOURCE,
RESET,
STOP,
START,
@@ -71,6 +74,19 @@ public:
return reply.readInt32();
}
+ sp<ISurfaceTexture> querySurfaceMediaSource()
+ {
+ LOGV("Query SurfaceMediaSource");
+ Parcel data, reply;
+ data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
+ remote()->transact(QUERY_SURFACE_MEDIASOURCE, data, &reply);
+ int returnedNull = reply.readInt32();
+ if (returnedNull) {
+ return NULL;
+ }
+ return interface_cast<ISurfaceTexture>(reply.readStrongBinder());
+ }
+
status_t setPreviewSurface(const sp<Surface>& surface)
{
LOGV("setPreviewSurface(%p)", surface.get());
@@ -440,6 +456,20 @@ status_t BnMediaRecorder::onTransact(
reply->writeInt32(setCamera(camera, proxy));
return NO_ERROR;
} break;
+ case QUERY_SURFACE_MEDIASOURCE: {
+ LOGV("QUERY_SURFACE_MEDIASOURCE");
+ CHECK_INTERFACE(IMediaRecorder, data, reply);
+ // call the mediaserver side to create
+ // a surfacemediasource
+ sp<ISurfaceTexture> surfaceMediaSource = querySurfaceMediaSource();
+ // The mediaserver might have failed to create a source
+ int returnedNull= (surfaceMediaSource == NULL) ? 1 : 0 ;
+ reply->writeInt32(returnedNull);
+ if (!returnedNull) {
+ reply->writeStrongBinder(surfaceMediaSource->asBinder());
+ }
+ return NO_ERROR;
+ } break;
default:
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/media/libmedia/mediaplayer.cpp b/media/libmedia/mediaplayer.cpp
index ed6e3c7..a11fb80 100644
--- a/media/libmedia/mediaplayer.cpp
+++ b/media/libmedia/mediaplayer.cpp
@@ -228,6 +228,7 @@ status_t MediaPlayer::setVideoSurface(const sp<Surface>& surface)
NATIVE_WINDOW_API_MEDIA);
if (err != OK) {
+ LOGE("setVideoSurface failed: %d", err);
// Note that we must do the reset before disconnecting from the ANW.
// Otherwise queue/dequeue calls could be made on the disconnected
// ANW, which may result in errors.
@@ -277,6 +278,7 @@ status_t MediaPlayer::setVideoSurfaceTexture(
NATIVE_WINDOW_API_MEDIA);
if (err != OK) {
+ LOGE("setVideoSurfaceTexture failed: %d", err);
// Note that we must do the reset before disconnecting from the ANW.
// Otherwise queue/dequeue calls could be made on the disconnected
// ANW, which may result in errors.
diff --git a/media/libmedia/mediarecorder.cpp b/media/libmedia/mediarecorder.cpp
index 9e4edd0..fab674c 100644
--- a/media/libmedia/mediarecorder.cpp
+++ b/media/libmedia/mediarecorder.cpp
@@ -25,6 +25,7 @@
#include <media/IMediaPlayerService.h>
#include <media/IMediaRecorder.h>
#include <media/mediaplayer.h> // for MEDIA_ERROR_SERVER_DIED
+#include <gui/ISurfaceTexture.h>
namespace android {
@@ -127,7 +128,9 @@ status_t MediaRecorder::setVideoSource(int vs)
return INVALID_OPERATION;
}
+ // following call is made over the Binder Interface
status_t ret = mMediaRecorder->setVideoSource(vs);
+
if (OK != ret) {
LOGV("setVideoSource failed: %d", ret);
mCurrentState = MEDIA_RECORDER_ERROR;
@@ -357,7 +360,7 @@ status_t MediaRecorder::setVideoSize(int width, int height)
return INVALID_OPERATION;
}
if (!mIsVideoSourceSet) {
- LOGE("try to set video size without setting video source first");
+ LOGE("Cannot set video size without setting video source first");
return INVALID_OPERATION;
}
@@ -367,9 +370,27 @@ status_t MediaRecorder::setVideoSize(int width, int height)
mCurrentState = MEDIA_RECORDER_ERROR;
return ret;
}
+
return ret;
}
+// Query a SurfaceMediaSurface through the Mediaserver, over the
+// binder interface. This is used by the Filter Framework (MeidaEncoder)
+// to get an <ISurfaceTexture> object to hook up to ANativeWindow.
+sp<ISurfaceTexture> MediaRecorder::
+ querySurfaceMediaSourceFromMediaServer()
+{
+ Mutex::Autolock _l(mLock);
+ mSurfaceMediaSource =
+ mMediaRecorder->querySurfaceMediaSource();
+ if (mSurfaceMediaSource == NULL) {
+ LOGE("SurfaceMediaSource could not be initialized!");
+ }
+ return mSurfaceMediaSource;
+}
+
+
+
status_t MediaRecorder::setVideoFrameRate(int frames_per_second)
{
LOGV("setVideoFrameRate(%d)", frames_per_second);
@@ -382,7 +403,7 @@ status_t MediaRecorder::setVideoFrameRate(int frames_per_second)
return INVALID_OPERATION;
}
if (!mIsVideoSourceSet) {
- LOGE("try to set video frame rate without setting video source first");
+ LOGE("Cannot set video frame rate without setting video source first");
return INVALID_OPERATION;
}
@@ -621,7 +642,7 @@ status_t MediaRecorder::release()
return INVALID_OPERATION;
}
-MediaRecorder::MediaRecorder()
+MediaRecorder::MediaRecorder() : mSurfaceMediaSource(NULL)
{
LOGV("constructor");
@@ -632,6 +653,8 @@ MediaRecorder::MediaRecorder()
if (mMediaRecorder != NULL) {
mCurrentState = MEDIA_RECORDER_IDLE;
}
+
+
doCleanUp();
}
@@ -646,6 +669,10 @@ MediaRecorder::~MediaRecorder()
if (mMediaRecorder != NULL) {
mMediaRecorder.clear();
}
+
+ if (mSurfaceMediaSource != NULL) {
+ mSurfaceMediaSource.clear();
+ }
}
status_t MediaRecorder::setListener(const sp<MediaRecorderListener>& listener)
diff --git a/media/libmediaplayerservice/MediaRecorderClient.cpp b/media/libmediaplayerservice/MediaRecorderClient.cpp
index 115db1a..905b885 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.cpp
+++ b/media/libmediaplayerservice/MediaRecorderClient.cpp
@@ -41,6 +41,7 @@
#include "MediaPlayerService.h"
#include "StagefrightRecorder.h"
+#include <gui/ISurfaceTexture.h>
namespace android {
@@ -57,6 +58,20 @@ static bool checkPermission(const char* permissionString) {
return ok;
}
+
+sp<ISurfaceTexture> MediaRecorderClient::querySurfaceMediaSource()
+{
+ LOGV("Query SurfaceMediaSource");
+ Mutex::Autolock lock(mLock);
+ if (mRecorder == NULL) {
+ LOGE("recorder is not initialized");
+ return NULL;
+ }
+ return mRecorder->querySurfaceMediaSource();
+}
+
+
+
status_t MediaRecorderClient::setCamera(const sp<ICamera>& camera,
const sp<ICameraRecordingProxy>& proxy)
{
diff --git a/media/libmediaplayerservice/MediaRecorderClient.h b/media/libmediaplayerservice/MediaRecorderClient.h
index bbca529..c87a3c0 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.h
+++ b/media/libmediaplayerservice/MediaRecorderClient.h
@@ -25,45 +25,51 @@ namespace android {
class MediaRecorderBase;
class MediaPlayerService;
class ICameraRecordingProxy;
+class ISurfaceTexture;
class MediaRecorderClient : public BnMediaRecorder
{
public:
- virtual status_t setCamera(const sp<ICamera>& camera,
- const sp<ICameraRecordingProxy>& proxy);
- virtual status_t setPreviewSurface(const sp<Surface>& surface);
- virtual status_t setVideoSource(int vs);
- virtual status_t setAudioSource(int as);
- virtual status_t setOutputFormat(int of);
- virtual status_t setVideoEncoder(int ve);
- virtual status_t setAudioEncoder(int ae);
- virtual status_t setOutputFile(const char* path);
- virtual status_t setOutputFile(int fd, int64_t offset, int64_t length);
- virtual status_t setOutputFileAuxiliary(int fd);
- virtual status_t setVideoSize(int width, int height);
- virtual status_t setVideoFrameRate(int frames_per_second);
- virtual status_t setParameters(const String8& params);
- virtual status_t setListener(const sp<IMediaRecorderClient>& listener);
- virtual status_t prepare();
- virtual status_t getMaxAmplitude(int* max);
- virtual status_t start();
- virtual status_t stop();
- virtual status_t reset();
- virtual status_t init();
- virtual status_t close();
- virtual status_t release();
+ virtual status_t setCamera(const sp<ICamera>& camera,
+ const sp<ICameraRecordingProxy>& proxy);
+ virtual status_t setPreviewSurface(const sp<Surface>& surface);
+ virtual status_t setVideoSource(int vs);
+ virtual status_t setAudioSource(int as);
+ virtual status_t setOutputFormat(int of);
+ virtual status_t setVideoEncoder(int ve);
+ virtual status_t setAudioEncoder(int ae);
+ virtual status_t setOutputFile(const char* path);
+ virtual status_t setOutputFile(int fd, int64_t offset,
+ int64_t length);
+ virtual status_t setOutputFileAuxiliary(int fd);
+ virtual status_t setVideoSize(int width, int height);
+ virtual status_t setVideoFrameRate(int frames_per_second);
+ virtual status_t setParameters(const String8& params);
+ virtual status_t setListener(
+ const sp<IMediaRecorderClient>& listener);
+ virtual status_t prepare();
+ virtual status_t getMaxAmplitude(int* max);
+ virtual status_t start();
+ virtual status_t stop();
+ virtual status_t reset();
+ virtual status_t init();
+ virtual status_t close();
+ virtual status_t release();
+ virtual status_t dump(int fd, const Vector<String16>& args) const;
+ virtual sp<ISurfaceTexture> querySurfaceMediaSource();
- virtual status_t dump(int fd, const Vector<String16>& args) const;
private:
- friend class MediaPlayerService; // for accessing private constructor
+ friend class MediaPlayerService; // for accessing private constructor
- MediaRecorderClient(const sp<MediaPlayerService>& service, pid_t pid);
- virtual ~MediaRecorderClient();
+ MediaRecorderClient(
+ const sp<MediaPlayerService>& service,
+ pid_t pid);
+ virtual ~MediaRecorderClient();
- pid_t mPid;
- Mutex mLock;
- MediaRecorderBase *mRecorder;
- sp<MediaPlayerService> mMediaPlayerService;
+ pid_t mPid;
+ Mutex mLock;
+ MediaRecorderBase *mRecorder;
+ sp<MediaPlayerService> mMediaPlayerService;
};
}; // namespace android
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp
index 223e0be..6427bb7 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -38,10 +38,12 @@
#include <media/stagefright/MetaData.h>
#include <media/stagefright/OMXClient.h>
#include <media/stagefright/OMXCodec.h>
+#include <media/stagefright/SurfaceMediaSource.h>
#include <media/MediaProfiles.h>
#include <camera/ICamera.h>
#include <camera/CameraParameters.h>
#include <surfaceflinger/Surface.h>
+
#include <utils/Errors.h>
#include <sys/types.h>
#include <ctype.h>
@@ -69,7 +71,7 @@ StagefrightRecorder::StagefrightRecorder()
mOutputFd(-1), mOutputFdAux(-1),
mAudioSource(AUDIO_SOURCE_CNT),
mVideoSource(VIDEO_SOURCE_LIST_END),
- mStarted(false) {
+ mStarted(false), mSurfaceMediaSource(NULL) {
LOGV("Constructor");
reset();
@@ -85,6 +87,14 @@ status_t StagefrightRecorder::init() {
return OK;
}
+// The client side of mediaserver asks it to creat a SurfaceMediaSource
+// and return a interface reference. The client side will use that
+// while encoding GL Frames
+sp<ISurfaceTexture> StagefrightRecorder::querySurfaceMediaSource() const {
+ LOGV("Get SurfaceMediaSource");
+ return mSurfaceMediaSource;
+}
+
status_t StagefrightRecorder::setAudioSource(audio_source_t as) {
LOGV("setAudioSource: %d", as);
if (as < AUDIO_SOURCE_DEFAULT ||
@@ -1006,13 +1016,13 @@ status_t StagefrightRecorder::startRTPRecording() {
source = createAudioSource();
} else {
- sp<CameraSource> cameraSource;
- status_t err = setupCameraSource(&cameraSource);
+ sp<MediaSource> mediaSource;
+ status_t err = setupMediaSource(&mediaSource);
if (err != OK) {
return err;
}
- err = setupVideoEncoder(cameraSource, mVideoBitRate, &source);
+ err = setupVideoEncoder(mediaSource, mVideoBitRate, &source);
if (err != OK) {
return err;
}
@@ -1042,20 +1052,19 @@ status_t StagefrightRecorder::startMPEG2TSRecording() {
}
}
- if (mVideoSource == VIDEO_SOURCE_DEFAULT
- || mVideoSource == VIDEO_SOURCE_CAMERA) {
+ if (mVideoSource < VIDEO_SOURCE_LIST_END) {
if (mVideoEncoder != VIDEO_ENCODER_H264) {
return ERROR_UNSUPPORTED;
}
- sp<CameraSource> cameraSource;
- status_t err = setupCameraSource(&cameraSource);
+ sp<MediaSource> mediaSource;
+ status_t err = setupMediaSource(&mediaSource);
if (err != OK) {
return err;
}
sp<MediaSource> encoder;
- err = setupVideoEncoder(cameraSource, mVideoBitRate, &encoder);
+ err = setupVideoEncoder(mediaSource, mVideoBitRate, &encoder);
if (err != OK) {
return err;
@@ -1289,6 +1298,60 @@ void StagefrightRecorder::clipVideoFrameHeight() {
}
}
+// Set up the appropriate MediaSource depending on the chosen option
+status_t StagefrightRecorder::setupMediaSource(
+ sp<MediaSource> *mediaSource) {
+ if (mVideoSource == VIDEO_SOURCE_DEFAULT
+ || mVideoSource == VIDEO_SOURCE_CAMERA) {
+ sp<CameraSource> cameraSource;
+ status_t err = setupCameraSource(&cameraSource);
+ if (err != OK) {
+ return err;
+ }
+ *mediaSource = cameraSource;
+ } else if (mVideoSource == VIDEO_SOURCE_GRALLOC_BUFFER) {
+ // If using GRAlloc buffers, setup surfacemediasource.
+ // Later a handle to that will be passed
+ // to the client side when queried
+ status_t err = setupSurfaceMediaSource();
+ if (err != OK) {
+ return err;
+ }
+ *mediaSource = mSurfaceMediaSource;
+ } else {
+ return INVALID_OPERATION;
+ }
+ return OK;
+}
+
+// setupSurfaceMediaSource creates a source with the given
+// width and height and framerate.
+// TODO: This could go in a static function inside SurfaceMediaSource
+// similar to that in CameraSource
+status_t StagefrightRecorder::setupSurfaceMediaSource() {
+ status_t err = OK;
+ mSurfaceMediaSource = new SurfaceMediaSource(mVideoWidth, mVideoHeight);
+ if (mSurfaceMediaSource == NULL) {
+ return NO_INIT;
+ }
+
+ if (mFrameRate == -1) {
+ int32_t frameRate = 0;
+ CHECK (mSurfaceMediaSource->getFormat()->findInt32(
+ kKeyFrameRate, &frameRate));
+ LOGI("Frame rate is not explicitly set. Use the current frame "
+ "rate (%d fps)", frameRate);
+ mFrameRate = frameRate;
+ } else {
+ err = mSurfaceMediaSource->setFrameRate(mFrameRate);
+ }
+ CHECK(mFrameRate != -1);
+
+ mIsMetaDataStoredInVideoBuffers =
+ mSurfaceMediaSource->isMetaDataStoredInVideoBuffers();
+ return err;
+}
+
status_t StagefrightRecorder::setupCameraSource(
sp<CameraSource> *cameraSource) {
status_t err = OK;
@@ -1465,29 +1528,37 @@ status_t StagefrightRecorder::setupMPEG4Recording(
status_t err = OK;
sp<MediaWriter> writer = new MPEG4Writer(outputFd);
- if (mVideoSource == VIDEO_SOURCE_DEFAULT
- || mVideoSource == VIDEO_SOURCE_CAMERA) {
+ if (mVideoSource < VIDEO_SOURCE_LIST_END) {
- sp<MediaSource> cameraMediaSource;
+ sp<MediaSource> mediaSource;
if (useSplitCameraSource) {
+ // TODO: Check if there is a better way to handle this
+ if (mVideoSource == VIDEO_SOURCE_GRALLOC_BUFFER) {
+ LOGE("Cannot use split camera when encoding frames");
+ return INVALID_OPERATION;
+ }
LOGV("Using Split camera source");
- cameraMediaSource = mCameraSourceSplitter->createClient();
+ mediaSource = mCameraSourceSplitter->createClient();
} else {
- sp<CameraSource> cameraSource;
- err = setupCameraSource(&cameraSource);
- cameraMediaSource = cameraSource;
+ err = setupMediaSource(&mediaSource);
}
+
if ((videoWidth != mVideoWidth) || (videoHeight != mVideoHeight)) {
+ // TODO: Might be able to handle downsampling even if using GRAlloc
+ if (mVideoSource == VIDEO_SOURCE_GRALLOC_BUFFER) {
+ LOGE("Cannot change size or Downsample when encoding frames");
+ return INVALID_OPERATION;
+ }
// Use downsampling from the original source.
- cameraMediaSource =
- new VideoSourceDownSampler(cameraMediaSource, videoWidth, videoHeight);
+ mediaSource =
+ new VideoSourceDownSampler(mediaSource, videoWidth, videoHeight);
}
if (err != OK) {
return err;
}
sp<MediaSource> encoder;
- err = setupVideoEncoder(cameraMediaSource, videoBitRate, &encoder);
+ err = setupVideoEncoder(mediaSource, videoBitRate, &encoder);
if (err != OK) {
return err;
}
diff --git a/media/libmediaplayerservice/StagefrightRecorder.h b/media/libmediaplayerservice/StagefrightRecorder.h
index 034b373..1618b92 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.h
+++ b/media/libmediaplayerservice/StagefrightRecorder.h
@@ -36,6 +36,8 @@ struct MediaWriter;
class MetaData;
struct AudioSource;
class MediaProfiles;
+class ISurfaceTexture;
+class SurfaceMediaSource;
struct StagefrightRecorder : public MediaRecorderBase {
StagefrightRecorder();
@@ -64,6 +66,8 @@ struct StagefrightRecorder : public MediaRecorderBase {
virtual status_t reset();
virtual status_t getMaxAmplitude(int *max);
virtual status_t dump(int fd, const Vector<String16>& args) const;
+ // Querying a SurfaceMediaSourcer
+ virtual sp<ISurfaceTexture> querySurfaceMediaSource() const;
private:
sp<ICamera> mCamera;
@@ -109,12 +113,18 @@ private:
sp<MediaSourceSplitter> mCameraSourceSplitter;
sp<CameraSourceTimeLapse> mCameraSourceTimeLapse;
+
String8 mParams;
bool mIsMetaDataStoredInVideoBuffers;
MediaProfiles *mEncoderProfiles;
bool mStarted;
+ // Needed when GLFrames are encoded.
+ // An <ISurfaceTexture> pointer
+ // will be sent to the client side using which the
+ // frame buffers will be queued and dequeued
+ sp<SurfaceMediaSource> mSurfaceMediaSource;
status_t setupMPEG4Recording(
bool useSplitCameraSource,
@@ -134,7 +144,14 @@ private:
sp<MediaSource> createAudioSource();
status_t checkVideoEncoderCapabilities();
status_t checkAudioEncoderCapabilities();
+ // Generic MediaSource set-up. Returns the appropriate
+ // source (CameraSource or SurfaceMediaSource)
+ // depending on the videosource type
+ status_t setupMediaSource(sp<MediaSource> *mediaSource);
status_t setupCameraSource(sp<CameraSource> *cameraSource);
+ // setup the surfacemediasource for the encoder
+ status_t setupSurfaceMediaSource();
+
status_t setupAudioEncoder(const sp<MediaWriter>& writer);
status_t setupVideoEncoder(
sp<MediaSource> cameraSource,
@@ -176,6 +193,7 @@ private:
void clipNumberOfAudioChannels();
void setDefaultProfileIfNecessary();
+
StagefrightRecorder(const StagefrightRecorder &);
StagefrightRecorder &operator=(const StagefrightRecorder &);
};
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
index e17e1e8..3a3c082 100644
--- a/media/libstagefright/Android.mk
+++ b/media/libstagefright/Android.mk
@@ -42,6 +42,7 @@ LOCAL_SRC_FILES:= \
SampleTable.cpp \
StagefrightMediaScanner.cpp \
StagefrightMetadataRetriever.cpp \
+ SurfaceMediaSource.cpp \
ThrottledSource.cpp \
TimeSource.cpp \
TimedEventQueue.cpp \
diff --git a/media/libstagefright/NuCachedSource2.cpp b/media/libstagefright/NuCachedSource2.cpp
index 77a6602..4edb613 100644
--- a/media/libstagefright/NuCachedSource2.cpp
+++ b/media/libstagefright/NuCachedSource2.cpp
@@ -185,7 +185,8 @@ NuCachedSource2::NuCachedSource2(const sp<DataSource> &source)
mFinalStatus(OK),
mLastAccessPos(0),
mFetching(true),
- mLastFetchTimeUs(-1) {
+ mLastFetchTimeUs(-1),
+ mNumRetriesLeft(kMaxNumRetries) {
mLooper->setName("NuCachedSource2");
mLooper->registerHandler(mReflector);
mLooper->start();
@@ -254,7 +255,27 @@ void NuCachedSource2::onMessageReceived(const sp<AMessage> &msg) {
void NuCachedSource2::fetchInternal() {
LOGV("fetchInternal");
- CHECK_EQ(mFinalStatus, (status_t)OK);
+ {
+ Mutex::Autolock autoLock(mLock);
+ CHECK(mFinalStatus == OK || mNumRetriesLeft > 0);
+
+ if (mFinalStatus != OK) {
+ --mNumRetriesLeft;
+
+ status_t err =
+ mSource->reconnectAtOffset(mCacheOffset + mCache->totalSize());
+
+ if (err == ERROR_UNSUPPORTED) {
+ mNumRetriesLeft = 0;
+ return;
+ } else if (err != OK) {
+ LOGI("The attempt to reconnect failed, %d retries remaining",
+ mNumRetriesLeft);
+
+ return;
+ }
+ }
+ }
PageCache::Page *page = mCache->acquirePage();
@@ -264,14 +285,23 @@ void NuCachedSource2::fetchInternal() {
Mutex::Autolock autoLock(mLock);
if (n < 0) {
- LOGE("source returned error %ld", n);
+ LOGE("source returned error %ld, %d retries left", n, mNumRetriesLeft);
mFinalStatus = n;
mCache->releasePage(page);
} else if (n == 0) {
LOGI("ERROR_END_OF_STREAM");
+
+ mNumRetriesLeft = 0;
mFinalStatus = ERROR_END_OF_STREAM;
+
mCache->releasePage(page);
} else {
+ if (mFinalStatus != OK) {
+ LOGI("retrying a previously failed read succeeded.");
+ }
+ mNumRetriesLeft = kMaxNumRetries;
+ mFinalStatus = OK;
+
page->mSize = n;
mCache->appendPage(page);
}
@@ -280,7 +310,7 @@ void NuCachedSource2::fetchInternal() {
void NuCachedSource2::onFetch() {
LOGV("onFetch");
- if (mFinalStatus != OK) {
+ if (mFinalStatus != OK && mNumRetriesLeft == 0) {
LOGV("EOS reached, done prefetching for now");
mFetching = false;
}
@@ -308,8 +338,19 @@ void NuCachedSource2::onFetch() {
restartPrefetcherIfNecessary_l();
}
- (new AMessage(kWhatFetchMore, mReflector->id()))->post(
- mFetching ? 0 : 100000ll);
+ int64_t delayUs;
+ if (mFetching) {
+ if (mFinalStatus != OK && mNumRetriesLeft > 0) {
+ // We failed this time and will try again in 3 seconds.
+ delayUs = 3000000ll;
+ } else {
+ delayUs = 0;
+ }
+ } else {
+ delayUs = 100000ll;
+ }
+
+ (new AMessage(kWhatFetchMore, mReflector->id()))->post(delayUs);
}
void NuCachedSource2::onRead(const sp<AMessage> &msg) {
@@ -345,7 +386,7 @@ void NuCachedSource2::restartPrefetcherIfNecessary_l(
bool ignoreLowWaterThreshold, bool force) {
static const size_t kGrayArea = 1024 * 1024;
- if (mFetching || mFinalStatus != OK) {
+ if (mFetching || (mFinalStatus != OK && mNumRetriesLeft == 0)) {
return;
}
@@ -427,6 +468,12 @@ size_t NuCachedSource2::approxDataRemaining(status_t *finalStatus) {
size_t NuCachedSource2::approxDataRemaining_l(status_t *finalStatus) {
*finalStatus = mFinalStatus;
+
+ if (mFinalStatus != OK && mNumRetriesLeft > 0) {
+ // Pretend that everything is fine until we're out of retries.
+ *finalStatus = OK;
+ }
+
off64_t lastBytePosCached = mCacheOffset + mCache->totalSize();
if (mLastAccessPos < lastBytePosCached) {
return lastBytePosCached - mLastAccessPos;
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 7bcbdcf..ac73351 100755
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -48,6 +48,10 @@
namespace android {
+// Treat time out as an error if we have not received any output
+// buffers after 3 seconds.
+const static int64_t kBufferFilledEventTimeOutUs = 3000000000LL;
+
struct CodecInfo {
const char *mime;
const char *codec;
@@ -3191,6 +3195,16 @@ void OMXCodec::setState(State newState) {
mBufferFilled.signal();
}
+status_t OMXCodec::waitForBufferFilled_l() {
+ status_t err = mBufferFilled.waitRelative(mLock, kBufferFilledEventTimeOutUs);
+ if (err != OK) {
+ LOGE("Timed out waiting for buffers from video encoder: %d/%d",
+ countBuffersWeOwn(mPortBuffers[kPortIndexInput]),
+ countBuffersWeOwn(mPortBuffers[kPortIndexOutput]));
+ }
+ return err;
+}
+
void OMXCodec::setRawAudioFormat(
OMX_U32 portIndex, int32_t sampleRate, int32_t numChannels) {
@@ -3623,6 +3637,7 @@ sp<MetaData> OMXCodec::getFormat() {
status_t OMXCodec::read(
MediaBuffer **buffer, const ReadOptions *options) {
+ status_t err = OK;
*buffer = NULL;
Mutex::Autolock autoLock(mLock);
@@ -3663,7 +3678,9 @@ status_t OMXCodec::read(
if (seeking) {
while (mState == RECONFIGURING) {
- mBufferFilled.wait(mLock);
+ if ((err = waitForBufferFilled_l()) != OK) {
+ return err;
+ }
}
if (mState != EXECUTING) {
@@ -3694,19 +3711,15 @@ status_t OMXCodec::read(
}
while (mSeekTimeUs >= 0) {
- mBufferFilled.wait(mLock);
+ if ((err = waitForBufferFilled_l()) != OK) {
+ return err;
+ }
}
}
while (mState != ERROR && !mNoMoreOutputData && mFilledBuffers.empty()) {
- if (mIsEncoder) {
- if (NO_ERROR != mBufferFilled.waitRelative(mLock, 3000000000LL)) {
- LOGW("Timed out waiting for buffers from video encoder: %d/%d",
- countBuffersWeOwn(mPortBuffers[kPortIndexInput]),
- countBuffersWeOwn(mPortBuffers[kPortIndexOutput]));
- }
- } else {
- mBufferFilled.wait(mLock);
+ if ((err = waitForBufferFilled_l()) != OK) {
+ return err;
}
}
@@ -4415,6 +4428,13 @@ status_t QueryCodecs(
return OK;
}
+status_t QueryCodecs(
+ const sp<IOMX> &omx,
+ const char *mimeType, bool queryDecoders,
+ Vector<CodecCapabilities> *results) {
+ return QueryCodecs(omx, mimeType, queryDecoders, false /*hwCodecOnly*/, results);
+}
+
void OMXCodec::restorePatchedDataPointer(BufferInfo *info) {
CHECK(mIsEncoder && (mQuirks & kAvoidMemcopyInputRecordingFrames));
CHECK(mOMXLivesLocally);
diff --git a/media/libstagefright/SurfaceMediaSource.cpp b/media/libstagefright/SurfaceMediaSource.cpp
new file mode 100644
index 0000000..ff4b08f
--- /dev/null
+++ b/media/libstagefright/SurfaceMediaSource.cpp
@@ -0,0 +1,756 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// #define LOG_NDEBUG 0
+#define LOG_TAG "SurfaceMediaSource"
+
+#include <media/stagefright/SurfaceMediaSource.h>
+#include <ui/GraphicBuffer.h>
+#include <media/stagefright/MetaData.h>
+#include <media/stagefright/MediaDefs.h>
+#include <media/stagefright/MediaDebug.h>
+#include <media/stagefright/openmax/OMX_IVCommon.h>
+
+#include <surfaceflinger/ISurfaceComposer.h>
+#include <surfaceflinger/SurfaceComposerClient.h>
+#include <surfaceflinger/IGraphicBufferAlloc.h>
+#include <OMX_Component.h>
+
+#include <utils/Log.h>
+#include <utils/String8.h>
+
+namespace android {
+
+SurfaceMediaSource::SurfaceMediaSource(uint32_t bufW, uint32_t bufH) :
+ mDefaultWidth(bufW),
+ mDefaultHeight(bufH),
+ mPixelFormat(0),
+ mBufferCount(MIN_ASYNC_BUFFER_SLOTS),
+ mClientBufferCount(0),
+ mServerBufferCount(MIN_ASYNC_BUFFER_SLOTS),
+ mCurrentSlot(INVALID_BUFFER_SLOT),
+ mCurrentTimestamp(0),
+ mSynchronousMode(true),
+ mConnectedApi(NO_CONNECTED_API),
+ mFrameRate(30),
+ mStarted(false) {
+ LOGV("SurfaceMediaSource::SurfaceMediaSource");
+ sp<ISurfaceComposer> composer(ComposerService::getComposerService());
+ mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
+}
+
+SurfaceMediaSource::~SurfaceMediaSource() {
+ LOGV("SurfaceMediaSource::~SurfaceMediaSource");
+ if (mStarted) {
+ stop();
+ }
+ freeAllBuffers();
+}
+
+size_t SurfaceMediaSource::getQueuedCount() const {
+ Mutex::Autolock lock(mMutex);
+ return mQueue.size();
+}
+
+status_t SurfaceMediaSource::setBufferCountServerLocked(int bufferCount) {
+ if (bufferCount > NUM_BUFFER_SLOTS)
+ return BAD_VALUE;
+
+ // special-case, nothing to do
+ if (bufferCount == mBufferCount)
+ return OK;
+
+ if (!mClientBufferCount &&
+ bufferCount >= mBufferCount) {
+ // easy, we just have more buffers
+ mBufferCount = bufferCount;
+ mServerBufferCount = bufferCount;
+ mDequeueCondition.signal();
+ } else {
+ // we're here because we're either
+ // - reducing the number of available buffers
+ // - or there is a client-buffer-count in effect
+
+ // less than 2 buffers is never allowed
+ if (bufferCount < 2)
+ return BAD_VALUE;
+
+ // when there is non client-buffer-count in effect, the client is not
+ // allowed to dequeue more than one buffer at a time,
+ // so the next time they dequeue a buffer, we know that they don't
+ // own one. the actual resizing will happen during the next
+ // dequeueBuffer.
+
+ mServerBufferCount = bufferCount;
+ }
+ return OK;
+}
+
+// Called from the consumer side
+status_t SurfaceMediaSource::setBufferCountServer(int bufferCount) {
+ Mutex::Autolock lock(mMutex);
+ return setBufferCountServerLocked(bufferCount);
+}
+
+status_t SurfaceMediaSource::setBufferCount(int bufferCount) {
+ LOGV("SurfaceMediaSource::setBufferCount");
+ if (bufferCount > NUM_BUFFER_SLOTS) {
+ LOGE("setBufferCount: bufferCount is larger than the number of buffer slots");
+ return BAD_VALUE;
+ }
+
+ Mutex::Autolock lock(mMutex);
+ // Error out if the user has dequeued buffers
+ for (int i = 0 ; i < mBufferCount ; i++) {
+ if (mSlots[i].mBufferState == BufferSlot::DEQUEUED) {
+ LOGE("setBufferCount: client owns some buffers");
+ return INVALID_OPERATION;
+ }
+ }
+
+ if (bufferCount == 0) {
+ const int minBufferSlots = mSynchronousMode ?
+ MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
+ mClientBufferCount = 0;
+ bufferCount = (mServerBufferCount >= minBufferSlots) ?
+ mServerBufferCount : minBufferSlots;
+ return setBufferCountServerLocked(bufferCount);
+ }
+
+ // We don't allow the client to set a buffer-count less than
+ // MIN_ASYNC_BUFFER_SLOTS (3), there is no reason for it.
+ if (bufferCount < MIN_ASYNC_BUFFER_SLOTS) {
+ return BAD_VALUE;
+ }
+
+ // here we're guaranteed that the client doesn't have dequeued buffers
+ // and will release all of its buffer references.
+ freeAllBuffers();
+ mBufferCount = bufferCount;
+ mClientBufferCount = bufferCount;
+ mCurrentSlot = INVALID_BUFFER_SLOT;
+ mQueue.clear();
+ mDequeueCondition.signal();
+ return OK;
+}
+
+status_t SurfaceMediaSource::requestBuffer(int slot, sp<GraphicBuffer>* buf) {
+ LOGV("SurfaceMediaSource::requestBuffer");
+ Mutex::Autolock lock(mMutex);
+ if (slot < 0 || mBufferCount <= slot) {
+ LOGE("requestBuffer: slot index out of range [0, %d]: %d",
+ mBufferCount, slot);
+ return BAD_VALUE;
+ }
+ mSlots[slot].mRequestBufferCalled = true;
+ *buf = mSlots[slot].mGraphicBuffer;
+ return NO_ERROR;
+}
+
+status_t SurfaceMediaSource::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
+ uint32_t format, uint32_t usage) {
+ LOGV("dequeueBuffer");
+
+
+ // Check for the buffer size- the client should just use the
+ // default width and height, and not try to set those.
+ // This is needed since
+ // the getFormat() returns mDefaultWidth/ Height for the OMX. It is
+ // queried by OMX in the beginning and not every time a frame comes.
+ // Not sure if there is a way to update the
+ // frame size while recording. So as of now, the client side
+ // sets the default values via the constructor, and the encoder is
+ // setup to encode frames of that size
+ // The design might need to change in the future.
+ // TODO: Currently just uses mDefaultWidth/Height. In the future
+ // we might declare mHeight and mWidth and check against those here.
+ if ((w != 0) || (h != 0)) {
+ LOGE("dequeuebuffer: invalid buffer size! Req: %dx%d, Found: %dx%d",
+ mDefaultWidth, mDefaultHeight, w, h);
+ return BAD_VALUE;
+ }
+
+ Mutex::Autolock lock(mMutex);
+
+ status_t returnFlags(OK);
+
+ int found, foundSync;
+ int dequeuedCount = 0;
+ bool tryAgain = true;
+ while (tryAgain) {
+ // We need to wait for the FIFO to drain if the number of buffer
+ // needs to change.
+ //
+ // The condition "number of buffer needs to change" is true if
+ // - the client doesn't care about how many buffers there are
+ // - AND the actual number of buffer is different from what was
+ // set in the last setBufferCountServer()
+ // - OR -
+ // setBufferCountServer() was set to a value incompatible with
+ // the synchronization mode (for instance because the sync mode
+ // changed since)
+ //
+ // As long as this condition is true AND the FIFO is not empty, we
+ // wait on mDequeueCondition.
+
+ int minBufferCountNeeded = mSynchronousMode ?
+ MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
+
+ if (!mClientBufferCount &&
+ ((mServerBufferCount != mBufferCount) ||
+ (mServerBufferCount < minBufferCountNeeded))) {
+ // wait for the FIFO to drain
+ while (!mQueue.isEmpty()) {
+ LOGV("Waiting for the FIFO to drain");
+ mDequeueCondition.wait(mMutex);
+ }
+ // need to check again since the mode could have changed
+ // while we were waiting
+ minBufferCountNeeded = mSynchronousMode ?
+ MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
+ }
+
+ if (!mClientBufferCount &&
+ ((mServerBufferCount != mBufferCount) ||
+ (mServerBufferCount < minBufferCountNeeded))) {
+ // here we're guaranteed that mQueue is empty
+ freeAllBuffers();
+ mBufferCount = mServerBufferCount;
+ if (mBufferCount < minBufferCountNeeded)
+ mBufferCount = minBufferCountNeeded;
+ mCurrentSlot = INVALID_BUFFER_SLOT;
+ returnFlags |= ISurfaceTexture::RELEASE_ALL_BUFFERS;
+ }
+
+ // look for a free buffer to give to the client
+ found = INVALID_BUFFER_SLOT;
+ foundSync = INVALID_BUFFER_SLOT;
+ dequeuedCount = 0;
+ for (int i = 0; i < mBufferCount; i++) {
+ const int state = mSlots[i].mBufferState;
+ if (state == BufferSlot::DEQUEUED) {
+ dequeuedCount++;
+ continue; // won't be continuing if could
+ // dequeue a non 'FREE' current slot like
+ // that in SurfaceTexture
+ }
+ // In case of Encoding, we do not deque the mCurrentSlot buffer
+ // since we follow synchronous mode (unlike possibly in
+ // SurfaceTexture that could be using the asynch mode
+ // or has some mechanism in GL to be able to wait till the
+ // currentslot is done using the data)
+ // Here, we have to wait for the MPEG4Writer(or equiv)
+ // to tell us when it's done using the current buffer
+ if (state == BufferSlot::FREE) {
+ foundSync = i;
+ // Unlike that in SurfaceTexture,
+ // We don't need to worry if it is the
+ // currentslot or not as it is in state FREE
+ found = i;
+ break;
+ }
+ }
+
+ // clients are not allowed to dequeue more than one buffer
+ // if they didn't set a buffer count.
+ if (!mClientBufferCount && dequeuedCount) {
+ return -EINVAL;
+ }
+
+ // See whether a buffer has been queued since the last setBufferCount so
+ // we know whether to perform the MIN_UNDEQUEUED_BUFFERS check below.
+ bool bufferHasBeenQueued = mCurrentSlot != INVALID_BUFFER_SLOT;
+ if (bufferHasBeenQueued) {
+ // make sure the client is not trying to dequeue more buffers
+ // than allowed.
+ const int avail = mBufferCount - (dequeuedCount+1);
+ if (avail < (MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode))) {
+ LOGE("dequeueBuffer: MIN_UNDEQUEUED_BUFFERS=%d exceeded (dequeued=%d)",
+ MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode),
+ dequeuedCount);
+ return -EBUSY;
+ }
+ }
+
+ // we're in synchronous mode and didn't find a buffer, we need to wait
+ // for for some buffers to be consumed
+ tryAgain = mSynchronousMode && (foundSync == INVALID_BUFFER_SLOT);
+ if (tryAgain) {
+ LOGW("Waiting..In synchronous mode and no buffer to dQ");
+ mDequeueCondition.wait(mMutex);
+ }
+ }
+
+ if (mSynchronousMode && found == INVALID_BUFFER_SLOT) {
+ // foundSync guaranteed to be != INVALID_BUFFER_SLOT
+ found = foundSync;
+ }
+
+ if (found == INVALID_BUFFER_SLOT) {
+ return -EBUSY;
+ }
+
+ const int buf = found;
+ *outBuf = found;
+
+ const bool useDefaultSize = !w && !h;
+ if (useDefaultSize) {
+ // use the default size
+ w = mDefaultWidth;
+ h = mDefaultHeight;
+ }
+
+ const bool updateFormat = (format != 0);
+ if (!updateFormat) {
+ // keep the current (or default) format
+ format = mPixelFormat;
+ }
+
+ // buffer is now in DEQUEUED (but can also be current at the same time,
+ // if we're in synchronous mode)
+ mSlots[buf].mBufferState = BufferSlot::DEQUEUED;
+
+ const sp<GraphicBuffer>& buffer(mSlots[buf].mGraphicBuffer);
+ if ((buffer == NULL) ||
+ (uint32_t(buffer->width) != w) ||
+ (uint32_t(buffer->height) != h) ||
+ (uint32_t(buffer->format) != format) ||
+ ((uint32_t(buffer->usage) & usage) != usage)) {
+ usage |= GraphicBuffer::USAGE_HW_TEXTURE;
+ status_t error;
+ sp<GraphicBuffer> graphicBuffer(
+ mGraphicBufferAlloc->createGraphicBuffer(
+ w, h, format, usage, &error));
+ if (graphicBuffer == 0) {
+ LOGE("dequeueBuffer: SurfaceComposer::createGraphicBuffer failed");
+ return error;
+ }
+ if (updateFormat) {
+ mPixelFormat = format;
+ }
+ mSlots[buf].mGraphicBuffer = graphicBuffer;
+ mSlots[buf].mRequestBufferCalled = false;
+ returnFlags |= ISurfaceTexture::BUFFER_NEEDS_REALLOCATION;
+ }
+ return returnFlags;
+}
+
+status_t SurfaceMediaSource::setSynchronousMode(bool enabled) {
+ Mutex::Autolock lock(mMutex);
+
+ status_t err = OK;
+ if (!enabled) {
+ // going to asynchronous mode, drain the queue
+ while (mSynchronousMode != enabled && !mQueue.isEmpty()) {
+ mDequeueCondition.wait(mMutex);
+ }
+ }
+
+ if (mSynchronousMode != enabled) {
+ // - if we're going to asynchronous mode, the queue is guaranteed to be
+ // empty here
+ // - if the client set the number of buffers, we're guaranteed that
+ // we have at least 3 (because we don't allow less)
+ mSynchronousMode = enabled;
+ mDequeueCondition.signal();
+ }
+ return err;
+}
+
+status_t SurfaceMediaSource::connect(int api) {
+ LOGV("SurfaceMediaSource::connect");
+ Mutex::Autolock lock(mMutex);
+ status_t err = NO_ERROR;
+ switch (api) {
+ case NATIVE_WINDOW_API_EGL:
+ case NATIVE_WINDOW_API_CPU:
+ case NATIVE_WINDOW_API_MEDIA:
+ case NATIVE_WINDOW_API_CAMERA:
+ if (mConnectedApi != NO_CONNECTED_API) {
+ err = -EINVAL;
+ } else {
+ mConnectedApi = api;
+ }
+ break;
+ default:
+ err = -EINVAL;
+ break;
+ }
+ return err;
+}
+
+status_t SurfaceMediaSource::disconnect(int api) {
+ LOGV("SurfaceMediaSource::disconnect");
+ Mutex::Autolock lock(mMutex);
+ status_t err = NO_ERROR;
+ switch (api) {
+ case NATIVE_WINDOW_API_EGL:
+ case NATIVE_WINDOW_API_CPU:
+ case NATIVE_WINDOW_API_MEDIA:
+ case NATIVE_WINDOW_API_CAMERA:
+ if (mConnectedApi == api) {
+ mConnectedApi = NO_CONNECTED_API;
+ } else {
+ err = -EINVAL;
+ }
+ break;
+ default:
+ err = -EINVAL;
+ break;
+ }
+ return err;
+}
+
+status_t SurfaceMediaSource::queueBuffer(int buf, int64_t timestamp,
+ uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
+ LOGV("queueBuffer");
+
+ Mutex::Autolock lock(mMutex);
+ if (buf < 0 || buf >= mBufferCount) {
+ LOGE("queueBuffer: slot index out of range [0, %d]: %d",
+ mBufferCount, buf);
+ return -EINVAL;
+ } else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
+ LOGE("queueBuffer: slot %d is not owned by the client (state=%d)",
+ buf, mSlots[buf].mBufferState);
+ return -EINVAL;
+ } else if (!mSlots[buf].mRequestBufferCalled) {
+ LOGE("queueBuffer: slot %d was enqueued without requesting a "
+ "buffer", buf);
+ return -EINVAL;
+ }
+
+ if (mSynchronousMode) {
+ // in synchronous mode we queue all buffers in a FIFO
+ mQueue.push_back(buf);
+ LOGV("Client queued buffer on slot: %d, Q size = %d",
+ buf, mQueue.size());
+ } else {
+ // in asynchronous mode we only keep the most recent buffer
+ if (mQueue.empty()) {
+ mQueue.push_back(buf);
+ } else {
+ Fifo::iterator front(mQueue.begin());
+ // buffer currently queued is freed
+ mSlots[*front].mBufferState = BufferSlot::FREE;
+ // and we record the new buffer index in the queued list
+ *front = buf;
+ }
+ }
+
+ mSlots[buf].mBufferState = BufferSlot::QUEUED;
+ mSlots[buf].mTimestamp = timestamp;
+ // TODO: (Confirm) Don't want to signal dequeue here.
+ // May be just in asynchronous mode?
+ // mDequeueCondition.signal();
+
+ // Once the queuing is done, we need to let the listener
+ // and signal the buffer consumer (encoder) know that a
+ // buffer is available
+ onFrameReceivedLocked();
+
+ *outWidth = mDefaultWidth;
+ *outHeight = mDefaultHeight;
+ *outTransform = 0;
+
+ return OK;
+}
+
+
+// onFrameReceivedLocked informs the buffer consumers (StageFrightRecorder)
+// or listeners that a frame has been received
+// It is supposed to be called only from queuebuffer.
+// The buffer is NOT made available for dequeueing immediately. We need to
+// wait to hear from StageFrightRecorder to set the buffer FREE
+// Make sure this is called when the mutex is locked
+status_t SurfaceMediaSource::onFrameReceivedLocked() {
+ LOGV("On Frame Received");
+ // Signal the encoder that a new frame has arrived
+ mFrameAvailableCondition.signal();
+
+ // call back the listener
+ // TODO: The listener may not be needed in SurfaceMediaSource at all.
+ // This can be made a SurfaceTexture specific thing
+ sp<FrameAvailableListener> listener;
+ if (mSynchronousMode || mQueue.empty()) {
+ listener = mFrameAvailableListener;
+ }
+
+ if (listener != 0) {
+ listener->onFrameAvailable();
+ }
+ return OK;
+}
+
+
+void SurfaceMediaSource::cancelBuffer(int buf) {
+ LOGV("SurfaceMediaSource::cancelBuffer");
+ Mutex::Autolock lock(mMutex);
+ if (buf < 0 || buf >= mBufferCount) {
+ LOGE("cancelBuffer: slot index out of range [0, %d]: %d",
+ mBufferCount, buf);
+ return;
+ } else if (mSlots[buf].mBufferState != BufferSlot::DEQUEUED) {
+ LOGE("cancelBuffer: slot %d is not owned by the client (state=%d)",
+ buf, mSlots[buf].mBufferState);
+ return;
+ }
+ mSlots[buf].mBufferState = BufferSlot::FREE;
+ mDequeueCondition.signal();
+}
+
+nsecs_t SurfaceMediaSource::getTimestamp() {
+ LOGV("SurfaceMediaSource::getTimestamp");
+ Mutex::Autolock lock(mMutex);
+ return mCurrentTimestamp;
+}
+
+
+void SurfaceMediaSource::setFrameAvailableListener(
+ const sp<FrameAvailableListener>& listener) {
+ LOGV("SurfaceMediaSource::setFrameAvailableListener");
+ Mutex::Autolock lock(mMutex);
+ mFrameAvailableListener = listener;
+}
+
+void SurfaceMediaSource::freeAllBuffers() {
+ LOGV("freeAllBuffers");
+ for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
+ mSlots[i].mGraphicBuffer = 0;
+ mSlots[i].mBufferState = BufferSlot::FREE;
+ }
+}
+
+sp<GraphicBuffer> SurfaceMediaSource::getCurrentBuffer() const {
+ Mutex::Autolock lock(mMutex);
+ return mCurrentBuf;
+}
+
+int SurfaceMediaSource::query(int what, int* outValue)
+{
+ LOGV("query");
+ Mutex::Autolock lock(mMutex);
+ int value;
+ switch (what) {
+ case NATIVE_WINDOW_WIDTH:
+ value = mDefaultWidth;
+ if (!mDefaultWidth && !mDefaultHeight && mCurrentBuf != 0)
+ value = mCurrentBuf->width;
+ break;
+ case NATIVE_WINDOW_HEIGHT:
+ value = mDefaultHeight;
+ if (!mDefaultWidth && !mDefaultHeight && mCurrentBuf != 0)
+ value = mCurrentBuf->height;
+ break;
+ case NATIVE_WINDOW_FORMAT:
+ value = mPixelFormat;
+ break;
+ case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
+ value = mSynchronousMode ?
+ (MIN_UNDEQUEUED_BUFFERS-1) : MIN_UNDEQUEUED_BUFFERS;
+ break;
+ default:
+ return BAD_VALUE;
+ }
+ outValue[0] = value;
+ return NO_ERROR;
+}
+
+void SurfaceMediaSource::dump(String8& result) const
+{
+ char buffer[1024];
+ dump(result, "", buffer, 1024);
+}
+
+void SurfaceMediaSource::dump(String8& result, const char* prefix,
+ char* buffer, size_t SIZE) const
+{
+ Mutex::Autolock _l(mMutex);
+ snprintf(buffer, SIZE,
+ "%smBufferCount=%d, mSynchronousMode=%d, default-size=[%dx%d], "
+ "mPixelFormat=%d, \n",
+ prefix, mBufferCount, mSynchronousMode, mDefaultWidth, mDefaultHeight,
+ mPixelFormat);
+ result.append(buffer);
+
+ String8 fifo;
+ int fifoSize = 0;
+ Fifo::const_iterator i(mQueue.begin());
+ while (i != mQueue.end()) {
+ snprintf(buffer, SIZE, "%02d ", *i++);
+ fifoSize++;
+ fifo.append(buffer);
+ }
+
+ result.append(buffer);
+
+ struct {
+ const char * operator()(int state) const {
+ switch (state) {
+ case BufferSlot::DEQUEUED: return "DEQUEUED";
+ case BufferSlot::QUEUED: return "QUEUED";
+ case BufferSlot::FREE: return "FREE";
+ default: return "Unknown";
+ }
+ }
+ } stateName;
+
+ for (int i = 0; i < mBufferCount; i++) {
+ const BufferSlot& slot(mSlots[i]);
+ snprintf(buffer, SIZE,
+ "%s%s[%02d] state=%-8s, "
+ "timestamp=%lld\n",
+ prefix, (i==mCurrentSlot)?">":" ", i, stateName(slot.mBufferState),
+ slot.mTimestamp
+ );
+ result.append(buffer);
+ }
+}
+
+status_t SurfaceMediaSource::setFrameRate(int32_t fps)
+{
+ Mutex::Autolock lock(mMutex);
+ const int MAX_FRAME_RATE = 60;
+ if (fps < 0 || fps > MAX_FRAME_RATE) {
+ return BAD_VALUE;
+ }
+ mFrameRate = fps;
+ return OK;
+}
+
+bool SurfaceMediaSource::isMetaDataStoredInVideoBuffers() const {
+ LOGV("isMetaDataStoredInVideoBuffers");
+ return true;
+}
+
+int32_t SurfaceMediaSource::getFrameRate( ) const {
+ Mutex::Autolock lock(mMutex);
+ return mFrameRate;
+}
+
+status_t SurfaceMediaSource::start(MetaData *params)
+{
+ LOGV("start");
+ Mutex::Autolock lock(mMutex);
+ CHECK(!mStarted);
+ mStarted = true;
+ return OK;
+}
+
+
+status_t SurfaceMediaSource::stop()
+{
+ LOGV("Stop");
+
+ Mutex::Autolock lock(mMutex);
+ // TODO: Add waiting on mFrameCompletedCondition here?
+ mStarted = false;
+ mFrameAvailableCondition.signal();
+
+ return OK;
+}
+
+sp<MetaData> SurfaceMediaSource::getFormat()
+{
+ LOGV("getFormat");
+ Mutex::Autolock autoLock(mMutex);
+ sp<MetaData> meta = new MetaData;
+
+ meta->setInt32(kKeyWidth, mDefaultWidth);
+ meta->setInt32(kKeyHeight, mDefaultHeight);
+ // The encoder format is set as an opaque colorformat
+ // The encoder will later find out the actual colorformat
+ // from the GL Frames itself.
+ meta->setInt32(kKeyColorFormat, OMX_COLOR_FormatAndroidOpaque);
+ meta->setInt32(kKeyStride, mDefaultWidth);
+ meta->setInt32(kKeySliceHeight, mDefaultHeight);
+ meta->setInt32(kKeyFrameRate, mFrameRate);
+ meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_RAW);
+ return meta;
+}
+
+status_t SurfaceMediaSource::read( MediaBuffer **buffer,
+ const ReadOptions *options)
+{
+ LOGV("Read. Size of queued buffer: %d", mQueue.size());
+ *buffer = NULL;
+
+ Mutex::Autolock autoLock(mMutex) ;
+ // If the recording has started and the queue is empty, then just
+ // wait here till the frames come in from the client side
+ while (mStarted && mQueue.empty()) {
+ LOGV("NO FRAMES! Recorder waiting for FrameAvailableCondition");
+ mFrameAvailableCondition.wait(mMutex);
+ }
+
+ // If the loop was exited as a result of stopping the recording,
+ // it is OK
+ if (!mStarted) {
+ return OK;
+ }
+
+ // Update the current buffer info
+ // TODO: mCurrentSlot can be made a bufferstate since there
+ // can be more than one "current" slots.
+ Fifo::iterator front(mQueue.begin());
+ mCurrentSlot = *front;
+ mCurrentBuf = mSlots[mCurrentSlot].mGraphicBuffer;
+ mCurrentTimestamp = mSlots[mCurrentSlot].mTimestamp;
+
+ // Pass the data to the MediaBuffer
+ // TODO: Change later to pass in only the metadata
+ *buffer = new MediaBuffer(mCurrentBuf);
+ (*buffer)->setObserver(this);
+ (*buffer)->add_ref();
+ (*buffer)->meta_data()->setInt64(kKeyTime, mCurrentTimestamp);
+
+ return OK;
+}
+
+void SurfaceMediaSource::signalBufferReturned(MediaBuffer *buffer) {
+ LOGV("signalBufferReturned");
+
+ bool foundBuffer = false;
+ Mutex::Autolock autoLock(mMutex);
+
+ if (!mStarted) {
+ LOGV("started = false. Nothing to do");
+ return;
+ }
+
+ for (Fifo::iterator it = mQueue.begin(); it != mQueue.end(); ++it) {
+ if (mSlots[*it].mGraphicBuffer == buffer->graphicBuffer()) {
+ LOGV("Buffer %d returned. Setting it 'FREE'. New Queue size = %d",
+ *it, mQueue.size()-1);
+ mSlots[*it].mBufferState = BufferSlot::FREE;
+ mQueue.erase(it);
+ buffer->setObserver(0);
+ buffer->release();
+ mDequeueCondition.signal();
+ mFrameCompleteCondition.signal();
+ foundBuffer = true;
+ break;
+ }
+ }
+
+ if (!foundBuffer) {
+ CHECK_EQ(0, "signalBufferReturned: bogus buffer");
+ }
+}
+
+
+
+} // end of namespace android
diff --git a/media/libstagefright/WAVExtractor.cpp b/media/libstagefright/WAVExtractor.cpp
index bf978d7..c406964 100644
--- a/media/libstagefright/WAVExtractor.cpp
+++ b/media/libstagefright/WAVExtractor.cpp
@@ -370,7 +370,9 @@ status_t WAVSource::read(
int16_t *dst = (int16_t *)tmp->data();
const uint8_t *src = (const uint8_t *)buffer->data();
- while (n-- > 0) {
+ ssize_t numBytes = n;
+
+ while (numBytes-- > 0) {
*dst++ = ((int16_t)(*src) - 128) * 256;
++src;
}
diff --git a/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp b/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
index 588a74d..07a9eb8 100644
--- a/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
+++ b/media/libstagefright/chromium_http/ChromiumHTTPDataSource.cpp
@@ -25,6 +25,8 @@
#include "support.h"
+#include <cutils/properties.h> // for property_get
+
namespace android {
ChromiumHTTPDataSource::ChromiumHTTPDataSource(uint32_t flags)
@@ -111,7 +113,7 @@ void ChromiumHTTPDataSource::onConnectionFailed(status_t err) {
mState = DISCONNECTED;
mCondition.broadcast();
- mURI.clear();
+ // mURI.clear();
mIOResult = err;
@@ -150,8 +152,18 @@ ssize_t ChromiumHTTPDataSource::readAt(off64_t offset, void *data, size_t size)
Mutex::Autolock autoLock(mLock);
if (mState != CONNECTED) {
- return ERROR_NOT_CONNECTED;
+ return INVALID_OPERATION;
+ }
+
+#if 0
+ char value[PROPERTY_VALUE_MAX];
+ if (property_get("media.stagefright.disable-net", value, 0)
+ && (!strcasecmp(value, "true") || !strcmp(value, "1"))) {
+ LOG_PRI(ANDROID_LOG_INFO, LOG_TAG, "Simulating that the network is down.");
+ disconnect_l();
+ return ERROR_IO;
}
+#endif
if (offset != mCurrentOffset) {
AString tmp = mURI;
@@ -236,7 +248,7 @@ void ChromiumHTTPDataSource::onDisconnectComplete() {
CHECK_EQ((int)mState, (int)DISCONNECTING);
mState = DISCONNECTED;
- mURI.clear();
+ // mURI.clear();
mCondition.broadcast();
@@ -299,5 +311,21 @@ void ChromiumHTTPDataSource::clearDRMState_l() {
}
}
+status_t ChromiumHTTPDataSource::reconnectAtOffset(off64_t offset) {
+ Mutex::Autolock autoLock(mLock);
+
+ if (mURI.empty()) {
+ return INVALID_OPERATION;
+ }
+
+ LOG_PRI(ANDROID_LOG_INFO, LOG_TAG, "Reconnecting...");
+ status_t err = connect_l(mURI.c_str(), &mHeaders, offset);
+ if (err != OK) {
+ LOG_PRI(ANDROID_LOG_INFO, LOG_TAG, "Reconnect failed w/ err 0x%08x", err);
+ }
+
+ return err;
+}
+
} // namespace android
diff --git a/media/libstagefright/include/ChromiumHTTPDataSource.h b/media/libstagefright/include/ChromiumHTTPDataSource.h
index d833e2e..18f8913 100644
--- a/media/libstagefright/include/ChromiumHTTPDataSource.h
+++ b/media/libstagefright/include/ChromiumHTTPDataSource.h
@@ -51,6 +51,8 @@ struct ChromiumHTTPDataSource : public HTTPBase {
virtual String8 getMIMEType() const;
+ virtual status_t reconnectAtOffset(off64_t offset);
+
protected:
virtual ~ChromiumHTTPDataSource();
diff --git a/media/libstagefright/include/NuCachedSource2.h b/media/libstagefright/include/NuCachedSource2.h
index 2d6cb84..22b2855 100644
--- a/media/libstagefright/include/NuCachedSource2.h
+++ b/media/libstagefright/include/NuCachedSource2.h
@@ -77,6 +77,10 @@ private:
kWhatRead = 'read',
};
+ enum {
+ kMaxNumRetries = 10,
+ };
+
sp<DataSource> mSource;
sp<AHandlerReflector<NuCachedSource2> > mReflector;
sp<ALooper> mLooper;
@@ -93,6 +97,8 @@ private:
bool mFetching;
int64_t mLastFetchTimeUs;
+ int32_t mNumRetriesLeft;
+
void onMessageReceived(const sp<AMessage> &msg);
void onFetch();
void onRead(const sp<AMessage> &msg);
diff --git a/media/libstagefright/tests/Android.mk b/media/libstagefright/tests/Android.mk
new file mode 100644
index 0000000..3ea8f39
--- /dev/null
+++ b/media/libstagefright/tests/Android.mk
@@ -0,0 +1,53 @@
+# Build the unit tests.
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+ifneq ($(TARGET_SIMULATOR),true)
+
+LOCAL_MODULE := SurfaceMediaSource_test
+
+LOCAL_MODULE_TAGS := tests
+
+LOCAL_SRC_FILES := \
+ SurfaceMediaSource_test.cpp \
+ DummyRecorder.cpp \
+
+LOCAL_SHARED_LIBRARIES := \
+ libEGL \
+ libGLESv2 \
+ libandroid \
+ libbinder \
+ libcutils \
+ libgui \
+ libstlport \
+ libui \
+ libutils \
+ libstagefright \
+ libstagefright_omx \
+ libstagefright_foundation \
+
+LOCAL_STATIC_LIBRARIES := \
+ libgtest \
+ libgtest_main \
+
+LOCAL_C_INCLUDES := \
+ bionic \
+ bionic/libstdc++/include \
+ external/gtest/include \
+ external/stlport/stlport \
+ frameworks/base/media/libstagefright \
+ frameworks/base/media/libstagefright/include \
+ $(TOP)/frameworks/base/include/media/stagefright/openmax \
+
+include $(BUILD_EXECUTABLE)
+
+endif
+
+# Include subdirectory makefiles
+# ============================================================
+
+# If we're building with ONE_SHOT_MAKEFILE (mm, mmm), then what the framework
+# team really wants is to build the stuff defined by this makefile.
+ifeq (,$(ONE_SHOT_MAKEFILE))
+include $(call first-makefiles-under,$(LOCAL_PATH))
+endif
diff --git a/media/libstagefright/tests/DummyRecorder.cpp b/media/libstagefright/tests/DummyRecorder.cpp
new file mode 100644
index 0000000..8d75d6b
--- /dev/null
+++ b/media/libstagefright/tests/DummyRecorder.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "DummyRecorder"
+// #define LOG_NDEBUG 0
+
+#include <media/stagefright/MediaBuffer.h>
+#include <media/stagefright/MediaSource.h>
+#include "DummyRecorder.h"
+
+#include <utils/Log.h>
+
+namespace android {
+
+// static
+void *DummyRecorder::threadWrapper(void *pthis) {
+ LOGV("ThreadWrapper: %p", pthis);
+ DummyRecorder *writer = static_cast<DummyRecorder *>(pthis);
+ writer->readFromSource();
+ return NULL;
+}
+
+
+status_t DummyRecorder::start() {
+ LOGV("Start");
+ mStarted = true;
+
+ mSource->start();
+
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+ int err = pthread_create(&mThread, &attr, threadWrapper, this);
+ pthread_attr_destroy(&attr);
+
+ if (err) {
+ LOGE("Error creating thread!");
+ return -ENODEV;
+ }
+ return OK;
+}
+
+
+status_t DummyRecorder::stop() {
+ LOGV("Stop");
+ mStarted = false;
+
+ mSource->stop();
+ void *dummy;
+ pthread_join(mThread, &dummy);
+ status_t err = (status_t) dummy;
+
+ LOGV("Ending the reading thread");
+ return err;
+}
+
+// pretend to read the source buffers
+void DummyRecorder::readFromSource() {
+ LOGV("ReadFromSource");
+ if (!mStarted) {
+ return;
+ }
+
+ status_t err = OK;
+ MediaBuffer *buffer;
+ LOGV("A fake writer accessing the frames");
+ while (mStarted && (err = mSource->read(&buffer)) == OK){
+ // if not getting a valid buffer from source, then exit
+ if (buffer == NULL) {
+ return;
+ }
+ buffer->release();
+ buffer = NULL;
+ }
+}
+
+
+} // end of namespace android
diff --git a/media/libstagefright/tests/DummyRecorder.h b/media/libstagefright/tests/DummyRecorder.h
new file mode 100644
index 0000000..1cbea1b
--- /dev/null
+++ b/media/libstagefright/tests/DummyRecorder.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef DUMMY_RECORDER_H_
+#define DUMMY_RECORDER_H_
+
+#include <pthread.h>
+#include <utils/String8.h>
+#include <media/stagefright/foundation/ABase.h>
+
+
+namespace android {
+
+class MediaSource;
+class MediaBuffer;
+
+class DummyRecorder {
+ public:
+ // The media source from which this will receive frames
+ sp<MediaSource> mSource;
+ bool mStarted;
+ pthread_t mThread;
+
+ status_t start();
+ status_t stop();
+
+ // actual entry point for the thread
+ void readFromSource();
+
+ // static function to wrap the actual thread entry point
+ static void *threadWrapper(void *pthis);
+
+ DummyRecorder(const sp<MediaSource> &source) : mSource(source)
+ , mStarted(false) {}
+ ~DummyRecorder( ) {}
+
+ private:
+
+ DISALLOW_EVIL_CONSTRUCTORS(DummyRecorder);
+};
+
+} // end of namespace android
+#endif
+
+
diff --git a/media/libstagefright/tests/SurfaceMediaSource_test.cpp b/media/libstagefright/tests/SurfaceMediaSource_test.cpp
new file mode 100644
index 0000000..ce10812
--- /dev/null
+++ b/media/libstagefright/tests/SurfaceMediaSource_test.cpp
@@ -0,0 +1,349 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "SurfaceMediaSource_test"
+// #define LOG_NDEBUG 0
+
+#include <gtest/gtest.h>
+#include <utils/String8.h>
+#include <utils/Errors.h>
+
+#include <media/stagefright/SurfaceMediaSource.h>
+
+#include <gui/SurfaceTextureClient.h>
+#include <ui/GraphicBuffer.h>
+#include <surfaceflinger/ISurfaceComposer.h>
+#include <surfaceflinger/Surface.h>
+#include <surfaceflinger/SurfaceComposerClient.h>
+
+#include <binder/ProcessState.h>
+#include <ui/FramebufferNativeWindow.h>
+
+#include <media/stagefright/MediaDebug.h>
+#include <media/stagefright/MediaDefs.h>
+#include <media/stagefright/MetaData.h>
+#include <media/stagefright/MPEG4Writer.h>
+#include <media/stagefright/OMXClient.h>
+#include <media/stagefright/OMXCodec.h>
+#include <OMX_Component.h>
+
+#include "DummyRecorder.h"
+
+namespace android {
+
+
+class SurfaceMediaSourceTest : public ::testing::Test {
+public:
+
+ SurfaceMediaSourceTest( ): mYuvTexWidth(64), mYuvTexHeight(66) { }
+ sp<MPEG4Writer> setUpWriter(OMXClient &client );
+ void oneBufferPass(int width, int height );
+ static void fillYV12Buffer(uint8_t* buf, int w, int h, int stride) ;
+ static void fillYV12BufferRect(uint8_t* buf, int w, int h,
+ int stride, const android_native_rect_t& rect) ;
+protected:
+
+ virtual void SetUp() {
+ mSMS = new SurfaceMediaSource(mYuvTexWidth, mYuvTexHeight);
+ mSMS->setSynchronousMode(true);
+ mSTC = new SurfaceTextureClient(mSMS);
+ mANW = mSTC;
+
+ }
+
+
+ virtual void TearDown() {
+ mSMS.clear();
+ mSTC.clear();
+ mANW.clear();
+ }
+
+ const int mYuvTexWidth;// = 64;
+ const int mYuvTexHeight;// = 66;
+
+ sp<SurfaceMediaSource> mSMS;
+ sp<SurfaceTextureClient> mSTC;
+ sp<ANativeWindow> mANW;
+
+};
+
+void SurfaceMediaSourceTest::oneBufferPass(int width, int height ) {
+ LOGV("One Buffer Pass");
+ ANativeWindowBuffer* anb;
+ ASSERT_EQ(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
+ ASSERT_TRUE(anb != NULL);
+
+ sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
+ ASSERT_EQ(NO_ERROR, mANW->lockBuffer(mANW.get(), buf->getNativeBuffer()));
+
+ // Fill the buffer with the a checkerboard pattern
+ uint8_t* img = NULL;
+ buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
+ SurfaceMediaSourceTest::fillYV12Buffer(img, width, height, buf->getStride());
+ buf->unlock();
+
+ ASSERT_EQ(NO_ERROR, mANW->queueBuffer(mANW.get(), buf->getNativeBuffer()));
+}
+
+sp<MPEG4Writer> SurfaceMediaSourceTest::setUpWriter(OMXClient &client ) {
+ // Writing to a file
+ const char *fileName = "/sdcard/outputSurfEnc.mp4";
+ sp<MetaData> enc_meta = new MetaData;
+ enc_meta->setInt32(kKeyBitRate, 300000);
+ enc_meta->setInt32(kKeyFrameRate, 30);
+
+ enc_meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_MPEG4);
+
+ sp<MetaData> meta = mSMS->getFormat();
+
+ int32_t width, height, stride, sliceHeight, colorFormat;
+ CHECK(meta->findInt32(kKeyWidth, &width));
+ CHECK(meta->findInt32(kKeyHeight, &height));
+ CHECK(meta->findInt32(kKeyStride, &stride));
+ CHECK(meta->findInt32(kKeySliceHeight, &sliceHeight));
+ CHECK(meta->findInt32(kKeyColorFormat, &colorFormat));
+
+ enc_meta->setInt32(kKeyWidth, width);
+ enc_meta->setInt32(kKeyHeight, height);
+ enc_meta->setInt32(kKeyIFramesInterval, 1);
+ enc_meta->setInt32(kKeyStride, stride);
+ enc_meta->setInt32(kKeySliceHeight, sliceHeight);
+ // TODO: overwriting the colorformat since the format set by GRAlloc
+ // could be wrong or not be read by OMX
+ enc_meta->setInt32(kKeyColorFormat, OMX_COLOR_FormatYUV420Planar);
+ // colorFormat);
+
+
+ sp<MediaSource> encoder =
+ OMXCodec::Create(
+ client.interface(), enc_meta, true /* createEncoder */, mSMS);
+
+ sp<MPEG4Writer> writer = new MPEG4Writer(fileName);
+ writer->addSource(encoder);
+
+ return writer;
+}
+
+// Fill a YV12 buffer with a multi-colored checkerboard pattern
+void SurfaceMediaSourceTest::fillYV12Buffer(uint8_t* buf, int w, int h, int stride) {
+ const int blockWidth = w > 16 ? w / 16 : 1;
+ const int blockHeight = h > 16 ? h / 16 : 1;
+ const int yuvTexOffsetY = 0;
+ int yuvTexStrideY = stride;
+ int yuvTexOffsetV = yuvTexStrideY * h;
+ int yuvTexStrideV = (yuvTexStrideY/2 + 0xf) & ~0xf;
+ int yuvTexOffsetU = yuvTexOffsetV + yuvTexStrideV * h/2;
+ int yuvTexStrideU = yuvTexStrideV;
+ for (int x = 0; x < w; x++) {
+ for (int y = 0; y < h; y++) {
+ int parityX = (x / blockWidth) & 1;
+ int parityY = (y / blockHeight) & 1;
+ unsigned char intensity = (parityX ^ parityY) ? 63 : 191;
+ buf[yuvTexOffsetY + (y * yuvTexStrideY) + x] = intensity;
+ if (x < w / 2 && y < h / 2) {
+ buf[yuvTexOffsetU + (y * yuvTexStrideU) + x] = intensity;
+ if (x * 2 < w / 2 && y * 2 < h / 2) {
+ buf[yuvTexOffsetV + (y*2 * yuvTexStrideV) + x*2 + 0] =
+ buf[yuvTexOffsetV + (y*2 * yuvTexStrideV) + x*2 + 1] =
+ buf[yuvTexOffsetV + ((y*2+1) * yuvTexStrideV) + x*2 + 0] =
+ buf[yuvTexOffsetV + ((y*2+1) * yuvTexStrideV) + x*2 + 1] =
+ intensity;
+ }
+ }
+ }
+ }
+}
+
+// Fill a YV12 buffer with red outside a given rectangle and green inside it.
+void SurfaceMediaSourceTest::fillYV12BufferRect(uint8_t* buf, int w,
+ int h, int stride, const android_native_rect_t& rect) {
+ const int yuvTexOffsetY = 0;
+ int yuvTexStrideY = stride;
+ int yuvTexOffsetV = yuvTexStrideY * h;
+ int yuvTexStrideV = (yuvTexStrideY/2 + 0xf) & ~0xf;
+ int yuvTexOffsetU = yuvTexOffsetV + yuvTexStrideV * h/2;
+ int yuvTexStrideU = yuvTexStrideV;
+ for (int x = 0; x < w; x++) {
+ for (int y = 0; y < h; y++) {
+ bool inside = rect.left <= x && x < rect.right &&
+ rect.top <= y && y < rect.bottom;
+ buf[yuvTexOffsetY + (y * yuvTexStrideY) + x] = inside ? 240 : 64;
+ if (x < w / 2 && y < h / 2) {
+ bool inside = rect.left <= 2*x && 2*x < rect.right &&
+ rect.top <= 2*y && 2*y < rect.bottom;
+ buf[yuvTexOffsetU + (y * yuvTexStrideU) + x] = 16;
+ buf[yuvTexOffsetV + (y * yuvTexStrideV) + x] =
+ inside ? 16 : 255;
+ }
+ }
+ }
+} ///////// End of class SurfaceMediaSourceTest
+
+///////////////////////////////////////////////////////////////////
+// Class to imitate the recording /////////////////////////////
+// ////////////////////////////////////////////////////////////////
+struct SimpleDummyRecorder {
+ sp<MediaSource> mSource;
+
+ SimpleDummyRecorder
+ (const sp<MediaSource> &source): mSource(source) {}
+
+ status_t start() { return mSource->start();}
+ status_t stop() { return mSource->stop();}
+
+ // fakes reading from a media source
+ status_t readFromSource() {
+ MediaBuffer *buffer;
+ status_t err = mSource->read(&buffer);
+ if (err != OK) {
+ return err;
+ }
+ buffer->release();
+ buffer = NULL;
+ return OK;
+ }
+};
+
+///////////////////////////////////////////////////////////////////
+// TESTS
+// Just pass one buffer from the native_window to the SurfaceMediaSource
+TEST_F(SurfaceMediaSourceTest, EncodingFromCpuFilledYV12BufferNpotOneBufferPass) {
+ LOGV("Testing OneBufferPass ******************************");
+
+ ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+ 0, 0, HAL_PIXEL_FORMAT_YV12));
+ // OMX_COLOR_FormatYUV420Planar)); // ));
+ ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ oneBufferPass(mYuvTexWidth, mYuvTexHeight);
+}
+
+// Pass the buffer with the wrong height and weight and should not be accepted
+TEST_F(SurfaceMediaSourceTest, EncodingFromCpuFilledYV12BufferNpotWrongSizeBufferPass) {
+ LOGV("Testing Wrong size BufferPass ******************************");
+
+ // setting the client side buffer size different than the server size
+ ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+ 10, 10, HAL_PIXEL_FORMAT_YV12));
+ // OMX_COLOR_FormatYUV420Planar)); // ));
+ ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ ANativeWindowBuffer* anb;
+
+ // make sure we get an error back when dequeuing!
+ ASSERT_NE(NO_ERROR, mANW->dequeueBuffer(mANW.get(), &anb));
+}
+
+
+// pass multiple buffers from the native_window the SurfaceMediaSource
+// A dummy writer is used to simulate actual MPEG4Writer
+TEST_F(SurfaceMediaSourceTest, EncodingFromCpuFilledYV12BufferNpotMultiBufferPass) {
+ LOGV("Testing MultiBufferPass, Dummy Recorder *********************");
+ ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+ 0, 0, HAL_PIXEL_FORMAT_YV12));
+ ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+ SimpleDummyRecorder writer(mSMS);
+ writer.start();
+
+ int32_t nFramesCount = 0;
+ while (nFramesCount < 300) {
+ oneBufferPass(mYuvTexWidth, mYuvTexHeight);
+
+ ASSERT_EQ(NO_ERROR, writer.readFromSource());
+
+ nFramesCount++;
+ }
+ writer.stop();
+}
+
+// Delayed pass of multiple buffers from the native_window the SurfaceMediaSource
+// A dummy writer is used to simulate actual MPEG4Writer
+TEST_F(SurfaceMediaSourceTest, EncodingFromCpuFilledYV12BufferNpotMultiBufferPassLag) {
+ LOGV("Testing MultiBufferPass, Dummy Recorder Lagging **************");
+ ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+ 0, 0, HAL_PIXEL_FORMAT_YV12));
+ ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+ SimpleDummyRecorder writer(mSMS);
+ writer.start();
+
+ int32_t nFramesCount = 1;
+ const int FRAMES_LAG = mSMS->getBufferCount() - 1;
+ while (nFramesCount <= 300) {
+ oneBufferPass(mYuvTexWidth, mYuvTexHeight);
+ // Forcing the writer to lag behind a few frames
+ if (nFramesCount > FRAMES_LAG) {
+ ASSERT_EQ(NO_ERROR, writer.readFromSource());
+ }
+ nFramesCount++;
+ }
+ writer.stop();
+}
+
+// pass multiple buffers from the native_window the SurfaceMediaSource
+// A dummy writer (MULTITHREADED) is used to simulate actual MPEG4Writer
+TEST_F(SurfaceMediaSourceTest, EncodingFromCpuFilledYV12BufferNpotMultiBufferPassThreaded) {
+ LOGV("Testing MultiBufferPass, Dummy Recorder Multi-Threaded **********");
+ ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+ 0, 0, HAL_PIXEL_FORMAT_YV12));
+ ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ DummyRecorder writer(mSMS);
+ writer.start();
+
+ int32_t nFramesCount = 0;
+ while (nFramesCount <= 300) {
+ oneBufferPass(mYuvTexWidth, mYuvTexHeight);
+
+ nFramesCount++;
+ }
+ writer.stop();
+}
+
+// Test to examine the actual encoding. Temporarily disabled till the
+// colorformat and encoding from GRAlloc data is resolved
+TEST_F(SurfaceMediaSourceTest, DISABLED_EncodingFromCpuFilledYV12BufferNpotWrite) {
+ LOGV("Testing the whole pipeline with actual Recorder");
+ ASSERT_EQ(NO_ERROR, native_window_set_buffers_geometry(mANW.get(),
+ 0, 0, HAL_PIXEL_FORMAT_YV12)); // OMX_COLOR_FormatYUV420Planar)); // ));
+ ASSERT_EQ(NO_ERROR, native_window_set_usage(mANW.get(),
+ GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN));
+
+ OMXClient client;
+ CHECK_EQ(OK, client.connect());
+
+ sp<MPEG4Writer> writer = setUpWriter(client);
+ int64_t start = systemTime();
+ CHECK_EQ(OK, writer->start());
+
+ int32_t nFramesCount = 0;
+ while (nFramesCount <= 300) {
+ oneBufferPass(mYuvTexWidth, mYuvTexHeight);
+ nFramesCount++;
+ }
+
+ CHECK_EQ(OK, writer->stop());
+ writer.clear();
+ int64_t end = systemTime();
+ client.disconnect();
+}
+
+
+} // namespace android
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 5298f2e..d7d7817 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -34,7 +34,7 @@
<string name="config_systemBarComponent" translatable="false">com.android.systemui.statusbar.tablet.TabletStatusBar</string>
<!-- Whether or not we show the number in the bar. -->
- <bool name="config_statusBarShowNumber">true</bool>
+ <bool name="config_statusBarShowNumber">false</bool>
<!-- How many icons may be shown at once in the system bar. Includes any
slots that may be reused for things like IME control. -->
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 082dab3..fc8ab96 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -158,7 +158,7 @@
<!-- Checkbox label for application compatibility mode OFF (normal mode on tablets).
[CHAR LIMIT=25] -->
<string name="compat_mode_off">Stretch to fill screen</string>
-
+
<!-- Compatibility mode help screen: header text. [CHAR LIMIT=50] -->
<string name="compat_mode_help_header">Compatibility Zoom</string>
@@ -168,7 +168,7 @@
<!-- toast message displayed when a screenshot is saved to the Gallery. -->
<string name="screenshot_saving_toast">Screenshot saved to Gallery</string>
<!-- toast message displayed when we fail to take a screenshot. -->
- <string name="screenshot_failed_toast">Could not save screenshot</string>
+ <string name="screenshot_failed_toast">Could not save screenshot. External storage may be in use.</string>
<!-- Title for the USB function chooser in UsbPreferenceActivity. [CHAR LIMIT=30] -->
<string name="usb_preference_title">USB file transfer options</string>
@@ -299,5 +299,4 @@
<!-- Content description of the ringer silent icon in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
<string name="accessibility_ringer_silent">Ringer silent.</string>
-
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
index 83a5578..02a955b 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
@@ -87,7 +87,7 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
Context context = params[0].context;
Bitmap image = params[0].image;
- try{
+ try {
long currentTime = System.currentTimeMillis();
String date = new SimpleDateFormat("MM-dd-yy-kk-mm-ss").format(new Date(currentTime));
String imageDir = Environment.getExternalStoragePublicDirectory(
@@ -114,7 +114,9 @@ class SaveImageInBackgroundTask extends AsyncTask<SaveImageInBackgroundData, Voi
out.close();
params[0].result = 0;
- }catch(IOException e){
+ } catch (Exception e) {
+ // IOException/UnsupportedOperationException may be thrown if external storage is not
+ // mounted
params[0].result = 1;
}
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index e0debf7..bfc3cdd 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -2040,13 +2040,14 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
mActionModePopup = new PopupWindow(mContext, null,
com.android.internal.R.attr.actionModePopupWindowStyle);
mActionModePopup.setLayoutInScreenEnabled(true);
+ mActionModePopup.setLayoutInsetDecor(true);
mActionModePopup.setClippingEnabled(false);
mActionModePopup.setContentView(mActionModeView);
mActionModePopup.setWidth(MATCH_PARENT);
TypedValue heightValue = new TypedValue();
mContext.getTheme().resolveAttribute(
- com.android.internal.R.attr.actionBarSize, heightValue, false);
+ com.android.internal.R.attr.actionBarSize, heightValue, true);
final int height = TypedValue.complexToDimensionPixelSize(heightValue.data,
mContext.getResources().getDisplayMetrics());
mActionModePopup.setHeight(height);
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index ae13ab5..b7f6adf 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -2444,20 +2444,22 @@ public class PhoneWindowManager implements WindowManagerPolicy {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (down) {
- // If the power key down was already triggered, take the screenshot
- if (mPowerDownTriggered) {
- // Dismiss the power-key longpress
- mHandler.removeCallbacks(mPowerLongPress);
- mPowerKeyHandled = true;
-
- // Take the screenshot
- takeScreenshot();
-
- // Prevent the event from being passed through to the current activity
- result &= ~ACTION_PASS_TO_USER;
- break;
+ if (isScreenOn) {
+ // If the power key down was already triggered, take the screenshot
+ if (mPowerDownTriggered) {
+ // Dismiss the power-key longpress
+ mHandler.removeCallbacks(mPowerLongPress);
+ mPowerKeyHandled = true;
+
+ // Take the screenshot
+ takeScreenshot();
+
+ // Prevent the event from being passed through to the current activity
+ result &= ~ACTION_PASS_TO_USER;
+ break;
+ }
+ mVolumeDownTriggered = true;
}
- mVolumeDownTriggered = true;
} else {
mVolumeDownTriggered = false;
}
@@ -2541,17 +2543,18 @@ public class PhoneWindowManager implements WindowManagerPolicy {
case KeyEvent.KEYCODE_POWER: {
result &= ~ACTION_PASS_TO_USER;
if (down) {
- // If the volume down key has been triggered, then just take the screenshot
- if (mVolumeDownTriggered) {
- // Take the screenshot
- takeScreenshot();
- mPowerKeyHandled = true;
-
- // Prevent the event from being passed through to the current activity
- break;
+ if (isScreenOn) {
+ // If the volume down key has been triggered, then just take the screenshot
+ if (mVolumeDownTriggered) {
+ // Take the screenshot
+ takeScreenshot();
+ mPowerKeyHandled = true;
+
+ // Prevent the event from being passed through to the current activity
+ break;
+ }
+ mPowerDownTriggered = true;
}
- mPowerDownTriggered = true;
-
ITelephony telephonyService = getTelephonyService();
boolean hungUp = false;
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 482336b..cb1f921 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1043,6 +1043,25 @@ status_t AudioFlinger::ThreadBase::dumpBase(int fd, const Vector<String16>& args
return NO_ERROR;
}
+status_t AudioFlinger::ThreadBase::dumpEffectChains(int fd, const Vector<String16>& args)
+{
+ const size_t SIZE = 256;
+ char buffer[SIZE];
+ String8 result;
+
+ snprintf(buffer, SIZE, "\n- %d Effect Chains:\n", mEffectChains.size());
+ write(fd, buffer, strlen(buffer));
+
+ for (size_t i = 0; i < mEffectChains.size(); ++i) {
+ sp<EffectChain> chain = mEffectChains[i];
+ if (chain != 0) {
+ chain->dump(fd, args);
+ }
+ }
+ return NO_ERROR;
+}
+
+
// ----------------------------------------------------------------------------
AudioFlinger::PlaybackThread::PlaybackThread(const sp<AudioFlinger>& audioFlinger,
@@ -1111,24 +1130,6 @@ status_t AudioFlinger::PlaybackThread::dumpTracks(int fd, const Vector<String16>
return NO_ERROR;
}
-status_t AudioFlinger::PlaybackThread::dumpEffectChains(int fd, const Vector<String16>& args)
-{
- const size_t SIZE = 256;
- char buffer[SIZE];
- String8 result;
-
- snprintf(buffer, SIZE, "\n- %d Effect Chains:\n", mEffectChains.size());
- write(fd, buffer, strlen(buffer));
-
- for (size_t i = 0; i < mEffectChains.size(); ++i) {
- sp<EffectChain> chain = mEffectChains[i];
- if (chain != 0) {
- chain->dump(fd, args);
- }
- }
- return NO_ERROR;
-}
-
status_t AudioFlinger::PlaybackThread::dumpInternals(int fd, const Vector<String16>& args)
{
const size_t SIZE = 256;
@@ -2954,7 +2955,7 @@ AudioFlinger::PlaybackThread::Track::Track(
mStreamType = streamType;
// NOTE: audio_track_cblk_t::frameSize for 8 bit PCM data is based on a sample size of
// 16 bit because data is converted to 16 bit before being stored in buffer by AudioTrack
- mCblk->frameSize = audio_is_linear_pcm(format) ? mChannelCount * audio_bytes_per_sample(format) : sizeof(uint8_t);
+ mCblk->frameSize = audio_is_linear_pcm(format) ? mChannelCount * sizeof(int16_t) : sizeof(uint8_t);
}
}
@@ -4178,6 +4179,7 @@ status_t AudioFlinger::RecordThread::dump(int fd, const Vector<String16>& args)
write(fd, result.string(), result.size());
dumpBase(fd, args);
+ dumpEffectChains(fd, args);
return NO_ERROR;
}
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index fff4f06..e2cf946 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -285,6 +285,7 @@ private:
};
status_t dumpBase(int fd, const Vector<String16>& args);
+ status_t dumpEffectChains(int fd, const Vector<String16>& args);
// base for record and playback
class TrackBase : public AudioBufferProvider, public RefBase {
@@ -724,7 +725,6 @@ private:
virtual status_t dumpInternals(int fd, const Vector<String16>& args);
status_t dumpTracks(int fd, const Vector<String16>& args);
- status_t dumpEffectChains(int fd, const Vector<String16>& args);
SortedVector< sp<Track> > mTracks;
// mStreamTypes[] uses 1 additionnal stream type internally for the OutputTrack used by DuplicatingThread
diff --git a/services/java/com/android/server/AppWidgetService.java b/services/java/com/android/server/AppWidgetService.java
index 438883e..a679ca7 100644
--- a/services/java/com/android/server/AppWidgetService.java
+++ b/services/java/com/android/server/AppWidgetService.java
@@ -230,8 +230,14 @@ class AppWidgetService extends IAppWidgetService.Stub
pw.println(':');
pw.print(" min=("); pw.print(info.minWidth);
pw.print("x"); pw.print(info.minHeight);
+ pw.print(") minResize=("); pw.print(info.minResizeWidth);
+ pw.print("x"); pw.print(info.minResizeHeight);
pw.print(") updatePeriodMillis=");
pw.print(info.updatePeriodMillis);
+ pw.print(" resizeMode=");
+ pw.print(info.resizeMode);
+ pw.print(" autoAdvanceViewId=");
+ pw.print(info.autoAdvanceViewId);
pw.print(" initialLayout=#");
pw.print(Integer.toHexString(info.initialLayout));
pw.print(" zombie="); pw.println(p.zombie);
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 5dd3a6a..79c0675 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -1090,7 +1090,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
try {
InetAddress addr = InetAddress.getByAddress(hostAddress);
LinkProperties lp = tracker.getLinkProperties();
- return addRoute(lp, RouteInfo.makeHostRoute(addr));
+ return addRouteToAddress(lp, addr);
} catch (UnknownHostException e) {}
return false;
}
@@ -1103,6 +1103,31 @@ public class ConnectivityService extends IConnectivityManager.Stub {
return modifyRoute(p.getInterfaceName(), p, r, 0, false);
}
+ private boolean addRouteToAddress(LinkProperties lp, InetAddress addr) {
+ return modifyRouteToAddress(lp, addr, true);
+ }
+
+ private boolean removeRouteToAddress(LinkProperties lp, InetAddress addr) {
+ return modifyRouteToAddress(lp, addr, false);
+ }
+
+ private boolean modifyRouteToAddress(LinkProperties lp, InetAddress addr, boolean doAdd) {
+ RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getRoutes(), addr);
+ if (bestRoute == null) {
+ bestRoute = RouteInfo.makeHostRoute(addr);
+ } else {
+ if (bestRoute.getGateway().equals(addr)) {
+ // if there is no better route, add the implied hostroute for our gateway
+ bestRoute = RouteInfo.makeHostRoute(addr);
+ } else {
+ // if we will connect to this through another route, add a direct route
+ // to it's gateway
+ bestRoute = RouteInfo.makeHostRoute(addr, bestRoute.getGateway());
+ }
+ }
+ return modifyRoute(lp.getInterfaceName(), lp, bestRoute, 0, doAdd);
+ }
+
private boolean modifyRoute(String ifaceName, LinkProperties lp, RouteInfo r, int cycleCount,
boolean doAdd) {
if ((ifaceName == null) || (lp == null) || (r == null)) return false;
@@ -1713,49 +1738,50 @@ public class ConnectivityService extends IConnectivityManager.Stub {
*/
private void updateRoutes(LinkProperties newLp, LinkProperties curLp, boolean isLinkDefault) {
Collection<RouteInfo> routesToAdd = null;
- CompareResult<InetAddress> dnsDiff = null;
-
+ CompareResult<InetAddress> dnsDiff = new CompareResult<InetAddress>();
+ CompareResult<RouteInfo> routeDiff = new CompareResult<RouteInfo>();
if (curLp != null) {
// check for the delta between the current set and the new
- CompareResult<RouteInfo> routeDiff = curLp.compareRoutes(newLp);
+ routeDiff = curLp.compareRoutes(newLp);
dnsDiff = curLp.compareDnses(newLp);
-
- for (RouteInfo r : routeDiff.removed) {
- if (isLinkDefault || ! r.isDefaultRoute()) {
- removeRoute(curLp, r);
- }
- }
- routesToAdd = routeDiff.added;
+ } else if (newLp != null) {
+ routeDiff.added = newLp.getRoutes();
+ dnsDiff.added = newLp.getDnses();
}
- if (newLp != null) {
- // if we didn't get a diff from cur -> new, then just use the new
- if (routesToAdd == null) {
- routesToAdd = newLp.getRoutes();
+ for (RouteInfo r : routeDiff.removed) {
+ if (isLinkDefault || ! r.isDefaultRoute()) {
+ removeRoute(curLp, r);
}
+ }
- for (RouteInfo r : routesToAdd) {
- if (isLinkDefault || ! r.isDefaultRoute()) {
- addRoute(newLp, r);
- }
+ for (RouteInfo r : routeDiff.added) {
+ if (isLinkDefault || ! r.isDefaultRoute()) {
+ addRoute(newLp, r);
}
}
if (!isLinkDefault) {
// handle DNS routes
- Collection<InetAddress> dnsToAdd = null;
- if (dnsDiff != null) {
- dnsToAdd = dnsDiff.added;
- for (InetAddress dnsAddress : dnsDiff.removed) {
- removeRoute(curLp, RouteInfo.makeHostRoute(dnsAddress));
+ if (routeDiff.removed.size() == 0 && routeDiff.added.size() == 0) {
+ // no change in routes, check for change in dns themselves
+ for (InetAddress oldDns : dnsDiff.removed) {
+ removeRouteToAddress(curLp, oldDns);
}
- }
- if (newLp != null) {
- if (dnsToAdd == null) {
- dnsToAdd = newLp.getDnses();
+ for (InetAddress newDns : dnsDiff.added) {
+ addRouteToAddress(newLp, newDns);
}
- for(InetAddress dnsAddress : dnsToAdd) {
- addRoute(newLp, RouteInfo.makeHostRoute(dnsAddress));
+ } else {
+ // routes changed - remove all old dns entries and add new
+ if (curLp != null) {
+ for (InetAddress oldDns : curLp.getDnses()) {
+ removeRouteToAddress(curLp, oldDns);
+ }
+ }
+ if (newLp != null) {
+ for (InetAddress newDns : newLp.getDnses()) {
+ addRouteToAddress(newLp, newDns);
+ }
}
}
}
@@ -2236,6 +2262,15 @@ public class ConnectivityService extends IConnectivityManager.Stub {
}
}
+ public int setUsbTethering(boolean enable) {
+ enforceTetherAccessPermission();
+ if (isTetheringSupported()) {
+ return mTethering.setUsbTethering(enable);
+ } else {
+ return ConnectivityManager.TETHER_ERROR_UNSUPPORTED;
+ }
+ }
+
// TODO - move iface listing, queries, etc to new module
// javadoc from interface
public String[] getTetherableIfaces() {
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index 7399679..73d790a 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -166,7 +166,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
private final KeyguardManager mKeyguardManager;
private final Notification mImeSwitcherNotification;
private final PendingIntent mImeSwitchPendingIntent;
- private final boolean mShowOngoingImeSwitcherForPhones;
+ private boolean mShowOngoingImeSwitcherForPhones;
private boolean mNotificationShown;
class SessionState {
@@ -538,8 +538,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
mImeSwitcherNotification.vibrate = null;
Intent intent = new Intent(Settings.ACTION_SHOW_INPUT_METHOD_PICKER);
mImeSwitchPendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
- mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
- com.android.internal.R.bool.show_ongoing_ime_switcher);
+
+ mShowOngoingImeSwitcherForPhones = false;
synchronized (mMethodMap) {
mFileManager = new InputMethodFileManager(mMethodMap);
@@ -612,6 +612,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
synchronized (mMethodMap) {
if (!mSystemReady) {
mSystemReady = true;
+ mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
+ com.android.internal.R.bool.show_ongoing_ime_switcher);
try {
startInputInnerLocked();
} catch (RuntimeException e) {
@@ -1125,13 +1127,21 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
mBackDisposition = backDisposition;
mStatusBar.setImeWindowStatus(token, vis, backDisposition);
final boolean iconVisibility = (vis & InputMethodService.IME_ACTIVE) != 0;
- if (iconVisibility && needsToShowImeSwitchOngoingNotification()) {
+ final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
+ if (imi != null && iconVisibility && needsToShowImeSwitchOngoingNotification()) {
final PackageManager pm = mContext.getPackageManager();
- final CharSequence label = mMethodMap.get(mCurMethodId).loadLabel(pm);
final CharSequence title = mRes.getText(
com.android.internal.R.string.select_input_method);
+ final CharSequence imiLabel = imi.loadLabel(pm);
+ final CharSequence summary = mCurrentSubtype != null
+ ? TextUtils.concat(mCurrentSubtype.getDisplayName(mContext,
+ imi.getPackageName(), imi.getServiceInfo().applicationInfo),
+ (TextUtils.isEmpty(imiLabel) ?
+ "" : " (" + imiLabel + ")"))
+ : imiLabel;
+
mImeSwitcherNotification.setLatestEventInfo(
- mContext, title, label, mImeSwitchPendingIntent);
+ mContext, title, summary, mImeSwitchPendingIntent);
mNotificationManager.notify(
com.android.internal.R.string.select_input_method,
mImeSwitcherNotification);
diff --git a/services/java/com/android/server/NetworkManagementService.java b/services/java/com/android/server/NetworkManagementService.java
index 2366fcb..17ad268 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -849,7 +849,6 @@ class NetworkManagementService extends INetworkManagementService.Stub {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.CHANGE_WIFI_STATE, "NetworkManagementService");
try {
- mConnector.doCommand(String.format("softap stop " + wlanIface));
mConnector.doCommand(String.format("softap fwreload " + wlanIface + " AP"));
mConnector.doCommand(String.format("softap start " + wlanIface));
if (wifiConfig == null) {
@@ -897,13 +896,15 @@ class NetworkManagementService extends INetworkManagementService.Stub {
}
}
- public void stopAccessPoint() throws IllegalStateException {
+ public void stopAccessPoint(String wlanIface) throws IllegalStateException {
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.CHANGE_NETWORK_STATE, "NetworkManagementService");
mContext.enforceCallingOrSelfPermission(
android.Manifest.permission.CHANGE_WIFI_STATE, "NetworkManagementService");
try {
mConnector.doCommand("softap stopap");
+ mConnector.doCommand("softap stop " + wlanIface);
+ mConnector.doCommand(String.format("softap fwreload " + wlanIface + " STA"));
} catch (NativeDaemonConnectorException e) {
throw new IllegalStateException("Error communicating to native daemon to stop soft AP",
e);
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 8c7e279..f15eca6 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -37,6 +37,7 @@ import android.provider.Settings;
import android.server.BluetoothA2dpService;
import android.server.BluetoothService;
import android.server.search.SearchManagerService;
+import android.server.WifiP2pService;
import android.util.DisplayMetrics;
import android.util.EventLog;
import android.util.Slog;
@@ -108,6 +109,7 @@ class ServerThread extends Thread {
NetworkStatsService networkStats = null;
NetworkPolicyManagerService networkPolicy = null;
ConnectivityService connectivity = null;
+ WifiP2pService wifiP2p = null;
IPackageManager pm = null;
Context context = null;
WindowManagerService wm = null;
@@ -230,6 +232,7 @@ class ServerThread extends Thread {
WallpaperManagerService wallpaper = null;
LocationManagerService location = null;
CountryDetectorService countryDetector = null;
+ TextServicesManagerService tsms = null;
if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
try {
@@ -273,6 +276,14 @@ class ServerThread extends Thread {
}
try {
+ Slog.i(TAG, "Text Service Manager Service");
+ tsms = new TextServicesManagerService(context);
+ ServiceManager.addService(Context.TEXT_SERVICES_MANAGER_SERVICE, tsms);
+ } catch (Throwable e) {
+ Slog.e(TAG, "Failure starting Text Service Manager Service", e);
+ }
+
+ try {
Slog.i(TAG, "NetworkStats Service");
networkStats = new NetworkStatsService(context, networkManagement, alarm);
ServiceManager.addService(Context.NETWORK_STATS_SERVICE, networkStats);
@@ -290,6 +301,14 @@ class ServerThread extends Thread {
Slog.e(TAG, "Failure starting NetworkPolicy Service", e);
}
+ try {
+ Slog.i(TAG, "Wi-Fi P2pService");
+ wifiP2p = new WifiP2pService(context);
+ ServiceManager.addService(Context.WIFI_P2P_SERVICE, wifiP2p);
+ } catch (Throwable e) {
+ Slog.e(TAG, "Failure starting Wi-Fi P2pService", e);
+ }
+
try {
Slog.i(TAG, "Connectivity Service");
connectivity = new ConnectivityService(context, networkManagement, networkPolicy);
@@ -538,6 +557,7 @@ class ServerThread extends Thread {
final LocationManagerService locationF = location;
final CountryDetectorService countryDetectorF = countryDetector;
final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
+ final TextServicesManagerService textServiceManagerServiceF = tsms;
// We now tell the activity manager it is okay to run third party
// code. It will call back into us once it has gotten to the state
@@ -571,6 +591,7 @@ class ServerThread extends Thread {
if (countryDetectorF != null) countryDetectorF.systemReady();
if (throttleF != null) throttleF.systemReady();
if (networkTimeUpdaterF != null) networkTimeUpdaterF.systemReady();
+ if (textServiceManagerServiceF != null) textServiceManagerServiceF.systemReady();
}
});
diff --git a/services/java/com/android/server/TextServicesManagerService.java b/services/java/com/android/server/TextServicesManagerService.java
new file mode 100644
index 0000000..ffdc288
--- /dev/null
+++ b/services/java/com/android/server/TextServicesManagerService.java
@@ -0,0 +1,357 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server;
+
+import com.android.internal.content.PackageMonitor;
+import com.android.internal.textservice.ISpellCheckerService;
+import com.android.internal.textservice.ISpellCheckerSession;
+import com.android.internal.textservice.ISpellCheckerSessionListener;
+import com.android.internal.textservice.ITextServicesManager;
+import com.android.internal.textservice.ITextServicesSessionListener;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.ServiceInfo;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.SystemClock;
+import android.provider.Settings;
+import android.text.TextUtils;
+import android.service.textservice.SpellCheckerService;
+import android.util.Log;
+import android.util.Slog;
+import android.view.textservice.SpellCheckerInfo;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+
+public class TextServicesManagerService extends ITextServicesManager.Stub {
+ private static final String TAG = TextServicesManagerService.class.getSimpleName();
+ private static final boolean DBG = false;
+
+ private final Context mContext;
+ private boolean mSystemReady;
+ private final TextServicesMonitor mMonitor;
+ private final HashMap<String, SpellCheckerInfo> mSpellCheckerMap =
+ new HashMap<String, SpellCheckerInfo>();
+ private final ArrayList<SpellCheckerInfo> mSpellCheckerList = new ArrayList<SpellCheckerInfo>();
+ private final HashMap<String, SpellCheckerBindGroup> mSpellCheckerBindGroups =
+ new HashMap<String, SpellCheckerBindGroup>();
+
+ public void systemReady() {
+ if (!mSystemReady) {
+ mSystemReady = true;
+ }
+ }
+
+ public TextServicesManagerService(Context context) {
+ mSystemReady = false;
+ mContext = context;
+ mMonitor = new TextServicesMonitor();
+ mMonitor.register(context, true);
+ synchronized (mSpellCheckerMap) {
+ buildSpellCheckerMapLocked(context, mSpellCheckerList, mSpellCheckerMap);
+ }
+ }
+
+ private class TextServicesMonitor extends PackageMonitor {
+ @Override
+ public void onSomePackagesChanged() {
+ synchronized (mSpellCheckerMap) {
+ buildSpellCheckerMapLocked(mContext, mSpellCheckerList, mSpellCheckerMap);
+ // TODO: Update for each locale
+ SpellCheckerInfo sci = getCurrentSpellChecker(null);
+ if (sci == null) {
+ sci = findAvailSpellCheckerLocked(null, null);
+ if (sci == null) return;
+ // Set the current spell checker if there is one or more spell checkers
+ // available. In this case, "sci" is the first one in the available spell
+ // checkers.
+ setCurrentSpellChecker(sci);
+ }
+ final String packageName = sci.getPackageName();
+ final int change = isPackageDisappearing(packageName);
+ if (change == PACKAGE_PERMANENT_CHANGE || change == PACKAGE_TEMPORARY_CHANGE) {
+ // Package disappearing
+ setCurrentSpellChecker(findAvailSpellCheckerLocked(null, packageName));
+ } else if (isPackageModified(packageName)) {
+ // Package modified
+ setCurrentSpellChecker(findAvailSpellCheckerLocked(null, packageName));
+ }
+ }
+ }
+ }
+
+ private static void buildSpellCheckerMapLocked(Context context,
+ ArrayList<SpellCheckerInfo> list, HashMap<String, SpellCheckerInfo> map) {
+ list.clear();
+ map.clear();
+ final PackageManager pm = context.getPackageManager();
+ List<ResolveInfo> services = pm.queryIntentServices(
+ new Intent(SpellCheckerService.SERVICE_INTERFACE), PackageManager.GET_META_DATA);
+ final int N = services.size();
+ for (int i = 0; i < N; ++i) {
+ final ResolveInfo ri = services.get(i);
+ final ServiceInfo si = ri.serviceInfo;
+ final ComponentName compName = new ComponentName(si.packageName, si.name);
+ if (!android.Manifest.permission.BIND_TEXT_SERVICE.equals(si.permission)) {
+ Slog.w(TAG, "Skipping text service " + compName
+ + ": it does not require the permission "
+ + android.Manifest.permission.BIND_TEXT_SERVICE);
+ continue;
+ }
+ if (DBG) Slog.d(TAG, "Add: " + compName);
+ final SpellCheckerInfo sci = new SpellCheckerInfo(context, ri);
+ list.add(sci);
+ map.put(sci.getId(), sci);
+ }
+ }
+
+ // TODO: find an appropriate spell checker for specified locale
+ private SpellCheckerInfo findAvailSpellCheckerLocked(String locale, String prefPackage) {
+ final int spellCheckersCount = mSpellCheckerList.size();
+ if (spellCheckersCount == 0) {
+ Slog.w(TAG, "no available spell checker services found");
+ return null;
+ }
+ if (prefPackage != null) {
+ for (int i = 0; i < spellCheckersCount; ++i) {
+ final SpellCheckerInfo sci = mSpellCheckerList.get(i);
+ if (prefPackage.equals(sci.getPackageName())) {
+ return sci;
+ }
+ }
+ }
+ if (spellCheckersCount > 1) {
+ Slog.w(TAG, "more than one spell checker service found, picking first");
+ }
+ return mSpellCheckerList.get(0);
+ }
+
+ // TODO: Save SpellCheckerService by supported languages. Currently only one spell
+ // checker is saved.
+ @Override
+ public SpellCheckerInfo getCurrentSpellChecker(String locale) {
+ synchronized (mSpellCheckerMap) {
+ final String curSpellCheckerId =
+ Settings.Secure.getString(mContext.getContentResolver(),
+ Settings.Secure.SPELL_CHECKER_SERVICE);
+ if (DBG) {
+ Slog.w(TAG, "getCurrentSpellChecker: " + curSpellCheckerId);
+ }
+ if (TextUtils.isEmpty(curSpellCheckerId)) {
+ return null;
+ }
+ return mSpellCheckerMap.get(curSpellCheckerId);
+ }
+ }
+
+ @Override
+ public void getSpellCheckerService(SpellCheckerInfo info, String locale,
+ ITextServicesSessionListener tsListener, ISpellCheckerSessionListener scListener) {
+ if (!mSystemReady) {
+ return;
+ }
+ if (info == null || tsListener == null) {
+ Slog.e(TAG, "getSpellCheckerService: Invalid input.");
+ return;
+ }
+ final String sciId = info.getId();
+ synchronized(mSpellCheckerMap) {
+ if (!mSpellCheckerMap.containsKey(sciId)) {
+ return;
+ }
+ if (mSpellCheckerBindGroups.containsKey(sciId)) {
+ mSpellCheckerBindGroups.get(sciId).addListener(tsListener, locale, scListener);
+ return;
+ }
+ final InternalServiceConnection connection = new InternalServiceConnection(
+ sciId, locale, scListener);
+ final Intent serviceIntent = new Intent(SpellCheckerService.SERVICE_INTERFACE);
+ serviceIntent.setComponent(info.getComponent());
+ if (!mContext.bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE)) {
+ Slog.e(TAG, "Failed to get a spell checker service.");
+ return;
+ }
+ final SpellCheckerBindGroup group = new SpellCheckerBindGroup(
+ connection, tsListener, locale, scListener);
+ mSpellCheckerBindGroups.put(sciId, group);
+ }
+ return;
+ }
+
+ @Override
+ public SpellCheckerInfo[] getEnabledSpellCheckers() {
+ return mSpellCheckerList.toArray(new SpellCheckerInfo[mSpellCheckerList.size()]);
+ }
+
+ @Override
+ public void finishSpellCheckerService(ISpellCheckerSessionListener listener) {
+ synchronized(mSpellCheckerMap) {
+ for (SpellCheckerBindGroup group : mSpellCheckerBindGroups.values()) {
+ if (group == null) continue;
+ group.removeListener(listener);
+ }
+ }
+ }
+
+ private void setCurrentSpellChecker(SpellCheckerInfo sci) {
+ if (DBG) {
+ Slog.w(TAG, "setCurrentSpellChecker: " + sci.getId());
+ }
+ if (sci == null || mSpellCheckerMap.containsKey(sci.getId())) return;
+ Settings.Secure.putString(mContext.getContentResolver(),
+ Settings.Secure.SPELL_CHECKER_SERVICE, sci == null ? "" : sci.getId());
+ }
+
+ // SpellCheckerBindGroup contains active text service session listeners.
+ // If there are no listeners anymore, the SpellCheckerBindGroup instance will be removed from
+ // mSpellCheckerBindGroups
+ private class SpellCheckerBindGroup {
+ final InternalServiceConnection mInternalConnection;
+ final ArrayList<InternalDeathRecipient> mListeners =
+ new ArrayList<InternalDeathRecipient>();
+
+ public SpellCheckerBindGroup(InternalServiceConnection connection,
+ ITextServicesSessionListener listener, String locale,
+ ISpellCheckerSessionListener scListener) {
+ mInternalConnection = connection;
+ addListener(listener, locale, scListener);
+ }
+
+ public void onServiceConnected(ISpellCheckerService spellChecker) {
+ synchronized(mSpellCheckerMap) {
+ for (InternalDeathRecipient listener : mListeners) {
+ try {
+ final ISpellCheckerSession session = spellChecker.getISpellCheckerSession(
+ listener.mScLocale, listener.mScListener);
+ listener.mTsListener.onServiceConnected(session);
+ } catch (RemoteException e) {
+ }
+ }
+ }
+ }
+
+ public void addListener(ITextServicesSessionListener tsListener, String locale,
+ ISpellCheckerSessionListener scListener) {
+ synchronized(mSpellCheckerMap) {
+ try {
+ final int size = mListeners.size();
+ for (int i = 0; i < size; ++i) {
+ if (mListeners.get(i).hasSpellCheckerListener(scListener)) {
+ // do not add the lister if the group already contains this.
+ return;
+ }
+ }
+ final InternalDeathRecipient recipient = new InternalDeathRecipient(
+ this, tsListener, locale, scListener);
+ scListener.asBinder().linkToDeath(recipient, 0);
+ mListeners.add(new InternalDeathRecipient(
+ this, tsListener, locale, scListener));
+ } catch(RemoteException e) {
+ // do nothing
+ }
+ cleanLocked();
+ }
+ }
+
+ public void removeListener(ISpellCheckerSessionListener listener) {
+ synchronized(mSpellCheckerMap) {
+ final int size = mListeners.size();
+ final ArrayList<InternalDeathRecipient> removeList =
+ new ArrayList<InternalDeathRecipient>();
+ for (int i = 0; i < size; ++i) {
+ final InternalDeathRecipient tempRecipient = mListeners.get(i);
+ if(tempRecipient.hasSpellCheckerListener(listener)) {
+ removeList.add(tempRecipient);
+ }
+ }
+ final int removeSize = removeList.size();
+ for (int i = 0; i < removeSize; ++i) {
+ mListeners.remove(removeList.get(i));
+ }
+ cleanLocked();
+ }
+ }
+
+ private void cleanLocked() {
+ if (mListeners.isEmpty()) {
+ mSpellCheckerBindGroups.remove(this);
+ // Unbind service when there is no active clients.
+ mContext.unbindService(mInternalConnection);
+ }
+ }
+ }
+
+ private class InternalServiceConnection implements ServiceConnection {
+ private final ISpellCheckerSessionListener mListener;
+ private final String mSciId;
+ private final String mLocale;
+ public InternalServiceConnection(
+ String id, String locale, ISpellCheckerSessionListener listener) {
+ mSciId = id;
+ mLocale = locale;
+ mListener = listener;
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ synchronized(mSpellCheckerMap) {
+ ISpellCheckerService spellChecker = ISpellCheckerService.Stub.asInterface(service);
+ final SpellCheckerBindGroup group = mSpellCheckerBindGroups.get(mSciId);
+ if (group != null) {
+ group.onServiceConnected(spellChecker);
+ }
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mSpellCheckerBindGroups.remove(mSciId);
+ }
+ }
+
+ private class InternalDeathRecipient implements IBinder.DeathRecipient {
+ public final ITextServicesSessionListener mTsListener;
+ public final ISpellCheckerSessionListener mScListener;
+ public final String mScLocale;
+ private final SpellCheckerBindGroup mGroup;
+ public InternalDeathRecipient(SpellCheckerBindGroup group,
+ ITextServicesSessionListener tsListener, String scLocale,
+ ISpellCheckerSessionListener scListener) {
+ mTsListener = tsListener;
+ mScListener = scListener;
+ mScLocale = scLocale;
+ mGroup = group;
+ }
+
+ public boolean hasSpellCheckerListener(ISpellCheckerSessionListener listener) {
+ return mScListener.equals(listener);
+ }
+
+ @Override
+ public void binderDied() {
+ mGroup.removeListener(mScListener);
+ }
+ }
+}
diff --git a/services/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/java/com/android/server/accessibility/AccessibilityManagerService.java
index bb9d15b..92647e6 100644
--- a/services/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -49,6 +49,7 @@ import android.util.SparseArray;
import android.view.IWindow;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.accessibility.IAccessibilityInteractionConnection;
import android.view.accessibility.IAccessibilityInteractionConnectionCallback;
@@ -129,10 +130,10 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
private boolean mIsAccessibilityEnabled;
- private boolean mIsTouchExplorationRequested;
-
private AccessibilityInputFilter mInputFilter;
+ private boolean mHasInputFilter;
+
private final List<AccessibilityServiceInfo> mEnabledServicesForFeedbackTempList = new ArrayList<AccessibilityServiceInfo>();
private boolean mIsTouchExplorationEnabled;
@@ -189,7 +190,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
manageServicesLocked();
}
}
-
+
@Override
public boolean onHandleForceStop(Intent intent, String[] packages,
int uid, boolean doit) {
@@ -236,17 +237,16 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
mIsAccessibilityEnabled = Settings.Secure.getInt(
mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 1;
- // if accessibility is enabled inform our clients we are on
- if (mIsAccessibilityEnabled) {
- sendAccessibilityEnabledToClientsLocked();
- }
+
manageServicesLocked();
// get touch exploration enabled setting on boot
- mIsTouchExplorationRequested = Settings.Secure.getInt(
+ mIsTouchExplorationEnabled = Settings.Secure.getInt(
mContext.getContentResolver(),
- Settings.Secure.TOUCH_EXPLORATION_REQUESTED, 0) == 1;
- updateTouchExplorationEnabledLocked();
+ Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1;
+ updateInputFilterLocked();
+
+ sendStateToClientsLocked();
}
return;
@@ -288,13 +288,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
} else {
unbindAllServicesLocked();
}
- sendAccessibilityEnabledToClientsLocked();
+ sendStateToClientsLocked();
}
}
});
Uri touchExplorationRequestedUri = Settings.Secure.getUriFor(
- Settings.Secure.TOUCH_EXPLORATION_REQUESTED);
+ Settings.Secure.TOUCH_EXPLORATION_ENABLED);
contentResolver.registerContentObserver(touchExplorationRequestedUri, false,
new ContentObserver(new Handler()) {
@Override
@@ -302,10 +302,11 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
super.onChange(selfChange);
synchronized (mLock) {
- mIsTouchExplorationRequested = Settings.Secure.getInt(
+ mIsTouchExplorationEnabled = Settings.Secure.getInt(
mContext.getContentResolver(),
- Settings.Secure.TOUCH_EXPLORATION_REQUESTED, 0) == 1;
- updateTouchExplorationEnabledLocked();
+ Settings.Secure.TOUCH_EXPLORATION_ENABLED, 0) == 1;
+ updateInputFilterLocked();
+ sendStateToClientsLocked();
}
}
});
@@ -325,7 +326,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
});
}
- public boolean addClient(IAccessibilityManagerClient client) throws RemoteException {
+ public int addClient(IAccessibilityManagerClient client) throws RemoteException {
synchronized (mLock) {
final IAccessibilityManagerClient addedClient = client;
mClients.add(addedClient);
@@ -338,7 +339,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
}
}
}, 0);
- return mIsAccessibilityEnabled;
+ return getState();
}
}
@@ -628,7 +629,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
service.linkToOwnDeath();
mServices.add(service);
mComponentNameToServiceMap.put(service.mComponentName, service);
- updateTouchExplorationEnabledLocked();
+ updateInputFilterLocked();
} catch (RemoteException e) {
/* do nothing */
}
@@ -648,7 +649,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
mComponentNameToServiceMap.remove(service.mComponentName);
mHandler.removeMessages(service.mId);
service.unlinkToOwnDeath();
- updateTouchExplorationEnabledLocked();
+ updateInputFilterLocked();
return removed;
}
@@ -781,12 +782,13 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
}
/**
- * Updates the state of {@link android.view.accessibility.AccessibilityManager} clients.
+ * Sends the state to the clients.
*/
- private void sendAccessibilityEnabledToClientsLocked() {
+ private void sendStateToClientsLocked() {
+ final int state = getState();
for (int i = 0, count = mClients.size(); i < count; i++) {
try {
- mClients.get(i).setEnabled(mIsAccessibilityEnabled);
+ mClients.get(i).setState(state);
} catch (RemoteException re) {
mClients.remove(i);
count--;
@@ -796,48 +798,39 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub
}
/**
- * Sends the touch exploration state to clients.
+ * Gets the current state as a set of flags.
+ *
+ * @return The state.
*/
- private void sendTouchExplorationEnabledToClientsLocked() {
- for (int i = 0, count = mClients.size(); i < count; i++) {
- try {
- mClients.get(i).setTouchExplorationEnabled(mIsTouchExplorationEnabled);
- } catch (RemoteException re) {
- mClients.remove(i);
- count--;
- i--;
- }
+ private int getState() {
+ int state = 0;
+ if (mIsAccessibilityEnabled) {
+ state |= AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED;
}
+ // Touch exploration relies on enabled accessibility.
+ if (mIsAccessibilityEnabled && mIsTouchExplorationEnabled) {
+ state |= AccessibilityManager.STATE_FLAG_TOUCH_EXPLORATION_ENABLED;
+ }
+ return state;
}
/**
- * Updates the touch exploration state. Touch exploration is enabled if it
- * is requested, accessibility is on and there is at least one enabled
- * accessibility service providing spoken feedback.
+ * Updates the touch exploration state.
*/
- private void updateTouchExplorationEnabledLocked() {
- if (mIsAccessibilityEnabled && mIsTouchExplorationRequested) {
- final boolean hasSpeakingServicesEnabled = !getEnabledAccessibilityServiceList(
- AccessibilityServiceInfo.FEEDBACK_SPOKEN).isEmpty();
- if (!mIsTouchExplorationEnabled) {
- if (!hasSpeakingServicesEnabled) {
- return;
- }
+ private void updateInputFilterLocked() {
+ if (mIsAccessibilityEnabled && mIsTouchExplorationEnabled) {
+ if (!mHasInputFilter) {
+ mHasInputFilter = true;
if (mInputFilter == null) {
mInputFilter = new AccessibilityInputFilter(mContext);
}
mWindowManagerService.setInputFilter(mInputFilter);
- mIsTouchExplorationEnabled = true;
- sendTouchExplorationEnabledToClientsLocked();
- return;
- } else if (hasSpeakingServicesEnabled) {
- return;
}
+ return;
}
- if (mIsTouchExplorationEnabled) {
+ if (mHasInputFilter) {
+ mHasInputFilter = false;
mWindowManagerService.setInputFilter(null);
- mIsTouchExplorationEnabled = false;
- sendTouchExplorationEnabledToClientsLocked();
}
}
diff --git a/services/java/com/android/server/accessibility/TouchExplorer.java b/services/java/com/android/server/accessibility/TouchExplorer.java
index 5a3a55d..0ad58d0 100644
--- a/services/java/com/android/server/accessibility/TouchExplorer.java
+++ b/services/java/com/android/server/accessibility/TouchExplorer.java
@@ -19,21 +19,21 @@ package com.android.server.accessibility;
import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END;
import static android.view.accessibility.AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START;
-import com.android.server.accessibility.AccessibilityInputFilter.Explorer;
-import com.android.server.wm.InputFilter;
-
import android.content.Context;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Slog;
import android.view.MotionEvent;
-import android.view.ViewConfiguration;
-import android.view.WindowManagerPolicy;
import android.view.MotionEvent.PointerCoords;
import android.view.MotionEvent.PointerProperties;
+import android.view.ViewConfiguration;
+import android.view.WindowManagerPolicy;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
+import com.android.server.accessibility.AccessibilityInputFilter.Explorer;
+import com.android.server.wm.InputFilter;
+
import java.util.Arrays;
/**
@@ -146,6 +146,9 @@ public class TouchExplorer implements Explorer {
// Command for delayed sending of a hover event.
private final SendHoverDelayed mSendHoverDelayed;
+ // Command for delayed sending of a long press.
+ private final PerformLongPressDelayed mPerformLongPressDelayed;
+
/**
* Creates a new instance.
*
@@ -160,6 +163,7 @@ public class TouchExplorer implements Explorer {
mPointerTracker = new PointerTracker(context);
mHandler = new Handler(context.getMainLooper());
mSendHoverDelayed = new SendHoverDelayed();
+ mPerformLongPressDelayed = new PerformLongPressDelayed();
mAccessibilityManager = AccessibilityManager.getInstance(context);
}
@@ -208,15 +212,7 @@ public class TouchExplorer implements Explorer {
final int activePointerCount = pointerTracker.getActivePointerCount();
switch (event.getActionMasked()) {
- case MotionEvent.ACTION_DOWN: {
- // Send a hover for every finger down so the user gets feedback
- // where she is currently touching.
- mSendHoverDelayed.forceSendAndRemove();
- final int pointerIndex = event.getActionIndex();
- final int pointerIdBits = (1 << event.getPointerId(pointerIndex));
- mSendHoverDelayed.post(event, MotionEvent.ACTION_HOVER_ENTER, pointerIdBits,
- policyFlags, DELAY_SEND_HOVER_MOVE);
- } break;
+ case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN: {
switch (activePointerCount) {
case 0: {
@@ -224,13 +220,13 @@ public class TouchExplorer implements Explorer {
+ "touch exploring state!");
}
case 1: {
- // Schedule a hover event which will lead to firing an
- // accessibility event from the hovered view.
- mSendHoverDelayed.remove();
+ // Send hover if pending.
+ mSendHoverDelayed.forceSendAndRemove();
+ // Send a hover for every finger down so the user gets feedback.
final int pointerId = pointerTracker.getPrimaryActivePointerId();
final int pointerIdBits = (1 << pointerId);
final int lastAction = pointerTracker.getLastInjectedHoverAction();
- // If a schedules hover enter for another pointer is delivered we send move.
+ // If a hover enter for another pointer is delivered we send move.
final int action = (lastAction == MotionEvent.ACTION_HOVER_ENTER)
? MotionEvent.ACTION_HOVER_MOVE
: MotionEvent.ACTION_HOVER_ENTER;
@@ -244,7 +240,19 @@ public class TouchExplorer implements Explorer {
// If more pointers down on the screen since the last touch
// exploration we discard the last cached touch explore event.
if (event.getPointerCount() != mLastTouchExploreEvent.getPointerCount()) {
- mLastTouchExploreEvent = null;
+ mLastTouchExploreEvent = null;
+ break;
+ }
+
+ // If the down is in the time slop => schedule a long press.
+ final long pointerDownTime =
+ pointerTracker.getReceivedPointerDownTime(pointerId);
+ final long lastExploreTime = mLastTouchExploreEvent.getEventTime();
+ final long deltaTimeExplore = pointerDownTime - lastExploreTime;
+ if (deltaTimeExplore <= ACTIVATION_TIME_SLOP) {
+ mPerformLongPressDelayed.post(event, policyFlags,
+ ViewConfiguration.getLongPressTimeout());
+ break;
}
} break;
default: {
@@ -275,6 +283,7 @@ public class TouchExplorer implements Explorer {
sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_START);
// Make sure the scheduled down/move event is sent.
mSendHoverDelayed.forceSendAndRemove();
+ mPerformLongPressDelayed.remove();
// If we have transitioned to exploring state from another one
// we need to send a hover enter event here.
final int lastAction = mPointerTracker.getLastInjectedHoverAction();
@@ -291,20 +300,11 @@ public class TouchExplorer implements Explorer {
policyFlags);
}
- // Detect long press on the last touch explored position.
- if (!mTouchExploreGestureInProgress && mLastTouchExploreEvent != null) {
+ // If the exploring pointer moved enough => cancel the long press.
+ if (!mTouchExploreGestureInProgress && mLastTouchExploreEvent != null
+ && mPerformLongPressDelayed.isPenidng()) {
- // If the down was not in the time slop => nothing else to do.
- final long pointerDownTime =
- pointerTracker.getReceivedPointerDownTime(pointerId);
- final long lastExploreTime = mLastTouchExploreEvent.getEventTime();
- final long deltaTimeExplore = pointerDownTime - lastExploreTime;
- if (deltaTimeExplore > ACTIVATION_TIME_SLOP) {
- mLastTouchExploreEvent = null;
- break;
- }
-
- // If the pointer moved more than the tap slop => nothing else to do.
+ // If the pointer moved more than the tap slop => cancel long press.
final float deltaX = mLastTouchExploreEvent.getX(pointerIndex)
- event.getX(pointerIndex);
final float deltaY = mLastTouchExploreEvent.getY(pointerIndex)
@@ -312,24 +312,14 @@ public class TouchExplorer implements Explorer {
final float moveDelta = (float) Math.hypot(deltaX, deltaY);
if (moveDelta > mTouchExplorationTapSlop) {
mLastTouchExploreEvent = null;
+ mPerformLongPressDelayed.remove();
break;
}
-
- // If down for long enough we get a long press.
- final long deltaTimeMove = event.getEventTime() - pointerDownTime;
- if (deltaTimeMove > ViewConfiguration.getLongPressTimeout()) {
- mCurrentState = STATE_DELEGATING;
- // Make sure the scheduled hover exit is delivered.
- mSendHoverDelayed.forceSendAndRemove();
- sendDownForAllActiveNotInjectedPointers(event, policyFlags);
- sendMotionEvent(event, policyFlags);
- mTouchExploreGestureInProgress = false;
- mLastTouchExploreEvent = null;
- }
}
} break;
case 2: {
mSendHoverDelayed.forceSendAndRemove();
+ mPerformLongPressDelayed.remove();
// We want to no longer hover over the location so subsequent
// touch at the same spot will generate a hover enter.
sendMotionEvent(event, MotionEvent.ACTION_HOVER_EXIT, pointerIdBits,
@@ -360,6 +350,7 @@ public class TouchExplorer implements Explorer {
} break;
default: {
mSendHoverDelayed.forceSendAndRemove();
+ mPerformLongPressDelayed.remove();
// We want to no longer hover over the location so subsequent
// touch at the same spot will generate a hover enter.
sendMotionEvent(event, MotionEvent.ACTION_HOVER_EXIT, pointerIdBits,
@@ -388,22 +379,26 @@ public class TouchExplorer implements Explorer {
break;
}
+ mSendHoverDelayed.forceSendAndRemove();
+ mPerformLongPressDelayed.remove();
+
// If touch exploring announce the end of the gesture.
+ // Also do not click on the last explored location.
if (mTouchExploreGestureInProgress) {
- sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END);
mTouchExploreGestureInProgress = false;
+ mLastTouchExploreEvent = MotionEvent.obtain(event);
+ sendAccessibilityEvent(TYPE_TOUCH_EXPLORATION_GESTURE_END);
+ break;
}
// Detect whether to activate i.e. click on the last explored location.
if (mLastTouchExploreEvent != null) {
-
// If the down was not in the time slop => nothing else to do.
final long eventTime =
pointerTracker.getLastReceivedUpPointerDownTime();
final long exploreTime = mLastTouchExploreEvent.getEventTime();
final long deltaTime = eventTime - exploreTime;
if (deltaTime > ACTIVATION_TIME_SLOP) {
- mSendHoverDelayed.forceSendAndRemove();
final int lastAction = mPointerTracker.getLastInjectedHoverAction();
if (lastAction != MotionEvent.ACTION_HOVER_EXIT) {
sendMotionEvent(event, MotionEvent.ACTION_HOVER_EXIT,
@@ -413,15 +408,14 @@ public class TouchExplorer implements Explorer {
break;
}
- // If the pointer moved more than the tap slop => nothing else to do.
+ // If a tap is farther than the tap slop => nothing to do.
final int pointerIndex = event.findPointerIndex(pointerId);
- final float deltaX = pointerTracker.getLastReceivedUpPointerDownX()
+ final float deltaX = mLastTouchExploreEvent.getX(pointerIndex)
- event.getX(pointerIndex);
- final float deltaY = pointerTracker.getLastReceivedUpPointerDownY()
+ final float deltaY = mLastTouchExploreEvent.getY(pointerIndex)
- event.getY(pointerIndex);
final float deltaMove = (float) Math.hypot(deltaX, deltaY);
if (deltaMove > mTouchExplorationTapSlop) {
- mSendHoverDelayed.forceSendAndRemove();
final int lastAction = mPointerTracker.getLastInjectedHoverAction();
if (lastAction != MotionEvent.ACTION_HOVER_EXIT) {
sendMotionEvent(event, MotionEvent.ACTION_HOVER_EXIT,
@@ -432,7 +426,6 @@ public class TouchExplorer implements Explorer {
}
// All preconditions are met, so click the last explored location.
- mSendHoverDelayed.forceSendAndRemove();
sendActionDownAndUp(mLastTouchExploreEvent, policyFlags);
mLastTouchExploreEvent = null;
} else {
@@ -448,6 +441,8 @@ public class TouchExplorer implements Explorer {
}
} break;
case MotionEvent.ACTION_CANCEL: {
+ mSendHoverDelayed.remove();
+ mPerformLongPressDelayed.remove();
final int lastAction = pointerTracker.getLastInjectedHoverAction();
if (lastAction != MotionEvent.ACTION_HOVER_EXIT) {
final int pointerId = pointerTracker.getPrimaryActivePointerId();
@@ -934,8 +929,6 @@ public class TouchExplorer implements Explorer {
private int mInjectedPointersDown;
// Keep track of the last up pointer data.
- private float mLastReceivedUpPointerDownX;
- private float mLastReveivedUpPointerDownY;
private long mLastReceivedUpPointerDownTime;
private int mLastReceivedUpPointerId;
private boolean mLastReceivedUpPointerActive;
@@ -968,8 +961,6 @@ public class TouchExplorer implements Explorer {
mPrimaryActivePointerId = 0;
mHasMovingActivePointer = false;
mInjectedPointersDown = 0;
- mLastReceivedUpPointerDownX = 0;
- mLastReveivedUpPointerDownY = 0;
mLastReceivedUpPointerDownTime = 0;
mLastReceivedUpPointerId = 0;
mLastReceivedUpPointerActive = false;
@@ -1126,20 +1117,6 @@ public class TouchExplorer implements Explorer {
}
/**
- * @return The X coordinate where the last up received pointer went down.
- */
- public float getLastReceivedUpPointerDownX() {
- return mLastReceivedUpPointerDownX;
- }
-
- /**
- * @return The Y coordinate where the last up received pointer went down.
- */
- public float getLastReceivedUpPointerDownY() {
- return mLastReveivedUpPointerDownY;
- }
-
- /**
* @return The time when the last up received pointer went down.
*/
public long getLastReceivedUpPointerDownTime() {
@@ -1220,8 +1197,6 @@ public class TouchExplorer implements Explorer {
final int pointerFlag = (1 << pointerId);
mLastReceivedUpPointerId = 0;
- mLastReceivedUpPointerDownX = 0;
- mLastReveivedUpPointerDownY = 0;
mLastReceivedUpPointerDownTime = 0;
mLastReceivedUpPointerActive = false;
@@ -1262,8 +1237,6 @@ public class TouchExplorer implements Explorer {
final int pointerFlag = (1 << pointerId);
mLastReceivedUpPointerId = pointerId;
- mLastReceivedUpPointerDownX = getReceivedPointerDownX(pointerId);
- mLastReveivedUpPointerDownY = getReceivedPointerDownY(pointerId);
mLastReceivedUpPointerDownTime = getReceivedPointerDownTime(pointerId);
mLastReceivedUpPointerActive = isActivePointer(pointerId);
@@ -1400,6 +1373,51 @@ public class TouchExplorer implements Explorer {
}
/**
+ * Class for delayed sending of long press.
+ */
+ private final class PerformLongPressDelayed implements Runnable {
+ private MotionEvent mEvent;
+ private int mPolicyFlags;
+
+ public void post(MotionEvent prototype, int policyFlags, long delay) {
+ mEvent = MotionEvent.obtain(prototype);
+ mPolicyFlags = policyFlags;
+ mHandler.postDelayed(this, delay);
+ }
+
+ public void remove() {
+ if (isPenidng()) {
+ mHandler.removeCallbacks(this);
+ clear();
+ }
+ }
+
+ private boolean isPenidng() {
+ return (mEvent != null);
+ }
+
+ @Override
+ public void run() {
+ mCurrentState = STATE_DELEGATING;
+ // Make sure the scheduled hover exit is delivered.
+ mSendHoverDelayed.forceSendAndRemove();
+ sendDownForAllActiveNotInjectedPointers(mEvent, mPolicyFlags);
+ mTouchExploreGestureInProgress = false;
+ mLastTouchExploreEvent = null;
+ clear();
+ }
+
+ private void clear() {
+ if (!isPenidng()) {
+ return;
+ }
+ mEvent.recycle();
+ mEvent = null;
+ mPolicyFlags = 0;
+ }
+ }
+
+ /**
* Class for delayed sending of hover events.
*/
private final class SendHoverDelayed implements Runnable {
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index 82bc505..a5a6d8e 100644
--- a/services/java/com/android/server/connectivity/Tethering.java
+++ b/services/java/com/android/server/connectivity/Tethering.java
@@ -36,7 +36,6 @@ import android.net.LinkProperties;
import android.net.NetworkInfo;
import android.net.NetworkUtils;
import android.os.Binder;
-import android.os.Environment;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
@@ -76,10 +75,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
private final static String TAG = "Tethering";
private final static boolean DEBUG = true;
- private boolean mBooted = false;
- //used to remember if we got connected before boot finished
- private boolean mDeferedUsbConnection = false;
-
// TODO - remove both of these - should be part of interface inspection/selection stuff
private String[] mTetherableUsbRegexs;
private String[] mTetherableWifiRegexs;
@@ -126,10 +121,9 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
private Notification mTetheredNotification;
- // whether we can tether is the && of these two - they come in as separate
- // broadcasts so track them so we can decide what to do when either changes
- private boolean mUsbMassStorageOff; // track the status of USB Mass Storage
- private boolean mUsbConnected; // track the status of USB connection
+ private boolean mRndisEnabled; // track the RNDIS function enabled state
+ private boolean mUsbTetherRequested; // true if USB tethering should be started
+ // when RNDIS is enabled
public Tethering(Context context, INetworkManagementService nmService, Looper looper) {
mContext = context;
@@ -149,7 +143,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_STATE);
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
- filter.addAction(Intent.ACTION_BOOT_COMPLETED);
mContext.registerReceiver(mStateReceiver, filter);
filter = new IntentFilter();
@@ -158,9 +151,6 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
filter.addDataScheme("file");
mContext.registerReceiver(mStateReceiver, filter);
- mUsbMassStorageOff = !Environment.MEDIA_SHARED.equals(
- Environment.getExternalStorageState());
-
mDhcpRange = context.getResources().getStringArray(
com.android.internal.R.array.config_tether_dhcp_range);
if ((mDhcpRange.length == 0) || (mDhcpRange.length % 2 ==1)) {
@@ -221,6 +211,8 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
}
public void interfaceLinkStateChanged(String iface, boolean up) {
+ if (DEBUG) Log.d(TAG, "interfaceLinkStateChanged " + iface + ", " + up);
+ interfaceStatusChanged(iface, up);
}
private boolean isUsb(String iface) {
@@ -243,6 +235,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
}
return false;
}
+
public void interfaceAdded(String iface) {
boolean found = false;
boolean usb = false;
@@ -456,47 +449,28 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
}
}
- private void updateUsbStatus() {
- boolean enable = mUsbConnected && mUsbMassStorageOff;
-
- if (mBooted) {
- enableUsbIfaces(enable);
- }
- }
-
private class StateReceiver extends BroadcastReceiver {
public void onReceive(Context content, Intent intent) {
String action = intent.getAction();
if (action.equals(UsbManager.ACTION_USB_STATE)) {
- mUsbConnected = intent.getExtras().getBoolean(UsbManager.USB_CONNECTED);
- updateUsbStatus();
- } else if (action.equals(Intent.ACTION_MEDIA_SHARED)) {
- mUsbMassStorageOff = false;
- updateUsbStatus();
- }
- else if (action.equals(Intent.ACTION_MEDIA_UNSHARED)) {
- mUsbMassStorageOff = true;
- updateUsbStatus();
+ synchronized (Tethering.this) {
+ boolean usbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
+ mRndisEnabled = intent.getBooleanExtra(UsbManager.USB_FUNCTION_RNDIS, false);
+ // start tethering if we have a request pending
+ if (usbConnected && mRndisEnabled && mUsbTetherRequested) {
+ tetherUsb(true);
+ }
+ mUsbTetherRequested = false;
+ }
} else if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
if (DEBUG) Log.d(TAG, "Tethering got CONNECTIVITY_ACTION");
mTetherMasterSM.sendMessage(TetherMasterSM.CMD_UPSTREAM_CHANGED);
- } else if (action.equals(Intent.ACTION_BOOT_COMPLETED)) {
- mBooted = true;
- updateUsbStatus();
}
}
}
- // used on cable insert/remove
- private void enableUsbIfaces(boolean enable) {
- // add/remove USB interfaces when USB is connected/disconnected
- for (String intf : mTetherableUsbRegexs) {
- if (enable) {
- interfaceAdded(intf);
- } else {
- interfaceRemoved(intf);
- }
- }
+ private void tetherUsb(boolean enable) {
+ if (DEBUG) Log.d(TAG, "tetherUsb " + enable);
String[] ifaces = new String[0];
try {
@@ -507,83 +481,50 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
}
for (String iface : ifaces) {
if (isUsb(iface)) {
- if (enable) {
- interfaceAdded(iface);
- } else {
- interfaceRemoved(iface);
+ int result = (enable ? tether(iface) : untether(iface));
+ if (result == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
+ return;
}
}
}
- }
-
- // toggled when we enter/leave the fully tethered state
- private boolean enableUsbRndis(boolean enabled) {
- if (DEBUG) Log.d(TAG, "enableUsbRndis(" + enabled + ")");
-
- UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE);
- if (usbManager == null) {
- Log.d(TAG, "could not get UsbManager");
- return false;
- }
- try {
- if (enabled) {
- usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false);
- } else {
- usbManager.setCurrentFunction(null, false);
- }
- } catch (Exception e) {
- Log.e(TAG, "Error toggling usb RNDIS", e);
- return false;
- }
- return true;
+ Log.e(TAG, "unable start or stop USB tethering");
}
// configured when we start tethering and unconfig'd on error or conclusion
private boolean configureUsbIface(boolean enabled) {
if (DEBUG) Log.d(TAG, "configureUsbIface(" + enabled + ")");
- if (enabled) {
- // must enable RNDIS first to create the interface
- enableUsbRndis(enabled);
- }
-
+ // toggle the USB interfaces
+ String[] ifaces = new String[0];
try {
- // bring toggle the interfaces
- String[] ifaces = new String[0];
- try {
- ifaces = mNMService.listInterfaces();
- } catch (Exception e) {
- Log.e(TAG, "Error listing Interfaces", e);
- return false;
- }
- for (String iface : ifaces) {
- if (isUsb(iface)) {
- InterfaceConfiguration ifcg = null;
- try {
- ifcg = mNMService.getInterfaceConfig(iface);
- if (ifcg != null) {
- InetAddress addr = NetworkUtils.numericToInetAddress(USB_NEAR_IFACE_ADDR);
- ifcg.addr = new LinkAddress(addr, USB_PREFIX_LENGTH);
- if (enabled) {
- ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
- } else {
- ifcg.interfaceFlags = ifcg.interfaceFlags.replace("up", "down");
- }
- ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
- ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" "," ");
- mNMService.setInterfaceConfig(iface, ifcg);
+ ifaces = mNMService.listInterfaces();
+ } catch (Exception e) {
+ Log.e(TAG, "Error listing Interfaces", e);
+ return false;
+ }
+ for (String iface : ifaces) {
+ if (isUsb(iface)) {
+ InterfaceConfiguration ifcg = null;
+ try {
+ ifcg = mNMService.getInterfaceConfig(iface);
+ if (ifcg != null) {
+ InetAddress addr = NetworkUtils.numericToInetAddress(USB_NEAR_IFACE_ADDR);
+ ifcg.addr = new LinkAddress(addr, USB_PREFIX_LENGTH);
+ if (enabled) {
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace("down", "up");
+ } else {
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace("up", "down");
}
- } catch (Exception e) {
- Log.e(TAG, "Error configuring interface " + iface, e);
- return false;
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace("running", "");
+ ifcg.interfaceFlags = ifcg.interfaceFlags.replace(" "," ");
+ mNMService.setInterfaceConfig(iface, ifcg);
}
+ } catch (Exception e) {
+ Log.e(TAG, "Error configuring interface " + iface, e);
+ return false;
}
- }
- } finally {
- if (!enabled) {
- enableUsbRndis(false);
}
- }
+ }
return true;
}
@@ -600,6 +541,28 @@ public class Tethering extends INetworkManagementEventObserver.Stub {
return mTetherableBluetoothRegexs;
}
+ public int setUsbTethering(boolean enable) {
+ UsbManager usbManager = (UsbManager)mContext.getSystemService(Context.USB_SERVICE);
+
+ synchronized (this) {
+ if (enable) {
+ if (mRndisEnabled) {
+ tetherUsb(true);
+ } else {
+ mUsbTetherRequested = true;
+ usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false);
+ }
+ } else {
+ tetherUsb(false);
+ if (mRndisEnabled) {
+ usbManager.setCurrentFunction(null, false);
+ }
+ mUsbTetherRequested = false;
+ }
+ }
+ return ConnectivityManager.TETHER_ERROR_NO_ERROR;
+ }
+
public int[] getUpstreamIfaceTypes() {
int values[] = new int[mUpstreamIfaceTypes.size()];
Iterator<Integer> iterator = mUpstreamIfaceTypes.iterator();
diff --git a/services/java/com/android/server/connectivity/Vpn.java b/services/java/com/android/server/connectivity/Vpn.java
index cf75d6b..9cb772e 100644
--- a/services/java/com/android/server/connectivity/Vpn.java
+++ b/services/java/com/android/server/connectivity/Vpn.java
@@ -396,7 +396,7 @@ public class Vpn extends INetworkManagementEventObserver.Stub {
if (mTimer == -1) {
mTimer = now;
Thread.sleep(1);
- } else if (now - mTimer <= 30000) {
+ } else if (now - mTimer <= 60000) {
Thread.sleep(yield ? 200 : 1);
} else {
mInfo.state = LegacyVpnInfo.STATE_TIMEOUT;
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java
index d6a15e6..9eb1179 100644
--- a/services/java/com/android/server/pm/PackageManagerService.java
+++ b/services/java/com/android/server/pm/PackageManagerService.java
@@ -2860,8 +2860,17 @@ public class PackageManagerService extends IPackageManager.Stub {
}
private File getDataPathForPackage(String packageName, int userId) {
- return new File(mUserAppDataDir.getAbsolutePath() + File.separator + userId
+ /*
+ * Until we fully support multiple users, return the directory we
+ * previously would have. The PackageManagerTests will need to be
+ * revised when this is changed back..
+ */
+ if (userId == 0) {
+ return new File(mAppDataDir, packageName);
+ } else {
+ return new File(mUserAppDataDir.getAbsolutePath() + File.separator + userId
+ File.separator + packageName);
+ }
}
private PackageParser.Package scanPackageLI(PackageParser.Package pkg,
diff --git a/services/java/com/android/server/wm/BlackFrame.java b/services/java/com/android/server/wm/BlackFrame.java
index d8fd7fe..36f5dcb 100644
--- a/services/java/com/android/server/wm/BlackFrame.java
+++ b/services/java/com/android/server/wm/BlackFrame.java
@@ -32,10 +32,12 @@ public class BlackFrame {
final int top;
final Surface surface;
- BlackSurface(SurfaceSession session, int layer, int l, int t, int w, int h)
+ BlackSurface(SurfaceSession session, int layer, int l, int t, int r, int b)
throws Surface.OutOfResourcesException {
left = l;
top = t;
+ int w = r-l;
+ int h = b-t;
surface = new Surface(session, 0, "BlackSurface",
-1, w, h, PixelFormat.OPAQUE, Surface.FX_SURFACE_DIM);
if (WindowManagerService.SHOW_TRANSACTIONS ||
diff --git a/services/surfaceflinger/SurfaceTextureLayer.cpp b/services/surfaceflinger/SurfaceTextureLayer.cpp
index 11f61cc..91e010f 100644
--- a/services/surfaceflinger/SurfaceTextureLayer.cpp
+++ b/services/surfaceflinger/SurfaceTextureLayer.cpp
@@ -60,7 +60,11 @@ status_t SurfaceTextureLayer::queueBuffer(int buf, int64_t timestamp,
sp<Layer> layer(mLayer.promote());
if (layer != NULL) {
- *outTransform = layer->getOrientation();
+ uint32_t orientation = layer->getOrientation();
+ if (orientation & Transform::ROT_INVALID) {
+ orientation = 0;
+ }
+ *outTransform = orientation;
}
return res;
diff --git a/services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java
index 1234bfd..46bcc4a 100644
--- a/services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/AccessibilityManagerServiceTest.java
@@ -29,12 +29,13 @@ import android.provider.Settings;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.IAccessibilityManager;
import android.view.accessibility.IAccessibilityManagerClient;
/**
* This test exercises the
- * {@link com.android.server.AccessibilityManagerService} by mocking the
+ * {@link com.android.server.accessibility.AccessibilityManagerService} by mocking the
* {@link android.view.accessibility.AccessibilityManager} which talks to to the
* service. The service itself is interacting with the platform. Note: Testing
* the service in full isolation would require significant amount of work for
@@ -97,7 +98,9 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase {
MyMockAccessibilityManagerClient mockClient = new MyMockAccessibilityManagerClient();
// invoke the method under test
- boolean enabledAccessibilityDisabled = mManagerService.addClient(mockClient);
+ final int stateFlagsDisabled = mManagerService.addClient(mockClient);
+ boolean enabledAccessibilityDisabled =
+ (stateFlagsDisabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
// check expected result
assertFalse("The client must be disabled since accessibility is disabled.",
@@ -107,7 +110,10 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase {
ensureAccessibilityEnabled(mContext, true);
// invoke the method under test
- boolean enabledAccessibilityEnabled = mManagerService.addClient(mockClient);
+ final int stateFlagsEnabled = mManagerService.addClient(mockClient);
+ boolean enabledAccessibilityEnabled =
+ (stateFlagsEnabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
+
// check expected result
assertTrue("The client must be enabled since accessibility is enabled.",
@@ -123,7 +129,9 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase {
MyMockAccessibilityManagerClient mockClient = new MyMockAccessibilityManagerClient();
// invoke the method under test
- boolean enabledAccessibilityEnabled = mManagerService.addClient(mockClient);
+ final int stateFlagsEnabled = mManagerService.addClient(mockClient);
+ boolean enabledAccessibilityEnabled =
+ (stateFlagsEnabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
// check expected result
assertTrue("The client must be enabled since accessibility is enabled.",
@@ -133,7 +141,9 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase {
ensureAccessibilityEnabled(mContext, false);
// invoke the method under test
- boolean enabledAccessibilityDisabled = mManagerService.addClient(mockClient);
+ final int stateFlagsDisabled = mManagerService.addClient(mockClient);
+ boolean enabledAccessibilityDisabled =
+ (stateFlagsDisabled & AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED) != 0;
// check expected result
assertFalse("The client must be disabled since accessibility is disabled.",
@@ -537,10 +547,10 @@ public class AccessibilityManagerServiceTest extends AndroidTestCase {
* This class is a mock {@link IAccessibilityManagerClient}.
*/
public class MyMockAccessibilityManagerClient extends IAccessibilityManagerClient.Stub {
- boolean mIsEnabled;
+ int mState;
- public void setEnabled(boolean enabled) {
- mIsEnabled = enabled;
+ public void setState(int state) {
+ mState = state;
}
public void setTouchExplorationEnabled(boolean enabled) {
diff --git a/services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java b/services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java
index 1463d30..e083815 100644
--- a/services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/AccessibilityManagerTest.java
@@ -70,7 +70,8 @@ public class AccessibilityManagerTest extends AndroidTestCase {
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
- expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(true);
+ expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(
+ AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
expect(mockServiceInterface.getInstalledAccessibilityServiceList()).andReturn(
expectedServices);
replay(mockServiceInterface);
@@ -91,7 +92,8 @@ public class AccessibilityManagerTest extends AndroidTestCase {
public void testInterrupt() throws Exception {
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
- expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(true);
+ expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(
+ AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
mockServiceInterface.interrupt();
replay(mockServiceInterface);
@@ -107,7 +109,8 @@ public class AccessibilityManagerTest extends AndroidTestCase {
public void testIsEnabled() throws Exception {
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
- expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(true);
+ expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(
+ AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
replay(mockServiceInterface);
// invoke the method under test
@@ -118,7 +121,7 @@ public class AccessibilityManagerTest extends AndroidTestCase {
assertTrue("Must be enabled since the mock service is enabled", isEnabledServiceEnabled);
// disable accessibility
- manager.getClient().setEnabled(false);
+ manager.getClient().setState(0);
// wait for the asynchronous IBinder call to complete
Thread.sleep(TIMEOUT_BINDER_CALL);
@@ -141,7 +144,8 @@ public class AccessibilityManagerTest extends AndroidTestCase {
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
- expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(true);
+ expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(
+ AccessibilityManager.STATE_FLAG_ACCESSIBILITY_ENABLED);
expect(mockServiceInterface.sendAccessibilityEvent(eqAccessibilityEvent(sentEvent)))
.andReturn(true);
expect(mockServiceInterface.sendAccessibilityEvent(eqAccessibilityEvent(sentEvent)))
@@ -176,7 +180,7 @@ public class AccessibilityManagerTest extends AndroidTestCase {
// configure the mock service behavior
IAccessibilityManager mockServiceInterface = mMockServiceInterface;
- expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(false);
+ expect(mockServiceInterface.addClient(anyIAccessibilityManagerClient())).andReturn(0);
replay(mockServiceInterface);
// invoke the method under test (accessibility disabled)
diff --git a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
index 4f8b525..3bd78e0 100644
--- a/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/DataConnectionTracker.java
@@ -36,6 +36,7 @@ import android.os.Messenger;
import android.os.SystemProperties;
import android.preference.PreferenceManager;
import android.provider.Settings;
+import android.telephony.ServiceState;
import android.provider.Settings.SettingNotFoundException;
import android.text.TextUtils;
import android.util.Log;
@@ -1031,6 +1032,27 @@ public abstract class DataConnectionTracker extends Handler {
protected void onSetDependencyMet(String apnType, boolean met) {
}
+ protected String getReryConfig(boolean forDefault) {
+ int rt = mPhone.getServiceState().getRadioTechnology();
+
+ if ((rt == ServiceState.RADIO_TECHNOLOGY_IS95A) ||
+ (rt == ServiceState.RADIO_TECHNOLOGY_IS95B) ||
+ (rt == ServiceState.RADIO_TECHNOLOGY_1xRTT) ||
+ (rt == ServiceState.RADIO_TECHNOLOGY_EVDO_0) ||
+ (rt == ServiceState.RADIO_TECHNOLOGY_EVDO_A) ||
+ (rt == ServiceState.RADIO_TECHNOLOGY_EVDO_B) ||
+ (rt == ServiceState.RADIO_TECHNOLOGY_EHRPD)) {
+ // CDMA variant
+ return SystemProperties.get("ro.cdma.data_retry_config");
+ } else {
+ // Use GSM varient for all others.
+ if (forDefault) {
+ return SystemProperties.get("ro.gsm.data_retry_config");
+ } else {
+ return SystemProperties.get("ro.gsm.2nd_data_retry_config");
+ }
+ }
+ }
protected void resetAllRetryCounts() {
for (DataConnection dc : mDataConnections.values()) {
diff --git a/telephony/java/com/android/internal/telephony/RILConstants.java b/telephony/java/com/android/internal/telephony/RILConstants.java
index 93fc9ce..facee5f 100644
--- a/telephony/java/com/android/internal/telephony/RILConstants.java
+++ b/telephony/java/com/android/internal/telephony/RILConstants.java
@@ -31,6 +31,8 @@ public interface RILConstants {
// From the top of ril.cpp
int RIL_ERRNO_INVALID_RESPONSE = -1;
+ int MAX_INT = 0x7FFFFFFF;
+
// from RIL_Errno
int SUCCESS = 0;
int RADIO_NOT_AVAILABLE = 1; /* If radio did not start or is resetting */
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
index 5df2edd..d3bb6a5 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
@@ -247,10 +247,11 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
boolean hasLocationChanged = !newCellLoc.equals(cellLoc);
boolean has4gHandoff =
- ((networkType == ServiceState.RADIO_TECHNOLOGY_LTE) &&
- (newNetworkType == ServiceState.RADIO_TECHNOLOGY_EHRPD)) ||
- ((networkType == ServiceState.RADIO_TECHNOLOGY_EHRPD) &&
- (newNetworkType == ServiceState.RADIO_TECHNOLOGY_LTE));
+ mNewDataConnectionState == ServiceState.STATE_IN_SERVICE &&
+ (((networkType == ServiceState.RADIO_TECHNOLOGY_LTE) &&
+ (newNetworkType == ServiceState.RADIO_TECHNOLOGY_EHRPD)) ||
+ ((networkType == ServiceState.RADIO_TECHNOLOGY_EHRPD) &&
+ (newNetworkType == ServiceState.RADIO_TECHNOLOGY_LTE)));
boolean hasMultiApnSupport =
(((newNetworkType == ServiceState.RADIO_TECHNOLOGY_LTE) ||
@@ -391,7 +392,7 @@ public class CdmaLteServiceStateTracker extends CdmaServiceStateTracker {
phone.notifyServiceStateChanged(ss);
}
- if (hasCdmaDataConnectionAttached) {
+ if (hasCdmaDataConnectionAttached || has4gHandoff) {
mAttachedRegistrants.notifyRegistrants();
}
diff --git a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
index ccdb0bf..be129d5 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmDataConnectionTracker.java
@@ -609,9 +609,20 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
for (DataConnectionAc dcac : mDataConnectionAsyncChannels.values()) {
if (dcac.getReconnectIntentSync() != null) {
cancelReconnectAlarm(dcac);
- if (dcac.dataConnection != null) {
- dcac.dataConnection.resetRetryCount();
+ }
+ // update retry config for existing calls to match up
+ // ones for the new RAT.
+ if (dcac.dataConnection != null) {
+ Collection<ApnContext> apns = dcac.getApnListSync();
+
+ boolean hasDefault = false;
+ for (ApnContext apnContext : apns) {
+ if (apnContext.getApnType().equals(Phone.APN_TYPE_DEFAULT)) {
+ hasDefault = true;
+ break;
+ }
}
+ configureRetry(dcac.dataConnection, hasDefault);
}
}
@@ -973,7 +984,7 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
// configure retry count if no other Apn is using the same connection.
if (refCount == 0) {
- configureRetry(dc, apnContext.getApnType());
+ configureRetry(dc, apn.canHandleType(Phone.APN_TYPE_DEFAULT));
}
apnContext.setDataConnectionAc(dcac);
apnContext.setDataConnection(dc);
@@ -1834,7 +1845,11 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
retryOverride =
((DataConnection.CallSetupException)ar.exception).getRetryOverride();
}
- startDelayedRetry(cause, apnContext, retryOverride);
+ if (retryOverride == RILConstants.MAX_INT) {
+ if (DBG) log("No retry is suggested.");
+ } else {
+ startDelayedRetry(cause, apnContext, retryOverride);
+ }
}
} else {
if (DBG) log("onDataSetupComplete: Try next APN");
@@ -2022,20 +2037,18 @@ public final class GsmDataConnectionTracker extends DataConnectionTracker {
return conn;
}
- private void configureRetry(DataConnection dc, String apnType) {
- if ((dc == null) || (apnType == null)) return;
+ private void configureRetry(DataConnection dc, boolean forDefault) {
+ if (dc == null) return;
- if (apnType.equals(Phone.APN_TYPE_DEFAULT)) {
- if (!dc.configureRetry(SystemProperties.get("ro.gsm.data_retry_config"))) {
+ if (!dc.configureRetry(getReryConfig(forDefault))) {
+ if (forDefault) {
if (!dc.configureRetry(DEFAULT_DATA_RETRY_CONFIG)) {
// Should never happen, log an error and default to a simple linear sequence.
loge("configureRetry: Could not configure using " +
"DEFAULT_DATA_RETRY_CONFIG=" + DEFAULT_DATA_RETRY_CONFIG);
dc.configureRetry(20, 2000, 1000);
}
- }
- } else {
- if (!dc.configureRetry(SystemProperties.get("ro.gsm.2nd_data_retry_config"))) {
+ } else {
if (!dc.configureRetry(SECONDARY_DATA_RETRY_CONFIG)) {
// Should never happen, log an error and default to a simple sequence.
loge("configureRetry: Could note configure using " +
diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index e776463..9aa70b0 100644
--- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -87,8 +87,6 @@ public class ImageProcessingActivity extends Activity
mIsProcessing = false;
}
- // This is a hack to work around an invalidation bug
- mBitmapOut.setPixel(0, 0, 0);
mOutPixelsAllocation.copyTo(mBitmapOut);
mDisplayView.invalidate();
}
diff --git a/wifi/java/android/net/wifi/StateChangeResult.java b/wifi/java/android/net/wifi/StateChangeResult.java
new file mode 100644
index 0000000..8ab5982
--- /dev/null
+++ b/wifi/java/android/net/wifi/StateChangeResult.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+ package android.net.wifi;
+
+/**
+ * Stores supplicant state change information passed from WifiMonitor to
+ * a state machine. WifiStateMachine, SupplicantStateTracker and WpsStateMachine
+ * are example state machines that handle it.
+ * @hide
+ */
+public class StateChangeResult {
+ StateChangeResult(int networkId, String BSSID, SupplicantState state) {
+ this.state = state;
+ this.BSSID = BSSID;
+ this.networkId = networkId;
+ }
+ int networkId;
+ String BSSID;
+ SupplicantState state;
+}
diff --git a/wifi/java/android/net/wifi/SupplicantStateTracker.java b/wifi/java/android/net/wifi/SupplicantStateTracker.java
index 0c4f9f6..9168e62 100644
--- a/wifi/java/android/net/wifi/SupplicantStateTracker.java
+++ b/wifi/java/android/net/wifi/SupplicantStateTracker.java
@@ -19,7 +19,7 @@ package android.net.wifi;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
-import android.net.wifi.WifiStateMachine.StateChangeResult;
+import android.net.wifi.StateChangeResult;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
@@ -159,11 +159,11 @@ class SupplicantStateTracker extends StateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch (message.what) {
- case WifiStateMachine.AUTHENTICATION_FAILURE_EVENT:
+ case WifiMonitor.AUTHENTICATION_FAILURE_EVENT:
mAuthenticationFailuresCount++;
mAuthFailureInSupplicantBroadcast = true;
break;
- case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
SupplicantState state = stateChangeResult.state;
sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast);
@@ -251,7 +251,7 @@ class SupplicantStateTracker extends StateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch (message.what) {
- case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
SupplicantState state = stateChangeResult.state;
if (SupplicantState.isHandshakeState(state)) {
@@ -293,7 +293,7 @@ class SupplicantStateTracker extends StateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch(message.what) {
- case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
SupplicantState state = stateChangeResult.state;
sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast);
diff --git a/wifi/java/android/net/wifi/WifiMonitor.java b/wifi/java/android/net/wifi/WifiMonitor.java
index 4ec4cfc..2ccc8a2 100644
--- a/wifi/java/android/net/wifi/WifiMonitor.java
+++ b/wifi/java/android/net/wifi/WifiMonitor.java
@@ -16,15 +16,24 @@
package android.net.wifi;
-import android.util.Log;
import android.net.NetworkInfo;
+import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.net.wifi.p2p.WifiP2pGroup;
+import android.net.wifi.StateChangeResult;
+import android.os.Message;
+import android.util.Log;
+
+
+import com.android.internal.util.Protocol;
+import com.android.internal.util.StateMachine;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
/**
* Listens for events from the wpa_supplicant server, and passes them on
- * to the {@link WifiStateMachine} for handling. Runs in its own thread.
+ * to the {@link StateMachine} for handling. Runs in its own thread.
*
* @hide
*/
@@ -45,16 +54,16 @@ public class WifiMonitor {
private static final int UNKNOWN = 9;
/** All events coming from the supplicant start with this prefix */
- private static final String eventPrefix = "CTRL-EVENT-";
- private static final int eventPrefixLen = eventPrefix.length();
+ private static final String EVENT_PREFIX_STR = "CTRL-EVENT-";
+ private static final int EVENT_PREFIX_LEN_STR = EVENT_PREFIX_STR.length();
/** All WPA events coming from the supplicant start with this prefix */
- private static final String wpaEventPrefix = "WPA:";
- private static final String passwordKeyMayBeIncorrectEvent =
+ private static final String WPA_EVENT_PREFIX_STR = "WPA:";
+ private static final String PASSWORD_MAY_BE_INCORRECT_STR =
"pre-shared key may be incorrect";
/* WPS events */
- private static final String wpsOverlapEvent = "WPS-OVERLAP-DETECTED";
+ private static final String WPS_OVERLAP_STR = "WPS-OVERLAP-DETECTED";
/**
* Names of events from wpa_supplicant (minus the prefix). In the
@@ -68,26 +77,26 @@ public class WifiMonitor {
* </pre>
* <code>xx:xx:xx:xx:xx:xx</code> is the BSSID of the associated access point
*/
- private static final String connectedEvent = "CONNECTED";
+ private static final String CONNECTED_STR = "CONNECTED";
/**
* <pre>
* CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys
* </pre>
*/
- private static final String disconnectedEvent = "DISCONNECTED";
+ private static final String DISCONNECTED_STR = "DISCONNECTED";
/**
* <pre>
* CTRL-EVENT-STATE-CHANGE x
* </pre>
* <code>x</code> is the numerical value of the new state.
*/
- private static final String stateChangeEvent = "STATE-CHANGE";
+ private static final String STATE_CHANGE_STR = "STATE-CHANGE";
/**
* <pre>
* CTRL-EVENT-SCAN-RESULTS ready
* </pre>
*/
- private static final String scanResultsEvent = "SCAN-RESULTS";
+ private static final String SCAN_RESULTS_STR = "SCAN-RESULTS";
/**
* <pre>
@@ -95,32 +104,32 @@ public class WifiMonitor {
* </pre>
* {@code x} is the link speed in Mb/sec.
*/
- private static final String linkSpeedEvent = "LINK-SPEED";
+ private static final String LINK_SPEED_STR = "LINK-SPEED";
/**
* <pre>
* CTRL-EVENT-TERMINATING - signal x
* </pre>
* <code>x</code> is the signal that caused termination.
*/
- private static final String terminatingEvent = "TERMINATING";
+ private static final String TERMINATING_STR = "TERMINATING";
/**
* <pre>
* CTRL-EVENT-DRIVER-STATE state
* </pre>
* <code>state</code> can be HANGED
*/
- private static final String driverStateEvent = "DRIVER-STATE";
+ private static final String DRIVER_STATE_STR = "DRIVER-STATE";
/**
* <pre>
* CTRL-EVENT-EAP-FAILURE EAP authentication failed
* </pre>
*/
- private static final String eapFailureEvent = "EAP-FAILURE";
+ private static final String EAP_FAILURE_STR = "EAP-FAILURE";
/**
* This indicates an authentication failure on EAP FAILURE event
*/
- private static final String eapAuthFailure = "EAP authentication failed";
+ private static final String EAP_AUTH_FAILURE_STR = "EAP authentication failed";
/**
* Regex pattern for extracting an Ethernet-style MAC address from a string.
@@ -130,17 +139,116 @@ public class WifiMonitor {
private static Pattern mConnectedEventPattern =
Pattern.compile("((?:[0-9a-f]{2}:){5}[0-9a-f]{2}) .* \\[id=([0-9]+) ");
- private final WifiStateMachine mWifiStateMachine;
+ /** P2P events */
+ private static final String P2P_EVENT_PREFIX_STR = "P2P";
+
+ /* P2P-DEVICE-FOUND fa:7b:7a:42:02:13 p2p_dev_addr=fa:7b:7a:42:02:13 pri_dev_type=1-0050F204-1
+ name='p2p-TEST1' config_methods=0x188 dev_capab=0x27 group_capab=0x0 */
+ private static final String P2P_DEVICE_FOUND_STR = "P2P-DEVICE-FOUND";
+
+ /* P2P-DEVICE-LOST p2p_dev_addr=42:fc:89:e1:e2:27 */
+ private static final String P2P_DEVICE_LOST_STR = "P2P-DEVICE-LOST";
+
+ /* P2P-GO-NEG-REQUEST 42:fc:89:a8:96:09 dev_passwd_id=4 */
+ private static final String P2P_GO_NEG_REQUEST_STR = "P2P-GO-NEG-REQUEST";
+
+ private static final String P2P_GO_NEG_SUCCESS_STR = "P2P-GO-NEG-SUCCESS";
+
+ private static final String P2P_GO_NEG_FAILURE_STR = "P2P-GO-NEG-FAILURE";
+
+ private static final String P2P_GROUP_FORMATION_SUCCESS_STR =
+ "P2P-GROUP-FORMATION-SUCCESS";
+
+ private static final String P2P_GROUP_FORMATION_FAILURE_STR =
+ "P2P-GROUP-FORMATION-FAILURE";
+
+ /* P2P-GROUP-STARTED p2p-wlan0-0 [client|GO] ssid="DIRECT-W8" freq=2437
+ [psk=2182b2e50e53f260d04f3c7b25ef33c965a3291b9b36b455a82d77fd82ca15bc|passphrase="fKG4jMe3"]
+ go_dev_addr=fa:7b:7a:42:02:13 */
+ private static final String P2P_GROUP_STARTED_STR = "P2P-GROUP-STARTED";
+
+ /* P2P-GROUP-REMOVED p2p-wlan0-0 [client|GO] reason=REQUESTED */
+ private static final String P2P_GROUP_REMOVED_STR = "P2P-GROUP-REMOVED";
+
+ /* P2P-INVITATION-RECEIVED sa=fa:7b:7a:42:02:13 go_dev_addr=f8:7b:7a:42:02:13
+ bssid=fa:7b:7a:42:82:13 unknown-network */
+ private static final String P2P_INVITATION_RECEIVED_STR = "P2P-INVITATION-RECEIVED";
+
+ /* P2P-INVITATION-RESULT status=1 */
+ private static final String P2P_INVITATION_RESULT_STR = "P2P-INVITATION-RESULT";
+
+ /* P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
+ pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ group_capab=0x0 */
+ private static final String P2P_PROV_DISC_PBC_REQ_STR = "P2P-PROV-DISC-PBC-REQ";
+ /* P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
+ pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ group_capab=0x0 */
+ private static final String P2P_PROV_DISC_ENTER_PIN_STR = "P2P-PROV-DISC-ENTER-PIN";
+ /* P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 p2p_dev_addr=42:fc:89:e1:e2:27
+ pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ group_capab=0x0 */
+ private static final String P2P_PROV_DISC_SHOW_PIN_STR = "P2P-PROV-DISC-SHOW-PIN";
+
+ private static final String HOST_AP_EVENT_PREFIX_STR = "AP";
+ /* AP-STA-CONNECTED 42:fc:89:a8:96:09 */
+ private static final String AP_STA_CONNECTED_STR = "AP-STA-CONNECTED";
+ /* AP-STA-DISCONNECTED 42:fc:89:a8:96:09 */
+ private static final String AP_STA_DISCONNECTED_STR = "AP-STA-DISCONNECTED";
+
+ private final StateMachine mStateMachine;
+
+ /* Supplicant events reported to a state machine */
+ private static final int BASE = Protocol.BASE_WIFI_MONITOR;
+
+ /* Connection to supplicant established */
+ public static final int SUP_CONNECTION_EVENT = BASE + 1;
+ /* Connection to supplicant lost */
+ public static final int SUP_DISCONNECTION_EVENT = BASE + 2;
+ /* Network connection completed */
+ public static final int NETWORK_CONNECTION_EVENT = BASE + 3;
+ /* Network disconnection completed */
+ public static final int NETWORK_DISCONNECTION_EVENT = BASE + 4;
+ /* Scan results are available */
+ public static final int SCAN_RESULTS_EVENT = BASE + 5;
+ /* Supplicate state changed */
+ public static final int SUPPLICANT_STATE_CHANGE_EVENT = BASE + 6;
+ /* Password failure and EAP authentication failure */
+ public static final int AUTHENTICATION_FAILURE_EVENT = BASE + 7;
+ /* WPS overlap detected */
+ public static final int WPS_OVERLAP_EVENT = BASE + 8;
+ /* Driver was hung */
+ public static final int DRIVER_HUNG_EVENT = BASE + 9;
+
+ /* P2P events */
+ public static final int P2P_DEVICE_FOUND_EVENT = BASE + 21;
+ public static final int P2P_DEVICE_LOST_EVENT = BASE + 22;
+ public static final int P2P_GO_NEGOTIATION_REQUEST_EVENT = BASE + 23;
+ public static final int P2P_GO_NEGOTIATION_SUCCESS_EVENT = BASE + 25;
+ public static final int P2P_GO_NEGOTIATION_FAILURE_EVENT = BASE + 26;
+ public static final int P2P_GROUP_FORMATION_SUCCESS_EVENT = BASE + 27;
+ public static final int P2P_GROUP_FORMATION_FAILURE_EVENT = BASE + 28;
+ public static final int P2P_GROUP_STARTED_EVENT = BASE + 29;
+ public static final int P2P_GROUP_REMOVED_EVENT = BASE + 30;
+ public static final int P2P_INVITATION_RECEIVED_EVENT = BASE + 31;
+ public static final int P2P_INVITATION_RESULT_EVENT = BASE + 32;
+ public static final int P2P_PROV_DISC_PBC_REQ_EVENT = BASE + 33;
+ public static final int P2P_PROV_DISC_ENTER_PIN_EVENT = BASE + 34;
+ public static final int P2P_PROV_DISC_SHOW_PIN_EVENT = BASE + 35;
+
+ /* hostap events */
+ public static final int AP_STA_DISCONNECTED_EVENT = BASE + 41;
+ public static final int AP_STA_CONNECTED_EVENT = BASE + 42;
/**
* This indicates the supplicant connection for the monitor is closed
*/
- private static final String monitorSocketClosed = "connection closed";
+ private static final String MONITOR_SOCKET_CLOSED_STR = "connection closed";
/**
* This indicates a read error on the monitor socket conenction
*/
- private static final String wpaRecvError = "recv error";
+ private static final String WPA_RECV_ERROR_STR = "recv error";
/**
* Tracks consecutive receive errors
@@ -152,8 +260,8 @@ public class WifiMonitor {
*/
private static final int MAX_RECV_ERRORS = 10;
- public WifiMonitor(WifiStateMachine wifiStateMachine) {
- mWifiStateMachine = wifiStateMachine;
+ public WifiMonitor(StateMachine wifiStateMachine) {
+ mStateMachine = wifiStateMachine;
}
public void startMonitoring() {
@@ -170,9 +278,9 @@ public class WifiMonitor {
if (connectToSupplicant()) {
// Send a message indicating that it is now possible to send commands
// to the supplicant
- mWifiStateMachine.notifySupplicantConnection();
+ mStateMachine.sendMessage(SUP_CONNECTION_EVENT);
} else {
- mWifiStateMachine.notifySupplicantLost();
+ mStateMachine.sendMessage(SUP_DISCONNECTION_EVENT);
return;
}
@@ -181,20 +289,24 @@ public class WifiMonitor {
String eventStr = WifiNative.waitForEvent();
// Skip logging the common but mostly uninteresting scan-results event
- if (false && eventStr.indexOf(scanResultsEvent) == -1) {
- Log.v(TAG, "Event [" + eventStr + "]");
+ if (false && eventStr.indexOf(SCAN_RESULTS_STR) == -1) {
+ Log.d(TAG, "Event [" + eventStr + "]");
}
- if (!eventStr.startsWith(eventPrefix)) {
- if (eventStr.startsWith(wpaEventPrefix) &&
- 0 < eventStr.indexOf(passwordKeyMayBeIncorrectEvent)) {
- mWifiStateMachine.notifyAuthenticationFailure();
- } else if (eventStr.startsWith(wpsOverlapEvent)) {
- mWifiStateMachine.notifyWpsOverlap();
+ if (!eventStr.startsWith(EVENT_PREFIX_STR)) {
+ if (eventStr.startsWith(WPA_EVENT_PREFIX_STR) &&
+ 0 < eventStr.indexOf(PASSWORD_MAY_BE_INCORRECT_STR)) {
+ mStateMachine.sendMessage(AUTHENTICATION_FAILURE_EVENT);
+ } else if (eventStr.startsWith(WPS_OVERLAP_STR)) {
+ mStateMachine.sendMessage(WPS_OVERLAP_EVENT);
+ } else if (eventStr.startsWith(P2P_EVENT_PREFIX_STR)) {
+ handleP2pEvents(eventStr);
+ } else if (eventStr.startsWith(HOST_AP_EVENT_PREFIX_STR)) {
+ handleHostApEvents(eventStr);
}
continue;
}
- String eventName = eventStr.substring(eventPrefixLen);
+ String eventName = eventStr.substring(EVENT_PREFIX_LEN_STR);
int nameEnd = eventName.indexOf(' ');
if (nameEnd != -1)
eventName = eventName.substring(0, nameEnd);
@@ -206,21 +318,21 @@ public class WifiMonitor {
* Map event name into event enum
*/
int event;
- if (eventName.equals(connectedEvent))
+ if (eventName.equals(CONNECTED_STR))
event = CONNECTED;
- else if (eventName.equals(disconnectedEvent))
+ else if (eventName.equals(DISCONNECTED_STR))
event = DISCONNECTED;
- else if (eventName.equals(stateChangeEvent))
+ else if (eventName.equals(STATE_CHANGE_STR))
event = STATE_CHANGE;
- else if (eventName.equals(scanResultsEvent))
+ else if (eventName.equals(SCAN_RESULTS_STR))
event = SCAN_RESULTS;
- else if (eventName.equals(linkSpeedEvent))
+ else if (eventName.equals(LINK_SPEED_STR))
event = LINK_SPEED;
- else if (eventName.equals(terminatingEvent))
+ else if (eventName.equals(TERMINATING_STR))
event = TERMINATING;
- else if (eventName.equals(driverStateEvent))
+ else if (eventName.equals(DRIVER_STATE_STR))
event = DRIVER_STATE;
- else if (eventName.equals(eapFailureEvent))
+ else if (eventName.equals(EAP_FAILURE_STR))
event = EAP_FAILURE;
else
event = UNKNOWN;
@@ -249,7 +361,7 @@ public class WifiMonitor {
* If monitor socket is closed, we have already
* stopped the supplicant, simply exit the monitor thread
*/
- if (eventData.startsWith(monitorSocketClosed)) {
+ if (eventData.startsWith(MONITOR_SOCKET_CLOSED_STR)) {
if (false) {
Log.d(TAG, "Monitor socket is closed, exiting thread");
}
@@ -260,7 +372,7 @@ public class WifiMonitor {
* Close the supplicant connection if we see
* too many recv errors
*/
- if (eventData.startsWith(wpaRecvError)) {
+ if (eventData.startsWith(WPA_RECV_ERROR_STR)) {
if (++mRecvErrors > MAX_RECV_ERRORS) {
if (false) {
Log.d(TAG, "too many recv errors, closing connection");
@@ -271,11 +383,11 @@ public class WifiMonitor {
}
// notify and exit
- mWifiStateMachine.notifySupplicantLost();
+ mStateMachine.sendMessage(SUP_DISCONNECTION_EVENT);
break;
} else if (event == EAP_FAILURE) {
- if (eventData.startsWith(eapAuthFailure)) {
- mWifiStateMachine.notifyAuthenticationFailure();
+ if (eventData.startsWith(EAP_AUTH_FAILURE_STR)) {
+ mStateMachine.sendMessage(AUTHENTICATION_FAILURE_EVENT);
}
} else {
handleEvent(event, eventData);
@@ -305,7 +417,7 @@ public class WifiMonitor {
return;
}
if (state.equals("HANGED")) {
- mWifiStateMachine.notifyDriverHung();
+ mStateMachine.sendMessage(DRIVER_HUNG_EVENT);
}
}
@@ -326,7 +438,7 @@ public class WifiMonitor {
break;
case SCAN_RESULTS:
- mWifiStateMachine.notifyScanResultsAvailable();
+ mStateMachine.sendMessage(SCAN_RESULTS_EVENT);
break;
case UNKNOWN:
@@ -335,6 +447,59 @@ public class WifiMonitor {
}
/**
+ * Handle p2p events
+ */
+ private void handleP2pEvents(String dataString) {
+ if (dataString.startsWith(P2P_DEVICE_FOUND_STR)) {
+ mStateMachine.sendMessage(P2P_DEVICE_FOUND_EVENT, new WifiP2pDevice(dataString));
+ } else if (dataString.startsWith(P2P_DEVICE_LOST_STR)) {
+ mStateMachine.sendMessage(P2P_DEVICE_LOST_EVENT, new WifiP2pDevice(dataString));
+ } else if (dataString.startsWith(P2P_GO_NEG_REQUEST_STR)) {
+ mStateMachine.sendMessage(P2P_GO_NEGOTIATION_REQUEST_EVENT,
+ new WifiP2pConfig(dataString));
+ } else if (dataString.startsWith(P2P_GO_NEG_SUCCESS_STR)) {
+ mStateMachine.sendMessage(P2P_GO_NEGOTIATION_SUCCESS_EVENT);
+ } else if (dataString.startsWith(P2P_GO_NEG_FAILURE_STR)) {
+ mStateMachine.sendMessage(P2P_GO_NEGOTIATION_FAILURE_EVENT);
+ } else if (dataString.startsWith(P2P_GROUP_FORMATION_SUCCESS_STR)) {
+ mStateMachine.sendMessage(P2P_GROUP_FORMATION_SUCCESS_EVENT);
+ } else if (dataString.startsWith(P2P_GROUP_FORMATION_FAILURE_STR)) {
+ mStateMachine.sendMessage(P2P_GROUP_FORMATION_FAILURE_EVENT);
+ } else if (dataString.startsWith(P2P_GROUP_STARTED_STR)) {
+ mStateMachine.sendMessage(P2P_GROUP_STARTED_EVENT, new WifiP2pGroup(dataString));
+ } else if (dataString.startsWith(P2P_GROUP_REMOVED_STR)) {
+ mStateMachine.sendMessage(P2P_GROUP_REMOVED_EVENT, new WifiP2pGroup(dataString));
+ } else if (dataString.startsWith(P2P_INVITATION_RECEIVED_STR)) {
+ mStateMachine.sendMessage(P2P_INVITATION_RECEIVED_EVENT,
+ new WifiP2pGroup(dataString));
+ } else if (dataString.startsWith(P2P_INVITATION_RESULT_STR)) {
+ String[] tokens = dataString.split(" ");
+ if (tokens.length != 2) return;
+ String[] nameValue = tokens[1].split("=");
+ if (nameValue.length != 2) return;
+ mStateMachine.sendMessage(P2P_INVITATION_RESULT_EVENT, nameValue[1]);
+ } else if (dataString.startsWith(P2P_PROV_DISC_PBC_REQ_STR)) {
+ mStateMachine.sendMessage(P2P_PROV_DISC_PBC_REQ_EVENT,
+ new WifiP2pDevice(dataString));
+ } else if (dataString.startsWith(P2P_PROV_DISC_ENTER_PIN_STR)) {
+ mStateMachine.sendMessage(P2P_PROV_DISC_ENTER_PIN_EVENT,
+ new WifiP2pDevice(dataString));
+ }
+ }
+
+ /**
+ * Handle hostap events
+ */
+ private void handleHostApEvents(String dataString) {
+ String[] tokens = dataString.split(" ");
+ if (tokens[0].equals(AP_STA_CONNECTED_STR)) {
+ mStateMachine.sendMessage(AP_STA_CONNECTED_EVENT, tokens[1]);
+ } else if (tokens[0].equals(AP_STA_DISCONNECTED_STR)) {
+ mStateMachine.sendMessage(AP_STA_DISCONNECTED_EVENT, tokens[1]);
+ }
+ }
+
+ /**
* Handle the supplicant STATE-CHANGE event
* @param dataString New supplicant state string in the format:
* id=network-id state=new-state
@@ -383,7 +548,7 @@ public class WifiMonitor {
if (newSupplicantState == SupplicantState.INVALID) {
Log.w(TAG, "Invalid supplicant state: " + newState);
}
- mWifiStateMachine.notifySupplicantStateChange(networkId, BSSID, newSupplicantState);
+ notifySupplicantStateChange(networkId, BSSID, newSupplicantState);
}
}
@@ -403,7 +568,40 @@ public class WifiMonitor {
}
}
}
- mWifiStateMachine.notifyNetworkStateChange(newState, BSSID, networkId);
+ notifyNetworkStateChange(newState, BSSID, networkId);
+ }
+
+ /**
+ * Send the state machine a notification that the state of Wifi connectivity
+ * has changed.
+ * @param networkId the configured network on which the state change occurred
+ * @param newState the new network state
+ * @param BSSID when the new state is {@link DetailedState#CONNECTED
+ * NetworkInfo.DetailedState.CONNECTED},
+ * this is the MAC address of the access point. Otherwise, it
+ * is {@code null}.
+ */
+ void notifyNetworkStateChange(NetworkInfo.DetailedState newState, String BSSID, int netId) {
+ if (newState == NetworkInfo.DetailedState.CONNECTED) {
+ Message m = mStateMachine.obtainMessage(NETWORK_CONNECTION_EVENT,
+ netId, 0, BSSID);
+ mStateMachine.sendMessage(m);
+ } else {
+ Message m = mStateMachine.obtainMessage(NETWORK_DISCONNECTION_EVENT,
+ netId, 0, BSSID);
+ mStateMachine.sendMessage(m);
+ }
+ }
+
+ /**
+ * Send the state machine a notification that the state of the supplicant
+ * has changed.
+ * @param networkId the configured network on which the state change occurred
+ * @param newState the new {@code SupplicantState}
+ */
+ void notifySupplicantStateChange(int networkId, String BSSID, SupplicantState newState) {
+ mStateMachine.sendMessage(mStateMachine.obtainMessage(SUPPLICANT_STATE_CHANGE_EVENT,
+ new StateChangeResult(networkId, BSSID, newState)));
}
/**
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index f1f0fcc..3b043b3 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -16,6 +16,16 @@
package android.net.wifi;
+import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pGroup;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.util.Log;
+
+import java.io.InputStream;
+import java.lang.Process;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* Native calls for sending requests to the supplicant daemon, and for
* receiving asynchronous events. All methods of the form "xxxxCommand()"
@@ -28,6 +38,10 @@ package android.net.wifi;
* WifiStateTracker class except for waitForEvent() call which is
* on a separate monitor channel for WifiMonitor
*
+ * TODO: clean up the API and move the functionality from JNI to here. We should
+ * be able to get everything done with doBooleanCommand, doIntCommand and
+ * doStringCommand native commands
+ *
* {@hide}
*/
public class WifiNative {
@@ -186,4 +200,141 @@ public class WifiNative {
public native static void enableBackgroundScanCommand(boolean enable);
public native static void setScanIntervalCommand(int scanInterval);
+
+ private native static boolean doBooleanCommand(String command);
+
+ //STOPSHIP: remove this after native interface works and replace all
+ //calls to doBooleanTempCommand() with doBooleanCommand()
+ private static boolean doBooleanTempCommand(String command) {
+ try {
+ String str = "/system/bin/wpa_cli " + command;
+ Log.e("WifiNative", "===> " + str);
+ Runtime.getRuntime()
+ .exec(str).waitFor();
+ } catch (Exception e) {
+ Log.e("WifiNative", "exception with doBooleanTempCommand");
+ return false;
+ }
+ return true;
+ }
+
+ private static String doStringTempCommand(String command) {
+ String lines[] = null;
+ try {
+ String str = "/system/bin/wpa_cli " + command;
+ Log.e("WifiNative", "===> " + str);
+ Process p = Runtime.getRuntime()
+ .exec(str);
+ InputStream in = p.getInputStream();
+ p.waitFor();
+ byte[] bytes=new byte[in.available()];
+ in.read(bytes);
+ String s = new String(bytes);
+ Log.e("WifiNative", "====> doString: " + s);
+ lines = s.split("\\r?\\n");
+ } catch (Exception e) {
+ Log.e("WifiNative", "exception with doBooleanTempCommand");
+ return null;
+ }
+ return lines[1];
+ }
+
+ private native static int doIntCommand(String command);
+
+ private native static String doStringCommand(String command);
+
+ public static boolean p2pFind() {
+ return doBooleanTempCommand("p2p_find");
+ }
+
+ public static boolean p2pFind(int timeout) {
+ if (timeout <= 0) {
+ return p2pFind();
+ }
+ return doBooleanTempCommand("p2p_find " + timeout);
+ }
+
+ public static boolean p2pListen() {
+ return doBooleanTempCommand("p2p_listen");
+ }
+
+ public static boolean p2pListen(int timeout) {
+ if (timeout <= 0) {
+ return p2pListen();
+ }
+ return doBooleanTempCommand("p2p_listen " + timeout);
+ }
+
+ public static boolean p2pFlush() {
+ return doBooleanTempCommand("p2p_flush");
+ }
+
+ /* p2p_connect <peer device address> <pbc|pin|PIN#> [label|display|keypad]
+ [persistent] [join|auth] [go_intent=<0..15>] [freq=<in MHz>] */
+ public static String p2pConnect(WifiP2pConfig config) {
+ if (config == null) return null;
+ List<String> args = new ArrayList<String>();
+ WpsConfiguration wpsConfig = config.wpsConfig;
+ args.add(config.deviceAddress);
+
+ switch (wpsConfig.setup) {
+ case PBC:
+ args.add("pbc");
+ break;
+ case DISPLAY:
+ //TODO: pass the pin back for display
+ args.add("pin");
+ args.add("display");
+ break;
+ case KEYPAD:
+ args.add(wpsConfig.pin);
+ args.add("keypad");
+ break;
+ case LABEL:
+ args.add(wpsConfig.pin);
+ args.add("label");
+ default:
+ break;
+ }
+
+ if (config.isPersistent) args.add("persistent");
+ if (config.joinExistingGroup) args.add("join");
+
+ args.add("go_intent=" + config.groupOwnerIntent);
+ if (config.channel > 0) args.add("freq=" + config.channel);
+
+ String command = "p2p_connect ";
+ for (String s : args) command += s + " ";
+
+ return doStringTempCommand(command);
+ }
+
+ public static boolean p2pGroupAdd() {
+ return doBooleanTempCommand("p2p_group_add");
+ }
+
+ public static boolean p2pGroupRemove(String iface) {
+ if (iface == null) return false;
+ return doBooleanTempCommand("p2p_group_remove " + iface);
+ }
+
+ public static boolean p2pReject(String deviceAddress) {
+ return doBooleanTempCommand("p2p_reject " + deviceAddress);
+ }
+
+ /* Invite a peer to a group */
+ public static boolean p2pInvite(WifiP2pGroup group, String deviceAddress) {
+ if (group == null || deviceAddress == null) return false;
+ return doBooleanTempCommand("p2p_invite group=" + group.getInterface()
+ + " peer=" + deviceAddress + " go_dev_addr=" + group.getOwner().deviceAddress);
+ }
+
+ public static boolean p2pWpsPbc() {
+ return doBooleanTempCommand("wps_pbc");
+ }
+
+ public static boolean p2pWpsPin(String pin) {
+ return doBooleanTempCommand("wps_pin any " + pin);
+ }
+
}
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index f08bb6a..74c6b49 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -56,6 +56,8 @@ import android.net.NetworkInfo;
import android.net.NetworkInfo.DetailedState;
import android.net.NetworkUtils;
import android.net.wifi.WpsResult.Status;
+import android.net.wifi.p2p.WifiP2pManager;
+import android.net.wifi.StateChangeResult;
import android.os.Binder;
import android.os.IBinder;
import android.os.INetworkManagementService;
@@ -67,6 +69,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.WorkSource;
+import android.server.WifiP2pService;
import android.provider.Settings;
import android.util.EventLog;
import android.util.Log;
@@ -89,6 +92,14 @@ import java.util.regex.Pattern;
* Track the state of Wifi connectivity. All event handling is done here,
* and all changes in connectivity state are initiated here.
*
+ * Wi-Fi now supports three modes of operation: Client, Soft Ap and Direct
+ * In the current implementation, we do not support any concurrency and thus only
+ * one of Client, Soft Ap or Direct operation is supported at any time.
+ *
+ * The WifiStateMachine supports Soft Ap and Client operations while WifiP2pService
+ * handles Direct. WifiP2pService and WifiStateMachine co-ordinate to ensure only
+ * one exists at a certain time.
+ *
* @hide
*/
public class WifiStateMachine extends StateMachine {
@@ -97,7 +108,7 @@ public class WifiStateMachine extends StateMachine {
private static final String NETWORKTYPE = "WIFI";
private static final boolean DBG = false;
- /* TODO: fetch a configurable interface */
+ /* TODO: This is no more used with the hostapd code. Clean up */
private static final String SOFTAP_IFACE = "wl0.1";
private WifiMonitor mWifiMonitor;
@@ -167,6 +178,10 @@ public class WifiStateMachine extends StateMachine {
// Channel for sending replies.
private AsyncChannel mReplyChannel = new AsyncChannel();
+ private WifiP2pManager mWifiP2pManager;
+ //Used to initiate a connection with WifiP2pService
+ private AsyncChannel mWifiP2pChannel = new AsyncChannel();
+
// Event log tags (must be in sync with event-log-tags)
private static final int EVENTLOG_WIFI_STATE_CHANGED = 50021;
private static final int EVENTLOG_WIFI_EVENT_HANDLED = 50022;
@@ -208,27 +223,10 @@ public class WifiStateMachine extends StateMachine {
static final int CMD_SET_AP_CONFIG = BASE + 23;
/* Get the soft access point configuration */
static final int CMD_GET_AP_CONFIG = BASE + 24;
+ /* Set configuration on tether interface */
+ static final int CMD_TETHER_INTERFACE = BASE + 25;
- static final int CMD_BLUETOOTH_ADAPTER_STATE_CHANGE = BASE + 25;
-
- /* Supplicant events */
- /* Connection to supplicant established */
- static final int SUP_CONNECTION_EVENT = BASE + 31;
- /* Connection to supplicant lost */
- static final int SUP_DISCONNECTION_EVENT = BASE + 32;
- /* Network connection completed */
- static final int NETWORK_CONNECTION_EVENT = BASE + 33;
- /* Network disconnection completed */
- static final int NETWORK_DISCONNECTION_EVENT = BASE + 34;
- /* Scan results are available */
- static final int SCAN_RESULTS_EVENT = BASE + 35;
- /* Supplicate state changed */
- static final int SUPPLICANT_STATE_CHANGE_EVENT = BASE + 36;
- /* Password failure and EAP authentication failure */
- static final int AUTHENTICATION_FAILURE_EVENT = BASE + 37;
- /* WPS overlap detected */
- static final int WPS_OVERLAP_EVENT = BASE + 38;
-
+ static final int CMD_BLUETOOTH_ADAPTER_STATE_CHANGE = BASE + 26;
/* Supplicant commands */
/* Is supplicant alive ? */
@@ -330,6 +328,10 @@ public class WifiStateMachine extends StateMachine {
/* Reset the WPS state machine */
static final int CMD_RESET_WPS_STATE = BASE + 122;
+ /* Interaction with WifiP2pService */
+ public static final int WIFI_ENABLE_PENDING = BASE + 131;
+ public static final int P2P_ENABLE_PROCEED = BASE + 132;
+
private static final int CONNECT_MODE = 1;
private static final int SCAN_ONLY_MODE = 2;
@@ -421,8 +423,13 @@ public class WifiStateMachine extends StateMachine {
/* Waiting for WPS to be completed*/
private State mWaitForWpsCompletionState = new WaitForWpsCompletionState();
- /* Soft Ap is running */
+ /* Soft ap is running */
private State mSoftApStartedState = new SoftApStartedState();
+ /* Soft ap is running and we are tethered through connectivity service */
+ private State mTetheredState = new TetheredState();
+
+ /* Wait till p2p is disabled */
+ private State mWaitForP2pDisableState = new WaitForP2pDisableState();
/**
@@ -513,13 +520,9 @@ public class WifiStateMachine extends StateMachine {
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
-
ArrayList<String> available = intent.getStringArrayListExtra(
ConnectivityManager.EXTRA_AVAILABLE_TETHER);
- ArrayList<String> active = intent.getStringArrayListExtra(
- ConnectivityManager.EXTRA_ACTIVE_TETHER);
- updateTetherState(available, active);
-
+ sendMessage(CMD_TETHER_INTERFACE, available);
}
},new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));
@@ -559,6 +562,8 @@ public class WifiStateMachine extends StateMachine {
addState(mDriverStoppedState, mSupplicantStartedState);
addState(mSupplicantStoppingState, mDefaultState);
addState(mSoftApStartedState, mDefaultState);
+ addState(mTetheredState, mSoftApStartedState);
+ addState(mWaitForP2pDisableState, mDefaultState);
setInitialState(mInitialState);
@@ -1048,14 +1053,17 @@ public class WifiStateMachine extends StateMachine {
* Internal private functions
********************************************************/
- private void updateTetherState(ArrayList<String> available, ArrayList<String> tethered) {
-
- boolean wifiTethered = false;
- boolean wifiAvailable = false;
-
+ private void checkAndSetConnectivityInstance() {
if (mCm == null) {
mCm = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
}
+ }
+
+ private boolean startTethering(ArrayList<String> available) {
+
+ boolean wifiAvailable = false;
+
+ checkAndSetConnectivityInstance();
String[] wifiRegexs = mCm.getTetherableWifiRegexs();
@@ -1077,18 +1085,43 @@ public class WifiStateMachine extends StateMachine {
} catch (Exception e) {
Log.e(TAG, "Error configuring interface " + intf + ", :" + e);
setWifiApEnabled(null, false);
- return;
+ return false;
}
if(mCm.tether(intf) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
Log.e(TAG, "Error tethering on " + intf);
setWifiApEnabled(null, false);
- return;
+ return false;
}
- break;
+ return true;
}
}
}
+ // We found no interfaces to tether
+ return false;
+ }
+
+ private void stopTethering() {
+
+ checkAndSetConnectivityInstance();
+
+ /* Clear the interface config to allow dhcp correctly configure new
+ ip settings */
+ InterfaceConfiguration ifcg = null;
+ try {
+ ifcg = nwService.getInterfaceConfig(mInterfaceName);
+ if (ifcg != null) {
+ ifcg.addr = new LinkAddress(NetworkUtils.numericToInetAddress(
+ "0.0.0.0"), 0);
+ nwService.setInterfaceConfig(mInterfaceName, ifcg);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Error resetting interface " + mInterfaceName + ", :" + e);
+ }
+
+ if (mCm.untether(mInterfaceName) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
+ Log.e(TAG, "Untether initiate failed!");
+ }
}
/**
@@ -1616,12 +1649,15 @@ public class WifiStateMachine extends StateMachine {
if (currentStatus == SOFT_AP_STOPPED) {
nwService.startAccessPoint(config, mInterfaceName, SOFTAP_IFACE);
} else if (currentStatus == SOFT_AP_RUNNING) {
- nwService.setAccessPoint(config, mInterfaceName, SOFTAP_IFACE);
+ //nwService.setAccessPoint(config, mInterfaceName, SOFTAP_IFACE);
+ //TODO: when we have a control channel to hostapd, we should not need to do this
+ nwService.stopAccessPoint(mInterfaceName);
+ nwService.startAccessPoint(config, mInterfaceName, SOFTAP_IFACE);
}
} catch (Exception e) {
Log.e(TAG, "Exception in softap start " + e);
try {
- nwService.stopAccessPoint();
+ nwService.stopAccessPoint(mInterfaceName);
nwService.startAccessPoint(config, mInterfaceName, SOFTAP_IFACE);
} catch (Exception ee) {
Log.e(TAG, "Exception during softap restart : " + ee);
@@ -1631,105 +1667,6 @@ public class WifiStateMachine extends StateMachine {
return true;
}
-
- /*********************************************************
- * Notifications from WifiMonitor
- ********************************************************/
-
- /**
- * Stores supplicant state change information passed from WifiMonitor
- */
- static class StateChangeResult {
- StateChangeResult(int networkId, String BSSID, SupplicantState state) {
- this.state = state;
- this.BSSID = BSSID;
- this.networkId = networkId;
- }
- int networkId;
- String BSSID;
- SupplicantState state;
- }
-
- /**
- * Send the tracker a notification that a user provided
- * configuration caused authentication failure - this could
- * be a password failure or a EAP authentication failure
- */
- void notifyAuthenticationFailure() {
- sendMessage(AUTHENTICATION_FAILURE_EVENT);
- }
-
- /**
- * Send a notification that the supplicant has detected overlapped
- * WPS sessions
- */
- void notifyWpsOverlap() {
- sendMessage(WPS_OVERLAP_EVENT);
- }
-
- /**
- * Send the tracker a notification that a connection to the supplicant
- * daemon has been established.
- */
- void notifySupplicantConnection() {
- sendMessage(SUP_CONNECTION_EVENT);
- }
-
- /**
- * Send the tracker a notification that connection to the supplicant
- * daemon is lost
- */
- void notifySupplicantLost() {
- sendMessage(SUP_DISCONNECTION_EVENT);
- }
-
- /**
- * Send the tracker a notification that the state of Wifi connectivity
- * has changed.
- * @param networkId the configured network on which the state change occurred
- * @param newState the new network state
- * @param BSSID when the new state is {@link DetailedState#CONNECTED
- * NetworkInfo.DetailedState.CONNECTED},
- * this is the MAC address of the access point. Otherwise, it
- * is {@code null}.
- */
- void notifyNetworkStateChange(DetailedState newState, String BSSID, int networkId) {
- if (newState == NetworkInfo.DetailedState.CONNECTED) {
- sendMessage(obtainMessage(NETWORK_CONNECTION_EVENT, networkId, 0, BSSID));
- } else {
- sendMessage(obtainMessage(NETWORK_DISCONNECTION_EVENT, networkId, 0, BSSID));
- }
- }
-
- /**
- * Send the tracker a notification that the state of the supplicant
- * has changed.
- * @param networkId the configured network on which the state change occurred
- * @param newState the new {@code SupplicantState}
- */
- void notifySupplicantStateChange(int networkId, String BSSID, SupplicantState newState) {
- sendMessage(obtainMessage(SUPPLICANT_STATE_CHANGE_EVENT,
- new StateChangeResult(networkId, BSSID, newState)));
- }
-
- /**
- * Send the tracker a notification that a scan has completed, and results
- * are available.
- */
- void notifyScanResultsAvailable() {
- /**
- * Switch scan mode over to passive.
- * Turning off scan-only mode happens only in "Connect" mode
- */
- setScanType(false);
- sendMessage(SCAN_RESULTS_EVENT);
- }
-
- void notifyDriverHung() {
- setWifiEnabled(false);
- setWifiEnabled(true);
- }
-
/********************************************************
* HSM states
*******************************************************/
@@ -1739,6 +1676,18 @@ public class WifiStateMachine extends StateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch (message.what) {
+ case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
+ if (message.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
+ mWifiP2pChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
+ } else {
+ Log.e(TAG, "WifiP2pService connection failure, error=" + message.arg1);
+ }
+ break;
+ case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
+ Log.e(TAG, "WifiP2pService channel lost, message.arg1 =" + message.arg1);
+ //TODO: Re-establish connection to state machine after a delay
+ //mWifiP2pChannel.connect(mContext, getHandler(), mWifiP2pManager.getMessenger());
+ break;
case CMD_BLUETOOTH_ADAPTER_STATE_CHANGE:
mBluetoothConnectionActive = (message.arg1 !=
BluetoothAdapter.STATE_DISCONNECTED);
@@ -1774,18 +1723,19 @@ public class WifiStateMachine extends StateMachine {
case CMD_STOP_DRIVER:
case CMD_START_AP:
case CMD_STOP_AP:
+ case CMD_TETHER_INTERFACE:
case CMD_START_SCAN:
case CMD_DISCONNECT:
case CMD_RECONNECT:
case CMD_REASSOCIATE:
- case SUP_CONNECTION_EVENT:
- case SUP_DISCONNECTION_EVENT:
- case NETWORK_CONNECTION_EVENT:
- case NETWORK_DISCONNECTION_EVENT:
- case SCAN_RESULTS_EVENT:
- case SUPPLICANT_STATE_CHANGE_EVENT:
- case AUTHENTICATION_FAILURE_EVENT:
- case WPS_OVERLAP_EVENT:
+ case WifiMonitor.SUP_CONNECTION_EVENT:
+ case WifiMonitor.SUP_DISCONNECTION_EVENT:
+ case WifiMonitor.NETWORK_CONNECTION_EVENT:
+ case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
+ case WifiMonitor.SCAN_RESULTS_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.AUTHENTICATION_FAILURE_EVENT:
+ case WifiMonitor.WPS_OVERLAP_EVENT:
case CMD_BLACKLIST_NETWORK:
case CMD_CLEAR_BLACKLIST:
case CMD_SET_SCAN_MODE:
@@ -1802,11 +1752,20 @@ public class WifiStateMachine extends StateMachine {
case DhcpStateMachine.CMD_PRE_DHCP_ACTION:
case DhcpStateMachine.CMD_POST_DHCP_ACTION:
break;
+ case WifiMonitor.DRIVER_HUNG_EVENT:
+ setWifiEnabled(false);
+ setWifiEnabled(true);
+ break;
case CMD_START_WPS:
/* Return failure when the state machine cannot handle WPS initiation*/
mReplyChannel.replyToMessage(message, WifiManager.CMD_WPS_COMPLETED,
new WpsResult(Status.FAILURE));
break;
+ case WifiP2pService.P2P_ENABLE_PENDING:
+ // turn off wifi and defer to be handled in DriverUnloadedState
+ setWifiEnabled(false);
+ deferMessage(message);
+ break;
default:
Log.e(TAG, "Error! unhandled message" + message);
break;
@@ -1833,6 +1792,11 @@ public class WifiStateMachine extends StateMachine {
else {
transitionTo(mDriverUnloadedState);
}
+
+ //Connect to WifiP2pService
+ mWifiP2pManager = (WifiP2pManager) mContext.getSystemService(Context.WIFI_P2P_SERVICE);
+ mWifiP2pChannel.connect(mContext, getHandler(), mWifiP2pManager.getMessenger());
+
}
}
@@ -2048,7 +2012,11 @@ public class WifiStateMachine extends StateMachine {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch (message.what) {
case CMD_LOAD_DRIVER:
- transitionTo(mDriverLoadingState);
+ mWifiP2pChannel.sendMessage(WIFI_ENABLE_PENDING);
+ transitionTo(mWaitForP2pDisableState);
+ break;
+ case WifiP2pService.P2P_ENABLE_PENDING:
+ mReplyChannel.replyToMessage(message, P2P_ENABLE_PROCEED);
break;
default:
return NOT_HANDLED;
@@ -2082,7 +2050,7 @@ public class WifiStateMachine extends StateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch(message.what) {
- case SUP_CONNECTION_EVENT:
+ case WifiMonitor.SUP_CONNECTION_EVENT:
Log.d(TAG, "Supplicant connection established");
setWifiState(WIFI_STATE_ENABLED);
mSupplicantRestartCount = 0;
@@ -2102,7 +2070,7 @@ public class WifiStateMachine extends StateMachine {
sendSupplicantConnectionChangedBroadcast(true);
transitionTo(mDriverStartedState);
break;
- case SUP_DISCONNECTION_EVENT:
+ case WifiMonitor.SUP_DISCONNECTION_EVENT:
if (++mSupplicantRestartCount <= SUPPLICANT_RESTART_TRIES) {
Log.e(TAG, "Failed to setup control channel, restart supplicant");
WifiNative.killSupplicant();
@@ -2165,7 +2133,7 @@ public class WifiStateMachine extends StateMachine {
case CMD_STOP_SUPPLICANT: /* Supplicant stopped by user */
transitionTo(mSupplicantStoppingState);
break;
- case SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */
+ case WifiMonitor.SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */
Log.e(TAG, "Connection lost, restart supplicant");
WifiNative.killSupplicant();
WifiNative.closeSupplicantConnection();
@@ -2177,7 +2145,7 @@ public class WifiStateMachine extends StateMachine {
transitionTo(mDriverLoadedState);
sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
break;
- case SCAN_RESULTS_EVENT:
+ case WifiMonitor.SCAN_RESULTS_EVENT:
eventLoggingEnabled = false;
setScanResults(WifiNative.scanResultsCommand());
sendScanResultsAvailableBroadcast();
@@ -2279,10 +2247,10 @@ public class WifiStateMachine extends StateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch(message.what) {
- case SUP_CONNECTION_EVENT:
+ case WifiMonitor.SUP_CONNECTION_EVENT:
Log.e(TAG, "Supplicant connection received while stopping");
break;
- case SUP_DISCONNECTION_EVENT:
+ case WifiMonitor.SUP_DISCONNECTION_EVENT:
Log.d(TAG, "Supplicant connection lost");
WifiNative.closeSupplicantConnection();
transitionTo(mDriverLoadedState);
@@ -2322,7 +2290,7 @@ public class WifiStateMachine extends StateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch(message.what) {
- case SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
SupplicantState state = handleSupplicantStateChange(message);
/* If suplicant is exiting out of INTERFACE_DISABLED state into
* a state that indicates driver has started, it is ready to
@@ -2335,10 +2303,10 @@ public class WifiStateMachine extends StateMachine {
/* Queue driver commands & connection events */
case CMD_START_DRIVER:
case CMD_STOP_DRIVER:
- case NETWORK_CONNECTION_EVENT:
- case NETWORK_DISCONNECTION_EVENT:
- case AUTHENTICATION_FAILURE_EVENT:
- case WPS_OVERLAP_EVENT:
+ case WifiMonitor.NETWORK_CONNECTION_EVENT:
+ case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
+ case WifiMonitor.AUTHENTICATION_FAILURE_EVENT:
+ case WifiMonitor.WPS_OVERLAP_EVENT:
case CMD_SET_SCAN_TYPE:
case CMD_SET_HIGH_PERF_MODE:
case CMD_SET_COUNTRY_CODE:
@@ -2495,7 +2463,7 @@ public class WifiStateMachine extends StateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch(message.what) {
- case SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
SupplicantState state = handleSupplicantStateChange(message);
if (state == SupplicantState.INTERFACE_DISABLED) {
transitionTo(mDriverStoppedState);
@@ -2539,7 +2507,7 @@ public class WifiStateMachine extends StateMachine {
WifiNative.startDriverCommand();
mWakeLock.release();
break;
- case SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
SupplicantState state = handleSupplicantStateChange(message);
/* A driver start causes supplicant to first report an INTERFACE_DISABLED
* state before transitioning out of it for connection. Stay in
@@ -2585,9 +2553,9 @@ public class WifiStateMachine extends StateMachine {
case CMD_DISCONNECT:
case CMD_RECONNECT:
case CMD_REASSOCIATE:
- case SUPPLICANT_STATE_CHANGE_EVENT:
- case NETWORK_CONNECTION_EVENT:
- case NETWORK_DISCONNECTION_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.NETWORK_CONNECTION_EVENT:
+ case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
break;
default:
return NOT_HANDLED;
@@ -2608,14 +2576,14 @@ public class WifiStateMachine extends StateMachine {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
StateChangeResult stateChangeResult;
switch(message.what) {
- case AUTHENTICATION_FAILURE_EVENT:
- mSupplicantStateTracker.sendMessage(AUTHENTICATION_FAILURE_EVENT);
+ case WifiMonitor.AUTHENTICATION_FAILURE_EVENT:
+ mSupplicantStateTracker.sendMessage(WifiMonitor.AUTHENTICATION_FAILURE_EVENT);
break;
- case WPS_OVERLAP_EVENT:
+ case WifiMonitor.WPS_OVERLAP_EVENT:
/* We just need to broadcast the error */
sendErrorBroadcast(WifiManager.WPS_OVERLAP_ERROR);
break;
- case SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
handleSupplicantStateChange(message);
break;
/* Do a redundant disconnect without transition */
@@ -2657,12 +2625,12 @@ public class WifiStateMachine extends StateMachine {
mWpsStateMachine.sendMessage(Message.obtain(message));
transitionTo(mWaitForWpsCompletionState);
break;
- case SCAN_RESULTS_EVENT:
+ case WifiMonitor.SCAN_RESULTS_EVENT:
/* Set the scan setting back to "connect" mode */
WifiNative.setScanResultHandlingCommand(CONNECT_MODE);
/* Handle scan results */
return NOT_HANDLED;
- case NETWORK_CONNECTION_EVENT:
+ case WifiMonitor.NETWORK_CONNECTION_EVENT:
Log.d(TAG,"Network connection established");
mLastNetworkId = message.arg1;
mLastBssid = (String) message.obj;
@@ -2676,7 +2644,7 @@ public class WifiStateMachine extends StateMachine {
sendNetworkStateChangeBroadcast(mLastBssid);
transitionTo(mConnectingState);
break;
- case NETWORK_DISCONNECTION_EVENT:
+ case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
Log.d(TAG,"Network connection lost");
handleNetworkDisconnect();
transitionTo(mDisconnectedState);
@@ -2763,7 +2731,7 @@ public class WifiStateMachine extends StateMachine {
deferMessage(message);
break;
/* Ignore */
- case NETWORK_CONNECTION_EVENT:
+ case WifiMonitor.NETWORK_CONNECTION_EVENT:
break;
case CMD_STOP_DRIVER:
sendMessage(CMD_DISCONNECT);
@@ -2828,10 +2796,7 @@ public class WifiStateMachine extends StateMachine {
deferMessage(message);
break;
case CMD_REQUEST_CM_WAKELOCK:
- if (mCm == null) {
- mCm = (ConnectivityManager)mContext.getSystemService(
- Context.CONNECTIVITY_SERVICE);
- }
+ checkAndSetConnectivityInstance();
mCm.requestNetworkTransitionWakelock(TAG);
break;
case CMD_SET_SCAN_MODE:
@@ -2873,7 +2838,7 @@ public class WifiStateMachine extends StateMachine {
}
break;
/* Ignore */
- case NETWORK_CONNECTION_EVENT:
+ case WifiMonitor.NETWORK_CONNECTION_EVENT:
break;
case CMD_RSSI_POLL:
eventLoggingEnabled = false;
@@ -2934,7 +2899,7 @@ public class WifiStateMachine extends StateMachine {
}
break;
/* Handle in DisconnectedState */
- case SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
deferMessage(message);
break;
default:
@@ -3019,9 +2984,9 @@ public class WifiStateMachine extends StateMachine {
}
break;
/* Ignore network disconnect */
- case NETWORK_DISCONNECTION_EVENT:
+ case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
break;
- case SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
setNetworkDetailedState(WifiInfo.getDetailedStateOf(stateChangeResult.state));
/* ConnectModeState does the rest of the handling */
@@ -3033,7 +2998,7 @@ public class WifiStateMachine extends StateMachine {
}
/* Handled in parent state */
return NOT_HANDLED;
- case SCAN_RESULTS_EVENT:
+ case WifiMonitor.SCAN_RESULTS_EVENT:
/* Re-enable background scan when a pending scan result is received */
if (mEnableBackgroundScan && mScanResultIsPending) {
WifiNative.enableBackgroundScanCommand(true);
@@ -3076,10 +3041,10 @@ public class WifiStateMachine extends StateMachine {
case CMD_ENABLE_NETWORK:
case CMD_RECONNECT:
case CMD_REASSOCIATE:
- case NETWORK_CONNECTION_EVENT: /* Handled after IP & proxy update */
+ case WifiMonitor.NETWORK_CONNECTION_EVENT: /* Handled after IP & proxy update */
deferMessage(message);
break;
- case NETWORK_DISCONNECTION_EVENT:
+ case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
Log.d(TAG,"Network connection lost");
handleNetworkDisconnect();
break;
@@ -3109,16 +3074,9 @@ public class WifiStateMachine extends StateMachine {
case CMD_STOP_AP:
Log.d(TAG,"Stopping Soft AP");
setWifiApState(WIFI_AP_STATE_DISABLING);
-
- if (mCm == null) {
- mCm = (ConnectivityManager) mContext.getSystemService(
- Context.CONNECTIVITY_SERVICE);
- }
- if (mCm.untether(SOFTAP_IFACE) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {
- Log.e(TAG, "Untether initiate failed!");
- }
+ stopTethering();
try {
- nwService.stopAccessPoint();
+ nwService.stopAccessPoint(mInterfaceName);
} catch(Exception e) {
Log.e(TAG, "Exception in stopAccessPoint()");
}
@@ -3140,6 +3098,17 @@ public class WifiStateMachine extends StateMachine {
Log.e(TAG,"Cannot start supplicant with a running soft AP");
setWifiState(WIFI_STATE_UNKNOWN);
break;
+ case CMD_TETHER_INTERFACE:
+ ArrayList<String> available = (ArrayList<String>) message.obj;
+ if (startTethering(available)) {
+ transitionTo(mTetheredState);
+ }
+ break;
+ case WifiP2pService.P2P_ENABLE_PENDING:
+ // turn of soft Ap and defer to be handled in DriverUnloadedState
+ setWifiApEnabled(null, false);
+ deferMessage(message);
+ break;
default:
return NOT_HANDLED;
}
@@ -3147,4 +3116,68 @@ public class WifiStateMachine extends StateMachine {
return HANDLED;
}
}
+
+ class WaitForP2pDisableState extends State {
+ private int mSavedArg;
+ @Override
+ public void enter() {
+ if (DBG) Log.d(TAG, getName() + "\n");
+ EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
+
+ //Preserve the argument arg1 that has information used in DriverLoadingState
+ mSavedArg = getCurrentMessage().arg1;
+ }
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
+ switch(message.what) {
+ case WifiP2pService.WIFI_ENABLE_PROCEED:
+ //restore argument from original message (CMD_LOAD_DRIVER)
+ message.arg1 = mSavedArg;
+ transitionTo(mDriverLoadingState);
+ break;
+ case CMD_LOAD_DRIVER:
+ case CMD_UNLOAD_DRIVER:
+ case CMD_START_SUPPLICANT:
+ case CMD_STOP_SUPPLICANT:
+ case CMD_START_AP:
+ case CMD_STOP_AP:
+ case CMD_START_DRIVER:
+ case CMD_STOP_DRIVER:
+ case CMD_SET_SCAN_MODE:
+ case CMD_SET_SCAN_TYPE:
+ case CMD_SET_HIGH_PERF_MODE:
+ case CMD_SET_COUNTRY_CODE:
+ case CMD_SET_FREQUENCY_BAND:
+ case CMD_START_PACKET_FILTERING:
+ case CMD_STOP_PACKET_FILTERING:
+ deferMessage(message);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
+ return HANDLED;
+ }
+ }
+
+ class TetheredState extends State {
+ @Override
+ public void enter() {
+ if (DBG) Log.d(TAG, getName() + "\n");
+ EventLog.writeEvent(EVENTLOG_WIFI_STATE_CHANGED, getName());
+ }
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
+ switch(message.what) {
+ case CMD_TETHER_INTERFACE:
+ // Ignore any duplicate interface available notifications
+ // when in tethered state
+ return HANDLED;
+ default:
+ return NOT_HANDLED;
+ }
+ }
+ }
}
diff --git a/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java b/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java
index b09e04b..fa7cf21 100644
--- a/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java
@@ -68,7 +68,7 @@ import java.util.regex.Pattern;
public class WifiWatchdogStateMachine extends StateMachine {
- private static final boolean VDBG = true; //TODO : Remove this before merge
+ private static final boolean VDBG = false;
private static final boolean DBG = true;
private static final String WWSM_TAG = "WifiWatchdogStateMachine";
diff --git a/wifi/java/android/net/wifi/WpsConfiguration.java b/wifi/java/android/net/wifi/WpsConfiguration.java
index 12d951f..2e7689a 100644
--- a/wifi/java/android/net/wifi/WpsConfiguration.java
+++ b/wifi/java/android/net/wifi/WpsConfiguration.java
@@ -30,13 +30,16 @@ import java.util.BitSet;
*/
public class WpsConfiguration implements Parcelable {
+ /* Wi-Fi Protected Setup. www.wi-fi.org/wifi-protected-setup has details */
public enum Setup {
- /* Wi-Fi protected setup push button configuration */
+ /* Push button configuration */
PBC,
- /* Wi-Fi protected setup pin method configuration with pin obtained from access point */
- PIN_FROM_ACCESS_POINT,
- /* Wi-Fi protected setup pin method configuration with pin obtained from device */
- PIN_FROM_DEVICE,
+ /* Display pin method configuration - pin is generated and displayed on device */
+ DISPLAY,
+ /* Keypad pin method configuration - pin is entered on device */
+ KEYPAD,
+ /* Label pin method configuration - pin is obtained from a printed label */
+ LABEL,
/* Invalid config */
INVALID
}
diff --git a/wifi/java/android/net/wifi/WpsStateMachine.java b/wifi/java/android/net/wifi/WpsStateMachine.java
index 120b228..af089ab 100644
--- a/wifi/java/android/net/wifi/WpsStateMachine.java
+++ b/wifi/java/android/net/wifi/WpsStateMachine.java
@@ -22,7 +22,7 @@ import com.android.internal.util.StateMachine;
import android.content.Context;
import android.content.Intent;
-import android.net.wifi.WifiStateMachine.StateChangeResult;
+import android.net.wifi.StateChangeResult;
import android.net.wifi.WpsResult.Status;
import android.os.Handler;
import android.os.Message;
@@ -99,10 +99,10 @@ class WpsStateMachine extends StateMachine {
case PBC:
result = WifiConfigStore.startWpsPbc(mWpsConfig);
break;
- case PIN_FROM_ACCESS_POINT:
+ case KEYPAD:
result = WifiConfigStore.startWpsWithPinFromAccessPoint(mWpsConfig);
break;
- case PIN_FROM_DEVICE:
+ case DISPLAY:
result = WifiConfigStore.startWpsWithPinFromDevice(mWpsConfig);
break;
default:
@@ -139,7 +139,7 @@ class WpsStateMachine extends StateMachine {
boolean retValue = HANDLED;
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch (message.what) {
- case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
SupplicantState supState = (SupplicantState) stateChangeResult.state;
switch (supState) {
@@ -194,7 +194,7 @@ class WpsStateMachine extends StateMachine {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
switch (message.what) {
//Ignore supplicant state changes
- case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
break;
default:
retValue = NOT_HANDLED;
diff --git a/wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl b/wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl
new file mode 100644
index 0000000..a0c7dd1
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/IWifiP2pManager.aidl
@@ -0,0 +1,31 @@
+/**
+ * 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.net.wifi.p2p;
+
+import android.os.Messenger;
+
+/**
+ * Interface that WifiP2pService implements
+ *
+ * {@hide}
+ */
+interface IWifiP2pManager
+{
+ Messenger getMessenger();
+ boolean isP2pSupported();
+}
+
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.aidl
new file mode 100644
index 0000000..ea3b280
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+parcelable WifiP2pConfig;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
new file mode 100644
index 0000000..fff5ee3
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pConfig.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+import android.net.wifi.WpsConfiguration;
+import android.net.wifi.WpsConfiguration.Setup;
+import android.os.Parcelable;
+import android.os.Parcel;
+
+/**
+ * A class representing a Wi-Fi P2p configuration
+ * @hide
+ */
+public class WifiP2pConfig implements Parcelable {
+
+ /**
+ * Device name
+ */
+ public String deviceName;
+
+ /**
+ * Device address
+ */
+ public String deviceAddress;
+
+ /**
+ * WPS configuration
+ */
+ public WpsConfiguration wpsConfig;
+
+ /**
+ * This is an integer value between 0 and 15 where 0 indicates the least
+ * inclination to be a group owner and 15 indicates the highest inclination
+ * to be a group owner.
+ */
+ public int groupOwnerIntent;
+
+ public boolean isPersistent;
+
+ public boolean joinExistingGroup;
+
+ /**
+ * Channel frequency in MHz
+ */
+ public int channel;
+
+ public WifiP2pConfig() {
+ //set defaults
+ wpsConfig = new WpsConfiguration();
+ wpsConfig.setup = Setup.PBC;
+ }
+
+ /* P2P-GO-NEG-REQUEST 42:fc:89:a8:96:09 dev_passwd_id=4 */
+ public WifiP2pConfig(String supplicantEvent) throws IllegalArgumentException {
+ String[] tokens = supplicantEvent.split(" ");
+
+ if (tokens.length < 2 || !tokens[0].equals("P2P-GO-NEG-REQUEST")) {
+ throw new IllegalArgumentException("Malformed supplicant event");
+ }
+
+ deviceAddress = tokens[1];
+ wpsConfig = new WpsConfiguration();
+
+ if (tokens.length > 2) {
+ String[] nameVal = tokens[2].split("=");
+ int devPasswdId;
+ try {
+ devPasswdId = Integer.parseInt(nameVal[1]);
+ } catch (NumberFormatException e) {
+ devPasswdId = 0;
+ }
+ //As defined in wps/wps_defs.h
+ switch (devPasswdId) {
+ case 0x00:
+ wpsConfig.setup = Setup.LABEL;
+ break;
+ case 0x01:
+ wpsConfig.setup = Setup.KEYPAD;
+ break;
+ case 0x04:
+ wpsConfig.setup = Setup.PBC;
+ break;
+ case 0x05:
+ wpsConfig.setup = Setup.DISPLAY;
+ break;
+ default:
+ wpsConfig.setup = Setup.PBC;
+ break;
+ }
+ }
+ }
+
+ public String toString() {
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append("Device: ").append(deviceName);
+ sbuf.append("\n address: ").append(deviceAddress);
+ sbuf.append("\n wps: ").append(wpsConfig);
+ sbuf.append("\n groupOwnerIntent: ").append(groupOwnerIntent);
+ sbuf.append("\n isPersistent: ").append(isPersistent);
+ sbuf.append("\n joinExistingGroup: ").append(joinExistingGroup);
+ sbuf.append("\n channel: ").append(channel);
+ return sbuf.toString();
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public int describeContents() {
+ return 0;
+ }
+
+ /** copy constructor {@hide} */
+ public WifiP2pConfig(WifiP2pConfig source) {
+ if (source != null) {
+ //TODO: implement
+ }
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(deviceName);
+ dest.writeString(deviceAddress);
+ dest.writeParcelable(wpsConfig, flags);
+ dest.writeInt(groupOwnerIntent);
+ dest.writeInt(isPersistent ? 1 : 0);
+ dest.writeInt(joinExistingGroup ? 1 : 0);
+ dest.writeInt(channel);
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public static final Creator<WifiP2pConfig> CREATOR =
+ new Creator<WifiP2pConfig>() {
+ public WifiP2pConfig createFromParcel(Parcel in) {
+ WifiP2pConfig config = new WifiP2pConfig();
+ config.deviceName = in.readString();
+ config.deviceAddress = in.readString();
+ config.wpsConfig = (WpsConfiguration) in.readParcelable(null);
+ config.groupOwnerIntent = in.readInt();
+ config.isPersistent = (in.readInt() == 1);
+ config.joinExistingGroup = (in.readInt() == 1);
+ config.channel = in.readInt();
+ return config;
+ }
+
+ public WifiP2pConfig[] newArray(int size) {
+ return new WifiP2pConfig[size];
+ }
+ };
+}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.aidl
new file mode 100644
index 0000000..8790c6f
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+parcelable WifiP2pDevice;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
new file mode 100644
index 0000000..83dc285
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDevice.java
@@ -0,0 +1,312 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+import android.os.Parcelable;
+import android.os.Parcel;
+import android.util.Log;
+
+import java.util.regex.Pattern;
+
+/**
+ * A class representing a Wi-Fi p2p device
+ * @hide
+ */
+public class WifiP2pDevice implements Parcelable {
+
+ private static final String TAG = "WifiP2pDevice";
+ /**
+ * Device name
+ */
+ public String deviceName;
+
+ /**
+ * Device MAC address
+ */
+ public String deviceAddress;
+
+ /**
+ * interfaceAddress
+ *
+ * This address is used during group owner negotiation as the Intended
+ * P2P Interface Address and the group interface will be created with
+ * address as the local address in case of successfully completed
+ * negotiation.
+ */
+ public String interfaceAddress;
+
+ /**
+ * Primary device type
+ */
+ public String primaryDeviceType;
+
+ /**
+ * Secondary device type
+ */
+ public String secondaryDeviceType;
+
+
+ // These definitions match the ones in wpa_supplicant
+ /* WPS config methods supported */
+ private static final int WPS_CONFIG_USBA = 0x0001;
+ private static final int WPS_CONFIG_ETHERNET = 0x0002;
+ private static final int WPS_CONFIG_LABEL = 0x0004;
+ private static final int WPS_CONFIG_DISPLAY = 0x0008;
+ private static final int WPS_CONFIG_EXT_NFC_TOKEN = 0x0010;
+ private static final int WPS_CONFIG_INT_NFC_TOKEN = 0x0020;
+ private static final int WPS_CONFIG_NFC_INTERFACE = 0x0040;
+ private static final int WPS_CONFIG_PUSHBUTTON = 0x0080;
+ private static final int WPS_CONFIG_KEYPAD = 0x0100;
+ private static final int WPS_CONFIG_VIRT_PUSHBUTTON = 0x0280;
+ private static final int WPS_CONFIG_PHY_PUSHBUTTON = 0x0480;
+ private static final int WPS_CONFIG_VIRT_DISPLAY = 0x2008;
+ private static final int WPS_CONFIG_PHY_DISPLAY = 0x4008;
+
+ /* Device Capability bitmap */
+ private static final int DEVICE_CAPAB_SERVICE_DISCOVERY = 1;
+ private static final int DEVICE_CAPAB_CLIENT_DISCOVERABILITY = 1<<1;
+ private static final int DEVICE_CAPAB_CONCURRENT_OPER = 1<<2;
+ private static final int DEVICE_CAPAB_INFRA_MANAGED = 1<<3;
+ private static final int DEVICE_CAPAB_DEVICE_LIMIT = 1<<4;
+ private static final int DEVICE_CAPAB_INVITATION_PROCEDURE = 1<<5;
+
+ /* Group Capability bitmap */
+ private static final int GROUP_CAPAB_GROUP_OWNER = 1;
+ private static final int GROUP_CAPAB_PERSISTENT_GROUP = 1<<1;
+ private static final int GROUP_CAPAB_GROUP_LIMIT = 1<<2;
+ private static final int GROUP_CAPAB_INTRA_BSS_DIST = 1<<3;
+ private static final int GROUP_CAPAB_CROSS_CONN = 1<<4;
+ private static final int GROUP_CAPAB_PERSISTENT_RECONN = 1<<5;
+ private static final int GROUP_CAPAB_GROUP_FORMATION = 1<<6;
+
+ /**
+ * WPS config methods supported
+ */
+ public int wpsConfigMethodsSupported;
+
+ /**
+ * Device capability
+ */
+ public int deviceCapability;
+
+ /**
+ * Group capability
+ */
+ public int groupCapability;
+
+ public enum Status {
+ CONNECTED,
+ INVITED,
+ FAILED,
+ AVAILABLE,
+ UNAVAILABLE,
+ }
+
+ public Status status = Status.UNAVAILABLE;
+
+ public WifiP2pDevice() {
+ }
+
+ /**
+ * @param string formats supported include
+ * P2P-DEVICE-FOUND fa:7b:7a:42:02:13 p2p_dev_addr=fa:7b:7a:42:02:13
+ * pri_dev_type=1-0050F204-1 name='p2p-TEST1' config_methods=0x188 dev_capab=0x27
+ * group_capab=0x0
+ *
+ * P2P-DEVICE-LOST p2p_dev_addr=fa:7b:7a:42:02:13
+ *
+ * fa:7b:7a:42:02:13
+ *
+ * P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
+ * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ * group_capab=0x0
+ *
+ * P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 p2p_dev_addr=42:fc:89:e1:e2:27
+ * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ * group_capab=0x0
+ *
+ * P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 p2p_dev_addr=42:fc:89:e1:e2:27
+ * pri_dev_type=1-0050F204-1 name='p2p-TEST2' config_methods=0x188 dev_capab=0x27
+ * group_capab=0x0
+ *
+ * Note: The events formats can be looked up in the wpa_supplicant code
+ */
+ public WifiP2pDevice(String string) throws IllegalArgumentException {
+ String[] tokens = string.split(" ");
+
+ if (tokens.length < 1) {
+ throw new IllegalArgumentException("Malformed supplicant event");
+ }
+
+ /* Just a device address */
+ if (tokens.length == 1) {
+ deviceAddress = string;
+ return;
+ }
+
+ Pattern p = Pattern.compile("(?:[0-9a-f]{2}:){5}[0-9a-f]{2}", Pattern.CASE_INSENSITIVE);
+ if (p.matcher(tokens[1]).matches()) interfaceAddress = tokens[1];
+
+ for (String token : tokens) {
+ String[] nameValue = token.split("=");
+ if (nameValue.length != 2) continue;
+
+ if (nameValue[0].equals("p2p_dev_addr")) {
+ deviceAddress = nameValue[1];
+ continue;
+ }
+
+ if (nameValue[0].equals("pri_dev_type")) {
+ primaryDeviceType = nameValue[1];
+ continue;
+ }
+
+ if (nameValue[0].equals("name")) {
+ deviceName = trimQuotes(nameValue[1]);
+ }
+
+ if (nameValue[0].equals("config_methods")) {
+ wpsConfigMethodsSupported = parseHex(nameValue[1]);
+ continue;
+ }
+
+ if (nameValue[0].equals("dev_capab")) {
+ deviceCapability = parseHex(nameValue[1]);
+ continue;
+ }
+
+ if (nameValue[0].equals("group_capab")) {
+ groupCapability = parseHex(nameValue[1]);
+ continue;
+ }
+ }
+
+ if (tokens[0].startsWith("P2P-DEVICE-FOUND")) {
+ status = Status.AVAILABLE;
+ }
+ }
+
+ public boolean isGroupOwner() {
+ return (groupCapability & GROUP_CAPAB_GROUP_OWNER) != 0;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (!(obj instanceof WifiP2pDevice)) return false;
+
+ WifiP2pDevice other = (WifiP2pDevice) obj;
+ if (other == null || other.deviceAddress == null) {
+ return (deviceAddress == null);
+ }
+ //STOPSHIP: fix later
+ //return other.deviceAddress.equals(deviceAddress);
+ return other.deviceAddress.startsWith(deviceAddress.substring(0,8));
+ }
+
+ public String toString() {
+ StringBuffer sbuf = new StringBuffer();
+ sbuf.append("Device: ").append(deviceName);
+ sbuf.append("\n deviceAddress: ").append(deviceAddress);
+ sbuf.append("\n interfaceAddress: ").append(interfaceAddress);
+ sbuf.append("\n primary type: ").append(primaryDeviceType);
+ sbuf.append("\n secondary type: ").append(secondaryDeviceType);
+ sbuf.append("\n wps: ").append(wpsConfigMethodsSupported);
+ sbuf.append("\n grpcapab: ").append(groupCapability);
+ sbuf.append("\n devcapab: ").append(deviceCapability);
+ sbuf.append("\n status: ").append(status);
+ return sbuf.toString();
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public int describeContents() {
+ return 0;
+ }
+
+ /** copy constructor {@hide} */
+ public WifiP2pDevice(WifiP2pDevice source) {
+ if (source != null) {
+ deviceName = source.deviceName;
+ deviceAddress = source.deviceAddress;
+ interfaceAddress = source.interfaceAddress;
+ primaryDeviceType = source.primaryDeviceType;
+ secondaryDeviceType = source.secondaryDeviceType;
+ wpsConfigMethodsSupported = source.wpsConfigMethodsSupported;
+ deviceCapability = source.deviceCapability;
+ groupCapability = source.groupCapability;
+ status = source.status;
+ }
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(deviceName);
+ dest.writeString(deviceAddress);
+ dest.writeString(interfaceAddress);
+ dest.writeString(primaryDeviceType);
+ dest.writeString(secondaryDeviceType);
+ dest.writeInt(wpsConfigMethodsSupported);
+ dest.writeInt(deviceCapability);
+ dest.writeInt(groupCapability);
+ dest.writeString(status.name());
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public static final Creator<WifiP2pDevice> CREATOR =
+ new Creator<WifiP2pDevice>() {
+ public WifiP2pDevice createFromParcel(Parcel in) {
+ WifiP2pDevice device = new WifiP2pDevice();
+ device.deviceName = in.readString();
+ device.deviceAddress = in.readString();
+ device.interfaceAddress = in.readString();
+ device.primaryDeviceType = in.readString();
+ device.secondaryDeviceType = in.readString();
+ device.wpsConfigMethodsSupported = in.readInt();
+ device.deviceCapability = in.readInt();
+ device.groupCapability = in.readInt();
+ device.status = Status.valueOf(in.readString());
+ return device;
+ }
+
+ public WifiP2pDevice[] newArray(int size) {
+ return new WifiP2pDevice[size];
+ }
+ };
+
+ private String trimQuotes(String str) {
+ str = str.trim();
+ if (str.startsWith("'") && str.endsWith("'")) {
+ return str.substring(1, str.length()-1);
+ }
+ return str;
+ }
+
+ //supported formats: 0x1abc, 0X1abc, 1abc
+ private int parseHex(String hexString) {
+ int num = 0;
+ if (hexString.startsWith("0x") || hexString.startsWith("0X")) {
+ hexString = hexString.substring(2);
+ }
+
+ try {
+ num = Integer.parseInt(hexString, 16);
+ } catch(NumberFormatException e) {
+ Log.e(TAG, "Failed to parse hex string " + hexString);
+ }
+ return num;
+ }
+}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.aidl
new file mode 100644
index 0000000..6c79009
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+parcelable WifiP2pDeviceList;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
new file mode 100644
index 0000000..4ec23b8
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pDeviceList.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+import android.os.Parcelable;
+import android.os.Parcel;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A class representing a Wi-Fi P2p device list
+ * @hide
+ */
+public class WifiP2pDeviceList implements Parcelable {
+
+ private Collection<WifiP2pDevice> mDevices;
+
+ public WifiP2pDeviceList() {
+ mDevices = new ArrayList<WifiP2pDevice>();
+ }
+
+ //copy constructor
+ public WifiP2pDeviceList(WifiP2pDeviceList source) {
+ if (source != null) {
+ mDevices = source.getDeviceList();
+ }
+ }
+
+ public WifiP2pDeviceList(ArrayList<WifiP2pDevice> devices) {
+ mDevices = new ArrayList<WifiP2pDevice>();
+ for (WifiP2pDevice device : devices) {
+ mDevices.add(device);
+ }
+ }
+
+ public void clear() {
+ mDevices.clear();
+ }
+
+ public void add(WifiP2pDevice device) {
+ if (device == null) return;
+ if (mDevices.contains(device)) return;
+ mDevices.add(device);
+ }
+
+ public boolean remove(WifiP2pDevice device) {
+ if (device == null) return false;
+ return mDevices.remove(device);
+ }
+
+ public Collection<WifiP2pDevice> getDeviceList() {
+ return Collections.unmodifiableCollection(mDevices);
+ }
+
+ public String toString() {
+ StringBuffer sbuf = new StringBuffer();
+ for (WifiP2pDevice device : mDevices) {
+ sbuf.append("\n").append(device);
+ }
+ return sbuf.toString();
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public int describeContents() {
+ return 0;
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mDevices.size());
+ for(WifiP2pDevice device : mDevices) {
+ dest.writeParcelable(device, flags);
+ }
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public static final Creator<WifiP2pDeviceList> CREATOR =
+ new Creator<WifiP2pDeviceList>() {
+ public WifiP2pDeviceList createFromParcel(Parcel in) {
+ WifiP2pDeviceList deviceList = new WifiP2pDeviceList();
+
+ int deviceCount = in.readInt();
+ for (int i = 0; i < deviceCount; i++) {
+ deviceList.add((WifiP2pDevice)in.readParcelable(null));
+ }
+ return deviceList;
+ }
+
+ public WifiP2pDeviceList[] newArray(int size) {
+ return new WifiP2pDeviceList[size];
+ }
+ };
+}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.aidl
new file mode 100644
index 0000000..403f2b1
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+parcelable WifiP2pGroup;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java
new file mode 100644
index 0000000..ca6e4d5
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pGroup.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+import android.os.Parcelable;
+import android.os.Parcel;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A class representing a Wi-Fi P2p group
+ * @hide
+ */
+public class WifiP2pGroup implements Parcelable {
+
+ /** The network name */
+ private String mNetworkName;
+
+ /** The network bssid */
+ private String mNetworkBssid;
+
+ /** Group owner */
+ private WifiP2pDevice mOwner;
+
+ /** Device is group owner */
+ private boolean mIsGroupOwner;
+
+ /** Group clients */
+ private List<WifiP2pDevice> mClients = new ArrayList<WifiP2pDevice>();
+
+ private int mChannel;
+
+ /**
+ * The network passphrase
+ * <p/>
+ * The passphrase used for WPA2-PSK
+ */
+ private String mPassphrase;
+
+ /**
+ * TODO: fix
+ * Sometimes supplicant sends a psk
+ */
+ private String mPsk;
+
+ /** Indicates that the group is persistent */
+ private boolean mIsPersistent;
+
+ private String mInterface;
+
+ public WifiP2pGroup() {
+ }
+
+ /**
+ * @param string formats supported include
+ *
+ * P2P-GROUP-STARTED p2p-wlan0-0 [client|GO] ssid="DIRECT-W8" freq=2437
+ * [psk=2182b2e50e53f260d04f3c7b25ef33c965a3291b9b36b455a82d77fd82ca15bc|
+ * passphrase="fKG4jMe3"] go_dev_addr=fa:7b:7a:42:02:13
+ *
+ * P2P-GROUP-REMOVED p2p-wlan0-0 [client|GO] reason=REQUESTED
+ *
+ * P2P-INVITATION-RECEIVED sa=fa:7b:7a:42:02:13 go_dev_addr=f8:7b:7a:42:02:13
+ * bssid=fa:7b:7a:42:82:13 unknown-network
+ *
+ * Note: The events formats can be looked up in the wpa_supplicant code
+ */
+ public WifiP2pGroup(String supplicantEvent) throws IllegalArgumentException {
+
+ String[] tokens = supplicantEvent.split(" ");
+
+ if (tokens.length < 3) {
+ throw new IllegalArgumentException("Malformed supplicant event");
+ }
+
+ if (tokens[0].startsWith("P2P-GROUP")) {
+ mInterface = tokens[1];
+ mIsGroupOwner = tokens[2].equals("GO");
+
+ for (String token : tokens) {
+ String[] nameValue = token.split("=");
+ if (nameValue.length != 2) continue;
+
+ if (nameValue[0].equals("ssid")) {
+ mNetworkName = nameValue[1];
+ continue;
+ }
+
+ if (nameValue[0].equals("freq")) {
+ try {
+ mChannel = Integer.parseInt(nameValue[1]);
+ } catch (NumberFormatException e) {
+ mChannel = 0; //invalid
+ }
+ continue;
+ }
+
+ if (nameValue[0].equals("psk")) {
+ mPsk = nameValue[1];
+ continue;
+ }
+
+ if (nameValue[0].equals("passphrase")) {
+ mPassphrase = nameValue[1];
+ continue;
+ }
+
+ if (nameValue[0].equals("go_dev_addr")) {
+ mOwner = new WifiP2pDevice(nameValue[1]);
+ }
+ }
+ } else if (tokens[0].equals("P2P-INVITATION-RECEIVED")) {
+ for (String token : tokens) {
+ String[] nameValue = token.split("=");
+ if (nameValue.length != 2) continue;
+
+ if (nameValue[0].equals("go_dev_addr")) {
+ mOwner = new WifiP2pDevice(nameValue[1]);
+ continue;
+ }
+
+ if (nameValue[0].equals("bssid")) {
+ mNetworkBssid = nameValue[1];
+ }
+ }
+ } else {
+ throw new IllegalArgumentException("Malformed supplicant event");
+ }
+ }
+
+ public boolean isGroupOwner() {
+ return mIsGroupOwner;
+ }
+
+ public WifiP2pDevice getOwner() {
+ return mOwner;
+ }
+
+ public void addClient(String address) {
+ addClient(new WifiP2pDevice(address));
+ }
+
+ public void addClient(WifiP2pDevice device) {
+ for (WifiP2pDevice client : mClients) {
+ if (client.equals(device)) return;
+ }
+ mClients.add(device);
+ }
+
+ public boolean removeClient(String address) {
+ return mClients.remove(new WifiP2pDevice(address));
+ }
+
+ public boolean removeClient(WifiP2pDevice device) {
+ return mClients.remove(device);
+ }
+
+ public boolean isClientListEmpty() {
+ return mClients.size() == 0;
+ }
+
+ public Collection<WifiP2pDevice> getClientList() {
+ return Collections.unmodifiableCollection(mClients);
+ }
+
+ public String getInterface() {
+ return mInterface;
+ }
+
+ // TODO: implement
+ public String toString() {
+ StringBuffer sbuf = new StringBuffer();
+ //sbuf.append("SSID: ").append(SSID);
+ //sbuf.append("\n passphrase: ").append(passphrase);
+ return sbuf.toString();
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public int describeContents() {
+ return 0;
+ }
+
+ /** copy constructor {@hide} */
+ // TODO: implement
+ public WifiP2pGroup(WifiP2pGroup source) {
+ if (source != null) {
+ }
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ // STOPSHIP: implement
+ public void writeToParcel(Parcel dest, int flags) {
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public static final Creator<WifiP2pGroup> CREATOR =
+ new Creator<WifiP2pGroup>() {
+ public WifiP2pGroup createFromParcel(Parcel in) {
+ WifiP2pGroup group = new WifiP2pGroup();
+ return group;
+ }
+
+ public WifiP2pGroup[] newArray(int size) {
+ return new WifiP2pGroup[size];
+ }
+ };
+}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
new file mode 100644
index 0000000..ea212ac
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
@@ -0,0 +1,344 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+import android.annotation.SdkConstant;
+import android.annotation.SdkConstant.SdkConstantType;
+import android.content.Context;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Handler;
+import android.os.Message;
+import android.os.RemoteException;
+import android.os.WorkSource;
+import android.os.Messenger;
+
+import com.android.internal.util.AsyncChannel;
+import com.android.internal.util.Protocol;
+
+/**
+ * This class provides the API for managing Wi-Fi p2p
+ * connectivity. Get an instance of this class by calling
+ * {@link android.content.Context#getSystemService(String)
+ * Context.getSystemService(Context.WIFI_P2P_SERVICE)}.
+ *
+ * It deals with the following:
+ * <ul>
+ * <li>Wi-Fi peer discovery and connection setup. Allows applications to initiate a discovery to
+ * find available peers and then setup a connection </li>
+ * <li>Configuration and status query. Allows applications to fetch the current list
+ * of available and connected peers and query connection status </li>
+ * <li>Intent actions that are broadcast to track operations
+ * on a p2p connection</li>
+ * </ul>
+ * @hide
+ */
+public class WifiP2pManager {
+ /**
+ * Broadcast intent action to indicate whether Wi-Fi p2p is enabled or disabled.
+ */
+ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+ public static final String WIFI_P2P_STATE_CHANGED_ACTION =
+ "android.net.wifi.P2P_STATE_CHANGED";
+
+ /**
+ * The lookup key for an int that indicates whether Wi-Fi p2p is enabled or disabled.
+ * Retrieve it with {@link android.content.Intent#getIntExtra(String,int)}.
+ *
+ * @see #WIFI_P2P_STATE_DISABLED
+ * @see #WIFI_P2P_STATE_ENABLED
+ */
+ public static final String EXTRA_WIFI_STATE = "wifi_p2p_state";
+
+ /**
+ * Wi-Fi p2p is disabled.
+ *
+ * @see #WIFI_P2P_STATE_CHANGED_ACTION
+ * @see #getWifiP2pState()
+ */
+ public static final int WIFI_P2P_STATE_DISABLED = 1;
+
+ /**
+ * Wi-Fi p2p is enabled.
+ *
+ * @see #WIFI_P2P_STATE_CHANGED_ACTION
+ * @see #getWifiP2pState()
+ */
+ public static final int WIFI_P2P_STATE_ENABLED = 2;
+
+ /**
+ * Broadcast intent action indicating that the state of Wi-Fi p2p connectivity
+ * has changed. One extra provides the new state
+ * in the form of a {@link android.net.NetworkInfo} object.
+ * @see #EXTRA_NETWORK_INFO
+ */
+ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+ public static final String WIFI_P2P_CONNECTION_CHANGED_ACTION =
+ "android.net.wifi.CONNECTION_STATE_CHANGE";
+
+ /**
+ * The lookup key for a {@link android.net.NetworkInfo} object associated with the
+ * Wi-Fi network. Retrieve with
+ * {@link android.content.Intent#getParcelableExtra(String)}.
+ */
+ public static final String EXTRA_NETWORK_INFO = "networkInfo";
+
+ /**
+ * Broadcast intent action indicating that the available peer list has changed
+ */
+ @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
+ public static final String WIFI_P2P_PEERS_CHANGED_ACTION =
+ "android.net.wifi.PEERS_CHANGED";
+
+ /**
+ * Activity Action: Pick a Wi-Fi p2p network to connect to.
+ * <p>Input: Nothing.
+ * <p>Output: Nothing.
+ */
+ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+ public static final String ACTION_PICK_WIFI_P2P_NETWORK =
+ "android.net.wifi.PICK_WIFI_P2P_NETWORK";
+
+ IWifiP2pManager mService;
+
+ /* For communication with WifiP2pService */
+ private AsyncChannel mAsyncChannel = new AsyncChannel();
+
+ /* AsyncChannel notifications to apps */
+ public static final int HANDLER_CONNECTION = AsyncChannel.CMD_CHANNEL_HALF_CONNECTED;
+ public static final int HANDLER_DISCONNECTION = AsyncChannel.CMD_CHANNEL_DISCONNECTED;
+
+ private static final int BASE = Protocol.BASE_WIFI_P2P_MANAGER;
+
+ public static final int ENABLE_P2P = BASE + 1;
+ public static final int ENABLE_P2P_FAILED = BASE + 2;
+ public static final int ENABLE_P2P_SUCCEEDED = BASE + 3;
+
+ /* arg1 on ENABLE_P2P_FAILED indicates a reason for failure */
+ public static final int P2P_UNSUPPORTED = 1;
+
+ public static final int DISABLE_P2P = BASE + 5;
+ public static final int DISABLE_P2P_FAILED = BASE + 6;
+ public static final int DISABLE_P2P_SUCCEEDED = BASE + 7;
+
+ public static final int START_LISTEN_MODE = BASE + 9;
+ public static final int START_LISTEN_FAILED = BASE + 10;
+ public static final int START_LISTEN_SUCCEEDED = BASE + 11;
+
+ public static final int DISCOVER_PEERS = BASE + 13;
+ public static final int DISCOVER_PEERS_FAILED = BASE + 14;
+ public static final int DISCOVER_PEERS_SUCCEDED = BASE + 15;
+
+ public static final int CANCEL_DISCOVER_PEERS = BASE + 17;
+ public static final int CANCEL_DISCOVER_PEERS_FAILED = BASE + 18;
+ public static final int CANCEL_DISCOVER_PEERS_SUCCEDED = BASE + 19;
+
+ public static final int CONNECT = BASE + 21;
+ public static final int CONNECT_FAILED = BASE + 22;
+ public static final int CONNECT_SUCCEEDED = BASE + 23;
+
+ public static final int CANCEL_CONNECT = BASE + 25;
+ public static final int CANCEL_CONNECT_FAILED = BASE + 26;
+ public static final int CANCEL_CONNECT_SUCCEDED = BASE + 27;
+
+ public static final int REJECT = BASE + 28;
+ public static final int REJECT_FAILED = BASE + 29;
+ public static final int REJECT_SUCCEEDED = BASE + 30;
+
+ public static final int CREATE_GROUP = BASE + 31;
+ public static final int CREATE_GROUP_FAILED = BASE + 32;
+ public static final int CREATE_GROUP_SUCCEEDED = BASE + 33;
+
+ public static final int REMOVE_GROUP = BASE + 34;
+ public static final int REMOVE_GROUP_FAILED = BASE + 35;
+ public static final int REMOVE_GROUP_SUCCEEDED = BASE + 36;
+
+ public static final int REQUEST_SETTINGS = BASE + 37;
+ public static final int RESPONSE_SETTINGS = BASE + 38;
+
+ public static final int REQUEST_PEERS = BASE + 39;
+ public static final int RESPONSE_PEERS = BASE + 40;
+
+ public static final int REQUEST_CONNECTION_STATUS = BASE + 41;
+ public static final int RESPONSE_CONNECTION_STATUS = BASE + 42;
+
+ public static final int WPS_PBC = BASE + 43;
+ public static final int WPS_PIN = BASE + 44;
+ public static final int WPS_PIN_AVAILABLE = BASE + 45;
+
+ /**
+ * Create a new WifiP2pManager instance. Applications use
+ * {@link android.content.Context#getSystemService Context.getSystemService()} to retrieve
+ * the standard {@link android.content.Context#WIFI_P2P_SERVICE Context.WIFI_P2P_SERVICE}.
+ * @param service the Binder interface
+ * @param handler target for messages
+ * @hide - hide this because it takes in a parameter of type IWifiP2pManager, which
+ * is a system private class.
+ */
+ public WifiP2pManager(IWifiP2pManager service) {
+ mService = service;
+ }
+
+ /**
+ * Registers the application handler with the Wi-Fi framework.
+ * This function must be the first to be called before any p2p control
+ * or query operations can be performed.
+ * @param srcContext is the context of the source
+ * @param srcHandler is the handler on which the source receives messages
+ * @return {@code true} if the operation succeeded
+ */
+ public boolean connectHandler(Context srcContext, Handler srcHandler) {
+ Messenger messenger = getMessenger();
+ if (messenger == null) return false;
+ return mAsyncChannel.connectSync(srcContext, srcHandler, messenger)
+ == AsyncChannel.STATUS_SUCCESSFUL;
+ }
+
+ public boolean isP2pSupported() {
+ try {
+ return mService.isP2pSupported();
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
+
+ /**
+ * Sends in a request to the system to enable p2p. This will pop up a dialog
+ * to the user and upon authorization will enable p2p.
+ */
+ public void enableP2p() {
+ mAsyncChannel.sendMessage(ENABLE_P2P);
+ }
+
+ /**
+ * Sends in a request to the system to disable p2p. This will pop up a dialog
+ * to the user and upon authorization will enable p2p.
+ */
+ public void disableP2p() {
+ mAsyncChannel.sendMessage(DISABLE_P2P);
+ }
+
+ /**
+ * Set device in listen mode. This will make the device discoverable by
+ * another peer.
+ * A dialog to the user is thrown to request his permission since it can
+ * have a significant impact on power consumption
+ */
+ public void setListenState(int timeout) {
+ mAsyncChannel.sendMessage(START_LISTEN_MODE, timeout);
+ }
+
+ /**
+ * Initiates peer discovery
+ */
+ public void discoverPeers() {
+ mAsyncChannel.sendMessage(DISCOVER_PEERS);
+ }
+
+ /**
+ * Initiates peer discovery with a timeout
+ */
+ public void discoverPeers(int timeout) {
+ mAsyncChannel.sendMessage(DISCOVER_PEERS, timeout);
+ }
+
+ /**
+ * Cancel any existing peer discovery operation
+ */
+ public void cancelPeerDiscovery() {
+ mAsyncChannel.sendMessage(CANCEL_DISCOVER_PEERS);
+ }
+
+ /**
+ * Start a p2p connection
+ *
+ * @param peer Configuration described in a {@link WifiP2pConfig} object.
+ */
+ public void connect(WifiP2pConfig config) {
+ mAsyncChannel.sendMessage(CONNECT, config);
+ }
+
+ /**
+ * Cancel any ongoing negotiation or disconnect from an existing group
+ */
+ public void disconnect() {
+ mAsyncChannel.sendMessage(CANCEL_CONNECT);
+ }
+
+ /**
+ * Create a p2p group. This is essentially an access point that can accept
+ * client connections.
+ */
+ public void createGroup() {
+ mAsyncChannel.sendMessage(CREATE_GROUP);
+ }
+
+ /**
+ * Remove the current group. This also removes the p2p interface created
+ * during group formation.
+ */
+ public void removeGroup() {
+ mAsyncChannel.sendMessage(REMOVE_GROUP);
+ }
+
+ /**
+ * Request current p2p settings. This returns a RESPONSE_SETTINGS on the source
+ * handler.
+ */
+ public void requestP2pSettings() {
+ mAsyncChannel.sendMessage(REQUEST_SETTINGS);
+ }
+
+ /**
+ * Request the list of peers. This returns a RESPONSE_PEERS on the source
+ * handler.
+ */
+ public void requestPeers() {
+ mAsyncChannel.sendMessage(REQUEST_PEERS);
+ }
+
+ /**
+ * Fetch device list from a RESPONSE_PEERS message
+ */
+ public WifiP2pDeviceList peersInResponse(Message msg) {
+ return (WifiP2pDeviceList) msg.obj;
+ }
+
+ /**
+ * Request device connection status. This returns a RESPONSE_CONNECTION_STATUS on
+ * the source handler.
+ */
+ public void requestConnectionStatus() {
+ mAsyncChannel.sendMessage(REQUEST_CONNECTION_STATUS);
+ }
+
+
+ /**
+ * Get a reference to WifiP2pService handler. This is used to establish
+ * an AsyncChannel communication with WifiService
+ *
+ * @return Messenger pointing to the WifiP2pService handler
+ * @hide
+ */
+ public Messenger getMessenger() {
+ try {
+ return mService.getMessenger();
+ } catch (RemoteException e) {
+ return null;
+ }
+ }
+}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pService.java b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
new file mode 100644
index 0000000..4988f0b
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pService.java
@@ -0,0 +1,880 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.server;
+
+import android.app.AlertDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiMonitor;
+import android.net.wifi.WifiNative;
+import android.net.wifi.WifiStateMachine;
+import android.net.wifi.WpsConfiguration;
+import android.net.wifi.WpsConfiguration.Setup;
+import android.net.wifi.p2p.IWifiP2pManager;
+import android.net.wifi.p2p.WifiP2pConfig;
+import android.net.wifi.p2p.WifiP2pDevice;
+import android.net.wifi.p2p.WifiP2pDevice.Status;
+import android.net.wifi.p2p.WifiP2pDeviceList;
+import android.net.wifi.p2p.WifiP2pGroup;
+import android.net.wifi.p2p.WifiP2pManager;
+import android.os.Binder;
+import android.os.IBinder;
+import android.os.Handler;
+import android.os.Messenger;
+import android.os.HandlerThread;
+import android.os.IBinder;
+import android.os.Message;
+import android.util.Slog;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.EditText;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+import java.util.Collection;
+
+import com.android.internal.util.AsyncChannel;
+import com.android.internal.util.Protocol;
+import com.android.internal.R;
+import com.android.internal.util.State;
+import com.android.internal.util.StateMachine;
+
+/**
+ * WifiP2pService inclues a state machine to perform Wi-Fi p2p operations. Applications
+ * communicate with this service to issue device discovery and connectivity requests
+ * through the WifiP2pManager interface. The state machine communicates with the wifi
+ * driver through wpa_supplicant and handles the event responses through WifiMonitor.
+ *
+ * Note that the term Wifi when used without a p2p suffix refers to the client mode
+ * of Wifi operation
+ * @hide
+ */
+public class WifiP2pService extends IWifiP2pManager.Stub {
+ private static final String TAG = "WifiP2pService";
+ private static final boolean DBG = true;
+
+ private Context mContext;
+
+ // Tracked to notify the user about wifi client/hotspot being shut down
+ // during p2p bring up
+ private int mWifiState = WifiManager.WIFI_STATE_DISABLED;
+ private int mWifiApState = WifiManager.WIFI_AP_STATE_DISABLED;
+
+ private P2pStateMachine mP2pStateMachine;
+ private AsyncChannel mReplyChannel = new AsyncChannel();;
+ private AsyncChannel mWifiChannel;
+
+ private static final int BASE = Protocol.BASE_WIFI_P2P_SERVICE;
+
+ /* Message sent to WifiStateMachine to indicate p2p enable is pending */
+ public static final int P2P_ENABLE_PENDING = BASE + 1;
+ /* Message sent to WifiStateMachine to indicate Wi-Fi client/hotspot operation can proceed */
+ public static final int WIFI_ENABLE_PROCEED = BASE + 2;
+
+ /* User accepted to disable Wi-Fi in order to enable p2p */
+ private static final int WIFI_DISABLE_USER_ACCEPT = BASE + 11;
+
+ private final boolean mP2pSupported;
+
+ public WifiP2pService(Context context) {
+ mContext = context;
+
+ mP2pSupported = mContext.getResources().getBoolean(
+ com.android.internal.R.bool.config_wifi_p2p_support);
+
+ mP2pStateMachine = new P2pStateMachine(TAG, mP2pSupported);
+ mP2pStateMachine.start();
+
+ // broadcasts
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
+ filter.addAction(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
+ mContext.registerReceiver(new WifiStateReceiver(), filter);
+
+ }
+
+ private class WifiStateReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(WifiManager.WIFI_STATE_CHANGED_ACTION)) {
+ mWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE,
+ WifiManager.WIFI_STATE_DISABLED);
+ } else if (intent.getAction().equals(WifiManager.WIFI_AP_STATE_CHANGED_ACTION)) {
+ mWifiApState = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE,
+ WifiManager.WIFI_AP_STATE_DISABLED);
+ }
+ }
+ }
+
+ private void enforceAccessPermission() {
+ mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_WIFI_STATE,
+ "WifiP2pService");
+ }
+
+ private void enforceChangePermission() {
+ mContext.enforceCallingOrSelfPermission(android.Manifest.permission.CHANGE_WIFI_STATE,
+ "WifiP2pService");
+ }
+
+ /**
+ * Get a reference to handler. This is used by a client to establish
+ * an AsyncChannel communication with WifiP2pService
+ */
+ public Messenger getMessenger() {
+ enforceAccessPermission();
+ enforceChangePermission();
+ return new Messenger(mP2pStateMachine.getHandler());
+ }
+
+ /**
+ * Return if p2p is supported
+ */
+ public boolean isP2pSupported() {
+ enforceAccessPermission();
+ return mP2pSupported;
+ }
+
+ @Override
+ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+ if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
+ != PackageManager.PERMISSION_GRANTED) {
+ pw.println("Permission Denial: can't dump WifiP2pService from from pid="
+ + Binder.getCallingPid()
+ + ", uid=" + Binder.getCallingUid());
+ return;
+ }
+ }
+
+
+ /**
+ * Handles interaction with WifiStateMachine
+ */
+ private class P2pStateMachine extends StateMachine {
+
+ private DefaultState mDefaultState = new DefaultState();
+ private P2pNotSupportedState mP2pNotSupportedState = new P2pNotSupportedState();
+ private P2pDisablingState mP2pDisablingState = new P2pDisablingState();
+ private P2pDisabledState mP2pDisabledState = new P2pDisabledState();
+ private WaitForWifiDisableState mWaitForWifiDisableState = new WaitForWifiDisableState();
+ private P2pEnablingState mP2pEnablingState = new P2pEnablingState();
+ private P2pEnabledState mP2pEnabledState = new P2pEnabledState();
+ // Inactive is when p2p is enabled with no connectivity
+ private InactiveState mInactiveState = new InactiveState();
+ private GroupNegotiationState mGroupNegotiationState = new GroupNegotiationState();
+ private GroupCreatedState mGroupCreatedState = new GroupCreatedState();
+
+ private WifiMonitor mWifiMonitor = new WifiMonitor(this);
+
+ private WifiP2pDeviceList mPeers = new WifiP2pDeviceList();
+ private WifiP2pGroup mGroup;
+
+ // Saved enable request message so the state machine can send an appropriate response
+ private Message mSavedEnableRequestMessage;
+
+ // Saved WifiP2pConfig from GO negotiation request
+ private WifiP2pConfig mSavedGoNegotiationConfig;
+
+ // Saved WifiP2pConfig from connect request
+ private WifiP2pConfig mSavedConnectConfig;
+
+ // Saved WifiP2pGroup from invitation request
+ private WifiP2pGroup mSavedP2pGroup;
+
+ P2pStateMachine(String name, boolean p2pSupported) {
+ super(name);
+
+ addState(mDefaultState);
+ addState(mP2pNotSupportedState, mDefaultState);
+ addState(mP2pDisablingState, mDefaultState);
+ addState(mP2pDisabledState, mDefaultState);
+ addState(mWaitForWifiDisableState, mDefaultState);
+ addState(mP2pEnablingState, mDefaultState);
+ addState(mP2pEnabledState, mDefaultState);
+ addState(mInactiveState, mP2pEnabledState);
+ addState(mGroupNegotiationState, mP2pEnabledState);
+ addState(mGroupCreatedState, mP2pEnabledState);
+
+ if (p2pSupported) {
+ setInitialState(mP2pDisabledState);
+ } else {
+ setInitialState(mP2pNotSupportedState);
+ }
+ }
+
+ // TODO: Respond to every p2p request with success/failure
+ class DefaultState extends State {
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
+ if (message.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
+ if (DBG) Slog.d(TAG, "Full connection with WifiStateMachine established");
+ mWifiChannel = (AsyncChannel) message.obj;
+ } else {
+ Slog.e(TAG, "Full connection failure, error = " + message.arg1);
+ mWifiChannel = null;
+ }
+ break;
+
+ case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
+ if (message.arg1 == AsyncChannel.STATUS_SEND_UNSUCCESSFUL) {
+ Slog.e(TAG, "Send failed, client connection lost");
+ } else {
+ Slog.e(TAG, "Client connection lost with reason: " + message.arg1);
+ }
+ mWifiChannel = null;
+ break;
+
+ case AsyncChannel.CMD_CHANNEL_FULL_CONNECTION:
+ AsyncChannel ac = new AsyncChannel();
+ ac.connect(mContext, getHandler(), message.replyTo);
+ break;
+ case WifiStateMachine.WIFI_ENABLE_PENDING:
+ // Disable p2p operation before we can respond
+ sendMessage(WifiP2pManager.DISABLE_P2P);
+ deferMessage(message);
+ break;
+ case WifiP2pManager.ENABLE_P2P:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.ENABLE_P2P_FAILED);
+ break;
+ case WifiP2pManager.DISABLE_P2P:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.DISABLE_P2P_FAILED);
+ break;
+ case WifiP2pManager.START_LISTEN_MODE:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.START_LISTEN_FAILED);
+ break;
+ case WifiP2pManager.DISCOVER_PEERS:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.DISCOVER_PEERS_FAILED);
+ break;
+ case WifiP2pManager.CANCEL_DISCOVER_PEERS:
+ mReplyChannel.replyToMessage(message,
+ WifiP2pManager.CANCEL_DISCOVER_PEERS_FAILED);
+ break;
+ case WifiP2pManager.CONNECT:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.CONNECT_FAILED);
+ break;
+ case WifiP2pManager.CANCEL_CONNECT:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.CANCEL_CONNECT_FAILED);
+ break;
+ case WifiP2pManager.REJECT:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.REJECT_FAILED);
+ break;
+ case WifiP2pManager.CREATE_GROUP:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.CREATE_GROUP_FAILED);
+ break;
+ case WifiP2pManager.REMOVE_GROUP:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.REMOVE_GROUP_FAILED);
+ break;
+ // TODO: fix
+ case WifiP2pManager.REQUEST_SETTINGS:
+ case WifiP2pManager.REQUEST_PEERS:
+ case WifiP2pManager.REQUEST_CONNECTION_STATUS:
+ break;
+ // Ignore
+ case WIFI_DISABLE_USER_ACCEPT:
+ break;
+ default:
+ Slog.e(TAG, "Unhandled message " + message);
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+ class P2pNotSupportedState extends State {
+ @Override
+ public boolean processMessage(Message message) {
+ switch (message.what) {
+ // Allow Wi-Fi to proceed
+ case WifiStateMachine.WIFI_ENABLE_PENDING:
+ mReplyChannel.replyToMessage(message, WIFI_ENABLE_PROCEED);
+ break;
+ case WifiP2pManager.ENABLE_P2P:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.ENABLE_P2P_FAILED,
+ WifiP2pManager.P2P_UNSUPPORTED);
+ break;
+ case WifiP2pManager.DISABLE_P2P:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.DISABLE_P2P_FAILED,
+ WifiP2pManager.P2P_UNSUPPORTED);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+ class P2pDisablingState extends State {
+ @Override
+ public void enter() {
+ if (DBG) Slog.d(TAG, getName());
+ // TODO: fix later
+ WifiNative.unloadDriver();
+ transitionTo(mP2pDisabledState);
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ case WifiMonitor.SUP_DISCONNECTION_EVENT:
+ WifiNative.unloadDriver();
+ transitionTo(mP2pDisabledState);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+
+ class P2pDisabledState extends State {
+ @Override
+ public void enter() {
+ if (DBG) Slog.d(TAG, getName());
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ case WifiP2pManager.ENABLE_P2P:
+ mSavedEnableRequestMessage = Message.obtain(message);
+ OnClickListener listener = new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (which == DialogInterface.BUTTON_POSITIVE) {
+ sendMessage(WIFI_DISABLE_USER_ACCEPT);
+ } else {
+ mReplyChannel.replyToMessage(mSavedEnableRequestMessage,
+ WifiP2pManager.ENABLE_P2P_FAILED);
+ }
+ }
+ };
+
+ // Show a user request dialog if we know Wi-Fi client/hotspot is in operation
+ if (mWifiState != WifiManager.WIFI_STATE_DISABLED ||
+ mWifiApState != WifiManager.WIFI_AP_STATE_DISABLED) {
+ Resources r = Resources.getSystem();
+ AlertDialog dialog = new AlertDialog.Builder(mContext)
+ .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setMessage(r.getString(R.string.wifi_p2p_turnon_message))
+ .setPositiveButton(r.getString(R.string.ok), listener)
+ .setNegativeButton(r.getString(R.string.cancel), listener)
+ .create();
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ } else {
+ mWifiChannel.sendMessage(P2P_ENABLE_PENDING);
+ transitionTo(mWaitForWifiDisableState);
+ }
+ break;
+ case WIFI_DISABLE_USER_ACCEPT:
+ mWifiChannel.sendMessage(P2P_ENABLE_PENDING);
+ transitionTo(mWaitForWifiDisableState);
+ break;
+ case WifiStateMachine.WIFI_ENABLE_PENDING:
+ mReplyChannel.replyToMessage(message, WIFI_ENABLE_PROCEED);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+ class WaitForWifiDisableState extends State {
+ @Override
+ public void enter() {
+ if (DBG) Slog.d(TAG, getName());
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ case WifiStateMachine.P2P_ENABLE_PROCEED:
+ // TODO: fix this for p2p
+ if (WifiNative.loadDriver() &&
+ WifiNative.startSupplicant()) {
+ Slog.d(TAG, "Wi-fi Direct start successful");
+ mWifiMonitor.startMonitoring();
+ transitionTo(mP2pEnablingState);
+ } else {
+ notifyP2pEnableFailure();
+ mReplyChannel.replyToMessage(mSavedEnableRequestMessage,
+ WifiP2pManager.ENABLE_P2P_FAILED);
+ transitionTo(mP2pDisabledState);
+ }
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+ class P2pEnablingState extends State {
+ @Override
+ public void enter() {
+ if (DBG) Slog.d(TAG, getName());
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ case WifiMonitor.SUP_CONNECTION_EVENT:
+ mReplyChannel.replyToMessage(mSavedEnableRequestMessage,
+ WifiP2pManager.ENABLE_P2P_SUCCEEDED);
+ transitionTo(mInactiveState);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+ class P2pEnabledState extends State {
+ @Override
+ public void enter() {
+ if (DBG) Slog.d(TAG, getName());
+ sendP2pStateChangedBroadcast(true);
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ case WifiP2pManager.DISABLE_P2P:
+ // TODO: use stopSupplicant after control channel fixed
+ WifiNative.killSupplicant();
+ transitionTo(mP2pDisablingState);
+ break;
+ case WifiP2pManager.DISCOVER_PEERS:
+ int timeout = message.arg1;
+ WifiNative.p2pFlush();
+ WifiNative.p2pFind(timeout);
+ break;
+ case WifiP2pManager.REQUEST_PEERS:
+ mReplyChannel.replyToMessage(message, WifiP2pManager.RESPONSE_PEERS, mPeers);
+ break;
+ case WifiMonitor.P2P_DEVICE_FOUND_EVENT:
+ WifiP2pDevice device = (WifiP2pDevice) message.obj;
+ mPeers.add(device);
+ sendP2pPeersChangedBroadcast();
+ break;
+ case WifiMonitor.P2P_DEVICE_LOST_EVENT:
+ device = (WifiP2pDevice) message.obj;
+ if (mPeers.remove(device)) sendP2pPeersChangedBroadcast();
+ break;
+ case WifiP2pManager.CONNECT:
+ if (DBG) Slog.d(TAG, getName() + " sending connect");
+ mSavedConnectConfig = (WifiP2pConfig) message.obj;
+ String pin = WifiNative.p2pConnect(mSavedConnectConfig);
+ try {
+ Integer.parseInt(pin);
+ notifyWpsPin(pin, mSavedConnectConfig.deviceAddress);
+ } catch (NumberFormatException ignore) {
+ // do nothing if p2pConnect did not return a pin
+ }
+ updateDeviceStatus(mSavedConnectConfig.deviceAddress, Status.INVITED);
+ sendP2pPeersChangedBroadcast();
+ transitionTo(mGroupNegotiationState);
+ break;
+ case WifiP2pManager.REJECT:
+ if (DBG) Slog.d(TAG, getName() + " sending reject");
+ WifiNative.p2pReject((String) message.obj);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+
+ @Override
+ public void exit() {
+ sendP2pStateChangedBroadcast(false);
+ }
+ }
+
+ class InactiveState extends State {
+ @Override public void enter() {
+ if (DBG) Slog.d(TAG, getName());
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ case WifiMonitor.P2P_GO_NEGOTIATION_REQUEST_EVENT:
+ mSavedGoNegotiationConfig = (WifiP2pConfig) message.obj;
+ notifyP2pGoNegotationRequest(mSavedGoNegotiationConfig);
+ break;
+ case WifiP2pManager.CREATE_GROUP:
+ WifiNative.p2pGroupAdd();
+ transitionTo(mGroupNegotiationState);
+ break;
+ case WifiMonitor.P2P_INVITATION_RECEIVED_EVENT:
+ WifiP2pGroup group = (WifiP2pGroup) message.obj;
+ notifyP2pInvitationReceived(group);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+ class GroupNegotiationState extends State {
+ @Override public void enter() {
+ if (DBG) Slog.d(TAG, getName());
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ // We ignore these right now, since we get a GROUP_STARTED notification
+ // afterwards
+ case WifiMonitor.P2P_GO_NEGOTIATION_SUCCESS_EVENT:
+ case WifiMonitor.P2P_GROUP_FORMATION_SUCCESS_EVENT:
+ if (DBG) Slog.d(TAG, getName() + " go success");
+ break;
+ case WifiMonitor.P2P_GO_NEGOTIATION_FAILURE_EVENT:
+ case WifiMonitor.P2P_GROUP_FORMATION_FAILURE_EVENT:
+ if (DBG) Slog.d(TAG, getName() + " go failure");
+ updateDeviceStatus(mSavedConnectConfig.deviceAddress, Status.FAILED);
+ mSavedConnectConfig = null;
+ transitionTo(mInactiveState);
+ break;
+ case WifiMonitor.P2P_GROUP_STARTED_EVENT:
+ mGroup = (WifiP2pGroup) message.obj;
+ if (DBG) Slog.d(TAG, getName() + " group started");
+ // If this device is GO, do nothing since there is a follow up
+ // AP_STA_CONNECTED event
+ if (!mGroup.isGroupOwner()) {
+ WifiP2pDevice groupOwner = mGroup.getOwner();
+ updateDeviceStatus(groupOwner.deviceAddress, Status.CONNECTED);
+ sendP2pPeersChangedBroadcast();
+ }
+ transitionTo(mGroupCreatedState);
+ break;
+ case WifiP2pManager.CANCEL_CONNECT:
+ // TODO: fix
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+ class GroupCreatedState extends State {
+ @Override
+ public void enter() {
+ if (DBG) Slog.d(TAG, getName());
+ }
+
+ @Override
+ public boolean processMessage(Message message) {
+ if (DBG) Slog.d(TAG, getName() + message.toString());
+ switch (message.what) {
+ case WifiMonitor.AP_STA_CONNECTED_EVENT:
+ String address = (String) message.obj;
+ mGroup.addClient(address);
+ updateDeviceStatus(address, Status.CONNECTED);
+ if (DBG) Slog.d(TAG, getName() + " ap sta connected");
+ sendP2pPeersChangedBroadcast();
+ break;
+ case WifiMonitor.AP_STA_DISCONNECTED_EVENT:
+ address = (String) message.obj;
+ updateDeviceStatus(address, Status.AVAILABLE);
+ if (mGroup.removeClient(address)) {
+ if (DBG) Slog.d(TAG, "Removed client " + address);
+ if (mGroup.isClientListEmpty()) {
+ Slog.d(TAG, "Client list empty, killing p2p connection");
+ sendMessage(WifiP2pManager.REMOVE_GROUP);
+ } else {
+ // Just send a notification
+ sendP2pPeersChangedBroadcast();
+ }
+ } else {
+ if (DBG) Slog.d(TAG, "Failed to remove client " + address);
+ for (WifiP2pDevice c : mGroup.getClientList()) {
+ if (DBG) Slog.d(TAG,"client " + c.deviceAddress);
+ }
+ }
+ if (DBG) Slog.e(TAG, getName() + " ap sta disconnected");
+ break;
+ // Disconnect & remove group have same effect when connected
+ case WifiP2pManager.CANCEL_CONNECT:
+ case WifiP2pManager.REMOVE_GROUP:
+ if (DBG) Slog.e(TAG, getName() + " remove group");
+ WifiNative.p2pFlush();
+ WifiNative.p2pGroupRemove(mGroup.getInterface());
+ break;
+ case WifiMonitor.P2P_GROUP_REMOVED_EVENT:
+ if (DBG) Slog.e(TAG, getName() + " group removed");
+ Collection <WifiP2pDevice> devices = mGroup.getClientList();
+ boolean changed = false;
+ for (WifiP2pDevice d : mPeers.getDeviceList()) {
+ if (devices.contains(d) || mGroup.getOwner().equals(d)) {
+ d.status = Status.AVAILABLE;
+ changed = true;
+ }
+ }
+ mGroup = null;
+ if (changed) sendP2pPeersChangedBroadcast();
+ transitionTo(mInactiveState);
+ break;
+ case WifiMonitor.P2P_DEVICE_LOST_EVENT:
+ WifiP2pDevice device = (WifiP2pDevice) message.obj;
+ if (device.equals(mGroup.getOwner())) {
+ Slog.d(TAG, "Lost the group owner, killing p2p connection");
+ sendMessage(WifiP2pManager.REMOVE_GROUP);
+ } else if (mGroup.removeClient(device) && mGroup.isClientListEmpty()) {
+ Slog.d(TAG, "Client list empty, killing p2p connection");
+ sendMessage(WifiP2pManager.REMOVE_GROUP);
+ }
+ return NOT_HANDLED; // Do the regular device lost handling
+ case WifiP2pManager.DISABLE_P2P:
+ sendMessage(WifiP2pManager.REMOVE_GROUP);
+ deferMessage(message);
+ break;
+ case WifiP2pManager.DISCOVER_PEERS:
+ int timeout = message.arg1;
+ WifiNative.p2pFind(timeout);
+ break;
+ case WifiP2pManager.CONNECT:
+ WifiP2pConfig config = (WifiP2pConfig) message.obj;
+ Slog.d(TAG, "Inviting device : " + config.deviceAddress);
+ WifiNative.p2pInvite(mGroup, config.deviceAddress);
+ updateDeviceStatus(config.deviceAddress, Status.INVITED);
+ sendP2pPeersChangedBroadcast();
+ // TODO: figure out updating the status to declined when invitation is rejected
+ break;
+ case WifiMonitor.P2P_INVITATION_RESULT_EVENT:
+ Slog.d(TAG,"===> INVITATION RESULT EVENT : " + message.obj);
+ break;
+ case WifiMonitor.P2P_PROV_DISC_PBC_REQ_EVENT:
+ notifyP2pProvDiscPbcRequest((WifiP2pDevice) message.obj);
+ break;
+ case WifiMonitor.P2P_PROV_DISC_ENTER_PIN_EVENT:
+ notifyP2pProvDiscPinRequest((WifiP2pDevice) message.obj);
+ break;
+ case WifiP2pManager.WPS_PBC:
+ WifiNative.p2pWpsPbc();
+ break;
+ case WifiP2pManager.WPS_PIN:
+ WifiNative.p2pWpsPin((String) message.obj);
+ break;
+ default:
+ return NOT_HANDLED;
+ }
+ return HANDLED;
+ }
+ }
+
+ private void sendP2pStateChangedBroadcast(boolean enabled) {
+ final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ if (enabled) {
+ intent.putExtra(WifiP2pManager.EXTRA_WIFI_STATE,
+ WifiP2pManager.WIFI_P2P_STATE_ENABLED);
+ } else {
+ intent.putExtra(WifiP2pManager.EXTRA_WIFI_STATE,
+ WifiP2pManager.WIFI_P2P_STATE_DISABLED);
+ }
+ mContext.sendStickyBroadcast(intent);
+ }
+
+ private void sendP2pPeersChangedBroadcast() {
+ final Intent intent = new Intent(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
+ intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
+ mContext.sendBroadcast(intent);
+ }
+
+ private void notifyP2pEnableFailure() {
+ Resources r = Resources.getSystem();
+ AlertDialog dialog = new AlertDialog.Builder(mContext)
+ .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setMessage(r.getString(R.string.wifi_p2p_failed_message))
+ .setPositiveButton(r.getString(R.string.ok), null)
+ .create();
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ }
+
+ private void notifyWpsPin(String pin, String peerAddress) {
+ Resources r = Resources.getSystem();
+ AlertDialog dialog = new AlertDialog.Builder(mContext)
+ .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setMessage(r.getString(R.string.wifi_p2p_pin_display_message, pin, peerAddress))
+ .setPositiveButton(r.getString(R.string.ok), null)
+ .create();
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ }
+
+ private void notifyP2pGoNegotationRequest(WifiP2pConfig config) {
+ Resources r = Resources.getSystem();
+ WpsConfiguration wpsConfig = config.wpsConfig;
+ final View textEntryView = LayoutInflater.from(mContext)
+ .inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null);
+ final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin);
+
+ AlertDialog dialog = new AlertDialog.Builder(mContext)
+ .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setView(textEntryView)
+ .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if (DBG) Slog.d(TAG, getName() + " connect " + pin.getText());
+ mSavedGoNegotiationConfig.wpsConfig.setup = Setup.KEYPAD;
+ mSavedGoNegotiationConfig.wpsConfig.pin = pin.getText().toString();
+ sendMessage(WifiP2pManager.CONNECT, mSavedGoNegotiationConfig);
+ mSavedGoNegotiationConfig = null;
+ }
+ })
+ .setNegativeButton(r.getString(R.string.cancel), new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (DBG) Slog.d(TAG, getName() + " reject");
+ sendMessage(WifiP2pManager.REJECT,
+ mSavedGoNegotiationConfig.deviceAddress);
+ mSavedGoNegotiationConfig = null;
+ }
+ })
+ .create();
+
+ if (wpsConfig.setup == Setup.PBC) {
+ pin.setVisibility(View.GONE);
+ dialog.setMessage(r.getString(R.string.wifi_p2p_pbc_go_negotiation_request_message,
+ config.deviceAddress));
+ } else {
+ dialog.setMessage(r.getString(R.string.wifi_p2p_pin_go_negotiation_request_message,
+ config.deviceAddress));
+ }
+
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ }
+
+ private void notifyP2pProvDiscPbcRequest(WifiP2pDevice peer) {
+ Resources r = Resources.getSystem();
+ final View textEntryView = LayoutInflater.from(mContext)
+ .inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null);
+ final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin);
+
+ AlertDialog dialog = new AlertDialog.Builder(mContext)
+ .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setView(textEntryView)
+ .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if (DBG) Slog.d(TAG, getName() + " wps_pbc");
+ sendMessage(WifiP2pManager.WPS_PBC);
+ }
+ })
+ .setNegativeButton(r.getString(R.string.cancel), null)
+ .create();
+
+ pin.setVisibility(View.GONE);
+ dialog.setMessage(r.getString(R.string.wifi_p2p_pbc_go_negotiation_request_message,
+ peer.deviceAddress));
+
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ }
+
+ private void notifyP2pProvDiscPinRequest(WifiP2pDevice peer) {
+ Resources r = Resources.getSystem();
+ final View textEntryView = LayoutInflater.from(mContext)
+ .inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null);
+ final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin);
+
+ AlertDialog dialog = new AlertDialog.Builder(mContext)
+ .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setView(textEntryView)
+ .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ if (DBG) Slog.d(TAG, getName() + " wps_pin");
+ sendMessage(WifiP2pManager.WPS_PIN, pin.getText().toString());
+ }
+ })
+ .setNegativeButton(r.getString(R.string.cancel), null)
+ .create();
+
+ dialog.setMessage(r.getString(R.string.wifi_p2p_pin_go_negotiation_request_message,
+ peer.deviceAddress));
+
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ }
+
+ private void notifyP2pInvitationReceived(WifiP2pGroup group) {
+ mSavedP2pGroup = group;
+ Resources r = Resources.getSystem();
+ final View textEntryView = LayoutInflater.from(mContext)
+ .inflate(R.layout.wifi_p2p_go_negotiation_request_alert, null);
+ final EditText pin = (EditText) textEntryView .findViewById(R.id.wifi_p2p_wps_pin);
+
+ AlertDialog dialog = new AlertDialog.Builder(mContext)
+ .setTitle(r.getString(R.string.wifi_p2p_dialog_title))
+ .setView(textEntryView)
+ .setPositiveButton(r.getString(R.string.ok), new OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ WifiP2pConfig config = new WifiP2pConfig();
+ config.deviceAddress = mSavedP2pGroup.getOwner().deviceAddress;
+ config.joinExistingGroup = true;
+ if (DBG) Slog.d(TAG, getName() + " connect to invited group");
+ sendMessage(WifiP2pManager.CONNECT, config);
+ mSavedP2pGroup = null;
+ }
+ })
+ .setNegativeButton(r.getString(R.string.cancel), null)
+ .create();
+
+ pin.setVisibility(View.GONE);
+ dialog.setMessage(r.getString(R.string.wifi_p2p_pbc_go_negotiation_request_message,
+ group.getOwner().deviceAddress));
+
+ dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
+ dialog.show();
+ }
+
+ private void updateDeviceStatus(String deviceAddress, Status status) {
+ for (WifiP2pDevice d : mPeers.getDeviceList()) {
+ // TODO: fix later
+ // if (d.deviceAddress.equals(deviceAddress)) {
+ if (d.deviceAddress.startsWith(deviceAddress.substring(0, 8))) {
+ d.status = status;
+ }
+ }
+ }
+ }
+}
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pStatus.aidl b/wifi/java/android/net/wifi/p2p/WifiP2pStatus.aidl
new file mode 100644
index 0000000..7bab5d3
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pStatus.aidl
@@ -0,0 +1,19 @@
+/**
+ * Copyright (c) 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+parcelable WifiP2pStatus;
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pStatus.java b/wifi/java/android/net/wifi/p2p/WifiP2pStatus.java
new file mode 100644
index 0000000..1c9b76c
--- /dev/null
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pStatus.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.net.wifi.p2p;
+
+import android.os.Parcelable;
+import android.os.Parcel;
+
+/**
+ * A class representing Wi-fi P2p status
+ * @hide
+ */
+public class WifiP2pStatus implements Parcelable {
+
+ //Comes from the wpa_supplicant
+ enum p2p_status_code {
+ SUCCESS,
+ FAIL_INFO_CURRENTLY_UNAVAILABLE,
+ FAIL_INCOMPATIBLE_PARAMS,
+ FAIL_LIMIT_REACHED,
+ FAIL_INVALID_PARAMS,
+ FAIL_UNABLE_TO_ACCOMMODATE,
+ FAIL_PREV_PROTOCOL_ERROR,
+ FAIL_NO_COMMON_CHANNELS,
+ FAIL_UNKNOWN_GROUP,
+ FAIL_BOTH_GO_INTENT_15,
+ FAIL_INCOMPATIBLE_PROV_METHOD,
+ FAIL_REJECTED_BY_USER
+ };
+
+ public WifiP2pStatus() {
+ }
+
+ //TODO: add support
+ public String toString() {
+ StringBuffer sbuf = new StringBuffer();
+ return sbuf.toString();
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public int describeContents() {
+ return 0;
+ }
+
+ /** copy constructor {@hide} */
+ //TODO: implement
+ public WifiP2pStatus(WifiP2pStatus source) {
+ if (source != null) {
+ }
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ // STOPSHIP: implement
+ public void writeToParcel(Parcel dest, int flags) {
+ }
+
+ /** Implement the Parcelable interface {@hide} */
+ public static final Creator<WifiP2pStatus> CREATOR =
+ new Creator<WifiP2pStatus>() {
+ public WifiP2pStatus createFromParcel(Parcel in) {
+ WifiP2pStatus status = new WifiP2pStatus();
+ return status;
+ }
+
+ public WifiP2pStatus[] newArray(int size) {
+ return new WifiP2pStatus[size];
+ }
+ };
+}