Merge "Add filename and line number in the debug messages."
diff --git a/Android.mk b/Android.mk
index 335fb73..7b8d0bc 100644
--- a/Android.mk
+++ b/Android.mk
@@ -158,6 +158,11 @@
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 @@
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 @@
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 265bbc4..db7713a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -21,6 +21,7 @@
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";
@@ -184,14 +185,14 @@
public static final class R.attr {
ctor public R.attr();
field public static final int absListViewStyle = 16842858; // 0x101006a
- field public static final int accessibilityEventTypes = 16843648; // 0x1010380
- field public static final int accessibilityFeedbackType = 16843650; // 0x1010382
- field public static final int accessibilityFlags = 16843652; // 0x1010384
+ field public static final int accessibilityEventTypes = 16843647; // 0x101037f
+ field public static final int accessibilityFeedbackType = 16843649; // 0x1010381
+ field public static final int accessibilityFlags = 16843651; // 0x1010383
field public static final int accountPreferences = 16843423; // 0x101029f
field public static final int accountType = 16843407; // 0x101028f
field public static final int action = 16842797; // 0x101002d
field public static final int actionBarSize = 16843499; // 0x10102eb
- field public static final int actionBarSplitStyle = 16843670; // 0x1010396
+ field public static final int actionBarSplitStyle = 16843669; // 0x1010395
field public static final int actionBarStyle = 16843470; // 0x10102ce
field public static final int actionBarTabBarStyle = 16843508; // 0x10102f4
field public static final int actionBarTabStyle = 16843507; // 0x10102f3
@@ -207,10 +208,10 @@
field public static final int actionModeCopyDrawable = 16843538; // 0x1010312
field public static final int actionModeCutDrawable = 16843537; // 0x1010311
field public static final int actionModePasteDrawable = 16843539; // 0x1010313
- field public static final int actionModeSelectAllDrawable = 16843646; // 0x101037e
- field public static final int actionModeStyle = 16843682; // 0x10103a2
+ field public static final int actionModeSelectAllDrawable = 16843645; // 0x101037d
+ field public static final int actionModeStyle = 16843681; // 0x10103a1
field public static final int actionOverflowButtonStyle = 16843510; // 0x10102f6
- field public static final int actionProviderClass = 16843671; // 0x1010397
+ field public static final int actionProviderClass = 16843670; // 0x1010396
field public static final int actionViewClass = 16843516; // 0x10102fc
field public static final int activatedBackgroundIndicator = 16843517; // 0x10102fd
field public static final int activityCloseEnterAnimation = 16842938; // 0x10100ba
@@ -222,7 +223,7 @@
field public static final int alertDialogIcon = 16843605; // 0x1010355
field public static final int alertDialogStyle = 16842845; // 0x101005d
field public static final int alertDialogTheme = 16843529; // 0x1010309
- field public static final int alignmentMode = 16843640; // 0x1010378
+ field public static final int alignmentMode = 16843639; // 0x1010377
field public static final int allContactsName = 16843468; // 0x10102cc
field public static final int allowBackup = 16843392; // 0x1010280
field public static final int allowClearUserData = 16842757; // 0x1010005
@@ -256,8 +257,8 @@
field public static final int background = 16842964; // 0x10100d4
field public static final int backgroundDimAmount = 16842802; // 0x1010032
field public static final int backgroundDimEnabled = 16843295; // 0x101021f
- field public static final int backgroundSplit = 16843673; // 0x1010399
- field public static final int backgroundStacked = 16843672; // 0x1010398
+ field public static final int backgroundSplit = 16843672; // 0x1010398
+ field public static final int backgroundStacked = 16843671; // 0x1010397
field public static final int backupAgent = 16843391; // 0x101027f
field public static final int baseline = 16843548; // 0x101031c
field public static final int baselineAlignBottom = 16843042; // 0x1010122
@@ -266,7 +267,7 @@
field public static final int borderlessButtonStyle = 16843563; // 0x101032b
field public static final int bottom = 16843184; // 0x10101b0
field public static final int bottomBright = 16842957; // 0x10100cd
- field public static final int bottomChevronDrawable = 16843659; // 0x101038b
+ field public static final int bottomChevronDrawable = 16843658; // 0x101038a
field public static final int bottomDark = 16842953; // 0x10100c9
field public static final int bottomLeftRadius = 16843179; // 0x10101ab
field public static final int bottomMedium = 16842958; // 0x10100ce
@@ -285,7 +286,7 @@
field public static final int cacheColorHint = 16843009; // 0x1010101
field public static final int calendarViewShown = 16843596; // 0x101034c
field public static final int calendarViewStyle = 16843613; // 0x101035d
- field public static final int canRetrieveWindowContent = 16843653; // 0x1010385
+ field public static final int canRetrieveWindowContent = 16843652; // 0x1010384
field public static final int candidatesTextStyleSpans = 16843312; // 0x1010230
field public static final deprecated int capitalize = 16843113; // 0x1010169
field public static final int centerBright = 16842956; // 0x10100cc
@@ -314,18 +315,18 @@
field public static final int codes = 16843330; // 0x1010242
field public static final int collapseColumns = 16843083; // 0x101014b
field public static final int color = 16843173; // 0x10101a5
- field public static final int colorActivatedHighlight = 16843678; // 0x101039e
+ field public static final int colorActivatedHighlight = 16843677; // 0x101039d
field public static final int colorBackground = 16842801; // 0x1010031
field public static final int colorBackgroundCacheHint = 16843435; // 0x10102ab
- field public static final int colorFocusedHighlight = 16843677; // 0x101039d
+ field public static final int colorFocusedHighlight = 16843676; // 0x101039c
field public static final int colorForeground = 16842800; // 0x1010030
field public static final int colorForegroundInverse = 16843270; // 0x1010206
- field public static final int colorLongPressedHighlight = 16843676; // 0x101039c
- field public static final int colorMultiSelectHighlight = 16843679; // 0x101039f
- field public static final int colorPressedHighlight = 16843675; // 0x101039b
- field public static final int columnCount = 16843637; // 0x1010375
+ field public static final int colorLongPressedHighlight = 16843675; // 0x101039b
+ field public static final int colorMultiSelectHighlight = 16843678; // 0x101039e
+ field public static final int colorPressedHighlight = 16843674; // 0x101039a
+ field public static final int columnCount = 16843636; // 0x1010374
field public static final int columnDelay = 16843215; // 0x10101cf
- field public static final int columnOrderPreserved = 16843638; // 0x1010376
+ field public static final int columnOrderPreserved = 16843637; // 0x1010375
field public static final int columnWidth = 16843031; // 0x1010117
field public static final int compatibleWidthLimitDp = 16843621; // 0x1010365
field public static final int completionHint = 16843122; // 0x1010172
@@ -379,11 +380,11 @@
field public static final int drawSelectorOnTop = 16843004; // 0x10100fc
field public static final int drawable = 16843161; // 0x1010199
field public static final int drawableBottom = 16843118; // 0x101016e
- field public static final int drawableEnd = 16843681; // 0x10103a1
+ field public static final int drawableEnd = 16843680; // 0x10103a0
field public static final int drawableLeft = 16843119; // 0x101016f
field public static final int drawablePadding = 16843121; // 0x1010171
field public static final int drawableRight = 16843120; // 0x1010170
- field public static final int drawableStart = 16843680; // 0x10103a0
+ field public static final int drawableStart = 16843679; // 0x101039f
field public static final int drawableTop = 16843117; // 0x101016d
field public static final int drawingCacheQuality = 16842984; // 0x10100e8
field public static final int dropDownAnchor = 16843363; // 0x1010263
@@ -440,7 +441,7 @@
field public static final int fastScrollTextColor = 16843609; // 0x1010359
field public static final int fastScrollThumbDrawable = 16843574; // 0x1010336
field public static final int fastScrollTrackDrawable = 16843577; // 0x1010339
- field public static final int feedbackCount = 16843665; // 0x1010391
+ field public static final int feedbackCount = 16843664; // 0x1010390
field public static final int fillAfter = 16843197; // 0x10101bd
field public static final int fillBefore = 16843196; // 0x10101bc
field public static final int fillEnabled = 16843343; // 0x101024f
@@ -493,7 +494,7 @@
field public static final int hand_hour = 16843011; // 0x1010103
field public static final int hand_minute = 16843012; // 0x1010104
field public static final int handle = 16843354; // 0x101025a
- field public static final int handleDrawable = 16843655; // 0x1010387
+ field public static final int handleDrawable = 16843654; // 0x1010386
field public static final int handleProfiling = 16842786; // 0x1010022
field public static final int hapticFeedbackEnabled = 16843358; // 0x101025e
field public static final int hardwareAccelerated = 16843475; // 0x10102d3
@@ -502,12 +503,12 @@
field public static final int headerDividersEnabled = 16843310; // 0x101022e
field public static final int height = 16843093; // 0x1010155
field public static final int hint = 16843088; // 0x1010150
- field public static final int hitRadius = 16843662; // 0x101038e
+ field public static final int hitRadius = 16843661; // 0x101038d
field public static final int homeAsUpIndicator = 16843531; // 0x101030b
field public static final int homeLayout = 16843549; // 0x101031d
field public static final int horizontalDivider = 16843053; // 0x101012d
field public static final int horizontalGap = 16843327; // 0x101023f
- field public static final int horizontalOffset = 16843667; // 0x1010393
+ field public static final int horizontalOffset = 16843666; // 0x1010392
field public static final int horizontalScrollViewStyle = 16843603; // 0x1010353
field public static final int horizontalSpacing = 16843028; // 0x1010114
field public static final int host = 16842792; // 0x1010028
@@ -553,7 +554,7 @@
field public static final int installLocation = 16843447; // 0x10102b7
field public static final int interpolator = 16843073; // 0x1010141
field public static final int isAlwaysSyncable = 16843571; // 0x1010333
- field public static final int isAuxiliary = 16843647; // 0x101037f
+ field public static final int isAuxiliary = 16843646; // 0x101037e
field public static final int isDefault = 16843297; // 0x1010221
field public static final int isIndicator = 16843079; // 0x1010147
field public static final int isModifier = 16843334; // 0x1010246
@@ -606,8 +607,8 @@
field public static final int layout_centerInParent = 16843151; // 0x101018f
field public static final int layout_centerVertical = 16843153; // 0x1010191
field public static final int layout_column = 16843084; // 0x101014c
- field public static final int layout_columnFlexibility = 16843645; // 0x101037d
- field public static final int layout_columnSpan = 16843644; // 0x101037c
+ field public static final deprecated int layout_columnFlexibility = 16843644; // 0x101037c
+ field public static final int layout_columnSpan = 16843643; // 0x101037b
field public static final int layout_gravity = 16842931; // 0x10100b3
field public static final int layout_height = 16842997; // 0x10100f5
field public static final int layout_margin = 16842998; // 0x10100f6
@@ -615,9 +616,9 @@
field public static final int layout_marginLeft = 16842999; // 0x10100f7
field public static final int layout_marginRight = 16843001; // 0x10100f9
field public static final int layout_marginTop = 16843000; // 0x10100f8
- field public static final int layout_row = 16843641; // 0x1010379
- field public static final int layout_rowFlexibility = 16843643; // 0x101037b
- field public static final int layout_rowSpan = 16843642; // 0x101037a
+ field public static final int layout_row = 16843640; // 0x1010378
+ field public static final deprecated int layout_rowFlexibility = 16843642; // 0x101037a
+ field public static final int layout_rowSpan = 16843641; // 0x1010379
field public static final int layout_scale = 16843155; // 0x1010193
field public static final int layout_span = 16843085; // 0x101014d
field public static final int layout_toLeftOf = 16843138; // 0x1010182
@@ -627,7 +628,7 @@
field public static final int layout_x = 16843135; // 0x101017f
field public static final int layout_y = 16843136; // 0x1010180
field public static final int left = 16843181; // 0x10101ad
- field public static final int leftChevronDrawable = 16843656; // 0x1010388
+ field public static final int leftChevronDrawable = 16843655; // 0x1010387
field public static final int lineSpacingExtra = 16843287; // 0x1010217
field public static final int lineSpacingMultiplier = 16843288; // 0x1010218
field public static final int lines = 16843092; // 0x1010154
@@ -639,8 +640,8 @@
field public static final int listDividerAlertDialog = 16843525; // 0x1010305
field public static final int listPopupWindowStyle = 16843519; // 0x10102ff
field public static final int listPreferredItemHeight = 16842829; // 0x101004d
- field public static final int listPreferredItemHeightLarge = 16843668; // 0x1010394
- field public static final int listPreferredItemHeightSmall = 16843669; // 0x1010395
+ field public static final int listPreferredItemHeightLarge = 16843667; // 0x1010393
+ field public static final int listPreferredItemHeightSmall = 16843668; // 0x1010394
field public static final int listSelector = 16843003; // 0x10100fb
field public static final int listSeparatorTextViewStyle = 16843272; // 0x1010208
field public static final int listViewStyle = 16842868; // 0x1010074
@@ -671,8 +672,8 @@
field public static final int minHeight = 16843072; // 0x1010140
field public static final int minLevel = 16843185; // 0x10101b1
field public static final int minLines = 16843094; // 0x1010156
- field public static final int minResizeHeight = 16843684; // 0x10103a4
- field public static final int minResizeWidth = 16843683; // 0x10103a3
+ field public static final int minResizeHeight = 16843683; // 0x10103a3
+ field public static final int minResizeWidth = 16843682; // 0x10103a2
field public static final int minSdkVersion = 16843276; // 0x101020c
field public static final int minWidth = 16843071; // 0x101013f
field public static final int mode = 16843134; // 0x101017e
@@ -688,7 +689,7 @@
field public static final int nextFocusUp = 16842979; // 0x10100e3
field public static final int noHistory = 16843309; // 0x101022d
field public static final int normalScreens = 16843397; // 0x1010285
- field public static final int notificationTimeout = 16843651; // 0x1010383
+ field public static final int notificationTimeout = 16843650; // 0x1010382
field public static final int numColumns = 16843032; // 0x1010118
field public static final int numStars = 16843076; // 0x1010144
field public static final deprecated int numeric = 16843109; // 0x1010165
@@ -702,11 +703,11 @@
field public static final int orderingFromXml = 16843239; // 0x10101e7
field public static final int orientation = 16842948; // 0x10100c4
field public static final int outAnimation = 16843128; // 0x1010178
- field public static final int outerRadius = 16843661; // 0x101038d
+ field public static final int outerRadius = 16843660; // 0x101038c
field public static final int overScrollFooter = 16843459; // 0x10102c3
field public static final int overScrollHeader = 16843458; // 0x10102c2
field public static final int overScrollMode = 16843457; // 0x10102c1
- field public static final int packageNames = 16843649; // 0x1010381
+ field public static final int packageNames = 16843648; // 0x1010380
field public static final int padding = 16842965; // 0x10100d5
field public static final int paddingBottom = 16842969; // 0x10100d9
field public static final int paddingLeft = 16842966; // 0x10100d6
@@ -791,17 +792,17 @@
field public static final int restoreAnyVersion = 16843450; // 0x10102ba
field public static final deprecated int restoreNeedsApplication = 16843421; // 0x101029d
field public static final int right = 16843183; // 0x10101af
- field public static final int rightChevronDrawable = 16843657; // 0x1010389
+ field public static final int rightChevronDrawable = 16843656; // 0x1010388
field public static final int ringtonePreferenceStyle = 16842899; // 0x1010093
field public static final int ringtoneType = 16843257; // 0x10101f9
field public static final int rotation = 16843558; // 0x1010326
field public static final int rotationX = 16843559; // 0x1010327
field public static final int rotationY = 16843560; // 0x1010328
- field public static final int rowCount = 16843635; // 0x1010373
+ field public static final int rowCount = 16843634; // 0x1010372
field public static final int rowDelay = 16843216; // 0x10101d0
field public static final int rowEdgeFlags = 16843329; // 0x1010241
field public static final int rowHeight = 16843058; // 0x1010132
- field public static final int rowOrderPreserved = 16843636; // 0x1010374
+ field public static final int rowOrderPreserved = 16843635; // 0x1010373
field public static final int saveEnabled = 16842983; // 0x10100e7
field public static final int scaleGravity = 16843262; // 0x10101fe
field public static final int scaleHeight = 16843261; // 0x10101fd
@@ -867,7 +868,7 @@
field public static final int smallIcon = 16843422; // 0x101029e
field public static final int smallScreens = 16843396; // 0x1010284
field public static final int smoothScrollbar = 16843313; // 0x1010231
- field public static final int snapMargin = 16843664; // 0x1010390
+ field public static final int snapMargin = 16843663; // 0x101038f
field public static final int soundEffectsEnabled = 16843285; // 0x1010215
field public static final int spacing = 16843027; // 0x1010113
field public static final int spinnerDropDownItemStyle = 16842887; // 0x1010087
@@ -915,7 +916,7 @@
field public static final int subtitleTextStyle = 16843513; // 0x10102f9
field public static final int suggestActionMsg = 16843228; // 0x10101dc
field public static final int suggestActionMsgColumn = 16843229; // 0x10101dd
- field public static final int suggestionsEnabled = 16843634; // 0x1010372
+ field public static final int suggestionsEnabled = 16843633; // 0x1010371
field public static final int summary = 16843241; // 0x10101e9
field public static final int summaryColumn = 16843426; // 0x10102a2
field public static final int summaryOff = 16843248; // 0x10101f0
@@ -932,7 +933,7 @@
field public static final int tag = 16842961; // 0x10100d1
field public static final int targetActivity = 16843266; // 0x1010202
field public static final int targetClass = 16842799; // 0x101002f
- field public static final int targetDrawables = 16843654; // 0x1010386
+ field public static final int targetDrawables = 16843653; // 0x1010385
field public static final int targetPackage = 16842785; // 0x1010021
field public static final int targetSdkVersion = 16843376; // 0x1010270
field public static final int taskAffinity = 16842770; // 0x1010012
@@ -947,7 +948,7 @@
field public static final int tension = 16843370; // 0x101026a
field public static final int testOnly = 16843378; // 0x1010272
field public static final int text = 16843087; // 0x101014f
- field public static final int textAllCaps = 16843674; // 0x101039a
+ field public static final int textAllCaps = 16843673; // 0x1010399
field public static final int textAppearance = 16842804; // 0x1010034
field public static final int textAppearanceButton = 16843271; // 0x1010207
field public static final int textAppearanceInverse = 16842805; // 0x1010035
@@ -988,9 +989,8 @@
field public static final int textEditPasteWindowLayout = 16843540; // 0x1010314
field public static final int textEditSideNoPasteWindowLayout = 16843615; // 0x101035f
field public static final int textEditSidePasteWindowLayout = 16843614; // 0x101035e
- field public static final int textEditSuggestionItemLayout = 16843633; // 0x1010371
- field public static final int textEditSuggestionsBottomWindowLayout = 16843631; // 0x101036f
- field public static final int textEditSuggestionsTopWindowLayout = 16843632; // 0x1010370
+ field public static final int textEditSuggestionItemLayout = 16843632; // 0x1010370
+ field public static final int textEditSuggestionsWindowLayout = 16843631; // 0x101036f
field public static final int textFilterEnabled = 16843007; // 0x10100ff
field public static final int textIsSelectable = 16843542; // 0x1010316
field public static final int textOff = 16843045; // 0x1010125
@@ -1023,7 +1023,7 @@
field public static final int toYScale = 16843205; // 0x10101c5
field public static final int top = 16843182; // 0x10101ae
field public static final int topBright = 16842955; // 0x10100cb
- field public static final int topChevronDrawable = 16843658; // 0x101038a
+ field public static final int topChevronDrawable = 16843657; // 0x1010389
field public static final int topDark = 16842951; // 0x10100c7
field public static final int topLeftRadius = 16843177; // 0x10101a9
field public static final int topOffset = 16843352; // 0x1010258
@@ -1039,7 +1039,7 @@
field public static final int unfocusedMonthDateColor = 16843588; // 0x1010344
field public static final int unselectedAlpha = 16843278; // 0x101020e
field public static final int updatePeriodMillis = 16843344; // 0x1010250
- field public static final int useDefaultMargins = 16843639; // 0x1010377
+ field public static final int useDefaultMargins = 16843638; // 0x1010376
field public static final int useIntrinsicSizeAsMinimum = 16843536; // 0x1010310
field public static final int useLevel = 16843167; // 0x101019f
field public static final int userVisible = 16843409; // 0x1010291
@@ -1053,10 +1053,10 @@
field public static final int verticalCorrection = 16843322; // 0x101023a
field public static final int verticalDivider = 16843054; // 0x101012e
field public static final int verticalGap = 16843328; // 0x1010240
- field public static final int verticalOffset = 16843666; // 0x1010392
+ field public static final int verticalOffset = 16843665; // 0x1010391
field public static final int verticalScrollbarPosition = 16843572; // 0x1010334
field public static final int verticalSpacing = 16843029; // 0x1010115
- field public static final int vibrationDuration = 16843663; // 0x101038f
+ field public static final int vibrationDuration = 16843662; // 0x101038e
field public static final int visibility = 16842972; // 0x10100dc
field public static final int visible = 16843156; // 0x1010194
field public static final int vmSafeMode = 16843448; // 0x10102b8
@@ -1073,7 +1073,7 @@
field public static final int wallpaperIntraOpenExitAnimation = 16843416; // 0x1010298
field public static final int wallpaperOpenEnterAnimation = 16843411; // 0x1010293
field public static final int wallpaperOpenExitAnimation = 16843412; // 0x1010294
- field public static final int waveDrawable = 16843660; // 0x101038c
+ field public static final int waveDrawable = 16843659; // 0x101038b
field public static final int webTextViewStyle = 16843449; // 0x10102b9
field public static final int webViewStyle = 16842885; // 0x1010085
field public static final int weekDayTextAppearance = 16843592; // 0x1010348
@@ -1828,6 +1828,7 @@
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
@@ -4784,6 +4785,7 @@
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";
@@ -10405,8 +10407,8 @@
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);
@@ -16709,7 +16711,7 @@
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";
@@ -16726,18 +16728,18 @@
field public static final java.lang.String WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY = "wifi_networks_available_repeat_delay";
field public static final java.lang.String WIFI_NUM_OPEN_NETWORKS_KEPT = "wifi_num_open_networks_kept";
field public static final java.lang.String WIFI_ON = "wifi_on";
- field public static final java.lang.String WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE = "wifi_watchdog_acceptable_packet_loss_percentage";
- field public static final java.lang.String WIFI_WATCHDOG_AP_COUNT = "wifi_watchdog_ap_count";
- field public static final java.lang.String WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS = "wifi_watchdog_background_check_delay_ms";
- field public static final java.lang.String WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED = "wifi_watchdog_background_check_enabled";
- field public static final java.lang.String WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS = "wifi_watchdog_background_check_timeout_ms";
- field public static final java.lang.String WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT = "wifi_watchdog_initial_ignored_ping_count";
- field public static final java.lang.String WIFI_WATCHDOG_MAX_AP_CHECKS = "wifi_watchdog_max_ap_checks";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE = "wifi_watchdog_acceptable_packet_loss_percentage";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_AP_COUNT = "wifi_watchdog_ap_count";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS = "wifi_watchdog_background_check_delay_ms";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED = "wifi_watchdog_background_check_enabled";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS = "wifi_watchdog_background_check_timeout_ms";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT = "wifi_watchdog_initial_ignored_ping_count";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_MAX_AP_CHECKS = "wifi_watchdog_max_ap_checks";
field public static final java.lang.String WIFI_WATCHDOG_ON = "wifi_watchdog_on";
- field public static final java.lang.String WIFI_WATCHDOG_PING_COUNT = "wifi_watchdog_ping_count";
- field public static final java.lang.String WIFI_WATCHDOG_PING_DELAY_MS = "wifi_watchdog_ping_delay_ms";
- field public static final java.lang.String WIFI_WATCHDOG_PING_TIMEOUT_MS = "wifi_watchdog_ping_timeout_ms";
- field public static final java.lang.String WIFI_WATCHDOG_WATCH_LIST = "wifi_watchdog_watch_list";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_PING_COUNT = "wifi_watchdog_ping_count";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_PING_DELAY_MS = "wifi_watchdog_ping_delay_ms";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_PING_TIMEOUT_MS = "wifi_watchdog_ping_timeout_ms";
+ field public static final deprecated java.lang.String WIFI_WATCHDOG_WATCH_LIST = "wifi_watchdog_watch_list";
}
public static class Settings.SettingNotFoundException extends android.util.AndroidException {
@@ -17942,6 +17944,31 @@
}
+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 {
@@ -21005,6 +21032,11 @@
method public void onPrepareSubMenu(android.view.SubMenu);
}
+ public abstract interface CollapsibleActionView {
+ method public abstract void onActionViewCollapsed();
+ method public abstract void onActionViewExpanded();
+ }
+
public abstract interface ContextMenu implements android.view.Menu {
method public abstract void clearHeader();
method public abstract android.view.ContextMenu setHeaderIcon(int);
@@ -22201,6 +22233,7 @@
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();
@@ -22442,6 +22475,7 @@
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);
@@ -22715,10 +22749,8 @@
ctor public ViewDebug();
method public static void dumpCapturedView(java.lang.String, java.lang.Object);
method public static void startHierarchyTracing(java.lang.String, android.view.View);
- method public static void startLooperProfiling(java.io.File);
method public static void startRecyclerTracing(java.lang.String, android.view.View);
method public static void stopHierarchyTracing();
- method public static void stopLooperProfiling();
method public static void stopRecyclerTracing();
method public static void trace(android.view.View, android.view.ViewDebug.RecyclerTraceType, int...);
method public static void trace(android.view.View, android.view.ViewDebug.HierarchyTraceType);
@@ -24019,6 +24051,54 @@
}
+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 {
@@ -25358,15 +25438,14 @@
method public void setRowCount(int);
method public void setRowOrderPreserved(boolean);
method public void setUseDefaultMargins(boolean);
- method public static android.widget.GridLayout.Spec spec(int, int, android.widget.GridLayout.Alignment, int);
- method public static android.widget.GridLayout.Spec spec(int, android.widget.GridLayout.Alignment, int);
method public static android.widget.GridLayout.Spec spec(int, int, android.widget.GridLayout.Alignment);
method public static android.widget.GridLayout.Spec spec(int, android.widget.GridLayout.Alignment);
+ method public static android.widget.GridLayout.Spec spec(int, int);
+ method public static android.widget.GridLayout.Spec spec(int);
field public static final int ALIGN_BOUNDS = 0; // 0x0
field public static final int ALIGN_MARGINS = 1; // 0x1
field public static final android.widget.GridLayout.Alignment BASELINE;
field public static final android.widget.GridLayout.Alignment BOTTOM;
- field public static final int CAN_STRETCH = 2; // 0x2
field public static final android.widget.GridLayout.Alignment CENTER;
field public static final android.widget.GridLayout.Alignment FILL;
field public static final int HORIZONTAL = 0; // 0x0
@@ -26121,7 +26200,7 @@
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();
@@ -26130,6 +26209,8 @@
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/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 3fb1736..6dfa12b 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -468,10 +468,16 @@
String profileFile = null;
boolean start = false;
boolean wall = false;
+ int profileType = 0;
String process = null;
String cmd = nextArgRequired();
+ if ("looper".equals(cmd)) {
+ cmd = nextArgRequired();
+ profileType = 1;
+ }
+
if ("start".equals(cmd)) {
start = true;
wall = "--wall".equals(nextOption());
@@ -516,7 +522,7 @@
} else if (start) {
//removeWallOption();
}
- if (!mAm.profileControl(process, start, profileFile, fd)) {
+ if (!mAm.profileControl(process, start, profileFile, fd, profileType)) {
wall = false;
throw new AndroidException("PROFILE FAILED on process " + process);
}
@@ -1076,8 +1082,8 @@
" am broadcast <INTENT>\n" +
" am instrument [-r] [-e <NAME> <VALUE>] [-p] [-w]\n" +
" [--no-window-animation] <COMPONENT>\n" +
- " am profile start <PROCESS> <FILE>\n" +
- " am profile stop <PROCESS>\n" +
+ " am profile [looper] start <PROCESS> <FILE>\n" +
+ " am profile [looper] stop <PROCESS>\n" +
" am dumpheap [flags] <PROCESS> <FILE>\n" +
" am monitor [--gdb <port>]\n" +
" am screen-compat [on|off] <PACKAGE>\n" +
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 @@
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..41a3eaca 100644
--- a/core/java/android/accessibilityservice/AccessibilityServiceInfo.java
+++ b/core/java/android/accessibilityservice/AccessibilityServiceInfo.java
@@ -75,6 +75,17 @@
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/Activity.java b/core/java/android/app/Activity.java
index aeb16f4..8d03ac7 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -1593,10 +1593,10 @@
//Log.v(TAG, "invalidateFragmentIndex: index=" + index);
if (mAllLoaderManagers != null) {
LoaderManagerImpl lm = mAllLoaderManagers.get(index);
- if (lm != null) {
+ if (lm != null && !lm.mRetaining) {
lm.doDestroy();
+ mAllLoaderManagers.remove(index);
}
- mAllLoaderManagers.remove(index);
}
}
diff --git a/core/java/android/app/ActivityManagerNative.java b/core/java/android/app/ActivityManagerNative.java
index 2a731a3..b7cd829 100644
--- a/core/java/android/app/ActivityManagerNative.java
+++ b/core/java/android/app/ActivityManagerNative.java
@@ -1104,10 +1104,11 @@
data.enforceInterface(IActivityManager.descriptor);
String process = data.readString();
boolean start = data.readInt() != 0;
+ int profileType = data.readInt();
String path = data.readString();
ParcelFileDescriptor fd = data.readInt() != 0
? data.readFileDescriptor() : null;
- boolean res = profileControl(process, start, path, fd);
+ boolean res = profileControl(process, start, path, fd, profileType);
reply.writeNoException();
reply.writeInt(res ? 1 : 0);
return true;
@@ -2888,13 +2889,14 @@
}
public boolean profileControl(String process, boolean start,
- String path, ParcelFileDescriptor fd) throws RemoteException
+ String path, ParcelFileDescriptor fd, int profileType) throws RemoteException
{
Parcel data = Parcel.obtain();
Parcel reply = Parcel.obtain();
data.writeInterfaceToken(IActivityManager.descriptor);
data.writeString(process);
data.writeInt(start ? 1 : 0);
+ data.writeInt(profileType);
data.writeString(path);
if (fd != null) {
data.writeInt(1);
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index f6cd866..9bbbd6c 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -676,11 +676,12 @@
queueOrSendMessage(H.ACTIVITY_CONFIGURATION_CHANGED, token);
}
- public void profilerControl(boolean start, String path, ParcelFileDescriptor fd) {
+ public void profilerControl(boolean start, String path, ParcelFileDescriptor fd,
+ int profileType) {
ProfilerControlData pcd = new ProfilerControlData();
pcd.path = path;
pcd.fd = fd;
- queueOrSendMessage(H.PROFILER_CONTROL, pcd, start ? 1 : 0);
+ queueOrSendMessage(H.PROFILER_CONTROL, pcd, start ? 1 : 0, profileType);
}
public void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd) {
@@ -954,7 +955,7 @@
}
public void scheduleTrimMemory(int level) {
- queueOrSendMessage(H.TRIM_MEMORY, level);
+ queueOrSendMessage(H.TRIM_MEMORY, null, level);
}
}
@@ -1148,7 +1149,7 @@
handleActivityConfigurationChanged((IBinder)msg.obj);
break;
case PROFILER_CONTROL:
- handleProfilerControl(msg.arg1 != 0, (ProfilerControlData)msg.obj);
+ handleProfilerControl(msg.arg1 != 0, (ProfilerControlData)msg.obj, msg.arg2);
break;
case CREATE_BACKUP_AGENT:
handleCreateBackupAgent((CreateBackupAgentData)msg.obj);
@@ -1184,8 +1185,10 @@
break;
case UPDATE_PACKAGE_COMPATIBILITY_INFO:
handleUpdatePackageCompatibilityInfo((UpdateCompatibilityData)msg.obj);
+ break;
case TRIM_MEMORY:
handleTrimMemory(msg.arg1);
+ break;
}
if (DEBUG_MESSAGES) Slog.v(TAG, "<<< done: " + msg.what);
}
@@ -3469,11 +3472,18 @@
performConfigurationChanged(r.activity, mCompatConfiguration);
}
- final void handleProfilerControl(boolean start, ProfilerControlData pcd) {
+ final void handleProfilerControl(boolean start, ProfilerControlData pcd, int profileType) {
if (start) {
try {
- Debug.startMethodTracing(pcd.path, pcd.fd.getFileDescriptor(),
- 8 * 1024 * 1024, 0);
+ switch (profileType) {
+ case 1:
+ ViewDebug.startLooperProfiling(pcd.path, pcd.fd.getFileDescriptor());
+ break;
+ default:
+ Debug.startMethodTracing(pcd.path, pcd.fd.getFileDescriptor(),
+ 8 * 1024 * 1024, 0);
+ break;
+ }
} catch (RuntimeException e) {
Slog.w(TAG, "Profiling failed on path " + pcd.path
+ " -- can the process access this path?");
@@ -3485,7 +3495,15 @@
}
}
} else {
- Debug.stopMethodTracing();
+ switch (profileType) {
+ case 1:
+ ViewDebug.stopLooperProfiling();
+ break;
+ default:
+ Debug.stopMethodTracing();
+ break;
+
+ }
}
}
diff --git a/core/java/android/app/ApplicationThreadNative.java b/core/java/android/app/ApplicationThreadNative.java
index 942f245..9a5b527 100644
--- a/core/java/android/app/ApplicationThreadNative.java
+++ b/core/java/android/app/ApplicationThreadNative.java
@@ -376,10 +376,11 @@
{
data.enforceInterface(IApplicationThread.descriptor);
boolean start = data.readInt() != 0;
+ int profileType = data.readInt();
String path = data.readString();
ParcelFileDescriptor fd = data.readInt() != 0
? data.readFileDescriptor() : null;
- profilerControl(start, path, fd);
+ profilerControl(start, path, fd, profileType);
return true;
}
@@ -936,10 +937,11 @@
}
public void profilerControl(boolean start, String path,
- ParcelFileDescriptor fd) throws RemoteException {
+ ParcelFileDescriptor fd, int profileType) throws RemoteException {
Parcel data = Parcel.obtain();
data.writeInterfaceToken(IApplicationThread.descriptor);
data.writeInt(start ? 1 : 0);
+ data.writeInt(profileType);
data.writeString(path);
if (fd != null) {
data.writeInt(1);
diff --git a/core/java/android/app/BackStackRecord.java b/core/java/android/app/BackStackRecord.java
index e5a7980..93330a7 100644
--- a/core/java/android/app/BackStackRecord.java
+++ b/core/java/android/app/BackStackRecord.java
@@ -224,6 +224,12 @@
writer.print(" mExitAnim=#");
writer.println(Integer.toHexString(mExitAnim));
}
+ if (mPopEnterAnim != 0 || mPopExitAnim !=0) {
+ writer.print(prefix); writer.print("mPopEnterAnim=#");
+ writer.print(Integer.toHexString(mPopEnterAnim));
+ writer.print(" mPopExitAnim=#");
+ writer.println(Integer.toHexString(mPopExitAnim));
+ }
if (mBreadCrumbTitleRes != 0 || mBreadCrumbTitleText != null) {
writer.print(prefix); writer.print("mBreadCrumbTitleRes=#");
writer.print(Integer.toHexString(mBreadCrumbTitleRes));
@@ -248,13 +254,16 @@
writer.print(innerPrefix); writer.print("cmd="); writer.print(op.cmd);
writer.print(" fragment="); writer.println(op.fragment);
if (op.enterAnim != 0 || op.exitAnim != 0) {
- writer.print(prefix); writer.print("enterAnim="); writer.print(op.enterAnim);
- writer.print(" exitAnim="); writer.println(op.exitAnim);
+ writer.print(prefix); writer.print("enterAnim=#");
+ writer.print(Integer.toHexString(op.enterAnim));
+ writer.print(" exitAnim=#");
+ writer.println(Integer.toHexString(op.exitAnim));
}
if (op.popEnterAnim != 0 || op.popExitAnim != 0) {
- writer.print(prefix);
- writer.print("popEnterAnim="); writer.print(op.popEnterAnim);
- writer.print(" popExitAnim="); writer.println(op.popExitAnim);
+ writer.print(prefix); writer.print("popEnterAnim=#");
+ writer.print(Integer.toHexString(op.popEnterAnim));
+ writer.print(" popExitAnim=#");
+ writer.println(Integer.toHexString(op.popExitAnim));
}
if (op.removed != null && op.removed.size() > 0) {
for (int i=0; i<op.removed.size(); i++) {
@@ -695,11 +704,13 @@
} break;
case OP_DETACH: {
Fragment f = op.fragment;
+ f.mNextAnim = op.popEnterAnim;
mManager.attachFragment(f,
FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
} break;
case OP_ATTACH: {
Fragment f = op.fragment;
+ f.mNextAnim = op.popExitAnim;
mManager.detachFragment(f,
FragmentManagerImpl.reverseTransit(mTransition), mTransitionStyle);
} break;
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.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.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 @@
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 @@
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 @@
public void dispatchDestroy() {
mDestroyed = true;
+ execPendingActions();
moveToState(Fragment.INITIALIZING, false);
mActivity = null;
}
diff --git a/core/java/android/app/IActivityManager.java b/core/java/android/app/IActivityManager.java
index 93c821c..64d77e8 100644
--- a/core/java/android/app/IActivityManager.java
+++ b/core/java/android/app/IActivityManager.java
@@ -284,7 +284,7 @@
// Turn on/off profiling in a particular process.
public boolean profileControl(String process, boolean start,
- String path, ParcelFileDescriptor fd) throws RemoteException;
+ String path, ParcelFileDescriptor fd, int profileType) throws RemoteException;
public boolean shutdown(int timeout) throws RemoteException;
diff --git a/core/java/android/app/IApplicationThread.java b/core/java/android/app/IApplicationThread.java
index 9de0bf4..d0607d0 100644
--- a/core/java/android/app/IApplicationThread.java
+++ b/core/java/android/app/IApplicationThread.java
@@ -105,7 +105,7 @@
throws RemoteException;
void scheduleLowMemory() throws RemoteException;
void scheduleActivityConfigurationChanged(IBinder token) throws RemoteException;
- void profilerControl(boolean start, String path, ParcelFileDescriptor fd)
+ void profilerControl(boolean start, String path, ParcelFileDescriptor fd, int profileType)
throws RemoteException;
void dumpHeap(boolean managed, String path, ParcelFileDescriptor fd)
throws RemoteException;
diff --git a/core/java/android/app/StatusBarManager.java b/core/java/android/app/StatusBarManager.java
index 1af0983..ca64c88 100644
--- a/core/java/android/app/StatusBarManager.java
+++ b/core/java/android/app/StatusBarManager.java
@@ -97,9 +97,10 @@
}
}
- public void setIcon(String slot, int iconId, int iconLevel) {
+ public void setIcon(String slot, int iconId, int iconLevel, String contentDescription) {
try {
- mService.setIcon(slot, mContext.getPackageName(), iconId, iconLevel);
+ mService.setIcon(slot, mContext.getPackageName(), iconId, iconLevel,
+ contentDescription);
} catch (RemoteException ex) {
// system process is dead anyway.
throw new RuntimeException(ex);
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 @@
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 @@
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 @@
}
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 @@
}
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/bluetooth/BluetoothDeviceProfileState.java b/core/java/android/bluetooth/BluetoothDeviceProfileState.java
index ab3a426..095cd11 100644
--- a/core/java/android/bluetooth/BluetoothDeviceProfileState.java
+++ b/core/java/android/bluetooth/BluetoothDeviceProfileState.java
@@ -120,6 +120,7 @@
private Pair<Integer, String> mIncomingConnections;
private PowerManager.WakeLock mWakeLock;
private PowerManager mPowerManager;
+ private boolean mPairingRequestRcvd = false;
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
@@ -187,27 +188,38 @@
Message msg = obtainMessage(CONNECTION_ACCESS_REQUEST_REPLY);
msg.arg1 = val;
sendMessage(msg);
+ } else if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
+ mPairingRequestRcvd = true;
+ } else if (action.equals(BluetoothDevice.ACTION_BOND_STATE_CHANGED)) {
+ int state = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
+ BluetoothDevice.ERROR);
+ if (state == BluetoothDevice.BOND_BONDED && mPairingRequestRcvd) {
+ setTrust(BluetoothDevice.CONNECTION_ACCESS_YES);
+ mPairingRequestRcvd = false;
+ } else if (state == BluetoothDevice.BOND_NONE) {
+ mPairingRequestRcvd = false;
+ }
}
}
};
private boolean isPhoneDocked(BluetoothDevice autoConnectDevice) {
- // This works only because these broadcast intents are "sticky"
- Intent i = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
- if (i != null) {
- int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
- if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
- BluetoothDevice device = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- if (device != null && autoConnectDevice.equals(device)) {
- return true;
- }
- }
- }
- return false;
- }
+ // This works only because these broadcast intents are "sticky"
+ Intent i = mContext.registerReceiver(null, new IntentFilter(Intent.ACTION_DOCK_EVENT));
+ if (i != null) {
+ int state = i.getIntExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
+ if (state != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
+ BluetoothDevice device = i.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ if (device != null && autoConnectDevice.equals(device)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
public BluetoothDeviceProfileState(Context context, String address,
- BluetoothService service, BluetoothA2dpService a2dpService) {
+ BluetoothService service, BluetoothA2dpService a2dpService, boolean setTrust) {
super(address);
mContext = context;
mDevice = new BluetoothDevice(address);
@@ -231,6 +243,8 @@
filter.addAction(BluetoothInputDevice.ACTION_CONNECTION_STATE_CHANGED);
filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
filter.addAction(BluetoothDevice.ACTION_CONNECTION_ACCESS_REPLY);
+ filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
+ filter.addAction(BluetoothDevice.ACTION_BOND_STATE_CHANGED);
mContext.registerReceiver(mBroadcastReceiver, filter);
@@ -247,6 +261,10 @@
PowerManager.ACQUIRE_CAUSES_WAKEUP |
PowerManager.ON_AFTER_RELEASE, TAG);
mWakeLock.setReferenceCounted(false);
+
+ if (setTrust) {
+ setTrust(BluetoothDevice.CONNECTION_ACCESS_YES);
+ }
}
private BluetoothProfile.ServiceListener mBluetoothProfileServiceListener =
diff --git a/core/java/android/content/ComponentCallbacks.java b/core/java/android/content/ComponentCallbacks.java
index 92b98fd..37cc141 100644
--- a/core/java/android/content/ComponentCallbacks.java
+++ b/core/java/android/content/ComponentCallbacks.java
@@ -56,11 +56,8 @@
static final int TRIM_MEMORY_COMPLETE = 80;
/** @hide */
- static final int TRIM_MEMORY_MODERATE = 60;
+ static final int TRIM_MEMORY_MODERATE = 50;
/** @hide */
- static final int TRIM_MEMORY_BACKGROUND = 40;
-
- /** @hide */
- static final int TRIM_MEMORY_INVISIBLE = 20;
+ static final int TRIM_MEMORY_BACKGROUND = 20;
}
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 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 @@
/**
* 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 @@
* {@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/inputmethodservice/ExtractEditLayout.java b/core/java/android/inputmethodservice/ExtractEditLayout.java
index eafff49..5cfa998 100644
--- a/core/java/android/inputmethodservice/ExtractEditLayout.java
+++ b/core/java/android/inputmethodservice/ExtractEditLayout.java
@@ -172,7 +172,10 @@
@Override
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
- return mCallback.onActionItemClicked(this, item);
+ if (mCallback != null) {
+ return mCallback.onActionItemClicked(this, item);
+ }
+ return false;
}
@Override
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 @@
}
}
+ /**
+ * {@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/EthernetDataTracker.java b/core/java/android/net/EthernetDataTracker.java
index a866436..b035c51 100644
--- a/core/java/android/net/EthernetDataTracker.java
+++ b/core/java/android/net/EthernetDataTracker.java
@@ -103,6 +103,10 @@
public void interfaceRemoved(String iface) {
mTracker.interfaceRemoved(iface);
}
+
+ public void limitReached(String limitName, String iface) {
+ // Ignored.
+ }
}
private EthernetDataTracker() {
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 @@
String[] getTetherableBluetoothRegexs();
+ int setUsbTethering(boolean enable);
+
void requestNetworkTransitionWakelock(in String forWhom);
void reportInetCondition(int networkType, int percentage);
diff --git a/core/java/android/net/INetworkManagementEventObserver.aidl b/core/java/android/net/INetworkManagementEventObserver.aidl
index 4436e6e..a97f203 100644
--- a/core/java/android/net/INetworkManagementEventObserver.aidl
+++ b/core/java/android/net/INetworkManagementEventObserver.aidl
@@ -52,4 +52,14 @@
* @param iface The interface.
*/
void interfaceRemoved(String iface);
+
+ /**
+ * A networking quota limit has been reached. The quota might not
+ * be specific to an interface.
+ *
+ * @param limitName The name of the limit that triggered.
+ * @param iface The interface on which the limit was detected.
+ */
+ void limitReached(String limitName, String iface);
+
}
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 @@
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/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java
index 76534ef..e289fc1 100644
--- a/core/java/android/net/NetworkUtils.java
+++ b/core/java/android/net/NetworkUtils.java
@@ -20,6 +20,7 @@
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.UnknownHostException;
+import java.util.Collection;
import android.util.Log;
@@ -235,4 +236,18 @@
throw new IllegalArgumentException(e);
}
}
+
+ /**
+ * Create a string array of host addresses from a collection of InetAddresses
+ * @param addrs a Collection of InetAddresses
+ * @return an array of Strings containing their host addresses
+ */
+ public static String[] makeStrings(Collection<InetAddress> addrs) {
+ String[] result = new String[addrs.size()];
+ int i = 0;
+ for (InetAddress addr : addrs) {
+ result[i++] = addr.getHostAddress();
+ }
+ return result;
+ }
}
diff --git a/core/java/android/net/VpnBuilder.java b/core/java/android/net/VpnBuilder.java
new file mode 100644
index 0000000..4582523
--- /dev/null
+++ b/core/java/android/net/VpnBuilder.java
@@ -0,0 +1,413 @@
+/*
+ * 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;
+
+import android.app.Activity;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.ParcelFileDescriptor;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+
+import com.android.internal.net.VpnConfig;
+
+import java.net.InetAddress;
+import java.net.Inet4Address;
+import java.net.Inet6Address;
+import java.net.DatagramSocket;
+import java.net.Socket;
+import java.util.ArrayList;
+
+/**
+ * VpnBuilder is a framework which enables applications to build their
+ * own VPN solutions. In general, it creates a virtual network interface,
+ * configures addresses and routing rules, and returns a file descriptor
+ * to the application. Each read from the descriptor retrieves an outgoing
+ * packet which was routed to the interface. Each write to the descriptor
+ * injects an incoming packet just like it was received from the interface.
+ * The framework is running on Internet Protocol (IP), so packets are
+ * always started with IP headers. The application then completes a VPN
+ * connection by processing and exchanging packets with a remote server
+ * over a secured tunnel.
+ *
+ * <p>Letting applications intercept packets raises huge security concerns.
+ * Besides, a VPN application can easily break the network, and two of them
+ * may conflict with each other. The framework takes several actions to
+ * address these issues. Here are some key points:
+ * <ul>
+ * <li>User action is required to create a VPN connection.</li>
+ * <li>There can be only one VPN connection running at the same time. The
+ * existing interface is deactivated when a new one is created.</li>
+ * <li>A system-managed notification is shown during the lifetime of a
+ * VPN connection.</li>
+ * <li>A system-managed dialog gives the information of the current VPN
+ * connection. It also provides a button to disconnect.</li>
+ * <li>The network is restored automatically when the file descriptor is
+ * closed. It also covers the cases when a VPN application is crashed
+ * or killed by the system.</li>
+ * </ul>
+ *
+ * <p>There are two primary methods in this class: {@link #prepare} and
+ * {@link #establish}. The former deals with the user action and stops
+ * the existing VPN connection created by another application. The latter
+ * creates a VPN interface using the parameters supplied to this builder.
+ * An application must call {@link #prepare} to grant the right to create
+ * an interface, and it can be revoked at any time by another application.
+ * The application got revoked is notified by an {@link #ACTION_VPN_REVOKED}
+ * broadcast. Here are the general steps to create a VPN connection:
+ * <ol>
+ * <li>When the user press the button to connect, call {@link #prepare}
+ * and launch the intent if necessary.</li>
+ * <li>Register a receiver for {@link #ACTION_VPN_REVOKED} broadcasts.
+ * <li>Connect to the remote server and negotiate the network parameters
+ * of the VPN connection.</li>
+ * <li>Use those parameters to configure a VpnBuilder and create a VPN
+ * interface by calling {@link #establish}.</li>
+ * <li>Start processing packets between the returned file descriptor and
+ * the VPN tunnel.</li>
+ * <li>When an {@link #ACTION_VPN_REVOKED} broadcast is received, the
+ * interface is already deactivated by the framework. Close the file
+ * descriptor and shut down the VPN tunnel gracefully.
+ * </ol>
+ * Methods in this class can be used in activities and services. However,
+ * the intent returned from {@link #prepare} must be launched from an
+ * activity. The broadcast receiver can be registered at any time, but doing
+ * it before calling {@link #establish} effectively avoids race conditions.
+ *
+ * <p class="note">Using this class requires
+ * {@link android.Manifest.permission#VPN} permission.
+ * @hide
+ */
+public class VpnBuilder {
+
+ /**
+ * Broadcast intent action indicating that the VPN application has been
+ * revoked. This can be only received by the target application on the
+ * receiver explicitly registered using {@link Context#registerReceiver}.
+ *
+ * <p>This is a protected intent that can only be sent by the system.
+ */
+ public static final String ACTION_VPN_REVOKED = VpnConfig.ACTION_VPN_REVOKED;
+
+ /**
+ * Use IConnectivityManager instead since those methods are hidden and
+ * not available in ConnectivityManager.
+ */
+ private static IConnectivityManager getService() {
+ return IConnectivityManager.Stub.asInterface(
+ ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
+ }
+
+ /**
+ * Prepare to establish a VPN connection. This method returns {@code null}
+ * if the VPN application is already prepared. Otherwise, it returns an
+ * {@link Intent} to a system activity. The application should launch the
+ * activity using {@link Activity#startActivityForResult} to get itself
+ * prepared. The activity may pop up a dialog to require user action, and
+ * the result will come back to the application through its
+ * {@link Activity#onActivityResult}. The application becomes prepared if
+ * the result is {@link Activity#RESULT_OK}, and it is granted to create a
+ * VPN interface by calling {@link #establish}.
+ *
+ * <p>Only one application can be granted at the same time. The right
+ * is revoked when another application is granted. The application
+ * losing the right will be notified by an {@link #ACTION_VPN_REVOKED}
+ * broadcast, and its VPN interface will be deactivated by the system.
+ * The application should then notify the remote server and disconnect
+ * gracefully. Unless the application becomes prepared again, subsequent
+ * calls to {@link #establish} will return {@code null}.
+ *
+ * @see #establish
+ * @see #ACTION_VPN_REVOKED
+ */
+ public static Intent prepare(Context context) {
+ try {
+ if (getService().prepareVpn(context.getPackageName(), null)) {
+ return null;
+ }
+ } catch (RemoteException e) {
+ // ignore
+ }
+ return VpnConfig.getIntentForConfirmation();
+ }
+
+ private VpnConfig mConfig = new VpnConfig();
+ private StringBuilder mAddresses = new StringBuilder();
+ private StringBuilder mRoutes = new StringBuilder();
+
+ /**
+ * Set the name of this session. It will be displayed in system-managed
+ * dialogs and notifications. This is recommended not required.
+ */
+ public VpnBuilder setSession(String session) {
+ mConfig.session = session;
+ return this;
+ }
+
+ /**
+ * Set the {@link PendingIntent} to an activity for users to configure
+ * the VPN connection. If it is not set, the button to configure will
+ * not be shown in system-managed dialogs.
+ */
+ public VpnBuilder setConfigureIntent(PendingIntent intent) {
+ mConfig.configureIntent = intent;
+ return this;
+ }
+
+ /**
+ * Set the maximum transmission unit (MTU) of the VPN interface. If it
+ * is not set, the default value in the operating system will be used.
+ *
+ * @throws IllegalArgumentException if the value is not positive.
+ */
+ public VpnBuilder setMtu(int mtu) {
+ if (mtu <= 0) {
+ throw new IllegalArgumentException("Bad mtu");
+ }
+ mConfig.mtu = mtu;
+ return this;
+ }
+
+ /**
+ * Private method to validate address and prefixLength.
+ */
+ private static void check(InetAddress address, int prefixLength) {
+ if (address.isLoopbackAddress()) {
+ throw new IllegalArgumentException("Bad address");
+ }
+ if (address instanceof Inet4Address) {
+ if (prefixLength < 0 || prefixLength > 32) {
+ throw new IllegalArgumentException("Bad prefixLength");
+ }
+ } else if (address instanceof Inet6Address) {
+ if (prefixLength < 0 || prefixLength > 128) {
+ throw new IllegalArgumentException("Bad prefixLength");
+ }
+ } else {
+ throw new IllegalArgumentException("Unsupported family");
+ }
+ }
+
+ /**
+ * Convenience method to add a network address to the VPN interface
+ * using a numeric address string. See {@link InetAddress} for the
+ * definitions of numeric address formats.
+ *
+ * @throws IllegalArgumentException if the address is invalid.
+ * @see #addAddress(InetAddress, int)
+ */
+ public VpnBuilder addAddress(String address, int prefixLength) {
+ return addAddress(InetAddress.parseNumericAddress(address), prefixLength);
+ }
+
+ /**
+ * Add a network address to the VPN interface. Both IPv4 and IPv6
+ * addresses are supported. At least one address must be set before
+ * calling {@link #establish}.
+ *
+ * @throws IllegalArgumentException if the address is invalid.
+ */
+ public VpnBuilder addAddress(InetAddress address, int prefixLength) {
+ check(address, prefixLength);
+
+ if (address.isAnyLocalAddress()) {
+ throw new IllegalArgumentException("Bad address");
+ }
+
+ mAddresses.append(String.format(" %s/%d", address.getHostAddress(), prefixLength));
+ return this;
+ }
+
+ /**
+ * Convenience method to add a network route to the VPN interface
+ * using a numeric address string. See {@link InetAddress} for the
+ * definitions of numeric address formats.
+ *
+ * @see #addRoute(InetAddress, int)
+ * @throws IllegalArgumentException if the route is invalid.
+ */
+ public VpnBuilder addRoute(String address, int prefixLength) {
+ return addRoute(InetAddress.parseNumericAddress(address), prefixLength);
+ }
+
+ /**
+ * Add a network route to the VPN interface. Both IPv4 and IPv6
+ * routes are supported.
+ *
+ * @throws IllegalArgumentException if the route is invalid.
+ */
+ public VpnBuilder addRoute(InetAddress address, int prefixLength) {
+ check(address, prefixLength);
+
+ int offset = prefixLength / 8;
+ byte[] bytes = address.getAddress();
+ if (offset < bytes.length) {
+ if ((byte)(bytes[offset] << (prefixLength % 8)) != 0) {
+ throw new IllegalArgumentException("Bad address");
+ }
+ while (++offset < bytes.length) {
+ if (bytes[offset] != 0) {
+ throw new IllegalArgumentException("Bad address");
+ }
+ }
+ }
+
+ mRoutes.append(String.format(" %s/%d", address.getHostAddress(), prefixLength));
+ return this;
+ }
+
+ /**
+ * Convenience method to add a DNS server to the VPN connection
+ * using a numeric address string. See {@link InetAddress} for the
+ * definitions of numeric address formats.
+ *
+ * @throws IllegalArgumentException if the address is invalid.
+ * @see #addDnsServer(InetAddress)
+ */
+ public VpnBuilder addDnsServer(String address) {
+ return addDnsServer(InetAddress.parseNumericAddress(address));
+ }
+
+ /**
+ * Add a DNS server to the VPN connection. Both IPv4 and IPv6
+ * addresses are supported. If none is set, the DNS servers of
+ * the default network will be used.
+ *
+ * @throws IllegalArgumentException if the address is invalid.
+ */
+ public VpnBuilder addDnsServer(InetAddress address) {
+ if (address.isLoopbackAddress() || address.isAnyLocalAddress()) {
+ throw new IllegalArgumentException("Bad address");
+ }
+ if (mConfig.dnsServers == null) {
+ mConfig.dnsServers = new ArrayList<String>();
+ }
+ mConfig.dnsServers.add(address.getHostAddress());
+ return this;
+ }
+
+ /**
+ * Add a search domain to the DNS resolver.
+ */
+ public VpnBuilder addSearchDomain(String domain) {
+ if (mConfig.searchDomains == null) {
+ mConfig.searchDomains = new ArrayList<String>();
+ }
+ mConfig.searchDomains.add(domain);
+ return this;
+ }
+
+ /**
+ * Create a VPN interface using the parameters supplied to this builder.
+ * The interface works on IP packets, and a file descriptor is returned
+ * for the application to access them. Each read retrieves an outgoing
+ * packet which was routed to the interface. Each write injects an
+ * incoming packet just like it was received from the interface. The file
+ * descriptor is put into non-blocking mode by default to avoid blocking
+ * Java threads. To use the file descriptor completely in native space,
+ * see {@link ParcelFileDescriptor#detachFd()}. The application MUST
+ * close the file descriptor when the VPN connection is terminated. The
+ * VPN interface will be removed and the network will be restored by the
+ * framework automatically.
+ *
+ * <p>To avoid conflicts, there can be only one active VPN interface at
+ * the same time. Usually network parameters are never changed during the
+ * lifetime of a VPN connection. It is also common for an application to
+ * create a new file descriptor after closing the previous one. However,
+ * it is rare but not impossible to have two interfaces while performing a
+ * seamless handover. In this case, the old interface will be deactivated
+ * when the new one is configured successfully. Both file descriptors are
+ * valid but now outgoing packets will be routed to the new interface.
+ * Therefore, after draining the old file descriptor, the application MUST
+ * close it and start using the new file descriptor. If the new interface
+ * cannot be created, the existing interface and its file descriptor remain
+ * untouched.
+ *
+ * <p>An exception will be thrown if the interface cannot be created for
+ * any reason. However, this method returns {@code null} if the application
+ * is not prepared or is revoked by another application. This helps solve
+ * possible race conditions while handling {@link #ACTION_VPN_REVOKED}
+ * broadcasts.
+ *
+ * @return {@link ParcelFileDescriptor} of the VPN interface, or
+ * {@code null} if the application is not prepared.
+ * @throws IllegalArgumentException if a parameter is not accepted by the
+ * operating system.
+ * @throws IllegalStateException if a parameter cannot be applied by the
+ * operating system.
+ * @see #prepare
+ */
+ public ParcelFileDescriptor establish() {
+ mConfig.addresses = mAddresses.toString();
+ mConfig.routes = mRoutes.toString();
+
+ try {
+ return getService().establishVpn(mConfig);
+ } catch (RemoteException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Protect a socket from VPN connections. The socket will be bound to the
+ * current default network interface, so its traffic will not be forwarded
+ * through VPN. This method is useful if some connections need to be kept
+ * outside of VPN. For example, a VPN tunnel should protect itself if its
+ * destination is covered by VPN routes. Otherwise its outgoing packets
+ * will be sent back to the VPN interface and cause an infinite loop.
+ *
+ * <p>The socket is NOT closed by this method.
+ *
+ * @return {@code true} on success.
+ */
+ public static boolean protect(int socket) {
+ ParcelFileDescriptor dup = null;
+ try {
+ dup = ParcelFileDescriptor.fromFd(socket);
+ return getService().protectVpn(dup);
+ } catch (Exception e) {
+ return false;
+ } finally {
+ try {
+ dup.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+
+ /**
+ * Protect a {@link Socket} from VPN connections.
+ *
+ * @return {@code true} on success.
+ * @see #protect(int)
+ */
+ public static boolean protect(Socket socket) {
+ return protect(socket.getFileDescriptor$().getInt$());
+ }
+
+ /**
+ * Protect a {@link DatagramSocket} from VPN connections.
+ *
+ * @return {@code true} on success.
+ * @see #protect(int)
+ */
+ public static boolean protect(DatagramSocket socket) {
+ return protect(socket.getFileDescriptor$().getInt$());
+ }
+}
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 @@
/**
* 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 @@
/**
* 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 @@
/**
* 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 @@
/**
* 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 @@
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/PreferenceActivity.java b/core/java/android/preference/PreferenceActivity.java
index c90de17..78c9010 100644
--- a/core/java/android/preference/PreferenceActivity.java
+++ b/core/java/android/preference/PreferenceActivity.java
@@ -563,6 +563,12 @@
// Single pane, showing just a prefs fragment.
findViewById(com.android.internal.R.id.headers).setVisibility(View.GONE);
mPrefsContainer.setVisibility(View.VISIBLE);
+ if (initialTitle != 0) {
+ CharSequence initialTitleStr = getText(initialTitle);
+ CharSequence initialShortTitleStr = initialShortTitle != 0
+ ? getText(initialShortTitle) : null;
+ showBreadCrumbs(initialTitleStr, initialShortTitleStr);
+ }
} else if (mHeaders.size() > 0) {
setListAdapter(new HeaderAdapter(this, mHeaders));
if (!mSinglePane) {
@@ -1093,6 +1099,10 @@
} else {
getListView().clearChoices();
}
+ showBreadCrumbs(header);
+ }
+
+ void showBreadCrumbs(Header header) {
if (header != null) {
CharSequence title = header.getBreadCrumbTitle(getResources());
if (title == null) title = header.getTitle(getResources());
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 @@
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 @@
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 @@
}
/**
- * 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 @@
}
};
}
+
+ 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 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 @@
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 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 ad32047..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.util.HashMap;
import java.util.HashSet;
-
/**
* The Settings provider contains global system-level device preferences.
*/
@@ -2691,11 +2688,9 @@
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.
@@ -2877,6 +2872,7 @@
* The acceptable packet loss percentage (range 0 - 100) before trying
* another AP on the same network.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_ACCEPTABLE_PACKET_LOSS_PERCENTAGE =
"wifi_watchdog_acceptable_packet_loss_percentage";
@@ -2884,11 +2880,13 @@
* The number of access points required for a network in order for the
* watchdog to monitor it.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_AP_COUNT = "wifi_watchdog_ap_count";
/**
* The delay between background checks.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_DELAY_MS =
"wifi_watchdog_background_check_delay_ms";
@@ -2896,12 +2894,14 @@
* Whether the Wi-Fi watchdog is enabled for background checking even
* after it thinks the user has connected to a good access point.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_ENABLED =
"wifi_watchdog_background_check_enabled";
/**
* The timeout for a background ping
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_BACKGROUND_CHECK_TIMEOUT_MS =
"wifi_watchdog_background_check_timeout_ms";
@@ -2911,6 +2911,7 @@
* calculation. For example, one network always seemed to time out for
* the first couple pings, so this is set to 3 by default.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_INITIAL_IGNORED_PING_COUNT =
"wifi_watchdog_initial_ignored_ping_count";
@@ -2920,6 +2921,7 @@
* initial connection state for the network. This is a safeguard for
* networks containing multiple APs whose DNS does not respond to pings.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_MAX_AP_CHECKS = "wifi_watchdog_max_ap_checks";
/**
@@ -2930,24 +2932,85 @@
/**
* A comma-separated list of SSIDs for which the Wi-Fi watchdog should be enabled.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_WATCH_LIST = "wifi_watchdog_watch_list";
/**
* The number of pings to test if an access point is a good connection.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_PING_COUNT = "wifi_watchdog_ping_count";
/**
* The delay between pings.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_PING_DELAY_MS = "wifi_watchdog_ping_delay_ms";
/**
* The timeout per ping.
*/
+ @Deprecated
public static final String WIFI_WATCHDOG_PING_TIMEOUT_MS = "wifi_watchdog_ping_timeout_ms";
/**
+ * ms delay before rechecking an 'online' wifi connection when it is thought to be unstable.
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_DNS_CHECK_SHORT_INTERVAL_MS =
+ "wifi_watchdog_dns_check_short_interval_ms";
+
+ /**
+ * ms delay before rechecking an 'online' wifi connection when it is thought to be stable.
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_DNS_CHECK_LONG_INTERVAL_MS =
+ "wifi_watchdog_dns_check_long_interval_ms";
+
+ /**
+ * ms delay before rechecking a connect SSID for walled garden with a http download.
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_WALLED_GARDEN_INTERVAL_MS =
+ "wifi_watchdog_walled_garden_interval_ms";
+
+ /**
+ * max blacklist calls on an SSID before full dns check failures disable the network.
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_MAX_SSID_BLACKLISTS =
+ "wifi_watchdog_max_ssid_blacklists";
+
+ /**
+ * Number of dns pings per check.
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_NUM_DNS_PINGS = "wifi_watchdog_num_dns_pings";
+
+ /**
+ * Minimum number of responses to the dns pings to consider the test 'successful'.
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_MIN_DNS_RESPONSES =
+ "wifi_watchdog_min_dns_responses";
+
+ /**
+ * Timeout on dns pings
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_DNS_PING_TIMEOUT_MS =
+ "wifi_watchdog_dns_ping_timeout_ms";
+
+ /**
+ * We consider action from a 'blacklist' call to have finished by the end of
+ * this interval. If we are connected to the same AP with no network connection,
+ * we are likely stuck on an SSID with no external connectivity.
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_BLACKLIST_FOLLOWUP_INTERVAL_MS =
+ "wifi_watchdog_blacklist_followup_interval_ms";
+
+ /**
* Setting to turn off walled garden test on Wi-Fi. Feature is enabled by default and
* the setting needs to be set to 0 to disable it.
* @hide
@@ -2972,6 +3035,14 @@
"wifi_watchdog_walled_garden_pattern";
/**
+ * Boolean to determine whether to notify on disabling a network. Secure setting used
+ * to notify user only once. This setting is not monitored continuously.
+ * @hide
+ */
+ public static final String WIFI_WATCHDOG_SHOW_DISABLED_NETWORK_POPUP =
+ "wifi_watchdog_show_disabled_network_popup";
+
+ /**
* The maximum number of times we will retry a connection to an access
* point for which we have failed in acquiring an IP address from DHCP.
* A value of N means that we will make N+1 connection attempts in all.
@@ -3661,6 +3732,15 @@
*/
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/>
@@ -3853,6 +3933,10 @@
/** 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 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/BluetoothBondState.java b/core/java/android/server/BluetoothBondState.java
index 75f38f9..30a8b2a 100644
--- a/core/java/android/server/BluetoothBondState.java
+++ b/core/java/android/server/BluetoothBondState.java
@@ -21,8 +21,13 @@
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothA2dp;
import android.bluetooth.BluetoothHeadset;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.provider.Settings;
import android.util.Log;
import java.io.BufferedReader;
@@ -74,11 +79,17 @@
private BluetoothA2dp mA2dpProxy;
private BluetoothHeadset mHeadsetProxy;
+ private ArrayList<String> mPairingRequestRcvd = new ArrayList<String>();
+
BluetoothBondState(Context context, BluetoothService service) {
mContext = context;
mService = service;
mBluetoothInputProfileHandler =
BluetoothInputProfileHandler.getInstance(mContext, mService);
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(BluetoothDevice.ACTION_PAIRING_REQUEST);
+ mContext.registerReceiver(mReceiver, filter);
}
synchronized void setPendingOutgoingBonding(String address) {
@@ -137,11 +148,18 @@
}
if (state == BluetoothDevice.BOND_BONDED) {
- mService.addProfileState(address);
+ boolean setTrust = false;
+ if (mPairingRequestRcvd.contains(address)) setTrust = true;
+
+ mService.addProfileState(address, setTrust);
+ mPairingRequestRcvd.remove(address);
+
} else if (state == BluetoothDevice.BOND_BONDING) {
if (mA2dpProxy == null || mHeadsetProxy == null) {
getProfileProxy();
}
+ } else if (state == BluetoothDevice.BOND_NONE) {
+ mPairingRequestRcvd.remove(address);
}
setProfilePriorities(address, state);
@@ -452,4 +470,17 @@
}
}
+ private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent == null) return;
+
+ String action = intent.getAction();
+ if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
+ BluetoothDevice dev = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
+ String address = dev.getAddress();
+ mPairingRequestRcvd.add(address);
+ }
+ }
+ };
}
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 @@
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 @@
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 @@
/**
* 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 @@
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 ff16c18..34f1971 100755
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -91,7 +91,7 @@
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 @@
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 @@
disableNative();
}
- mBluetoothState = BluetoothAdapter.STATE_OFF;
mIsDiscovering = false;
mBondState = new BluetoothBondState(context, this);
@@ -306,7 +304,9 @@
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 @@
}
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 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 @@
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 @@
}
}
- 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 @@
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 @@
}
}
+ /**
+ * 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 @@
if (mIsAirplaneSensitive && isAirplaneModeOn() && !mIsAirplaneToggleable) {
return false;
}
- if (mBluetoothState != BluetoothAdapter.STATE_OFF) {
+ 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;
}
- if (mEnableThread != null && mEnableThread.isAlive()) {
- 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 @@
}
}
- 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) {
@@ -527,74 +505,24 @@
break;
case MESSAGE_AUTO_PAIRING_FAILURE_ATTEMPT_DELAY:
address = (String)msg.obj;
- if (address != null) {
+ if (address == null) return;
+ int attempt = mBondState.getAttempt(address);
+
+ // Try only if attemps are in progress and cap it 2 attempts
+ // The 2 attempts cap is a fail safe if the stack returns
+ // an incorrect error code for bonding failures and if the pin
+ // is entered wrongly twice we should abort.
+ if (attempt > 0 && attempt <= 2) {
+ mBondState.attempt(address);
createBond(address);
return;
}
+ if (attempt > 0) mBondState.clearPinAttempts(address);
break;
}
}
};
- 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()];
@@ -641,38 +569,37 @@
* 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);
+ /*package*/ synchronized void updateBluetoothState(String uuids) {
+ 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);
- }
-
- 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) {
@@ -741,7 +668,6 @@
BluetoothDevice.BOND_NONE, result);
return;
}
- mBondState.attempt(address);
}
/*package*/ BluetoothDevice getRemoteDevice(String address) {
@@ -810,6 +736,26 @@
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;
@@ -831,9 +777,15 @@
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;
}
@@ -1561,14 +1513,10 @@
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,
@@ -1642,8 +1590,7 @@
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
- dumpBluetoothState(pw);
- if (mBluetoothState != BluetoothAdapter.STATE_ON) {
+ if (getBluetoothStateInternal() != BluetoothAdapter.STATE_ON) {
return;
}
@@ -1832,25 +1779,6 @@
}
}
- 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) {
@@ -2277,11 +2205,11 @@
return false;
}
- BluetoothDeviceProfileState addProfileState(String address) {
+ BluetoothDeviceProfileState addProfileState(String address, boolean setTrust) {
BluetoothDeviceProfileState state = mDeviceProfileState.get(address);
if (state != null) return state;
- state = new BluetoothDeviceProfileState(mContext, address, this, mA2dpService);
+ state = new BluetoothDeviceProfileState(mContext, address, this, mA2dpService, setTrust);
mDeviceProfileState.put(address, state);
state.start();
return state;
@@ -2311,7 +2239,7 @@
}
for (String path : bonds) {
String address = getAddressFromObjectPath(path);
- BluetoothDeviceProfileState state = addProfileState(address);
+ BluetoothDeviceProfileState state = addProfileState(address, false);
}
}
@@ -2381,7 +2309,7 @@
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) ||
@@ -2397,6 +2325,10 @@
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,
@@ -2590,8 +2522,8 @@
/*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/text/format/Time.java b/core/java/android/text/format/Time.java
index c6ffe58..5926db3 100644
--- a/core/java/android/text/format/Time.java
+++ b/core/java/android/text/format/Time.java
@@ -281,10 +281,29 @@
}
/**
- * return a negative number if a is less than b, a positive number if a is
- * greater than b, and 0 if they are equal.
+ * Compare two {@code Time} objects and return a negative number if {@code
+ * a} is less than {@code b}, a positive number if {@code a} is greater than
+ * {@code b}, or 0 if they are equal.
+ *
+ * @param a first {@code Time} instance to compare
+ * @param b second {@code Time} instance to compare
+ * @throws NullPointerException if either argument is {@code null}
+ * @throws IllegalArgumentException if {@link #allDay} is true but {@code
+ * hour}, {@code minute}, and {@code second} are not 0.
+ * @return a negative result if {@code a} is earlier, a positive result if
+ * {@code a} is earlier, or 0 if they are equal.
*/
- native public static int compare(Time a, Time b);
+ public static int compare(Time a, Time b) {
+ if (a == null) {
+ throw new NullPointerException("a == null");
+ } else if (b == null) {
+ throw new NullPointerException("b == null");
+ }
+
+ return nativeCompare(a, b);
+ }
+
+ private static native int nativeCompare(Time a, Time b);
/**
* Print the current value given the format string provided. See man
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 @@
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 @@
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/CollapsibleActionView.java b/core/java/android/view/CollapsibleActionView.java
new file mode 100644
index 0000000..ab2365e
--- /dev/null
+++ b/core/java/android/view/CollapsibleActionView.java
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+import android.view.MenuItem.OnActionExpandListener;
+
+/**
+ * When a {@link View} implements this interface it will receive callbacks
+ * when expanded or collapsed as an action view alongside the optional,
+ * app-specified callbacks to {@link OnActionExpandListener}.
+ *
+ * <p>See {@link MenuItem} for more information about action views.
+ * See {@link android.app.ActionBar} for more information about the action bar.
+ */
+public interface CollapsibleActionView {
+ /**
+ * Called when this view is expanded as an action view.
+ * See {@link MenuItem#expandActionView()}.
+ */
+ public void onActionViewExpanded();
+
+ /**
+ * Called when this view is collapsed as an action view.
+ * See {@link MenuItem#collapseActionView()}.
+ */
+ public void onActionViewCollapsed();
+}
diff --git a/core/java/android/view/DisplayList.java b/core/java/android/view/DisplayList.java
index 4484d59..f4c0249 100644
--- a/core/java/android/view/DisplayList.java
+++ b/core/java/android/view/DisplayList.java
@@ -41,15 +41,6 @@
abstract void end();
/**
- * Indicates whether this display list can be replayed or not.
- *
- * @return True if the display list can be replayed, false otherwise.
- *
- * @see android.view.HardwareCanvas#drawDisplayList(DisplayList)
- */
- abstract boolean isReady();
-
- /**
* Invalidates the display list, indicating that it should be repopulated
* with new drawing commands prior to being used again. Calling this method
* causes calls to {@link #isValid()} to return <code>false</code>.
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index 80244bb..d22fa6e 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -51,6 +51,7 @@
// The native renderer will be destroyed when this object dies.
// DO NOT overwrite this reference once it is set.
+ @SuppressWarnings("unused")
private CanvasFinalizer mFinalizer;
private int mWidth;
@@ -97,12 +98,8 @@
protected GLES20Canvas(boolean record, boolean translucent) {
mOpaque = !translucent;
- setupRenderer(record);
- }
-
- protected void setupRenderer(boolean record) {
if (record) {
- mRenderer = nGetDisplayListRenderer(mRenderer);
+ mRenderer = nCreateDisplayListRenderer();
} else {
mRenderer = nCreateRenderer();
}
@@ -114,43 +111,31 @@
if (mRenderer == 0) {
throw new IllegalStateException("Could not create GLES20Canvas renderer");
} else {
- mFinalizer = CanvasFinalizer.getFinalizer(mFinalizer, mRenderer);
+ mFinalizer = new CanvasFinalizer(mRenderer);
}
}
+ protected void resetDisplayListRenderer() {
+ nResetDisplayListRenderer(mRenderer);
+ }
+
private static native int nCreateRenderer();
private static native int nCreateLayerRenderer(int layer);
- private static native int nGetDisplayListRenderer(int renderer);
+ private static native int nCreateDisplayListRenderer();
+ private static native void nResetDisplayListRenderer(int renderer);
private static native void nDestroyRenderer(int renderer);
- private static class CanvasFinalizer {
- int mRenderer;
+ private static final class CanvasFinalizer {
+ private final int mRenderer;
- // Factory method returns new instance if old one is null, or old instance
- // otherwise, destroying native renderer along the way as necessary
- static CanvasFinalizer getFinalizer(CanvasFinalizer oldFinalizer, int renderer) {
- if (oldFinalizer == null) {
- return new CanvasFinalizer(renderer);
- }
- oldFinalizer.replaceNativeObject(renderer);
- return oldFinalizer;
- }
-
- private CanvasFinalizer(int renderer) {
+ public CanvasFinalizer(int renderer) {
mRenderer = renderer;
}
- private void replaceNativeObject(int newRenderer) {
- if (mRenderer != 0 && newRenderer != mRenderer) {
- nDestroyRenderer(mRenderer);
- }
- mRenderer = newRenderer;
- }
-
@Override
protected void finalize() throws Throwable {
try {
- replaceNativeObject(0);
+ nDestroyRenderer(mRenderer);
} finally {
super.finalize();
}
@@ -322,11 +307,11 @@
// Display list
///////////////////////////////////////////////////////////////////////////
- int getDisplayList() {
- return nGetDisplayList(mRenderer);
+ int getDisplayList(int displayList) {
+ return nGetDisplayList(mRenderer, displayList);
}
- private static native int nGetDisplayList(int renderer);
+ private static native int nGetDisplayList(int renderer, int displayList);
static void destroyDisplayList(int displayList) {
nDestroyDisplayList(displayList);
@@ -337,7 +322,7 @@
@Override
public boolean drawDisplayList(DisplayList displayList, int width, int height, Rect dirty) {
return nDrawDisplayList(mRenderer,
- ((GLES20DisplayList) displayList).mNativeDisplayList, width, height, dirty);
+ ((GLES20DisplayList) displayList).getNativeDisplayList(), width, height, dirty);
}
private static native boolean nDrawDisplayList(int renderer, int displayList,
@@ -345,7 +330,7 @@
@Override
void outputDisplayList(DisplayList displayList) {
- nOutputDisplayList(mRenderer, ((GLES20DisplayList) displayList).mNativeDisplayList);
+ nOutputDisplayList(mRenderer, ((GLES20DisplayList) displayList).getNativeDisplayList());
}
private static native void nOutputDisplayList(int renderer, int displayList);
diff --git a/core/java/android/view/GLES20DisplayList.java b/core/java/android/view/GLES20DisplayList.java
index aeff31f..9e649cea 100644
--- a/core/java/android/view/GLES20DisplayList.java
+++ b/core/java/android/view/GLES20DisplayList.java
@@ -16,52 +16,50 @@
package android.view;
-import java.lang.ref.WeakReference;
+import android.graphics.Bitmap;
+
+import java.util.ArrayList;
/**
* An implementation of display list for OpenGL ES 2.0.
*/
class GLES20DisplayList extends DisplayList {
- private GLES20Canvas mCanvas;
+ // These lists ensure that any Bitmaps recorded by a DisplayList are kept alive as long
+ // as the DisplayList is alive. The Bitmaps are populated by the GLES20RecordingCanvas.
+ final ArrayList<Bitmap> mBitmaps = new ArrayList<Bitmap>(5);
- private boolean mStarted = false;
- private boolean mRecorded = false;
- private boolean mValid = false;
-
- int mNativeDisplayList;
- WeakReference<View> hostView;
+ private GLES20RecordingCanvas mCanvas;
+ private boolean mValid;
// The native display list will be destroyed when this object dies.
// DO NOT overwrite this reference once it is set.
- @SuppressWarnings("unused")
private DisplayListFinalizer mFinalizer;
- public GLES20DisplayList(View view) {
- hostView = new WeakReference<View>(view);
+ int getNativeDisplayList() {
+ if (!mValid || mFinalizer == null) {
+ throw new IllegalStateException("The display list is not valid.");
+ }
+ return mFinalizer.mNativeDisplayList;
}
@Override
HardwareCanvas start() {
- if (mStarted) {
+ if (mCanvas != null) {
throw new IllegalStateException("Recording has already started");
}
- if (mCanvas != null) {
- ((GLES20RecordingCanvas) mCanvas).reset();
- } else {
- mCanvas = new GLES20RecordingCanvas(true);
- }
- mStarted = true;
- mRecorded = false;
- mValid = true;
-
+ mValid = false;
+ mCanvas = GLES20RecordingCanvas.obtain(this);
+ mCanvas.start();
return mCanvas;
}
@Override
void invalidate() {
- mStarted = false;
- mRecorded = false;
+ if (mCanvas != null) {
+ mCanvas.recycle();
+ mCanvas = null;
+ }
mValid = false;
}
@@ -73,48 +71,28 @@
@Override
void end() {
if (mCanvas != null) {
- mStarted = false;
- mRecorded = true;
-
- mNativeDisplayList = mCanvas.getDisplayList();
- mFinalizer = DisplayListFinalizer.getFinalizer(mFinalizer, mNativeDisplayList);
+ if (mFinalizer != null) {
+ mCanvas.end(mFinalizer.mNativeDisplayList);
+ } else {
+ mFinalizer = new DisplayListFinalizer(mCanvas.end(0));
+ }
+ mCanvas.recycle();
+ mCanvas = null;
+ mValid = true;
}
}
- @Override
- boolean isReady() {
- return !mStarted && mRecorded;
- }
-
private static class DisplayListFinalizer {
- int mNativeDisplayList;
+ final int mNativeDisplayList;
- // Factory method returns new instance if old one is null, or old instance
- // otherwise, destroying native display list along the way as necessary
- static DisplayListFinalizer getFinalizer(DisplayListFinalizer oldFinalizer,
- int nativeDisplayList) {
- if (oldFinalizer == null) {
- return new DisplayListFinalizer(nativeDisplayList);
- }
- oldFinalizer.replaceNativeObject(nativeDisplayList);
- return oldFinalizer;
- }
-
- private DisplayListFinalizer(int nativeDisplayList) {
+ public DisplayListFinalizer(int nativeDisplayList) {
mNativeDisplayList = nativeDisplayList;
}
- private void replaceNativeObject(int newNativeDisplayList) {
- if (mNativeDisplayList != 0 && mNativeDisplayList != newNativeDisplayList) {
- GLES20Canvas.destroyDisplayList(mNativeDisplayList);
- }
- mNativeDisplayList = newNativeDisplayList;
- }
-
@Override
protected void finalize() throws Throwable {
try {
- replaceNativeObject(0);
+ GLES20Canvas.destroyDisplayList(mNativeDisplayList);
} finally {
super.finalize();
}
diff --git a/core/java/android/view/GLES20RecordingCanvas.java b/core/java/android/view/GLES20RecordingCanvas.java
index ec94fe7..078222b 100644
--- a/core/java/android/view/GLES20RecordingCanvas.java
+++ b/core/java/android/view/GLES20RecordingCanvas.java
@@ -24,8 +24,10 @@
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
-
-import java.util.ArrayList;
+import android.util.Pool;
+import android.util.Poolable;
+import android.util.PoolableManager;
+import android.util.Pools;
/**
* An implementation of a GL canvas that records drawing operations.
@@ -33,62 +35,94 @@
* Bitmap objects that it draws, preventing the backing memory of Bitmaps from being freed while
* the DisplayList is still holding a native reference to the memory.
*/
-class GLES20RecordingCanvas extends GLES20Canvas {
- // These lists ensure that any Bitmaps recorded by a DisplayList are kept alive as long
- // as the DisplayList is alive.
- @SuppressWarnings({"MismatchedQueryAndUpdateOfCollection"})
- private final ArrayList<Bitmap> mBitmaps = new ArrayList<Bitmap>(5);
+class GLES20RecordingCanvas extends GLES20Canvas implements Poolable<GLES20RecordingCanvas> {
+ // The recording canvas pool should be large enough to handle a deeply nested
+ // view hierarchy because display lists are generated recursively.
+ private static final int POOL_LIMIT = 50;
- GLES20RecordingCanvas(boolean translucent) {
- super(true, translucent);
+ private static final Pool<GLES20RecordingCanvas> sPool = Pools.synchronizedPool(
+ Pools.finitePool(new PoolableManager<GLES20RecordingCanvas>() {
+ public GLES20RecordingCanvas newInstance() {
+ return new GLES20RecordingCanvas();
+ }
+ @Override
+ public void onAcquired(GLES20RecordingCanvas element) {
+ }
+ @Override
+ public void onReleased(GLES20RecordingCanvas element) {
+ }
+ }, POOL_LIMIT));
+
+ private GLES20RecordingCanvas mNextPoolable;
+ private boolean mIsPooled;
+
+ private GLES20DisplayList mDisplayList;
+
+ private GLES20RecordingCanvas() {
+ super(true /*record*/, true /*translucent*/);
+ }
+
+ static GLES20RecordingCanvas obtain(GLES20DisplayList displayList) {
+ GLES20RecordingCanvas canvas = sPool.acquire();
+ canvas.mDisplayList = displayList;
+ return canvas;
+ }
+
+ void recycle() {
+ mDisplayList = null;
+ resetDisplayListRenderer();
+ sPool.release(this);
+ }
+
+ void start() {
+ mDisplayList.mBitmaps.clear();
+ }
+
+ int end(int nativeDisplayList) {
+ return getDisplayList(nativeDisplayList);
}
private void recordShaderBitmap(Paint paint) {
if (paint != null) {
final Shader shader = paint.getShader();
if (shader instanceof BitmapShader) {
- mBitmaps.add(((BitmapShader) shader).mBitmap);
+ mDisplayList.mBitmaps.add(((BitmapShader) shader).mBitmap);
}
}
}
- void reset() {
- mBitmaps.clear();
- setupRenderer(true);
- }
-
@Override
public void drawPatch(Bitmap bitmap, byte[] chunks, RectF dst, Paint paint) {
super.drawPatch(bitmap, chunks, dst, paint);
- mBitmaps.add(bitmap);
+ mDisplayList.mBitmaps.add(bitmap);
// Shaders in the Paint are ignored when drawing a Bitmap
}
@Override
public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
super.drawBitmap(bitmap, left, top, paint);
- mBitmaps.add(bitmap);
+ mDisplayList.mBitmaps.add(bitmap);
// Shaders in the Paint are ignored when drawing a Bitmap
}
@Override
public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
super.drawBitmap(bitmap, matrix, paint);
- mBitmaps.add(bitmap);
+ mDisplayList.mBitmaps.add(bitmap);
// Shaders in the Paint are ignored when drawing a Bitmap
}
@Override
public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
super.drawBitmap(bitmap, src, dst, paint);
- mBitmaps.add(bitmap);
+ mDisplayList.mBitmaps.add(bitmap);
// Shaders in the Paint are ignored when drawing a Bitmap
}
@Override
public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) {
super.drawBitmap(bitmap, src, dst, paint);
- mBitmaps.add(bitmap);
+ mDisplayList.mBitmaps.add(bitmap);
// Shaders in the Paint are ignored when drawing a Bitmap
}
@@ -111,7 +145,7 @@
int vertOffset, int[] colors, int colorOffset, Paint paint) {
super.drawBitmapMesh(bitmap, meshWidth, meshHeight, verts, vertOffset, colors, colorOffset,
paint);
- mBitmaps.add(bitmap);
+ mDisplayList.mBitmaps.add(bitmap);
// Shaders in the Paint are ignored when drawing a Bitmap
}
@@ -270,4 +304,24 @@
colorOffset, indices, indexOffset, indexCount, paint);
recordShaderBitmap(paint);
}
+
+ @Override
+ public GLES20RecordingCanvas getNextPoolable() {
+ return mNextPoolable;
+ }
+
+ @Override
+ public void setNextPoolable(GLES20RecordingCanvas element) {
+ mNextPoolable = element;
+ }
+
+ @Override
+ public boolean isPooled() {
+ return mIsPooled;
+ }
+
+ @Override
+ public void setPooled(boolean isPooled) {
+ mIsPooled = isPooled;
+ }
}
diff --git a/core/java/android/view/HardwareRenderer.java b/core/java/android/view/HardwareRenderer.java
index b865b50..14a77b4 100644
--- a/core/java/android/view/HardwareRenderer.java
+++ b/core/java/android/view/HardwareRenderer.java
@@ -33,6 +33,8 @@
import javax.microedition.khronos.egl.EGLSurface;
import javax.microedition.khronos.opengles.GL;
+import static javax.microedition.khronos.egl.EGL10.*;
+
/**
* Interface for rendering a ViewAncestor using hardware acceleration.
*
@@ -70,6 +72,15 @@
static final String DISABLE_VSYNC_PROPERTY = "hwui.disable_vsync";
/**
+ * System property used to debug EGL configuration choice.
+ *
+ * Possible values:
+ * "choice", print the chosen configuration only
+ * "all", print all possible configurations
+ */
+ static final String PRINT_CONFIG_PROPERTY = "hwui.print_config";
+
+ /**
* Turn on to draw dirty regions every other frame.
*/
private static final boolean DEBUG_DIRTY_REGION = false;
@@ -189,7 +200,7 @@
*
* @return A new display list.
*/
- abstract DisplayList createDisplayList(View v);
+ abstract DisplayList createDisplayList();
/**
* Creates a new hardware layer. A hardware layer built by calling this
@@ -389,33 +400,33 @@
*/
static String getEGLErrorString(int error) {
switch (error) {
- case EGL10.EGL_SUCCESS:
+ case EGL_SUCCESS:
return "EGL_SUCCESS";
- case EGL10.EGL_NOT_INITIALIZED:
+ case EGL_NOT_INITIALIZED:
return "EGL_NOT_INITIALIZED";
- case EGL10.EGL_BAD_ACCESS:
+ case EGL_BAD_ACCESS:
return "EGL_BAD_ACCESS";
- case EGL10.EGL_BAD_ALLOC:
+ case EGL_BAD_ALLOC:
return "EGL_BAD_ALLOC";
- case EGL10.EGL_BAD_ATTRIBUTE:
+ case EGL_BAD_ATTRIBUTE:
return "EGL_BAD_ATTRIBUTE";
- case EGL10.EGL_BAD_CONFIG:
+ case EGL_BAD_CONFIG:
return "EGL_BAD_CONFIG";
- case EGL10.EGL_BAD_CONTEXT:
+ case EGL_BAD_CONTEXT:
return "EGL_BAD_CONTEXT";
- case EGL10.EGL_BAD_CURRENT_SURFACE:
+ case EGL_BAD_CURRENT_SURFACE:
return "EGL_BAD_CURRENT_SURFACE";
- case EGL10.EGL_BAD_DISPLAY:
+ case EGL_BAD_DISPLAY:
return "EGL_BAD_DISPLAY";
- case EGL10.EGL_BAD_MATCH:
+ case EGL_BAD_MATCH:
return "EGL_BAD_MATCH";
- case EGL10.EGL_BAD_NATIVE_PIXMAP:
+ case EGL_BAD_NATIVE_PIXMAP:
return "EGL_BAD_NATIVE_PIXMAP";
- case EGL10.EGL_BAD_NATIVE_WINDOW:
+ case EGL_BAD_NATIVE_WINDOW:
return "EGL_BAD_NATIVE_WINDOW";
- case EGL10.EGL_BAD_PARAMETER:
+ case EGL_BAD_PARAMETER:
return "EGL_BAD_PARAMETER";
- case EGL10.EGL_BAD_SURFACE:
+ case EGL_BAD_SURFACE:
return "EGL_BAD_SURFACE";
case EGL11.EGL_CONTEXT_LOST:
return "EGL_CONTEXT_LOST";
@@ -432,7 +443,7 @@
void checkEglErrors() {
if (isEnabled()) {
int error = sEgl.eglGetError();
- if (error != EGL10.EGL_SUCCESS) {
+ if (error != EGL_SUCCESS) {
// something bad has happened revert to
// normal rendering.
fallback(error != EGL11.EGL_CONTEXT_LOST);
@@ -460,7 +471,7 @@
if (mGl != null) {
int err = sEgl.eglGetError();
- if (err != EGL10.EGL_SUCCESS) {
+ if (err != EGL_SUCCESS) {
destroy(true);
setRequested(false);
} else {
@@ -489,15 +500,17 @@
abstract GLES20Canvas createCanvas();
+ abstract int[] getConfig(boolean dirtyRegions);
+
void initializeEgl() {
synchronized (sEglLock) {
if (sEgl == null && sEglConfig == null) {
sEgl = (EGL10) EGLContext.getEGL();
// Get to the default display.
- sEglDisplay = sEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
+ sEglDisplay = sEgl.eglGetDisplay(EGL_DEFAULT_DISPLAY);
- if (sEglDisplay == EGL10.EGL_NO_DISPLAY) {
+ if (sEglDisplay == EGL_NO_DISPLAY) {
throw new RuntimeException("eglGetDisplay failed "
+ getEGLErrorString(sEgl.eglGetError()));
}
@@ -535,19 +548,63 @@
}
private EGLConfig chooseEglConfig() {
- int[] configsCount = new int[1];
EGLConfig[] configs = new EGLConfig[1];
+ int[] configsCount = new int[1];
int[] configSpec = getConfig(sDirtyRegions);
+
+ // Debug
+ final String debug = SystemProperties.get(PRINT_CONFIG_PROPERTY, "");
+ if ("all".equalsIgnoreCase(debug)) {
+ sEgl.eglChooseConfig(sEglDisplay, configSpec, null, 0, configsCount);
+
+ EGLConfig[] debugConfigs = new EGLConfig[configsCount[0]];
+ sEgl.eglChooseConfig(sEglDisplay, configSpec, debugConfigs,
+ configsCount[0], configsCount);
+
+ for (EGLConfig config : debugConfigs) {
+ printConfig(config);
+ }
+ }
+
if (!sEgl.eglChooseConfig(sEglDisplay, configSpec, configs, 1, configsCount)) {
throw new IllegalArgumentException("eglChooseConfig failed " +
getEGLErrorString(sEgl.eglGetError()));
} else if (configsCount[0] > 0) {
+ if ("choice".equalsIgnoreCase(debug)) {
+ printConfig(configs[0]);
+ }
return configs[0];
}
+
return null;
}
- abstract int[] getConfig(boolean dirtyRegions);
+ private void printConfig(EGLConfig config) {
+ int[] value = new int[1];
+
+ Log.d(LOG_TAG, "EGL configuration " + config + ":");
+
+ sEgl.eglGetConfigAttrib(sEglDisplay, config, EGL_RED_SIZE, value);
+ Log.d(LOG_TAG, " RED_SIZE = " + value[0]);
+
+ sEgl.eglGetConfigAttrib(sEglDisplay, config, EGL_GREEN_SIZE, value);
+ Log.d(LOG_TAG, " GREEN_SIZE = " + value[0]);
+
+ sEgl.eglGetConfigAttrib(sEglDisplay, config, EGL_BLUE_SIZE, value);
+ Log.d(LOG_TAG, " BLUE_SIZE = " + value[0]);
+
+ sEgl.eglGetConfigAttrib(sEglDisplay, config, EGL_ALPHA_SIZE, value);
+ Log.d(LOG_TAG, " ALPHA_SIZE = " + value[0]);
+
+ sEgl.eglGetConfigAttrib(sEglDisplay, config, EGL_DEPTH_SIZE, value);
+ Log.d(LOG_TAG, " DEPTH_SIZE = " + value[0]);
+
+ sEgl.eglGetConfigAttrib(sEglDisplay, config, EGL_STENCIL_SIZE, value);
+ Log.d(LOG_TAG, " STENCIL_SIZE = " + value[0]);
+
+ sEgl.eglGetConfigAttrib(sEglDisplay, config, EGL_SURFACE_TYPE, value);
+ Log.d(LOG_TAG, " SURFACE_TYPE = 0x" + Integer.toHexString(value[0]));
+ }
GL createEglSurface(SurfaceHolder holder) throws Surface.OutOfResourcesException {
// Check preconditions.
@@ -569,22 +626,21 @@
* The window size has changed, so we need to create a new
* surface.
*/
- if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
+ if (mEglSurface != null && mEglSurface != EGL_NO_SURFACE) {
/*
* Unbind and destroy the old EGL surface, if
* there is one.
*/
- sEgl.eglMakeCurrent(sEglDisplay, EGL10.EGL_NO_SURFACE,
- EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
+ sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
sEgl.eglDestroySurface(sEglDisplay, mEglSurface);
}
// Create an EGL surface we can render into.
mEglSurface = sEgl.eglCreateWindowSurface(sEglDisplay, sEglConfig, holder, null);
- if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
+ if (mEglSurface == null || mEglSurface == EGL_NO_SURFACE) {
int error = sEgl.eglGetError();
- if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
+ if (error == EGL_BAD_NATIVE_WINDOW) {
Log.e(LOG_TAG, "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
return null;
}
@@ -621,9 +677,9 @@
}
EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) {
- int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, mGlVersion, EGL10.EGL_NONE };
+ int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, mGlVersion, EGL_NONE };
- return egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT,
+ return egl.eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT,
mGlVersion != 0 ? attrib_list : null);
}
@@ -646,8 +702,7 @@
mDestroyed = true;
- sEgl.eglMakeCurrent(sEglDisplay, EGL10.EGL_NO_SURFACE,
- EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
+ sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
sEgl.eglDestroySurface(sEglDisplay, mEglSurface);
mEglSurface = null;
@@ -660,8 +715,8 @@
void invalidate() {
// Cancels any existing buffer to ensure we'll get a buffer
// of the right size before we call eglSwapBuffers
- sEgl.eglMakeCurrent(sEglDisplay, EGL10.EGL_NO_SURFACE,
- EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
+ sEgl.eglMakeCurrent(sEglDisplay, EGL_NO_SURFACE,
+ EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
@Override
@@ -772,7 +827,7 @@
}
if (!mEglContext.equals(sEgl.eglGetCurrentContext()) ||
- !mEglSurface.equals(sEgl.eglGetCurrentSurface(EGL10.EGL_DRAW))) {
+ !mEglSurface.equals(sEgl.eglGetCurrentSurface(EGL_DRAW))) {
if (!sEgl.eglMakeCurrent(sEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
fallback(true);
Log.e(LOG_TAG, "eglMakeCurrent failed " +
@@ -804,16 +859,16 @@
@Override
int[] getConfig(boolean dirtyRegions) {
return new int[] {
- EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL10.EGL_RED_SIZE, 8,
- EGL10.EGL_GREEN_SIZE, 8,
- EGL10.EGL_BLUE_SIZE, 8,
- EGL10.EGL_ALPHA_SIZE, 8,
- EGL10.EGL_DEPTH_SIZE, 0,
- EGL10.EGL_STENCIL_SIZE, 0,
- EGL_SURFACE_TYPE, EGL10.EGL_WINDOW_BIT |
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_DEPTH_SIZE, 0,
+ EGL_STENCIL_SIZE, 0,
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT |
(dirtyRegions ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT : 0),
- EGL10.EGL_NONE
+ EGL_NONE
};
}
@@ -852,8 +907,8 @@
}
@Override
- DisplayList createDisplayList(View v) {
- return new GLES20DisplayList(v);
+ DisplayList createDisplayList() {
+ return new GLES20DisplayList();
}
@Override
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 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 @@
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 @@
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 0108ecf..2213188 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -3903,6 +3903,7 @@
int[] locationOnScreen = mAttachInfo.mInvalidateChildLocation;
getLocationOnScreen(locationOnScreen);
+ bounds.offsetTo(0, 0);
bounds.offset(locationOnScreen[0], locationOnScreen[1]);
info.setBoundsInScreen(bounds);
@@ -4280,6 +4281,36 @@
}
/**
+ * 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}.
@@ -9099,7 +9130,10 @@
mPrivateFlags2 |= LAYOUT_DIRECTION_RESOLVED;
}
- private void resolvePadding() {
+ /**
+ * @hide
+ */
+ protected void resolvePadding() {
// If the user specified the absolute padding (either with android:padding or
// android:paddingLeft/Top/Right/Bottom), use this padding, otherwise
// use the default padding or the padding from the background drawable
@@ -9830,7 +9864,7 @@
// we copy in child display lists into ours in drawChild()
mRecreateDisplayList = true;
if (mDisplayList == null) {
- mDisplayList = mAttachInfo.mHardwareRenderer.createDisplayList(this);
+ mDisplayList = mAttachInfo.mHardwareRenderer.createDisplayList();
// If we're creating a new display list, make sure our parent gets invalidated
// since they will need to recreate their display list to account for this
// new child display list.
@@ -12025,12 +12059,13 @@
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/ViewDebug.java b/core/java/android/view/ViewDebug.java
index 3798c9d..4acf48c 100644
--- a/core/java/android/view/ViewDebug.java
+++ b/core/java/android/view/ViewDebug.java
@@ -25,6 +25,7 @@
import android.os.Environment;
import android.os.Looper;
import android.os.Message;
+import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.DisplayMetrics;
@@ -36,7 +37,7 @@
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
-import java.io.FileNotFoundException;
+import java.io.FileDescriptor;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
@@ -50,6 +51,9 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
@@ -426,22 +430,22 @@
* and obtain the traces. Both methods must be invoked on the
* same thread.
*
- * @param traceFile The path where to write the looper traces
- *
- * @see #stopLooperProfiling()
+ * @hide
*/
- public static void startLooperProfiling(File traceFile) {
+ public static void startLooperProfiling(String path, FileDescriptor fileDescriptor) {
if (sLooperProfilerStorage.get() == null) {
- LooperProfiler profiler = new LooperProfiler(traceFile);
+ LooperProfiler profiler = new LooperProfiler(path, fileDescriptor);
sLooperProfilerStorage.set(profiler);
Looper.myLooper().setMessageLogging(profiler);
}
- }
+ }
/**
* Stops profiling the looper associated with the current thread.
*
- * @see #startLooperProfiling(java.io.File)
+ * @see #startLooperProfiling(String, java.io.FileDescriptor)
+ *
+ * @hide
*/
public static void stopLooperProfiling() {
LooperProfiler profiler = sLooperProfilerStorage.get();
@@ -453,21 +457,33 @@
}
private static class LooperProfiler implements Looper.Profiler, Printer {
- private static final int LOOPER_PROFILER_VERSION = 1;
-
private static final String LOG_TAG = "LooperProfiler";
+ private static final int TRACE_VERSION_NUMBER = 3;
+ private static final int ACTION_EXIT_METHOD = 0x1;
+ private static final int HEADER_SIZE = 32;
+ private static final String HEADER_MAGIC = "SLOW";
+ private static final short HEADER_RECORD_SIZE = (short) 14;
+
private final long mTraceWallStart;
private final long mTraceThreadStart;
private final ArrayList<Entry> mTraces = new ArrayList<Entry>(512);
- private final File mTraceFile;
- private final HashMap<String, Short> mTraceNames = new HashMap<String, Short>(32);
- private short mTraceId = 0;
+ private final HashMap<String, Integer> mTraceNames = new HashMap<String, Integer>(32);
+ private int mTraceId = 0;
- LooperProfiler(File traceFile) {
- mTraceFile = traceFile;
+ private final String mPath;
+ private ParcelFileDescriptor mFileDescriptor;
+
+ LooperProfiler(String path, FileDescriptor fileDescriptor) {
+ mPath = path;
+ try {
+ mFileDescriptor = ParcelFileDescriptor.dup(fileDescriptor);
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "Could not write trace file " + mPath, e);
+ throw new RuntimeException(e);
+ }
mTraceWallStart = SystemClock.currentTimeMicro();
mTraceThreadStart = SystemClock.currentThreadTimeMicro();
}
@@ -490,11 +506,11 @@
mTraces.add(entry);
}
- private short getTraceId(Message message) {
+ private int getTraceId(Message message) {
String name = message.getTarget().getMessageName(message);
- Short traceId = mTraceNames.get(name);
+ Integer traceId = mTraceNames.get(name);
if (traceId == null) {
- traceId = mTraceId++;
+ traceId = mTraceId++ << 4;
mTraceNames.put(name, traceId);
}
return traceId;
@@ -507,62 +523,135 @@
public void run() {
saveTraces();
}
- }, "LooperProfiler[" + mTraceFile + "]").start();
+ }, "LooperProfiler[" + mPath + "]").start();
}
private void saveTraces() {
- FileOutputStream fos;
- try {
- fos = new FileOutputStream(mTraceFile);
- } catch (FileNotFoundException e) {
- Log.e(LOG_TAG, "Could not open trace file: " + mTraceFile);
- return;
- }
-
+ FileOutputStream fos = new FileOutputStream(mFileDescriptor.getFileDescriptor());
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(fos));
try {
- out.writeInt(LOOPER_PROFILER_VERSION);
- out.writeLong(mTraceWallStart);
- out.writeLong(mTraceThreadStart);
+ writeHeader(out, mTraceWallStart, mTraceNames, mTraces);
+ out.flush();
- out.writeInt(mTraceNames.size());
- for (Map.Entry<String, Short> entry : mTraceNames.entrySet()) {
- saveTraceName(entry.getKey(), entry.getValue(), out);
- }
+ writeTraces(fos, out.size(), mTraceWallStart, mTraceThreadStart, mTraces);
- out.writeInt(mTraces.size());
- for (Entry entry : mTraces) {
- saveTrace(entry, out);
- }
-
- Log.d(LOG_TAG, "Looper traces ready: " + mTraceFile);
+ Log.d(LOG_TAG, "Looper traces ready: " + mPath);
} catch (IOException e) {
- Log.e(LOG_TAG, "Could not write trace file: ", e);
+ Log.e(LOG_TAG, "Could not write trace file " + mPath, e);
} finally {
try {
out.close();
} catch (IOException e) {
- // Ignore
+ Log.e(LOG_TAG, "Could not write trace file " + mPath, e);
+ }
+ try {
+ mFileDescriptor.close();
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "Could not write trace file " + mPath, e);
}
}
}
-
- private void saveTraceName(String name, short id, DataOutputStream out) throws IOException {
- out.writeShort(id);
- out.writeUTF(name);
+
+ private static void writeTraces(FileOutputStream out, long offset, long wallStart,
+ long threadStart, ArrayList<Entry> entries) throws IOException {
+
+ FileChannel channel = out.getChannel();
+
+ // Header
+ ByteBuffer buffer = ByteBuffer.allocateDirect(HEADER_SIZE);
+ buffer.put(HEADER_MAGIC.getBytes());
+ buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);
+ buffer.putShort((short) TRACE_VERSION_NUMBER); // version
+ buffer.putShort((short) HEADER_SIZE); // offset to data
+ buffer.putLong(wallStart); // start time in usec
+ buffer.putShort(HEADER_RECORD_SIZE); // size of a record in bytes
+ // padding to 32 bytes
+ for (int i = 0; i < HEADER_SIZE - 18; i++) {
+ buffer.put((byte) 0);
+ }
+
+ buffer.flip();
+ channel.position(offset).write(buffer);
+
+ buffer = ByteBuffer.allocateDirect(14).order(ByteOrder.LITTLE_ENDIAN);
+ for (Entry entry : entries) {
+ buffer.putShort((short) 1); // we simulate only one thread
+ buffer.putInt(entry.traceId); // entering method
+ buffer.putInt((int) (entry.threadStart - threadStart));
+ buffer.putInt((int) (entry.wallStart - wallStart));
+
+ buffer.flip();
+ channel.write(buffer);
+ buffer.clear();
+
+ buffer.putShort((short) 1);
+ buffer.putInt(entry.traceId | ACTION_EXIT_METHOD); // exiting method
+ buffer.putInt((int) (entry.threadStart + entry.threadTime - threadStart));
+ buffer.putInt((int) (entry.wallStart + entry.wallTime - wallStart));
+
+ buffer.flip();
+ channel.write(buffer);
+ buffer.clear();
+ }
+
+ channel.close();
}
+
+ private static void writeHeader(DataOutputStream out, long start,
+ HashMap<String, Integer> names, ArrayList<Entry> entries) throws IOException {
+
+ Entry last = entries.get(entries.size() - 1);
+ long wallTotal = (last.wallStart + last.wallTime) - start;
+
+ startSection("version", out);
+ addValue(null, Integer.toString(TRACE_VERSION_NUMBER), out);
+ addValue("data-file-overflow", "false", out);
+ addValue("clock", "dual", out);
+ addValue("elapsed-time-usec", Long.toString(wallTotal), out);
+ addValue("num-method-calls", Integer.toString(entries.size()), out);
+ addValue("clock-call-overhead-nsec", "1", out);
+ addValue("vm", "dalvik", out);
+
+ startSection("threads", out);
+ addThreadId(1, "main", out);
+
+ startSection("methods", out);
+ addMethods(names, out);
+
+ startSection("end", out);
+ }
+
+ private static void addMethods(HashMap<String, Integer> names, DataOutputStream out)
+ throws IOException {
+
+ for (Map.Entry<String, Integer> name : names.entrySet()) {
+ out.writeBytes(String.format("0x%08x\tEventQueue\t%s\t()V\tLooper\t-2\n",
+ name.getValue(), name.getKey()));
+ }
+ }
+
+ private static void addThreadId(int id, String name, DataOutputStream out)
+ throws IOException {
- private void saveTrace(Entry entry, DataOutputStream out) throws IOException {
- out.writeShort(entry.traceId);
- out.writeLong(entry.wallStart);
- out.writeLong(entry.wallTime);
- out.writeLong(entry.threadStart);
- out.writeLong(entry.threadTime);
+ out.writeBytes(Integer.toString(id) + '\t' + name + '\n');
+ }
+
+ private static void addValue(String name, String value, DataOutputStream out)
+ throws IOException {
+
+ if (name != null) {
+ out.writeBytes(name + "=");
+ }
+ out.writeBytes(value + '\n');
+ }
+
+ private static void startSection(String name, DataOutputStream out) throws IOException {
+ out.writeBytes("*" + name + '\n');
}
static class Entry {
- short traceId;
+ int traceId;
long wallStart;
long wallTime;
long threadStart;
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 54fee3c..8cf03a6 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -2148,9 +2148,12 @@
onPopulateAccessibilityEvent(event);
// Let our children have a shot in populating the event.
for (int i = 0, count = getChildCount(); i < count; i++) {
- boolean handled = getChildAt(i).dispatchPopulateAccessibilityEvent(event);
- if (handled) {
- return handled;
+ View child = getChildAt(i);
+ if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE) {
+ boolean handled = getChildAt(i).dispatchPopulateAccessibilityEvent(event);
+ if (handled) {
+ return handled;
+ }
}
}
return false;
@@ -2851,7 +2854,7 @@
// 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() && (child.mPrivateFlags & ALPHA_SET) == ALPHA_SET) {
// 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 @@
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 @@
}
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 @@
@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 @@
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 @@
}
/**
+ * 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 @@
}
/**
- * 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 @@
*/
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 @@
*/
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 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 @@
}
/**
+ * 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 @@
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 @@
}
/**
+ * @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 @@
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..ae253cf
--- /dev/null
+++ b/core/java/android/view/textservice/TextServicesManager.java
@@ -0,0 +1,131 @@
+/*
+ * 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.service.textservice.SpellCheckerSession;
+import android.service.textservice.SpellCheckerSession.SpellCheckerSessionListener;
+import android.util.Log;
+
+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 final boolean DBG = false;
+
+ 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 (listener == null) {
+ throw new NullPointerException();
+ }
+ // TODO: set a proper locale instead of the dummy locale
+ final String localeString = locale == null ? "en" : locale.toString();
+ final SpellCheckerInfo info;
+ try {
+ info = sService.getCurrentSpellChecker(localeString);
+ } catch (RemoteException e) {
+ return null;
+ }
+ if (info == null) {
+ return null;
+ }
+ final SpellCheckerSession session = new SpellCheckerSession(info, sService, listener);
+ try {
+ sService.getSpellCheckerService(info, localeString,
+ session.getTextServicesSessionListener(),
+ session.getSpellCheckerSessionListener());
+ } catch (RemoteException e) {
+ return null;
+ }
+ return session;
+ }
+
+ /**
+ * @hide
+ */
+ public SpellCheckerInfo[] getEnabledSpellCheckers() {
+ try {
+ final SpellCheckerInfo[] retval = sService.getEnabledSpellCheckers();
+ if (DBG) {
+ Log.d(TAG, "getEnabledSpellCheckers: " + (retval != null ? retval.length : "null"));
+ }
+ return retval;
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error in getEnabledSpellCheckers: " + 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 @@
import android.content.Context;
import android.net.Uri;
+import android.provider.Settings;
import android.util.Log;
import java.io.InputStream;
@@ -38,7 +39,7 @@
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 @@
* @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 @@
* @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 @@
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 b22c57b0..e24ab58 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -4701,6 +4701,7 @@
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 @@
mUpdateMessage = msg;
mAutoFillable = autoFillable;
mAutoComplete = autoComplete;
+ mWebSettings = getSettings();
}
public void run() {
@@ -4718,8 +4720,7 @@
// 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() +
" " +
@@ -6330,8 +6331,8 @@
if (action == MotionEvent.ACTION_POINTER_DOWN) {
cancelTouch();
action = MotionEvent.ACTION_DOWN;
- } else if (action == MotionEvent.ACTION_POINTER_UP && ev.getPointerCount() == 2) {
- // set mLastTouchX/Y to the remaining point
+ } else if (action == MotionEvent.ACTION_POINTER_UP && ev.getPointerCount() >= 2) {
+ // set mLastTouchX/Y to the remaining points for multi-touch.
mLastTouchX = Math.round(x);
mLastTouchY = Math.round(y);
} else if (action == MotionEvent.ACTION_MOVE) {
@@ -9119,20 +9120,12 @@
return nativeTileProfilingNumTilesInFrame(frame);
}
/** @hide only used by profiling tests */
- public int tileProfilingGetX(int frame, int tile) {
- return nativeTileProfilingGetX(frame, tile);
+ public int tileProfilingGetInt(int frame, int tile, String key) {
+ return nativeTileProfilingGetInt(frame, tile, key);
}
/** @hide only used by profiling tests */
- public int tileProfilingGetY(int frame, int tile) {
- return nativeTileProfilingGetY(frame, tile);
- }
- /** @hide only used by profiling tests */
- public boolean tileProfilingGetReady(int frame, int tile) {
- return nativeTileProfilingGetReady(frame, tile);
- }
- /** @hide only used by profiling tests */
- public int tileProfilingGetLevel(int frame, int tile) {
- return nativeTileProfilingGetLevel(frame, tile);
+ public float tileProfilingGetFloat(int frame, int tile, String key) {
+ return nativeTileProfilingGetFloat(frame, tile, key);
}
private native int nativeCacheHitFramePointer();
@@ -9262,10 +9255,8 @@
private native void nativeTileProfilingClear();
private native int nativeTileProfilingNumFrames();
private native int nativeTileProfilingNumTilesInFrame(int frame);
- private native int nativeTileProfilingGetX(int frame, int tile);
- private native int nativeTileProfilingGetY(int frame, int tile);
- private native boolean nativeTileProfilingGetReady(int frame, int tile);
- private native int nativeTileProfilingGetLevel(int frame, int tile);
+ private native int nativeTileProfilingGetInt(int frame, int tile, String key);
+ private native float nativeTileProfilingGetFloat(int frame, int tile, String key);
// Never call this version except by updateCachedTextfield(String) -
// we always want to pass in our generation number.
private native void nativeUpdateCachedTextfield(String updatedText,
diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java
index d7a2526..8d8023b 100644
--- a/core/java/android/webkit/WebViewCore.java
+++ b/core/java/android/webkit/WebViewCore.java
@@ -1069,6 +1069,15 @@
+ " arg1=" + msg.arg1 + " arg2=" + msg.arg2
+ " obj=" + msg.obj);
}
+ if (mWebView == null
+ && msg.what != EventHub.RESUME_TIMERS
+ && msg.what != EventHub.PAUSE_TIMERS) {
+ if (DebugFlags.WEB_VIEW_CORE) {
+ Log.v(LOGTAG, "Rejecting message " + msg.what
+ + " because we are destroyed");
+ }
+ return;
+ }
switch (msg.what) {
case WEBKIT_DRAW:
webkitDraw();
@@ -1757,30 +1766,17 @@
}
/**
- * Removes pending messages and trigger a DESTROY message to send to
- * WebCore.
+ * Sends a DESTROY message to WebCore.
* Called from UI thread.
*/
void destroy() {
- // We don't want anyone to post a message between removing pending
- // messages and sending the destroy message.
synchronized (mEventHub) {
- // RESUME_TIMERS and PAUSE_TIMERS are per process base. They need to
- // be preserved even the WebView is destroyed.
- // Note: we should not have more than one RESUME_TIMERS/PAUSE_TIMERS
- boolean hasResume = mEventHub.hasMessages(EventHub.RESUME_TIMERS);
- boolean hasPause = mEventHub.hasMessages(EventHub.PAUSE_TIMERS);
- mEventHub.removeMessages();
+ // Do not call removeMessages as then we risk removing PAUSE_TIMERS
+ // or RESUME_TIMERS messages, which we must still handle as they
+ // are per process. DESTROY will instead trigger a white list in
+ // mEventHub, skipping any remaining messages in the queue
mEventHub.sendMessageAtFrontOfQueue(
Message.obtain(null, EventHub.DESTROY));
- if (hasPause) {
- mEventHub.sendMessageAtFrontOfQueue(
- Message.obtain(null, EventHub.PAUSE_TIMERS));
- }
- if (hasResume) {
- mEventHub.sendMessageAtFrontOfQueue(
- Message.obtain(null, EventHub.RESUME_TIMERS));
- }
mEventHub.blockMessages();
}
}
@@ -2113,13 +2109,17 @@
// called from JNI or WebView thread
/* package */ void contentDraw() {
- // don't update the Picture until we have an initial width and finish
- // the first layout
- if (mCurrentViewWidth == 0 || !mBrowserFrame.firstLayoutDone()) {
- return;
- }
- // only fire an event if this is our first request
synchronized (this) {
+ if (mWebView == null || mBrowserFrame == null) {
+ // We were destroyed
+ return;
+ }
+ // don't update the Picture until we have an initial width and finish
+ // the first layout
+ if (mCurrentViewWidth == 0 || !mBrowserFrame.firstLayoutDone()) {
+ return;
+ }
+ // only fire an event if this is our first request
if (mDrawIsScheduled) return;
mDrawIsScheduled = true;
if (mDrawIsPaused) return;
diff --git a/core/java/android/webkit/ZoomManager.java b/core/java/android/webkit/ZoomManager.java
index 49ea944..70e48ad 100644
--- a/core/java/android/webkit/ZoomManager.java
+++ b/core/java/android/webkit/ZoomManager.java
@@ -794,6 +794,8 @@
mInitialZoomOverview = false;
dismissZoomPicker();
mFocusMovementQueue.clear();
+ mFocusX = detector.getFocusX();
+ mFocusY = detector.getFocusY();
mWebView.mViewManager.startZoom();
mWebView.onPinchToZoomAnimationStart();
mAccumulatedSpan = 0;
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index 8f8c1d0..b7c1687 100644
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -4638,9 +4638,6 @@
childrenTop += getVerticalFadingEdgeLength();
}
}
- // Don't ever focus a disabled item.
- if (!mAdapter.isEnabled(i)) continue;
-
if (top >= childrenTop) {
// Found a view whose top is fully visisble
selectedPos = firstPosition + i;
diff --git a/core/java/android/widget/ActivityChooserModel.java b/core/java/android/widget/ActivityChooserModel.java
index d7429b3..4b0a6da 100644
--- a/core/java/android/widget/ActivityChooserModel.java
+++ b/core/java/android/widget/ActivityChooserModel.java
@@ -317,6 +317,7 @@
dataModel = new ActivityChooserModel(context, historyFileName);
sDataModelRegistry.put(historyFileName, dataModel);
}
+ dataModel.readHistoricalData();
return dataModel;
}
}
@@ -505,7 +506,7 @@
* data is read until this method is invoked.
* <p>
*/
- public void readHistoricalData() {
+ private void readHistoricalData() {
synchronized (mInstanceLock) {
if (!mCanReadHistoricalData || !mHistoricalRecordsChanged) {
return;
@@ -527,7 +528,7 @@
* @throws IllegalStateException If this method is called before a call to
* {@link #readHistoricalData()}.
*/
- public void persistHistoricalData() {
+ private void persistHistoricalData() {
synchronized (mInstanceLock) {
if (!mReadShareHistoryCalled) {
throw new IllegalStateException("No preceding call to #readHistoricalData");
@@ -629,6 +630,7 @@
if (added) {
mHistoricalRecordsChanged = true;
pruneExcessiveHistoricalRecordsLocked();
+ persistHistoricalData();
sortActivities();
}
return added;
diff --git a/core/java/android/widget/ActivityChooserView.java b/core/java/android/widget/ActivityChooserView.java
index 5b69aa8..d85f8a4 100644
--- a/core/java/android/widget/ActivityChooserView.java
+++ b/core/java/android/widget/ActivityChooserView.java
@@ -307,7 +307,6 @@
ActivityChooserModel dataModel = mAdapter.getDataModel();
if (dataModel != null) {
dataModel.registerObserver(mModelDataSetOberver);
- dataModel.readHistoricalData();
}
mIsAttachedToWindow = true;
}
@@ -318,7 +317,6 @@
ActivityChooserModel dataModel = mAdapter.getDataModel();
if (dataModel != null) {
dataModel.unregisterObserver(mModelDataSetOberver);
- dataModel.persistHistoricalData();
}
mIsAttachedToWindow = false;
}
diff --git a/core/java/android/widget/AdapterView.java b/core/java/android/widget/AdapterView.java
index 755d4e0..00c75a9 100644
--- a/core/java/android/widget/AdapterView.java
+++ b/core/java/android/widget/AdapterView.java
@@ -902,15 +902,16 @@
@Override
public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
- // Add a record for ourselves as well.
- AccessibilityEvent record = AccessibilityEvent.obtain();
- record.setSource(this);
- // Set the class since it is not populated in #dispatchPopulateAccessibilityEvent
- record.setClassName(getClass().getName());
- child.onInitializeAccessibilityEvent(record);
- child.dispatchPopulateAccessibilityEvent(record);
- event.appendRecord(record);
- return true;
+ if (super.onRequestSendAccessibilityEvent(child, event)) {
+ // Add a record for ourselves as well.
+ AccessibilityEvent record = AccessibilityEvent.obtain();
+ onInitializeAccessibilityEvent(record);
+ // Populate with the text of the requesting child.
+ child.dispatchPopulateAccessibilityEvent(record);
+ event.appendRecord(record);
+ return true;
+ }
+ return false;
}
@Override
diff --git a/core/java/android/widget/AdapterViewFlipper.java b/core/java/android/widget/AdapterViewFlipper.java
index 273c258..4419886 100644
--- a/core/java/android/widget/AdapterViewFlipper.java
+++ b/core/java/android/widget/AdapterViewFlipper.java
@@ -62,15 +62,14 @@
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
- com.android.internal.R.styleable.ViewFlipper);
+ com.android.internal.R.styleable.AdapterViewFlipper);
mFlipInterval = a.getInt(
- com.android.internal.R.styleable.ViewFlipper_flipInterval, DEFAULT_INTERVAL);
+ com.android.internal.R.styleable.AdapterViewFlipper_flipInterval, DEFAULT_INTERVAL);
mAutoStart = a.getBoolean(
- com.android.internal.R.styleable.ViewFlipper_autoStart, false);
+ com.android.internal.R.styleable.AdapterViewFlipper_autoStart, false);
- // By default we want the flipper to loop
- mLoopViews = a.getBoolean(
- com.android.internal.R.styleable.AdapterViewAnimator_loopViews, true);
+ // A view flipper should cycle through the views
+ mLoopViews = true;
a.recycle();
}
diff --git a/core/java/android/widget/CheckedTextView.java b/core/java/android/widget/CheckedTextView.java
index 49616cc..f3a6da7 100644
--- a/core/java/android/widget/CheckedTextView.java
+++ b/core/java/android/widget/CheckedTextView.java
@@ -39,8 +39,9 @@
private boolean mChecked;
private int mCheckMarkResource;
private Drawable mCheckMarkDrawable;
- private int mBasePaddingRight;
+ private int mBasePadding;
private int mCheckMarkWidth;
+ private boolean mNeedRequestlayout;
private static final int[] CHECKED_STATE_SET = {
R.attr.state_checked
@@ -123,6 +124,7 @@
mCheckMarkDrawable.setCallback(null);
unscheduleDrawable(mCheckMarkDrawable);
}
+ mNeedRequestlayout = (d != mCheckMarkDrawable);
if (d != null) {
d.setCallback(this);
d.setVisible(getVisibility() == VISIBLE, false);
@@ -130,19 +132,35 @@
setMinHeight(d.getIntrinsicHeight());
mCheckMarkWidth = d.getIntrinsicWidth();
- mUserPaddingRight = mCheckMarkWidth + mBasePaddingRight;
d.setState(getDrawableState());
} else {
- mUserPaddingRight = mBasePaddingRight;
+ mCheckMarkWidth = 0;
}
mCheckMarkDrawable = d;
- requestLayout();
+ // Do padding resolution. This will call setPadding() and do a requestLayout() if needed.
+ resolvePadding();
+ }
+
+ /**
+ * @hide
+ */
+ @Override
+ protected void resolvePadding() {
+ super.resolvePadding();
+ int newPadding = (mCheckMarkDrawable != null) ?
+ mCheckMarkWidth + mBasePadding : mBasePadding;
+ mNeedRequestlayout |= (mPaddingRight != newPadding);
+ mPaddingRight = newPadding;
+ if (mNeedRequestlayout) {
+ requestLayout();
+ mNeedRequestlayout = false;
+ }
}
@Override
public void setPadding(int left, int top, int right, int bottom) {
super.setPadding(left, top, right, bottom);
- mBasePaddingRight = mUserPaddingRight;
+ mBasePadding = mPaddingRight;
}
@Override
@@ -167,9 +185,9 @@
int right = getWidth();
checkMarkDrawable.setBounds(
- right - mUserPaddingRight,
+ right - mPaddingRight,
y,
- right - mUserPaddingRight + mCheckMarkWidth,
+ right - mPaddingRight + mCheckMarkWidth,
y + height);
checkMarkDrawable.draw(canvas);
}
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index 3bd7fab..f999960 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -21,7 +21,6 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
-import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
@@ -38,6 +37,7 @@
import java.util.List;
import java.util.Map;
+import static android.view.Gravity.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
@@ -167,7 +167,7 @@
// Misc constants
private static final String TAG = GridLayout.class.getName();
- static boolean DEBUG = false;
+ private static boolean DEBUG = false;
private static final int PRF = 1;
// Defaults
@@ -198,7 +198,8 @@
private int mOrientation = DEFAULT_ORIENTATION;
private boolean mUseDefaultMargins = DEFAULT_USE_DEFAULT_MARGINS;
private int mAlignmentMode = DEFAULT_ALIGNMENT_MODE;
- private int mDefaultGravity = Gravity.NO_GRAVITY;
+ private Alignment mColumnAlignment = LEFT;
+ private Alignment mRowAlignment = BASELINE;
private int mDefaultGap;
// Constructors
@@ -216,9 +217,9 @@
try {
setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT));
setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT));
- mOrientation = a.getInt(ORIENTATION, DEFAULT_ORIENTATION);
- mUseDefaultMargins = a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS);
- mAlignmentMode = a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE);
+ setOrientation(a.getInt(ORIENTATION, DEFAULT_ORIENTATION));
+ setUseDefaultMargins(a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS));
+ setAlignmentMode(a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE));
setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED));
} finally {
@@ -514,6 +515,8 @@
requestLayout();
}
+ // Static utility methods
+
private static int max2(int[] a, int valueIfEmpty) {
int result = valueIfEmpty;
for (int i = 0, N = a.length; i < N; i++) {
@@ -537,6 +540,24 @@
return result;
}
+ private static Alignment getAlignment(int gravity, boolean horizontal) {
+ int mask = horizontal ? HORIZONTAL_GRAVITY_MASK : VERTICAL_GRAVITY_MASK;
+ int shift = horizontal ? AXIS_X_SHIFT : AXIS_Y_SHIFT;
+ int flags = (gravity & mask) >> shift;
+ switch (flags) {
+ case (AXIS_SPECIFIED | AXIS_PULL_BEFORE):
+ return LEADING;
+ case (AXIS_SPECIFIED | AXIS_PULL_AFTER):
+ return TRAILING;
+ case (AXIS_SPECIFIED | AXIS_PULL_BEFORE | AXIS_PULL_AFTER):
+ return FILL;
+ case AXIS_SPECIFIED:
+ return CENTER;
+ default:
+ return UNDEFINED_ALIGNMENT;
+ }
+ }
+
private int getDefaultMargin(View c, boolean horizontal, boolean leading) {
return mDefaultGap / 2;
}
@@ -678,7 +699,7 @@
@Override
public LayoutParams generateLayoutParams(AttributeSet attrs) {
- return new LayoutParams(getContext(), attrs, mDefaultGravity);
+ return new LayoutParams(getContext(), attrs);
}
@Override
@@ -833,6 +854,9 @@
}
private int getMeasurementIncludingMargin(View c, boolean horizontal) {
+ if (isGone(c)) {
+ return 0;
+ }
int result = getMeasurement(c, horizontal);
if (mAlignmentMode == ALIGN_MARGINS) {
return result + getTotalMargin(c, horizontal);
@@ -846,6 +870,11 @@
invalidateValues();
}
+ private Alignment getAlignment(Alignment alignment, boolean horizontal) {
+ return (alignment != UNDEFINED_ALIGNMENT) ? alignment :
+ (horizontal ? mColumnAlignment : mRowAlignment);
+ }
+
// Layout container
/**
@@ -895,8 +924,8 @@
int pWidth = getMeasurement(c, true);
int pHeight = getMeasurement(c, false);
- Alignment hAlign = columnSpec.alignment;
- Alignment vAlign = rowSpec.alignment;
+ Alignment hAlign = getAlignment(columnSpec.alignment, true);
+ Alignment vAlign = getAlignment(rowSpec.alignment, false);
int dx, dy;
@@ -1035,14 +1064,10 @@
Assoc<Spec, Bounds> assoc = Assoc.of(Spec.class, Bounds.class);
for (int i = 0, N = getChildCount(); i < N; i++) {
View c = getChildAt(i);
- if (isGone(c)) {
- assoc.put(Spec.GONE, Bounds.GONE);
- } else {
- LayoutParams lp = getLayoutParams(c);
- Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
- Bounds bounds = spec.alignment.getBounds();
- assoc.put(spec, bounds);
- }
+ LayoutParams lp = getLayoutParams(c);
+ Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
+ Bounds bounds = getAlignment(spec.alignment, horizontal).getBounds();
+ assoc.put(spec, bounds);
}
return assoc.pack();
}
@@ -1054,7 +1079,6 @@
}
for (int i = 0, N = getChildCount(); i < N; i++) {
View c = getChildAt(i);
- if (isGone(c)) continue;
LayoutParams lp = getLayoutParams(c);
Spec spec = horizontal ? lp.columnSpec : lp.rowSpec;
groupBounds.getValue(i).include(c, spec, GridLayout.this, this);
@@ -1094,11 +1118,8 @@
for (int i = 0; i < bounds.length; i++) {
int size = bounds[i].size(min);
MutableInt valueHolder = links.getValue(i);
- if (min) {
- valueHolder.value = max(valueHolder.value, size);
- } else {
- valueHolder.value = -max(-valueHolder.value, size);
- }
+ // this effectively takes the max() of the minima and the min() of the maxima
+ valueHolder.value = max(valueHolder.value, min ? size : -size);
}
}
@@ -1397,7 +1418,7 @@
}
if (!changed) {
if (DEBUG) {
- Log.d(TAG, axis + " iteration completed in " + (1 + i) + " steps of " + N);
+ Log.v(TAG, axis + " iteration completed in " + (1 + i) + " steps of " + N);
}
return;
}
@@ -1654,14 +1675,6 @@
private static final int DEFAULT_COLUMN = UNDEFINED;
private static final Interval DEFAULT_SPAN = new Interval(UNDEFINED, UNDEFINED + 1);
private static final int DEFAULT_SPAN_SIZE = DEFAULT_SPAN.size();
- private static final Alignment DEFAULT_COLUMN_ALIGNMENT = LEFT;
- private static final Alignment DEFAULT_ROW_ALIGNMENT = BASELINE;
-
- // Misc
-
- private static final Rect CONTAINER_BOUNDS = new Rect(0, 0, 2, 2);
- private static final Alignment[] COLUMN_ALIGNMENTS = { LEFT, CENTER, RIGHT };
- private static final Alignment[] ROW_ALIGNMENTS = { TOP, CENTER, BOTTOM };
// TypedArray indices
@@ -1728,8 +1741,7 @@
* Constructs a new LayoutParams with default values as defined in {@link LayoutParams}.
*/
public LayoutParams() {
- this(new Spec(DEFAULT_SPAN, DEFAULT_ROW_ALIGNMENT, Spec.DEFAULT_FLEXIBILITY),
- new Spec(DEFAULT_SPAN, DEFAULT_COLUMN_ALIGNMENT, Spec.DEFAULT_FLEXIBILITY));
+ this(spec(UNDEFINED), spec(UNDEFINED));
}
// Copying constructors
@@ -1753,18 +1765,12 @@
*/
public LayoutParams(LayoutParams that) {
super(that);
- this.columnSpec = new Spec(that.columnSpec);
this.rowSpec = new Spec(that.rowSpec);
+ this.columnSpec = new Spec(that.columnSpec);
}
// AttributeSet constructors
- private LayoutParams(Context context, AttributeSet attrs, int defaultGravity) {
- super(context, attrs);
- reInitSuper(context, attrs);
- init(context, attrs, defaultGravity);
- }
-
/**
* {@inheritDoc}
*
@@ -1772,27 +1778,13 @@
* defined in {@link LayoutParams}.
*/
public LayoutParams(Context context, AttributeSet attrs) {
- this(context, attrs, Gravity.NO_GRAVITY);
+ super(context, attrs);
+ reInitSuper(context, attrs);
+ init(context, attrs);
}
// Implementation
- private static boolean definesVertical(int gravity) {
- return gravity > 0 && (gravity & Gravity.VERTICAL_GRAVITY_MASK) != 0;
- }
-
- private static boolean definesHorizontal(int gravity) {
- return gravity > 0 && (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) != 0;
- }
-
- private static <T> T getAlignment(T[] alignments, T fill, int min, int max,
- boolean isUndefined, T defaultValue) {
- if (isUndefined) {
- return defaultValue;
- }
- return min != max ? fill : alignments[min];
- }
-
// Reinitialise the margins using a different default policy than MarginLayoutParams.
// Here we use the value UNDEFINED (as distinct from zero) to represent the undefined state
// so that a layout manager default can be accessed post set up. We need this as, at the
@@ -1817,44 +1809,20 @@
}
}
- // Gravity. For conversion from the static the integers defined in the Gravity class,
- // use Gravity.apply() to apply gravity to a view of zero size and see where it ends up.
- private static Alignment getColAlignment(int gravity, int width) {
- Rect r = new Rect(0, 0, 0, 0);
- Gravity.apply(gravity, 0, 0, CONTAINER_BOUNDS, r);
-
- boolean fill = (width == MATCH_PARENT);
- Alignment defaultAlignment = fill ? FILL : DEFAULT_COLUMN_ALIGNMENT;
- return getAlignment(COLUMN_ALIGNMENTS, FILL, r.left, r.right,
- !definesHorizontal(gravity), defaultAlignment);
- }
-
- private static Alignment getRowAlignment(int gravity, int height) {
- Rect r = new Rect(0, 0, 0, 0);
- Gravity.apply(gravity, 0, 0, CONTAINER_BOUNDS, r);
-
- boolean fill = (height == MATCH_PARENT);
- Alignment defaultAlignment = fill ? FILL : DEFAULT_ROW_ALIGNMENT;
- return getAlignment(ROW_ALIGNMENTS, FILL, r.top, r.bottom,
- !definesVertical(gravity), defaultAlignment);
- }
-
- private void init(Context context, AttributeSet attrs, int defaultGravity) {
+ private void init(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridLayout_Layout);
try {
- int gravity = a.getInt(GRAVITY, defaultGravity);
+ int gravity = a.getInt(GRAVITY, Gravity.NO_GRAVITY);
int column = a.getInt(COLUMN, DEFAULT_COLUMN);
- int columnSpan = a.getInt(COLUMN_SPAN, DEFAULT_SPAN_SIZE);
- Interval hSpan = new Interval(column, column + columnSpan);
- int hFlexibility = a.getInt(COLUMN_FLEXIBILITY, Spec.DEFAULT_FLEXIBILITY);
- this.columnSpec = new Spec(hSpan, getColAlignment(gravity, width), hFlexibility);
+ int colSpan = a.getInt(COLUMN_SPAN, DEFAULT_SPAN_SIZE);
+ int hFlexibility = a.getInt(COLUMN_FLEXIBILITY, Spec.UNDEFINED_FLEXIBILITY);
+ this.columnSpec = spec(column, colSpan, getAlignment(gravity, true), hFlexibility);
int row = a.getInt(ROW, DEFAULT_ROW);
int rowSpan = a.getInt(ROW_SPAN, DEFAULT_SPAN_SIZE);
- Interval vSpan = new Interval(row, row + rowSpan);
- int vFlexibility = a.getInt(ROW_FLEXIBILITY, Spec.DEFAULT_FLEXIBILITY);
- this.rowSpec = new Spec(vSpan, getRowAlignment(gravity, height), vFlexibility);
+ int vFlexibility = a.getInt(ROW_FLEXIBILITY, Spec.UNDEFINED_FLEXIBILITY);
+ this.rowSpec = spec(row, rowSpan, getAlignment(gravity, false), vFlexibility);
} finally {
a.recycle();
}
@@ -1869,8 +1837,8 @@
* @attr ref android.R.styleable#GridLayout_Layout_layout_gravity
*/
public void setGravity(int gravity) {
- columnSpec = columnSpec.copyWriteAlignment(getColAlignment(gravity, width));
- rowSpec = rowSpec.copyWriteAlignment(getRowAlignment(gravity, height));
+ rowSpec = rowSpec.copyWriteAlignment(getAlignment(gravity, false));
+ columnSpec = columnSpec.copyWriteAlignment(getAlignment(gravity, true));
}
@Override
@@ -2045,7 +2013,7 @@
public int before;
public int after;
- public int flexibility;
+ public int flexibility; // we're flexible iff all included specs are flexible
private Bounds() {
reset();
@@ -2054,7 +2022,7 @@
protected void reset() {
before = Integer.MIN_VALUE;
after = Integer.MIN_VALUE;
- flexibility = UNDEFINED_FLEXIBILITY;
+ flexibility = CAN_STRETCH; // from the above, we're flexible when empty
}
protected void include(int before, int after) {
@@ -2064,10 +2032,7 @@
protected int size(boolean min) {
if (!min) {
- // Note in the usual case, components don't define anything
- // leaving their flexibility is undefined and their stretchability
- // defined as if the CAN_STRETCH flag was false.
- if (canStretch(flexibility) && !isUndefined(flexibility)) {
+ if (canStretch(flexibility)) {
return MAX_SIZE;
}
}
@@ -2078,11 +2043,12 @@
return before - alignment.getAlignmentValue(c, size);
}
- protected void include(View c, Spec spec, GridLayout gridLayout, Axis axis) {
- this.flexibility &= spec.flexibility;
+ protected final void include(View c, Spec spec, GridLayout gridLayout, Axis axis) {
+ this.flexibility &= spec.getFlexibility();
int size = gridLayout.getMeasurementIncludingMargin(c, axis.horizontal);
// todo test this works correctly when the returned value is UNDEFINED
- int before = spec.alignment.getAlignmentValue(c, size);
+ Alignment alignment = gridLayout.getAlignment(spec.alignment, axis.horizontal);
+ int before = alignment.getAlignmentValue(c, size);
include(before, size - before);
}
@@ -2107,8 +2073,6 @@
* {@code x} such that {@code min <= x < max}.
*/
static class Interval {
- private static final Interval GONE = new Interval(UNDEFINED, UNDEFINED);
-
/**
* The minimum value.
*/
@@ -2186,40 +2150,38 @@
}
}
- /**
- * A spec defines either the horizontal or vertical characteristics of a group of
- * cells.
- */
+ /**
+ * A Spec defines the horizontal or vertical characteristics of a group of
+ * cells. Each spec. defines the <em>grid indices</em>, <em>alignment</em> and
+ * <em>flexibility</em> along the appropriate axis.
+ * <p>
+ * The <em>grid indices</em> are the leading and trailing edges of this cell group.
+ * See {@link GridLayout} for a description of the conventions used by GridLayout
+ * for grid indices.
+ * <p>
+ * The <em>alignment</em> property specifies how cells should be aligned in this group.
+ * For row groups, this specifies the vertical alignment.
+ * For column groups, this specifies the horizontal alignment.
+ */
public static class Spec {
- private static final int DEFAULT_FLEXIBILITY = UNDEFINED_FLEXIBILITY;
+ private static final int UNDEFINED_FLEXIBILITY = UNDEFINED;
- private static final Spec GONE = new Spec(Interval.GONE, Alignment.GONE);
-
- /**
- * The grid indices of the leading and trailing edges of this cell group for the
- * appropriate axis.
- * <p>
- * See {@link GridLayout} for a description of the conventions used by GridLayout
- * for grid indices.
- */
final Interval span;
- /**
- * Specifies how cells should be aligned in this group.
- * For row groups, this specifies the vertical alignment.
- * For column groups, this specifies the horizontal alignment.
- */
+
final Alignment alignment;
- /**
- * The flexibility field tells GridLayout how to derive minimum and maximum size
- * values for a component. Specifications are made with respect to a child's
- * 'measured size'. A child's measured size is, in turn, controlled by its
- * height and width layout parameters which either specify a size or, in
- * the case of {@link LayoutParams#WRAP_CONTENT WRAP_CONTENT}, defer to
- * the computed size of the component.
- *
- * @see GridLayout#CAN_STRETCH
- */
+ /**
+ * The <em>flexibility</em> property tells GridLayout how to derive minimum and maximum size
+ * values for a component. Specifications are made with respect to a child's
+ * 'measured size'. A child's measured size is, in turn, controlled by its
+ * height and width layout parameters which either specify a size or, in
+ * the case of {@link LayoutParams#WRAP_CONTENT WRAP_CONTENT}, defer to
+ * the computed size of the component.
+ * <p>
+ * A cell group is flexible only if <em>all</em> of its components are flexible.
+ * <p>
+ * By default, flexibility is {@link #INFLEXIBLE} only when alignment/gravity is undefined.
+ */
final int flexibility;
private Spec(Interval span, Alignment alignment, int flexibility) {
@@ -2229,7 +2191,7 @@
}
private Spec(Interval span, Alignment alignment) {
- this(span, alignment, DEFAULT_FLEXIBILITY);
+ this(span, alignment, UNDEFINED_FLEXIBILITY);
}
/* Copying constructor */
@@ -2249,8 +2211,14 @@
return new Spec(span, alignment, flexibility);
}
- private Spec copyWriteFlexibility(int flexibility) {
- return new Spec(span, alignment, flexibility);
+ private static int defaultFlexibility(Alignment alignment) {
+ return (alignment == UNDEFINED_ALIGNMENT) ? INFLEXIBLE : CAN_STRETCH;
+ }
+
+ int getFlexibility() {
+ return (flexibility != UNDEFINED_FLEXIBILITY) ?
+ flexibility :
+ defaultFlexibility(alignment);
}
/**
@@ -2293,34 +2261,23 @@
}
/**
- * Return a Spec, {@code spec}, where:
- * <ul>
- * <li> {@code spec.span = [start, start + size]} </li>
- * <li> {@code spec.alignment = alignment} </li>
- * <li> {@code spec.flexibility = flexibility} </li>
- * </ul>
+ * @deprecated Please use {@link #spec(int, int, Alignment)} instead,
+ * all spec's that define alignments (gravity) are assumed to be able to stretch.
*
- * @param start the start
- * @param size the size
- * @param alignment the alignment
- * @param flexibility the flexibility
+ * @hide
*/
+ @Deprecated
public static Spec spec(int start, int size, Alignment alignment, int flexibility) {
return new Spec(start, size, alignment, flexibility);
}
/**
- * Return a Spec, {@code spec}, where:
- * <ul>
- * <li> {@code spec.span = [start, start + 1]} </li>
- * <li> {@code spec.alignment = alignment} </li>
- * <li> {@code spec.flexibility = flexibility} </li>
- * </ul>
+ * @deprecated Please use {@link #spec(int, Alignment)} instead,
+ * all spec's that define alignments (gravity) are assumed to be able to stretch.
*
- * @param start the start
- * @param alignment the alignment
- * @param flexibility the flexibility
+ * @hide
*/
+ @Deprecated
public static Spec spec(int start, Alignment alignment, int flexibility) {
return spec(start, 1, alignment, flexibility);
}
@@ -2337,7 +2294,7 @@
* @param alignment the alignment
*/
public static Spec spec(int start, int size, Alignment alignment) {
- return spec(start, size, alignment, Spec.DEFAULT_FLEXIBILITY);
+ return spec(start, size, alignment, Spec.UNDEFINED_FLEXIBILITY);
}
/**
@@ -2355,6 +2312,31 @@
}
/**
+ * Return a Spec, {@code spec}, where:
+ * <ul>
+ * <li> {@code spec.span = [start, start + size]} </li>
+ * </ul>
+ *
+ * @param start the start
+ * @param size the size
+ */
+ public static Spec spec(int start, int size) {
+ return spec(start, size, UNDEFINED_ALIGNMENT);
+ }
+
+ /**
+ * Return a Spec, {@code spec}, where:
+ * <ul>
+ * <li> {@code spec.span = [start, start + 1]} </li>
+ * </ul>
+ *
+ * @param start the start index
+ */
+ public static Spec spec(int start) {
+ return spec(start, 1);
+ }
+
+ /**
* Alignments specify where a view should be placed within a cell group and
* what size it should be.
* <p>
@@ -2376,13 +2358,6 @@
* <p>
*/
public static abstract class Alignment {
- private static final Alignment GONE = new Alignment() {
- public int getAlignmentValue(View view, int viewSize) {
- assert false;
- return 0;
- }
- };
-
Alignment() {
}
@@ -2422,11 +2397,16 @@
}
}
+ private static final Alignment UNDEFINED_ALIGNMENT = new Alignment() {
+ public int getAlignmentValue(View view, int viewSize) {
+ return UNDEFINED;
+ }
+ };
+
private static final Alignment LEADING = new Alignment() {
public int getAlignmentValue(View view, int viewSize) {
return 0;
}
-
};
private static final Alignment TRAILING = new Alignment() {
@@ -2542,38 +2522,17 @@
return (flexibility & CAN_STRETCH) != 0;
}
- private static boolean isUndefined(int flexibility) {
- return (flexibility & UNDEFINED) != 0;
- }
-
- /**
- * Indicates that a view requests precisely the size specified by its layout parameters.
- *
- * @see Spec#flexibility
- */
- private static final int NONE = 0;
-
- /**
- * Indicates that a view's size should lie between its minimum and the size specified by
- * its layout parameters.
- *
- * @see Spec#flexibility
- */
- private static final int CAN_SHRINK = 1;
+ private static final int INFLEXIBLE = 0;
/**
* Indicates that a view's size should be greater than or equal to the size specified by
* its layout parameters.
*
- * @see Spec#flexibility
- */
- public static final int CAN_STRETCH = 2;
-
- /**
- * A default value for flexibility.
+ * @deprecated Please use {@link #spec(int, int, Alignment)} instead,
+ * all spec's that define alignment (gravity) are assumed to able to stretch.
*
- * @see Spec#flexibility
+ * @hide
*/
- private static final int UNDEFINED_FLEXIBILITY = UNDEFINED | CAN_SHRINK | CAN_STRETCH;
-
+ @Deprecated
+ public static final int CAN_STRETCH = 2;
}
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index 161b404..299e1ff 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -30,14 +30,15 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.RemotableViewMethod;
import android.view.View;
import android.view.ViewDebug;
+import android.view.accessibility.AccessibilityEvent;
import android.widget.RemoteViews.RemoteView;
-
/**
* Displays an arbitrary image, such as an icon. The ImageView class
* can load images from various sources (such as resources or content
@@ -208,7 +209,15 @@
}
return false;
}
-
+
+ @Override
+ public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
+ CharSequence contentDescription = getContentDescription();
+ if (!TextUtils.isEmpty(contentDescription)) {
+ event.getText().add(contentDescription);
+ }
+ }
+
/**
* Set this to true if you want the ImageView to adjust its bounds
* to preserve the aspect ratio of its drawable.
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 @@
private boolean mLayoutInScreen;
private boolean mClipToScreen;
private boolean mAllowScrollingAnchorParent = true;
+ private boolean mLayoutInsetDecor = false;
private OnTouchListener mTouchInterceptor;
@@ -658,6 +659,22 @@
}
/**
+ * 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 @@
if (mContext != null) {
p.packageName = mContext.getPackageName();
}
+ mPopupView.setFitsSystemWindows(mLayoutInsetDecor);
mWindowManager.addView(mPopupView, p);
}
@@ -1012,6 +1030,9 @@
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.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 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 @@
private int mMaxWidth;
private boolean mVoiceButtonEnabled;
private CharSequence mUserQuery;
+ private boolean mExpandedInActionView;
private SearchableInfo mSearchable;
private Bundle mAppSearchData;
@@ -623,7 +637,7 @@
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 @@
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.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
+import android.view.accessibility.AccessibilityEvent;
import com.android.internal.R;
@@ -360,6 +361,13 @@
}
}
+ @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/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 108ac33..a7324b0 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -329,7 +329,7 @@
private int mTextEditPasteWindowLayout, mTextEditSidePasteWindowLayout;
private int mTextEditNoPasteWindowLayout, mTextEditSideNoPasteWindowLayout;
- private int mTextEditSuggestionsBottomWindowLayout, mTextEditSuggestionsTopWindowLayout;
+ private int mTextEditSuggestionsWindowLayout;
private int mTextEditSuggestionItemLayout;
private SuggestionsPopupWindow mSuggestionsPopupWindow;
private SuggestionRangeSpan mSuggestionRangeSpan;
@@ -830,12 +830,8 @@
mTextEditSideNoPasteWindowLayout = a.getResourceId(attr, 0);
break;
- case com.android.internal.R.styleable.TextView_textEditSuggestionsBottomWindowLayout:
- mTextEditSuggestionsBottomWindowLayout = a.getResourceId(attr, 0);
- break;
-
- case com.android.internal.R.styleable.TextView_textEditSuggestionsTopWindowLayout:
- mTextEditSuggestionsTopWindowLayout = a.getResourceId(attr, 0);
+ case com.android.internal.R.styleable.TextView_textEditSuggestionsWindowLayout:
+ mTextEditSuggestionsWindowLayout = a.getResourceId(attr, 0);
break;
case com.android.internal.R.styleable.TextView_textEditSuggestionItemLayout:
@@ -8785,9 +8781,7 @@
private static final int MAX_NUMBER_SUGGESTIONS = 5;
private static final int NO_SUGGESTIONS = -1;
private final PopupWindow mContainer;
- private final ViewGroup[] mSuggestionViews = new ViewGroup[2];
- private final int[] mSuggestionViewLayouts = new int[] {
- mTextEditSuggestionsBottomWindowLayout, mTextEditSuggestionsTopWindowLayout};
+ private ViewGroup mSuggestionViewGroup;
private WordIterator mSuggestionWordIterator;
private TextAppearanceSpan[] mHighlightSpans = new TextAppearanceSpan[0];
@@ -8809,12 +8803,8 @@
int suggestionIndex; // the index of the suggestion inside suggestionSpan
}
- private ViewGroup getViewGroup(boolean under) {
- final int viewIndex = under ? 0 : 1;
- ViewGroup viewGroup = mSuggestionViews[viewIndex];
-
- if (viewGroup == null) {
- final int layout = mSuggestionViewLayouts[viewIndex];
+ private void initSuggestionViewGroup() {
+ if (mSuggestionViewGroup == null) {
LayoutInflater inflater = (LayoutInflater) TextView.this.mContext.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -8823,19 +8813,19 @@
"Unable to create TextEdit suggestion window inflater");
}
- View view = inflater.inflate(layout, null);
+ View view = inflater.inflate(mTextEditSuggestionsWindowLayout, null);
if (! (view instanceof ViewGroup)) {
throw new IllegalArgumentException(
"Inflated TextEdit suggestion window is not a ViewGroup: " + view);
}
- viewGroup = (ViewGroup) view;
+ mSuggestionViewGroup = (ViewGroup) view;
// Inflate the suggestion items once and for all.
for (int i = 0; i < MAX_NUMBER_SUGGESTIONS; i++) {
- View childView = inflater.inflate(mTextEditSuggestionItemLayout, viewGroup,
- false);
+ View childView = inflater.inflate(mTextEditSuggestionItemLayout,
+ mSuggestionViewGroup, false);
if (! (childView instanceof TextView)) {
throw new IllegalArgumentException(
@@ -8843,14 +8833,12 @@
}
childView.setTag(new SuggestionInfo());
- viewGroup.addView(childView);
+ mSuggestionViewGroup.addView(childView);
childView.setOnClickListener(this);
}
- mSuggestionViews[viewIndex] = viewGroup;
+ mContainer.setContentView(mSuggestionViewGroup);
}
-
- return viewGroup;
}
public void show() {
@@ -8861,8 +8849,7 @@
SuggestionSpan[] suggestionSpans = spannable.getSpans(pos, pos, SuggestionSpan.class);
final int nbSpans = suggestionSpans.length;
- ViewGroup viewGroup = getViewGroup(true);
- mContainer.setContentView(viewGroup);
+ initSuggestionViewGroup();
int totalNbSuggestions = 0;
int spanUnionStart = mText.length();
@@ -8878,7 +8865,8 @@
String[] suggestions = suggestionSpan.getSuggestions();
int nbSuggestions = suggestions.length;
for (int suggestionIndex = 0; suggestionIndex < nbSuggestions; suggestionIndex++) {
- TextView textView = (TextView) viewGroup.getChildAt(totalNbSuggestions);
+ TextView textView = (TextView) mSuggestionViewGroup.getChildAt(
+ totalNbSuggestions);
textView.setText(suggestions[suggestionIndex]);
SuggestionInfo suggestionInfo = (SuggestionInfo) textView.getTag();
suggestionInfo.spanStart = spanStart;
@@ -8897,7 +8885,7 @@
if (totalNbSuggestions == 0) {
// TODO Replace by final text, use a dedicated layout, add a fade out timer...
- TextView textView = (TextView) viewGroup.getChildAt(0);
+ TextView textView = (TextView) mSuggestionViewGroup.getChildAt(0);
textView.setText("No suggestions available");
SuggestionInfo suggestionInfo = (SuggestionInfo) textView.getTag();
suggestionInfo.spanStart = NO_SUGGESTIONS;
@@ -8908,17 +8896,24 @@
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
for (int i = 0; i < totalNbSuggestions; i++) {
- final TextView textView = (TextView) viewGroup.getChildAt(i);
+ final TextView textView = (TextView) mSuggestionViewGroup.getChildAt(i);
highlightTextDifferences(textView, spanUnionStart, spanUnionEnd);
}
}
- for (int i = 0; i < MAX_NUMBER_SUGGESTIONS; i++) {
- viewGroup.getChildAt(i).setVisibility(i < totalNbSuggestions ? VISIBLE : GONE);
+ for (int i = 0; i < totalNbSuggestions; i++) {
+ mSuggestionViewGroup.getChildAt(i).setVisibility(VISIBLE);
+ }
+ for (int i = totalNbSuggestions; i < MAX_NUMBER_SUGGESTIONS; i++) {
+ mSuggestionViewGroup.getChildAt(i).setVisibility(GONE);
}
- final int size = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
- viewGroup.measure(size, size);
+ final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
+ final int screenWidth = displayMetrics.widthPixels;
+ final int screenHeight = displayMetrics.heightPixels;
+ mSuggestionViewGroup.measure(
+ View.MeasureSpec.makeMeasureSpec(screenWidth, View.MeasureSpec.AT_MOST),
+ View.MeasureSpec.makeMeasureSpec(screenHeight, View.MeasureSpec.AT_MOST));
positionAtCursor();
}
@@ -9171,23 +9166,12 @@
// Vertical clipping
if (coords[1] + height > screenHeight) {
- // Try to position above current line instead
- // TODO use top layout instead, reverse suggestion order,
- // try full screen vertical down if it still does not fit. TBD with designers.
-
- // Update dimensions from new view
- contentView = mContainer.getContentView();
- width = contentView.getMeasuredWidth();
- height = contentView.getMeasuredHeight();
-
- final int lineTop = mLayout.getLineTop(line);
- final int lineHeight = lineBottom - lineTop;
- coords[1] -= height + lineHeight;
+ coords[1] = screenHeight - height;
}
// Horizontal clipping
- coords[0] = Math.max(0, coords[0]);
coords[0] = Math.min(displayMetrics.widthPixels - width, coords[0]);
+ coords[0] = Math.max(0, coords[0]);
mContainer.showAtLocation(TextView.this, Gravity.NO_GRAVITY, coords[0], coords[1]);
}
diff --git a/core/java/com/android/internal/app/AlertController.java b/core/java/com/android/internal/app/AlertController.java
index 8d6caa1..2061c90 100644
--- a/core/java/com/android/internal/app/AlertController.java
+++ b/core/java/com/android/internal/app/AlertController.java
@@ -438,7 +438,7 @@
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
- topPanel.addView(mCustomTitleView, lp);
+ topPanel.addView(mCustomTitleView, 0, lp);
// Hide the title template
View titleTemplate = mWindow.findViewById(R.id.title_template);
diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
index a9e5057..07430e7 100644
--- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
@@ -27,7 +27,7 @@
void expand();
void collapse();
void disable(int what, IBinder token, String pkg);
- void setIcon(String slot, String iconPackage, int iconId, int iconLevel);
+ void setIcon(String slot, String iconPackage, int iconId, int iconLevel, String contentDescription);
void setIconVisibility(String slot, boolean visible);
void removeIcon(String slot);
void topAppWindowChanged(boolean menuVisible);
diff --git a/core/java/com/android/internal/statusbar/StatusBarIcon.java b/core/java/com/android/internal/statusbar/StatusBarIcon.java
index ae2cac2..3333c82 100644
--- a/core/java/com/android/internal/statusbar/StatusBarIcon.java
+++ b/core/java/com/android/internal/statusbar/StatusBarIcon.java
@@ -19,42 +19,35 @@
import android.os.Parcel;
import android.os.Parcelable;
-/**
- * @hide
- */
public class StatusBarIcon implements Parcelable {
public String iconPackage;
public int iconId;
public int iconLevel;
public boolean visible = true;
public int number;
+ public CharSequence contentDescription;
- private StatusBarIcon() {
- }
-
- public StatusBarIcon(String iconPackage, int iconId, int iconLevel) {
- this.iconPackage = iconPackage;
- this.iconId = iconId;
- this.iconLevel = iconLevel;
- }
-
- public StatusBarIcon(String iconPackage, int iconId, int iconLevel, int number) {
+ public StatusBarIcon(String iconPackage, int iconId, int iconLevel, int number,
+ CharSequence contentDescription) {
this.iconPackage = iconPackage;
this.iconId = iconId;
this.iconLevel = iconLevel;
this.number = number;
+ this.contentDescription = contentDescription;
}
+ @Override
public String toString() {
return "StatusBarIcon(pkg=" + this.iconPackage + " id=0x" + Integer.toHexString(this.iconId)
+ " level=" + this.iconLevel + " visible=" + visible
+ " num=" + this.number + " )";
}
+ @Override
public StatusBarIcon clone() {
- StatusBarIcon that = new StatusBarIcon(this.iconPackage, this.iconId, this.iconLevel);
+ StatusBarIcon that = new StatusBarIcon(this.iconPackage, this.iconId, this.iconLevel,
+ this.number, this.contentDescription);
that.visible = this.visible;
- that.number = this.number;
return that;
}
@@ -71,6 +64,7 @@
this.iconLevel = in.readInt();
this.visible = in.readInt() != 0;
this.number = in.readInt();
+ this.contentDescription = in.readCharSequence();
}
public void writeToParcel(Parcel out, int flags) {
@@ -79,6 +73,7 @@
out.writeInt(this.iconLevel);
out.writeInt(this.visible ? 1 : 0);
out.writeInt(this.number);
+ out.writeCharSequence(this.contentDescription);
}
public int describeContents() {
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 @@
/** 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/view/menu/MenuBuilder.java b/core/java/com/android/internal/view/menu/MenuBuilder.java
index 164d581..159b3da 100644
--- a/core/java/com/android/internal/view/menu/MenuBuilder.java
+++ b/core/java/com/android/internal/view/menu/MenuBuilder.java
@@ -50,6 +50,8 @@
private static final String LOGTAG = "MenuBuilder";
private static final String PRESENTER_KEY = "android:menu:presenters";
+ private static final String ACTION_VIEW_STATES_KEY = "android:menu:actionviewstates";
+ private static final String EXPANDED_ACTION_VIEW_ID = "android:menu:expandedactionview";
private static final int[] sCategoryToOrder = new int[] {
1, /* No category */
@@ -308,6 +310,67 @@
dispatchRestoreInstanceState(state);
}
+ public void saveActionViewStates(Bundle outStates) {
+ SparseArray<Parcelable> viewStates = null;
+
+ final int itemCount = size();
+ for (int i = 0; i < itemCount; i++) {
+ final MenuItem item = getItem(i);
+ final View v = item.getActionView();
+ if (v != null && v.getId() != View.NO_ID) {
+ if (viewStates == null) {
+ viewStates = new SparseArray<Parcelable>();
+ }
+ v.saveHierarchyState(viewStates);
+ if (item.isActionViewExpanded()) {
+ outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
+ }
+ }
+ if (item.hasSubMenu()) {
+ final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
+ subMenu.saveActionViewStates(outStates);
+ }
+ }
+
+ if (viewStates != null) {
+ outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
+ }
+ }
+
+ public void restoreActionViewStates(Bundle states) {
+ if (states == null) {
+ return;
+ }
+
+ SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(
+ getActionViewStatesKey());
+
+ final int itemCount = size();
+ for (int i = 0; i < itemCount; i++) {
+ final MenuItem item = getItem(i);
+ final View v = item.getActionView();
+ if (v != null && v.getId() != View.NO_ID) {
+ v.restoreHierarchyState(viewStates);
+ }
+ if (item.hasSubMenu()) {
+ final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
+ subMenu.restoreActionViewStates(states);
+ }
+ }
+
+ final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
+ if (expandedId > 0) {
+ MenuItem itemToExpand = findItem(expandedId);
+ if (itemToExpand != null) {
+ itemToExpand.expandActionView();
+ }
+ }
+ }
+
+ protected String getActionViewStatesKey() {
+ return ACTION_VIEW_STATES_KEY;
+ }
+
public void setCallback(Callback cb) {
mCallback = cb;
}
diff --git a/core/java/com/android/internal/view/menu/MenuItemImpl.java b/core/java/com/android/internal/view/menu/MenuItemImpl.java
index 541d101..b0a002d 100644
--- a/core/java/com/android/internal/view/menu/MenuItemImpl.java
+++ b/core/java/com/android/internal/view/menu/MenuItemImpl.java
@@ -553,6 +553,9 @@
public MenuItem setActionView(View view) {
mActionView = view;
mActionProvider = null;
+ if (view != null && view.getId() == View.NO_ID && mId > 0) {
+ view.setId(mId);
+ }
mMenu.onItemActionRequestChanged(this);
return this;
}
diff --git a/core/java/com/android/internal/view/menu/SubMenuBuilder.java b/core/java/com/android/internal/view/menu/SubMenuBuilder.java
index fb1cd5e..92acf8c 100644
--- a/core/java/com/android/internal/view/menu/SubMenuBuilder.java
+++ b/core/java/com/android/internal/view/menu/SubMenuBuilder.java
@@ -121,4 +121,13 @@
public boolean collapseItemActionView(MenuItemImpl item) {
return mParentMenu.collapseItemActionView(item);
}
+
+ @Override
+ public String getActionViewStatesKey() {
+ final int itemId = mItem != null ? mItem.getItemId() : 0;
+ if (itemId == 0) {
+ return null;
+ }
+ return super.getActionViewStatesKey() + ":" + itemId;
+ }
}
diff --git a/core/java/com/android/internal/widget/ActionBarView.java b/core/java/com/android/internal/widget/ActionBarView.java
index e03858b..09262e0 100644
--- a/core/java/com/android/internal/widget/ActionBarView.java
+++ b/core/java/com/android/internal/widget/ActionBarView.java
@@ -42,6 +42,7 @@
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
+import android.view.CollapsibleActionView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -285,8 +286,11 @@
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);
}
@@ -332,7 +336,10 @@
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();
@@ -351,6 +358,10 @@
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);
@@ -365,6 +376,10 @@
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.
@@ -1304,6 +1319,10 @@
if (mCustomNavView != null) mCustomNavView.setVisibility(GONE);
requestLayout();
item.setActionViewExpanded(true);
+
+ if (mExpandedActionView instanceof CollapsibleActionView) {
+ ((CollapsibleActionView) mExpandedActionView).onActionViewExpanded();
+ }
return true;
}
@@ -1330,11 +1349,16 @@
if (mCustomNavView != null && (mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0) {
mCustomNavView.setVisibility(VISIBLE);
}
+ View collapsedView = mExpandedActionView;
mExpandedActionView = null;
mExpandedHomeLayout.setIcon(null);
mCurrentExpandedItem = null;
requestLayout();
item.setActionViewExpanded(false);
+
+ if (collapsedView instanceof CollapsibleActionView) {
+ ((CollapsibleActionView) collapsedView).onActionViewCollapsed();
+ }
return true;
}
diff --git a/core/jni/android_net_wifi_Wifi.cpp b/core/jni/android_net_wifi_Wifi.cpp
index e930c5c..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;
@@ -315,26 +318,56 @@
return doBooleanCommand("OK", "DRIVER STOP");
}
-static jboolean android_net_wifi_startPacketFiltering(JNIEnv* env, jobject)
+/*
+ Multicast filtering rules work as follows:
+
+ The driver can filter multicast (v4 and/or v6) and broadcast packets when in
+ a power optimized mode (typically when screen goes off).
+
+ In order to prevent the driver from filtering the multicast/broadcast packets, we have to
+ add a DRIVER RXFILTER-ADD rule followed by DRIVER RXFILTER-START to make the rule effective
+
+ DRIVER RXFILTER-ADD Num
+ where Num = 0 - Unicast, 1 - Broadcast, 2 - Mutil4 or 3 - Multi6
+
+ and DRIVER RXFILTER-START
+
+ In order to stop the usage of these rules, we do
+
+ DRIVER RXFILTER-STOP
+ DRIVER RXFILTER-REMOVE Num
+ where Num is as described for RXFILTER-ADD
+
+ The SETSUSPENDOPT driver command overrides the filtering rules
+*/
+
+static jboolean android_net_wifi_startMultiV4Filtering(JNIEnv* env, jobject)
{
- return doBooleanCommand("OK", "DRIVER RXFILTER-ADD 0")
- && doBooleanCommand("OK", "DRIVER RXFILTER-ADD 1")
- && doBooleanCommand("OK", "DRIVER RXFILTER-ADD 3")
+ return doBooleanCommand("OK", "DRIVER RXFILTER-STOP")
+ && doBooleanCommand("OK", "DRIVER RXFILTER-REMOVE 2")
&& doBooleanCommand("OK", "DRIVER RXFILTER-START");
}
-static jboolean android_net_wifi_stopPacketFiltering(JNIEnv* env, jobject)
+static jboolean android_net_wifi_stopMultiV4Filtering(JNIEnv* env, jobject)
{
- jboolean result = doBooleanCommand("OK", "DRIVER RXFILTER-STOP");
- if (result) {
- (void)doBooleanCommand("OK", "DRIVER RXFILTER-REMOVE 3");
- (void)doBooleanCommand("OK", "DRIVER RXFILTER-REMOVE 1");
- (void)doBooleanCommand("OK", "DRIVER RXFILTER-REMOVE 0");
- }
-
- return result;
+ return doBooleanCommand("OK", "DRIVER RXFILTER-ADD 2")
+ && doBooleanCommand("OK", "DRIVER RXFILTER-START");
}
+static jboolean android_net_wifi_startMultiV6Filtering(JNIEnv* env, jobject)
+{
+ return doBooleanCommand("OK", "DRIVER RXFILTER-STOP")
+ && doBooleanCommand("OK", "DRIVER RXFILTER-REMOVE 3")
+ && doBooleanCommand("OK", "DRIVER RXFILTER-START");
+}
+
+static jboolean android_net_wifi_stopMultiV6Filtering(JNIEnv* env, jobject)
+{
+ return doBooleanCommand("OK", "DRIVER RXFILTER-ADD 3")
+ && doBooleanCommand("OK", "DRIVER RXFILTER-START");
+}
+
+
static jint android_net_wifi_getRssiHelper(const char *cmd)
{
char reply[BUF_SIZE];
@@ -507,6 +540,35 @@
}
+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());
+}
+
+
+
// ----------------------------------------------------------------------------
/*
@@ -545,8 +607,10 @@
{ "setScanModeCommand", "(Z)Z", (void*) android_net_wifi_setScanModeCommand },
{ "startDriverCommand", "()Z", (void*) android_net_wifi_startDriverCommand },
{ "stopDriverCommand", "()Z", (void*) android_net_wifi_stopDriverCommand },
- { "startPacketFiltering", "()Z", (void*) android_net_wifi_startPacketFiltering },
- { "stopPacketFiltering", "()Z", (void*) android_net_wifi_stopPacketFiltering },
+ { "startFilteringMulticastV4Packets", "()Z", (void*) android_net_wifi_startMultiV4Filtering},
+ { "stopFilteringMulticastV4Packets", "()Z", (void*) android_net_wifi_stopMultiV4Filtering},
+ { "startFilteringMulticastV6Packets", "()Z", (void*) android_net_wifi_startMultiV6Filtering},
+ { "stopFilteringMulticastV6Packets", "()Z", (void*) android_net_wifi_stopMultiV6Filtering},
{ "setPowerModeCommand", "(I)Z", (void*) android_net_wifi_setPowerModeCommand },
{ "getPowerModeCommand", "()I", (void*) android_net_wifi_getPowerModeCommand },
{ "setBandCommand", "(I)Z", (void*) android_net_wifi_setBandCommand},
@@ -576,6 +640,9 @@
(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_text_format_Time.cpp b/core/jni/android_text_format_Time.cpp
index c152aa8..69c6021 100644
--- a/core/jni/android_text_format_Time.cpp
+++ b/core/jni/android_text_format_Time.cpp
@@ -641,7 +641,7 @@
/* name, signature, funcPtr */
{ "normalize", "(Z)J", (void*)android_text_format_Time_normalize },
{ "switchTimezone", "(Ljava/lang/String;)V", (void*)android_text_format_Time_switchTimezone },
- { "compare", "(Landroid/text/format/Time;Landroid/text/format/Time;)I", (void*)android_text_format_Time_compare },
+ { "nativeCompare", "(Landroid/text/format/Time;Landroid/text/format/Time;)I", (void*)android_text_format_Time_compare },
{ "format1", "(Ljava/lang/String;)Ljava/lang/String;", (void*)android_text_format_Time_format },
{ "format2445", "()Ljava/lang/String;", (void*)android_text_format_Time_format2445 },
{ "toString", "()Ljava/lang/String;", (void*)android_text_format_Time_toString },
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index b0c2f2c..b06de9d 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -576,18 +576,18 @@
// ----------------------------------------------------------------------------
static DisplayList* android_view_GLES20Canvas_getDisplayList(JNIEnv* env,
- jobject clazz, DisplayListRenderer* renderer) {
- return renderer->getDisplayList();
+ jobject clazz, DisplayListRenderer* renderer, DisplayList* displayList) {
+ return renderer->getDisplayList(displayList);
}
-static OpenGLRenderer* android_view_GLES20Canvas_getDisplayListRenderer(JNIEnv* env,
+static OpenGLRenderer* android_view_GLES20Canvas_createDisplayListRenderer(JNIEnv* env,
+ jobject clazz) {
+ return new DisplayListRenderer;
+}
+
+static void android_view_GLES20Canvas_resetDisplayListRenderer(JNIEnv* env,
jobject clazz, DisplayListRenderer* renderer) {
- if (renderer == NULL) {
- renderer = new DisplayListRenderer;
- } else {
- renderer->reset();
- }
- return renderer;
+ renderer->reset();
}
static void android_view_GLES20Canvas_destroyDisplayList(JNIEnv* env,
@@ -812,9 +812,10 @@
{ "nGetClipBounds", "(ILandroid/graphics/Rect;)Z",
(void*) android_view_GLES20Canvas_getClipBounds },
- { "nGetDisplayList", "(I)I", (void*) android_view_GLES20Canvas_getDisplayList },
+ { "nGetDisplayList", "(II)I", (void*) android_view_GLES20Canvas_getDisplayList },
{ "nDestroyDisplayList", "(I)V", (void*) android_view_GLES20Canvas_destroyDisplayList },
- { "nGetDisplayListRenderer", "(I)I", (void*) android_view_GLES20Canvas_getDisplayListRenderer },
+ { "nCreateDisplayListRenderer", "()I", (void*) android_view_GLES20Canvas_createDisplayListRenderer },
+ { "nResetDisplayListRenderer", "(I)V", (void*) android_view_GLES20Canvas_resetDisplayListRenderer },
{ "nDrawDisplayList", "(IIIILandroid/graphics/Rect;)Z",
(void*) android_view_GLES20Canvas_drawDisplayList },
{ "nOutputDisplayList", "(II)V", (void*) android_view_GLES20Canvas_outputDisplayList },
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 @@
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 @@
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 @@
{"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 103a326..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"
@@ -1197,7 +1204,7 @@
<permission android:name="android.permission.READ_FRAME_BUFFER"
android:label="@string/permlab_readFrameBuffer"
android:description="@string/permdesc_readFrameBuffer"
- android:protectionLevel="signature" />
+ android:protectionLevel="signatureOrSystem" />
<!-- Required to be able to disable the device (very dangerous!). -->
<permission android:name="android.permission.BRICK"
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/drawable-hdpi/text_edit_suggestions_top_window.9.png b/core/res/res/drawable-hdpi/text_edit_suggestions_top_window.9.png
deleted file mode 100644
index ff6b34a..0000000
--- a/core/res/res/drawable-hdpi/text_edit_suggestions_top_window.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-hdpi/text_edit_suggestions_bottom_window.9.png b/core/res/res/drawable-hdpi/text_edit_suggestions_window.9.png
similarity index 100%
rename from core/res/res/drawable-hdpi/text_edit_suggestions_bottom_window.9.png
rename to core/res/res/drawable-hdpi/text_edit_suggestions_window.9.png
Binary files differ
diff --git a/core/res/res/drawable-mdpi/text_edit_suggestions_top_window.9.png b/core/res/res/drawable-mdpi/text_edit_suggestions_top_window.9.png
deleted file mode 100644
index 41886eb..0000000
--- a/core/res/res/drawable-mdpi/text_edit_suggestions_top_window.9.png
+++ /dev/null
Binary files differ
diff --git a/core/res/res/drawable-mdpi/text_edit_suggestions_bottom_window.9.png b/core/res/res/drawable-mdpi/text_edit_suggestions_window.9.png
similarity index 100%
rename from core/res/res/drawable-mdpi/text_edit_suggestions_bottom_window.9.png
rename to core/res/res/drawable-mdpi/text_edit_suggestions_window.9.png
Binary files differ
diff --git a/core/res/res/layout/text_edit_suggestion_item.xml b/core/res/res/layout/text_edit_suggestion_item.xml
index ef537d9..082c5ec 100644
--- a/core/res/res/layout/text_edit_suggestion_item.xml
+++ b/core/res/res/layout/text_edit_suggestion_item.xml
@@ -22,6 +22,8 @@
android:paddingTop="8dip"
android:paddingBottom="8dip"
android:layout_gravity="left|center_vertical"
+ android:singleLine="true"
+ android:ellipsize="marquee"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/dim_foreground_light" />
diff --git a/core/res/res/layout/text_edit_suggestions_top_window.xml b/core/res/res/layout/text_edit_suggestions_window.xml
similarity index 98%
rename from core/res/res/layout/text_edit_suggestions_top_window.xml
rename to core/res/res/layout/text_edit_suggestions_window.xml
index 67faa37..824025e 100644
--- a/core/res/res/layout/text_edit_suggestions_top_window.xml
+++ b/core/res/res/layout/text_edit_suggestions_window.xml
@@ -18,6 +18,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:background="@android:drawable/text_edit_suggestions_top_window">
+ android:background="@android:drawable/text_edit_suggestions_window">
</LinearLayout>
diff --git a/core/res/res/layout/text_edit_suggestions_bottom_window.xml b/core/res/res/layout/wifi_p2p_go_negotiation_request_alert.xml
similarity index 77%
rename from core/res/res/layout/text_edit_suggestions_bottom_window.xml
rename to core/res/res/layout/wifi_p2p_go_negotiation_request_alert.xml
index 588bfbd..41ca657 100644
--- a/core/res/res/layout/text_edit_suggestions_bottom_window.xml
+++ b/core/res/res/layout/wifi_p2p_go_negotiation_request_alert.xml
@@ -4,9 +4,9 @@
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.
@@ -16,8 +16,11 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:background="@android:drawable/text_edit_suggestions_bottom_window">
+ 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 082284a..88ab983 100755
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -713,10 +713,7 @@
<!-- Layout of a the view that is used to create the text suggestions popup window in an
EditText. This window will be displayed below the text line. -->
- <attr name="textEditSuggestionsBottomWindowLayout" format="reference" />
- <!-- Same as textEditSuggestionsBottomWindowLayout, but used when the popup is displayed
- above the current line of text instead of below. -->
- <attr name="textEditSuggestionsTopWindowLayout" format="reference" />
+ <attr name="textEditSuggestionsWindowLayout" format="reference" />
<!-- Layout of the TextView item that will populate the suggestion popup window. -->
<attr name="textEditSuggestionItemLayout" format="reference" />
@@ -2281,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
@@ -3082,10 +3081,7 @@
<!-- Layout of a the view that is used to create the text suggestions popup window in an
EditText. This window will be displayed below the text line. -->
- <attr name="textEditSuggestionsBottomWindowLayout" />
- <!-- Same as textEditSuggestionsBottomWindowLayout, but used when the popup is displayed
- above the current line of text instead of below. -->
- <attr name="textEditSuggestionsTopWindowLayout" />
+ <attr name="textEditSuggestionsWindowLayout" />
<!-- Layout of the TextView item that will populate the suggestion popup window. -->
<attr name="textEditSuggestionItemLayout" />
@@ -3365,18 +3361,16 @@
The default is LEFT | BASELINE.
See {@link android.widget.GridLayout.LayoutParams#setGravity(int)}. -->
<attr name="layout_gravity" />
- <!-- A value specifying how much deficit or excess width this component can accomodate.
- The default is FIXED. -->
+ <!-- {@deprecated To make a column group lexible, ensure that every component in the
+ group defines a horizontal gravity.} -->
<attr name="layout_columnFlexibility" >
- <!-- If possible, width should be greater than or equal to the specified width.
- See {@link android.widget.GridLayout#CAN_STRETCH}. -->
+ <enum name="inflexible" value="0" />
<enum name="canStretch" value="2" />
</attr>
- <!-- A value specifying how much deficit or excess height this component can accomodate.
- The default is FIXED. -->
+ <!-- {@deprecated To make a row group flexible, ensure that every component in the
+ group defines a vertical gravity.} -->
<attr name="layout_rowFlexibility" >
- <!-- If possible, height should be greater than or equal to the specified height.
- See {@link android.widget.GridLayout#CAN_STRETCH}. -->
+ <enum name="inflexible" value="0" />
<enum name="canStretch" value="2" />
</attr>
</declare-styleable>
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/public.xml b/core/res/res/values/public.xml
index 75f0c4e..b2b7025 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -1715,8 +1715,7 @@
<public type="attr" name="switchPreferenceStyle" />
<public type="attr" name="textSuggestionsWindowStyle" />
- <public type="attr" name="textEditSuggestionsBottomWindowLayout" />
- <public type="attr" name="textEditSuggestionsTopWindowLayout" />
+ <public type="attr" name="textEditSuggestionsWindowLayout" />
<public type="attr" name="textEditSuggestionItemLayout" />
<public type="attr" name="suggestionsEnabled" />
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 419734a..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
@@ -2568,9 +2574,23 @@
<item quantity="one">Open Wi-Fi network available</item>
<item quantity="other">Open Wi-Fi networks available</item>
</plurals>
+
+ <!-- A notification is shown the first time a wireless network is disabled due to bad connectivity. This is the notification's title / ticker. -->
+ <string name="wifi_watchdog_network_disabled">A Wi-Fi network was disabled</string>
+ <!-- A notification is shown the first time a wireless network is disabled due to bad connectivity. This is the notification's message which leads to the settings pane -->
+ <string name="wifi_watchdog_network_disabled_detailed">A Wi-Fi network was temporarily disabled due to bad connectivity.</string>
+
<!-- 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>
@@ -2669,12 +2689,14 @@
<!-- USB_STORAGE_ERROR dialog ok button-->
<string name="dlg_ok">OK</string>
- <!-- USB_PREFERENCES: Notification for wehen the user connects the phone to a computer via USB in MTP mode. This is the title -->
+ <!-- USB_PREFERENCES: Notification for when the user connects the phone to a computer via USB in MTP mode. This is the title -->
<string name="usb_mtp_notification_title">Connected as a media device</string>
- <!-- USB_PREFERENCES: Notification for wehen the user connects the phone to a computer via USB in PTP mode. This is the title -->
+ <!-- USB_PREFERENCES: Notification for when the user connects the phone to a computer via USB in PTP mode. This is the title -->
<string name="usb_ptp_notification_title">Connected as a camera</string>
- <!-- USB_PREFERENCES: Notification for wehen the user connects the phone to a computer via USB in mass storage mode (for installer CD image). This is the title -->
+ <!-- USB_PREFERENCES: Notification for when the user connects the phone to a computer via USB in mass storage mode (for installer CD image). This is the title -->
<string name="usb_cd_installer_notification_title">Connected as an installer</string>
+ <!-- USB_PREFERENCES: Notification for when a USB accessory is attached. This is the title -->
+ <string name="usb_accessory_notification_title">Connected to a USB accessory</string>
<!-- See USB_PREFERENCES. This is the message. -->
<string name="usb_notification_message">Touch for other USB options</string>
@@ -3050,4 +3072,9 @@
<!-- Title for a dialog showing possible activities for sharing in ShareActionProvider [CHAR LIMIT=25] -->
<string name="share_action_provider_share_with">Share with...</string>
+ <!-- Status Bar icon descriptions -->
+
+ <!-- Description of for the status bar's icon that the device is locked for accessibility. [CHAR LIMIT=NONE] -->
+ <string name="status_bar_device_locked">Device locked.</string>
+
</resources>
diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml
index d647467..9b6c442 100644
--- a/core/res/res/values/styles.xml
+++ b/core/res/res/values/styles.xml
@@ -423,8 +423,7 @@
<item name="android:textEditNoPasteWindowLayout">?android:attr/textEditNoPasteWindowLayout</item>
<item name="android:textEditSidePasteWindowLayout">?android:attr/textEditSidePasteWindowLayout</item>
<item name="android:textEditSideNoPasteWindowLayout">?android:attr/textEditSideNoPasteWindowLayout</item>
- <item name="android:textEditSuggestionsBottomWindowLayout">?android:attr/textEditSuggestionsBottomWindowLayout</item>
- <item name="android:textEditSuggestionsTopWindowLayout">?android:attr/textEditSuggestionsTopWindowLayout</item>
+ <item name="android:textEditSuggestionsWindowLayout">?android:attr/textEditSuggestionsWindowLayout</item>
<item name="android:textEditSuggestionItemLayout">?android:attr/textEditSuggestionItemLayout</item>
<item name="android:textCursorDrawable">?android:attr/textCursorDrawable</item>
</style>
diff --git a/core/res/res/values/themes.xml b/core/res/res/values/themes.xml
index 90f3602..93ccfe3 100644
--- a/core/res/res/values/themes.xml
+++ b/core/res/res/values/themes.xml
@@ -190,8 +190,7 @@
<item name="textEditSidePasteWindowLayout">@android:layout/text_edit_side_paste_window</item>
<item name="textEditSideNoPasteWindowLayout">@android:layout/text_edit_side_no_paste_window</item>
<item name="textSuggestionsWindowStyle">@android:style/Widget.TextSuggestions</item>
- <item name="textEditSuggestionsBottomWindowLayout">@android:layout/text_edit_suggestions_bottom_window</item>
- <item name="textEditSuggestionsTopWindowLayout">@android:layout/text_edit_suggestions_top_window</item>
+ <item name="textEditSuggestionsWindowLayout">@android:layout/text_edit_suggestions_window</item>
<item name="textEditSuggestionItemLayout">@android:layout/text_edit_suggestion_item</item>
<item name="textCursorDrawable">@null</item>
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 @@
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 @@
<td>Run PPP over USB.
<ul>
<li><code><tty></code> — 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> — 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 @@
<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 — 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> —
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 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 — multiple
-"{@code state...}" values, for example &mdash has undefined results.
+"{@code state...}" values, for example — has undefined results.
Individual values are separated by a vertical bar ({@code |}). For example:
</p>
@@ -801,4 +801,4 @@
<dt>see also:</dt>
<dd><code><a href="{@docRoot}guide/topics/manifest/application-element.html"><application></a></code>
<br/><code><a href="{@docRoot}guide/topics/manifest/activity-alias-element.html"><activity-alias></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 @@
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 — {@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/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp
index 2d8e877..986f32c 100644
--- a/drm/common/IDrmManagerService.cpp
+++ b/drm/common/IDrmManagerService.cpp
@@ -110,11 +110,11 @@
handle->extendedData.clear();
}
-int BpDrmManagerService::addUniqueId(int uniqueId) {
+int BpDrmManagerService::addUniqueId(bool isNative) {
LOGV("add uniqueid");
Parcel data, reply;
data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
- data.writeInt32(uniqueId);
+ data.writeInt32(isNative);
remote()->transact(ADD_UNIQUEID, data, &reply);
return reply.readInt32();
}
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index 1809619..3e4fe8c 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -49,32 +49,42 @@
}
-int DrmManager::addUniqueId(int uniqueId) {
+int DrmManager::addUniqueId(bool isNative) {
Mutex::Autolock _l(mLock);
- if (0 == uniqueId) {
- int temp = 0;
- bool foundUniqueId = false;
- srand(time(NULL));
- while (!foundUniqueId) {
- const int size = mUniqueIdVector.size();
- temp = rand() % 100;
+ int temp = 0;
+ bool foundUniqueId = false;
+ const int size = mUniqueIdVector.size();
+ const int uniqueIdRange = 0xfff;
+ int maxLoopTimes = (uniqueIdRange - 1) / 2;
+ srand(time(NULL));
- int index = 0;
- for (; index < size; ++index) {
- if (mUniqueIdVector.itemAt(index) == temp) {
- foundUniqueId = false;
- break;
- }
- }
- if (index == size) {
- foundUniqueId = true;
+ while (!foundUniqueId) {
+ temp = rand() & uniqueIdRange;
+
+ if (isNative) {
+ // set a flag to differentiate DrmManagerClient
+ // created from native side and java side
+ temp |= 0x1000;
+ }
+
+ int index = 0;
+ for (; index < size; ++index) {
+ if (mUniqueIdVector.itemAt(index) == temp) {
+ foundUniqueId = false;
+ break;
}
}
- uniqueId = temp;
+ if (index == size) {
+ foundUniqueId = true;
+ }
+
+ maxLoopTimes --;
+ LOG_FATAL_IF(maxLoopTimes <= 0, "cannot find an unique ID for this session");
}
- mUniqueIdVector.push(uniqueId);
- return uniqueId;
+
+ mUniqueIdVector.push(temp);
+ return temp;
}
void DrmManager::removeUniqueId(int uniqueId) {
diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp
index 583669e..7ebcac3 100644
--- a/drm/drmserver/DrmManagerService.cpp
+++ b/drm/drmserver/DrmManagerService.cpp
@@ -78,8 +78,8 @@
delete mDrmManager; mDrmManager = NULL;
}
-int DrmManagerService::addUniqueId(int uniqueId) {
- return mDrmManager->addUniqueId(uniqueId);
+int DrmManagerService::addUniqueId(bool isNative) {
+ return mDrmManager->addUniqueId(isNative);
}
void DrmManagerService::removeUniqueId(int uniqueId) {
diff --git a/drm/java/android/drm/DrmManagerClient.java b/drm/java/android/drm/DrmManagerClient.java
index f3a0343..9a7194c 100755
--- a/drm/java/android/drm/DrmManagerClient.java
+++ b/drm/java/android/drm/DrmManagerClient.java
@@ -248,9 +248,7 @@
mEventHandler = new EventHandler(eventThread.getLooper());
// save the unique id
- mUniqueId = hashCode();
-
- _initialize(mUniqueId, new WeakReference<DrmManagerClient>(this));
+ mUniqueId = _initialize(new WeakReference<DrmManagerClient>(this));
}
protected void finalize() {
@@ -794,7 +792,7 @@
}
// private native interfaces
- private native void _initialize(int uniqueId, Object weak_this);
+ private native int _initialize(Object weak_this);
private native void _finalize(int uniqueId);
diff --git a/drm/jni/android_drm_DrmManagerClient.cpp b/drm/jni/android_drm_DrmManagerClient.cpp
index e131839..80a8447 100644
--- a/drm/jni/android_drm_DrmManagerClient.cpp
+++ b/drm/jni/android_drm_DrmManagerClient.cpp
@@ -224,11 +224,12 @@
return sp<DrmManagerClientImpl>(client);
}
-static void android_drm_DrmManagerClient_initialize(
- JNIEnv* env, jobject thiz, jint uniqueId, jobject weak_thiz) {
+static jint android_drm_DrmManagerClient_initialize(
+ JNIEnv* env, jobject thiz, jobject weak_thiz) {
LOGV("initialize - Enter");
- sp<DrmManagerClientImpl> drmManager = DrmManagerClientImpl::create(&uniqueId);
+ int uniqueId = 0;
+ sp<DrmManagerClientImpl> drmManager = DrmManagerClientImpl::create(&uniqueId, false);
drmManager->addClient(uniqueId);
// Set the listener to DrmManager
@@ -237,6 +238,8 @@
setDrmManagerClientImpl(env, thiz, drmManager);
LOGV("initialize - Exit");
+
+ return uniqueId;
}
static void android_drm_DrmManagerClient_finalize(JNIEnv* env, jobject thiz, jint uniqueId) {
@@ -711,7 +714,7 @@
static JNINativeMethod nativeMethods[] = {
- {"_initialize", "(ILjava/lang/Object;)V",
+ {"_initialize", "(Ljava/lang/Object;)I",
(void*)android_drm_DrmManagerClient_initialize},
{"_finalize", "(I)V",
diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp
index b50199f..c9c0d57 100644
--- a/drm/libdrmframework/DrmManagerClient.cpp
+++ b/drm/libdrmframework/DrmManagerClient.cpp
@@ -24,7 +24,7 @@
DrmManagerClient::DrmManagerClient():
mUniqueId(0), mDrmManagerClientImpl(NULL) {
- mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId);
+ mDrmManagerClientImpl = DrmManagerClientImpl::create(&mUniqueId, true);
mDrmManagerClientImpl->addClient(mUniqueId);
}
diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp
index a36bd4a..67f58ca 100644
--- a/drm/libdrmframework/DrmManagerClientImpl.cpp
+++ b/drm/libdrmframework/DrmManagerClientImpl.cpp
@@ -33,13 +33,10 @@
sp<DrmManagerClientImpl::DeathNotifier> DrmManagerClientImpl::sDeathNotifier;
const String8 DrmManagerClientImpl::EMPTY_STRING("");
-DrmManagerClientImpl* DrmManagerClientImpl::create(int* pUniqueId) {
- if (0 == *pUniqueId) {
- int uniqueId = getDrmManagerService()->addUniqueId(*pUniqueId);
- *pUniqueId = uniqueId;
- } else {
- getDrmManagerService()->addUniqueId(*pUniqueId);
- }
+DrmManagerClientImpl* DrmManagerClientImpl::create(
+ int* pUniqueId, bool isNative) {
+ *pUniqueId = getDrmManagerService()->addUniqueId(isNative);
+
return new DrmManagerClientImpl();
}
diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h
index af2c2a8..ac2b946 100644
--- a/drm/libdrmframework/include/DrmManager.h
+++ b/drm/libdrmframework/include/DrmManager.h
@@ -53,7 +53,7 @@
virtual ~DrmManager();
public:
- int addUniqueId(int uniqueId);
+ int addUniqueId(bool isNative);
void removeUniqueId(int uniqueId);
diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h
index 564896b..e3338d9 100644
--- a/drm/libdrmframework/include/DrmManagerClientImpl.h
+++ b/drm/libdrmframework/include/DrmManagerClientImpl.h
@@ -38,7 +38,7 @@
DrmManagerClientImpl() { }
public:
- static DrmManagerClientImpl* create(int* pUniqueId);
+ static DrmManagerClientImpl* create(int* pUniqueId, bool isNative);
static void remove(int uniqueId);
diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h
index 227496a..9cb5804 100644
--- a/drm/libdrmframework/include/DrmManagerService.h
+++ b/drm/libdrmframework/include/DrmManagerService.h
@@ -46,7 +46,7 @@
virtual ~DrmManagerService();
public:
- int addUniqueId(int uniqueId);
+ int addUniqueId(bool isNative);
void removeUniqueId(int uniqueId);
diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h
index 7727e55..b9618bb 100644
--- a/drm/libdrmframework/include/IDrmManagerService.h
+++ b/drm/libdrmframework/include/IDrmManagerService.h
@@ -81,7 +81,7 @@
DECLARE_META_INTERFACE(DrmManagerService);
public:
- virtual int addUniqueId(int uniqueId) = 0;
+ virtual int addUniqueId(bool isNative) = 0;
virtual void removeUniqueId(int uniqueId) = 0;
@@ -167,7 +167,7 @@
BpDrmManagerService(const sp<IBinder>& impl)
: BpInterface<IDrmManagerService>(impl) {}
- virtual int addUniqueId(int uniqueId);
+ virtual int addUniqueId(bool isNative);
virtual void removeUniqueId(int uniqueId);
diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
index b61e3d3..4a5afcf 100644
--- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
+++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
@@ -143,7 +143,13 @@
* Register a callback to be invoked when the caller required to
* receive necessary information
*
- * @param[in] uniqueId Unique identifier for a session
+ * @param[in] uniqueId Unique identifier for a session. uniqueId is a random
+ * number generated in the DRM service. If the DrmManagerClient
+ * is created in native code, uniqueId will be a number ranged
+ * from 0x1000 to 0x1fff. If it comes from Java code, the uniqueId
+ * will be a number ranged from 0x00 to 0xfff. So bit 0x1000 in
+ * uniqueId could be used in DRM plugins to differentiate native
+ * OnInfoListener and Java OnInfoListener.
* @param[in] infoListener Listener
* @return status_t
* Returns DRM_NO_ERROR for success, DRM_ERROR_UNKNOWN for failure
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 @@
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 @@
// 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 @@
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 @@
// 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 @@
// 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 @@
// all slots.
void freeAllBuffers();
static bool isExternalFormat(uint32_t format);
- static GLenum getTextureTarget(uint32_t format);
private:
@@ -337,14 +347,9 @@
// 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 @@
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 @@
// 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/AudioEffect.h b/include/media/AudioEffect.h
index 496b23e..1417416 100644
--- a/include/media/AudioEffect.h
+++ b/include/media/AudioEffect.h
@@ -21,6 +21,7 @@
#include <sys/types.h>
#include <media/IAudioFlinger.h>
+#include <media/IAudioPolicyService.h>
#include <media/IEffect.h>
#include <media/IEffectClient.h>
#include <hardware/audio_effect.h>
@@ -111,6 +112,36 @@
/*
+ * Returns a list of descriptors corresponding to the pre processings enabled by default
+ * on an AudioRecord with the supplied audio session ID.
+ *
+ * Parameters:
+ * audioSession: audio session ID.
+ * descriptors: address where the effect descriptors should be returned.
+ * count: as input, the maximum number of descriptor than should be returned
+ * as output, the number of descriptor returned if status is NO_ERROR or the actual
+ * number of enabled pre processings if status is NO_MEMORY
+ *
+ * Returned status (from utils/Errors.h) can be:
+ * NO_ERROR successful operation.
+ * NO_MEMORY the number of descriptor to return is more than the maximum number
+ * indicated by count.
+ * PERMISSION_DENIED could not get AudioFlinger interface
+ * NO_INIT effect library failed to initialize
+ * BAD_VALUE invalid audio session or descriptor pointers
+ *
+ * Returned value
+ * *descriptor updated with descriptors of pre processings enabled by default
+ * *count number of descriptors returned if returned status is N_ERROR.
+ * total number of pre processing enabled by default if returned status is
+ * NO_MEMORY. This happens if the count passed as input is less than the number
+ * of descriptors to return
+ */
+ static status_t queryDefaultPreProcessing(int audioSession,
+ effect_descriptor_t *descriptors,
+ uint32_t *count);
+
+ /*
* Events used by callback function (effect_callback_t).
*/
enum event_type {
diff --git a/include/media/IAudioPolicyService.h b/include/media/IAudioPolicyService.h
index 86b9f85..ed265e1 100644
--- a/include/media/IAudioPolicyService.h
+++ b/include/media/IAudioPolicyService.h
@@ -85,6 +85,9 @@
int id) = 0;
virtual status_t unregisterEffect(int id) = 0;
virtual bool isStreamActive(int stream, uint32_t inPastMs = 0) const = 0;
+ virtual status_t queryDefaultPreProcessing(int audioSession,
+ effect_descriptor_t *descriptors,
+ uint32_t *count) = 0;
};
diff --git a/include/media/IMediaRecorder.h b/include/media/IMediaRecorder.h
index a73267d..ec84e25 100644
--- a/include/media/IMediaRecorder.h
+++ b/include/media/IMediaRecorder.h
@@ -26,6 +26,7 @@
class ICamera;
class ICameraRecordingProxy;
class IMediaRecorderClient;
+class ISurfaceTexture;
class IMediaRecorder: public IInterface
{
@@ -42,7 +43,6 @@
virtual status_t setAudioEncoder(int ae) = 0;
virtual status_t setOutputFile(const char* path) = 0;
virtual status_t setOutputFile(int fd, int64_t offset, int64_t length) = 0;
- virtual status_t setOutputFileAuxiliary(int fd) = 0;
virtual status_t setVideoSize(int width, int height) = 0;
virtual status_t setVideoFrameRate(int frames_per_second) = 0;
virtual status_t setParameters(const String8& params) = 0;
@@ -55,6 +55,7 @@
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/MediaProfiles.h b/include/media/MediaProfiles.h
index ed26e63..69d5001 100644
--- a/include/media/MediaProfiles.h
+++ b/include/media/MediaProfiles.h
@@ -45,6 +45,18 @@
CAMCORDER_QUALITY_TIME_LAPSE_LIST_END = 1006,
};
+/**
+ *Set CIF as default maximum import and export resolution of video editor.
+ *The maximum import and export resolutions are platform specific,
+ *which should be defined in media_profiles.xml.
+ */
+enum videoeditor_capability {
+ VIDEOEDITOR_DEFAULT_MAX_INPUT_FRAME_WIDTH = 352,
+ VIDEOEDITOR_DEFUALT_MAX_INPUT_FRAME_HEIGHT = 288,
+ VIDEOEDITOR_DEFAULT_MAX_OUTPUT_FRAME_WIDTH = 352,
+ VIDEOEDITOR_DEFUALT_MAX_OUTPUT_FRAME_HEIGHT = 288,
+};
+
enum video_decoder {
VIDEO_DECODER_WMV,
};
@@ -117,6 +129,17 @@
int getVideoEncoderParamByName(const char *name, video_encoder codec) const;
/**
+ * Returns the value for the given param name for the video editor cap
+ * param or -1 if error.
+ * Supported param name are:
+ * videoeditor.input.width.max - max input video frame width
+ * videoeditor.input.height.max - max input video frame height
+ * videoeditor.output.width.max - max output video frame width
+ * videoeditor.output.height.max - max output video frame height
+ */
+ int getVideoEditorCapParamByName(const char *name) const;
+
+ /**
* Returns the audio encoders supported.
*/
Vector<audio_encoder> getAudioEncoders() const;
@@ -164,7 +187,7 @@
MediaProfiles& operator=(const MediaProfiles&); // Don't call me
MediaProfiles(const MediaProfiles&); // Don't call me
- MediaProfiles() {} // Dummy default constructor
+ MediaProfiles() { mVideoEditorCap = NULL; } // Dummy default constructor
~MediaProfiles(); // Don't delete me
struct VideoCodec {
@@ -310,6 +333,22 @@
Vector<int> mLevels;
};
+ struct VideoEditorCap {
+ VideoEditorCap(int inFrameWidth, int inFrameHeight,
+ int outFrameWidth, int outFrameHeight)
+ : mMaxInputFrameWidth(inFrameWidth),
+ mMaxInputFrameHeight(inFrameHeight),
+ mMaxOutputFrameWidth(outFrameWidth),
+ mMaxOutputFrameHeight(outFrameHeight) {}
+
+ ~VideoEditorCap() {}
+
+ int mMaxInputFrameWidth;
+ int mMaxInputFrameHeight;
+ int mMaxOutputFrameWidth;
+ int mMaxOutputFrameHeight;
+ };
+
int getCamcorderProfileIndex(int cameraId, camcorder_quality quality) const;
void initRequiredProfileRefs(const Vector<int>& cameraIds);
int getRequiredProfileRefIndex(int cameraId);
@@ -321,6 +360,7 @@
static void logAudioEncoderCap(const AudioEncoderCap& cap);
static void logVideoDecoderCap(const VideoDecoderCap& cap);
static void logAudioDecoderCap(const AudioDecoderCap& cap);
+ static void logVideoEditorCap(const VideoEditorCap& cap);
// If the xml configuration file does exist, use the settings
// from the xml
@@ -332,6 +372,8 @@
static VideoDecoderCap* createVideoDecoderCap(const char **atts);
static VideoEncoderCap* createVideoEncoderCap(const char **atts);
static AudioEncoderCap* createAudioEncoderCap(const char **atts);
+ static VideoEditorCap* createVideoEditorCap(
+ const char **atts, MediaProfiles *profiles);
static CamcorderProfile* createCamcorderProfile(
int cameraId, const char **atts, Vector<int>& cameraIds);
@@ -375,6 +417,7 @@
static void createDefaultEncoderOutputFileFormats(MediaProfiles *profiles);
static void createDefaultImageEncodingQualityLevels(MediaProfiles *profiles);
static void createDefaultImageDecodingMaxMemory(MediaProfiles *profiles);
+ static void createDefaultVideoEditorCap(MediaProfiles *profiles);
static VideoEncoderCap* createDefaultH263VideoEncoderCap();
static VideoEncoderCap* createDefaultM4vVideoEncoderCap();
static AudioEncoderCap* createDefaultAmrNBEncoderCap();
@@ -431,6 +474,7 @@
RequiredProfiles *mRequiredProfileRefs;
Vector<int> mCameraIds;
+ VideoEditorCap* mVideoEditorCap;
};
}; // namespace android
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 @@
class ICameraRecordingProxy;
class Surface;
+class ISurfaceTexture;
struct MediaRecorderBase {
MediaRecorderBase() {}
@@ -54,6 +55,7 @@
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..30db642 100644
--- a/include/media/mediarecorder.h
+++ b/include/media/mediarecorder.h
@@ -31,12 +31,15 @@
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
};
@@ -212,7 +215,6 @@
status_t setAudioEncoder(int ae);
status_t setOutputFile(const char* path);
status_t setOutputFile(int fd, int64_t offset, int64_t length);
- status_t setOutputFileAuxiliary(int fd);
status_t setVideoSize(int width, int height);
status_t setVideoFrameRate(int frames_per_second);
status_t setParameters(const String8& params);
@@ -226,6 +228,7 @@
status_t close();
status_t release();
void notify(int msg, int ext1, int ext2);
+ sp<ISurfaceTexture> querySurfaceMediaSourceFromMediaServer();
private:
void doCleanUp();
@@ -233,13 +236,18 @@
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;
bool mIsAudioEncoderSet;
bool mIsVideoEncoderSet;
bool mIsOutputFileSet;
- bool mIsAuxiliaryOutputFileSet;
Mutex mLock;
Mutex mNotifyLock;
};
diff --git a/include/media/stagefright/CameraSourceTimeLapse.h b/include/media/stagefright/CameraSourceTimeLapse.h
index f07ebba..0e264c7 100644
--- a/include/media/stagefright/CameraSourceTimeLapse.h
+++ b/include/media/stagefright/CameraSourceTimeLapse.h
@@ -53,27 +53,10 @@
void startQuickReadReturns();
private:
- // If true, will use still camera takePicture() for time lapse frames
- // If false, will use the videocamera frames instead.
- bool mUseStillCameraForTimeLapse;
-
- // Size of picture taken from still camera. This may be larger than the size
- // of the video, as still camera may not support the exact video resolution
- // demanded. See setPictureSizeToClosestSupported().
- int32_t mPictureWidth;
- int32_t mPictureHeight;
-
// size of the encoded video.
int32_t mVideoWidth;
int32_t mVideoHeight;
- // True if we need to crop the still camera image to get the video frame.
- bool mNeedCropping;
-
- // Start location of the cropping rectangle.
- int32_t mCropRectStartX;
- int32_t mCropRectStartY;
-
// Time between capture of two frames during time lapse recording
// Negative value indicates that timelapse is disabled.
int64_t mTimeBetweenTimeLapseFrameCaptureUs;
@@ -84,9 +67,6 @@
// Real timestamp of the last encoded time lapse frame
int64_t mLastTimeLapseFrameRealTimestampUs;
- // Thread id of thread which takes still picture and sleeps in a loop.
- pthread_t mThreadTimeLapse;
-
// Variable set in dataCallbackTimestamp() to help skipCurrentFrame()
// to know if current frame needs to be skipped.
bool mSkipCurrentFrame;
@@ -111,9 +91,6 @@
// Lock for accessing quick stop variables.
Mutex mQuickStopLock;
- // Condition variable to wake up still picture thread.
- Condition mTakePictureCondition;
-
// mQuickStop is set to true if we use quick read() returns, otherwise it is set
// to false. Once in this mode read() return a copy of the last read frame
// with the same time stamp. See startQuickReadReturns().
@@ -148,32 +125,13 @@
// Wrapper over CameraSource::read() to implement quick stop.
virtual status_t read(MediaBuffer **buffer, const ReadOptions *options = NULL);
- // For still camera case starts a thread which calls camera's takePicture()
- // in a loop. For video camera case, just starts the camera's video recording.
- virtual void startCameraRecording();
-
- // For still camera case joins the thread created in startCameraRecording().
// For video camera case, just stops the camera's video recording.
virtual void stopCameraRecording();
- // For still camera case don't need to do anything as memory is locally
- // allocated with refcounting.
- // For video camera case just tell the camera to release the frame.
- virtual void releaseRecordingFrame(const sp<IMemory>& frame);
-
// mSkipCurrentFrame is set to true in dataCallbackTimestamp() if the current
// frame needs to be skipped and this function just returns the value of mSkipCurrentFrame.
virtual bool skipCurrentFrame(int64_t timestampUs);
- // Handles the callback to handle raw frame data from the still camera.
- // Creates a copy of the frame data as the camera can reuse the frame memory
- // once this callback returns. The function also sets a new timstamp corresponding
- // to one frame time ahead of the last encoded frame's time stamp. It then
- // calls dataCallbackTimestamp() of the base class with the copied data and the
- // modified timestamp, which will think that it recieved the frame from a video
- // camera and proceed as usual.
- virtual void dataCallback(int32_t msgType, const sp<IMemory> &data);
-
// In the video camera case calls skipFrameAndModifyTimeStamp() to modify
// timestamp and set mSkipCurrentFrame.
// Then it calls the base CameraSource::dataCallbackTimestamp()
@@ -189,24 +147,6 @@
// Otherwise returns false.
bool trySettingVideoSize(int32_t width, int32_t height);
- // The still camera may not support the demanded video width and height.
- // We look for the supported picture sizes from the still camera and
- // choose the smallest one with either dimensions higher than the corresponding
- // video dimensions. The still picture will be cropped to get the video frame.
- // The function returns true if the camera supports picture sizes greater than
- // or equal to the passed in width and height, and false otherwise.
- bool setPictureSizeToClosestSupported(int32_t width, int32_t height);
-
- // Computes the offset of the rectangle from where to start cropping the
- // still image into the video frame. We choose the center of the image to be
- // cropped. The offset is stored in (mCropRectStartX, mCropRectStartY).
- bool computeCropRectangleOffset();
-
- // Crops the source data into a smaller image starting at
- // (mCropRectStartX, mCropRectStartY) and of the size of the video frame.
- // The data is returned into a newly allocated IMemory.
- sp<IMemory> cropYUVImage(const sp<IMemory> &source_data);
-
// When video camera is used for time lapse capture, returns true
// until enough time has passed for the next time lapse frame. When
// the frame needs to be encoded, it returns false and also modifies
@@ -217,22 +157,6 @@
// Wrapper to enter threadTimeLapseEntry()
static void *ThreadTimeLapseWrapper(void *me);
- // Runs a loop which sleeps until a still picture is required
- // and then calls mCamera->takePicture() to take the still picture.
- // Used only in the case mUseStillCameraForTimeLapse = true.
- void threadTimeLapseEntry();
-
- // Wrapper to enter threadStartPreview()
- static void *ThreadStartPreviewWrapper(void *me);
-
- // Starts the camera's preview.
- void threadStartPreview();
-
- // Starts thread ThreadStartPreviewWrapper() for restarting preview.
- // Needs to be done in a thread so that dataCallback() which calls this function
- // can return, and the camera can know that takePicture() is done.
- void restartPreview();
-
// Creates a copy of source_data into a new memory of final type MemoryBase.
sp<IMemory> createIMemoryCopy(const sp<IMemory> &source_data);
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 @@
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 @@
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 @@
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/MetadataBufferType.h b/include/media/stagefright/MetadataBufferType.h
index 52a3257..4eaf8ac 100644
--- a/include/media/stagefright/MetadataBufferType.h
+++ b/include/media/stagefright/MetadataBufferType.h
@@ -69,6 +69,16 @@
* kMetadataBufferTypeGrallocSource is used to indicate that
* the payload of the metadata buffers can be interpreted as
* a buffer_handle_t.
+ * So in this case,the metadata that the encoder receives
+ * will have a byte stream that consists of two parts:
+ * 1. First, there is an integer indicating that it is a GRAlloc
+ * source (kMetadataBufferTypeGrallocSource)
+ * 2. This is followed by the buffer_handle_t that is a handle to the
+ * GRalloc buffer. The encoder needs to interpret this GRalloc handle
+ * and encode the frames.
+ * --------------------------------------------------------------
+ * | kMetadataBufferTypeGrallocSource | sizeof(buffer_handle_t) |
+ * --------------------------------------------------------------
*/
kMetadataBufferTypeGrallocSource = 1,
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 @@
void restorePatchedDataPointer(BufferInfo *info);
status_t applyRotation();
+ status_t waitForBufferFilled_l();
int64_t retrieveDecodingTimeUs(bool isCodecSpecific);
@@ -348,6 +349,8 @@
// 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 @@
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..fab258c
--- /dev/null
+++ b/include/media/stagefright/SurfaceMediaSource.h
@@ -0,0 +1,354 @@
+/*
+ * 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();
+
+ // Pass the metadata over to the buffer, call when you have the lock
+ void passMetadataBufferLocked(MediaBuffer **buffer);
+ bool checkBufferMatchesSlot(int slot, MediaBuffer *buffer);
+
+ // 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 read()
+ //
+ // 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/media/stagefright/openmax/OMX_IVCommon.h b/include/media/stagefright/openmax/OMX_IVCommon.h
index 7ed072b..97170d7 100644
--- a/include/media/stagefright/openmax/OMX_IVCommon.h
+++ b/include/media/stagefright/openmax/OMX_IVCommon.h
@@ -16,29 +16,29 @@
* -------------------------------------------------------------------
*/
/**
- * Copyright (c) 2008 The Khronos Group Inc.
- *
+ * Copyright (c) 2008 The Khronos Group Inc.
+ *
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject
- * to the following conditions:
+ * to the following conditions:
* The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
+ * in all copies or substantial portions of the Software.
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
-/**
+/**
* @file OMX_IVCommon.h - OpenMax IL version 1.1.2
* The structures needed by Video and Image components to exchange
* parameters and configuration data with the components.
@@ -53,7 +53,7 @@
/**
* Each OMX header must include all required header files to allow the header
* to compile without errors. The includes below are required for this header
- * file to compile successfully
+ * file to compile successfully
*/
#include <OMX_Core.h>
@@ -64,8 +64,8 @@
*/
-/**
- * Enumeration defining possible uncompressed image/video formats.
+/**
+ * Enumeration defining possible uncompressed image/video formats.
*
* ENUMS:
* Unused : Placeholder value when format is N/A
@@ -113,7 +113,7 @@
OMX_COLOR_Format16bitBGR565,
OMX_COLOR_Format18bitRGB666,
OMX_COLOR_Format18bitARGB1665,
- OMX_COLOR_Format19bitARGB1666,
+ OMX_COLOR_Format19bitARGB1666,
OMX_COLOR_Format24bitRGB888,
OMX_COLOR_Format24bitBGR888,
OMX_COLOR_Format24bitARGB1887,
@@ -136,55 +136,62 @@
OMX_COLOR_FormatRawBayer8bit,
OMX_COLOR_FormatRawBayer10bit,
OMX_COLOR_FormatRawBayer8bitcompressed,
- OMX_COLOR_FormatL2,
- OMX_COLOR_FormatL4,
- OMX_COLOR_FormatL8,
- OMX_COLOR_FormatL16,
- OMX_COLOR_FormatL24,
+ OMX_COLOR_FormatL2,
+ OMX_COLOR_FormatL4,
+ OMX_COLOR_FormatL8,
+ OMX_COLOR_FormatL16,
+ OMX_COLOR_FormatL24,
OMX_COLOR_FormatL32,
OMX_COLOR_FormatYUV420PackedSemiPlanar,
OMX_COLOR_FormatYUV422PackedSemiPlanar,
OMX_COLOR_Format18BitBGR666,
OMX_COLOR_Format24BitARGB6666,
OMX_COLOR_Format24BitABGR6666,
- OMX_COLOR_FormatKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_COLOR_FormatKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_COLOR_FormatVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
+ /**<Reserved android opaque colorformat. Tells the encoder that
+ * the actual colorformat will be relayed by the
+ * Gralloc Buffers.
+ * FIXME: In the process of reserving some enum values for
+ * Android-specific OMX IL colorformats. Change this enum to
+ * an acceptable range once that is done.*/
+ OMX_COLOR_FormatAndroidOpaque = 0x7F000001,
OMX_TI_COLOR_FormatYUV420PackedSemiPlanar = 0x7F000100,
OMX_QCOM_COLOR_FormatYVU420SemiPlanar = 0x7FA30C00,
OMX_COLOR_FormatMax = 0x7FFFFFFF
} OMX_COLOR_FORMATTYPE;
-/**
+/**
* Defines the matrix for conversion from RGB to YUV or vice versa.
- * iColorMatrix should be initialized with the fixed point values
+ * iColorMatrix should be initialized with the fixed point values
* used in converting between formats.
*/
typedef struct OMX_CONFIG_COLORCONVERSIONTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
- OMX_VERSIONTYPE nVersion; /**< OMX specification version info */
+ OMX_VERSIONTYPE nVersion; /**< OMX specification version info */
OMX_U32 nPortIndex; /**< Port that this struct applies to */
OMX_S32 xColorMatrix[3][3]; /**< Stored in signed Q16 format */
OMX_S32 xColorOffset[4]; /**< Stored in signed Q16 format */
}OMX_CONFIG_COLORCONVERSIONTYPE;
-/**
- * Structure defining percent to scale each frame dimension. For example:
+/**
+ * Structure defining percent to scale each frame dimension. For example:
* To make the width 50% larger, use fWidth = 1.5 and to make the width
* 1/2 the original size, use fWidth = 0.5
*/
typedef struct OMX_CONFIG_SCALEFACTORTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
- OMX_VERSIONTYPE nVersion; /**< OMX specification version info */
+ OMX_VERSIONTYPE nVersion; /**< OMX specification version info */
OMX_U32 nPortIndex; /**< Port that this struct applies to */
OMX_S32 xWidth; /**< Fixed point value stored as Q16 */
OMX_S32 xHeight; /**< Fixed point value stored as Q16 */
}OMX_CONFIG_SCALEFACTORTYPE;
-/**
- * Enumeration of possible image filter types
+/**
+ * Enumeration of possible image filter types
*/
typedef enum OMX_IMAGEFILTERTYPE {
OMX_ImageFilterNone,
@@ -195,23 +202,23 @@
OMX_ImageFilterOilPaint,
OMX_ImageFilterHatch,
OMX_ImageFilterGpen,
- OMX_ImageFilterAntialias,
- OMX_ImageFilterDeRing,
+ OMX_ImageFilterAntialias,
+ OMX_ImageFilterDeRing,
OMX_ImageFilterSolarize,
- OMX_ImageFilterKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_ImageFilterKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_ImageFilterVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_ImageFilterMax = 0x7FFFFFFF
} OMX_IMAGEFILTERTYPE;
-/**
- * Image filter configuration
+/**
+ * Image filter configuration
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
- * eImageFilter : Image filter type enumeration
+ * nPortIndex : Port that this structure applies to
+ * eImageFilter : Image filter type enumeration
*/
typedef struct OMX_CONFIG_IMAGEFILTERTYPE {
OMX_U32 nSize;
@@ -221,22 +228,22 @@
} OMX_CONFIG_IMAGEFILTERTYPE;
-/**
- * Customized U and V for color enhancement
+/**
+ * Customized U and V for color enhancement
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
+ * nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* bColorEnhancement : Enable/disable color enhancement
- * nCustomizedU : Practical values: 16-240, range: 0-255, value set for
+ * nCustomizedU : Practical values: 16-240, range: 0-255, value set for
* U component
- * nCustomizedV : Practical values: 16-240, range: 0-255, value set for
+ * nCustomizedV : Practical values: 16-240, range: 0-255, value set for
* V component
*/
typedef struct OMX_CONFIG_COLORENHANCEMENTTYPE {
OMX_U32 nSize;
- OMX_VERSIONTYPE nVersion;
+ OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_BOOL bColorEnhancement;
OMX_U8 nCustomizedU;
@@ -244,12 +251,12 @@
} OMX_CONFIG_COLORENHANCEMENTTYPE;
-/**
- * Define color key and color key mask
+/**
+ * Define color key and color key mask
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
+ * nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nARGBColor : 32bit Alpha, Red, Green, Blue Color
* nARGBMask : 32bit Mask for Alpha, Red, Green, Blue channels
@@ -263,12 +270,12 @@
} OMX_CONFIG_COLORKEYTYPE;
-/**
- * List of color blend types for pre/post processing
+/**
+ * List of color blend types for pre/post processing
*
* ENUMS:
* None : No color blending present
- * AlphaConstant : Function is (alpha_constant * src) +
+ * AlphaConstant : Function is (alpha_constant * src) +
* (1 - alpha_constant) * dst)
* AlphaPerPixel : Function is (alpha * src) + (1 - alpha) * dst)
* Alternate : Function is alternating pixels from src and dst
@@ -284,21 +291,21 @@
OMX_ColorBlendAnd,
OMX_ColorBlendOr,
OMX_ColorBlendInvert,
- OMX_ColorBlendKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_ColorBlendKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_ColorBlendVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_ColorBlendMax = 0x7FFFFFFF
} OMX_COLORBLENDTYPE;
-/**
- * Color blend configuration
+/**
+ * Color blend configuration
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
+ * nSize : Size of the structure in bytes
+ * nVersion : OMX specification version information
+ * nPortIndex : Port that this structure applies to
* nRGBAlphaConstant : Constant global alpha values when global alpha is used
- * eColorBlend : Color blend type enumeration
+ * eColorBlend : Color blend type enumeration
*/
typedef struct OMX_CONFIG_COLORBLENDTYPE {
OMX_U32 nSize;
@@ -309,15 +316,15 @@
} OMX_CONFIG_COLORBLENDTYPE;
-/**
+/**
* Hold frame dimension
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
- * nWidth : Frame width in pixels
- * nHeight : Frame height in pixels
+ * nPortIndex : Port that this structure applies to
+ * nWidth : Frame width in pixels
+ * nHeight : Frame height in pixels
*/
typedef struct OMX_FRAMESIZETYPE {
OMX_U32 nSize;
@@ -329,69 +336,69 @@
/**
- * Rotation configuration
+ * Rotation configuration
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
- * nRotation : +/- integer rotation value
+ * nRotation : +/- integer rotation value
*/
typedef struct OMX_CONFIG_ROTATIONTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
- OMX_S32 nRotation;
+ OMX_S32 nRotation;
} OMX_CONFIG_ROTATIONTYPE;
-/**
- * Possible mirroring directions for pre/post processing
+/**
+ * Possible mirroring directions for pre/post processing
*
* ENUMS:
- * None : No mirroring
- * Vertical : Vertical mirroring, flip on X axis
- * Horizontal : Horizontal mirroring, flip on Y axis
+ * None : No mirroring
+ * Vertical : Vertical mirroring, flip on X axis
+ * Horizontal : Horizontal mirroring, flip on Y axis
* Both : Both vertical and horizontal mirroring
*/
typedef enum OMX_MIRRORTYPE {
OMX_MirrorNone = 0,
OMX_MirrorVertical,
OMX_MirrorHorizontal,
- OMX_MirrorBoth,
- OMX_MirrorKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_MirrorBoth,
+ OMX_MirrorKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_MirrorVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
- OMX_MirrorMax = 0x7FFFFFFF
+ OMX_MirrorMax = 0x7FFFFFFF
} OMX_MIRRORTYPE;
-/**
- * Mirroring configuration
+/**
+ * Mirroring configuration
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
- * eMirror : Mirror type enumeration
+ * nPortIndex : Port that this structure applies to
+ * eMirror : Mirror type enumeration
*/
typedef struct OMX_CONFIG_MIRRORTYPE {
OMX_U32 nSize;
- OMX_VERSIONTYPE nVersion;
+ OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex;
OMX_MIRRORTYPE eMirror;
} OMX_CONFIG_MIRRORTYPE;
-/**
- * Position information only
+/**
+ * Position information only
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
- * nX : X coordinate for the point
- * nY : Y coordinate for the point
- */
+ * nX : X coordinate for the point
+ * nY : Y coordinate for the point
+ */
typedef struct OMX_CONFIG_POINTTYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
@@ -401,37 +408,37 @@
} OMX_CONFIG_POINTTYPE;
-/**
- * Frame size plus position
+/**
+ * Frame size plus position
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
+ * nSize : Size of the structure in bytes
+ * nVersion : OMX specification version information
+ * nPortIndex : Port that this structure applies to
* nLeft : X Coordinate of the top left corner of the rectangle
* nTop : Y Coordinate of the top left corner of the rectangle
- * nWidth : Width of the rectangle
- * nHeight : Height of the rectangle
+ * nWidth : Width of the rectangle
+ * nHeight : Height of the rectangle
*/
typedef struct OMX_CONFIG_RECTTYPE {
OMX_U32 nSize;
- OMX_VERSIONTYPE nVersion;
- OMX_U32 nPortIndex;
- OMX_S32 nLeft;
+ OMX_VERSIONTYPE nVersion;
+ OMX_U32 nPortIndex;
+ OMX_S32 nLeft;
OMX_S32 nTop;
OMX_U32 nWidth;
OMX_U32 nHeight;
} OMX_CONFIG_RECTTYPE;
-/**
- * Deblocking state; it is required to be set up before starting the codec
+/**
+ * Deblocking state; it is required to be set up before starting the codec
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
+ * nSize : Size of the structure in bytes
+ * nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
- * bDeblocking : Enable/disable deblocking mode
+ * bDeblocking : Enable/disable deblocking mode
*/
typedef struct OMX_PARAM_DEBLOCKINGTYPE {
OMX_U32 nSize;
@@ -441,13 +448,13 @@
} OMX_PARAM_DEBLOCKINGTYPE;
-/**
- * Stabilization state
+/**
+ * Stabilization state
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
+ * nSize : Size of the structure in bytes
+ * nVersion : OMX specification version information
+ * nPortIndex : Port that this structure applies to
* bStab : Enable/disable frame stabilization state
*/
typedef struct OMX_CONFIG_FRAMESTABTYPE {
@@ -458,8 +465,8 @@
} OMX_CONFIG_FRAMESTABTYPE;
-/**
- * White Balance control type
+/**
+ * White Balance control type
*
* STRUCT MEMBERS:
* SunLight : Referenced in JSR-234
@@ -476,20 +483,20 @@
OMX_WhiteBalControlIncandescent,
OMX_WhiteBalControlFlash,
OMX_WhiteBalControlHorizon,
- OMX_WhiteBalControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_WhiteBalControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_WhiteBalControlVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_WhiteBalControlMax = 0x7FFFFFFF
} OMX_WHITEBALCONTROLTYPE;
-/**
- * White Balance control configuration
+/**
+ * White Balance control configuration
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
- * eWhiteBalControl : White balance enumeration
+ * nPortIndex : Port that this structure applies to
+ * eWhiteBalControl : White balance enumeration
*/
typedef struct OMX_CONFIG_WHITEBALCONTROLTYPE {
OMX_U32 nSize;
@@ -499,8 +506,8 @@
} OMX_CONFIG_WHITEBALCONTROLTYPE;
-/**
- * Exposure control type
+/**
+ * Exposure control type
*/
typedef enum OMX_EXPOSURECONTROLTYPE {
OMX_ExposureControlOff = 0,
@@ -513,20 +520,20 @@
OMX_ExposureControlBeach,
OMX_ExposureControlLargeAperture,
OMX_ExposureControlSmallApperture,
- OMX_ExposureControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_ExposureControlKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_ExposureControlVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_ExposureControlMax = 0x7FFFFFFF
} OMX_EXPOSURECONTROLTYPE;
-/**
- * White Balance control configuration
+/**
+ * White Balance control configuration
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
- * eExposureControl : Exposure control enumeration
+ * nPortIndex : Port that this structure applies to
+ * eExposureControl : Exposure control enumeration
*/
typedef struct OMX_CONFIG_EXPOSURECONTROLTYPE {
OMX_U32 nSize;
@@ -536,16 +543,16 @@
} OMX_CONFIG_EXPOSURECONTROLTYPE;
-/**
- * Defines sensor supported mode.
+/**
+ * Defines sensor supported mode.
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
- * nFrameRate : Single shot mode is indicated by a 0
+ * nPortIndex : Port that this structure applies to
+ * nFrameRate : Single shot mode is indicated by a 0
* bOneShot : Enable for single shot, disable for streaming
- * sFrameSize : Framesize
+ * sFrameSize : Framesize
*/
typedef struct OMX_PARAM_SENSORMODETYPE {
OMX_U32 nSize;
@@ -557,13 +564,13 @@
} OMX_PARAM_SENSORMODETYPE;
-/**
- * Defines contrast level
+/**
+ * Defines contrast level
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
+ * nSize : Size of the structure in bytes
+ * nVersion : OMX specification version information
+ * nPortIndex : Port that this structure applies to
* nContrast : Values allowed for contrast -100 to 100, zero means no change
*/
typedef struct OMX_CONFIG_CONTRASTTYPE {
@@ -574,14 +581,14 @@
} OMX_CONFIG_CONTRASTTYPE;
-/**
- * Defines brightness level
+/**
+ * Defines brightness level
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
- * nPortIndex : Port that this structure applies to
- * nBrightness : 0-100%
+ * nSize : Size of the structure in bytes
+ * nVersion : OMX specification version information
+ * nPortIndex : Port that this structure applies to
+ * nBrightness : 0-100%
*/
typedef struct OMX_CONFIG_BRIGHTNESSTYPE {
OMX_U32 nSize;
@@ -591,16 +598,16 @@
} OMX_CONFIG_BRIGHTNESSTYPE;
-/**
- * Defines backlight level configuration for a video sink, e.g. LCD panel
+/**
+ * Defines backlight level configuration for a video sink, e.g. LCD panel
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
+ * nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nBacklight : Values allowed for backlight 0-100%
- * nTimeout : Number of milliseconds before backlight automatically turns
- * off. A value of 0x0 disables backight timeout
+ * nTimeout : Number of milliseconds before backlight automatically turns
+ * off. A value of 0x0 disables backight timeout
*/
typedef struct OMX_CONFIG_BACKLIGHTTYPE {
OMX_U32 nSize;
@@ -611,12 +618,12 @@
} OMX_CONFIG_BACKLIGHTTYPE;
-/**
- * Defines setting for Gamma
+/**
+ * Defines setting for Gamma
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
+ * nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* nGamma : Values allowed for gamma -100 to 100, zero means no change
*/
@@ -628,14 +635,14 @@
} OMX_CONFIG_GAMMATYPE;
-/**
- * Define for setting saturation
- *
+/**
+ * Define for setting saturation
+ *
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
- * nSaturation : Values allowed for saturation -100 to 100, zero means
+ * nSaturation : Values allowed for saturation -100 to 100, zero means
* no change
*/
typedef struct OMX_CONFIG_SATURATIONTYPE {
@@ -646,14 +653,14 @@
} OMX_CONFIG_SATURATIONTYPE;
-/**
- * Define for setting Lightness
+/**
+ * Define for setting Lightness
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
- * nLightness : Values allowed for lightness -100 to 100, zero means no
+ * nLightness : Values allowed for lightness -100 to 100, zero means no
* change
*/
typedef struct OMX_CONFIG_LIGHTNESSTYPE {
@@ -664,17 +671,17 @@
} OMX_CONFIG_LIGHTNESSTYPE;
-/**
- * Plane blend configuration
+/**
+ * Plane blend configuration
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
+ * nSize : Size of the structure in bytes
* nVersion : OMX specification version information
* nPortIndex : Index of input port associated with the plane.
- * nDepth : Depth of the plane in relation to the screen. Higher
- * numbered depths are "behind" lower number depths.
+ * nDepth : Depth of the plane in relation to the screen. Higher
+ * numbered depths are "behind" lower number depths.
* This number defaults to the Port Index number.
- * nAlpha : Transparency blending component for the entire plane.
+ * nAlpha : Transparency blending component for the entire plane.
* See blending modes for more detail.
*/
typedef struct OMX_CONFIG_PLANEBLENDTYPE {
@@ -686,17 +693,17 @@
} OMX_CONFIG_PLANEBLENDTYPE;
-/**
+/**
* Define interlace type
*
* STRUCT MEMBERS:
- * nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
+ * nSize : Size of the structure in bytes
+ * nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
- * bEnable : Enable control variable for this functionality
+ * bEnable : Enable control variable for this functionality
* (see below)
- * nInterleavePortIndex : Index of input or output port associated with
- * the interleaved plane.
+ * nInterleavePortIndex : Index of input or output port associated with
+ * the interleaved plane.
* pPlanarPortIndexes[4] : Index of input or output planar ports.
*/
typedef struct OMX_PARAM_INTERLEAVETYPE {
@@ -708,8 +715,8 @@
} OMX_PARAM_INTERLEAVETYPE;
-/**
- * Defines the picture effect used for an input picture
+/**
+ * Defines the picture effect used for an input picture
*/
typedef enum OMX_TRANSITIONEFFECTTYPE {
OMX_EffectNone,
@@ -719,18 +726,18 @@
OMX_EffectDissolve,
OMX_EffectWipe,
OMX_EffectUnspecifiedMixOfTwoScenes,
- OMX_EffectKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_EffectKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_EffectVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_EffectMax = 0x7FFFFFFF
} OMX_TRANSITIONEFFECTTYPE;
-/**
- * Structure used to configure current transition effect
+/**
+ * Structure used to configure current transition effect
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
- * nVersion : OMX specification version information
+ * nVersion : OMX specification version information
* nPortIndex : Port that this structure applies to
* eEffect : Effect to enable
*/
@@ -742,43 +749,43 @@
} OMX_CONFIG_TRANSITIONEFFECTTYPE;
-/**
- * Defines possible data unit types for encoded video data. The data unit
+/**
+ * Defines possible data unit types for encoded video data. The data unit
* types are used both for encoded video input for playback as well as
- * encoded video output from recording.
+ * encoded video output from recording.
*/
typedef enum OMX_DATAUNITTYPE {
OMX_DataUnitCodedPicture,
OMX_DataUnitVideoSegment,
OMX_DataUnitSeveralSegments,
OMX_DataUnitArbitraryStreamSection,
- OMX_DataUnitKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_DataUnitKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_DataUnitVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_DataUnitMax = 0x7FFFFFFF
} OMX_DATAUNITTYPE;
-/**
- * Defines possible encapsulation types for coded video data unit. The
- * encapsulation information is used both for encoded video input for
- * playback as well as encoded video output from recording.
+/**
+ * Defines possible encapsulation types for coded video data unit. The
+ * encapsulation information is used both for encoded video input for
+ * playback as well as encoded video output from recording.
*/
typedef enum OMX_DATAUNITENCAPSULATIONTYPE {
OMX_DataEncapsulationElementaryStream,
OMX_DataEncapsulationGenericPayload,
OMX_DataEncapsulationRtpPayload,
- OMX_DataEncapsulationKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_DataEncapsulationKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_DataEncapsulationVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_DataEncapsulationMax = 0x7FFFFFFF
} OMX_DATAUNITENCAPSULATIONTYPE;
-/**
- * Structure used to configure the type of being decoded/encoded
+/**
+ * Structure used to configure the type of being decoded/encoded
*/
typedef struct OMX_PARAM_DATAUNITTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
- OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
+ OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< Port that this structure applies to */
OMX_DATAUNITTYPE eUnitType;
OMX_DATAUNITENCAPSULATIONTYPE eEncapsulationType;
@@ -786,25 +793,25 @@
/**
- * Defines dither types
+ * Defines dither types
*/
typedef enum OMX_DITHERTYPE {
OMX_DitherNone,
OMX_DitherOrdered,
OMX_DitherErrorDiffusion,
OMX_DitherOther,
- OMX_DitherKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_DitherKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_DitherVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_DitherMax = 0x7FFFFFFF
} OMX_DITHERTYPE;
-/**
- * Structure used to configure current type of dithering
+/**
+ * Structure used to configure current type of dithering
*/
typedef struct OMX_CONFIG_DITHERTYPE {
OMX_U32 nSize; /**< Size of the structure in bytes */
- OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
+ OMX_VERSIONTYPE nVersion; /**< OMX specification version information */
OMX_U32 nPortIndex; /**< Port that this structure applies to */
OMX_DITHERTYPE eDither; /**< Type of dithering to use */
} OMX_CONFIG_DITHERTYPE;
@@ -813,28 +820,28 @@
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
OMX_U32 nPortIndex; /**< Port that this structure applies to */
- OMX_BOOL bContinuous; /**< If true then ignore frame rate and emit capture
+ OMX_BOOL bContinuous; /**< If true then ignore frame rate and emit capture
* data as fast as possible (otherwise obey port's frame rate). */
- OMX_BOOL bFrameLimited; /**< If true then terminate capture after the port emits the
- * specified number of frames (otherwise the port does not
- * terminate the capture until instructed to do so by the client).
- * Even if set, the client may manually terminate the capture prior
+ OMX_BOOL bFrameLimited; /**< If true then terminate capture after the port emits the
+ * specified number of frames (otherwise the port does not
+ * terminate the capture until instructed to do so by the client).
+ * Even if set, the client may manually terminate the capture prior
* to reaching the limit. */
OMX_U32 nFrameLimit; /**< Limit on number of frames emitted during a capture (only
* valid if bFrameLimited is set). */
} OMX_CONFIG_CAPTUREMODETYPE;
typedef enum OMX_METERINGTYPE {
-
+
OMX_MeteringModeAverage, /**< Center-weighted average metering. */
OMX_MeteringModeSpot, /**< Spot (partial) metering. */
OMX_MeteringModeMatrix, /**< Matrix or evaluative metering. */
-
- OMX_MeteringKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+
+ OMX_MeteringKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_MeteringVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_EVModeMax = 0x7fffffff
} OMX_METERINGTYPE;
-
+
typedef struct OMX_CONFIG_EXPOSUREVALUETYPE {
OMX_U32 nSize;
OMX_VERSIONTYPE nVersion;
@@ -843,14 +850,14 @@
OMX_S32 xEVCompensation; /**< Fixed point value stored as Q16 */
OMX_U32 nApertureFNumber; /**< e.g. nApertureFNumber = 2 implies "f/2" - Q16 format */
OMX_BOOL bAutoAperture; /**< Whether aperture number is defined automatically */
- OMX_U32 nShutterSpeedMsec; /**< Shutterspeed in milliseconds */
- OMX_BOOL bAutoShutterSpeed; /**< Whether shutter speed is defined automatically */
+ OMX_U32 nShutterSpeedMsec; /**< Shutterspeed in milliseconds */
+ OMX_BOOL bAutoShutterSpeed; /**< Whether shutter speed is defined automatically */
OMX_U32 nSensitivity; /**< e.g. nSensitivity = 100 implies "ISO 100" */
OMX_BOOL bAutoSensitivity; /**< Whether sensitivity is defined automatically */
} OMX_CONFIG_EXPOSUREVALUETYPE;
-/**
- * Focus region configuration
+/**
+ * Focus region configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
@@ -881,8 +888,8 @@
OMX_BOOL bBottomRight;
} OMX_CONFIG_FOCUSREGIONTYPE;
-/**
- * Focus Status type
+/**
+ * Focus Status type
*/
typedef enum OMX_FOCUSSTATUSTYPE {
OMX_FocusStatusOff = 0,
@@ -890,13 +897,13 @@
OMX_FocusStatusReached,
OMX_FocusStatusUnableToReach,
OMX_FocusStatusLost,
- OMX_FocusStatusKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
+ OMX_FocusStatusKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
OMX_FocusStatusVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
OMX_FocusStatusMax = 0x7FFFFFFF
} OMX_FOCUSSTATUSTYPE;
-/**
- * Focus status configuration
+/**
+ * Focus status configuration
*
* STRUCT MEMBERS:
* nSize : Size of the structure in bytes
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 @@
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 @@
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 @@
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 @@
INDEX_GREEN = 2,
INDEX_BLUE = 3
};
-
+
enum { // components
ALPHA = 1,
RGB = 2,
@@ -98,10 +98,10 @@
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 @@
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 @@
CANCEL_BUFFER,
SET_CROP,
SET_TRANSFORM,
- GET_ALLOCATOR,
QUERY,
SET_SYNCHRONOUS_MODE,
CONNECT,
@@ -55,18 +54,18 @@
{
}
- 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 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
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 @@
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::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 @@
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 @@
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 @@
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 @@
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) {
- LOGE("requestBuffer: slot index out of range [0, %d]: %d",
- mBufferCount, buf);
- return 0;
+ if (mAbandoned) {
+ LOGE("requestBuffer: SurfaceTexture has been abandoned!");
+ return NO_INIT;
}
- mSlots[buf].mRequestBufferCalled = true;
- return mSlots[buf].mGraphicBuffer;
+ 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 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 @@
// 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::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 @@
{ // 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 @@
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 @@
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::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::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::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 @@
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 @@
// Update the SurfaceTexture state.
mCurrentTexture = buf;
- mCurrentTextureTarget = target;
mCurrentTextureBuf = mSlots[buf].mGraphicBuffer;
mCurrentCrop = mSlots[buf].mCrop;
mCurrentTransform = mSlots[buf].mTransform;
@@ -636,7 +686,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
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 @@
mQueryWidth = 0;
mQueryHeight = 0;
mQueryFormat = 0;
+ mDefaultWidth = 0;
+ mDefaultHeight = 0;
+ mTransformHint = 0;
mConnectedToCpu = false;
}
@@ -62,9 +65,6 @@
const sp<ISurfaceTexture>& surfaceTexture)
{
mSurfaceTexture = surfaceTexture;
-
- // Get a reference to the allocator.
- mAllocator = mSurfaceTexture->getAllocator();
}
sp<ISurfaceTexture> SurfaceTextureClient::getISurfaceTexture() const {
@@ -148,10 +148,11 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
eglSwapBuffers(mEglDisplay, stcEglSurface);
+ eglDestroySurface(mEglDisplay, stcEglSurface);
+
// Do the consumer side of things
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
mEglContext));
@@ -1018,6 +1014,83 @@
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 @@
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 @@
// 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 @@
// 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, RepeatedUpdateTexImageAfterFrameFinishedWorks) {
+TEST_F(SurfaceTextureGLToGLTest, RepeatedUpdateTexImageAfterFrameFinishedCompletes) {
enum { NUM_ITERATIONS = 1024 };
class PT : public ProducerThread {
@@ -1297,4 +1370,70 @@
}
}
+// 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/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 8b1caeee..886c05c 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -883,7 +883,6 @@
///////////////////////////////////////////////////////////////////////////////
DisplayListRenderer::DisplayListRenderer(): mWriter(MIN_WRITER_SIZE) {
- mDisplayList = NULL;
}
DisplayListRenderer::~DisplayListRenderer() {
@@ -923,13 +922,13 @@
// Operations
///////////////////////////////////////////////////////////////////////////////
-DisplayList* DisplayListRenderer::getDisplayList() {
- if (mDisplayList == NULL) {
- mDisplayList = new DisplayList(*this);
+DisplayList* DisplayListRenderer::getDisplayList(DisplayList* displayList) {
+ if (!displayList) {
+ displayList = new DisplayList(*this);
} else {
- mDisplayList->initFromDisplayListRenderer(*this, true);
+ displayList->initFromDisplayListRenderer(*this, true);
}
- return mDisplayList;
+ return displayList;
}
void DisplayListRenderer::setViewport(int width, int height) {
diff --git a/libs/hwui/DisplayListRenderer.h b/libs/hwui/DisplayListRenderer.h
index b83259f..8157631 100644
--- a/libs/hwui/DisplayListRenderer.h
+++ b/libs/hwui/DisplayListRenderer.h
@@ -217,7 +217,7 @@
DisplayListRenderer();
~DisplayListRenderer();
- DisplayList* getDisplayList();
+ DisplayList* getDisplayList(DisplayList* displayList);
void setViewport(int width, int height);
void prepareDirty(float left, float top, float right, float bottom, bool opaque);
@@ -474,8 +474,6 @@
SkWriter32 mWriter;
- DisplayList *mDisplayList;
-
int mRestoreSaveCount;
friend class DisplayList;
diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp
index 4a40a63..996acd5 100644
--- a/libs/hwui/GradientCache.cpp
+++ b/libs/hwui/GradientCache.cpp
@@ -181,11 +181,8 @@
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bitmap->rowBytesAsPixels(), texture->height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, bitmap->getPixels());
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ texture->setFilter(GL_LINEAR, GL_LINEAR);
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
}
}; // namespace uirenderer
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h
index 3c2d80d..0c536b0 100644
--- a/libs/hwui/Layer.h
+++ b/libs/hwui/Layer.h
@@ -51,8 +51,6 @@
texture.width = layerWidth;
texture.height = layerHeight;
colorFilter = NULL;
- firstFilter = true;
- firstWrap = true;
}
~Layer() {
@@ -150,27 +148,11 @@
}
void setWrap(GLenum wrapS, GLenum wrapT, bool bindTexture = false, bool force = false) {
- if (firstWrap || force || wrapS != texture.wrapS || wrapT != texture.wrapT) {
- firstWrap = true;
- texture.setWrap(wrapS, wrapT);
- if (bindTexture) {
- glBindTexture(renderTarget, texture.id);
- }
- glTexParameteri(renderTarget, GL_TEXTURE_WRAP_S, wrapS);
- glTexParameteri(renderTarget, GL_TEXTURE_WRAP_T, wrapT);
- }
+ texture.setWrap(wrapS, wrapT, bindTexture, force, renderTarget);
}
void setFilter(GLenum min, GLenum mag, bool bindTexture = false, bool force = false) {
- if (firstFilter || force || min != texture.minFilter || mag != texture.magFilter) {
- firstFilter = false;
- texture.setFilter(min, mag);
- if (bindTexture) {
- glBindTexture(renderTarget, texture.id);
- }
- glTexParameteri(renderTarget, GL_TEXTURE_MIN_FILTER, min);
- glTexParameteri(renderTarget, GL_TEXTURE_MAG_FILTER, mag);
- }
+ texture.setFilter(min, mag,bindTexture, force, renderTarget);
}
inline bool isCacheable() {
@@ -296,8 +278,6 @@
*/
mat4 texTransform;
- bool firstFilter;
- bool firstWrap;
}; // struct Layer
}; // namespace uirenderer
diff --git a/libs/hwui/LayerCache.cpp b/libs/hwui/LayerCache.cpp
index 1a15e87..36083af 100644
--- a/libs/hwui/LayerCache.cpp
+++ b/libs/hwui/LayerCache.cpp
@@ -107,7 +107,7 @@
layer->generateTexture();
layer->bindTexture();
layer->setFilter(GL_NEAREST, GL_NEAREST);
- layer->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+ layer->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, false);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
#if DEBUG_LAYERS
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 85a9762..e67abbd 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1293,16 +1293,16 @@
SkXfermode::Mode mode;
getAlphaAndMode(paint, &alpha, &mode);
- setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
-
float x = left;
float y = top;
+ GLenum filter = GL_LINEAR;
bool ignoreTransform = false;
if (mSnapshot->transform->isPureTranslate()) {
x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
ignoreTransform = true;
+ filter = GL_NEAREST;
}
setupDraw();
@@ -1315,7 +1315,11 @@
setupDrawBlending(true, mode);
setupDrawProgram();
setupDrawModelView(x, y, x + texture->width, y + texture->height, ignoreTransform);
+
setupDrawTexture(texture->id);
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+ texture->setFilter(filter, filter);
+
setupDrawPureColorUniforms();
setupDrawColorFilterUniforms();
setupDrawShaderUniforms();
@@ -1379,7 +1383,9 @@
Texture* texture = mCaches.textureCache.get(bitmap);
if (!texture) return;
const AutoTexture autoCleanup(texture);
- setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, true);
+ texture->setFilter(GL_LINEAR, GL_LINEAR, true);
int alpha;
SkXfermode::Mode mode;
@@ -1462,7 +1468,7 @@
Texture* texture = mCaches.textureCache.get(bitmap);
if (!texture) return;
const AutoTexture autoCleanup(texture);
- setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, true);
const float width = texture->width;
const float height = texture->height;
@@ -1483,11 +1489,13 @@
const float x = (int) floorf(dstLeft + mSnapshot->transform->getTranslateX() + 0.5f);
const float y = (int) floorf(dstTop + mSnapshot->transform->getTranslateY() + 0.5f);
+ texture->setFilter(GL_NEAREST, GL_NEAREST, true);
drawTextureMesh(x, y, x + (dstRight - dstLeft), y + (dstBottom - dstTop),
texture->id, alpha / 255.0f, mode, texture->blend,
&mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
GL_TRIANGLE_STRIP, gMeshCount, false, true);
} else {
+ texture->setFilter(GL_LINEAR, GL_LINEAR, true);
drawTextureMesh(dstLeft, dstTop, dstRight, dstBottom, texture->id, alpha / 255.0f,
mode, texture->blend, &mMeshVertices[0].position[0], &mMeshVertices[0].texture[0],
GL_TRIANGLE_STRIP, gMeshCount);
@@ -1507,7 +1515,8 @@
Texture* texture = mCaches.textureCache.get(bitmap);
if (!texture) return;
const AutoTexture autoCleanup(texture);
- setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, true);
+ texture->setFilter(GL_LINEAR, GL_LINEAR, true);
int alpha;
SkXfermode::Mode mode;
@@ -2411,16 +2420,18 @@
SkXfermode::Mode mode;
getAlphaAndMode(paint, &alpha, &mode);
- setTextureWrapModes(texture, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, true);
if (mSnapshot->transform->isPureTranslate()) {
const float x = (int) floorf(left + mSnapshot->transform->getTranslateX() + 0.5f);
const float y = (int) floorf(top + mSnapshot->transform->getTranslateY() + 0.5f);
+ texture->setFilter(GL_NEAREST, GL_NEAREST, true);
drawTextureMesh(x, y, x + texture->width, y + texture->height, texture->id,
alpha / 255.0f, mode, texture->blend, (GLvoid*) NULL,
(GLvoid*) gMeshTextureOffset, GL_TRIANGLE_STRIP, gMeshCount, false, true);
} else {
+ texture->setFilter(GL_LINEAR, GL_LINEAR, true);
drawTextureMesh(left, top, right, bottom, texture->id, alpha / 255.0f, mode,
texture->blend, (GLvoid*) NULL, (GLvoid*) gMeshTextureOffset,
GL_TRIANGLE_STRIP, gMeshCount);
@@ -2550,22 +2561,5 @@
return resultMode;
}
-void OpenGLRenderer::setTextureWrapModes(Texture* texture, GLenum wrapS, GLenum wrapT) {
- bool bound = false;
- if (wrapS != texture->wrapS) {
- glBindTexture(GL_TEXTURE_2D, texture->id);
- bound = true;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
- texture->wrapS = wrapS;
- }
- if (wrapT != texture->wrapT) {
- if (!bound) {
- glBindTexture(GL_TEXTURE_2D, texture->id);
- }
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
- texture->wrapT = wrapT;
- }
-}
-
}; // namespace uirenderer
}; // namespace android
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 0a3d5090..fa893f0 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -464,12 +464,6 @@
}
/**
- * Sets the wrap modes for the specified texture. The wrap modes are modified
- * only when needed.
- */
- inline void setTextureWrapModes(Texture* texture, GLenum wrapS, GLenum wrapT);
-
- /**
* Enable or disable blending as necessary. This function sets the appropriate
* blend function based on the specified xfermode.
*/
diff --git a/libs/hwui/ShapeCache.h b/libs/hwui/ShapeCache.h
index f4d9686..33953be 100644
--- a/libs/hwui/ShapeCache.h
+++ b/libs/hwui/ShapeCache.h
@@ -624,11 +624,8 @@
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, texture->width, texture->height, 0,
GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.getPixels());
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ texture->setFilter(GL_LINEAR, GL_LINEAR);
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
}
}; // namespace uirenderer
diff --git a/libs/hwui/SkiaShader.cpp b/libs/hwui/SkiaShader.cpp
index 8878c70..1a60dca 100644
--- a/libs/hwui/SkiaShader.cpp
+++ b/libs/hwui/SkiaShader.cpp
@@ -77,14 +77,7 @@
void SkiaShader::bindTexture(Texture* texture, GLenum wrapS, GLenum wrapT) {
glBindTexture(GL_TEXTURE_2D, texture->id);
- if (wrapS != texture->wrapS) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapS);
- texture->wrapS = wrapS;
- }
- if (wrapT != texture->wrapT) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapT);
- texture->wrapT = wrapT;
- }
+ texture->setWrap(wrapS, wrapT);
}
void SkiaShader::computeScreenSpaceMatrix(mat4& screenSpace, const mat4& modelView) {
@@ -151,6 +144,9 @@
// Uniforms
bindTexture(texture, mWrapS, mWrapT);
+ GLenum filter = textureTransform.isPureTranslate() ? GL_NEAREST : GL_LINEAR;
+ texture->setFilter(filter, filter);
+
glUniform1i(program->getUniform("bitmapSampler"), textureSlot);
glUniformMatrix4fv(program->getUniform("textureTransform"), 1,
GL_FALSE, &textureTransform.data[0]);
diff --git a/libs/hwui/TextDropShadowCache.cpp b/libs/hwui/TextDropShadowCache.cpp
index 8f6f860..a3ee63b 100644
--- a/libs/hwui/TextDropShadowCache.cpp
+++ b/libs/hwui/TextDropShadowCache.cpp
@@ -137,11 +137,8 @@
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, texture->width, texture->height, 0,
GL_ALPHA, GL_UNSIGNED_BYTE, shadow.image);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ texture->setFilter(GL_LINEAR, GL_LINEAR);
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
if (size < mMaxSize) {
if (mDebugEnabled) {
diff --git a/libs/hwui/Texture.h b/libs/hwui/Texture.h
index c6ae326..48229b6 100644
--- a/libs/hwui/Texture.h
+++ b/libs/hwui/Texture.h
@@ -35,16 +35,45 @@
minFilter = GL_NEAREST;
magFilter = GL_NEAREST;
+
+ firstFilter = true;
+ firstWrap = true;
}
- void setWrap(GLenum wrapS, GLenum wrapT) {
- this->wrapS = wrapS;
- this->wrapT = wrapT;
+ void setWrap(GLenum wrapS, GLenum wrapT, bool bindTexture = false, bool force = false,
+ GLenum renderTarget = GL_TEXTURE_2D) {
+
+ if (firstWrap || force || wrapS != this->wrapS || wrapT != this->wrapT) {
+ firstWrap = true;
+
+ this->wrapS = wrapS;
+ this->wrapT = wrapT;
+
+ if (bindTexture) {
+ glBindTexture(renderTarget, id);
+ }
+
+ glTexParameteri(renderTarget, GL_TEXTURE_WRAP_S, wrapS);
+ glTexParameteri(renderTarget, GL_TEXTURE_WRAP_T, wrapT);
+ }
}
- void setFilter(GLenum min, GLenum mag) {
- minFilter = min;
- magFilter = mag;
+ void setFilter(GLenum min, GLenum mag, bool bindTexture = false, bool force = false,
+ GLenum renderTarget = GL_TEXTURE_2D) {
+
+ if (firstFilter || force || min != minFilter || mag != magFilter) {
+ firstFilter = false;
+
+ minFilter = min;
+ magFilter = mag;
+
+ if (bindTexture) {
+ glBindTexture(renderTarget, id);
+ }
+
+ glTexParameteri(renderTarget, GL_TEXTURE_MIN_FILTER, min);
+ glTexParameteri(renderTarget, GL_TEXTURE_MAG_FILTER, mag);
+ }
}
/**
@@ -87,6 +116,10 @@
*/
GLenum minFilter;
GLenum magFilter;
+
+private:
+ bool firstFilter;
+ bool firstWrap;
}; // struct Texture
class AutoTexture {
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index 3752874..f926fdd 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -219,11 +219,8 @@
break;
}
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ texture->setFilter(GL_LINEAR, GL_LINEAR);
+ texture->setWrap(GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE);
}
void TextureCache::uploadLoFiTexture(bool resize, SkBitmap* bitmap,
diff --git a/libs/rs/driver/rsdRuntimeStubs.cpp b/libs/rs/driver/rsdRuntimeStubs.cpp
index 2f9f410..d8050ac 100644
--- a/libs/rs/driver/rsdRuntimeStubs.cpp
+++ b/libs/rs/driver/rsdRuntimeStubs.cpp
@@ -365,24 +365,49 @@
return rsrGetAllocation(rsc, sc, ptr);
}
-static void SC_ForEach(Script *target,
- Allocation *in,
- Allocation *out,
- const void *usr,
- const RsScriptCall *call) {
+static void SC_ForEach_SAA(Script *target,
+ Allocation *in,
+ Allocation *out) {
+ GET_TLS();
+ rsrForEach(rsc, sc, target, in, out, NULL, 0, NULL);
+}
+
+static void SC_ForEach_SAAU(Script *target,
+ Allocation *in,
+ Allocation *out,
+ const void *usr) {
GET_TLS();
rsrForEach(rsc, sc, target, in, out, usr, 0, NULL);
}
-static void SC_ForEach2(Script *target,
- Allocation *in,
- Allocation *out,
- const void *usr,
- const RsScriptCall *call) {
+static void SC_ForEach_SAAUS(Script *target,
+ Allocation *in,
+ Allocation *out,
+ const void *usr,
+ const RsScriptCall *call) {
GET_TLS();
rsrForEach(rsc, sc, target, in, out, usr, 0, call);
}
+static void SC_ForEach_SAAUL(Script *target,
+ Allocation *in,
+ Allocation *out,
+ const void *usr,
+ uint32_t usrLen) {
+ GET_TLS();
+ rsrForEach(rsc, sc, target, in, out, usr, usrLen, NULL);
+}
+
+static void SC_ForEach_SAAULS(Script *target,
+ Allocation *in,
+ Allocation *out,
+ const void *usr,
+ uint32_t usrLen,
+ const RsScriptCall *call) {
+ GET_TLS();
+ rsrForEach(rsc, sc, target, in, out, usr, usrLen, call);
+}
+
//////////////////////////////////////////////////////////////////////////////
@@ -648,8 +673,11 @@
{ "_Z19rsgClearDepthTargetv", (void *)&SC_ClearFrameBufferObjectDepthTarget, false },
{ "_Z24rsgClearAllRenderTargetsv", (void *)&SC_ClearFrameBufferObjectTargets, false },
- { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach, false },
- { "_Z9rsForEach9rs_script13rs_allocationS0_PKvj", (void *)&SC_ForEach2, false },
+ { "_Z9rsForEach9rs_script13rs_allocationS0_", (void *)&SC_ForEach_SAA, false },
+ { "_Z9rsForEach9rs_script13rs_allocationS0_PKv", (void *)&SC_ForEach_SAAU, false },
+ { "_Z9rsForEach9rs_script13rs_allocationS0_PKvPK16rs_script_call_t", (void *)&SC_ForEach_SAAUS, false },
+ { "_Z9rsForEach9rs_script13rs_allocationS0_PKvj", (void *)&SC_ForEach_SAAUL, false },
+ { "_Z9rsForEach9rs_script13rs_allocationS0_PKvjPK16rs_script_call_t", (void *)&SC_ForEach_SAAULS, false },
// time
{ "_Z6rsTimePi", (void *)&SC_Time, true },
diff --git a/libs/rs/scriptc/rs_math.rsh b/libs/rs/scriptc/rs_math.rsh
index f38f72c..fb5c4f6 100644
--- a/libs/rs/scriptc/rs_math.rsh
+++ b/libs/rs/scriptc/rs_math.rsh
@@ -249,15 +249,28 @@
uint32_t arrayEnd;
} rs_script_call_t;
+#if 1//(RS_VERSION >= 14)
extern void __attribute__((overloadable))
- rsForEach(rs_script script, rs_allocation input,
- rs_allocation output, const void * usrData);
+ rsForEach(rs_script script, rs_allocation input, rs_allocation output);
extern void __attribute__((overloadable))
+ rsForEach(rs_script script, rs_allocation input, rs_allocation output,
+ const void * usrData, size_t usrDataLen);
+
+extern void __attribute__((overloadable))
+ rsForEach(rs_script script, rs_allocation input, rs_allocation output,
+ const void * usrData, size_t usrDataLen, const rs_script_call_t *);
+#else
+extern void __attribute__((overloadable))
rsForEach(rs_script script, rs_allocation input,
rs_allocation output, const void * usrData,
const rs_script_call_t *);
+#endif
+// Move me once dependant changes are in.
+extern void __attribute__((overloadable))
+ rsForEach(rs_script script, rs_allocation input,
+ rs_allocation output, const void * usrData);
/**
diff --git a/libs/rs/scriptc/rs_types.rsh b/libs/rs/scriptc/rs_types.rsh
index 536d1f04..121e013 100644
--- a/libs/rs/scriptc/rs_types.rsh
+++ b/libs/rs/scriptc/rs_types.rsh
@@ -19,6 +19,9 @@
typedef uint32_t uint;
typedef uint64_t ulong;
+typedef uint32_t size_t;
+typedef int32_t ssize_t;
+
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_element;
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_type;
typedef struct { const int* const p; } __attribute__((packed, aligned(4))) rs_allocation;
@@ -88,6 +91,8 @@
#define RS_PACKED __attribute__((packed, aligned(4)))
+#define NULL ((const void *)0)
+
typedef enum {
RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X = 0,
RS_ALLOCATION_CUBEMAP_FACE_NEGATIVE_X = 1,
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 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
- 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_USAGE:
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
+ case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
+ // TODO: we should implement these
return NO_ERROR;
+
+ case NATIVE_WINDOW_LOCK:
+ case NATIVE_WINDOW_UNLOCK_AND_POST:
+ case NATIVE_WINDOW_SET_CROP:
+ case NATIVE_WINDOW_SET_BUFFER_COUNT:
+ case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
case NATIVE_WINDOW_SET_SCALING_MODE:
return INVALID_OPERATION;
}
diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp
index cb6c246..6cf01c8 100644
--- a/libs/utils/ResourceTypes.cpp
+++ b/libs/utils/ResourceTypes.cpp
@@ -4346,7 +4346,8 @@
| (0x0000ffff & (entryIndex));
resource_name resName;
if (!this->getResourceName(resID, &resName)) {
- return UNKNOWN_ERROR;
+ LOGW("idmap: resource 0x%08x has spec but lacks values, skipping\n", resID);
+ continue;
}
const String16 overlayType(resName.type, resName.typeLen);
diff --git a/media/java/android/media/AudioFormat.java b/media/java/android/media/AudioFormat.java
index 31e46312..82e8d77 100644
--- a/media/java/android/media/AudioFormat.java
+++ b/media/java/android/media/AudioFormat.java
@@ -54,7 +54,8 @@
/** 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 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 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 @@
* 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 @@
}
/**
+ * 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 @@
* @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 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 @@
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 @@
}
/**
- * 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 @@
// 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 @@
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/java/android/media/audiofx/AcousticEchoCanceler.java b/media/java/android/media/audiofx/AcousticEchoCanceler.java
new file mode 100644
index 0000000..7197dd2
--- /dev/null
+++ b/media/java/android/media/audiofx/AcousticEchoCanceler.java
@@ -0,0 +1,67 @@
+/*
+ * 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.media.audiofx;
+
+/**
+ * Acoustic Echo Canceler (AEC).
+ * <p>Acoustic Echo Canceler (AEC) is an audio pre-processing which removes the contribution of the
+ * signal received from the remote party from the captured audio signal.
+ * <p>AEC is used by voice communication applications (voice chat, video conferencing, SIP calls)
+ * where the presence of echo with significant delay in the signal received from the remote party
+ * is highly disturbing. AEC is often used in conjunction with noise suppression (NS).
+ * <p>An application creates an AcousticEchoCanceler object to instantiate and control an AEC
+ * engine in the audio capture path.
+ * <p>To attach the AcousticEchoCanceler to a particular {@link android.media.AudioRecord},
+ * specify the audio session ID of this AudioRecord when constructing the AcousticEchoCanceler.
+ * The audio session is retrieved by calling
+ * {@link android.media.AudioRecord#getAudioSessionId()} on the AudioRecord instance.
+ * <p>On some devices, an AEC can be inserted by default in the capture path by the platform
+ * according to the {@link android.media.MediaRecorder.AudioSource} used. The application can
+ * query which pre-processings are currently applied to an AudioRecord instance by calling
+ * {@link android.media.audiofx.AudioEffect#queryPreProcessings(int)} with the audio session of the
+ * AudioRecord.
+ * <p>See {@link android.media.audiofx.AudioEffect} class for more details on
+ * controlling audio effects.
+ * @hide
+ */
+
+public class AcousticEchoCanceler extends AudioEffect {
+
+ private final static String TAG = "AcousticEchoCanceler";
+
+ /**
+ * Class constructor.
+ * <p> The application must catch exceptions when creating an AcousticEchoCanceler as the
+ * constructor is not guarantied to succeed:
+ * <ul>
+ * <li>IllegalArgumentException is thrown if the device does not implement an AEC</li>
+ * <li>UnsupportedOperationException is thrown is the resources allocated to audio
+ * pre-procesing are currently exceeded.</li>
+ * </ul>
+ *
+ * @param audioSession system wide unique audio session identifier. The AcousticEchoCanceler
+ * will be applied to the AudioRecord with the same audio session.
+ *
+ * @throws java.lang.IllegalArgumentException
+ * @throws java.lang.UnsupportedOperationException
+ * @throws java.lang.RuntimeException
+ */
+ public AcousticEchoCanceler(int audioSession)
+ throws IllegalArgumentException, UnsupportedOperationException, RuntimeException {
+ super(EFFECT_TYPE_AEC, EFFECT_TYPE_NULL, 0, audioSession);
+ }
+}
diff --git a/media/java/android/media/audiofx/AudioEffect.java b/media/java/android/media/audiofx/AudioEffect.java
index 39c6d3e..3ac0104 100644
--- a/media/java/android/media/audiofx/AudioEffect.java
+++ b/media/java/android/media/audiofx/AudioEffect.java
@@ -66,6 +66,8 @@
private final static String TAG = "AudioEffect-JAVA";
+ // effect type UUIDs are taken from hardware/libhardware/include/hardware/audio_effect.h
+
/**
* The following UUIDs define effect types corresponding to standard audio
* effects whose implementation and interface conform to the OpenSL ES
@@ -105,6 +107,27 @@
.fromString("37cc2c00-dddd-11db-8577-0002a5d5c51b");
/**
+ * UUID for Automatic Gain Control (AGC) audio pre-processing
+ * @hide
+ */
+ public static final UUID EFFECT_TYPE_AGC = UUID
+ .fromString("0a8abfe0-654c-11e0-ba26-0002a5d5c51b");
+
+ /**
+ * UUID for Acoustic Echo Canceler (AEC) audio pre-processing
+ * @hide
+ */
+ public static final UUID EFFECT_TYPE_AEC = UUID
+ .fromString("7b491460-8d4d-11e0-bd61-0002a5d5c51b");
+
+ /**
+ * UUID for Noise Suppressor (NS) audio pre-processing
+ * @hide
+ */
+ public static final UUID EFFECT_TYPE_NS = UUID
+ .fromString("58b4b260-8e06-11e0-aa8e-0002a5d5c51b");
+
+ /**
* Null effect UUID. Used when the UUID for effect type of
* @hide
*/
@@ -180,7 +203,8 @@
* <ul>
* <li>type: UUID corresponding to the OpenSL ES interface implemented by this effect</li>
* <li>uuid: UUID for this particular implementation</li>
- * <li>connectMode: {@link #EFFECT_INSERT} or {@link #EFFECT_AUXILIARY}</li>
+ * <li>connectMode: {@link #EFFECT_INSERT}, {@link #EFFECT_AUXILIARY} or
+ * {at_link #EFFECT_PRE_PROCESSING}</li>
* <li>name: human readable effect name</li>
* <li>implementor: human readable effect implementor name</li>
* </ul>
@@ -212,11 +236,13 @@
*/
public UUID uuid;
/**
- * Indicates if the effect is of insert category {@link #EFFECT_INSERT} or auxiliary
- * category {@link #EFFECT_AUXILIARY}. Insert effects (Typically an Equalizer) are applied
+ * Indicates if the effect is of insert category {@link #EFFECT_INSERT}, auxiliary
+ * category {@link #EFFECT_AUXILIARY} or pre processing category
+ * {at_link #EFFECT_PRE_PROCESSING}. Insert effects (Typically an Equalizer) are applied
* to the entire audio source and usually not shared by several sources. Auxiliary effects
* (typically a reverberator) are applied to part of the signal (wet) and the effect output
* is added to the original signal (dry).
+ * Audio pre processing are applied to audio captured on a particular AudioRecord.
*/
public String connectMode;
/**
@@ -243,6 +269,12 @@
* attaching it to the MediaPlayer or AudioTrack.
*/
public static final String EFFECT_AUXILIARY = "Auxiliary";
+ /**
+ * Effect connection mode is pre processing.
+ * The audio pre processing effects are attached to an audio input (AudioRecord).
+ * @hide
+ */
+ public static final String EFFECT_PRE_PROCESSING = "Pre Processing";
// --------------------------------------------------------------------------
// Member variables
@@ -410,6 +442,19 @@
return (Descriptor[]) native_query_effects();
}
+ /**
+ * Query all audio pre processing effects applied to the AudioRecord with the supplied
+ * audio session ID. Returns an array of {@link android.media.audiofx.AudioEffect.Descriptor}
+ * objects.
+ * @param audioSession system wide unique audio session identifier.
+ * @throws IllegalStateException
+ * @hide
+ */
+
+ static public Descriptor[] queryPreProcessings(int audioSession) {
+ return (Descriptor[]) native_query_pre_processing(audioSession);
+ }
+
// --------------------------------------------------------------------------
// Control methods
// --------------------
@@ -1155,6 +1200,8 @@
private static native Object[] native_query_effects();
+ private static native Object[] native_query_pre_processing(int audioSession);
+
// ---------------------------------------------------------
// Utility methods
// ------------------
diff --git a/media/java/android/media/audiofx/AutomaticGainControl.java b/media/java/android/media/audiofx/AutomaticGainControl.java
new file mode 100644
index 0000000..44574f0
--- /dev/null
+++ b/media/java/android/media/audiofx/AutomaticGainControl.java
@@ -0,0 +1,67 @@
+/*
+ * 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.media.audiofx;
+
+/**
+ * Automatic Gain Control (AGC).
+ * <p>Automatic Gain Control (AGC) is an audio pre-processing which automatically normalizes the
+ * output of the captured signal by boosting or lowering input from the microphone to match a preset
+ * level so that that the output signal level is virtually constant.
+ * AGC can be used by applications where the input signal dynamic range is not important but where
+ * a constant strong capture level is desired.
+ * <p>An application creates a AutomaticGainControl object to instantiate and control an AGC
+ * engine in the audio framework.
+ * <p>To attach the AutomaticGainControl to a particular {@link android.media.AudioRecord},
+ * specify the audio session ID of this AudioRecord when constructing the AutomaticGainControl.
+ * The audio session is retrieved by calling
+ * {@link android.media.AudioRecord#getAudioSessionId()} on the AudioRecord instance.
+ * <p>On some devices, an AGC can be inserted by default in the capture path by the platform
+ * according to the {@link android.media.MediaRecorder.AudioSource} used. The application can
+ * query which pre-processings are currently applied to an AudioRecord instance by calling
+ * {@link android.media.audiofx.AudioEffect#queryPreProcessings(int)} with the audio session of the
+ * AudioRecord.
+ * <p>See {@link android.media.audiofx.AudioEffect} class for more details on
+ * controlling audio effects.
+ * @hide
+ */
+
+public class AutomaticGainControl extends AudioEffect {
+
+ private final static String TAG = "AutomaticGainControl";
+
+ /**
+ * Class constructor.
+ * <p> The application must catch exceptions when creating an AutomaticGainControl as the
+ * constructor is not guarantied to succeed:
+ * <ul>
+ * <li>IllegalArgumentException is thrown if the device does not implement an AGC</li>
+ * <li>UnsupportedOperationException is thrown is the resources allocated to audio
+ * pre-procesing are currently exceeded.</li>
+ * </ul>
+ *
+ * @param audioSession system wide unique audio session identifier. The AutomaticGainControl
+ * will be applied to the AudioRecord with the same audio session.
+ *
+ * @throws java.lang.IllegalArgumentException
+ * @throws java.lang.UnsupportedOperationException
+ * @throws java.lang.RuntimeException
+ */
+ public AutomaticGainControl(int audioSession)
+ throws IllegalArgumentException, UnsupportedOperationException, RuntimeException {
+ super(EFFECT_TYPE_AGC, EFFECT_TYPE_NULL, 0, audioSession);
+ }
+}
diff --git a/media/java/android/media/audiofx/NoiseSuppressor.java b/media/java/android/media/audiofx/NoiseSuppressor.java
new file mode 100644
index 0000000..4e7a8b6
--- /dev/null
+++ b/media/java/android/media/audiofx/NoiseSuppressor.java
@@ -0,0 +1,68 @@
+/*
+ * 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.media.audiofx;
+
+/**
+ * Noise Suppressor (NS).
+ * <p>Noise suppression (NS) is an audio pre-processing which removes background noise from the
+ * captured signal. The component of the signal considered as noise can be either stationary
+ * (car/airplane engine, AC system) or non-stationary (other peoples conversations, car horn) for
+ * more advanced implementations.
+ * <p>NS is mostly used by voice communication applications (voice chat, video conferencing,
+ * SIP calls).
+ * <p>An application creates a NoiseSuppressor object to instantiate and control an NS
+ * engine in the audio framework.
+ * <p>To attach the NoiseSuppressor to a particular {@link android.media.AudioRecord},
+ * specify the audio session ID of this AudioRecord when constructing the NoiseSuppressor.
+ * The audio session is retrieved by calling
+ * {@link android.media.AudioRecord#getAudioSessionId()} on the AudioRecord instance.
+ * <p>On some devices, NS can be inserted by default in the capture path by the platform
+ * according to the {@link android.media.MediaRecorder.AudioSource} used. The application can
+ * query which pre-processings are currently applied to an AudioRecord instance by calling
+ * {@link android.media.audiofx.AudioEffect#queryPreProcessings(int)} with the audio session of the
+ * AudioRecord.
+ * <p>See {@link android.media.audiofx.AudioEffect} class for more details on
+ * controlling audio effects.
+ * @hide
+ */
+
+public class NoiseSuppressor extends AudioEffect {
+
+ private final static String TAG = "NoiseSuppressor";
+
+ /**
+ * Class constructor.
+ * <p> The application must catch exceptions when creating an NoiseSuppressor as the
+ * constructor is not guarantied to succeed:
+ * <ul>
+ * <li>IllegalArgumentException is thrown if the device does not implement an NS</li>
+ * <li>UnsupportedOperationException is thrown is the resources allocated to audio
+ * pre-procesing are currently exceeded.</li>
+ * </ul>
+ *
+ * @param audioSession system wide unique audio session identifier. The NoiseSuppressor
+ * will be applied to the AudioRecord with the same audio session.
+ *
+ * @throws java.lang.IllegalArgumentException
+ * @throws java.lang.UnsupportedOperationException
+ * @throws java.lang.RuntimeException
+ */
+ public NoiseSuppressor(int audioSession)
+ throws IllegalArgumentException, UnsupportedOperationException, RuntimeException {
+ super(EFFECT_TYPE_NS, EFFECT_TYPE_NULL, 0, audioSession);
+ }
+}
diff --git a/media/java/android/media/videoeditor/MediaArtistNativeHelper.java b/media/java/android/media/videoeditor/MediaArtistNativeHelper.java
index 0d2bcd5..6b0fb12 100644
--- a/media/java/android/media/videoeditor/MediaArtistNativeHelper.java
+++ b/media/java/android/media/videoeditor/MediaArtistNativeHelper.java
@@ -912,11 +912,14 @@
/** 720p 1280 X 720 */
public static final int V720p = 10;
- /** 1080 x 720 */
+ /** W720p 1080 x 720 */
public static final int W720p = 11;
- /** 1080 960 x 720 */
+ /** S720p 960 x 720 */
public static final int S720p = 12;
+
+ /** 1080p 1920 x 1080 */
+ public static final int V1080p = 13;
}
/**
@@ -3548,6 +3551,8 @@
retValue = VideoFrameSize.WVGA16x9;
else if (height == MediaProperties.HEIGHT_720)
retValue = VideoFrameSize.V720p;
+ else if (height == MediaProperties.HEIGHT_1080)
+ retValue = VideoFrameSize.V1080p;
break;
case MediaProperties.ASPECT_RATIO_4_3:
if (height == MediaProperties.HEIGHT_480)
diff --git a/media/java/android/media/videoeditor/MediaImageItem.java b/media/java/android/media/videoeditor/MediaImageItem.java
index 4faa83a..73cc7e2 100755
--- a/media/java/android/media/videoeditor/MediaImageItem.java
+++ b/media/java/android/media/videoeditor/MediaImageItem.java
@@ -503,7 +503,60 @@
return adjustedOverlays;
}
+ /**
+ * This function get the proper width by given aspect ratio
+ * and height.
+ *
+ * @param aspectRatio Given aspect ratio
+ * @param height Given height
+ */
+ private int getWidthByAspectRatioAndHeight(int aspectRatio, int height) {
+ int width = 0;
+ switch (aspectRatio) {
+ case MediaProperties.ASPECT_RATIO_3_2:
+ if (height == MediaProperties.HEIGHT_480)
+ width = 720;
+ else if (height == MediaProperties.HEIGHT_720)
+ width = 1080;
+ break;
+
+ case MediaProperties.ASPECT_RATIO_16_9:
+ if (height == MediaProperties.HEIGHT_360)
+ width = 640;
+ else if (height == MediaProperties.HEIGHT_480)
+ width = 854;
+ else if (height == MediaProperties.HEIGHT_720)
+ width = 1280;
+ else if (height == MediaProperties.HEIGHT_1080)
+ width = 1920;
+ break;
+
+ case MediaProperties.ASPECT_RATIO_4_3:
+ if (height == MediaProperties.HEIGHT_480)
+ width = 640;
+ if (height == MediaProperties.HEIGHT_720)
+ width = 960;
+ break;
+
+ case MediaProperties.ASPECT_RATIO_5_3:
+ if (height == MediaProperties.HEIGHT_480)
+ width = 800;
+ break;
+
+ case MediaProperties.ASPECT_RATIO_11_9:
+ if (height == MediaProperties.HEIGHT_144)
+ width = 176;
+ break;
+
+ default : {
+ throw new IllegalArgumentException(
+ "Illegal arguments for aspectRatio");
+ }
+ }
+
+ return width;
+ }
/**
* This function sets the Ken Burn effect generated clip
@@ -515,39 +568,10 @@
void setGeneratedImageClip(String generatedFilePath) {
super.setGeneratedImageClip(generatedFilePath);
-
// set the Kenburns clip width and height
mGeneratedClipHeight = getScaledHeight();
- switch (mVideoEditor.getAspectRatio()) {
- case MediaProperties.ASPECT_RATIO_3_2:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_480)
- mGeneratedClipWidth = 720;
- else if (mGeneratedClipHeight == MediaProperties.HEIGHT_720)
- mGeneratedClipWidth = 1080;
- break;
- case MediaProperties.ASPECT_RATIO_16_9:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_360)
- mGeneratedClipWidth = 640;
- else if (mGeneratedClipHeight == MediaProperties.HEIGHT_480)
- mGeneratedClipWidth = 854;
- else if (mGeneratedClipHeight == MediaProperties.HEIGHT_720)
- mGeneratedClipWidth = 1280;
- break;
- case MediaProperties.ASPECT_RATIO_4_3:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_480)
- mGeneratedClipWidth = 640;
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_720)
- mGeneratedClipWidth = 960;
- break;
- case MediaProperties.ASPECT_RATIO_5_3:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_480)
- mGeneratedClipWidth = 800;
- break;
- case MediaProperties.ASPECT_RATIO_11_9:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_144)
- mGeneratedClipWidth = 176;
- break;
- }
+ mGeneratedClipWidth = getWidthByAspectRatioAndHeight(
+ mVideoEditor.getAspectRatio(), mGeneratedClipHeight);
}
/**
@@ -841,37 +865,8 @@
clipSettings.fileType = FileType.THREE_GPP;
mGeneratedClipHeight = getScaledHeight();
- switch (mVideoEditor.getAspectRatio()) {
- case MediaProperties.ASPECT_RATIO_3_2:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_480)
- mGeneratedClipWidth = 720;
- else if (mGeneratedClipHeight == MediaProperties.HEIGHT_720)
- mGeneratedClipWidth = 1080;
- break;
- case MediaProperties.ASPECT_RATIO_16_9:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_360)
- mGeneratedClipWidth = 640;
- else if (mGeneratedClipHeight == MediaProperties.HEIGHT_480)
- mGeneratedClipWidth = 854;
- else if (mGeneratedClipHeight == MediaProperties.HEIGHT_720)
- mGeneratedClipWidth = 1280;
- break;
- case MediaProperties.ASPECT_RATIO_4_3:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_480)
- mGeneratedClipWidth = 640;
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_720)
- mGeneratedClipWidth = 960;
- break;
- case MediaProperties.ASPECT_RATIO_5_3:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_480)
- mGeneratedClipWidth = 800;
- break;
- case MediaProperties.ASPECT_RATIO_11_9:
- if (mGeneratedClipHeight == MediaProperties.HEIGHT_144)
- mGeneratedClipWidth = 176;
- break;
- }
-
+ mGeneratedClipWidth = getWidthByAspectRatioAndHeight(
+ mVideoEditor.getAspectRatio(), mGeneratedClipHeight);
} else {
if (getGeneratedImageClip() == null) {
clipSettings.clipPath = getDecodedImageFileName();
diff --git a/media/java/android/media/videoeditor/MediaProperties.java b/media/java/android/media/videoeditor/MediaProperties.java
index 0225807..ff13e5d 100755
--- a/media/java/android/media/videoeditor/MediaProperties.java
+++ b/media/java/android/media/videoeditor/MediaProperties.java
@@ -17,8 +17,9 @@
package android.media.videoeditor;
+import android.media.videoeditor.VideoEditorProfile;
import android.util.Pair;
-
+import java.lang.System;
/**
* This class defines all properties of a media file such as supported height,
* aspect ratio, bitrate for export function.
@@ -33,7 +34,7 @@
public static final int HEIGHT_360 = 360;
public static final int HEIGHT_480 = 480;
public static final int HEIGHT_720 = 720;
- public static final int HEIGHT_1088 = 1088;
+ public static final int HEIGHT_1080 = 1080;
/**
* Supported aspect ratios
@@ -63,8 +64,7 @@
private static final Pair<Integer, Integer>[] ASPECT_RATIO_3_2_RESOLUTIONS =
new Pair[] {
new Pair<Integer, Integer>(720, HEIGHT_480),
-//*tmpLSA*/ new Pair<Integer, Integer>(1080, HEIGHT_720)
-/*tmpLSA*/ new Pair<Integer, Integer>(1088, HEIGHT_720)
+ new Pair<Integer, Integer>(1080, HEIGHT_720)
};
@SuppressWarnings({"unchecked"})
@@ -92,6 +92,7 @@
new Pair[] {
new Pair<Integer, Integer>(848, HEIGHT_480),
new Pair<Integer, Integer>(1280, HEIGHT_720),
+ new Pair<Integer, Integer>(1920, HEIGHT_1080),
};
/**
@@ -345,7 +346,31 @@
}
}
- return resolutions;
+ /** Check the platform specific maximum export resolution */
+ VideoEditorProfile veProfile = VideoEditorProfile.get();
+ if (veProfile == null) {
+ throw new RuntimeException("Can't get the video editor profile");
+ }
+ final int maxWidth = veProfile.maxOutputVideoFrameWidth;
+ final int maxHeight = veProfile.maxOutputVideoFrameHeight;
+ Pair<Integer, Integer>[] tmpResolutions = new Pair[resolutions.length];
+ int numSupportedResolution = 0;
+ int i = 0;
+
+ /** Get supported resolution list */
+ for (i = 0; i < resolutions.length; i++) {
+ if ((resolutions[i].first <= maxWidth) &&
+ (resolutions[i].second <= maxHeight)) {
+ tmpResolutions[numSupportedResolution] = resolutions[i];
+ numSupportedResolution++;
+ }
+ }
+ final Pair<Integer, Integer>[] supportedResolutions =
+ new Pair[numSupportedResolution];
+ System.arraycopy(tmpResolutions, 0,
+ supportedResolutions, 0, numSupportedResolution);
+
+ return supportedResolutions;
}
/**
diff --git a/media/java/android/media/videoeditor/MediaVideoItem.java b/media/java/android/media/videoeditor/MediaVideoItem.java
index 4758de6..6248651 100755
--- a/media/java/android/media/videoeditor/MediaVideoItem.java
+++ b/media/java/android/media/videoeditor/MediaVideoItem.java
@@ -23,6 +23,7 @@
import android.graphics.Bitmap;
import android.media.videoeditor.MediaArtistNativeHelper.ClipSettings;
import android.media.videoeditor.MediaArtistNativeHelper.Properties;
+import android.media.videoeditor.VideoEditorProfile;
import android.view.Surface;
import android.view.SurfaceHolder;
@@ -118,6 +119,21 @@
throw new IllegalArgumentException(e.getMessage() + " : " + filename);
}
+ /** Check the platform specific maximum import resolution */
+ VideoEditorProfile veProfile = VideoEditorProfile.get();
+ if (veProfile == null) {
+ throw new RuntimeException("Can't get the video editor profile");
+ }
+ final int maxInputWidth = veProfile.maxInputVideoFrameWidth;
+ final int maxInputHeight = veProfile.maxInputVideoFrameHeight;
+ if ((properties.width > maxInputWidth) ||
+ (properties.height > maxInputHeight)) {
+ throw new IllegalArgumentException(
+ "Unsupported import resolution. Supported maximum width:" +
+ maxInputWidth + " height:" + maxInputHeight +
+ ", current width:" + properties.width +
+ " height:" + properties.height);
+ }
switch (mMANativeHelper.getFileType(properties.fileType)) {
case MediaProperties.FILE_3GP:
case MediaProperties.FILE_MP4:
diff --git a/media/java/android/media/videoeditor/VideoEditor.java b/media/java/android/media/videoeditor/VideoEditor.java
index 59e4540..720e8022 100755
--- a/media/java/android/media/videoeditor/VideoEditor.java
+++ b/media/java/android/media/videoeditor/VideoEditor.java
@@ -370,7 +370,7 @@
*/
public void export(String filename, int height, int bitrate,
ExportProgressListener listener)
- throws IOException;
+ throws IOException;
/**
* Create the output movie based on all media items added and the applied
@@ -413,7 +413,7 @@
*/
public void export(String filename, int height, int bitrate, int audioCodec,
int videoCodec, ExportProgressListener listener)
- throws IOException;
+ throws IOException;
/**
* Cancel the running export operation. This method blocks until the export
diff --git a/media/java/android/media/videoeditor/VideoEditorImpl.java b/media/java/android/media/videoeditor/VideoEditorImpl.java
index 649b98a..ea7fe63 100755
--- a/media/java/android/media/videoeditor/VideoEditorImpl.java
+++ b/media/java/android/media/videoeditor/VideoEditorImpl.java
@@ -337,7 +337,8 @@
*/
public void export(String filename, int height, int bitrate,
int audioCodec, int videoCodec,
- ExportProgressListener listener) throws IOException {
+ ExportProgressListener listener)
+ throws IOException {
switch (audioCodec) {
case MediaProperties.ACODEC_AAC_LC:
@@ -372,7 +373,8 @@
* {@inheritDoc}
*/
public void export(String filename, int height, int bitrate,
- ExportProgressListener listener) throws IOException {
+ ExportProgressListener listener)
+ throws IOException {
if (filename == null) {
throw new IllegalArgumentException("export: filename is null");
}
@@ -386,6 +388,20 @@
throw new IllegalStateException("No MediaItems added");
}
+ /** Check the platform specific maximum export resolution */
+ VideoEditorProfile veProfile = VideoEditorProfile.get();
+ if (veProfile == null) {
+ throw new RuntimeException("Can't get the video editor profile");
+ }
+ final int maxOutputHeight = veProfile.maxOutputVideoFrameHeight;
+ final int maxOutputWidth = veProfile.maxOutputVideoFrameWidth;
+ if (height > maxOutputHeight) {
+ throw new IllegalArgumentException(
+ "Unsupported export resolution. Supported maximum width:" +
+ maxOutputWidth + " height:" + maxOutputHeight +
+ " current height:" + height);
+ }
+
switch (height) {
case MediaProperties.HEIGHT_144:
break;
@@ -397,6 +413,8 @@
break;
case MediaProperties.HEIGHT_720:
break;
+ case MediaProperties.HEIGHT_1080:
+ break;
default: {
String message = "Unsupported height value " + height;
diff --git a/media/java/android/media/videoeditor/VideoEditorProfile.java b/media/java/android/media/videoeditor/VideoEditorProfile.java
new file mode 100755
index 0000000..7d9fc8f
--- /dev/null
+++ b/media/java/android/media/videoeditor/VideoEditorProfile.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.media.videoeditor;
+
+/**
+ * The VideoEditorProfile class is used to retrieve the
+ * predefined videoeditor profile settings for videoeditor applications.
+ * These settings are read-only.
+ *
+ * <p>The videoeditor profile specifies the following set of parameters:
+ * <ul>
+ * <li> max input video frame width
+ * <li> max input video frame height
+ * <li> max output video frame width
+ * <li> max output video frame height
+ * </ul>
+ * {@hide}
+ */
+public class VideoEditorProfile
+{
+ /**
+ * The max input video frame width
+ */
+ public int maxInputVideoFrameWidth;
+
+ /**
+ * The max input video frame height
+ */
+ public int maxInputVideoFrameHeight;
+
+ /**
+ * The max ouput video frame width
+ */
+ public int maxOutputVideoFrameWidth;
+
+ /**
+ * The max ouput video frame height
+ */
+ public int maxOutputVideoFrameHeight;
+
+ /**
+ * Returns the videoeditor profile
+ */
+ public static VideoEditorProfile get() {
+ return native_get_videoeditor_profile();
+ }
+
+ static {
+ System.loadLibrary("media_jni");
+ native_init();
+ }
+
+ // Private constructor called by JNI
+ private VideoEditorProfile(int inputWidth,
+ int inputHeight,
+ int outputWidth,
+ int outputHeight) {
+
+ this.maxInputVideoFrameWidth = inputWidth;
+ this.maxInputVideoFrameHeight = inputHeight;
+ this.maxOutputVideoFrameWidth = outputWidth;
+ this.maxOutputVideoFrameHeight = outputHeight;
+ }
+
+ // Methods implemented by JNI
+ private static native final void native_init();
+ private static native final VideoEditorProfile
+ native_get_videoeditor_profile();
+}
diff --git a/media/jni/android_media_MediaProfiles.cpp b/media/jni/android_media_MediaProfiles.cpp
index 08a6de1..2b8dfe4 100644
--- a/media/jni/android_media_MediaProfiles.cpp
+++ b/media/jni/android_media_MediaProfiles.cpp
@@ -286,6 +286,44 @@
}
return static_cast<jint>(levels[index]);
}
+static jobject
+android_media_MediaProfiles_native_get_videoeditor_profile(JNIEnv *env, jobject thiz)
+{
+ LOGV("native_get_videoeditor_profile");
+
+ int maxInputFrameWidth =
+ sProfiles->getVideoEditorCapParamByName("videoeditor.input.width.max");
+ int maxInputFrameHeight =
+ sProfiles->getVideoEditorCapParamByName("videoeditor.input.height.max");
+ int maxOutputFrameWidth =
+ sProfiles->getVideoEditorCapParamByName("videoeditor.output.width.max");
+ int maxOutputFrameHeight =
+ sProfiles->getVideoEditorCapParamByName("videoeditor.output.height.max");
+
+ // Check on the values retrieved
+ if (maxInputFrameWidth == -1 || maxInputFrameHeight == -1 ||
+ maxOutputFrameWidth == -1 || maxOutputFrameHeight == -1) {
+
+ jniThrowException(env, "java/lang/RuntimeException",\
+ "Error retrieving videoeditor profile params");
+ return NULL;
+ }
+ LOGV("native_get_videoeditor_profile \
+ inWidth:%d inHeight:%d,outWidth:%d, outHeight:%d",\
+ maxInputFrameWidth,maxInputFrameHeight,\
+ maxOutputFrameWidth,maxOutputFrameHeight);
+
+ jclass VideoEditorProfileClazz =
+ env->FindClass("android/media/videoeditor/VideoEditorProfile");
+ jmethodID VideoEditorProfileConstructorMethodID =
+ env->GetMethodID(VideoEditorProfileClazz, "<init>", "(IIII)V");
+ return env->NewObject(VideoEditorProfileClazz,
+ VideoEditorProfileConstructorMethodID,
+ maxInputFrameWidth,
+ maxInputFrameHeight,
+ maxOutputFrameWidth,
+ maxOutputFrameHeight);
+}
static JNINativeMethod gMethodsForEncoderCapabilitiesClass[] = {
{"native_init", "()V", (void *)android_media_MediaProfiles_native_init},
@@ -324,10 +362,17 @@
{"native_get_image_encoding_quality_level","(II)I", (void *)android_media_MediaProfiles_native_get_image_encoding_quality_level},
};
+static JNINativeMethod gMethodsForVideoEditorProfileClass[] = {
+ {"native_init", "()V", (void *)android_media_MediaProfiles_native_init},
+ {"native_get_videoeditor_profile", "()Landroid/media/videoeditor/VideoEditorProfile;",
+ (void *)android_media_MediaProfiles_native_get_videoeditor_profile},
+};
+
static const char* const kEncoderCapabilitiesClassPathName = "android/media/EncoderCapabilities";
static const char* const kDecoderCapabilitiesClassPathName = "android/media/DecoderCapabilities";
static const char* const kCamcorderProfileClassPathName = "android/media/CamcorderProfile";
static const char* const kCameraProfileClassPathName = "android/media/CameraProfile";
+static const char* const kVideoEditorProfileClassPathName = "android/media/videoeditor/VideoEditorProfile";
// This function only registers the native methods, and is called from
// JNI_OnLoad in android_media_MediaPlayer.cpp
@@ -353,6 +398,11 @@
gMethodsForCameraProfileClass,
NELEM(gMethodsForCameraProfileClass));
+ int ret5 = AndroidRuntime::registerNativeMethods(env,
+ kVideoEditorProfileClassPathName,
+ gMethodsForVideoEditorProfileClass,
+ NELEM(gMethodsForVideoEditorProfileClass));
+
// Success if all return values from above are 0
- return (ret1 || ret2 || ret3 || ret4);
+ return (ret1 || ret2 || ret3 || ret4 || ret5);
}
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 @@
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 @@
}
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 @@
{"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/jni/audioeffect/android_media_AudioEffect.cpp b/media/jni/audioeffect/android_media_AudioEffect.cpp
index e71e727..57cabe2 100644
--- a/media/jni/audioeffect/android_media_AudioEffect.cpp
+++ b/media/jni/audioeffect/android_media_AudioEffect.cpp
@@ -725,18 +725,22 @@
goto queryEffects_failure;
}
+ if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
+ jdescConnect = env->NewStringUTF("Auxiliary");
+ } else if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_INSERT) {
+ jdescConnect = env->NewStringUTF("Insert");
+ } else if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC) {
+ jdescConnect = env->NewStringUTF("Pre Processing");
+ } else {
+ continue;
+ }
+
AudioEffect::guidToString(&desc.type, str, EFFECT_STRING_LEN_MAX);
jdescType = env->NewStringUTF(str);
AudioEffect::guidToString(&desc.uuid, str, EFFECT_STRING_LEN_MAX);
jdescUuid = env->NewStringUTF(str);
- if ((desc.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
- jdescConnect = env->NewStringUTF("Auxiliary");
- } else {
- jdescConnect = env->NewStringUTF("Insert");
- }
-
jdescName = env->NewStringUTF(desc.name);
jdescImplementor = env->NewStringUTF(desc.implementor);
@@ -771,6 +775,87 @@
}
+
+
+static jobjectArray
+android_media_AudioEffect_native_queryPreProcessings(JNIEnv *env, jclass clazz, jint audioSession)
+{
+ // kDefaultNumEffects is a "reasonable" value ensuring that only one query will be enough on
+ // most devices to get all active audio pre processing on a given session.
+ static const uint32_t kDefaultNumEffects = 5;
+
+ effect_descriptor_t *descriptors = new effect_descriptor_t[kDefaultNumEffects];
+ uint32_t numEffects = kDefaultNumEffects;
+
+ status_t status = AudioEffect::queryDefaultPreProcessing(audioSession,
+ descriptors,
+ &numEffects);
+ if ((status != NO_ERROR && status != NO_MEMORY) ||
+ numEffects == 0) {
+ delete[] descriptors;
+ return NULL;
+ }
+ if (status == NO_MEMORY) {
+ delete [] descriptors;
+ descriptors = new effect_descriptor_t[numEffects];
+ status = AudioEffect::queryDefaultPreProcessing(audioSession,
+ descriptors,
+ &numEffects);
+ }
+ if (status != NO_ERROR || numEffects == 0) {
+ delete[] descriptors;
+ return NULL;
+ }
+ LOGV("queryDefaultPreProcessing() got %d effects", numEffects);
+
+ jobjectArray ret = env->NewObjectArray(numEffects, fields.clazzDesc, NULL);
+ if (ret == NULL) {
+ delete[] descriptors;
+ return ret;
+ }
+
+ char str[EFFECT_STRING_LEN_MAX];
+ jstring jdescType;
+ jstring jdescUuid;
+ jstring jdescConnect;
+ jstring jdescName;
+ jstring jdescImplementor;
+ jobject jdesc;
+
+ for (uint32_t i = 0; i < numEffects; i++) {
+
+ AudioEffect::guidToString(&descriptors[i].type, str, EFFECT_STRING_LEN_MAX);
+ jdescType = env->NewStringUTF(str);
+ AudioEffect::guidToString(&descriptors[i].uuid, str, EFFECT_STRING_LEN_MAX);
+ jdescUuid = env->NewStringUTF(str);
+ jdescConnect = env->NewStringUTF("Pre Processing");
+ jdescName = env->NewStringUTF(descriptors[i].name);
+ jdescImplementor = env->NewStringUTF(descriptors[i].implementor);
+
+ jdesc = env->NewObject(fields.clazzDesc,
+ fields.midDescCstor,
+ jdescType,
+ jdescUuid,
+ jdescConnect,
+ jdescName,
+ jdescImplementor);
+ env->DeleteLocalRef(jdescType);
+ env->DeleteLocalRef(jdescUuid);
+ env->DeleteLocalRef(jdescConnect);
+ env->DeleteLocalRef(jdescName);
+ env->DeleteLocalRef(jdescImplementor);
+ if (jdesc == NULL) {
+ LOGE("env->NewObject(fields.clazzDesc, fields.midDescCstor)");
+ env->DeleteLocalRef(ret);
+ return NULL;;
+ }
+
+ env->SetObjectArrayElement(ret, i, jdesc);
+ }
+
+ return ret;
+}
+
// ----------------------------------------------------------------------------
// Dalvik VM type signatures
@@ -787,6 +872,8 @@
{"native_getParameter", "(I[BI[B)I", (void *)android_media_AudioEffect_native_getParameter},
{"native_command", "(II[BI[B)I", (void *)android_media_AudioEffect_native_command},
{"native_query_effects", "()[Ljava/lang/Object;", (void *)android_media_AudioEffect_native_queryEffects},
+ {"native_query_pre_processing", "(I)[Ljava/lang/Object;",
+ (void *)android_media_AudioEffect_native_queryPreProcessings},
};
diff --git a/media/jni/mediaeditor/VideoEditorClasses.cpp b/media/jni/mediaeditor/VideoEditorClasses.cpp
index 277e16c..4c0e7315 100755
--- a/media/jni/mediaeditor/VideoEditorClasses.cpp
+++ b/media/jni/mediaeditor/VideoEditorClasses.cpp
@@ -439,9 +439,10 @@
VIDEOEDIT_JAVA_CONSTANT_INIT("NTSC", M4VIDEOEDITING_kNTSC),
VIDEOEDIT_JAVA_CONSTANT_INIT("nHD", M4VIDEOEDITING_k640_360),
VIDEOEDIT_JAVA_CONSTANT_INIT("WVGA16x9", M4VIDEOEDITING_k854_480),
- VIDEOEDIT_JAVA_CONSTANT_INIT("V720p", M4VIDEOEDITING_kHD1280),
- VIDEOEDIT_JAVA_CONSTANT_INIT("W720p", M4VIDEOEDITING_kHD1080),
- VIDEOEDIT_JAVA_CONSTANT_INIT("S720p", M4VIDEOEDITING_kHD960)
+ VIDEOEDIT_JAVA_CONSTANT_INIT("V720p", M4VIDEOEDITING_k1280_720),
+ VIDEOEDIT_JAVA_CONSTANT_INIT("W720p", M4VIDEOEDITING_k1080_720),
+ VIDEOEDIT_JAVA_CONSTANT_INIT("S720p", M4VIDEOEDITING_k960_720),
+ VIDEOEDIT_JAVA_CONSTANT_INIT("V1080p", M4VIDEOEDITING_k1920_1080)
};
VIDEOEDIT_JAVA_DEFINE_CONSTANT_CLASS(VideoFrameSize, VIDEO_FRAME_SIZE_CLASS_NAME,
diff --git a/media/jni/mediaeditor/VideoEditorPropertiesMain.cpp b/media/jni/mediaeditor/VideoEditorPropertiesMain.cpp
index 9de7207..93fe702 100755
--- a/media/jni/mediaeditor/VideoEditorPropertiesMain.cpp
+++ b/media/jni/mediaeditor/VideoEditorPropertiesMain.cpp
@@ -214,18 +214,6 @@
"Invalid File or File not found ");
}
- /**
- * Max resolution supported is 1280 x 720.
- */
- if ( (pClipProperties->uiVideoWidth > 1280)
- || (pClipProperties->uiVideoHeight > 720) )
- {
- result = M4MCS_ERR_INVALID_INPUT_VIDEO_FRAME_SIZE;
- videoEditJava_checkAndThrowIllegalArgumentException(
- &gotten, pEnv, (M4NO_ERROR != result),
- "Unsupported input video frame size");
- }
-
#ifdef USE_SOFTWARE_DECODER
/**
* Input clip with non-multiples of 16 is not supported.
diff --git a/media/libmedia/AudioEffect.cpp b/media/libmedia/AudioEffect.cpp
index 3919551..0633744 100644
--- a/media/libmedia/AudioEffect.cpp
+++ b/media/libmedia/AudioEffect.cpp
@@ -419,6 +419,15 @@
return af->getEffectDescriptor(uuid, descriptor);
}
+
+status_t AudioEffect::queryDefaultPreProcessing(int audioSession,
+ effect_descriptor_t *descriptors,
+ uint32_t *count)
+{
+ const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
+ if (aps == 0) return PERMISSION_DENIED;
+ return aps->queryDefaultPreProcessing(audioSession, descriptors, count);
+}
// -------------------------------------------------------------------------
status_t AudioEffect::stringToGuid(const char *str, effect_uuid_t *guid)
diff --git a/media/libmedia/IAudioPolicyService.cpp b/media/libmedia/IAudioPolicyService.cpp
index 49d410f..15f4be0 100644
--- a/media/libmedia/IAudioPolicyService.cpp
+++ b/media/libmedia/IAudioPolicyService.cpp
@@ -53,6 +53,7 @@
UNREGISTER_EFFECT,
IS_STREAM_ACTIVE,
GET_DEVICES_FOR_STREAM,
+ QUERY_DEFAULT_PRE_PROCESSING
};
class BpAudioPolicyService : public BpInterface<IAudioPolicyService>
@@ -321,6 +322,31 @@
remote()->transact(IS_STREAM_ACTIVE, data, &reply);
return reply.readInt32();
}
+
+ virtual status_t queryDefaultPreProcessing(int audioSession,
+ effect_descriptor_t *descriptors,
+ uint32_t *count)
+ {
+ if (descriptors == NULL || count == NULL) {
+ return BAD_VALUE;
+ }
+ Parcel data, reply;
+ data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
+ data.writeInt32(audioSession);
+ data.writeInt32(*count);
+ status_t status = remote()->transact(QUERY_DEFAULT_PRE_PROCESSING, data, &reply);
+ if (status != NO_ERROR) {
+ return status;
+ }
+ status = static_cast <status_t> (reply.readInt32());
+ uint32_t retCount = reply.readInt32();
+ if (retCount != 0) {
+ uint32_t numDesc = (retCount < *count) ? retCount : *count;
+ reply.read(descriptors, sizeof(effect_descriptor_t) * numDesc);
+ }
+ *count = retCount;
+ return status;
+ }
};
IMPLEMENT_META_INTERFACE(AudioPolicyService, "android.media.IAudioPolicyService");
@@ -559,6 +585,29 @@
return NO_ERROR;
} break;
+ case QUERY_DEFAULT_PRE_PROCESSING: {
+ CHECK_INTERFACE(IAudioPolicyService, data, reply);
+ int audioSession = data.readInt32();
+ uint32_t count = data.readInt32();
+ uint32_t retCount = count;
+ effect_descriptor_t *descriptors =
+ (effect_descriptor_t *)new char[count * sizeof(effect_descriptor_t)];
+ status_t status = queryDefaultPreProcessing(audioSession, descriptors, &retCount);
+ reply->writeInt32(status);
+ if (status != NO_ERROR && status != NO_MEMORY) {
+ retCount = 0;
+ }
+ reply->writeInt32(retCount);
+ if (retCount) {
+ if (retCount < count) {
+ count = retCount;
+ }
+ reply->write(descriptors, sizeof(effect_descriptor_t) * count);
+ }
+ delete[] descriptors;
+ return status;
+ }
+
default:
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/media/libmedia/IMediaRecorder.cpp b/media/libmedia/IMediaRecorder.cpp
index a44ef5a..38e111e 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,
@@ -43,7 +46,6 @@
SET_AUDIO_ENCODER,
SET_OUTPUT_FILE_PATH,
SET_OUTPUT_FILE_FD,
- SET_OUTPUT_FILE_AUXILIARY_FD,
SET_VIDEO_SIZE,
SET_VIDEO_FRAMERATE,
SET_PARAMETERS,
@@ -71,6 +73,19 @@
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());
@@ -161,15 +176,6 @@
return reply.readInt32();
}
- status_t setOutputFileAuxiliary(int fd) {
- LOGV("setOutputFileAuxiliary(%d)", fd);
- Parcel data, reply;
- data.writeInterfaceToken(IMediaRecorder::getInterfaceDescriptor());
- data.writeFileDescriptor(fd);
- remote()->transact(SET_OUTPUT_FILE_AUXILIARY_FD, data, &reply);
- return reply.readInt32();
- }
-
status_t setVideoSize(int width, int height)
{
LOGV("setVideoSize(%dx%d)", width, height);
@@ -388,13 +394,6 @@
::close(fd);
return NO_ERROR;
} break;
- case SET_OUTPUT_FILE_AUXILIARY_FD: {
- LOGV("SET_OUTPUT_FILE_AUXILIARY_FD");
- CHECK_INTERFACE(IMediaRecorder, data, reply);
- int fd = dup(data.readFileDescriptor());
- reply->writeInt32(setOutputFileAuxiliary(fd));
- return NO_ERROR;
- } break;
case SET_VIDEO_SIZE: {
LOGV("SET_VIDEO_SIZE");
CHECK_INTERFACE(IMediaRecorder, data, reply);
@@ -440,6 +439,20 @@
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/MediaProfiles.cpp b/media/libmedia/MediaProfiles.cpp
index 069bbb7..f0f07a2 100644
--- a/media/libmedia/MediaProfiles.cpp
+++ b/media/libmedia/MediaProfiles.cpp
@@ -132,6 +132,16 @@
LOGV("codec = %d", cap.mCodec);
}
+/*static*/ void
+MediaProfiles::logVideoEditorCap(const MediaProfiles::VideoEditorCap& cap)
+{
+ LOGV("videoeditor cap:");
+ LOGV("mMaxInputFrameWidth = %d", cap.mMaxInputFrameWidth);
+ LOGV("mMaxInputFrameHeight = %d", cap.mMaxInputFrameHeight);
+ LOGV("mMaxOutputFrameWidth = %d", cap.mMaxOutputFrameWidth);
+ LOGV("mMaxOutputFrameHeight = %d", cap.mMaxOutputFrameHeight);
+}
+
/*static*/ int
MediaProfiles::findTagForName(const MediaProfiles::NameToTagMap *map, size_t nMappings, const char *name)
{
@@ -368,6 +378,24 @@
mStartTimeOffsets.replaceValueFor(cameraId, offsetTimeMs);
}
+/*static*/ MediaProfiles::VideoEditorCap*
+MediaProfiles::createVideoEditorCap(const char **atts, MediaProfiles *profiles)
+{
+ CHECK(!strcmp("maxInputFrameWidth", atts[0]) &&
+ !strcmp("maxInputFrameHeight", atts[2]) &&
+ !strcmp("maxOutputFrameWidth", atts[4]) &&
+ !strcmp("maxOutputFrameHeight", atts[6]));
+
+ MediaProfiles::VideoEditorCap *pVideoEditorCap =
+ new MediaProfiles::VideoEditorCap(atoi(atts[1]), atoi(atts[3]),
+ atoi(atts[5]), atoi(atts[7]));
+
+ logVideoEditorCap(*pVideoEditorCap);
+ profiles->mVideoEditorCap = pVideoEditorCap;
+
+ return pVideoEditorCap;
+}
+
/*static*/ void
MediaProfiles::startElementHandler(void *userData, const char *name, const char **atts)
{
@@ -398,6 +426,8 @@
createCamcorderProfile(profiles->mCurrentCameraId, atts, profiles->mCameraIds));
} else if (strcmp("ImageEncoding", name) == 0) {
profiles->addImageEncodingQualityLevel(profiles->mCurrentCameraId, atts);
+ } else if (strcmp("VideoEditorCap", name) == 0) {
+ createVideoEditorCap(atts, profiles);
}
}
@@ -790,6 +820,17 @@
profiles->mImageEncodingQualityLevels.add(levels);
}
+/*static*/ void
+MediaProfiles::createDefaultVideoEditorCap(MediaProfiles *profiles)
+{
+ profiles->mVideoEditorCap =
+ new MediaProfiles::VideoEditorCap(
+ VIDEOEDITOR_DEFAULT_MAX_INPUT_FRAME_WIDTH,
+ VIDEOEDITOR_DEFUALT_MAX_INPUT_FRAME_HEIGHT,
+ VIDEOEDITOR_DEFAULT_MAX_OUTPUT_FRAME_WIDTH,
+ VIDEOEDITOR_DEFUALT_MAX_OUTPUT_FRAME_HEIGHT);
+}
+
/*static*/ MediaProfiles*
MediaProfiles::createDefaultInstance()
{
@@ -801,6 +842,7 @@
createDefaultAudioDecoders(profiles);
createDefaultEncoderOutputFileFormats(profiles);
createDefaultImageEncodingQualityLevels(profiles);
+ createDefaultVideoEditorCap(profiles);
return profiles;
}
@@ -899,6 +941,28 @@
return -1;
}
+int MediaProfiles::getVideoEditorCapParamByName(const char *name) const
+{
+ LOGV("getVideoEditorCapParamByName: %s", name);
+
+ if (mVideoEditorCap == NULL) {
+ LOGE("The mVideoEditorCap is not created, then create default cap.");
+ createDefaultVideoEditorCap(sInstance);
+ }
+
+ if (!strcmp("videoeditor.input.width.max", name))
+ return mVideoEditorCap->mMaxInputFrameWidth;
+ if (!strcmp("videoeditor.input.height.max", name))
+ return mVideoEditorCap->mMaxInputFrameHeight;
+ if (!strcmp("videoeditor.output.width.max", name))
+ return mVideoEditorCap->mMaxOutputFrameWidth;
+ if (!strcmp("videoeditor.output.height.max", name))
+ return mVideoEditorCap->mMaxOutputFrameHeight;
+
+ LOGE("The given video editor param name %s is not found", name);
+ return -1;
+}
+
Vector<audio_encoder> MediaProfiles::getAudioEncoders() const
{
Vector<audio_encoder> encoders;
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 @@
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 @@
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..11d281f 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 @@
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;
@@ -319,32 +322,6 @@
return ret;
}
-status_t MediaRecorder::setOutputFileAuxiliary(int fd)
-{
- LOGV("setOutputFileAuxiliary(%d)", fd);
- if(mMediaRecorder == NULL) {
- LOGE("media recorder is not initialized yet");
- return INVALID_OPERATION;
- }
- if (mIsAuxiliaryOutputFileSet) {
- LOGE("output file has already been set");
- return INVALID_OPERATION;
- }
- if (!(mCurrentState & MEDIA_RECORDER_DATASOURCE_CONFIGURED)) {
- LOGE("setOutputFile called in an invalid state(%d)", mCurrentState);
- return INVALID_OPERATION;
- }
-
- status_t ret = mMediaRecorder->setOutputFileAuxiliary(fd);
- if (OK != ret) {
- LOGV("setOutputFileAuxiliary failed: %d", ret);
- mCurrentState = MEDIA_RECORDER_ERROR;
- return ret;
- }
- mIsAuxiliaryOutputFileSet = true;
- return ret;
-}
-
status_t MediaRecorder::setVideoSize(int width, int height)
{
LOGV("setVideoSize(%d, %d)", width, height);
@@ -357,7 +334,7 @@
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 +344,27 @@
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 +377,7 @@
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;
}
@@ -608,7 +603,6 @@
mIsAudioEncoderSet = false;
mIsVideoEncoderSet = false;
mIsOutputFileSet = false;
- mIsAuxiliaryOutputFileSet = false;
}
// Release should be OK in any state
@@ -621,7 +615,7 @@
return INVALID_OPERATION;
}
-MediaRecorder::MediaRecorder()
+MediaRecorder::MediaRecorder() : mSurfaceMediaSource(NULL)
{
LOGV("constructor");
@@ -632,6 +626,8 @@
if (mMediaRecorder != NULL) {
mCurrentState = MEDIA_RECORDER_IDLE;
}
+
+
doCleanUp();
}
@@ -646,6 +642,10 @@
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..6f80b35 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 @@
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)
{
@@ -163,17 +178,6 @@
return mRecorder->setOutputFile(fd, offset, length);
}
-status_t MediaRecorderClient::setOutputFileAuxiliary(int fd)
-{
- LOGV("setOutputFileAuxiliary(%d)", fd);
- Mutex::Autolock lock(mLock);
- if (mRecorder == NULL) {
- LOGE("recorder is not initialized");
- return NO_INIT;
- }
- return mRecorder->setOutputFileAuxiliary(fd);
-}
-
status_t MediaRecorderClient::setVideoSize(int width, int height)
{
LOGV("setVideoSize(%dx%d)", width, height);
diff --git a/media/libmediaplayerservice/MediaRecorderClient.h b/media/libmediaplayerservice/MediaRecorderClient.h
index bbca529..c9ccf22 100644
--- a/media/libmediaplayerservice/MediaRecorderClient.h
+++ b/media/libmediaplayerservice/MediaRecorderClient.h
@@ -25,45 +25,50 @@
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 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..6fdb726 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -28,9 +28,7 @@
#include <media/stagefright/AMRWriter.h>
#include <media/stagefright/AACWriter.h>
#include <media/stagefright/CameraSource.h>
-#include <media/stagefright/VideoSourceDownSampler.h>
#include <media/stagefright/CameraSourceTimeLapse.h>
-#include <media/stagefright/MediaSourceSplitter.h>
#include <media/stagefright/MPEG2TSWriter.h>
#include <media/stagefright/MPEG4Writer.h>
#include <media/stagefright/MediaDebug.h>
@@ -38,10 +36,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>
@@ -65,11 +65,11 @@
StagefrightRecorder::StagefrightRecorder()
- : mWriter(NULL), mWriterAux(NULL),
- mOutputFd(-1), mOutputFdAux(-1),
+ : mWriter(NULL),
+ mOutputFd(-1),
mAudioSource(AUDIO_SOURCE_CNT),
mVideoSource(VIDEO_SOURCE_LIST_END),
- mStarted(false) {
+ mStarted(false), mSurfaceMediaSource(NULL) {
LOGV("Constructor");
reset();
@@ -85,6 +85,14 @@
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 ||
@@ -249,24 +257,6 @@
return OK;
}
-status_t StagefrightRecorder::setOutputFileAuxiliary(int fd) {
- LOGV("setOutputFileAuxiliary: %d", fd);
-
- if (fd < 0) {
- LOGE("Invalid file descriptor: %d", fd);
- return -EBADF;
- }
-
- mCaptureAuxVideo = true;
-
- if (mOutputFdAux >= 0) {
- ::close(mOutputFdAux);
- }
- mOutputFdAux = dup(fd);
-
- return OK;
-}
-
// Attempt to parse an int64 literal optionally surrounded by whitespace,
// returns true on success, false otherwise.
static bool safe_strtoi64(const char *s, int64_t *val) {
@@ -563,42 +553,6 @@
return OK;
}
-status_t StagefrightRecorder::setParamAuxVideoWidth(int32_t width) {
- LOGV("setParamAuxVideoWidth : %d", width);
-
- if (width <= 0) {
- LOGE("Width (%d) is not positive", width);
- return BAD_VALUE;
- }
-
- mAuxVideoWidth = width;
- return OK;
-}
-
-status_t StagefrightRecorder::setParamAuxVideoHeight(int32_t height) {
- LOGV("setParamAuxVideoHeight : %d", height);
-
- if (height <= 0) {
- LOGE("Height (%d) is not positive", height);
- return BAD_VALUE;
- }
-
- mAuxVideoHeight = height;
- return OK;
-}
-
-status_t StagefrightRecorder::setParamAuxVideoEncodingBitRate(int32_t bitRate) {
- LOGV("StagefrightRecorder::setParamAuxVideoEncodingBitRate: %d", bitRate);
-
- if (bitRate <= 0) {
- LOGE("Invalid video encoding bit rate: %d", bitRate);
- return BAD_VALUE;
- }
-
- mAuxVideoBitRate = bitRate;
- return OK;
-}
-
status_t StagefrightRecorder::setParamGeoDataLongitude(
int32_t longitudex10000) {
@@ -728,21 +682,6 @@
return setParamTimeBetweenTimeLapseFrameCapture(
1000LL * timeBetweenTimeLapseFrameCaptureMs);
}
- } else if (key == "video-aux-param-width") {
- int32_t auxWidth;
- if (safe_strtoi32(value.string(), &auxWidth)) {
- return setParamAuxVideoWidth(auxWidth);
- }
- } else if (key == "video-aux-param-height") {
- int32_t auxHeight;
- if (safe_strtoi32(value.string(), &auxHeight)) {
- return setParamAuxVideoHeight(auxHeight);
- }
- } else if (key == "video-aux-param-encoding-bitrate") {
- int32_t auxVideoBitRate;
- if (safe_strtoi32(value.string(), &auxVideoBitRate)) {
- return setParamAuxVideoEncodingBitRate(auxVideoBitRate);
- }
} else {
LOGE("setParameter: failed to find key %s", key.string());
}
@@ -1006,13 +945,13 @@
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 +981,19 @@
}
}
- 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 +1227,60 @@
}
}
+// 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;
@@ -1454,7 +1446,6 @@
}
status_t StagefrightRecorder::setupMPEG4Recording(
- bool useSplitCameraSource,
int outputFd,
int32_t videoWidth, int32_t videoHeight,
int32_t videoBitRate,
@@ -1465,29 +1456,16 @@
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;
- if (useSplitCameraSource) {
- LOGV("Using Split camera source");
- cameraMediaSource = mCameraSourceSplitter->createClient();
- } else {
- sp<CameraSource> cameraSource;
- err = setupCameraSource(&cameraSource);
- cameraMediaSource = cameraSource;
- }
- if ((videoWidth != mVideoWidth) || (videoHeight != mVideoHeight)) {
- // Use downsampling from the original source.
- cameraMediaSource =
- new VideoSourceDownSampler(cameraMediaSource, videoWidth, videoHeight);
- }
+ sp<MediaSource> mediaSource;
+ err = setupMediaSource(&mediaSource);
if (err != OK) {
return err;
}
sp<MediaSource> encoder;
- err = setupVideoEncoder(cameraMediaSource, videoBitRate, &encoder);
+ err = setupVideoEncoder(mediaSource, videoBitRate, &encoder);
if (err != OK) {
return err;
}
@@ -1549,24 +1527,8 @@
}
status_t StagefrightRecorder::startMPEG4Recording() {
- if (mCaptureAuxVideo) {
- if (!mCaptureTimeLapse) {
- LOGE("Auxiliary video can be captured only in time lapse mode");
- return UNKNOWN_ERROR;
- }
- LOGV("Creating MediaSourceSplitter");
- sp<CameraSource> cameraSource;
- status_t err = setupCameraSource(&cameraSource);
- if (err != OK) {
- return err;
- }
- mCameraSourceSplitter = new MediaSourceSplitter(cameraSource);
- } else {
- mCameraSourceSplitter = NULL;
- }
-
int32_t totalBitRate;
- status_t err = setupMPEG4Recording(mCaptureAuxVideo,
+ status_t err = setupMPEG4Recording(
mOutputFd, mVideoWidth, mVideoHeight,
mVideoBitRate, &totalBitRate, &mWriter);
if (err != OK) {
@@ -1582,33 +1544,6 @@
return err;
}
- if (mCaptureAuxVideo) {
- CHECK(mOutputFdAux >= 0);
- if (mWriterAux != NULL) {
- LOGE("Auxiliary File writer is not avaialble");
- return UNKNOWN_ERROR;
- }
- if ((mAuxVideoWidth > mVideoWidth) || (mAuxVideoHeight > mVideoHeight) ||
- ((mAuxVideoWidth == mVideoWidth) && mAuxVideoHeight == mVideoHeight)) {
- LOGE("Auxiliary video size (%d x %d) same or larger than the main video size (%d x %d)",
- mAuxVideoWidth, mAuxVideoHeight, mVideoWidth, mVideoHeight);
- return UNKNOWN_ERROR;
- }
-
- int32_t totalBitrateAux;
- err = setupMPEG4Recording(mCaptureAuxVideo,
- mOutputFdAux, mAuxVideoWidth, mAuxVideoHeight,
- mAuxVideoBitRate, &totalBitrateAux, &mWriterAux);
- if (err != OK) {
- return err;
- }
-
- sp<MetaData> metaAux = new MetaData;
- setupMPEG4MetaData(startTimeUs, totalBitrateAux, &metaAux);
-
- return mWriterAux->start(metaAux.get());
- }
-
return OK;
}
@@ -1619,13 +1554,6 @@
}
mWriter->pause();
- if (mCaptureAuxVideo) {
- if (mWriterAux == NULL) {
- return UNKNOWN_ERROR;
- }
- mWriterAux->pause();
- }
-
if (mStarted) {
mStarted = false;
@@ -1653,13 +1581,6 @@
mCameraSourceTimeLapse = NULL;
}
- if (mCaptureAuxVideo) {
- if (mWriterAux != NULL) {
- mWriterAux->stop();
- mWriterAux.clear();
- }
- }
-
if (mWriter != NULL) {
err = mWriter->stop();
mWriter.clear();
@@ -1670,13 +1591,6 @@
mOutputFd = -1;
}
- if (mCaptureAuxVideo) {
- if (mOutputFdAux >= 0) {
- ::close(mOutputFdAux);
- mOutputFdAux = -1;
- }
- }
-
if (mStarted) {
mStarted = false;
@@ -1716,11 +1630,8 @@
mVideoEncoder = VIDEO_ENCODER_H263;
mVideoWidth = 176;
mVideoHeight = 144;
- mAuxVideoWidth = 176;
- mAuxVideoHeight = 144;
mFrameRate = -1;
mVideoBitRate = 192000;
- mAuxVideoBitRate = 192000;
mSampleRate = 8000;
mAudioChannels = 1;
mAudioBitRate = 12200;
@@ -1740,8 +1651,6 @@
mTrackEveryTimeDurationUs = 0;
mCaptureTimeLapse = false;
mTimeBetweenTimeLapseFrameCaptureUs = -1;
- mCaptureAuxVideo = false;
- mCameraSourceSplitter = NULL;
mCameraSourceTimeLapse = NULL;
mIsMetaDataStoredInVideoBuffers = false;
mEncoderProfiles = MediaProfiles::getInstance();
@@ -1750,7 +1659,6 @@
mLongitudex10000 = -3600000;
mOutputFd = -1;
- mOutputFdAux = -1;
return OK;
}
@@ -1787,8 +1695,6 @@
snprintf(buffer, SIZE, " Recorder: %p\n", this);
snprintf(buffer, SIZE, " Output file (fd %d):\n", mOutputFd);
result.append(buffer);
- snprintf(buffer, SIZE, " Output file Auxiliary (fd %d):\n", mOutputFdAux);
- result.append(buffer);
snprintf(buffer, SIZE, " File format: %d\n", mOutputFormat);
result.append(buffer);
snprintf(buffer, SIZE, " Max file size (bytes): %lld\n", mMaxFileSizeBytes);
@@ -1833,14 +1739,10 @@
result.append(buffer);
snprintf(buffer, SIZE, " Frame size (pixels): %dx%d\n", mVideoWidth, mVideoHeight);
result.append(buffer);
- snprintf(buffer, SIZE, " Aux Frame size (pixels): %dx%d\n", mAuxVideoWidth, mAuxVideoHeight);
- result.append(buffer);
snprintf(buffer, SIZE, " Frame rate (fps): %d\n", mFrameRate);
result.append(buffer);
snprintf(buffer, SIZE, " Bit rate (bps): %d\n", mVideoBitRate);
result.append(buffer);
- snprintf(buffer, SIZE, " Aux Bit rate (bps): %d\n", mAuxVideoBitRate);
- result.append(buffer);
::write(fd, result.string(), result.size());
return OK;
}
diff --git a/media/libmediaplayerservice/StagefrightRecorder.h b/media/libmediaplayerservice/StagefrightRecorder.h
index 034b373..5c5f05c 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.h
+++ b/media/libmediaplayerservice/StagefrightRecorder.h
@@ -30,12 +30,13 @@
class ICameraRecordingProxy;
class CameraSource;
class CameraSourceTimeLapse;
-class MediaSourceSplitter;
struct MediaSource;
struct MediaWriter;
class MetaData;
struct AudioSource;
class MediaProfiles;
+class ISurfaceTexture;
+class SurfaceMediaSource;
struct StagefrightRecorder : public MediaRecorderBase {
StagefrightRecorder();
@@ -53,7 +54,6 @@
virtual status_t setPreviewSurface(const sp<Surface>& surface);
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 setParameters(const String8& params);
virtual status_t setListener(const sp<IMediaRecorderClient>& listener);
virtual status_t prepare();
@@ -64,14 +64,16 @@
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;
sp<ICameraRecordingProxy> mCameraProxy;
sp<Surface> mPreviewSurface;
sp<IMediaRecorderClient> mListener;
- sp<MediaWriter> mWriter, mWriterAux;
- int mOutputFd, mOutputFdAux;
+ sp<MediaWriter> mWriter;
+ int mOutputFd;
sp<AudioSource> mAudioSourceNode;
audio_source_t mAudioSource;
@@ -81,9 +83,8 @@
video_encoder mVideoEncoder;
bool mUse64BitFileOffset;
int32_t mVideoWidth, mVideoHeight;
- int32_t mAuxVideoWidth, mAuxVideoHeight;
int32_t mFrameRate;
- int32_t mVideoBitRate, mAuxVideoBitRate;
+ int32_t mVideoBitRate;
int32_t mAudioBitRate;
int32_t mAudioChannels;
int32_t mSampleRate;
@@ -105,19 +106,22 @@
bool mCaptureTimeLapse;
int64_t mTimeBetweenTimeLapseFrameCaptureUs;
- bool mCaptureAuxVideo;
- 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,
int outputFd,
int32_t videoWidth, int32_t videoHeight,
int32_t videoBitRate,
@@ -134,7 +138,14 @@
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,
@@ -149,9 +160,6 @@
status_t setParamAudioTimeScale(int32_t timeScale);
status_t setParamTimeLapseEnable(int32_t timeLapseEnable);
status_t setParamTimeBetweenTimeLapseFrameCapture(int64_t timeUs);
- status_t setParamAuxVideoHeight(int32_t height);
- status_t setParamAuxVideoWidth(int32_t width);
- status_t setParamAuxVideoEncodingBitRate(int32_t bitRate);
status_t setParamVideoEncodingBitRate(int32_t bitRate);
status_t setParamVideoIFramesInterval(int32_t seconds);
status_t setParamVideoEncoderProfile(int32_t profile);
@@ -176,6 +184,7 @@
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 @@
SampleTable.cpp \
StagefrightMediaScanner.cpp \
StagefrightMetadataRetriever.cpp \
+ SurfaceMediaSource.cpp \
ThrottledSource.cpp \
TimeSource.cpp \
TimedEventQueue.cpp \
diff --git a/media/libstagefright/CameraSourceTimeLapse.cpp b/media/libstagefright/CameraSourceTimeLapse.cpp
index fe78c46..1ba79e5 100644
--- a/media/libstagefright/CameraSourceTimeLapse.cpp
+++ b/media/libstagefright/CameraSourceTimeLapse.cpp
@@ -24,15 +24,10 @@
#include <media/stagefright/CameraSourceTimeLapse.h>
#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MetaData.h>
-#include <media/stagefright/YUVImage.h>
-#include <media/stagefright/YUVCanvas.h>
#include <camera/Camera.h>
#include <camera/CameraParameters.h>
-#include <ui/Rect.h>
#include <utils/String8.h>
#include <utils/Vector.h>
-#include "OMX_Video.h"
-#include <limits.h>
namespace android {
@@ -74,20 +69,14 @@
mLastTimeLapseFrameRealTimestampUs(0),
mSkipCurrentFrame(false) {
- LOGD("starting time lapse mode: %lld us", mTimeBetweenTimeLapseFrameCaptureUs);
+ LOGD("starting time lapse mode: %lld us",
+ mTimeBetweenTimeLapseFrameCaptureUs);
+
mVideoWidth = videoSize.width;
mVideoHeight = videoSize.height;
- if (trySettingVideoSize(videoSize.width, videoSize.height)) {
- mUseStillCameraForTimeLapse = false;
- } else {
- // TODO: Add a check to see that mTimeBetweenTimeLapseFrameCaptureUs is greater
- // than the fastest rate at which the still camera can take pictures.
- mUseStillCameraForTimeLapse = true;
- CHECK(setPictureSizeToClosestSupported(videoSize.width, videoSize.height));
- mNeedCropping = computeCropRectangleOffset();
- mMeta->setInt32(kKeyWidth, videoSize.width);
- mMeta->setInt32(kKeyHeight, videoSize.height);
+ if (!trySettingVideoSize(videoSize.width, videoSize.height)) {
+ mInitCheck = NO_INIT;
}
// Initialize quick stop variables.
@@ -101,24 +90,22 @@
}
void CameraSourceTimeLapse::startQuickReadReturns() {
+ LOGV("startQuickReadReturns");
Mutex::Autolock autoLock(mQuickStopLock);
- LOGV("Enabling quick read returns");
// Enable quick stop mode.
mQuickStop = true;
- if (mUseStillCameraForTimeLapse) {
- // wake up the thread right away.
- mTakePictureCondition.signal();
- } else {
- // Force dataCallbackTimestamp() coming from the video camera to not skip the
- // next frame as we want read() to get a get a frame right away.
- mForceRead = true;
- }
+ // Force dataCallbackTimestamp() coming from the video camera to
+ // not skip the next frame as we want read() to get a get a frame
+ // right away.
+ mForceRead = true;
}
-bool CameraSourceTimeLapse::trySettingVideoSize(int32_t width, int32_t height) {
- LOGV("trySettingVideoSize: %dx%d", width, height);
+bool CameraSourceTimeLapse::trySettingVideoSize(
+ int32_t width, int32_t height) {
+
+ LOGV("trySettingVideoSize");
int64_t token = IPCThreadState::self()->clearCallingIdentity();
String8 s = mCamera->getParameters();
@@ -162,53 +149,8 @@
return isSuccessful;
}
-bool CameraSourceTimeLapse::setPictureSizeToClosestSupported(int32_t width, int32_t height) {
- LOGV("setPictureSizeToClosestSupported: %dx%d", width, height);
- int64_t token = IPCThreadState::self()->clearCallingIdentity();
- String8 s = mCamera->getParameters();
- IPCThreadState::self()->restoreCallingIdentity(token);
-
- CameraParameters params(s);
- Vector<Size> supportedSizes;
- params.getSupportedPictureSizes(supportedSizes);
-
- int32_t minPictureSize = INT_MAX;
- for (uint32_t i = 0; i < supportedSizes.size(); ++i) {
- int32_t pictureWidth = supportedSizes[i].width;
- int32_t pictureHeight = supportedSizes[i].height;
-
- if ((pictureWidth >= width) && (pictureHeight >= height)) {
- int32_t pictureSize = pictureWidth*pictureHeight;
- if (pictureSize < minPictureSize) {
- minPictureSize = pictureSize;
- mPictureWidth = pictureWidth;
- mPictureHeight = pictureHeight;
- }
- }
- }
- LOGV("Picture size = (%d, %d)", mPictureWidth, mPictureHeight);
- return (minPictureSize != INT_MAX);
-}
-
-bool CameraSourceTimeLapse::computeCropRectangleOffset() {
- if ((mPictureWidth == mVideoWidth) && (mPictureHeight == mVideoHeight)) {
- return false;
- }
-
- CHECK((mPictureWidth > mVideoWidth) && (mPictureHeight > mVideoHeight));
-
- int32_t widthDifference = mPictureWidth - mVideoWidth;
- int32_t heightDifference = mPictureHeight - mVideoHeight;
-
- mCropRectStartX = widthDifference/2;
- mCropRectStartY = heightDifference/2;
-
- LOGV("setting crop rectangle offset to (%d, %d)", mCropRectStartX, mCropRectStartY);
-
- return true;
-}
-
void CameraSourceTimeLapse::signalBufferReturned(MediaBuffer* buffer) {
+ LOGV("signalBufferReturned");
Mutex::Autolock autoLock(mQuickStopLock);
if (mQuickStop && (buffer == mLastReadBufferCopy)) {
buffer->setObserver(NULL);
@@ -218,7 +160,12 @@
}
}
-void createMediaBufferCopy(const MediaBuffer& sourceBuffer, int64_t frameTime, MediaBuffer **newBuffer) {
+void createMediaBufferCopy(
+ const MediaBuffer& sourceBuffer,
+ int64_t frameTime,
+ MediaBuffer **newBuffer) {
+
+ LOGV("createMediaBufferCopy");
size_t sourceSize = sourceBuffer.size();
void* sourcePointer = sourceBuffer.data();
@@ -229,6 +176,7 @@
}
void CameraSourceTimeLapse::fillLastReadBufferCopy(MediaBuffer& sourceBuffer) {
+ LOGV("fillLastReadBufferCopy");
int64_t frameTime;
CHECK(sourceBuffer.meta_data()->findInt64(kKeyTime, &frameTime));
createMediaBufferCopy(sourceBuffer, frameTime, &mLastReadBufferCopy);
@@ -238,11 +186,12 @@
status_t CameraSourceTimeLapse::read(
MediaBuffer **buffer, const ReadOptions *options) {
+ LOGV("read");
if (mLastReadBufferCopy == NULL) {
mLastReadStatus = CameraSource::read(buffer, options);
- // mQuickStop may have turned to true while read was blocked. Make a copy of
- // the buffer in that case.
+ // mQuickStop may have turned to true while read was blocked.
+ // Make a copy of the buffer in that case.
Mutex::Autolock autoLock(mQuickStopLock);
if (mQuickStop && *buffer) {
fillLastReadBufferCopy(**buffer);
@@ -255,105 +204,19 @@
}
}
-// static
-void *CameraSourceTimeLapse::ThreadTimeLapseWrapper(void *me) {
- CameraSourceTimeLapse *source = static_cast<CameraSourceTimeLapse *>(me);
- source->threadTimeLapseEntry();
- return NULL;
-}
-
-void CameraSourceTimeLapse::threadTimeLapseEntry() {
- while (mStarted) {
- {
- Mutex::Autolock autoLock(mCameraIdleLock);
- if (!mCameraIdle) {
- mCameraIdleCondition.wait(mCameraIdleLock);
- }
- CHECK(mCameraIdle);
- mCameraIdle = false;
- }
-
- // Even if mQuickStop == true we need to take one more picture
- // as a read() may be blocked, waiting for a frame to get available.
- // After this takePicture, if mQuickStop == true, we can safely exit
- // this thread as read() will make a copy of this last frame and keep
- // returning it in the quick stop mode.
- Mutex::Autolock autoLock(mQuickStopLock);
- CHECK_EQ(OK, mCamera->takePicture(CAMERA_MSG_RAW_IMAGE));
- if (mQuickStop) {
- LOGV("threadTimeLapseEntry: Exiting due to mQuickStop = true");
- return;
- }
- mTakePictureCondition.waitRelative(mQuickStopLock,
- mTimeBetweenTimeLapseFrameCaptureUs * 1000);
- }
- LOGV("threadTimeLapseEntry: Exiting due to mStarted = false");
-}
-
-void CameraSourceTimeLapse::startCameraRecording() {
- if (mUseStillCameraForTimeLapse) {
- LOGV("start time lapse recording using still camera");
-
- int64_t token = IPCThreadState::self()->clearCallingIdentity();
- String8 s = mCamera->getParameters();
-
- CameraParameters params(s);
- params.setPictureSize(mPictureWidth, mPictureHeight);
- mCamera->setParameters(params.flatten());
- mCameraIdle = true;
- mStopWaitingForIdleCamera = false;
-
- // disable shutter sound and play the recording sound.
- mCamera->sendCommand(CAMERA_CMD_ENABLE_SHUTTER_SOUND, 0, 0);
- mCamera->sendCommand(CAMERA_CMD_PLAY_RECORDING_SOUND, 0, 0);
- IPCThreadState::self()->restoreCallingIdentity(token);
-
- // create a thread which takes pictures in a loop
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
-
- pthread_create(&mThreadTimeLapse, &attr, ThreadTimeLapseWrapper, this);
- pthread_attr_destroy(&attr);
- } else {
- LOGV("start time lapse recording using video camera");
- CameraSource::startCameraRecording();
- }
-}
-
void CameraSourceTimeLapse::stopCameraRecording() {
- if (mUseStillCameraForTimeLapse) {
- void *dummy;
- pthread_join(mThreadTimeLapse, &dummy);
-
- // Last takePicture may still be underway. Wait for the camera to get
- // idle.
- Mutex::Autolock autoLock(mCameraIdleLock);
- mStopWaitingForIdleCamera = true;
- if (!mCameraIdle) {
- mCameraIdleCondition.wait(mCameraIdleLock);
- }
- CHECK(mCameraIdle);
- mCamera->setListener(NULL);
-
- // play the recording sound.
- mCamera->sendCommand(CAMERA_CMD_PLAY_RECORDING_SOUND, 0, 0);
- } else {
- CameraSource::stopCameraRecording();
- }
+ LOGV("stopCameraRecording");
+ CameraSource::stopCameraRecording();
if (mLastReadBufferCopy) {
mLastReadBufferCopy->release();
mLastReadBufferCopy = NULL;
}
}
-void CameraSourceTimeLapse::releaseRecordingFrame(const sp<IMemory>& frame) {
- if (!mUseStillCameraForTimeLapse) {
- CameraSource::releaseRecordingFrame(frame);
- }
-}
+sp<IMemory> CameraSourceTimeLapse::createIMemoryCopy(
+ const sp<IMemory> &source_data) {
-sp<IMemory> CameraSourceTimeLapse::createIMemoryCopy(const sp<IMemory> &source_data) {
+ LOGV("createIMemoryCopy");
size_t source_size = source_data->size();
void* source_pointer = source_data->pointer();
@@ -363,102 +226,8 @@
return newMemory;
}
-// Allocates IMemory of final type MemoryBase with the given size.
-sp<IMemory> allocateIMemory(size_t size) {
- sp<MemoryHeapBase> newMemoryHeap = new MemoryHeapBase(size);
- sp<MemoryBase> newMemory = new MemoryBase(newMemoryHeap, 0, size);
- return newMemory;
-}
-
-// static
-void *CameraSourceTimeLapse::ThreadStartPreviewWrapper(void *me) {
- CameraSourceTimeLapse *source = static_cast<CameraSourceTimeLapse *>(me);
- source->threadStartPreview();
- return NULL;
-}
-
-void CameraSourceTimeLapse::threadStartPreview() {
- CHECK_EQ(OK, mCamera->startPreview());
- Mutex::Autolock autoLock(mCameraIdleLock);
- mCameraIdle = true;
- mCameraIdleCondition.signal();
-}
-
-void CameraSourceTimeLapse::restartPreview() {
- // Start this in a different thread, so that the dataCallback can return
- LOGV("restartPreview");
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
- pthread_t threadPreview;
- pthread_create(&threadPreview, &attr, ThreadStartPreviewWrapper, this);
- pthread_attr_destroy(&attr);
-}
-
-sp<IMemory> CameraSourceTimeLapse::cropYUVImage(const sp<IMemory> &source_data) {
- // find the YUV format
- int32_t srcFormat;
- CHECK(mMeta->findInt32(kKeyColorFormat, &srcFormat));
- YUVImage::YUVFormat yuvFormat;
- if (srcFormat == OMX_COLOR_FormatYUV420SemiPlanar) {
- yuvFormat = YUVImage::YUV420SemiPlanar;
- } else {
- CHECK_EQ(srcFormat, OMX_COLOR_FormatYUV420Planar);
- yuvFormat = YUVImage::YUV420Planar;
- }
-
- // allocate memory for cropped image and setup a canvas using it.
- sp<IMemory> croppedImageMemory = allocateIMemory(
- YUVImage::bufferSize(yuvFormat, mVideoWidth, mVideoHeight));
- YUVImage yuvImageCropped(yuvFormat,
- mVideoWidth, mVideoHeight,
- (uint8_t *)croppedImageMemory->pointer());
- YUVCanvas yuvCanvasCrop(yuvImageCropped);
-
- YUVImage yuvImageSource(yuvFormat,
- mPictureWidth, mPictureHeight,
- (uint8_t *)source_data->pointer());
- yuvCanvasCrop.CopyImageRect(
- Rect(mCropRectStartX, mCropRectStartY,
- mCropRectStartX + mVideoWidth,
- mCropRectStartY + mVideoHeight),
- 0, 0,
- yuvImageSource);
-
- return croppedImageMemory;
-}
-
-void CameraSourceTimeLapse::dataCallback(int32_t msgType, const sp<IMemory> &data) {
- if (msgType == CAMERA_MSG_COMPRESSED_IMAGE) {
- // takePicture will complete after this callback, so restart preview.
- restartPreview();
- return;
- }
- if (msgType != CAMERA_MSG_RAW_IMAGE) {
- return;
- }
-
- LOGV("dataCallback for timelapse still frame");
- CHECK_EQ(true, mUseStillCameraForTimeLapse);
-
- int64_t timestampUs;
- if (mNumFramesReceived == 0) {
- timestampUs = mStartTimeUs;
- } else {
- timestampUs = mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
- }
-
- if (mNeedCropping) {
- sp<IMemory> croppedImageData = cropYUVImage(data);
- dataCallbackTimestamp(timestampUs, msgType, croppedImageData);
- } else {
- sp<IMemory> dataCopy = createIMemoryCopy(data);
- dataCallbackTimestamp(timestampUs, msgType, dataCopy);
- }
-}
-
bool CameraSourceTimeLapse::skipCurrentFrame(int64_t timestampUs) {
+ LOGV("skipCurrentFrame");
if (mSkipCurrentFrame) {
mSkipCurrentFrame = false;
return true;
@@ -468,72 +237,58 @@
}
bool CameraSourceTimeLapse::skipFrameAndModifyTimeStamp(int64_t *timestampUs) {
- if (!mUseStillCameraForTimeLapse) {
- if (mLastTimeLapseFrameRealTimestampUs == 0) {
- // First time lapse frame. Initialize mLastTimeLapseFrameRealTimestampUs
- // to current time (timestampUs) and save frame data.
- LOGV("dataCallbackTimestamp timelapse: initial frame");
+ LOGV("skipFrameAndModifyTimeStamp");
+ if (mLastTimeLapseFrameRealTimestampUs == 0) {
+ // First time lapse frame. Initialize mLastTimeLapseFrameRealTimestampUs
+ // to current time (timestampUs) and save frame data.
+ LOGV("dataCallbackTimestamp timelapse: initial frame");
- mLastTimeLapseFrameRealTimestampUs = *timestampUs;
+ mLastTimeLapseFrameRealTimestampUs = *timestampUs;
+ return false;
+ }
+
+ {
+ Mutex::Autolock autoLock(mQuickStopLock);
+
+ // mForceRead may be set to true by startQuickReadReturns(). In that
+ // case don't skip this frame.
+ if (mForceRead) {
+ LOGV("dataCallbackTimestamp timelapse: forced read");
+ mForceRead = false;
+ *timestampUs =
+ mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
return false;
}
+ }
- {
- Mutex::Autolock autoLock(mQuickStopLock);
+ // Workaround to bypass the first 2 input frames for skipping.
+ // The first 2 output frames from the encoder are: decoder specific info and
+ // the compressed video frame data for the first input video frame.
+ if (mNumFramesEncoded >= 1 && *timestampUs <
+ (mLastTimeLapseFrameRealTimestampUs + mTimeBetweenTimeLapseFrameCaptureUs)) {
+ // Skip all frames from last encoded frame until
+ // sufficient time (mTimeBetweenTimeLapseFrameCaptureUs) has passed.
+ // Tell the camera to release its recording frame and return.
+ LOGV("dataCallbackTimestamp timelapse: skipping intermediate frame");
+ return true;
+ } else {
+ // Desired frame has arrived after mTimeBetweenTimeLapseFrameCaptureUs time:
+ // - Reset mLastTimeLapseFrameRealTimestampUs to current time.
+ // - Artificially modify timestampUs to be one frame time (1/framerate) ahead
+ // of the last encoded frame's time stamp.
+ LOGV("dataCallbackTimestamp timelapse: got timelapse frame");
- // mForceRead may be set to true by startQuickReadReturns(). In that
- // case don't skip this frame.
- if (mForceRead) {
- LOGV("dataCallbackTimestamp timelapse: forced read");
- mForceRead = false;
- *timestampUs =
- mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
- return false;
- }
- }
-
- // Workaround to bypass the first 2 input frames for skipping.
- // The first 2 output frames from the encoder are: decoder specific info and
- // the compressed video frame data for the first input video frame.
- if (mNumFramesEncoded >= 1 && *timestampUs <
- (mLastTimeLapseFrameRealTimestampUs + mTimeBetweenTimeLapseFrameCaptureUs)) {
- // Skip all frames from last encoded frame until
- // sufficient time (mTimeBetweenTimeLapseFrameCaptureUs) has passed.
- // Tell the camera to release its recording frame and return.
- LOGV("dataCallbackTimestamp timelapse: skipping intermediate frame");
- return true;
- } else {
- // Desired frame has arrived after mTimeBetweenTimeLapseFrameCaptureUs time:
- // - Reset mLastTimeLapseFrameRealTimestampUs to current time.
- // - Artificially modify timestampUs to be one frame time (1/framerate) ahead
- // of the last encoded frame's time stamp.
- LOGV("dataCallbackTimestamp timelapse: got timelapse frame");
-
- mLastTimeLapseFrameRealTimestampUs = *timestampUs;
- *timestampUs = mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
- return false;
- }
+ mLastTimeLapseFrameRealTimestampUs = *timestampUs;
+ *timestampUs = mLastFrameTimestampUs + mTimeBetweenTimeLapseVideoFramesUs;
+ return false;
}
return false;
}
void CameraSourceTimeLapse::dataCallbackTimestamp(int64_t timestampUs, int32_t msgType,
const sp<IMemory> &data) {
- if (!mUseStillCameraForTimeLapse) {
- mSkipCurrentFrame = skipFrameAndModifyTimeStamp(×tampUs);
- } else {
- Mutex::Autolock autoLock(mCameraIdleLock);
- // If we are using the still camera and stop() has been called, it may
- // be waiting for the camera to get idle. In that case return
- // immediately. Calling CameraSource::dataCallbackTimestamp() will lead
- // to a deadlock since it tries to access CameraSource::mLock which in
- // this case is held by CameraSource::stop() currently waiting for the
- // camera to get idle. And camera will not get idle until this call
- // returns.
- if (mStopWaitingForIdleCamera) {
- return;
- }
- }
+ LOGV("dataCallbackTimestamp");
+ mSkipCurrentFrame = skipFrameAndModifyTimeStamp(×tampUs);
CameraSource::dataCallbackTimestamp(timestampUs, msgType, data);
}
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 @@
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::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 @@
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::onFetch() {
LOGV("onFetch");
- if (mFinalStatus != OK) {
+ if (mFinalStatus != OK && mNumRetriesLeft == 0) {
LOGV("EOS reached, done prefetching for now");
mFetching = false;
}
@@ -308,8 +338,19 @@
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 @@
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_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 @@
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 @@
status_t OMXCodec::read(
MediaBuffer **buffer, const ReadOptions *options) {
+ status_t err = OK;
*buffer = NULL;
Mutex::Autolock autoLock(mLock);
@@ -3663,7 +3678,9 @@
if (seeking) {
while (mState == RECONFIGURING) {
- mBufferFilled.wait(mLock);
+ if ((err = waitForBufferFilled_l()) != OK) {
+ return err;
+ }
}
if (mState != EXECUTING) {
@@ -3694,19 +3711,15 @@
}
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 @@
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..3d8c56a
--- /dev/null
+++ b/media/libstagefright/SurfaceMediaSource.cpp
@@ -0,0 +1,792 @@
+/*
+ * 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 <media/stagefright/MetadataBufferType.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. Pass in only the metadata
+ passMetadataBufferLocked(buffer);
+
+ (*buffer)->setObserver(this);
+ (*buffer)->add_ref();
+ (*buffer)->meta_data()->setInt64(kKeyTime, mCurrentTimestamp);
+
+ return OK;
+}
+
+// Pass the data to the MediaBuffer. Pass in only the metadata
+// The metadata passed consists of two parts:
+// 1. First, there is an integer indicating that it is a GRAlloc
+// source (kMetadataBufferTypeGrallocSource)
+// 2. This is followed by the buffer_handle_t that is a handle to the
+// GRalloc buffer. The encoder needs to interpret this GRalloc handle
+// and encode the frames.
+// --------------------------------------------------------------
+// | kMetadataBufferTypeGrallocSource | sizeof(buffer_handle_t) |
+// --------------------------------------------------------------
+// Note: Call only when you have the lock
+void SurfaceMediaSource::passMetadataBufferLocked(MediaBuffer **buffer) {
+ LOGV("passMetadataBuffer");
+ // MediaBuffer allocates and owns this data
+ MediaBuffer *tempBuffer =
+ new MediaBuffer(4 + sizeof(buffer_handle_t));
+ char *data = (char *)tempBuffer->data();
+ if (data == NULL) {
+ LOGE("Cannot allocate memory for passing buffer metadata!");
+ return;
+ }
+ OMX_U32 type = kMetadataBufferTypeGrallocSource;
+ memcpy(data, &type, 4);
+ memcpy(data + 4, &(mCurrentBuf->handle), sizeof(buffer_handle_t));
+ *buffer = tempBuffer;
+}
+
+
+void SurfaceMediaSource::signalBufferReturned(MediaBuffer *buffer) {
+ LOGV("signalBufferReturned");
+
+ bool foundBuffer = false;
+ Mutex::Autolock autoLock(mMutex);
+
+ if (!mStarted) {
+ LOGW("signalBufferReturned: mStarted = false! Nothing to do!");
+ return;
+ }
+
+ for (Fifo::iterator it = mQueue.begin(); it != mQueue.end(); ++it) {
+ CHECK(mSlots[*it].mGraphicBuffer != NULL);
+ if (checkBufferMatchesSlot(*it, buffer)) {
+ 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");
+ }
+}
+
+bool SurfaceMediaSource::checkBufferMatchesSlot(int slot, MediaBuffer *buffer) {
+ LOGV("Check if Buffer matches slot");
+ // need to convert to char* for pointer arithmetic and then
+ // copy the byte stream into our handle
+ buffer_handle_t bufferHandle ;
+ memcpy( &bufferHandle, (char *)(buffer->data()) + 4, sizeof(buffer_handle_t));
+ return mSlots[slot].mGraphicBuffer->handle == bufferHandle;
+}
+
+
+} // 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 @@
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 @@
mState = DISCONNECTED;
mCondition.broadcast();
- mURI.clear();
+ // mURI.clear();
mIOResult = err;
@@ -150,9 +152,19 @@
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;
KeyedVector<String8, String8> tmpHeaders = mHeaders;
@@ -236,7 +248,7 @@
CHECK_EQ((int)mState, (int)DISCONNECTING);
mState = DISCONNECTED;
- mURI.clear();
+ // mURI.clear();
mCondition.broadcast();
@@ -299,5 +311,21 @@
}
}
+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 @@
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 @@
kWhatRead = 'read',
};
+ enum {
+ kMaxNumRetries = 10,
+ };
+
sp<DataSource> mSource;
sp<AHandlerReflector<NuCachedSource2> > mReflector;
sp<ALooper> mLooper;
@@ -93,6 +97,8 @@
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..dc6f2c9
--- /dev/null
+++ b/media/libstagefright/tests/SurfaceMediaSource_test.cpp
@@ -0,0 +1,348 @@
+/*
+ * 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;
+ const int mYuvTexHeight;
+
+ 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);
+
+
+ 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));
+ 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));
+ 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));
+ 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/layout-sw600dp/compat_mode_help.xml b/packages/SystemUI/res/layout-sw600dp/compat_mode_help.xml
index d29e495..a354336 100644
--- a/packages/SystemUI/res/layout-sw600dp/compat_mode_help.xml
+++ b/packages/SystemUI/res/layout-sw600dp/compat_mode_help.xml
@@ -43,6 +43,7 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/compat_mode_help_diagram"
+ android:contentDescription="@string/accessibility_compatibility_zoom_example"
/>
<RelativeLayout
android:orientation="horizontal"
@@ -61,6 +62,7 @@
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/compat_mode_help_icon"
+ android:contentDescription="@string/accessibility_compatibility_zoom_button"
/>
<TextView
android:id="@+id/explanation"
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar.xml b/packages/SystemUI/res/layout-sw600dp/status_bar.xml
index d9f3f23..a2a6473 100644
--- a/packages/SystemUI/res/layout-sw600dp/status_bar.xml
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar.xml
@@ -49,6 +49,7 @@
android:src="@drawable/ic_sysbar_back"
android:layout_alignParentLeft="true"
systemui:keyCode="4"
+ android:contentDescription="@string/accessibility_back"
/>
<LinearLayout
android:id="@+id/navigationArea"
@@ -62,11 +63,13 @@
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_home"
systemui:keyCode="3"
+ android:contentDescription="@string/accessibility_home"
/>
<ImageView android:id="@+id/recent_apps"
android:layout_width="80dip"
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_recent"
+ android:contentDescription="@string/accessibility_menu"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/menu"
android:layout_width="80dip"
@@ -74,6 +77,7 @@
android:src="@drawable/ic_sysbar_menu"
systemui:keyCode="82"
android:visibility="invisible"
+ android:contentDescription="@string/accessibility_menu"
/>
</LinearLayout>
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_input_methods_item.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_input_methods_item.xml
index 3fef7e0..41a20fb 100644
--- a/packages/SystemUI/res/layout-sw600dp/status_bar_input_methods_item.xml
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_input_methods_item.xml
@@ -53,7 +53,8 @@
android:id="@+id/item_icon"
android:layout_width="@android:dimen/app_icon_size"
android:layout_height="wrap_content"
- android:scaleType="fitCenter" />
+ android:scaleType="fitCenter"
+ android:contentDescription="@null" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0px"
@@ -94,7 +95,8 @@
android:visibility="visible"
android:clickable="true"
android:focusable="true"
- android:background="?android:attr/selectableItemBackground" />
+ android:background="?android:attr/selectableItemBackground"
+ android:contentDescription="@string/accessibility_settings_button" />
</LinearLayout>
<View
android:layout_width="match_parent"
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_area.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_area.xml
index fecfe7f..1e3099dc 100644
--- a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_area.xml
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_area.xml
@@ -16,7 +16,7 @@
-->
<!-- notification icons & panel access -->
-<LinearLayout
+<com.android.systemui.statusbar.tablet.NotificationArea
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
android:id="@+id/notificationArea"
@@ -40,6 +40,7 @@
android:layout_marginLeft="8dip"
android:src="@drawable/ic_sysbar_ime_default"
android:visibility="gone"
+ android:contentDescription="@string/accessibility_ime_switch_button"
/>
<com.android.systemui.statusbar.policy.CompatModeButton
@@ -49,6 +50,7 @@
android:layout_marginLeft="8dip"
android:src="@drawable/ic_sysbar_zoom"
android:visibility="gone"
+ android:contentDescription="@string/accessibility_compatibility_zoom_button"
/>
<com.android.systemui.statusbar.tablet.NotificationIconArea
@@ -152,4 +154,4 @@
/>
</LinearLayout>
</LinearLayout>
-</LinearLayout>
+</com.android.systemui.statusbar.tablet.NotificationArea>
diff --git a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_panel_title.xml b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_panel_title.xml
index 543f4ed..bbb2bc6 100644
--- a/packages/SystemUI/res/layout-sw600dp/status_bar_notification_panel_title.xml
+++ b/packages/SystemUI/res/layout-sw600dp/status_bar_notification_panel_title.xml
@@ -14,15 +14,17 @@
limitations under the License.
-->
-<RelativeLayout
+<com.android.systemui.statusbar.tablet.NotificationPanelTitle
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui"
android:id="@+id/title_area"
- android:layout_width="0dp"
- android:layout_height="0dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:clickable="true"
android:orientation="vertical"
android:background="@drawable/notify_panel_clock_bg"
>
+
<LinearLayout
android:id="@+id/icons"
android:layout_width="wrap_content"
@@ -34,6 +36,7 @@
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
>
+
<ImageView
android:id="@+id/bluetooth"
android:layout_height="32dp"
@@ -41,6 +44,7 @@
android:scaleType="centerInside"
android:baseline="22dp"
android:visibility="gone"
+ android:contentDescription="@null"
/>
<FrameLayout
@@ -49,21 +53,28 @@
android:layout_width="32dp"
android:layout_marginRight="4dp"
>
+
<ImageView
android:id="@+id/network_signal"
android:layout_height="match_parent"
android:layout_width="match_parent"
+ android:contentDescription="@null"
/>
+
<ImageView
android:id="@+id/network_type"
android:layout_height="match_parent"
android:layout_width="match_parent"
+ android:contentDescription="@null"
/>
+
<ImageView
android:id="@+id/network_direction"
android:layout_height="match_parent"
android:layout_width="match_parent"
+ android:contentDescription="@null"
/>
+
</FrameLayout>
<TextView
@@ -86,6 +97,7 @@
android:layout_toRightOf="@id/network_text"
android:layout_alignBaseline="@id/network_signal"
android:baseline="22dp"
+ android:contentDescription="@null"
/>
<TextView
@@ -110,6 +122,7 @@
android:paddingRight="16dp"
android:src="@drawable/ic_sysbar_quicksettings"
android:baseline="21dp"
+ android:contentDescription="@string/accessibility_settings_button"
/>
<ImageView
@@ -122,6 +135,7 @@
android:src="@drawable/ic_notification_open"
android:baseline="21dp"
android:visibility="invisible"
+ android:contentDescription="@string/accessibility_notifications_button"
/>
<View
@@ -138,7 +152,7 @@
<com.android.systemui.statusbar.tablet.HoloClock
android:id="@+id/clock"
android:layout_height="wrap_content"
- android:layout_width="match_parent"
+ android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_above="@id/title_divider"
android:layout_marginRight="6dip"
@@ -164,19 +178,11 @@
android:id="@+id/date"
style="@style/StatusBarNotificationText"
android:layout_height="wrap_content"
- android:layout_width="120dp"
+ android:layout_width="wrap_content"
android:layout_alignBottom="@id/clock"
android:layout_alignParentLeft="true"
android:gravity="left"
android:layout_marginLeft="32dp"
/>
- <view
- class="com.android.systemui.statusbar.tablet.NotificationPanel$ModeToggle"
- android:id="@+id/mode_toggle"
- android:background="@null"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:clickable="true"
- />
-</RelativeLayout>
+</com.android.systemui.statusbar.tablet.NotificationPanelTitle>
diff --git a/packages/SystemUI/res/layout/navigation_bar.xml b/packages/SystemUI/res/layout/navigation_bar.xml
index 51e7d97..5d7e8de 100644
--- a/packages/SystemUI/res/layout/navigation_bar.xml
+++ b/packages/SystemUI/res/layout/navigation_bar.xml
@@ -54,6 +54,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
+ android:contentDescription="@string/accessibility_back"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
android:layout_width="80dp"
@@ -66,6 +67,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
+ android:contentDescription="@string/accessibility_home"
/>
<ImageView android:id="@+id/recent_apps"
android:layout_width="80dp"
@@ -80,6 +82,7 @@
systemui:keyCode="82"
android:layout_weight="0"
android:visibility="invisible"
+ android:contentDescription="@string/accessibility_menu"
/>
</LinearLayout>
@@ -124,6 +127,7 @@
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
+ android:contentDescription="@string/accessibility_menu"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
android:layout_height="80dp"
@@ -131,11 +135,13 @@
android:src="@drawable/ic_sysbar_home_default_land"
systemui:keyCode="3"
android:layout_weight="0"
+ android:contentDescription="@string/accessibility_home"
/>
<View
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1"
+ android:contentDescription="@string/accessibility_back"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
android:layout_height="80dp"
@@ -148,6 +154,7 @@
android:layout_height="40dp"
android:layout_width="match_parent"
android:layout_weight="0"
+ android:contentDescription="@string/accessibility_menu"
/>
</LinearLayout>
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 01cf2dc..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,5 +168,135 @@
<!-- 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>
+ <!-- Label for the MTP USB function in UsbPreferenceActivity. [CHAR LIMIT=50] -->
+ <string name="use_mtp_button_title">Mount as a media player (MTP)</string>
+ <!-- Label for the PTP USB function in UsbPreferenceActivity. [CHAR LIMIT=50] -->
+ <string name="use_ptp_button_title">Mount as a camera (PTP)</string>
+ <!-- Label for the installer CD image option in UsbPreferenceActivity. [CHAR LIMIT=50] -->
+ <string name="installer_cd_button_title">Install Android File Transfer application for Mac</string>
+
+ <!-- Content description of the back button for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_back">Back</string>
+ <!-- Content description of the home button for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_home">Home</string>
+ <!-- Content description of the menu button for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_menu">Menu</string>
+
+ <!-- Content description of the switch input method button for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_ime_switch_button">Switch input method button.</string>
+ <!-- Content description of the compatibility zoom button for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_compatibility_zoom_button">Compatibility zoom button.</string>
+
+ <!-- Content description of picture of the compatibility zoom example for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_compatibility_zoom_example">Zoom smaller to larger screen.</string>
+
+ <!-- Content description of the bluetooth icon when connected for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_bluetooth_connected">Bluetooth connected.</string>
+ <!-- Content description of the bluetooth icon when connecting for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_bluetooth_disconnected">Bluetooth disconnected.</string>
+
+ <!-- Content description of the battery when no battery for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_no_battery">No battery.</string>
+ <!-- Content description of the battery when it is one bar for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_battery_one_bar">Battery one bar.</string>
+ <!-- Content description of the battery when it is two bars for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_battery_two_bars">Battery two bars.</string>
+ <!-- Content description of the battery when it is three bars for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_battery_three_bars">Battery three bars.</string>
+ <!-- Content description of the battery when it is full for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_battery_full">Battery full.</string>
+
+ <!-- Content description of the phone signal when no signal for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_no_phone">No phone.</string>
+ <!-- Content description of the phone signal when it is one bar for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_phone_one_bar">Phone one bar.</string>
+ <!-- Content description of the phone signal when it is two bars for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_phone_two_bars">Phone two bars.</string>
+ <!-- Content description of the phone signal when it is three bars for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_phone_three_bars">Phone three bars.</string>
+ <!-- Content description of the phone signal when it is full for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_phone_signal_full">Phone signal full.</string>
+
+ <!-- Content description of the data signal when no signal for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_no_data">No data.</string>
+ <!-- Content description of the data signal when it is one bar for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_one_bar">Data one bar.</string>
+ <!-- Content description of the data signal when it is two bars for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_two_bars">Data two bars.</string>
+ <!-- Content description of the data signal when it is three bars for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_three_bars">Data three bars.</string>
+ <!-- Content description of the data signal when it is full for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_signal_full">Data signal full.</string>
+
+ <!-- Content description of the WIFI signal when no signal for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_no_wifi">No WiFi.</string>
+ <!-- Content description of the WIFI signal when it is one bar for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_wifi_one_bar">WiFi one bar.</string>
+ <!-- Content description of the WIFI signal when it is two bars for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_wifi_two_bars">WiFi two bars.</string>
+ <!-- Content description of the WIFI signal when it is three bars for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_wifi_three_bars">WiFi three bars.</string>
+ <!-- Content description of the WIFI signal when it is full for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_wifi_signal_full">WiFi signal full.</string>
+
+ <!-- Content description of the data connection type GPRS for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_connection_gprs">GPRS</string>
+
+ <!-- Content description of the data connection type 3G for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_connection_3g">3G</string>
+
+ <!-- Content description of the data connection type 3.5G for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_connection_3.5g">3.5G</string>
+
+ <!-- Content description of the data connection type 4G for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_connection_4g">4G</string>
+
+ <!-- Content description of the data connection type CDMA for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_connection_cdma">CDMA</string>
+
+ <!-- Content description of the data connection type Edge for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_connection_edge">Edge</string>
+
+ <!-- Content description of the data connection type WiFi for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_data_connection_wifi">WiFi</string>
+
+ <!-- Content description of the data connection with no SIM for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_no_sim">No SIM.</string>
+
+ <!-- Content description of the bluetooth tethering icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_bluetooth_tether">Bluetooth tethering.</string>
+
+ <!-- Content description of the airplane mode icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_airplane_mode">Airplane mode.</string>
+
+ <!-- Content description of the battery level icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_battery_level">Battery <xliff:g id="number">%d</xliff:g> percent.</string>
+
+ <!-- Content description of the button for showing a settings panel in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_settings_button">Settings button.</string>
+
+ <!-- Content description of the button for showing a notifications panel in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_notifications_button">Notifications button.</string>
+
+ <!-- Content description of the button for removing a notification in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_remove_notification">Remove notification.</string>
+
+ <!-- Content description of the enabled GPS icon in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_gps_enabled">GPS enabled.</string>
+
+ <!-- Content description of the acquiring GPS icon in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_gps_acquiring">GPS acquiring.</string>
+
+ <!-- Content description of the TeleTypewriter(TTY) enabled icon in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_tty_enabled">TeleTypewriter enabled.</string>
+
+ <!-- Content description of the ringer vibrate icon in the notification panel for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
+ <string name="accessibility_ringer_vibrate">Ringer vibrate.</string>
+
+ <!-- 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/SwipeHelper.java b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
new file mode 100644
index 0000000..eaffd1a
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/SwipeHelper.java
@@ -0,0 +1,317 @@
+/*
+ * 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.systemui;
+
+import android.animation.Animator;
+import android.animation.ObjectAnimator;
+import android.animation.Animator.AnimatorListener;
+import android.animation.ValueAnimator;
+import android.animation.ValueAnimator.AnimatorUpdateListener;
+import android.graphics.RectF;
+import android.util.Log;
+import android.view.animation.LinearInterpolator;
+import android.view.MotionEvent;
+import android.view.VelocityTracker;
+import android.view.View;
+
+public class SwipeHelper {
+ static final String TAG = "com.android.systemui.SwipeHelper";
+ private static final boolean DEBUG = true;
+ private static final boolean DEBUG_INVALIDATE = false;
+ private static final boolean SLOW_ANIMATIONS = false; // DEBUG;
+
+ public static final int X = 0;
+ public static final int Y = 1;
+
+ private boolean CONSTRAIN_SWIPE = true;
+ private boolean FADE_OUT_DURING_SWIPE = true;
+ private boolean DISMISS_IF_SWIPED_FAR_ENOUGH = true;
+
+ private float SWIPE_ESCAPE_VELOCITY = 100f; // dp/sec
+ private int MAX_ESCAPE_ANIMATION_DURATION = 500; // ms
+ private static final int SNAP_ANIM_LEN = SLOW_ANIMATIONS ? 1000 : 250; // ms
+
+ public static float ALPHA_FADE_START = 0.8f; // fraction of thumbnail width
+ // where fade starts
+ static final float ALPHA_FADE_END = 0.5f; // fraction of thumbnail width
+ // beyond which alpha->0
+
+ private float mPagingTouchSlop;
+ private Callback mCallback;
+ private int mSwipeDirection;
+ private VelocityTracker mVelocityTracker;
+
+ private float mInitialTouchPos;
+ private boolean mDragging;
+ private View mCurrView;
+ private float mDensityScale;
+
+ public SwipeHelper(int swipeDirection, Callback callback, float densityScale,
+ float pagingTouchSlop) {
+ mCallback = callback;
+ mSwipeDirection = swipeDirection;
+ mVelocityTracker = VelocityTracker.obtain();
+ mDensityScale = densityScale;
+ mPagingTouchSlop = pagingTouchSlop;
+ }
+
+ public void setDensityScale(float densityScale) {
+ mDensityScale = densityScale;
+ }
+
+ public void setPagingTouchSlop(float pagingTouchSlop) {
+ mPagingTouchSlop = pagingTouchSlop;
+ }
+
+ private float getPos(MotionEvent ev) {
+ return mSwipeDirection == X ? ev.getX() : ev.getY();
+ }
+
+ private float getPos(View v) {
+ return mSwipeDirection == X ? v.getX() : v.getY();
+ }
+
+ private float getVelocity(VelocityTracker vt) {
+ return mSwipeDirection == X ? vt.getXVelocity() :
+ vt.getYVelocity();
+ }
+
+ private ObjectAnimator createTranslationAnimation(View v, float newPos) {
+ ObjectAnimator anim = ObjectAnimator.ofFloat(v,
+ mSwipeDirection == X ? "translationX" : "translationY", newPos);
+ return anim;
+ }
+
+ private float getPerpendicularVelocity(VelocityTracker vt) {
+ return mSwipeDirection == X ? vt.getYVelocity() :
+ vt.getXVelocity();
+ }
+
+ private void setTranslation(View v, float translate) {
+ if (mSwipeDirection == X) {
+ v.setTranslationX(translate);
+ } else {
+ v.setTranslationY(translate);
+ }
+ }
+
+ private float getSize(View v) {
+ return mSwipeDirection == X ? v.getMeasuredWidth() :
+ v.getMeasuredHeight();
+ }
+
+ private float getContentSize(View v) {
+ View content = mCallback.getChildContentView(v);
+ return getSize(content);
+ }
+
+ private float getAlphaForOffset(View view, float thumbSize) {
+ final float fadeSize = ALPHA_FADE_END * thumbSize;
+ float result = 1.0f;
+ float pos = getPos(view);
+ if (pos >= thumbSize * ALPHA_FADE_START) {
+ result = 1.0f - (pos - thumbSize * ALPHA_FADE_START) / fadeSize;
+ } else if (pos < thumbSize * (1.0f - ALPHA_FADE_START)) {
+ result = 1.0f + (thumbSize * ALPHA_FADE_START + pos) / fadeSize;
+ }
+ return result;
+ }
+
+ void invalidateGlobalRegion(View view) {
+ RectF childBounds = new RectF(view.getLeft(), view.getTop(), view.getRight(), view
+ .getBottom());
+ childBounds.offset(view.getX(), view.getY());
+ if (DEBUG_INVALIDATE)
+ Log.v(TAG, "-------------");
+ while (view.getParent() != null && view.getParent() instanceof View) {
+ view = (View) view.getParent();
+ view.getMatrix().mapRect(childBounds);
+ view.invalidate((int) Math.floor(childBounds.left),
+ (int) Math.floor(childBounds.top),
+ (int) Math.ceil(childBounds.right),
+ (int) Math.ceil(childBounds.bottom));
+ if (DEBUG_INVALIDATE) {
+ Log.v(TAG, "INVALIDATE(" + (int) Math.floor(childBounds.left)
+ + "," + (int) Math.floor(childBounds.top)
+ + "," + (int) Math.ceil(childBounds.right)
+ + "," + (int) Math.ceil(childBounds.bottom));
+ }
+ }
+ }
+
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ final int action = ev.getAction();
+
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ mDragging = false;
+ mCurrView = mCallback.getChildAtPosition(ev);
+ mVelocityTracker.clear();
+ mVelocityTracker.addMovement(ev);
+ mInitialTouchPos = getPos(ev);
+ break;
+ case MotionEvent.ACTION_MOVE:
+ if (mCurrView != null) {
+ mVelocityTracker.addMovement(ev);
+ float pos = getPos(ev);
+ float delta = pos - mInitialTouchPos;
+ if (Math.abs(delta) > mPagingTouchSlop) {
+ mCallback.onBeginDrag(mCurrView);
+ mDragging = true;
+ mInitialTouchPos = getPos(ev) - getPos(mCurrView);
+ }
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ mDragging = false;
+ mCurrView = null;
+ break;
+ }
+ return mDragging;
+ }
+
+ public void dismissChild(final View animView, float velocity) {
+ float newPos;
+ if (velocity < 0 || (velocity == 0 && getPos(animView) < 0)) {
+ newPos = -getSize(animView);
+ } else {
+ newPos = getSize(animView);
+ }
+ int duration = MAX_ESCAPE_ANIMATION_DURATION;
+ if (velocity != 0) {
+ duration = Math.min(duration,
+ (int) (Math.abs(newPos - getPos(animView)) * 1000f / Math
+ .abs(velocity)));
+ }
+ ObjectAnimator anim = createTranslationAnimation(animView, newPos);
+ anim.setInterpolator(new LinearInterpolator());
+ anim.setDuration(duration);
+ anim.addListener(new AnimatorListener() {
+ public void onAnimationStart(Animator animation) {
+ }
+
+ public void onAnimationRepeat(Animator animation) {
+ }
+
+ public void onAnimationEnd(Animator animation) {
+ mCallback.onChildDismissed(animView);
+ }
+
+ public void onAnimationCancel(Animator animation) {
+ mCallback.onChildDismissed(animView);
+ }
+ });
+ anim.addUpdateListener(new AnimatorUpdateListener() {
+ public void onAnimationUpdate(ValueAnimator animation) {
+ if (FADE_OUT_DURING_SWIPE) {
+ animView.setAlpha(getAlphaForOffset(animView, getContentSize(animView)));
+ }
+ invalidateGlobalRegion(animView);
+ }
+ });
+ anim.start();
+ }
+
+ public void snapChild(final View animView, float velocity) {
+ ObjectAnimator anim = createTranslationAnimation(animView, 0);
+ int duration = SNAP_ANIM_LEN;
+ anim.setDuration(duration);
+ anim.addUpdateListener(new AnimatorUpdateListener() {
+ public void onAnimationUpdate(ValueAnimator animation) {
+ if (FADE_OUT_DURING_SWIPE) {
+ animView.setAlpha(getAlphaForOffset(animView, getContentSize(animView)));
+ }
+ invalidateGlobalRegion(animView);
+ }
+ });
+ anim.start();
+ }
+
+ public boolean onTouchEvent(MotionEvent ev) {
+ if (!mDragging) {
+ return false;
+ }
+
+ mVelocityTracker.addMovement(ev);
+ final int action = ev.getAction();
+ switch (action) {
+ case MotionEvent.ACTION_OUTSIDE:
+ case MotionEvent.ACTION_MOVE:
+ if (mCurrView != null) {
+ float delta = getPos(ev) - mInitialTouchPos;
+ // don't let items that can't be dismissed be dragged more than
+ // maxScrollDistance
+ if (CONSTRAIN_SWIPE && !mCallback.canChildBeDismissed(mCurrView)) {
+ float size = getSize(mCurrView);
+ float maxScrollDistance = 0.15f * size;
+ if (Math.abs(delta) >= size) {
+ delta = delta > 0 ? maxScrollDistance : -maxScrollDistance;
+ } else {
+ delta = maxScrollDistance * (float) Math.sin((delta/size)*(Math.PI/2));
+ }
+ }
+ setTranslation(mCurrView, delta);
+ if (FADE_OUT_DURING_SWIPE) {
+ mCurrView.setAlpha(getAlphaForOffset(mCurrView, getContentSize(mCurrView)));
+ }
+ invalidateGlobalRegion(mCurrView);
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ if (mCurrView != null) {
+ float maxVelocity = 1000; // px/sec
+ mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, maxVelocity);
+ float escapeVelocity = SWIPE_ESCAPE_VELOCITY * mDensityScale;
+ float velocity = getVelocity(mVelocityTracker);
+ float perpendicularVelocity = getPerpendicularVelocity(mVelocityTracker);
+
+ // Decide whether to dismiss the current view
+ boolean childSwipedFarEnough = DISMISS_IF_SWIPED_FAR_ENOUGH &&
+ Math.abs(getPos(mCurrView)) > 0.4 * getSize(mCurrView);
+ boolean childSwipedFastEnough = (Math.abs(velocity) > escapeVelocity) &&
+ (Math.abs(velocity) > Math.abs(perpendicularVelocity)) &&
+ (velocity > 0) == (getPos(mCurrView) > 0);
+
+ boolean dismissChild = mCallback.canChildBeDismissed(mCurrView) &&
+ (childSwipedFastEnough || childSwipedFarEnough);
+
+ if (dismissChild) {
+ // flingadingy
+ dismissChild(mCurrView, childSwipedFastEnough ? velocity : 0f);
+ } else {
+ // snappity
+ snapChild(mCurrView, velocity);
+ }
+ }
+ break;
+ }
+ return true;
+ }
+
+ public interface Callback {
+ View getChildAtPosition(MotionEvent ev);
+
+ View getChildContentView(View v);
+
+ boolean canChildBeDismissed(View v);
+
+ void onBeginDrag(View v);
+
+ void onChildDismissed(View v);
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsCallback.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsCallback.java
index 797f94c..5609ead 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsCallback.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsCallback.java
@@ -25,6 +25,6 @@
static final int SWIPE_DOWN = 3;
void handleOnClick(View selectedView);
- void handleSwipe(View selectedView, int direction);
+ void handleSwipe(View selectedView);
void handleLongPress(View selectedView, View anchorView);
}
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
index 2a5d1dd..14efdd0 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsHorizontalScrollView.java
@@ -16,52 +16,35 @@
package com.android.systemui.recent;
-import com.android.systemui.recent.RecentsPanelView.ActivityDescriptionAdapter;
-
-import android.animation.Animator;
-import android.animation.Animator.AnimatorListener;
-import android.animation.AnimatorListenerAdapter;
import android.animation.LayoutTransition;
-import android.animation.ObjectAnimator;
-import android.animation.ValueAnimator;
-import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.Configuration;
import android.database.DataSetObserver;
-import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
-import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
-import android.view.animation.DecelerateInterpolator;
-import android.view.animation.LinearInterpolator;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import com.android.systemui.R;
+import com.android.systemui.SwipeHelper;
+import com.android.systemui.recent.RecentsPanelView.ActivityDescriptionAdapter;
-public class RecentsHorizontalScrollView extends HorizontalScrollView {
+public class RecentsHorizontalScrollView extends HorizontalScrollView
+ implements SwipeHelper.Callback {
private static final String TAG = RecentsPanelView.TAG;
- private static final boolean DEBUG_INVALIDATE = false;
private static final boolean DEBUG = RecentsPanelView.DEBUG;
private LinearLayout mLinearLayout;
private ActivityDescriptionAdapter mAdapter;
private RecentsCallback mCallback;
protected int mLastScrollPosition;
- private View mCurrentView;
- private float mLastY;
- private boolean mDragging;
- private VelocityTracker mVelocityTracker;
- private float mDensityScale;
- private float mPagingTouchSlop;
+ private SwipeHelper mSwipeHelper;
private OnLongClickListener mOnLongClick = new OnLongClickListener() {
public boolean onLongClick(View v) {
final View anchorView = v.findViewById(R.id.app_description);
- mCurrentView = v;
mCallback.handleLongPress(v, anchorView);
- mCurrentView = null; // make sure we don't accept the return click from this
return true;
}
};
@@ -72,8 +55,9 @@
public RecentsHorizontalScrollView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
- mDensityScale = getResources().getDisplayMetrics().density;
- mPagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ float densityScale = getResources().getDisplayMetrics().density;
+ float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ mSwipeHelper = new SwipeHelper(SwipeHelper.Y, this, densityScale, pagingTouchSlop);
}
private int scrollPositionOfMostRecent() {
@@ -84,8 +68,16 @@
mLinearLayout.removeAllViews();
for (int i = 0; i < mAdapter.getCount(); i++) {
final View view = mAdapter.getView(i, null, mLinearLayout);
- view.setClickable(true);
+ view.setLongClickable(true);
view.setOnLongClickListener(mOnLongClick);
+
+ final View thumbnail = getChildContentView(view);
+ // thumbnail is set to clickable in the layout file
+ thumbnail.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ mCallback.handleOnClick(view);
+ }
+ });
mLinearLayout.addView(view);
}
// Scroll to end after layout.
@@ -99,175 +91,52 @@
@Override
public void removeViewInLayout(final View view) {
- ObjectAnimator anim = animateClosed(view, Constants.MAX_ESCAPE_ANIMATION_DURATION,
- "y", view.getY(), view.getY() + view.getHeight());
- anim.addListener(new AnimatorListenerAdapter() {
- public void onAnimationEnd(Animator animation) {
- RecentsHorizontalScrollView.super.removeView(view);
- }
- });
- anim.start();
+ dismissChild(view);
}
- @Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()");
- if (mVelocityTracker == null) {
- mVelocityTracker = VelocityTracker.obtain();
- }
- mVelocityTracker.addMovement(ev);
- switch (ev.getAction()) {
- case MotionEvent.ACTION_DOWN:
- mDragging = false;
- mLastY = ev.getY();
- final float x = ev.getX() + getScrollX();
- final float y = ev.getY() + getScrollY();
- mCurrentView = null;
- for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
- View item = mLinearLayout.getChildAt(i);
- if (x >= item.getLeft() && x < item.getRight()
- && y >= item.getTop() && y < item.getBottom()) {
- mCurrentView = item;
- if (DEBUG) Log.v(TAG, "Hit item " + item);
- break;
- }
- }
- break;
-
- case MotionEvent.ACTION_MOVE:
- float delta = ev.getY() - mLastY;
- if (DEBUG) Log.v(TAG, "ACTION_MOVE : " + delta);
- if (Math.abs(delta) > mPagingTouchSlop) {
- mDragging = true;
- }
- break;
-
- case MotionEvent.ACTION_UP:
- if (mCurrentView != null) {
- mCallback.handleOnClick(mCurrentView);
- }
- mDragging = false;
- break;
- }
- return mDragging ? true : super.onInterceptTouchEvent(ev);
- }
-
- private float getAlphaForOffset(View view, float thumbHeight) {
- final float fadeHeight = Constants.ALPHA_FADE_END * thumbHeight;
- float result = 1.0f;
- if (view.getY() >= thumbHeight * Constants.ALPHA_FADE_START) {
- result = 1.0f - (view.getY() - thumbHeight * Constants.ALPHA_FADE_START) / fadeHeight;
- } else if (view.getY() < thumbHeight * (1.0f - Constants.ALPHA_FADE_START)) {
- result = 1.0f + (thumbHeight * Constants.ALPHA_FADE_START + view.getY()) / fadeHeight;
- }
- return result;
+ return mSwipeHelper.onInterceptTouchEvent(ev) ||
+ super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
- if (!mDragging) {
- return super.onTouchEvent(ev);
- }
+ return mSwipeHelper.onTouchEvent(ev) ||
+ super.onTouchEvent(ev);
+ }
- mVelocityTracker.addMovement(ev);
-
- final View animView = mCurrentView;
-
- switch (ev.getAction()) {
- case MotionEvent.ACTION_MOVE:
- if (animView != null) {
- final float delta = ev.getY() - mLastY;
- final View thumb = animView.findViewById(R.id.app_thumbnail);
- animView.setY(animView.getY() + delta);
- animView.setAlpha(getAlphaForOffset(animView, thumb.getHeight()));
- invalidateGlobalRegion(animView);
- }
- mLastY = ev.getY();
- break;
-
- case MotionEvent.ACTION_UP:
- final ObjectAnimator anim;
- if (animView != null) {
- final VelocityTracker velocityTracker = mVelocityTracker;
- velocityTracker.computeCurrentVelocity(1000, 10000);
- final float velocityX = velocityTracker.getXVelocity();
- final float velocityY = velocityTracker.getYVelocity();
- final float curY = animView.getY();
- final float newY = (velocityY >= 0.0f ? 1 : -1) * animView.getHeight();
- final float maxVelocity = Constants.ESCAPE_VELOCITY * mDensityScale;
- if (Math.abs(velocityY) > Math.abs(velocityX)
- && Math.abs(velocityY) > maxVelocity
- && (velocityY >= 0.0f) == (animView.getY() >= 0)) {
- long duration =
- (long) (Math.abs(newY - curY) * 1000.0f / Math.abs(velocityY));
- duration = Math.min(duration, Constants.MAX_ESCAPE_ANIMATION_DURATION);
- anim = animateClosed(animView, duration, "y", curY, newY);
- } else { // Animate back to position
- long duration = Math.abs(velocityY) > 0.0f ?
- (long) (Math.abs(newY - curY) * 1000.0f / Math.abs(velocityY))
- : Constants.SNAP_BACK_DURATION;
- duration = Math.min(duration, Constants.SNAP_BACK_DURATION);
- anim = ObjectAnimator.ofFloat(animView, "y", animView.getY(), 0.0f);
- anim.setInterpolator(new DecelerateInterpolator(4.0f));
- anim.setDuration(duration);
- }
-
- final View thumb = animView.findViewById(R.id.app_thumbnail);
- anim.addUpdateListener(new AnimatorUpdateListener() {
- public void onAnimationUpdate(ValueAnimator animation) {
- animView.setAlpha(getAlphaForOffset(animView, thumb.getHeight()));
- invalidateGlobalRegion(animView);
- }
- });
- anim.start();
- }
-
- mVelocityTracker.recycle();
- mVelocityTracker = null;
- break;
- }
+ public boolean canChildBeDismissed(View v) {
return true;
}
- private ObjectAnimator animateClosed(final View animView, long duration,
- String attr, float from, float to) {
- ObjectAnimator anim = ObjectAnimator.ofFloat(animView, attr, from, to);
- anim.setInterpolator(new LinearInterpolator());
- final int swipeDirection = animView.getX() >= 0.0f ?
- RecentsCallback.SWIPE_RIGHT : RecentsCallback.SWIPE_LEFT;
- anim.addListener(new AnimatorListenerAdapter() {
- public void onAnimationEnd(Animator animation) {
- mLinearLayout.removeView(animView);
- mCallback.handleSwipe(animView, swipeDirection);
- }
- public void onAnimationCancel(Animator animation) {
- mLinearLayout.removeView(animView);
- mCallback.handleSwipe(animView, swipeDirection);
- }
- });
- anim.setDuration(duration);
- return anim;
+ public void dismissChild(View v) {
+ mSwipeHelper.dismissChild(v, 0);
}
- void invalidateGlobalRegion(View view) {
- RectF childBounds
- = new RectF(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
- childBounds.offset(view.getX(), view.getY());
- if (DEBUG_INVALIDATE) Log.v(TAG, "-------------");
- while (view.getParent() != null && view.getParent() instanceof View) {
- view = (View) view.getParent();
- view.getMatrix().mapRect(childBounds);
- view.invalidate((int) Math.floor(childBounds.left),
- (int) Math.floor(childBounds.top),
- (int) Math.ceil(childBounds.right),
- (int) Math.ceil(childBounds.bottom));
- if (DEBUG_INVALIDATE) {
- Log.v(TAG, "INVALIDATE(" + (int) Math.floor(childBounds.left)
- + "," + (int) Math.floor(childBounds.top)
- + "," + (int) Math.ceil(childBounds.right)
- + "," + (int) Math.ceil(childBounds.bottom));
+ public void onChildDismissed(View v) {
+ mLinearLayout.removeView(v);
+ mCallback.handleSwipe(v);
+ }
+
+ public void onBeginDrag(View v) {
+ }
+
+ public View getChildAtPosition(MotionEvent ev) {
+ final float x = ev.getX() + getScrollX();
+ final float y = ev.getY() + getScrollY();
+ for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
+ View item = mLinearLayout.getChildAt(i);
+ if (x >= item.getLeft() && x < item.getRight()
+ && y >= item.getTop() && y < item.getBottom()) {
+ return item;
}
}
+ return null;
+ }
+
+ public View getChildContentView(View v) {
+ return v.findViewById(R.id.app_thumbnail);
}
@Override
@@ -283,8 +152,10 @@
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- mDensityScale = getResources().getDisplayMetrics().density;
- mPagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ float densityScale = getResources().getDisplayMetrics().density;
+ mSwipeHelper.setDensityScale(densityScale);
+ float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
}
private void setOverScrollEffectPadding(int leftPadding, int i) {
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
index bc0a508..e988b68 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsPanelView.java
@@ -22,7 +22,6 @@
import android.animation.Animator;
import android.animation.LayoutTransition;
import android.app.ActivityManager;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -48,6 +47,7 @@
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@@ -112,7 +112,7 @@
position = _pos;
packageName = _packageName;
}
- };
+ }
private final class OnLongClickDelegate implements View.OnLongClickListener {
View mOtherView;
@@ -252,6 +252,19 @@
mChoreo.setPanelHeight(mRecentsContainer.getHeight());
}
+ @Override
+ public boolean dispatchHoverEvent(MotionEvent event) {
+ // Ignore hover events outside of this panel bounds since such events
+ // generate spurious accessibility events with the panel content when
+ // tapping outside of it, thus confusing the user.
+ final int x = (int) event.getX();
+ final int y = (int) event.getY();
+ if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
+ return super.dispatchHoverEvent(event);
+ }
+ return true;
+ }
+
/**
* Whether the panel is showing, or, if it's animating, whether it will be
* when the animation is done.
@@ -516,7 +529,7 @@
handleOnClick(view);
}
- public void handleSwipe(View view, int direction) {
+ public void handleSwipe(View view) {
ActivityDescription ad = ((ViewHolder) view.getTag()).activityDescription;
if (DEBUG) Log.v(TAG, "Jettison " + ad.label);
mActivityDescriptions.remove(ad);
diff --git a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
index 47ee4aa..1bcc413 100644
--- a/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
+++ b/packages/SystemUI/src/com/android/systemui/recent/RecentsVerticalScrollView.java
@@ -16,53 +16,35 @@
package com.android.systemui.recent;
-import com.android.systemui.recent.RecentsPanelView.ActivityDescriptionAdapter;
-
-import android.animation.Animator;
-import android.animation.Animator.AnimatorListener;
-import android.animation.AnimatorListenerAdapter;
import android.animation.LayoutTransition;
-import android.animation.ObjectAnimator;
-import android.animation.ValueAnimator;
-import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.Configuration;
import android.database.DataSetObserver;
-import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
-import android.view.LayoutInflater;
import android.view.MotionEvent;
-import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
-import android.view.animation.DecelerateInterpolator;
-import android.view.animation.LinearInterpolator;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import com.android.systemui.R;
+import com.android.systemui.SwipeHelper;
+import com.android.systemui.recent.RecentsPanelView.ActivityDescriptionAdapter;
-public class RecentsVerticalScrollView extends ScrollView {
+public class RecentsVerticalScrollView extends ScrollView implements SwipeHelper.Callback {
private static final String TAG = RecentsPanelView.TAG;
- private static final boolean DEBUG_INVALIDATE = false;
private static final boolean DEBUG = RecentsPanelView.DEBUG;
private LinearLayout mLinearLayout;
private ActivityDescriptionAdapter mAdapter;
private RecentsCallback mCallback;
protected int mLastScrollPosition;
- private View mCurrentView;
- private float mLastX;
- private boolean mDragging;
- private VelocityTracker mVelocityTracker;
- private float mDensityScale;
- private float mPagingTouchSlop;
+ private SwipeHelper mSwipeHelper;
+
private OnLongClickListener mOnLongClick = new OnLongClickListener() {
public boolean onLongClick(View v) {
final View anchorView = v.findViewById(R.id.app_description);
- mCurrentView = v;
mCallback.handleLongPress(v, anchorView);
- mCurrentView = null; // make sure we don't accept the return click from this
return true;
}
};
@@ -73,8 +55,9 @@
public RecentsVerticalScrollView(Context context, AttributeSet attrs) {
super(context, attrs, 0);
- mDensityScale = getResources().getDisplayMetrics().density;
- mPagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ float densityScale = getResources().getDisplayMetrics().density;
+ float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop);
}
private int scrollPositionOfMostRecent() {
@@ -87,6 +70,15 @@
final View view = mAdapter.getView(i, null, mLinearLayout);
view.setClickable(true);
view.setOnLongClickListener(mOnLongClick);
+
+ final View thumbnail = getChildContentView(view);
+ // thumbnail is set to clickable in the layout file
+ thumbnail.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ mCallback.handleOnClick(view);
+ }
+ });
+
mLinearLayout.addView(view);
}
// Scroll to end after layout.
@@ -100,175 +92,52 @@
@Override
public void removeViewInLayout(final View view) {
- ObjectAnimator anim = animateClosed(view, Constants.MAX_ESCAPE_ANIMATION_DURATION,
- "x", view.getX(), view.getX() + view.getWidth());
- anim.addListener(new AnimatorListenerAdapter() {
- public void onAnimationEnd(Animator animation) {
- RecentsVerticalScrollView.super.removeView(view);
- }
- });
- anim.start();
+ dismissChild(view);
}
- @Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()");
- if (mVelocityTracker == null) {
- mVelocityTracker = VelocityTracker.obtain();
- }
- mVelocityTracker.addMovement(ev);
- switch (ev.getAction()) {
- case MotionEvent.ACTION_DOWN:
- mDragging = false;
- mLastX = ev.getX();
- final float x = ev.getX() + getScrollX();
- final float y = ev.getY() + getScrollY();
- mCurrentView = null;
- for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
- View item = mLinearLayout.getChildAt(i);
- if (x >= item.getLeft() && x < item.getRight()
- && y >= item.getTop() && y < item.getBottom()) {
- mCurrentView = item;
- Log.v(TAG, "Hit item " + item);
- break;
- }
- }
- break;
-
- case MotionEvent.ACTION_MOVE:
- float delta = ev.getX() - mLastX;
- if (DEBUG) Log.v(TAG, "ACTION_MOVE : " + delta);
- if (Math.abs(delta) > mPagingTouchSlop) {
- mDragging = true;
- }
- break;
-
- case MotionEvent.ACTION_UP:
- if (mCurrentView != null) {
- mCallback.handleOnClick(mCurrentView);
- }
- mDragging = false;
- break;
- }
- return mDragging ? true : super.onInterceptTouchEvent(ev);
- }
-
- private float getAlphaForOffset(View view, float thumbWidth) {
- final float fadeWidth = Constants.ALPHA_FADE_END * thumbWidth;
- float result = 1.0f;
- if (view.getX() >= thumbWidth*Constants.ALPHA_FADE_START) {
- result = 1.0f - (view.getX() - thumbWidth*Constants.ALPHA_FADE_START) / fadeWidth;
- } else if (view.getX() < thumbWidth* (1.0f - Constants.ALPHA_FADE_START)) {
- result = 1.0f + (thumbWidth*Constants.ALPHA_FADE_START + view.getX()) / fadeWidth;
- }
- return result;
+ return mSwipeHelper.onInterceptTouchEvent(ev) ||
+ super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
- if (!mDragging) {
- return super.onTouchEvent(ev);
- }
+ return mSwipeHelper.onTouchEvent(ev) ||
+ super.onTouchEvent(ev);
+ }
- mVelocityTracker.addMovement(ev);
-
- final View animView = mCurrentView;
-
- switch (ev.getAction()) {
- case MotionEvent.ACTION_MOVE:
- if (animView != null) {
- final float delta = ev.getX() - mLastX;
- final View thumb = animView.findViewById(R.id.app_thumbnail);
- animView.setX(animView.getX() + delta);
- animView.setAlpha(getAlphaForOffset(animView, thumb.getWidth()));
- invalidateGlobalRegion(animView);
- }
- mLastX = ev.getX();
- break;
-
- case MotionEvent.ACTION_UP:
- final ObjectAnimator anim;
- if (animView != null) {
- final VelocityTracker velocityTracker = mVelocityTracker;
- velocityTracker.computeCurrentVelocity(1000, 10000);
- final float velocityX = velocityTracker.getXVelocity();
- final float velocityY = velocityTracker.getYVelocity();
- final float curX = animView.getX();
- final float newX = (velocityX >= 0.0f ? 1 : -1) * animView.getWidth();
- final float maxVelocity = Constants.ESCAPE_VELOCITY * mDensityScale;
- if (Math.abs(velocityX) > Math.abs(velocityY)
- && Math.abs(velocityX) > maxVelocity
- && (velocityX >= 0.0f) == (animView.getX() >= 0)) {
- long duration =
- (long) (Math.abs(newX-curX) * 1000.0f / Math.abs(velocityX));
- duration = Math.min(duration, Constants.MAX_ESCAPE_ANIMATION_DURATION);
- anim = animateClosed(animView, duration, "x", curX, newX);
- } else { // Animate back to position
- long duration = Math.abs(velocityX) > 0.0f ?
- (long) (Math.abs(newX-curX) * 1000.0f / Math.abs(velocityX))
- : Constants.SNAP_BACK_DURATION;
- duration = Math.min(duration, Constants.SNAP_BACK_DURATION);
- anim = ObjectAnimator.ofFloat(animView, "x", animView.getX(), 0.0f);
- anim.setInterpolator(new DecelerateInterpolator(4.0f));
- anim.setDuration(duration);
- }
-
- final View thumb = animView.findViewById(R.id.app_thumbnail);
- anim.addUpdateListener(new AnimatorUpdateListener() {
- public void onAnimationUpdate(ValueAnimator animation) {
- animView.setAlpha(getAlphaForOffset(animView, thumb.getWidth()));
- invalidateGlobalRegion(animView);
- }
- });
- anim.start();
- }
-
- mVelocityTracker.recycle();
- mVelocityTracker = null;
- break;
- }
+ public boolean canChildBeDismissed(View v) {
return true;
}
- private ObjectAnimator animateClosed(final View animView, long duration,
- String attr, float from, float to) {
- ObjectAnimator anim = ObjectAnimator.ofFloat(animView, attr, from, to);
- anim.setInterpolator(new LinearInterpolator());
- final int swipeDirection = animView.getX() >= 0.0f ?
- RecentsCallback.SWIPE_RIGHT : RecentsCallback.SWIPE_LEFT;
- anim.addListener(new AnimatorListenerAdapter() {
- public void onAnimationEnd(Animator animation) {
- mLinearLayout.removeView(animView);
- mCallback.handleSwipe(animView, swipeDirection);
- }
- public void onAnimationCancel(Animator animation) {
- mLinearLayout.removeView(animView);
- mCallback.handleSwipe(animView, swipeDirection);
- }
- });
- anim.setDuration(duration);
- return anim;
+ public void dismissChild(View v) {
+ mSwipeHelper.dismissChild(v, 0);
}
- void invalidateGlobalRegion(View view) {
- RectF childBounds
- = new RectF(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
- childBounds.offset(view.getX(), view.getY());
- if (DEBUG_INVALIDATE) Log.v(TAG, "-------------");
- while (view.getParent() != null && view.getParent() instanceof View) {
- view = (View) view.getParent();
- view.getMatrix().mapRect(childBounds);
- view.invalidate((int) Math.floor(childBounds.left),
- (int) Math.floor(childBounds.top),
- (int) Math.ceil(childBounds.right),
- (int) Math.ceil(childBounds.bottom));
- if (DEBUG_INVALIDATE) {
- Log.v(TAG, "INVALIDATE(" + (int) Math.floor(childBounds.left)
- + "," + (int) Math.floor(childBounds.top)
- + "," + (int) Math.ceil(childBounds.right)
- + "," + (int) Math.ceil(childBounds.bottom));
+ public void onChildDismissed(View v) {
+ mLinearLayout.removeView(v);
+ mCallback.handleSwipe(v);
+ }
+
+ public void onBeginDrag(View v) {
+ }
+
+ public View getChildAtPosition(MotionEvent ev) {
+ final float x = ev.getX() + getScrollX();
+ final float y = ev.getY() + getScrollY();
+ for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
+ View item = mLinearLayout.getChildAt(i);
+ if (x >= item.getLeft() && x < item.getRight()
+ && y >= item.getTop() && y < item.getBottom()) {
+ return item;
}
}
+ return null;
+ }
+
+ public View getChildContentView(View v) {
+ return v.findViewById(R.id.app_thumbnail);
}
@Override
@@ -284,8 +153,10 @@
@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- mDensityScale = getResources().getDisplayMetrics().density;
- mPagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ float densityScale = getResources().getDisplayMetrics().density;
+ mSwipeHelper.setDensityScale(densityScale);
+ float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
}
private void setOverScrollEffectPadding(int leftPadding, int i) {
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
index 83a5578..3e037c1 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java
@@ -78,7 +78,8 @@
SaveImageInBackgroundData> {
private static final String TAG = "SaveImageInBackgroundTask";
private static final String SCREENSHOTS_DIR_NAME = "Screenshots";
- private static final String SCREENSHOT_FILE_PATH_TEMPLATE = "%s/%s/Screenshot_%s-%d.png";
+ private static final String SCREENSHOT_FILE_NAME_TEMPLATE = "Screenshot_%s.png";
+ private static final String SCREENSHOT_FILE_PATH_TEMPLATE = "%s/%s/%s";
@Override
protected SaveImageInBackgroundData doInBackground(SaveImageInBackgroundData... params) {
@@ -87,20 +88,20 @@
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 date = new SimpleDateFormat("yyyy-MM-dd-kk-mm-ss").format(new Date(currentTime));
String imageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).getAbsolutePath();
- String imageFilePath = String.format(SCREENSHOT_FILE_PATH_TEMPLATE,
- imageDir, SCREENSHOTS_DIR_NAME,
- date, currentTime % 1000);
+ String imageFileName = String.format(SCREENSHOT_FILE_NAME_TEMPLATE, date);
+ String imageFilePath = String.format(SCREENSHOT_FILE_PATH_TEMPLATE, imageDir,
+ SCREENSHOTS_DIR_NAME, imageFileName);
// Save the screenshot to the MediaStore
ContentValues values = new ContentValues();
values.put(MediaStore.Images.ImageColumns.DATA, imageFilePath);
- values.put(MediaStore.Images.ImageColumns.TITLE, "Screenshot");
- values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, "Screenshot");
+ values.put(MediaStore.Images.ImageColumns.TITLE, imageFileName);
+ values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, imageFileName);
values.put(MediaStore.Images.ImageColumns.DATE_TAKEN, currentTime);
values.put(MediaStore.Images.ImageColumns.DATE_ADDED, currentTime);
values.put(MediaStore.Images.ImageColumns.DATE_MODIFIED, currentTime);
@@ -114,7 +115,9 @@
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/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemView.java b/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemView.java
index 64ec063..6419777 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/LatestItemView.java
@@ -18,8 +18,8 @@
import android.content.Context;
import android.util.AttributeSet;
-import android.util.Slog;
-import android.view.MotionEvent;
+import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
import android.widget.FrameLayout;
public class LatestItemView extends FrameLayout {
@@ -27,7 +27,22 @@
super(context, attrs);
}
+ @Override
public void setOnClickListener(OnClickListener l) {
super.setOnClickListener(l);
}
+
+ @Override
+ public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
+ if (super.onRequestSendAccessibilityEvent(child, event)) {
+ // Add a record for the entire layout since its content is somehow small.
+ // The event comes from a leaf view that is interacted with.
+ AccessibilityEvent record = AccessibilityEvent.obtain();
+ onInitializeAccessibilityEvent(record);
+ dispatchPopulateAccessibilityEvent(record);
+ event.appendRecord(record);
+ return true;
+ }
+ return false;
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java
index d9d9c06..be4b395 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar;
+import android.app.Notification;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
@@ -23,11 +24,11 @@
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
+import android.text.TextUtils;
import android.util.Slog;
import android.util.Log;
-import android.view.View;
import android.view.ViewDebug;
-import android.widget.FrameLayout;
+import android.view.accessibility.AccessibilityEvent;
import java.text.NumberFormat;
@@ -45,8 +46,9 @@
private int mNumberX;
private int mNumberY;
private String mNumberText;
+ private Notification mNotification;
- public StatusBarIconView(Context context, String slot) {
+ public StatusBarIconView(Context context, String slot, Notification notification) {
super(context);
final Resources res = context.getResources();
mSlot = slot;
@@ -54,6 +56,8 @@
mNumberPain.setTextAlign(Paint.Align.CENTER);
mNumberPain.setColor(res.getColor(R.drawable.notification_number_text_color));
mNumberPain.setAntiAlias(true);
+ mNotification = notification;
+ setContentDescription(notification);
}
private static boolean streq(String a, String b) {
@@ -83,6 +87,7 @@
final boolean numberEquals = mIcon != null
&& mIcon.number == icon.number;
mIcon = icon.clone();
+ setContentDescription(icon.contentDescription);
if (!iconEquals) {
Drawable drawable = getIcon(icon);
if (drawable == null) {
@@ -159,6 +164,15 @@
return mIcon;
}
+ @Override
+ public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
+ super.onInitializeAccessibilityEvent(event);
+ if (mNotification != null) {
+ event.setParcelableData(mNotification);
+ }
+ }
+
+ @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (mNumberBackground != null) {
@@ -166,6 +180,7 @@
}
}
+ @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
@@ -175,6 +190,7 @@
}
}
+ @Override
protected void debug(int depth) {
super.debug(depth);
Log.d("View", debugIndent(depth) + "slot=" + mSlot);
@@ -213,4 +229,13 @@
mNumberY = h-r.bottom-((dh-r.top-th-r.bottom)/2);
mNumberBackground.setBounds(w-dw, h-dh, w, h);
}
+
+ private void setContentDescription(Notification notification) {
+ if (notification != null) {
+ CharSequence tickerText = notification.tickerText;
+ if (!TextUtils.isEmpty(tickerText)) {
+ setContentDescription(tickerText);
+ }
+ }
+ }
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/IconMerger.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/IconMerger.java
index e1d17a8..f6aa159 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/IconMerger.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/IconMerger.java
@@ -33,7 +33,8 @@
private int mIconSize;
private StatusBarIconView mMoreView;
- private StatusBarIcon mMoreIcon = new StatusBarIcon(null, R.drawable.stat_notify_more, 0);
+ private StatusBarIcon mMoreIcon = new StatusBarIcon(null, R.drawable.stat_notify_more, 0, 0,
+ null);
public IconMerger(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -41,7 +42,7 @@
mIconSize = context.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.status_bar_icon_size);
- mMoreView = new StatusBarIconView(context, "more");
+ mMoreView = new StatusBarIconView(context, "more", null);
mMoreView.set(mMoreIcon);
addView(mMoreView, 0, new LinearLayout.LayoutParams(mIconSize, mIconSize));
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index f4c4bbc..b93ad68 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -472,7 +472,7 @@
public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
if (SPEW) Slog.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
+ " icon=" + icon);
- StatusBarIconView view = new StatusBarIconView(mContext, slot);
+ StatusBarIconView view = new StatusBarIconView(mContext, slot, null);
view.set(icon);
mStatusIcons.addView(view, viewIndex, new LinearLayout.LayoutParams(mIconSize, mIconSize));
}
@@ -607,7 +607,7 @@
// Update the icon.
final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
notification.notification.icon, notification.notification.iconLevel,
- notification.notification.number);
+ notification.notification.number, notification.notification.tickerText);
if (!oldEntry.icon.set(ic)) {
handleNotificationError(key, notification, "Couldn't update icon: " + ic);
return;
@@ -765,9 +765,11 @@
final View expanded = views[2];
// Construct the icon.
final StatusBarIconView iconView = new StatusBarIconView(mContext,
- notification.pkg + "/0x" + Integer.toHexString(notification.id));
+ notification.pkg + "/0x" + Integer.toHexString(notification.id),
+ notification.notification);
final StatusBarIcon ic = new StatusBarIcon(notification.pkg, notification.notification.icon,
- notification.notification.iconLevel, notification.notification.number);
+ notification.notification.iconLevel, notification.notification.number,
+ notification.notification.tickerText);
if (!iconView.set(ic)) {
handleNotificationError(key, notification, "Coulding create icon: " + ic);
return null;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
index af5c72d..7b50985 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java
@@ -18,25 +18,17 @@
import android.app.StatusBarManager;
import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothProfile;
-import android.bluetooth.BluetoothPbap;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.res.TypedArray;
-import android.graphics.PixelFormat;
-import android.graphics.Typeface;
-import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Binder;
import android.os.Handler;
-import android.os.Message;
import android.os.RemoteException;
import android.os.storage.StorageManager;
import android.provider.Settings;
@@ -44,18 +36,7 @@
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
-import android.text.format.DateFormat;
-import android.text.style.CharacterStyle;
-import android.text.style.RelativeSizeSpan;
-import android.text.style.ForegroundColorSpan;
-import android.text.style.StyleSpan;
-import android.text.Spannable;
-import android.text.SpannableStringBuilder;
import android.util.Slog;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
import com.android.internal.app.IBatteryStats;
import com.android.internal.telephony.IccCard;
@@ -63,7 +44,6 @@
import com.android.internal.telephony.cdma.EriInfo;
import com.android.internal.telephony.cdma.TtyIntent;
import com.android.server.am.BatteryStatsService;
-
import com.android.systemui.R;
/**
@@ -447,6 +427,32 @@
R.drawable.stat_sys_data_fully_inandout_1x }
};
+ // Accessibility;
+
+ private static final int[] sPhoneSignalStrength = {
+ R.string.accessibility_no_phone,
+ R.string.accessibility_phone_one_bar,
+ R.string.accessibility_phone_two_bars,
+ R.string.accessibility_phone_three_bars,
+ R.string.accessibility_phone_signal_full
+ };
+
+ private static final int[] sDataConnectionStrength = {
+ R.string.accessibility_no_data,
+ R.string.accessibility_data_one_bar,
+ R.string.accessibility_data_two_bars,
+ R.string.accessibility_data_three_bars,
+ R.string.accessibility_data_signal_full
+ };
+
+ private static final int[] sWifiConnectionStrength = {
+ R.string.accessibility_no_wifi,
+ R.string.accessibility_wifi_one_bar,
+ R.string.accessibility_wifi_two_bars,
+ R.string.accessibility_wifi_three_bars,
+ R.string.accessibility_wifi_signal_full
+ };
+
// Assume it's all good unless we hear otherwise. We don't always seem
// to get broadcasts that it *is* there.
IccCard.State mSimState = IccCard.State.READY;
@@ -546,12 +552,13 @@
new com.android.systemui.usb.StorageNotification(context));
// battery
- mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0);
+ mService.setIcon("battery", com.android.internal.R.drawable.stat_sys_battery_unknown, 0,
+ null);
// phone_signal
mPhone = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
- mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
+ mService.setIcon("phone_signal", mPhoneSignalIconId, 0, null);
// register for phone state notifications.
((TelephonyManager)mContext.getSystemService(Context.TELEPHONY_SERVICE))
@@ -563,24 +570,24 @@
| PhoneStateListener.LISTEN_DATA_ACTIVITY);
// data_connection
- mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0);
+ mService.setIcon("data_connection", R.drawable.stat_sys_data_connected_g, 0, null);
mService.setIconVisibility("data_connection", false);
// wifi
- mService.setIcon("wifi", sWifiSignalImages[0][0], 0);
+ mService.setIcon("wifi", sWifiSignalImages[0][0], 0, null);
mService.setIconVisibility("wifi", false);
// wifi will get updated by the sticky intents
// TTY status
- mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
+ mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0, null);
mService.setIconVisibility("tty", false);
// Cdma Roaming Indicator, ERI
- mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0);
+ mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_0, 0, null);
mService.setIconVisibility("cdma_eri", false);
// bluetooth status
- mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0);
+ mService.setIcon("bluetooth", R.drawable.stat_sys_data_bluetooth, 0, null);
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null) {
mBluetoothEnabled = adapter.isEnabled();
@@ -590,21 +597,23 @@
mService.setIconVisibility("bluetooth", mBluetoothEnabled);
// Gps status
- mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
+ mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0, null);
mService.setIconVisibility("gps", false);
// Alarm clock
- mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0);
+ mService.setIcon("alarm_clock", R.drawable.stat_notify_alarm, 0, null);
mService.setIconVisibility("alarm_clock", false);
// Sync state
- mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0, 0);
- mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error, 0);
+ mService.setIcon("sync_active", com.android.internal.R.drawable.stat_notify_sync_anim0,
+ 0, null);
+ mService.setIcon("sync_failing", com.android.internal.R.drawable.stat_notify_sync_error,
+ 0, null);
mService.setIconVisibility("sync_active", false);
mService.setIconVisibility("sync_failing", false);
// volume
- mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0);
+ mService.setIcon("volume", R.drawable.stat_sys_ringer_silent, 0, null);
mService.setIconVisibility("volume", false);
updateVolume();
@@ -655,7 +664,8 @@
private final void updateBattery(Intent intent) {
final int id = intent.getIntExtra("icon-small", 0);
int level = intent.getIntExtra("level", 0);
- mService.setIcon("battery", id, level);
+ String contentDescription = mContext.getString(R.string.accessibility_battery_level, level);
+ mService.setIcon("battery", id, level, contentDescription);
}
private void updateConnectivity(Intent intent) {
@@ -677,12 +687,16 @@
if (info.isConnected()) {
mIsWifiConnected = true;
int iconId;
+ String contentDescription = null;
if (mLastWifiSignalLevel == -1) {
iconId = sWifiSignalImages[mInetCondition][0];
+ contentDescription = mContext.getString(sWifiConnectionStrength[0]);
} else {
iconId = sWifiSignalImages[mInetCondition][mLastWifiSignalLevel];
- }
- mService.setIcon("wifi", iconId, 0);
+ contentDescription = mContext.getString(
+ sWifiConnectionStrength[mLastWifiSignalLevel]);
+ }
+ mService.setIcon("wifi", iconId, 0, contentDescription);
// Show the icon since wi-fi is connected
mService.setIconVisibility("wifi", true);
} else {
@@ -690,7 +704,8 @@
mIsWifiConnected = false;
int iconId = sWifiSignalImages[0][0];
- mService.setIcon("wifi", iconId, 0);
+ String contentDescription = mContext.getString(R.string.accessibility_no_wifi);
+ mService.setIcon("wifi", iconId, 0, contentDescription);
// Hide the icon since we're not connected
mService.setIconVisibility("wifi", false);
}
@@ -781,6 +796,7 @@
private final void updateSignalStrength() {
int[] iconList;
+ String contentDescription = null;
// Display signal strength while in "emergency calls only" mode
if (mServiceState == null || (!hasService() && !mServiceState.isEmergencyOnly())) {
@@ -788,10 +804,12 @@
if (Settings.System.getInt(mContext.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) == 1) {
mPhoneSignalIconId = R.drawable.stat_sys_signal_flightmode;
+ contentDescription = mContext.getString(R.string.accessibility_airplane_mode);
} else {
mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
+ contentDescription = mContext.getString(R.string.accessibility_no_phone);
}
- mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
+ mService.setIcon("phone_signal", mPhoneSignalIconId, 0, contentDescription);
return;
}
@@ -805,8 +823,11 @@
} else {
iconList = sSignalImages[mInetCondition];
}
- mPhoneSignalIconId = iconList[mSignalStrength.getLevel()];
- mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
+
+ final int signalLevel = mSignalStrength.getLevel();
+ mPhoneSignalIconId = iconList[signalLevel];
+ contentDescription = mContext.getString(sPhoneSignalStrength[signalLevel]);
+ mService.setIcon("phone_signal", mPhoneSignalIconId, 0, contentDescription);
}
private final void updateDataNetType(int net) {
@@ -850,6 +871,7 @@
private final void updateDataIcon() {
int iconId;
+ String contentDescription = null;
boolean visible = true;
if (!isCdma()) {
@@ -870,13 +892,15 @@
iconId = mDataIconList[0];
break;
}
- mService.setIcon("data_connection", iconId, 0);
+ contentDescription = mContext.getString(sDataConnectionStrength[mDataActivity]);
+ mService.setIcon("data_connection", iconId, 0, contentDescription);
} else {
visible = false;
}
} else {
iconId = R.drawable.stat_sys_no_sim;
- mService.setIcon("data_connection", iconId, 0);
+ contentDescription = mContext.getString(R.string.accessibility_no_sim);
+ mService.setIcon("data_connection", iconId, 0, contentDescription);
}
} else {
// CDMA case, mDataActivity can be also DATA_ACTIVITY_DORMANT
@@ -896,7 +920,7 @@
iconId = mDataIconList[0];
break;
}
- mService.setIcon("data_connection", iconId, 0);
+ mService.setIcon("data_connection", iconId, 0, null);
} else {
visible = false;
}
@@ -921,12 +945,19 @@
final int ringerMode = audioManager.getRingerMode();
final boolean visible = ringerMode == AudioManager.RINGER_MODE_SILENT ||
ringerMode == AudioManager.RINGER_MODE_VIBRATE;
- final int iconId = audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)
- ? R.drawable.stat_sys_ringer_vibrate
- : R.drawable.stat_sys_ringer_silent;
+
+ final int iconId;
+ String contentDescription = null;
+ if (audioManager.shouldVibrate(AudioManager.VIBRATE_TYPE_RINGER)) {
+ iconId = R.drawable.stat_sys_ringer_vibrate;
+ contentDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
+ } else {
+ iconId = R.drawable.stat_sys_ringer_silent;
+ contentDescription = mContext.getString(R.string.accessibility_ringer_silent);
+ }
if (visible) {
- mService.setIcon("volume", iconId, 0);
+ mService.setIcon("volume", iconId, 0, contentDescription);
}
if (visible != mVolumeVisible) {
mService.setIconVisibility("volume", visible);
@@ -936,6 +967,7 @@
private final void updateBluetooth(Intent intent) {
int iconId = R.drawable.stat_sys_data_bluetooth;
+ String contentDescription = null;
String action = intent.getAction();
if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
@@ -945,12 +977,16 @@
BluetoothAdapter.STATE_DISCONNECTED);
if (state == BluetoothAdapter.STATE_CONNECTED) {
iconId = R.drawable.stat_sys_data_bluetooth_connected;
+ contentDescription = mContext.getString(R.string.accessibility_bluetooth_connected);
+ } else {
+ contentDescription = mContext.getString(
+ R.string.accessibility_bluetooth_disconnected);
}
} else {
return;
}
- mService.setIcon("bluetooth", iconId, 0);
+ mService.setIcon("bluetooth", iconId, 0, contentDescription);
mService.setIconVisibility("bluetooth", mBluetoothEnabled);
}
@@ -974,6 +1010,7 @@
}
} else if (action.equals(WifiManager.RSSI_CHANGED_ACTION)) {
int iconId;
+ String contentDescription = null;
final int newRssi = intent.getIntExtra(WifiManager.EXTRA_NEW_RSSI, -200);
int newSignalLevel = WifiManager.calculateSignalLevel(newRssi,
sWifiSignalImages[0].length);
@@ -981,10 +1018,13 @@
mLastWifiSignalLevel = newSignalLevel;
if (mIsWifiConnected) {
iconId = sWifiSignalImages[mInetCondition][newSignalLevel];
+ contentDescription = mContext.getString(
+ sWifiConnectionStrength[newSignalLevel]);
} else {
iconId = sWifiTemporarilyNotConnectedImage;
+ contentDescription = mContext.getString(R.string.accessibility_no_wifi);
}
- mService.setIcon("wifi", iconId, 0);
+ mService.setIcon("wifi", iconId, 0, contentDescription);
}
}
}
@@ -995,14 +1035,16 @@
if (action.equals(LocationManager.GPS_FIX_CHANGE_ACTION) && enabled) {
// GPS is getting fixes
- mService.setIcon("gps", com.android.internal.R.drawable.stat_sys_gps_on, 0);
+ mService.setIcon("gps", com.android.internal.R.drawable.stat_sys_gps_on, 0,
+ mContext.getString(R.string.accessibility_gps_enabled));
mService.setIconVisibility("gps", true);
} else if (action.equals(LocationManager.GPS_ENABLED_CHANGE_ACTION) && !enabled) {
// GPS is off
mService.setIconVisibility("gps", false);
} else {
// GPS is on, but not receiving fixes
- mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0);
+ mService.setIcon("gps", R.drawable.stat_sys_gps_acquiring_anim, 0,
+ mContext.getString(R.string.accessibility_gps_acquiring));
mService.setIconVisibility("gps", true);
}
}
@@ -1016,7 +1058,8 @@
if (enabled) {
// TTY is on
if (false) Slog.v(TAG, "updateTTY: set TTY on");
- mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0);
+ mService.setIcon("tty", R.drawable.stat_sys_tty_mode, 0,
+ mContext.getString(R.string.accessibility_tty_enabled));
mService.setIconVisibility("tty", true);
} else {
// TTY is off
@@ -1058,15 +1101,15 @@
switch (iconMode) {
case EriInfo.ROAMING_ICON_MODE_NORMAL:
- mService.setIcon("cdma_eri", iconList[iconIndex], 0);
+ mService.setIcon("cdma_eri", iconList[iconIndex], 0, null);
mService.setIconVisibility("cdma_eri", true);
break;
case EriInfo.ROAMING_ICON_MODE_FLASH:
- mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_flash, 0);
+ mService.setIcon("cdma_eri", R.drawable.stat_sys_roaming_cdma_flash, 0, null);
mService.setIconVisibility("cdma_eri", true);
break;
}
- mService.setIcon("phone_signal", mPhoneSignalIconId, 0);
+ mService.setIcon("phone_signal", mPhoneSignalIconId, 0, null);
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
index 84c524a..c2390e8 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
@@ -26,6 +26,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
+import android.view.accessibility.AccessibilityEvent;
import android.widget.FrameLayout;
import com.android.systemui.R;
@@ -203,5 +204,19 @@
return mService.interceptTouchEvent(event)
? true : super.onInterceptTouchEvent(event);
}
-}
+ @Override
+ public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
+ if (super.onRequestSendAccessibilityEvent(child, event)) {
+ // The status bar is very small so augment the view that the user is touching
+ // with the content of the status bar a whole. This way an accessibility service
+ // may announce the current item as well as the entire content if appropriate.
+ AccessibilityEvent record = AccessibilityEvent.obtain();
+ onInitializeAccessibilityEvent(record);
+ dispatchPopulateAccessibilityEvent(record);
+ event.appendRecord(record);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java
index 8ee12de..e76fe51 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java
@@ -183,7 +183,8 @@
}
final Drawable icon = StatusBarIconView.getIcon(mContext,
- new StatusBarIcon(n.pkg, n.notification.icon, n.notification.iconLevel, 0));
+ new StatusBarIcon(n.pkg, n.notification.icon, n.notification.iconLevel, 0,
+ n.notification.tickerText));
final Segment newSegment = new Segment(n, icon, n.notification.tickerText);
// If there's already a notification schedule for this package and id, remove it.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessibilityContentDescriptions.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessibilityContentDescriptions.java
new file mode 100644
index 0000000..13fb03e
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AccessibilityContentDescriptions.java
@@ -0,0 +1,37 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+
+package com.android.systemui.statusbar.policy;
+
+import com.android.systemui.R;
+
+/**
+ * Content descriptions for accessibility support.
+ */
+public class AccessibilityContentDescriptions {
+
+ private AccessibilityContentDescriptions() {}
+
+ static final int[] PHONE_SIGNAL_STRENGTH = {
+ R.string.accessibility_no_phone,
+ R.string.accessibility_phone_one_bar,
+ R.string.accessibility_phone_two_bars,
+ R.string.accessibility_phone_three_bars,
+ R.string.accessibility_phone_signal_full
+ };
+
+ static final int[] DATA_CONNECTION_STRENGTH = {
+ R.string.accessibility_no_data,
+ R.string.accessibility_data_one_bar,
+ R.string.accessibility_data_two_bars,
+ R.string.accessibility_data_three_bars,
+ R.string.accessibility_data_signal_full
+ };
+
+ static final int[] WIFI_CONNECTION_STRENGTH = {
+ R.string.accessibility_no_wifi,
+ R.string.accessibility_wifi_one_bar,
+ R.string.accessibility_wifi_two_bars,
+ R.string.accessibility_wifi_three_bars,
+ R.string.accessibility_wifi_signal_full
+ };
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java
index ae2b6b2..3957c1b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java
@@ -62,12 +62,15 @@
ImageView v = mIconViews.get(i);
v.setImageResource(icon);
v.setImageLevel(level);
+ v.setContentDescription(mContext.getString(R.string.accessibility_battery_level,
+ level));
}
N = mLabelViews.size();
for (int i=0; i<N; i++) {
//final boolean plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0) != 0;
TextView v = mLabelViews.get(i);
- v.setText(mContext.getString(R.string.status_bar_settings_battery_meter_format, level));
+ v.setText(mContext.getString(R.string.status_bar_settings_battery_meter_format,
+ level));
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java
index 0525054..c6f416f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BluetoothController.java
@@ -19,12 +19,10 @@
import java.util.ArrayList;
import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.util.Slog;
import android.view.View;
import android.widget.ImageView;
@@ -54,26 +52,24 @@
@Override
public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
- int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR);
- mEnabled = state == BluetoothAdapter.STATE_ON;
- } else if (action.equals(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED)) {
- int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
+ int state = intent.getIntExtra(BluetoothAdapter.EXTRA_CONNECTION_STATE,
BluetoothAdapter.STATE_DISCONNECTED);
- if (state == BluetoothAdapter.STATE_CONNECTED) {
- mIconId = R.drawable.stat_sys_data_bluetooth_connected;
- } else {
- mIconId = R.drawable.stat_sys_data_bluetooth;
- }
- }
+ int contentDescriptionResId = 0;
+ if (state == BluetoothAdapter.STATE_CONNECTED) {
+ mIconId = R.drawable.stat_sys_data_bluetooth_connected;
+ contentDescriptionResId = R.string.accessibility_bluetooth_connected;
+ } else {
+ mIconId = R.drawable.stat_sys_data_bluetooth;
+ contentDescriptionResId = R.string.accessibility_bluetooth_disconnected;
+ }
int N = mIconViews.size();
for (int i=0; i<N; i++) {
ImageView v = mIconViews.get(i);
v.setImageResource(mIconId);
v.setVisibility(mEnabled ? View.VISIBLE : View.GONE);
+ v.setContentDescription(mContext.getString(contentDescriptionResId));
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java
index 3175a99..829855b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NetworkController.java
@@ -28,14 +28,11 @@
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-import android.net.wifi.SupplicantState;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Binder;
import android.os.Handler;
-import android.os.HandlerThread;
-import android.os.Looper;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
@@ -87,6 +84,11 @@
int mDataTypeIconId;
boolean mDataActive;
+ String mContentDescriptionPhoneSignal;
+ String mContentDescriptionWifi;
+ String mContentDescriptionCombinedSignal;
+ String mContentDescriptionDataType;
+
// wifi
final WifiManager mWifiManager;
AsyncChannel mWifiChannel;
@@ -366,6 +368,8 @@
if (mSignalStrength == null) {
mPhoneSignalIconId = R.drawable.stat_sys_signal_null;
mDataSignalIconId = R.drawable.stat_sys_signal_0; // note we use 0 instead of null
+ mContentDescriptionPhoneSignal = mContext.getString(
+ AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[0]);
} else {
int iconLevel;
int[] iconList;
@@ -385,6 +389,9 @@
}
}
mPhoneSignalIconId = iconList[iconLevel];
+ mContentDescriptionPhoneSignal = mContext.getString(
+ AccessibilityContentDescriptions.PHONE_SIGNAL_STRENGTH[iconLevel]);
+
mDataSignalIconId = TelephonyIcons.DATA_SIGNAL_STRENGTH[mInetCondition][iconLevel];
}
}
@@ -395,14 +402,20 @@
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
mDataIconList = TelephonyIcons.DATA_G[mInetCondition];
mDataTypeIconId = 0;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_gprs);
break;
case TelephonyManager.NETWORK_TYPE_EDGE:
mDataIconList = TelephonyIcons.DATA_E[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_edge;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_edge);
break;
case TelephonyManager.NETWORK_TYPE_UMTS:
mDataIconList = TelephonyIcons.DATA_3G[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_3g;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_3g);
break;
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
@@ -410,19 +423,27 @@
if (mHspaDataDistinguishable) {
mDataIconList = TelephonyIcons.DATA_H[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_hsdpa;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_3_5g);
} else {
mDataIconList = TelephonyIcons.DATA_3G[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_3g;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_3g);
}
break;
case TelephonyManager.NETWORK_TYPE_CDMA:
// display 1xRTT for IS95A/B
mDataIconList = TelephonyIcons.DATA_1X[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_1x;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_cdma);
break;
case TelephonyManager.NETWORK_TYPE_1xRTT:
mDataIconList = TelephonyIcons.DATA_1X[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_1x;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_cdma);
break;
case TelephonyManager.NETWORK_TYPE_EVDO_0: //fall through
case TelephonyManager.NETWORK_TYPE_EVDO_A:
@@ -430,14 +451,20 @@
case TelephonyManager.NETWORK_TYPE_EHRPD:
mDataIconList = TelephonyIcons.DATA_3G[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_3g;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_3g);
break;
case TelephonyManager.NETWORK_TYPE_LTE:
mDataIconList = TelephonyIcons.DATA_4G[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_4g;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_4g);
break;
default:
mDataIconList = TelephonyIcons.DATA_G[mInetCondition];
mDataTypeIconId = R.drawable.stat_sys_signal_gprs;
+ mContentDescriptionDataType = mContext.getString(
+ R.string.accessibility_data_connection_gprs);
break;
}
if ((isCdma() && isCdmaEri()) || mPhone.isNetworkRoaming()) {
@@ -618,8 +645,11 @@
private void updateWifiIcons() {
if (mWifiConnected) {
mWifiIconId = WifiIcons.WIFI_SIGNAL_STRENGTH[mInetCondition][mWifiLevel];
+ mContentDescriptionWifi = mContext.getString(
+ AccessibilityContentDescriptions.WIFI_CONNECTION_STRENGTH[mWifiLevel]);
} else {
mWifiIconId = WifiIcons.WIFI_SIGNAL_STRENGTH[0][0];
+ mContentDescriptionWifi = mContext.getString(R.string.accessibility_no_wifi);
}
}
@@ -704,6 +734,7 @@
}
}
combinedSignalIconId = mWifiIconId;
+ mContentDescriptionCombinedSignal = mContentDescriptionWifi;
dataTypeIconId = 0;
} else if (mDataConnected) {
label = mNetworkName;
@@ -723,22 +754,29 @@
break;
}
combinedSignalIconId = mDataSignalIconId;
+ mContentDescriptionCombinedSignal = mContentDescriptionDataType;
dataTypeIconId = mDataTypeIconId;
} else if (mBluetoothTethered) {
label = mContext.getString(R.string.bluetooth_tethered);
combinedSignalIconId = mBluetoothTetherIconId;
+ mContentDescriptionCombinedSignal = mContext.getString(
+ R.string.accessibility_bluetooth_tether);
dataTypeIconId = 0;
} else if (mAirplaneMode &&
(mServiceState == null || (!hasService() && !mServiceState.isEmergencyOnly()))) {
// Only display the flight-mode icon if not in "emergency calls only" mode.
label = context.getString(R.string.status_bar_settings_signal_meter_disconnected);
combinedSignalIconId = R.drawable.stat_sys_signal_flightmode;
+ mContentDescriptionCombinedSignal = mContext.getString(
+ R.string.accessibility_airplane_mode);
dataTypeIconId = 0;
} else {
label = context.getString(R.string.status_bar_settings_signal_meter_disconnected);
// On devices without mobile radios, we want to show the wifi icon
combinedSignalIconId =
hasMobileDataFeature() ? mDataSignalIconId : mWifiIconId;
+ mContentDescriptionCombinedSignal = hasMobileDataFeature()
+ ? mContentDescriptionDataType : mContentDescriptionWifi;
dataTypeIconId = 0;
}
@@ -764,6 +802,7 @@
for (int i=0; i<N; i++) {
final ImageView v = mPhoneSignalIconViews.get(i);
v.setImageResource(mPhoneSignalIconId);
+ v.setContentDescription(mContentDescriptionPhoneSignal);
}
}
@@ -774,6 +813,7 @@
for (int i=0; i<N; i++) {
final ImageView v = mDataDirectionIconViews.get(i);
v.setImageResource(mDataDirectionIconId);
+ v.setContentDescription(mContentDescriptionDataType);
}
}
@@ -784,6 +824,7 @@
for (int i=0; i<N; i++) {
final ImageView v = mWifiIconViews.get(i);
v.setImageResource(mWifiIconId);
+ v.setContentDescription(mContentDescriptionWifi);
}
}
@@ -794,6 +835,7 @@
for (int i=0; i<N; i++) {
final ImageView v = mCombinedSignalIconViews.get(i);
v.setImageResource(combinedSignalIconId);
+ v.setContentDescription(mContentDescriptionCombinedSignal);
}
}
@@ -808,6 +850,7 @@
} else {
v.setVisibility(View.VISIBLE);
v.setImageResource(dataTypeIconId);
+ v.setContentDescription(mContentDescriptionDataType);
}
}
}
@@ -826,6 +869,7 @@
} else {
v.setVisibility(View.VISIBLE);
v.setImageResource(dataDirectionOverlayIconId);
+ v.setContentDescription(mContentDescriptionDataType);
}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java
index b4d2a14..90234c7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/NotificationRowLayout.java
@@ -21,47 +21,33 @@
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeAnimator;
-import android.animation.ValueAnimator;
import android.content.Context;
-import android.content.res.Resources;
+import android.content.res.Configuration;
import android.content.res.TypedArray;
-import android.graphics.Canvas;
import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
+import android.util.Log;
import android.util.Slog;
-import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
+import android.view.ViewConfiguration;
import android.view.ViewGroup;
-import android.view.animation.AccelerateInterpolator;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-import android.widget.TextView;
+
+import com.android.systemui.R;
+import com.android.systemui.SwipeHelper;
import java.util.HashSet;
-import com.android.systemui.R;
-
-public class NotificationRowLayout extends ViewGroup {
+public class NotificationRowLayout extends ViewGroup implements SwipeHelper.Callback {
private static final String TAG = "NotificationRowLayout";
private static final boolean DEBUG = false;
private static final boolean SLOW_ANIMATIONS = false; // DEBUG;
private static final boolean ANIMATE_LAYOUT = true;
- private static final boolean CLEAR_IF_SWIPED_FAR_ENOUGH = true;
-
- private static final boolean CONSTRAIN_SWIPE_ON_PERMANENT = true;
-
private static final int APPEAR_ANIM_LEN = SLOW_ANIMATIONS ? 5000 : 250;
private static final int DISAPPEAR_ANIM_LEN = APPEAR_ANIM_LEN;
- private static final int SNAP_ANIM_LEN = SLOW_ANIMATIONS ? 1000 : 250;
-
- private static final float SWIPE_ESCAPE_VELOCITY = 1500f;
- private static final float SWIPE_ANIM_VELOCITY_MIN = 1000f;
Rect mTmpRect = new Rect();
int mNumRows = 0;
@@ -71,10 +57,7 @@
HashSet<View> mAppearingViews = new HashSet<View>();
HashSet<View> mDisappearingViews = new HashSet<View>();
- VelocityTracker mVT;
- float mInitialTouchX, mInitialTouchY;
- View mSlidingChild = null;
- float mLiftoffVelocity;
+ private SwipeHelper mSwipeHelper;
public NotificationRowLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
@@ -83,8 +66,6 @@
public NotificationRowLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
- mVT = VelocityTracker.obtain();
-
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NotificationRowLayout,
defStyle, 0);
mRowHeight = a.getDimensionPixelSize(R.styleable.NotificationRowLayout_rowHeight, 0);
@@ -107,112 +88,71 @@
setBackgroundColor(0x80FF8000);
}
+ float densityScale = getResources().getDisplayMetrics().density;
+ float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ mSwipeHelper = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop);
}
- // Swipey code
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
- final int action = ev.getAction();
-// if (DEBUG) Slog.d(TAG, "intercepting touch event: " + ev);
- switch (action) {
- case MotionEvent.ACTION_DOWN:
- mVT.clear();
- mVT.addMovement(ev);
- mInitialTouchX = ev.getX();
- mInitialTouchY = ev.getY();
- mSlidingChild = null;
- break;
- case MotionEvent.ACTION_MOVE:
- mVT.addMovement(ev);
- if (mSlidingChild == null) {
- if (Math.abs(ev.getX() - mInitialTouchX) > 4) { // slide slop
-
- // find the view under the pointer, accounting for GONE views
- final int count = getChildCount();
- int y = 0;
- int childIdx = 0;
- for (; childIdx < count; childIdx++) {
- mSlidingChild = getChildAt(childIdx);
- if (mSlidingChild.getVisibility() == GONE) {
- continue;
- }
- y += mRowHeight;
- if (mInitialTouchY < y) break;
- }
-
- mInitialTouchX -= mSlidingChild.getTranslationX();
- mSlidingChild.animate().cancel();
-
- if (DEBUG) {
- Slog.d(TAG, String.format(
- "now sliding child %d: %s (touchY=%.1f, rowHeight=%d, count=%d)",
- childIdx, mSlidingChild, mInitialTouchY, mRowHeight, count));
- }
- }
- }
- break;
- }
- return mSlidingChild != null;
- }
-
- protected boolean canBeCleared(View v) {
- final View veto = v.findViewById(R.id.veto);
- return (veto != null && veto.getVisibility() != View.GONE);
- }
-
- protected boolean clear(View v) {
- final View veto = v.findViewById(R.id.veto);
- if (veto != null && veto.getVisibility() != View.GONE) {
- veto.performClick();
- return true;
- }
- return false;
+ if (DEBUG) Log.v(TAG, "onInterceptTouchEvent()");
+ return mSwipeHelper.onInterceptTouchEvent(ev) ||
+ super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
- final int action = ev.getAction();
-// if (DEBUG) Slog.d(TAG, "touch event: " + ev + " sliding: " + mSlidingChild);
- if (mSlidingChild != null) {
- switch (action) {
- case MotionEvent.ACTION_OUTSIDE:
- case MotionEvent.ACTION_MOVE:
- mVT.addMovement(ev);
+ return mSwipeHelper.onTouchEvent(ev) ||
+ super.onTouchEvent(ev);
+ }
- float delta = (ev.getX() - mInitialTouchX);
- if (CONSTRAIN_SWIPE_ON_PERMANENT && !canBeCleared(mSlidingChild)) {
- delta = Math.copySign(
- Math.min(Math.abs(delta),
- mSlidingChild.getMeasuredWidth() * 0.2f), delta);
- }
- mSlidingChild.setTranslationX(delta);
- break;
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- mVT.addMovement(ev);
- mVT.computeCurrentVelocity(1000 /* px/sec */);
- if (DEBUG) Slog.d(TAG, "exit velocity: " + mVT.getXVelocity());
- boolean restore = true;
- mLiftoffVelocity = mVT.getXVelocity();
- if (Math.abs(mLiftoffVelocity) > SWIPE_ESCAPE_VELOCITY
- || (CLEAR_IF_SWIPED_FAR_ENOUGH &&
- (mSlidingChild.getTranslationX() * 2) > mSlidingChild.getMeasuredWidth()))
- {
+ public boolean canChildBeDismissed(View v) {
+ final View veto = v.findViewById(R.id.veto);
+ return (veto != null && veto.getVisibility() != View.GONE);
+ }
- // flingadingy
- restore = ! clear(mSlidingChild);
- }
- if (restore) {
- // snappity
- mSlidingChild.animate().translationX(0)
- .setDuration(SNAP_ANIM_LEN)
- .start();
- }
- break;
- }
- return true;
+ public void onChildDismissed(View v) {
+ final View veto = v.findViewById(R.id.veto);
+ if (veto != null && veto.getVisibility() != View.GONE) {
+ veto.performClick();
}
- return false;
+ }
+
+ public void onBeginDrag(View v) {
+ // We need to prevent the surrounding ScrollView from intercepting us now;
+ // the scroll position will be locked while we swipe
+ requestDisallowInterceptTouchEvent(true);
+ }
+
+ public View getChildAtPosition(MotionEvent ev) {
+ // find the view under the pointer, accounting for GONE views
+ final int count = getChildCount();
+ int y = 0;
+ int touchY = (int) ev.getY();
+ int childIdx = 0;
+ View slidingChild;
+ for (; childIdx < count; childIdx++) {
+ slidingChild = getChildAt(childIdx);
+ if (slidingChild.getVisibility() == GONE) {
+ continue;
+ }
+ y += mRowHeight;
+ if (touchY < y) return slidingChild;
+ }
+ return null;
+ }
+
+ public View getChildContentView(View v) {
+ return v;
+ }
+
+ @Override
+ protected void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ float densityScale = getResources().getDisplayMetrics().density;
+ mSwipeHelper.setDensityScale(densityScale);
+ float pagingTouchSlop = ViewConfiguration.get(mContext).getScaledPagingTouchSlop();
+ mSwipeHelper.setPagingTouchSlop(pagingTouchSlop);
}
//**
@@ -255,9 +195,10 @@
child.setPivotY(0);
- final float velocity = (mSlidingChild == child)
- ? Math.min(mLiftoffVelocity, SWIPE_ANIM_VELOCITY_MIN)
- : SWIPE_ESCAPE_VELOCITY;
+ //final float velocity = (mSlidingChild == child)
+ // ? Math.min(mLiftoffVelocity, SWIPE_ANIM_VELOCITY_MIN)
+ // : SWIPE_ESCAPE_VELOCITY;
+ final float velocity = 0f;
final TimeAnimator zoom = new TimeAnimator();
zoom.setTimeListener(new TimeAnimator.TimeListener() {
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/CompatModePanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/CompatModePanel.java
index c62c4ad..8c4ae19 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/CompatModePanel.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/CompatModePanel.java
@@ -22,6 +22,7 @@
import android.os.RemoteException;
import android.util.AttributeSet;
import android.util.Slog;
+import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
@@ -90,6 +91,19 @@
return false;
}
+ @Override
+ public boolean dispatchHoverEvent(MotionEvent event) {
+ // Ignore hover events outside of this panel bounds since such events
+ // generate spurious accessibility events with the panel content when
+ // tapping outside of it, thus confusing the user.
+ final int x = (int) event.getX();
+ final int y = (int) event.getY();
+ if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
+ return super.dispatchHoverEvent(event);
+ }
+ return true;
+ }
+
public void setTrigger(View v) {
mTrigger = v;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java
index 339e3f3..1e417ac 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java
@@ -30,6 +30,7 @@
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
+import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -160,6 +161,19 @@
}
}
+ @Override
+ public boolean dispatchHoverEvent(MotionEvent event) {
+ // Ignore hover events outside of this panel bounds since such events
+ // generate spurious accessibility events with the panel content when
+ // tapping outside of it, thus confusing the user.
+ final int x = (int) event.getX();
+ final int y = (int) event.getY();
+ if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
+ return super.dispatchHoverEvent(event);
+ }
+ return true;
+ }
+
private void updateHardKeyboardEnabled() {
if (mHardKeyboardAvailable) {
final boolean checked = mHardKeyboardSwitch.isChecked();
@@ -222,6 +236,7 @@
itemSubtitle.setText(imiName);
}
subtypeIcon.setImageDrawable(icon);
+ subtypeIcon.setContentDescription(itemTitle.getText());
final String settingsActivity = imi.getSettingsActivity();
if (!TextUtils.isEmpty(settingsActivity)) {
settingsIcon.setOnClickListener(new View.OnClickListener() {
@@ -463,4 +478,5 @@
public interface OnHardKeyboardEnabledChangeListener {
public void onHardKeyboardEnabledChange(boolean enabled);
}
+
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationArea.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationArea.java
new file mode 100644
index 0000000..42bdf3d
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationArea.java
@@ -0,0 +1,45 @@
+/*
+ * 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.systemui.statusbar.tablet;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
+import android.widget.LinearLayout;
+
+public class NotificationArea extends LinearLayout {
+
+ public NotificationArea(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
+ if (super.onRequestSendAccessibilityEvent(child, event)) {
+ // The event is coming from a descendant like battery but append
+ // the content of the entire notification area so accessibility
+ // services can choose how to present the content to the user.
+ AccessibilityEvent record = AccessibilityEvent.obtain();
+ onInitializeAccessibilityEvent(record);
+ dispatchPopulateAccessibilityEvent(record);
+ event.appendRecord(record);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanel.java
index 64a4f16..a316e4b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanel.java
@@ -20,27 +20,15 @@
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
-import android.animation.ValueAnimator;
import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Canvas;
import android.graphics.Rect;
-import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Slog;
-import android.view.accessibility.AccessibilityEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
-import android.view.SoundEffectConstants;
import android.view.View;
import android.view.ViewGroup;
-import android.view.animation.AccelerateInterpolator;
-import android.widget.FrameLayout;
-import android.widget.FrameLayout;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
import android.widget.RelativeLayout;
-import android.widget.TextView;
import com.android.systemui.R;
@@ -53,8 +41,7 @@
boolean mShowing;
int mNotificationCount = 0;
- View mTitleArea;
- ModeToggle mModeToggle;
+ NotificationPanelTitle mTitleArea;
View mSettingsButton;
View mNotificationButton;
View mNotificationScroller;
@@ -68,48 +55,6 @@
Choreographer mChoreo = new Choreographer();
- static class ModeToggle extends View {
- NotificationPanel mPanel;
- View mTitle;
- public ModeToggle(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public void setPanel(NotificationPanel p) {
- mPanel = p;
- }
- public void setTitleArea(View v) {
- mTitle = v;
- }
- @Override
- public boolean onTouchEvent(MotionEvent e) {
- final int x = (int)e.getX();
- final int y = (int)e.getY();
- switch (e.getAction()) {
- case MotionEvent.ACTION_DOWN:
- mTitle.setPressed(true);
- break;
- case MotionEvent.ACTION_MOVE:
- mTitle.setPressed(x >= 0
- && x < getWidth()
- && y >= 0
- && y < getHeight());
- break;
- case MotionEvent.ACTION_CANCEL:
- mTitle.setPressed(false);
- break;
- case MotionEvent.ACTION_UP:
- if (mTitle.isPressed()) {
- sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
- playSoundEffect(SoundEffectConstants.CLICK);
- mPanel.swapPanels();
- mTitle.setPressed(false);
- }
- break;
- }
- return true;
- }
- }
-
public NotificationPanel(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@@ -126,14 +71,11 @@
mContentParent = (ViewGroup)findViewById(R.id.content_parent);
mContentParent.bringToFront();
- mTitleArea = findViewById(R.id.title_area);
- mModeToggle = (ModeToggle) findViewById(R.id.mode_toggle);
- mModeToggle.setOnClickListener(this);
- mModeToggle.setPanel(this);
- mModeToggle.setTitleArea(mTitleArea);
+ mTitleArea = (NotificationPanelTitle) findViewById(R.id.title_area);
+ mTitleArea.setPanel(this);
- mSettingsButton = (ImageView)findViewById(R.id.settings_button);
- mNotificationButton = (ImageView)findViewById(R.id.notification_button);
+ mSettingsButton = findViewById(R.id.settings_button);
+ mNotificationButton = findViewById(R.id.notification_button);
mNotificationScroller = findViewById(R.id.notification_scroller);
mContentFrame = (ViewGroup)findViewById(R.id.content_frame);
@@ -185,6 +127,19 @@
}
}
+ @Override
+ public boolean dispatchHoverEvent(MotionEvent event) {
+ // Ignore hover events outside of this panel bounds since such events
+ // generate spurious accessibility events with the panel content when
+ // tapping outside of it, thus confusing the user.
+ final int x = (int) event.getX();
+ final int y = (int) event.getY();
+ if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
+ return super.dispatchHoverEvent(event);
+ }
+ return true;
+ }
+
/*
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
@@ -205,7 +160,7 @@
*/
public void onClick(View v) {
- if (v == mModeToggle) {
+ if (v == mTitleArea) {
swapPanels();
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanelTitle.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanelTitle.java
new file mode 100644
index 0000000..689bc36
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPanelTitle.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 com.android.systemui.statusbar.tablet;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.SoundEffectConstants;
+import android.view.View;
+import android.view.accessibility.AccessibilityEvent;
+import android.widget.RelativeLayout;
+
+public class NotificationPanelTitle extends RelativeLayout implements View.OnClickListener {
+ private NotificationPanel mPanel;
+
+ public NotificationPanelTitle(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setOnClickListener(this);
+ }
+
+ public void setPanel(NotificationPanel p) {
+ mPanel = p;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent e) {
+ switch (e.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ setPressed(true);
+ break;
+ case MotionEvent.ACTION_MOVE:
+ final int x = (int) e.getX();
+ final int y = (int) e.getY();
+ setPressed(x > 0 && x < getWidth() && y > 0 && y < getHeight());
+ break;
+ case MotionEvent.ACTION_UP:
+ if (isPressed()) {
+ playSoundEffect(SoundEffectConstants.CLICK);
+ mPanel.swapPanels();
+ setPressed(false);
+ }
+ break;
+ case MotionEvent.ACTION_CANCEL:
+ setPressed(false);
+ break;
+ }
+ return true;
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == this) {
+ mPanel.swapPanels();
+ }
+ }
+
+ @Override
+ public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
+ if (super.onRequestSendAccessibilityEvent(child, event)) {
+ AccessibilityEvent record = AccessibilityEvent.obtain();
+ onInitializeAccessibilityEvent(record);
+ dispatchPopulateAccessibilityEvent(record);
+ event.appendRecord(record);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPeekPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPeekPanel.java
index 8b68240..ba28306 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPeekPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/NotificationPeekPanel.java
@@ -18,12 +18,9 @@
import android.content.Context;
import android.util.AttributeSet;
-import android.util.Slog;
import android.view.MotionEvent;
import android.widget.RelativeLayout;
-import com.android.systemui.R;
-
public class NotificationPeekPanel extends RelativeLayout implements StatusBarPanel {
TabletStatusBar mBar;
@@ -54,5 +51,17 @@
mBar.resetNotificationPeekFadeTimer();
return false;
}
-}
+ @Override
+ public boolean dispatchHoverEvent(MotionEvent event) {
+ // Ignore hover events outside of this panel bounds since such events
+ // generate spurious accessibility events with the panel content when
+ // tapping outside of it, thus confusing the user.
+ final int x = (int) event.getX();
+ final int y = (int) event.getY();
+ if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
+ return super.dispatchHoverEvent(event);
+ }
+ return true;
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
index df09f84..13846ed 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java
@@ -808,7 +808,8 @@
// Update the icon.
final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
notification.notification.icon, notification.notification.iconLevel,
- notification.notification.number);
+ notification.notification.number,
+ notification.notification.tickerText);
if (!oldEntry.icon.set(ic)) {
handleNotificationError(key, notification, "Couldn't update icon: " + ic);
return;
@@ -1012,10 +1013,7 @@
mCompatModeButton.refresh();
if (mCompatModeButton.getVisibility() == View.VISIBLE) {
- if (DEBUG_COMPAT_HELP
- || ! Prefs.read(mContext).getBoolean(Prefs.SHOWN_COMPAT_MODE_HELP, false)) {
showCompatibilityHelp();
- }
} else {
hideCompatibilityHelp();
mCompatModePanel.closePanel();
@@ -1451,13 +1449,15 @@
}
// Construct the icon.
final StatusBarIconView iconView = new StatusBarIconView(mContext,
- notification.pkg + "/0x" + Integer.toHexString(notification.id));
+ notification.pkg + "/0x" + Integer.toHexString(notification.id),
+ notification.notification);
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
notification.notification.icon,
notification.notification.iconLevel,
- notification.notification.number);
+ notification.notification.number,
+ notification.notification.tickerText);
if (!iconView.set(ic)) {
handleNotificationError(key, notification, "Couldn't attach StatusBarIcon: " + ic);
return null;
@@ -1501,11 +1501,6 @@
// alternate behavior in DND mode
if (mNotificationDNDMode) {
if (mIconLayout.getChildCount() == 0) {
- final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd");
- iconView.setImageResource(R.drawable.ic_notification_dnd);
- iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
- iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0);
-
final Notification dndNotification = new Notification.Builder(mContext)
.setContentTitle(mContext.getText(R.string.notifications_off_title))
.setContentText(mContext.getText(R.string.notifications_off_text))
@@ -1513,6 +1508,12 @@
.setOngoing(true)
.getNotification();
+ final StatusBarIconView iconView = new StatusBarIconView(mContext, "_dnd",
+ dndNotification);
+ iconView.setImageResource(R.drawable.ic_notification_dnd);
+ iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
+ iconView.setPadding(mIconHPadding, 0, mIconHPadding, 0);
+
mNotificationDNDDummyEntry = new NotificationData.Entry(
null,
new StatusBarNotification("", 0, "", 0, 0, dndNotification),
@@ -1634,19 +1635,24 @@
} else {
if ((sbn.notification.flags & Notification.FLAG_ONGOING_EVENT) == 0) {
vetoButton.setVisibility(View.INVISIBLE);
+ vetoButton.setContentDescription("VETO");
} else {
vetoButton.setVisibility(View.GONE);
}
}
+ vetoButton.setContentDescription(mContext.getString(
+ R.string.accessibility_remove_notification));
// the large icon
ImageView largeIcon = (ImageView)row.findViewById(R.id.large_icon);
if (sbn.notification.largeIcon != null) {
largeIcon.setImageBitmap(sbn.notification.largeIcon);
+ largeIcon.setContentDescription(sbn.notification.tickerText);
} else {
largeIcon.getLayoutParams().width = 0;
largeIcon.setVisibility(View.INVISIBLE);
}
+ largeIcon.setContentDescription(sbn.notification.tickerText);
// bind the click event to the content area
ViewGroup content = (ViewGroup)row.findViewById(R.id.content);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java
index a8f4262..6045e31 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java
@@ -284,7 +284,7 @@
} else if (n.tickerText != null) {
group = (ViewGroup)inflater.inflate(R.layout.status_bar_ticker_compat, mWindow, false);
final Drawable icon = StatusBarIconView.getIcon(mContext,
- new StatusBarIcon(notification.pkg, n.icon, n.iconLevel, 0));
+ new StatusBarIcon(notification.pkg, n.icon, n.iconLevel, 0, n.tickerText));
ImageView iv = (ImageView)group.findViewById(iconId);
iv.setImageDrawable(icon);
iv.setVisibility(View.VISIBLE);
diff --git a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
index 935f4ad..47d34b3 100644
--- a/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
+++ b/policy/src/com/android/internal/policy/impl/KeyguardViewMediator.java
@@ -35,7 +35,6 @@
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Handler;
-import android.os.IBinder;
import android.os.LocalPowerManager;
import android.os.Message;
import android.os.PowerManager;
@@ -43,7 +42,6 @@
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Settings;
-import android.provider.Settings.SettingNotFoundException;
import android.telephony.TelephonyManager;
import android.util.EventLog;
import android.util.Log;
@@ -1117,8 +1115,11 @@
// Give feedback to user when secure keyguard is active and engaged
if (mShowing && isSecure()) {
if (!mShowingLockIcon) {
+ String contentDescription = mContext.getString(
+ com.android.internal.R.string.status_bar_device_locked);
mStatusBarManager.setIcon("secure",
- com.android.internal.R.drawable.stat_sys_secure, 0);
+ com.android.internal.R.drawable.stat_sys_secure, 0,
+ contentDescription);
mShowingLockIcon = true;
}
} else {
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindow.java b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
index b963b13..bfc3cdd 100644
--- a/policy/src/com/android/internal/policy/impl/PhoneWindow.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindow.java
@@ -388,6 +388,11 @@
st.isHandled = false;
mPreparedPanel = st;
+ if (st.frozenActionViewState != null) {
+ st.menu.restoreActionViewStates(st.frozenActionViewState);
+ st.frozenActionViewState = null;
+ }
+
return true;
}
@@ -652,7 +657,13 @@
@Override
public void invalidatePanelMenu(int featureId) {
PanelFeatureState st = getPanelState(featureId, true);
+ Bundle savedActionViewStates = null;
if (st.menu != null) {
+ savedActionViewStates = new Bundle();
+ st.menu.saveActionViewStates(savedActionViewStates);
+ if (savedActionViewStates.size() > 0) {
+ st.frozenActionViewState = savedActionViewStates;
+ }
st.menu.clear();
}
st.refreshMenuContent = true;
@@ -2029,13 +2040,14 @@
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);
@@ -3024,6 +3036,12 @@
*/
Bundle frozenMenuState;
+ /**
+ * Contains the state of associated action views when told to freeze.
+ * These are saved across invalidations.
+ */
+ Bundle frozenActionViewState;
+
PanelFeatureState(int featureId) {
this.featureId = featureId;
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index ad6cebb..b7f6adf 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -166,22 +166,22 @@
static final int SYSTEM_DIALOG_LAYER = 6;
// toasts and the plugged-in battery thing
static final int TOAST_LAYER = 7;
- static final int STATUS_BAR_LAYER = 8;
- static final int STATUS_BAR_PANEL_LAYER = 9;
// SIM errors and unlock. Not sure if this really should be in a high layer.
- static final int PRIORITY_PHONE_LAYER = 10;
+ static final int PRIORITY_PHONE_LAYER = 8;
// like the ANR / app crashed dialogs
- static final int SYSTEM_ALERT_LAYER = 11;
+ static final int SYSTEM_ALERT_LAYER = 9;
// system-level error dialogs
- static final int SYSTEM_ERROR_LAYER = 12;
+ static final int SYSTEM_ERROR_LAYER = 10;
// on-screen keyboards and other such input method user interfaces go here.
- static final int INPUT_METHOD_LAYER = 13;
+ static final int INPUT_METHOD_LAYER = 11;
// on-screen keyboards and other such input method user interfaces go here.
- static final int INPUT_METHOD_DIALOG_LAYER = 14;
+ static final int INPUT_METHOD_DIALOG_LAYER = 12;
// the keyguard; nothing on top of these can take focus, since they are
// responsible for power management when displayed.
- static final int KEYGUARD_LAYER = 15;
- static final int KEYGUARD_DIALOG_LAYER = 16;
+ static final int KEYGUARD_LAYER = 13;
+ static final int KEYGUARD_DIALOG_LAYER = 14;
+ static final int STATUS_BAR_LAYER = 15;
+ static final int STATUS_BAR_PANEL_LAYER = 16;
// the navigation bar, if available, shows atop most things
static final int NAVIGATION_BAR_LAYER = 17;
// the drag layer: input for drag-and-drop is associated with this window,
@@ -1703,7 +1703,11 @@
}
}
}
- if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + navr);
+ if (DEBUG_LAYOUT) {
+ Log.i(TAG, "mNavigationBar frame: " + navr);
+ Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
+ mDockLeft, mDockTop, mDockRight, mDockBottom));
+ }
// apply navigation bar insets
pf.left = df.left = vf.left = mDockLeft;
@@ -1713,6 +1717,25 @@
mStatusBar.computeFrameLw(pf, df, vf, vf);
+ // now, let's consider the navigation bar; if it exists, it must be removed from the
+ // available screen real estate (like an un-hideable status bar)
+ if (navr != null) {
+ if (navr.top == 0) {
+ // Navigation bar is vertical
+ if (mRestrictedScreenLeft == navr.left) {
+ mRestrictedScreenLeft = navr.right;
+ mRestrictedScreenWidth -= (navr.right - navr.left);
+ } else if ((mRestrictedScreenLeft+mRestrictedScreenWidth) == navr.right) {
+ mRestrictedScreenWidth -= (navr.right - navr.left);
+ }
+ } else {
+ // Navigation bar horizontal, at bottom
+ if ((mRestrictedScreenHeight+mRestrictedScreenTop) == navr.bottom) {
+ mRestrictedScreenHeight -= (navr.bottom-navr.top);
+ }
+ }
+ }
+
if (mStatusBar.isVisibleLw()) {
// If the status bar is hidden, we don't want to cause
// windows behind it to scroll.
@@ -1745,23 +1768,6 @@
mRestrictedScreenHeight -= (r.bottom-r.top);
}
- if (navr != null) {
- if (navr.top == 0) {
- // Navigation bar is vertical
- if (mRestrictedScreenLeft == navr.left) {
- mRestrictedScreenLeft = navr.right;
- mRestrictedScreenWidth -= (navr.right - navr.left);
- } else if ((mRestrictedScreenLeft+mRestrictedScreenWidth) == navr.right) {
- mRestrictedScreenWidth -= (navr.right - navr.left);
- }
- } else {
- // Navigation bar horizontal, at bottom
- if ((mRestrictedScreenHeight-mRestrictedScreenTop) == r.bottom) {
- mRestrictedScreenHeight -= (navr.bottom-navr.top);
- }
- }
- }
-
mContentTop = mCurTop = mDockTop = mRestrictedScreenTop;
mContentBottom = mCurBottom = mDockBottom
= mRestrictedScreenTop + mRestrictedScreenHeight;
@@ -1873,19 +1879,22 @@
// permission, so they have the same privileges as the status
// bar itself.
//
- // However, they should still dodge the navigation bar if it exists. A
- // straightforward way to do this is to only allow the status bar panels to
- // extend to the extrema of the allowable region for the IME dock.
+ // However, they should still dodge the navigation bar if it exists.
pf.left = df.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
pf.top = df.top = mUnrestrictedScreenTop;
pf.right = df.right = hasNavBar
- ? mDockRight
+ ? mRestrictedScreenLeft+mRestrictedScreenWidth
: mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
pf.bottom = df.bottom = hasNavBar
- ? mDockBottom
+ ? mRestrictedScreenTop+mRestrictedScreenHeight
: mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
+ if (DEBUG_LAYOUT) {
+ Log.v(TAG, String.format(
+ "Laying out status bar window: (%d,%d - %d,%d)",
+ pf.left, pf.top, pf.right, pf.bottom));
+ }
} else {
pf.left = df.left = mRestrictedScreenLeft;
pf.top = df.top = mRestrictedScreenTop;
@@ -1922,12 +1931,23 @@
pf.left = df.left = cf.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
pf.top = df.top = cf.top = mUnrestrictedScreenTop;
pf.right = df.right = cf.right = hasNavBar
- ? mDockRight
+ ? mRestrictedScreenLeft+mRestrictedScreenWidth
: mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
pf.bottom = df.bottom = cf.bottom = hasNavBar
- ? mDockBottom
+ ? mRestrictedScreenTop+mRestrictedScreenHeight
: mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
+ } else if (attrs.type == TYPE_NAVIGATION_BAR) {
+ // The navigation bar has Real Ultimate Power.
+ pf.left = df.left = mUnrestrictedScreenLeft;
+ pf.top = df.top = mUnrestrictedScreenTop;
+ pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
+ pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
+ if (DEBUG_LAYOUT) {
+ Log.v(TAG, String.format(
+ "Laying out navigation bar window: (%d,%d - %d,%d)",
+ pf.left, pf.top, pf.right, pf.bottom));
+ }
} else {
pf.left = df.left = cf.left = mRestrictedScreenLeft;
pf.top = df.top = cf.top = mRestrictedScreenTop;
@@ -2424,20 +2444,22 @@
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;
+ 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();
+ // Take the screenshot
+ takeScreenshot();
- // Prevent the event from being passed through to the current activity
- result &= ~ACTION_PASS_TO_USER;
- break;
+ // Prevent the event from being passed through to the current activity
+ result &= ~ACTION_PASS_TO_USER;
+ break;
+ }
+ mVolumeDownTriggered = true;
}
- mVolumeDownTriggered = true;
} else {
mVolumeDownTriggered = false;
}
@@ -2521,17 +2543,18 @@
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;
+ 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;
+ // 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 @@
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 @@
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 @@
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 @@
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 @@
};
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 @@
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/audioflinger/AudioPolicyService.cpp b/services/audioflinger/AudioPolicyService.cpp
index dd1e153..6d06d83 100644
--- a/services/audioflinger/AudioPolicyService.cpp
+++ b/services/audioflinger/AudioPolicyService.cpp
@@ -497,6 +497,43 @@
return mpAudioPolicy->is_stream_active(mpAudioPolicy, stream, inPastMs);
}
+status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession,
+ effect_descriptor_t *descriptors,
+ uint32_t *count)
+{
+
+ if (mpAudioPolicy == NULL) {
+ *count = 0;
+ return NO_INIT;
+ }
+ Mutex::Autolock _l(mLock);
+ status_t status = NO_ERROR;
+
+ size_t index;
+ for (index = 0; index < mInputs.size(); index++) {
+ if (mInputs.valueAt(index)->mSessionId == audioSession) {
+ break;
+ }
+ }
+ if (index == mInputs.size()) {
+ *count = 0;
+ return BAD_VALUE;
+ }
+ Vector< sp<AudioEffect> > effects = mInputs.valueAt(index)->mEffects;
+
+ for (size_t i = 0; i < effects.size(); i++) {
+ effect_descriptor_t desc = effects[i]->descriptor();
+ if (i < *count) {
+ memcpy(descriptors + i, &desc, sizeof(effect_descriptor_t));
+ }
+ }
+ if (effects.size() > *count) {
+ status = NO_MEMORY;
+ }
+ *count = effects.size();
+ return status;
+}
+
void AudioPolicyService::binderDied(const wp<IBinder>& who) {
LOGW("binderDied() %p, tid %d, calling tid %d", who.unsafe_get(), gettid(),
IPCThreadState::self()->getCallingPid());
diff --git a/services/audioflinger/AudioPolicyService.h b/services/audioflinger/AudioPolicyService.h
index 62ad29e..834b794 100644
--- a/services/audioflinger/AudioPolicyService.h
+++ b/services/audioflinger/AudioPolicyService.h
@@ -104,6 +104,9 @@
virtual status_t unregisterEffect(int id);
virtual bool isStreamActive(int stream, uint32_t inPastMs = 0) const;
+ virtual status_t queryDefaultPreProcessing(int audioSession,
+ effect_descriptor_t *descriptors,
+ uint32_t *count);
virtual status_t onTransact(
uint32_t code,
const Parcel& data,
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 @@
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..0843948 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -1090,7 +1090,7 @@
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 @@
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 @@
*/
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);
+ }
}
}
}
@@ -1900,7 +1926,8 @@
}
// Caller must grab mDnsLock.
- private boolean updateDns(String network, Collection<InetAddress> dnses, String domains) {
+ private boolean updateDns(String network, String iface,
+ Collection<InetAddress> dnses, String domains) {
boolean changed = false;
int last = 0;
if (dnses.size() == 0 && mDefaultDns != null) {
@@ -1936,6 +1963,14 @@
}
mNumDnsEntries = last;
+ if (changed) {
+ try {
+ mNetd.setDnsServersForInterface(iface, NetworkUtils.makeStrings(dnses));
+ mNetd.setDefaultInterfaceForDns(iface);
+ } catch (Exception e) {
+ Slog.e(TAG, "exception setting default dns interface: " + e);
+ }
+ }
if (!domains.equals(SystemProperties.get("net.dns.search"))) {
SystemProperties.set("net.dns.search", domains);
changed = true;
@@ -1955,10 +1990,16 @@
String network = nt.getNetworkInfo().getTypeName();
synchronized (mDnsLock) {
if (!mDnsOverridden) {
- changed = updateDns(network, dnses, "");
+ changed = updateDns(network, p.getInterfaceName(), dnses, "");
}
}
} else {
+ try {
+ mNetd.setDnsServersForInterface(Integer.toString(netType),
+ NetworkUtils.makeStrings(dnses));
+ } catch (Exception e) {
+ Slog.e(TAG, "exception setting dns servers: " + e);
+ }
// set per-pid dns for attached secondary nets
List pids = mNetRequestersPids[netType];
for (int y=0; y< pids.size(); y++) {
@@ -2236,6 +2277,15 @@
}
}
+ 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() {
@@ -2651,7 +2701,7 @@
// Apply DNS changes.
boolean changed = false;
synchronized (mDnsLock) {
- changed = updateDns("VPN", addresses, domains);
+ changed = updateDns("VPN", "VPN", addresses, domains);
mDnsOverridden = true;
}
if (changed) {
diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java
index 2597978..73d790a 100644
--- a/services/java/com/android/server/InputMethodManagerService.java
+++ b/services/java/com/android/server/InputMethodManagerService.java
@@ -50,6 +50,7 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Configuration;
@@ -165,7 +166,7 @@
private final KeyguardManager mKeyguardManager;
private final Notification mImeSwitcherNotification;
private final PendingIntent mImeSwitchPendingIntent;
- private final boolean mShowOngoingImeSwitcherForPhones;
+ private boolean mShowOngoingImeSwitcherForPhones;
private boolean mNotificationShown;
class SessionState {
@@ -537,8 +538,8 @@
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);
@@ -611,6 +612,8 @@
synchronized (mMethodMap) {
if (!mSystemReady) {
mSystemReady = true;
+ mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
+ com.android.internal.R.bool.show_ongoing_ime_switcher);
try {
startInputInnerLocked();
} catch (RuntimeException e) {
@@ -1046,7 +1049,16 @@
mStatusBar.setIconVisibility("ime", false);
} else if (packageName != null) {
if (DEBUG) Slog.d(TAG, "show a small icon for the input method");
- mStatusBar.setIcon("ime", packageName, iconId, 0);
+ CharSequence contentDescription = null;
+ try {
+ PackageManager packageManager = mContext.getPackageManager();
+ contentDescription = packageManager.getApplicationLabel(
+ packageManager.getApplicationInfo(packageName, 0));
+ } catch (NameNotFoundException nnfe) {
+ /* ignore */
+ }
+ mStatusBar.setIcon("ime", packageName, iconId, 0,
+ contentDescription != null ? contentDescription.toString() : null);
mStatusBar.setIconVisibility("ime", true);
}
}
@@ -1115,13 +1127,21 @@
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 41e8a31..17ad268f 100644
--- a/services/java/com/android/server/NetworkManagementService.java
+++ b/services/java/com/android/server/NetworkManagementService.java
@@ -93,6 +93,7 @@
private static final String KEY_TX = "tx_bytes";
class NetdResponseCode {
+ /* Keep in sync with system/netd/ResponseCode.h */
public static final int InterfaceListResult = 110;
public static final int TetherInterfaceListResult = 111;
public static final int TetherDnsFwdTgtListResult = 112;
@@ -108,6 +109,7 @@
public static final int InterfaceTxThrottleResult = 219;
public static final int InterfaceChange = 600;
+ public static final int BandwidthControl = 601;
}
/**
@@ -265,6 +267,20 @@
}
/**
+ * Notify our observers of a limit reached.
+ */
+ private void notifyLimitReached(String limitName, String iface) {
+ for (INetworkManagementEventObserver obs : mObservers) {
+ try {
+ obs.limitReached(limitName, iface);
+ Slog.d(TAG, "Observer notified limit reached for " + limitName + " " + iface);
+ } catch (Exception ex) {
+ Slog.w(TAG, "Observer notifier failed", ex);
+ }
+ }
+ }
+
+ /**
* Let us know the daemon is connected
*/
protected void onConnected() {
@@ -286,33 +302,52 @@
}.start();
}
public boolean onEvent(int code, String raw, String[] cooked) {
- if (code == NetdResponseCode.InterfaceChange) {
- /*
- * a network interface change occured
- * Format: "NNN Iface added <name>"
- * "NNN Iface removed <name>"
- * "NNN Iface changed <name> <up/down>"
- * "NNN Iface linkstatus <name> <up/down>"
- */
- if (cooked.length < 4 || !cooked[1].equals("Iface")) {
+ switch (code) {
+ case NetdResponseCode.InterfaceChange:
+ /*
+ * a network interface change occured
+ * Format: "NNN Iface added <name>"
+ * "NNN Iface removed <name>"
+ * "NNN Iface changed <name> <up/down>"
+ * "NNN Iface linkstatus <name> <up/down>"
+ */
+ if (cooked.length < 4 || !cooked[1].equals("Iface")) {
+ throw new IllegalStateException(
+ String.format("Invalid event from daemon (%s)", raw));
+ }
+ if (cooked[2].equals("added")) {
+ notifyInterfaceAdded(cooked[3]);
+ return true;
+ } else if (cooked[2].equals("removed")) {
+ notifyInterfaceRemoved(cooked[3]);
+ return true;
+ } else if (cooked[2].equals("changed") && cooked.length == 5) {
+ notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
+ return true;
+ } else if (cooked[2].equals("linkstate") && cooked.length == 5) {
+ notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
+ return true;
+ }
throw new IllegalStateException(
String.format("Invalid event from daemon (%s)", raw));
- }
- if (cooked[2].equals("added")) {
- notifyInterfaceAdded(cooked[3]);
- return true;
- } else if (cooked[2].equals("removed")) {
- notifyInterfaceRemoved(cooked[3]);
- return true;
- } else if (cooked[2].equals("changed") && cooked.length == 5) {
- notifyInterfaceStatusChanged(cooked[3], cooked[4].equals("up"));
- return true;
- } else if (cooked[2].equals("linkstate") && cooked.length == 5) {
- notifyInterfaceLinkStateChanged(cooked[3], cooked[4].equals("up"));
- return true;
- }
- throw new IllegalStateException(
- String.format("Invalid event from daemon (%s)", raw));
+ // break;
+ case NetdResponseCode.BandwidthControl:
+ /*
+ * Bandwidth control needs some attention
+ * Format: "NNN limit alert <alertName> <ifaceName>"
+ */
+ if (cooked.length < 5 || !cooked[1].equals("limit")) {
+ throw new IllegalStateException(
+ String.format("Invalid event from daemon (%s)", raw));
+ }
+ if (cooked[2].equals("alert")) {
+ notifyLimitReached(cooked[3], cooked[4]);
+ return true;
+ }
+ throw new IllegalStateException(
+ String.format("Invalid event from daemon (%s)", raw));
+ // break;
+ default: break;
}
return false;
}
@@ -814,7 +849,6 @@
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) {
@@ -862,13 +896,15 @@
}
}
- 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/NotificationManagerService.java b/services/java/com/android/server/NotificationManagerService.java
index 4ecdfed..8031c4e 100755
--- a/services/java/com/android/server/NotificationManagerService.java
+++ b/services/java/com/android/server/NotificationManagerService.java
@@ -262,7 +262,7 @@
public void onNotificationClick(String pkg, String tag, int id) {
cancelNotification(pkg, tag, id, Notification.FLAG_AUTO_CANCEL,
- Notification.FLAG_FOREGROUND_SERVICE, true);
+ Notification.FLAG_FOREGROUND_SERVICE, false);
}
public void onNotificationClear(String pkg, String tag, int id) {
@@ -469,6 +469,24 @@
record = mToastQueue.get(index);
record.update(duration);
} else {
+ // Limit the number of toasts that any given package except the android
+ // package can enqueue. Prevents DOS attacks and deals with leaks.
+ if (!"android".equals(pkg)) {
+ int count = 0;
+ final int N = mToastQueue.size();
+ for (int i=0; i<N; i++) {
+ final ToastRecord r = mToastQueue.get(i);
+ if (r.pkg.equals(pkg)) {
+ count++;
+ if (count >= MAX_PACKAGE_NOTIFICATIONS) {
+ Slog.e(TAG, "Package has already posted " + count
+ + " toasts. Not showing more. Package=" + pkg);
+ return;
+ }
+ }
+ }
+ }
+
record = new ToastRecord(callingPid, pkg, callback, duration);
mToastQueue.add(record);
index = mToastQueue.size() - 1;
diff --git a/services/java/com/android/server/StatusBarManagerService.java b/services/java/com/android/server/StatusBarManagerService.java
index 286a937..4ced83c 100644
--- a/services/java/com/android/server/StatusBarManagerService.java
+++ b/services/java/com/android/server/StatusBarManagerService.java
@@ -22,10 +22,10 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
-import android.os.IBinder;
-import android.os.RemoteException;
import android.os.Binder;
import android.os.Handler;
+import android.os.IBinder;
+import android.os.RemoteException;
import android.util.Slog;
import android.view.View;
@@ -175,7 +175,8 @@
}
}
- public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) {
+ public void setIcon(String slot, String iconPackage, int iconId, int iconLevel,
+ String contentDescription) {
enforceStatusBar();
synchronized (mIcons) {
@@ -184,7 +185,8 @@
throw new SecurityException("invalid status bar icon slot: " + slot);
}
- StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel);
+ StatusBarIcon icon = new StatusBarIcon(iconPackage, iconId, iconLevel, 0,
+ contentDescription);
//Slog.d(TAG, "setIcon slot=" + slot + " index=" + index + " icon=" + icon);
mIcons.setIcon(index, icon);
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.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 @@
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 @@
WallpaperManagerService wallpaper = null;
LocationManagerService location = null;
CountryDetectorService countryDetector = null;
+ TextServicesManagerService tsms = null;
if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
try {
@@ -273,6 +276,14 @@
}
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 @@
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 @@
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 @@
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..3e76a3a1
--- /dev/null
+++ b/services/java/com/android/server/TextServicesManagerService.java
@@ -0,0 +1,383 @@
+/*
+ * 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) return;
+ 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);
+ }
+ if (DBG) {
+ Slog.d(TAG, "buildSpellCheckerMapLocked: " + list.size() + "," + map.size());
+ }
+ }
+
+ // 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())) {
+ if (DBG) {
+ Slog.d(TAG, "findAvailSpellCheckerLocked: " + 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) {
+ String curSpellCheckerId =
+ Settings.Secure.getString(mContext.getContentResolver(),
+ Settings.Secure.SPELL_CHECKER_SERVICE);
+ if (DBG) {
+ Slog.w(TAG, "getCurrentSpellChecker: " + curSpellCheckerId);
+ }
+ if (TextUtils.isEmpty(curSpellCheckerId)) {
+ final SpellCheckerInfo sci = findAvailSpellCheckerLocked(null, null);
+ if (sci == null) return null;
+ // 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);
+ return sci;
+ }
+ 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() {
+ if (DBG) {
+ Slog.d(TAG, "getEnabledSpellCheckers: " + mSpellCheckerList.size());
+ for (int i = 0; i < mSpellCheckerList.size(); ++i) {
+ Slog.d(TAG, "EnabledSpellCheckers: " + mSpellCheckerList.get(i).getPackageName());
+ }
+ }
+ return mSpellCheckerList.toArray(new SpellCheckerInfo[mSpellCheckerList.size()]);
+ }
+
+ @Override
+ public void finishSpellCheckerService(ISpellCheckerSessionListener listener) {
+ if (DBG) {
+ Slog.d(TAG, "FinishSpellCheckerService");
+ }
+ 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) {
+ if (DBG) {
+ Slog.d(TAG, "onServiceConnected");
+ }
+ 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) {
+ if (DBG) {
+ Slog.d(TAG, "addListener: " + locale);
+ }
+ 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) {
+ if (DBG) {
+ Slog.d(TAG, "remove 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 (DBG) {
+ Slog.d(TAG, "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/ThrottleService.java b/services/java/com/android/server/ThrottleService.java
index b8890aa..cd649ce 100644
--- a/services/java/com/android/server/ThrottleService.java
+++ b/services/java/com/android/server/ThrottleService.java
@@ -194,6 +194,7 @@
}
public void interfaceRemoved(String iface) {}
+ public void limitReached(String limitName, String iface) {}
}
diff --git a/services/java/com/android/server/VibratorService.java b/services/java/com/android/server/VibratorService.java
index c39dc80..de25747 100755
--- a/services/java/com/android/server/VibratorService.java
+++ b/services/java/com/android/server/VibratorService.java
@@ -383,6 +383,12 @@
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
synchronized (mVibrations) {
doCancelVibrateLocked();
+
+ int size = mVibrations.size();
+ for(int i = 0; i < size; i++) {
+ unlinkVibration(mVibrations.get(i));
+ }
+
mVibrations.clear();
}
}
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 7112553..f9f63b1 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -1461,7 +1461,7 @@
if (mMulticasters.size() != 0) {
return;
} else {
- mWifiStateMachine.startPacketFiltering();
+ mWifiStateMachine.startFilteringMulticastV4Packets();
}
}
}
@@ -1472,11 +1472,11 @@
synchronized (mMulticasters) {
mMulticastEnabled++;
mMulticasters.add(new Multicaster(tag, binder));
- // Note that we could call stopPacketFiltering only when
+ // Note that we could call stopFilteringMulticastV4Packets only when
// our new size == 1 (first call), but this function won't
// be called often and by making the stopPacket call each
// time we're less fragile and self-healing.
- mWifiStateMachine.stopPacketFiltering();
+ mWifiStateMachine.stopFilteringMulticastV4Packets();
}
int uid = Binder.getCallingUid();
@@ -1513,7 +1513,7 @@
removed.unlinkDeathRecipient();
}
if (mMulticasters.size() == 0) {
- mWifiStateMachine.startPacketFiltering();
+ mWifiStateMachine.startFilteringMulticastV4Packets();
}
Long ident = Binder.clearCallingIdentity();
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.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 @@
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 @@
manageServicesLocked();
}
}
-
+
@Override
public boolean onHandleForceStop(Intent intent, String[] packages,
int uid, boolean doit) {
@@ -236,17 +237,16 @@
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 @@
} 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 @@
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 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 @@
}
}
}, 0);
- return mIsAccessibilityEnabled;
+ return getState();
}
}
@@ -628,7 +629,7 @@
service.linkToOwnDeath();
mServices.add(service);
mComponentNameToServiceMap.put(service.mComponentName, service);
- updateTouchExplorationEnabledLocked();
+ updateInputFilterLocked();
} catch (RemoteException e) {
/* do nothing */
}
@@ -648,7 +649,7 @@
mComponentNameToServiceMap.remove(service.mComponentName);
mHandler.removeMessages(service.mId);
service.unlinkToOwnDeath();
- updateTouchExplorationEnabledLocked();
+ updateInputFilterLocked();
return removed;
}
@@ -781,12 +782,13 @@
}
/**
- * 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 @@
}
/**
- * 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 @@
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 @@
// 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 @@
mPointerTracker = new PointerTracker(context);
mHandler = new Handler(context.getMainLooper());
mSendHoverDelayed = new SendHoverDelayed();
+ mPerformLongPressDelayed = new PerformLongPressDelayed();
mAccessibilityManager = AccessibilityManager.getInstance(context);
}
@@ -208,15 +212,7 @@
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 @@
+ "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 @@
// 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 @@
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 @@
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 @@
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 @@
} 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 @@
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 @@
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 @@
}
// All preconditions are met, so click the last explored location.
- mSendHoverDelayed.forceSendAndRemove();
sendActionDownAndUp(mLastTouchExploreEvent, policyFlags);
mLastTouchExploreEvent = null;
} else {
@@ -448,6 +441,8 @@
}
} 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 @@
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 @@
mPrimaryActivePointerId = 0;
mHasMovingActivePointer = false;
mInjectedPointersDown = 0;
- mLastReceivedUpPointerDownX = 0;
- mLastReveivedUpPointerDownY = 0;
mLastReceivedUpPointerDownTime = 0;
mLastReceivedUpPointerId = 0;
mLastReceivedUpPointerActive = false;
@@ -1126,20 +1117,6 @@
}
/**
- * @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 @@
final int pointerFlag = (1 << pointerId);
mLastReceivedUpPointerId = 0;
- mLastReceivedUpPointerDownX = 0;
- mLastReveivedUpPointerDownY = 0;
mLastReceivedUpPointerDownTime = 0;
mLastReceivedUpPointerActive = false;
@@ -1262,8 +1237,6 @@
final int pointerFlag = (1 << pointerId);
mLastReceivedUpPointerId = pointerId;
- mLastReceivedUpPointerDownX = getReceivedPointerDownX(pointerId);
- mLastReveivedUpPointerDownY = getReceivedPointerDownY(pointerId);
mLastReceivedUpPointerDownTime = getReceivedPointerDownTime(pointerId);
mLastReceivedUpPointerActive = isActivePointer(pointerId);
@@ -1400,6 +1373,51 @@
}
/**
+ * 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/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 0924b86..3389f33 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -3628,6 +3628,7 @@
app.setSchedGroup = Process.THREAD_GROUP_BG_NONINTERACTIVE;
app.forcingToForeground = null;
app.foregroundServices = false;
+ app.hasShownUi = false;
app.debugging = false;
mHandler.removeMessages(PROC_START_TIMEOUT_MSG, app);
@@ -9218,6 +9219,7 @@
app.forcingToForeground = null;
app.foregroundServices = false;
app.foregroundActivities = false;
+ app.hasShownUi = false;
killServicesLocked(app, true);
@@ -9331,8 +9333,6 @@
// This app is persistent, so we need to keep its record around.
// If it is not already on the pending app list, add it there
// and start a new process for it.
- app.forcingToForeground = null;
- app.foregroundServices = false;
if (mPersistentStartingProcesses.indexOf(app) < 0) {
mPersistentStartingProcesses.add(app);
restart = true;
@@ -12728,21 +12728,31 @@
while (jt.hasNext() && adj > FOREGROUND_APP_ADJ) {
ServiceRecord s = jt.next();
if (s.startRequested) {
- if (now < (s.lastActivity+MAX_SERVICE_INACTIVITY)) {
- // This service has seen some activity within
- // recent memory, so we will keep its process ahead
- // of the background processes.
+ if (app.hasShownUi) {
+ // If this process has shown some UI, let it immediately
+ // go to the LRU list because it may be pretty heavy with
+ // UI stuff. We'll tag it with a label just to help
+ // debug and understand what is going on.
if (adj > SECONDARY_SERVER_ADJ) {
- adj = SECONDARY_SERVER_ADJ;
- app.adjType = "started-services";
- app.hidden = false;
+ app.adjType = "started-bg-ui-services";
}
- }
- // If we have let the service slide into the background
- // state, still have some text describing what it is doing
- // even though the service no longer has an impact.
- if (adj > SECONDARY_SERVER_ADJ) {
- app.adjType = "started-bg-services";
+ } else {
+ if (now < (s.lastActivity+MAX_SERVICE_INACTIVITY)) {
+ // This service has seen some activity within
+ // recent memory, so we will keep its process ahead
+ // of the background processes.
+ if (adj > SECONDARY_SERVER_ADJ) {
+ adj = SECONDARY_SERVER_ADJ;
+ app.adjType = "started-services";
+ app.hidden = false;
+ }
+ }
+ // If we have let the service slide into the background
+ // state, still have some text describing what it is doing
+ // even though the service no longer has an impact.
+ if (adj > SECONDARY_SERVER_ADJ) {
+ app.adjType = "started-bg-services";
+ }
}
// Don't kill this process because it is doing work; it
// has said it is doing work.
@@ -13351,15 +13361,15 @@
break;
}
}
- } else if (app.curAdj >= PERCEPTIBLE_APP_ADJ) {
- if (app.trimMemoryLevel < ComponentCallbacks.TRIM_MEMORY_INVISIBLE
+ } else if (app.curAdj == HEAVY_WEIGHT_APP_ADJ) {
+ if (app.trimMemoryLevel < ComponentCallbacks.TRIM_MEMORY_BACKGROUND
&& app.thread != null) {
try {
- app.thread.scheduleTrimMemory(ComponentCallbacks.TRIM_MEMORY_INVISIBLE);
+ app.thread.scheduleTrimMemory(ComponentCallbacks.TRIM_MEMORY_BACKGROUND);
} catch (RemoteException e) {
}
}
- app.trimMemoryLevel = ComponentCallbacks.TRIM_MEMORY_INVISIBLE;
+ app.trimMemoryLevel = ComponentCallbacks.TRIM_MEMORY_BACKGROUND;
} else {
app.trimMemoryLevel = 0;
}
@@ -13442,7 +13452,7 @@
}
public boolean profileControl(String process, boolean start,
- String path, ParcelFileDescriptor fd) throws RemoteException {
+ String path, ParcelFileDescriptor fd, int profileType) throws RemoteException {
try {
synchronized (this) {
@@ -13487,7 +13497,7 @@
}
}
- proc.thread.profilerControl(start, path, fd);
+ proc.thread.profilerControl(start, path, fd, profileType);
fd = null;
return true;
}
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 0d89081..cc58eaf 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -559,6 +559,7 @@
r.forceNewConfig = false;
showAskCompatModeDialogLocked(r);
r.compat = mService.compatibilityInfoForPackageLocked(r.info.applicationInfo);
+ app.hasShownUi = true;
app.thread.scheduleLaunchActivity(new Intent(r.intent), r,
System.identityHashCode(r),
r.info, r.compat, r.icicle, results, newIntents, !andResume,
diff --git a/services/java/com/android/server/am/ProcessRecord.java b/services/java/com/android/server/am/ProcessRecord.java
index 9e597aa..5b59363 100644
--- a/services/java/com/android/server/am/ProcessRecord.java
+++ b/services/java/com/android/server/am/ProcessRecord.java
@@ -66,6 +66,7 @@
boolean setIsForeground; // Running foreground UI when last set?
boolean foregroundServices; // Running any services that are foreground?
boolean foregroundActivities; // Running any activities that are foreground?
+ boolean hasShownUi; // Has UI been shown in this process since it was started?
boolean bad; // True if disabled in the bad process list
boolean killedBackground; // True when proc has been killed due to too many bg
String waitingToKill; // Process is waiting to be killed when in the bg; reason
@@ -185,6 +186,7 @@
pw.print(prefix); pw.print("curSchedGroup="); pw.print(curSchedGroup);
pw.print(" setSchedGroup="); pw.print(setSchedGroup);
pw.print(" trimMemoryLevel="); pw.println(trimMemoryLevel);
+ pw.print(" hasShownUi="); pw.println(hasShownUi);
pw.print(prefix); pw.print("setIsForeground="); pw.print(setIsForeground);
pw.print(" foregroundServices="); pw.print(foregroundServices);
pw.print(" forcingToForeground="); pw.println(forcingToForeground);
diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java
index d7d4b03..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.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 @@
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 @@
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 @@
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 @@
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 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 @@
}
return false;
}
+
public void interfaceAdded(String iface) {
boolean found = false;
boolean usb = false;
@@ -288,6 +281,8 @@
}
}
+ public void limitReached(String limitName, String iface) {}
+
public int tether(String iface) {
Log.d(TAG, "Tethering " + iface);
TetherInterfaceSM sm = null;
@@ -454,47 +449,28 @@
}
}
- 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 {
@@ -505,83 +481,50 @@
}
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);
- }
- } catch (Exception e) {
- Log.e(TAG, "Error configuring interface " + iface, e);
- return false;
- }
- }
- }
- } finally {
- if (!enabled) {
- enableUsbRndis(false);
- }
+ 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);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Error configuring interface " + iface, e);
+ return false;
+ }
+ }
+ }
return true;
}
@@ -598,6 +541,28 @@
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 05e95a7..9cb772e 100644
--- a/services/java/com/android/server/connectivity/Vpn.java
+++ b/services/java/com/android/server/connectivity/Vpn.java
@@ -248,6 +248,8 @@
}
}
+ public void limitReached(String limitName, String iface) {}
+
private void showNotification(VpnConfig config, String label, Bitmap icon) {
NotificationManager nm = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -394,7 +396,7 @@
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 @@
}
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/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java
index c80cd0a..f183f83 100644
--- a/services/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/java/com/android/server/usb/UsbDeviceManager.java
@@ -19,6 +19,7 @@
import android.app.PendingIntent;
import android.app.Notification;
import android.app.NotificationManager;
+import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -80,6 +81,7 @@
private static final int MSG_ENABLE_ADB = 1;
private static final int MSG_SET_CURRENT_FUNCTION = 2;
private static final int MSG_SYSTEM_READY = 3;
+ private static final int MSG_BOOT_COMPLETED = 4;
// Delay for debouncing USB disconnects.
// We often get rapid connect/disconnect events when enabling USB functions,
@@ -87,7 +89,7 @@
private static final int UPDATE_DELAY = 1000;
private UsbHandler mHandler;
- private boolean mSystemReady;
+ private boolean mBootCompleted;
private final Context mContext;
private final ContentResolver mContentResolver;
@@ -141,10 +143,15 @@
Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mHandler = new UsbHandler(thread.getLooper());
+
+ if (nativeIsStartRequested()) {
+ if (DEBUG) Slog.d(TAG, "accessory attached at boot");
+ setCurrentFunction(UsbManager.USB_FUNCTION_ACCESSORY, false);
+ }
}
public void systemReady() {
- mSystemReady = true;
+ if (DEBUG) Slog.d(TAG, "systemReady");
mNotificationManager = (NotificationManager)
mContext.getSystemService(Context.NOTIFICATION_SERVICE);
@@ -236,15 +243,22 @@
private String mCurrentFunctions;
private String mDefaultFunctions;
private UsbAccessory mCurrentAccessory;
- private boolean mDeferAccessoryAttached;
private int mUsbNotificationId;
private boolean mAdbNotificationShown;
+ private final BroadcastReceiver mBootCompletedReceiver = new BroadcastReceiver() {
+ public void onReceive(Context context, Intent intent) {
+ if (DEBUG) Slog.d(TAG, "boot completed");
+ mHandler.sendEmptyMessage(MSG_BOOT_COMPLETED);
+ }
+ };
+
private static final int NOTIFICATION_NONE = 0;
private static final int NOTIFICATION_MTP = 1;
private static final int NOTIFICATION_PTP = 2;
private static final int NOTIFICATION_INSTALLER = 3;
- private static final int NOTIFICATION_ADB = 4;
+ private static final int NOTIFICATION_ACCESSORY = 4;
+ private static final int NOTIFICATION_ADB = 5;
public UsbHandler(Looper looper) {
super(looper);
@@ -285,6 +299,9 @@
// Watch for USB configuration changes
mUEventObserver.startObserving(USB_STATE_MATCH);
mUEventObserver.startObserving(ACCESSORY_START_MATCH);
+
+ mContext.registerReceiver(mBootCompletedReceiver,
+ new IntentFilter(Intent.ACTION_BOOT_COMPLETED));
} catch (Exception e) {
Slog.e(TAG, "Error initializing UsbHandler", e);
}
@@ -406,11 +423,9 @@
mCurrentAccessory = new UsbAccessory(strings);
Slog.d(TAG, "entering USB accessory mode: " + mCurrentAccessory);
// defer accessoryAttached if system is not ready
- if (mSystemReady) {
+ if (mBootCompleted) {
mSettingsManager.accessoryAttached(mCurrentAccessory);
- } else {
- mDeferAccessoryAttached = true;
- }
+ } // else handle in mBootCompletedReceiver
} else {
Slog.e(TAG, "nativeGetAccessoryStrings failed");
}
@@ -421,7 +436,7 @@
setEnabledFunctions(mDefaultFunctions);
if (mCurrentAccessory != null) {
- if (mSystemReady) {
+ if (mBootCompleted) {
mSettingsManager.accessoryDetached(mCurrentAccessory);
}
mCurrentAccessory = null;
@@ -463,7 +478,7 @@
// restore defaults when USB is disconnected
doSetCurrentFunctions(mDefaultFunctions);
}
- if (mSystemReady) {
+ if (mBootCompleted) {
updateUsbState();
}
break;
@@ -497,7 +512,10 @@
updateUsbNotification();
updateAdbNotification();
updateUsbState();
- if (mCurrentAccessory != null && mDeferAccessoryAttached) {
+ break;
+ case MSG_BOOT_COMPLETED:
+ mBootCompleted = true;
+ if (mCurrentAccessory != null) {
mSettingsManager.accessoryAttached(mCurrentAccessory);
}
break;
@@ -527,6 +545,10 @@
title = r.getText(
com.android.internal.R.string.usb_cd_installer_notification_title);
id = NOTIFICATION_INSTALLER;
+ } else if (containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ACCESSORY)) {
+ title = r.getText(
+ com.android.internal.R.string.usb_accessory_notification_title);
+ id = NOTIFICATION_ACCESSORY;
} else {
Slog.e(TAG, "No known USB function in updateUsbNotification");
}
@@ -671,4 +693,5 @@
private native String[] nativeGetAccessoryStrings();
private native ParcelFileDescriptor nativeOpenAccessory();
+ private native boolean nativeIsStartRequested();
}
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 @@
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/jni/com_android_server_UsbDeviceManager.cpp b/services/jni/com_android_server_UsbDeviceManager.cpp
index 6954171..40f0dbd 100644
--- a/services/jni/com_android_server_UsbDeviceManager.cpp
+++ b/services/jni/com_android_server_UsbDeviceManager.cpp
@@ -99,11 +99,26 @@
gParcelFileDescriptorOffsets.mConstructor, fileDescriptor);
}
+static jboolean android_server_UsbDeviceManager_isStartRequested(JNIEnv *env, jobject thiz)
+{
+ int fd = open(DRIVER_NAME, O_RDWR);
+ if (fd < 0) {
+ LOGE("could not open %s", DRIVER_NAME);
+ return false;
+ }
+ int result = ioctl(fd, ACCESSORY_IS_START_REQUESTED);
+ close(fd);
+ return (result == 1);
+}
+
+
static JNINativeMethod method_table[] = {
{ "nativeGetAccessoryStrings", "()[Ljava/lang/String;",
(void*)android_server_UsbDeviceManager_getAccessoryStrings },
{ "nativeOpenAccessory", "()Landroid/os/ParcelFileDescriptor;",
(void*)android_server_UsbDeviceManager_openAccessory },
+ { "nativeIsStartRequested", "()Z",
+ (void*)android_server_UsbDeviceManager_isStartRequested },
};
int register_android_server_UsbDeviceManager(JNIEnv *env)
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 @@
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.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 @@
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 @@
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 @@
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 @@
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 @@
* 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 @@
// 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 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 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 @@
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 @@
// 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 @@
// 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..3bd78e04 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.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 @@
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/PhoneBase.java b/telephony/java/com/android/internal/telephony/PhoneBase.java
index 40a70a8..a0961ca 100644
--- a/telephony/java/com/android/internal/telephony/PhoneBase.java
+++ b/telephony/java/com/android/internal/telephony/PhoneBase.java
@@ -806,10 +806,10 @@
mNotifier.notifyDataConnection(this, reason, apnType, getDataConnectionState(apnType));
}
- public void notifyDataConnection() {
+ public void notifyDataConnection(String reason) {
String types[] = getActiveApnTypes();
for (String apnType : types) {
- mNotifier.notifyDataConnection(this, null, apnType, getDataConnectionState(apnType));
+ mNotifier.notifyDataConnection(this, reason, apnType, getDataConnectionState(apnType));
}
}
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 @@
// 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 0d551aa..d3bb6a5 100644
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaLteServiceStateTracker.java
@@ -134,8 +134,6 @@
}
}
- // Not sure if this is needed in CDMALTE phone.
- // mDataRoaming = regCodeIsRoaming(regState);
mLteSS.setRadioTechnology(type);
mLteSS.setState(regCodeToServiceState(regState));
} else {
@@ -249,10 +247,11 @@
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) ||
@@ -345,13 +344,14 @@
}
if (cm.getSimState().isSIMReady()) {
- // SIM is found on the device. If ERI roaming is OFF, use operator name
- // from CSIM record.
+ // SIM is found on the device. If ERI roaming is OFF and SID/NID matches
+ // one configfured in SIM, use operator name from CSIM record.
boolean showSpn =
((CdmaLteUiccRecords)phone.mIccRecords).getCsimSpnDisplayCondition();
int iconIndex = ss.getCdmaEriIconIndex();
- if (showSpn && (iconIndex == EriInfo.ROAMING_INDICATOR_OFF)) {
+ if (showSpn && (iconIndex == EriInfo.ROAMING_INDICATOR_OFF) &&
+ isInHomeSidNid(ss.getSystemId(), ss.getNetworkId())) {
ss.setOperatorAlphaLong(phone.mIccRecords.getServiceProviderName());
}
}
@@ -392,7 +392,7 @@
phone.notifyServiceStateChanged(ss);
}
- if (hasCdmaDataConnectionAttached) {
+ if (hasCdmaDataConnectionAttached || has4gHandoff) {
mAttachedRegistrants.notifyRegistrants();
}
@@ -401,7 +401,7 @@
}
if ((hasCdmaDataConnectionChanged || hasNetworkTypeChanged)) {
- phone.notifyDataConnection();
+ phone.notifyDataConnection(null);
}
if (hasRoamingOn) {
@@ -469,6 +469,34 @@
}
/**
+ * Check whether the specified SID and NID pair appears in the HOME SID/NID list
+ * read from NV or SIM.
+ *
+ * @return true if provided sid/nid pair belongs to operator's home network.
+ */
+ private boolean isInHomeSidNid(int sid, int nid) {
+ // if SID/NID is not available, assume this is home network.
+ if (isSidsAllZeros()) return true;
+
+ // length of SID/NID shold be same
+ if (mHomeSystemId.length != mHomeNetworkId.length) return true;
+
+ if (sid == 0) return true;
+
+ for (int i = 0; i < mHomeSystemId.length; i++) {
+ // Use SID only if NID is a reserved value.
+ // SID 0 and NID 0 and 65535 are reserved. (C.0005 2.6.5.2)
+ if ((mHomeSystemId[i] == sid) &&
+ ((mHomeNetworkId[i] == 0) || (mHomeNetworkId[i] == 65535) ||
+ (nid == 0) || (nid == 65535) || (mHomeNetworkId[i] == nid))) {
+ return true;
+ }
+ }
+ // SID/NID are not in the list. So device is not in home network
+ return false;
+ }
+
+ /**
* Returns OTASP_NOT_NEEDED as its not needed for LTE
*/
@Override
diff --git a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
index 24a468a..2cf4b88 100755
--- a/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/cdma/CdmaServiceStateTracker.java
@@ -130,8 +130,8 @@
protected String mCurPlmn = null;
protected String mMdn;
- private int mHomeSystemId[] = null;
- private int mHomeNetworkId[] = null;
+ protected int mHomeSystemId[] = null;
+ protected int mHomeNetworkId[] = null;
protected String mMin;
protected String mPrlVersion;
protected boolean mIsMinInfoReady = false;
@@ -999,7 +999,7 @@
}
if (hasCdmaDataConnectionChanged || hasNetworkTypeChanged) {
- phone.notifyDataConnection();
+ phone.notifyDataConnection(null);
}
if (hasRoamingOn) {
@@ -1481,7 +1481,7 @@
}
}
- private boolean isSidsAllZeros() {
+ protected boolean isSidsAllZeros() {
if (mHomeSystemId != null) {
for (int i=0; i < mHomeSystemId.length; i++) {
if (mHomeSystemId[i] != 0) {
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 @@
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 @@
// 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 @@
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 @@
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/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
index 93f4b4e..d3645fa 100644
--- a/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
+++ b/telephony/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java
@@ -915,7 +915,7 @@
}
if (hasRadioTechnologyChanged) {
- phone.notifyDataConnection(Phone.REASON_NW_TYPE_CHANGED, Phone.APN_TYPE_ALL);
+ phone.notifyDataConnection(Phone.REASON_NW_TYPE_CHANGED);
}
if (hasRoamingOn) {
diff --git a/tests/GridLayoutTest/res/layout/grid3.xml b/tests/GridLayoutTest/res/layout/grid3.xml
index 3c2db54..2eca384 100644
--- a/tests/GridLayoutTest/res/layout/grid3.xml
+++ b/tests/GridLayoutTest/res/layout/grid3.xml
@@ -27,8 +27,8 @@
>
<TextView
- android:text="Email account"
- android:textSize="48dip"
+ android:text="Email setup"
+ android:textSize="32dip"
android:layout_columnSpan="4"
android:layout_gravity="center_horizontal"
@@ -36,7 +36,7 @@
<TextView
android:text="You can configure email in just a few steps:"
- android:textSize="20dip"
+ android:textSize="16dip"
android:layout_columnSpan="4"
android:layout_gravity="left"
@@ -49,7 +49,7 @@
/>
<EditText
- android:layout_width="100dip"
+ android:layout_width="64dip"
/>
<TextView
@@ -60,14 +60,14 @@
/>
<EditText
- android:layout_width="50dip"
+ android:layout_width="32dip"
/>
<Space
android:layout_row="4"
android:layout_column="2"
- android:layout_rowFlexibility="canStretch"
- android:layout_columnFlexibility="canStretch"
+ android:layout_margin="0dip"
+ android:layout_gravity="fill"
/>
<Button
@@ -75,7 +75,6 @@
android:layout_row="5"
android:layout_column="3"
- android:layout_gravity="fill_horizontal"
/>
<Button
diff --git a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
index 38a85a3..e1871ac 100644
--- a/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
+++ b/tests/GridLayoutTest/src/com/android/test/layout/Activity2.java
@@ -38,30 +38,31 @@
vg.setUseDefaultMargins(true);
vg.setAlignmentMode(ALIGN_BOUNDS);
- Spec row1 = spec(0, CENTER);
- Spec row2 = spec(1, CENTER);
+ Spec row1 = spec(0);
+ Spec row2 = spec(1);
Spec row3 = spec(2, BASELINE);
Spec row4 = spec(3, BASELINE);
- Spec row5 = spec(4, FILL, CAN_STRETCH);
- Spec row6 = spec(5, CENTER);
- Spec row7 = spec(6, CENTER);
+ Spec row5 = spec(4, FILL);
+ Spec row6 = spec(5);
+ Spec row7 = spec(6);
Spec col1a = spec(0, 4, CENTER);
Spec col1b = spec(0, 4, LEFT);
Spec col1c = spec(0, RIGHT);
Spec col2 = spec(1, LEFT);
- Spec col3 = spec(2, FILL, CAN_STRETCH);
- Spec col4 = spec(3, FILL);
+ Spec col3 = spec(2, FILL);
+ Spec col4a = spec(3);
+ Spec col4b = spec(3, FILL);
{
TextView v = new TextView(context);
- v.setTextSize(48);
+ v.setTextSize(32);
v.setText("Email setup");
vg.addView(v, new LayoutParams(row1, col1a));
}
{
TextView v = new TextView(context);
- v.setTextSize(20);
+ v.setTextSize(16);
v.setText("You can configure email in just a few steps:");
vg.addView(v, new LayoutParams(row2, col1b));
}
@@ -75,7 +76,7 @@
v.setInputType(TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
{
LayoutParams lp = new LayoutParams(row3, col2);
- lp.width = (int) v.getPaint().measureText("Frederick.W.Flintstone@bedrock.com ");
+ lp.width = (int) v.getPaint().measureText("Frederick.W.Flintstone");
vg.addView(v, lp);
}
}
@@ -95,17 +96,19 @@
}
{
Space v = new Space(context);
- vg.addView(v, new LayoutParams(row5, col3));
+ LayoutParams lp = new LayoutParams(row5, col3);
+ lp.setMargins(0, 0, 0, 0);
+ vg.addView(v, lp);
}
{
Button v = new Button(context);
v.setText("Manual setup");
- vg.addView(v, new LayoutParams(row6, col4));
+ vg.addView(v, new LayoutParams(row6, col4a));
}
{
Button v = new Button(context);
v.setText("Next");
- vg.addView(v, new LayoutParams(row7, col4));
+ vg.addView(v, new LayoutParams(row7, col4b));
}
return vg;
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ListActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ListActivity.java
index 1493ab9..13b6129 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ListActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ListActivity.java
@@ -93,12 +93,9 @@
}
public void startProfiling(View v) {
- ViewDebug.startLooperProfiling(new File(Environment.getExternalStorageDirectory(),
- "looper.trace"));
}
public void stopProfiling(View v) {
- ViewDebug.stopLooperProfiling();
}
@Override
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 @@
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/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs
index 16ebe08..d93238c 100644
--- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs
+++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs
@@ -84,10 +84,10 @@
fs.radius = radius;
fs.ain = rsGetAllocation(ScratchPixel1);
- rsForEach(hBlurScript, fs.ain, rsGetAllocation(ScratchPixel2), &fs);
+ rsForEach(hBlurScript, fs.ain, rsGetAllocation(ScratchPixel2), &fs, sizeof(fs));
fs.ain = rsGetAllocation(ScratchPixel2);
- rsForEach(vBlurScript, fs.ain, rsGetAllocation(OutPixel), &fs);
+ rsForEach(vBlurScript, fs.ain, rsGetAllocation(OutPixel), &fs, sizeof(fs));
rsSendToClientBlocking(CMD_FINISHED);
}
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/scenegraph.rs b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/scenegraph.rs
index f046952..0e619ea 100644
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/scenegraph.rs
+++ b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/scenegraph.rs
@@ -60,7 +60,7 @@
robot2Ptr->transforms[1].w += 2.5f;
robot2Ptr->isDirty = 1;
- rsForEach(gTransformRS, gRootNode->children, gRootNode->children, 0);
+ rsForEach(gTransformRS, gRootNode->children, gRootNode->children, NULL, 0);
rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
rsgClearDepth(1.0f);
diff --git a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform.rs b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform.rs
index f328025..85c0630 100644
--- a/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform.rs
+++ b/tests/RenderScriptTests/ModelViewer/src/com/android/modelviewer/transform.rs
@@ -91,6 +91,6 @@
//rsDebug("Transform calling self with child ", (int)data->children.p);
if (data->children.p) {
- rsForEach(transformScript, data->children, data->children, (void*)&toChild);
+ rsForEach(transformScript, data->children, data->children, (void*)&toChild, sizeof(toChild));
}
}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
index eaafe1d..db97835 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
@@ -280,7 +280,7 @@
testData.renderSurfaceW = gRenderSurfaceW;
testData.renderSurfaceH = gRenderSurfaceH;
testData.user = fillNum;
- rsForEach(gFontScript, gDummyAlloc, gDummyAlloc, &testData);
+ rsForEach(gFontScript, gDummyAlloc, gDummyAlloc, &testData, sizeof(testData));
}
static void bindProgramVertexOrtho() {
@@ -520,7 +520,7 @@
testData.user = 0;
testData.user1 = useTexture ? 1 : 0;
testData.user2 = numMeshes;
- rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData);
+ rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData, sizeof(testData));
}
static void displayCustomShaderSamples(int numMeshes) {
@@ -530,7 +530,7 @@
testData.dt = gDt;
testData.user = 1;
testData.user1 = numMeshes;
- rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData);
+ rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData, sizeof(testData));
}
static void displayPixelLightSamples(int numMeshes, bool heavyVertex) {
@@ -541,7 +541,7 @@
testData.user = 2;
testData.user1 = numMeshes;
testData.user2 = heavyVertex ? 1 : 0;
- rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData);
+ rsForEach(gTorusScript, gDummyAlloc, gDummyAlloc, &testData, sizeof(testData));
}
static void displayMultitextureSample(bool blend, int quadCount) {
diff --git a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
index b212533..e75a079 100644
--- a/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
+++ b/tests/StatusBar/src/com/android/statusbartest/StatusBarTest.java
@@ -100,22 +100,22 @@
new Test("Double Remove") {
public void run() {
Log.d(TAG, "set 0");
- mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0);
+ mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0, null);
Log.d(TAG, "remove 1");
mStatusBarManager.removeIcon("tty");
SystemClock.sleep(1000);
Log.d(TAG, "set 1");
- mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0);
+ mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0, null);
if (false) {
Log.d(TAG, "set 2");
- mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0);
+ mStatusBarManager.setIcon("tty", R.drawable.stat_sys_phone, 0, null);
}
Log.d(TAG, "remove 2");
mStatusBarManager.removeIcon("tty");
Log.d(TAG, "set 3");
- mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0);
+ mStatusBarManager.setIcon("speakerphone", R.drawable.stat_sys_phone, 0, null);
}
},
new Test("Hide (FLAG_FULLSCREEN)") {
diff --git a/tests/TileBenchmark/AndroidManifest.xml b/tests/TileBenchmark/AndroidManifest.xml
index 663cc0d..ab61a9e 100644
--- a/tests/TileBenchmark/AndroidManifest.xml
+++ b/tests/TileBenchmark/AndroidManifest.xml
@@ -7,14 +7,16 @@
android:label="@string/app_name"
android:hardwareAccelerated="true">
<activity android:name=".ProfileActivity"
- android:label="@string/profile_activity">
+ android:label="@string/profile_activity"
+ android:theme="@android:style/Theme.Holo.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PlaybackActivity"
- android:label="@string/playback_activity">
+ android:label="@string/playback_activity"
+ android:theme="@android:style/Theme.Holo.NoActionBar">
</activity>
</application>
</manifest>
diff --git a/tests/TileBenchmark/res/layout/main.xml b/tests/TileBenchmark/res/layout/main.xml
index 4a81da6..577c466 100644
--- a/tests/TileBenchmark/res/layout/main.xml
+++ b/tests/TileBenchmark/res/layout/main.xml
@@ -23,11 +23,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
- <Button
- android:id="@+id/inspect"
+ <Spinner
+ android:id="@+id/movement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/inspect_log"
+ android:prompt="@string/movement_method"
/>
<Spinner
android:id="@+id/velocity"
@@ -36,6 +36,13 @@
android:gravity="center_horizontal"
android:prompt="@string/desired_scroll_velocity"
/>
+ <ToggleButton
+ android:id="@+id/capture"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textOn="@string/capture_stop"
+ android:textOff="@string/capture_start"
+ />
<EditText
android:id="@+id/url"
android:layout_width="0dip"
@@ -44,6 +51,12 @@
android:imeOptions="actionGo"
android:layout_weight="1"
/>
+ <Button
+ android:id="@+id/inspect"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/inspect_log"
+ />
</LinearLayout>
<com.test.tilebenchmark.ProfiledWebView
android:id="@+id/web"
diff --git a/tests/TileBenchmark/res/values/colors.xml b/tests/TileBenchmark/res/values/colors.xml
index 3958083..dbb8e72 100644
--- a/tests/TileBenchmark/res/values/colors.xml
+++ b/tests/TileBenchmark/res/values/colors.xml
@@ -18,8 +18,17 @@
<color name="ready_tile">#ff4ac230</color>
<!-- The color of tiles with stale / invalid textures -->
<color name="unready_tile">#ff744400</color>
- <!-- Background color for logged URLs -->
- <color name="finished_url">#ff004000</color>
- <!-- Background color for URLs with logging in progress -->
- <color name="unfinished_url">#ff400000</color>
+ <!-- Viewport overlay in playback -->
+ <color name="view">#50000050</color>
+ <!-- Invalidated region overlay in playback - start color -->
+ <color name="inval_region_start">#80ff0000</color>
+ <!-- Invalidated region overlay in playback - stop color-->
+ <color name="inval_region_stop">#80ffffff</color>
+
+ <!-- Background color for not testing -->
+ <color name="background_not_testing">#ff000000</color>
+ <!-- Background color for during testing -->
+ <color name="background_start_testing">#ff400000</color>
+ <!-- Background color for testing complete -->
+ <color name="background_stop_testing">#ff004000</color>
</resources>
diff --git a/tests/TileBenchmark/res/values/strings.xml b/tests/TileBenchmark/res/values/strings.xml
index f70ee2c..66972ac 100644
--- a/tests/TileBenchmark/res/values/strings.xml
+++ b/tests/TileBenchmark/res/values/strings.xml
@@ -28,6 +28,10 @@
<string name="loadbutton">Load</string>
<!-- Button, opens the playback activity [CHAR LIMIT=20] -->
<string name="inspect_log">Inspect Log</string>
+ <!-- ToggleButton label when pressing starts capture [CHAR LIMIT=15] -->
+ <string name="capture_start">Start Capture</string>
+ <!-- ToggleButton label when pressing stops capture [CHAR LIMIT=15] -->
+ <string name="capture_stop">Stop Capture</string>
<!-- The speed of auto-scrolling [CHAR LIMIT=30] -->
<string name="desired_scroll_velocity">Choose Scroll Velocity</string>
<!-- Pixels moved per frame [CHAR LIMIT=10] -->
@@ -39,6 +43,21 @@
<item>200</item>
<item>400</item>
</string-array>
+ <!-- Drop down menu for selecting scrolling vs manual navigation for
+ capturing [CHAR LIMIT=15] -->
+ <string name="movement_method">Movement Method</string>
+ <!-- Drop down menu entry - automatically scroll to the end of the page
+ with scrollBy() [CHAR LIMIT=15] -->
+ <string name="movement_auto_scroll">Auto-scroll</string>
+ <!-- Drop down menu entry - [CHAR LIMIT=15] -->
+ <string name="movement_auto_fling">Auto-fling</string>
+ <!-- Drop down menu entry - manually navigate the page(s), hit 'capture'
+ button [CHAR LIMIT=15] -->
+ <string name="movement_manual">Manual</string>
+
+ <!-- Error popup indicating log data couldn't be loaded [CHAR LIMIT=60] -->
+ <string name="error_no_data">Error: log data could not be loaded.</string>
+
<!-- 25th percentile - 25% of frames fall below this value [CHAR LIMIT=12]
-->
<string name="percentile_25">25%ile</string>
@@ -56,7 +75,7 @@
<string name="format_stat">%4.4f</string>
<!-- Format string for displaying aggregate stats+values (nr of valid tiles,
etc.) [CHAR LIMIT=20] -->
- <string name="format_stat_name">%1$9s %2$3d</string>
+ <string name="format_stat_name">%1$-20s %2$3d</string>
<!-- Text hovering over canvas, number of tiles ready [CHAR LIMIT=15] -->
<string name="ready_tiles">Ready Tiles</string>
<!-- Text hovering over canvas, number tiles not ready [CHAR LIMIT=15] -->
@@ -64,4 +83,7 @@
<!-- Text hovering over canvas, number of tiles that haven't been
allocated to a place on the page [CHAR LIMIT=15] -->
<string name="unplaced_tiles">Unplaced Tiles</string>
+ <!-- Text hovering over canvas, number of invalidated regions this frame
+ [CHAR LIMIT=15] -->
+ <string name="number_invalidates">Invalidates</string>
</resources>
diff --git a/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackActivity.java b/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackActivity.java
index 5130f5d..36694a7 100644
--- a/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackActivity.java
+++ b/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackActivity.java
@@ -27,6 +27,7 @@
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
+import android.widget.Toast;
import java.io.FileInputStream;
import java.io.IOException;
@@ -102,7 +103,10 @@
@Override
protected void onPostExecute(TileData data[][]) {
if (data == null) {
- data = genTestPattern();
+ Toast.makeText(getApplicationContext(),
+ getResources().getString(R.string.error_no_data),
+ Toast.LENGTH_LONG).show();
+ return;
}
mPlaybackView.setData(data);
@@ -166,23 +170,4 @@
new LoadFileTask().execute(ProfileActivity.TEMP_FILENAME);
}
-
- private TileData[][] genTestPattern() {
- final int XMAX = 5;
- final int FRAMEMAX = 99;
-
- TileData example[][] = new TileData[FRAMEMAX][];
- for (int frame = 0; frame < FRAMEMAX; frame++) {
- int numTiles = frame + 10;
-
- example[frame] = new TileData[numTiles];
- for (int t = 0; t < numTiles; t++) {
- int x = t % XMAX;
- int y = t / XMAX;
- boolean isReady = y * 10 < frame;
- example[frame][t] = new TileData(x, y, isReady, 0);
- }
- }
- return example;
- }
}
diff --git a/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackGraphs.java b/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackGraphs.java
index db4a341..35b1563 100644
--- a/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackGraphs.java
+++ b/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackGraphs.java
@@ -28,19 +28,17 @@
import java.util.Arrays;
public class PlaybackGraphs {
- private static final int BAR_WIDTH = PlaybackView.TILEX * 3;
+ private static final int BAR_WIDTH = PlaybackView.TILE_SCALE * 3;
private static final float CANVAS_SCALE = 0.2f;
private static final double IDEAL_FRAMES = 60;
private static final int LABELOFFSET = 100;
private static Paint whiteLabels;
- private static double viewportCoverage(int l, int b, int r, int t,
- int tileIndexX,
- int tileIndexY) {
- if (tileIndexX * PlaybackView.TILEX < r
- && (tileIndexX + 1) * PlaybackView.TILEX >= l
- && tileIndexY * PlaybackView.TILEY < t
- && (tileIndexY + 1) * PlaybackView.TILEY >= b) {
+ private static double viewportCoverage(TileData view, TileData tile) {
+ if (tile.left < view.right
+ && tile.right >= view.left
+ && tile.top < view.bottom
+ && tile.bottom >= view.top) {
return 1.0f;
}
return 0.0f;
@@ -76,13 +74,10 @@
// coverage graph
@Override
public double getValue(TileData[] frame) {
- int l = frame[0].x, b = frame[0].y;
- int r = frame[1].x, t = frame[1].y;
double total = 0, totalCount = 0;
- for (int tileID = 2; tileID < frame.length; tileID++) {
+ for (int tileID = 1; tileID < frame.length; tileID++) {
TileData data = frame[tileID];
- double coverage = viewportCoverage(l, b, r, t, data.x,
- data.y);
+ double coverage = viewportCoverage(frame[0], data);
total += coverage * (data.isReady ? 1 : 0);
totalCount += coverage;
}
@@ -158,7 +153,7 @@
public PlaybackGraphs() {
whiteLabels = new Paint();
whiteLabels.setColor(Color.WHITE);
- whiteLabels.setTextSize(PlaybackView.TILEY / 3);
+ whiteLabels.setTextSize(PlaybackView.TILE_SCALE / 3);
}
private ArrayList<ShapeDrawable> mShapes = new ArrayList<ShapeDrawable>();
@@ -177,11 +172,13 @@
int lastBar = 0;
for (int frameIndex = 0; frameIndex < tileProfilingData.length; frameIndex++) {
TileData frame[] = tileProfilingData[frameIndex];
- int newBar = (frame[0].y + frame[1].y) / 2;
+ int newBar = (frame[0].top + frame[0].bottom) / 2;
MetricGen s = Metrics[metricIndex];
double absoluteValue = s.getValue(frame);
double relativeValue = absoluteValue / s.getMax();
+ relativeValue = Math.min(1,relativeValue);
+ relativeValue = Math.max(0,relativeValue);
int rightPos = (int) (-BAR_WIDTH * metricIndex);
int leftPos = (int) (-BAR_WIDTH * (metricIndex + relativeValue));
@@ -207,7 +204,7 @@
ArrayList<ShapeDrawable> shapes) {
// Shapes drawn here are drawn relative to the viewRect
Rect viewRect = shapes.get(shapes.size() - 1).getBounds();
- canvas.translate(0, 5 * PlaybackView.TILEY - viewRect.top);
+ canvas.translate(0, 5 * PlaybackView.TILE_SCALE - viewRect.top);
for (ShapeDrawable shape : mShapes) {
shape.draw(canvas);
@@ -234,13 +231,15 @@
int yPos = LABELOFFSET;
canvas.drawText(label, xPos, yPos, whiteLabels);
for (int statIndex = 0; statIndex < Stats.length; statIndex++) {
- label = resources.getString(R.string.format_stat, mStats[metricIndex][statIndex]);
- yPos = LABELOFFSET + (1 + statIndex) * PlaybackView.TILEY / 2;
+ label = resources.getString(R.string.format_stat,
+ mStats[metricIndex][statIndex]);
+ yPos = LABELOFFSET + (1 + statIndex) * PlaybackView.TILE_SCALE
+ / 2;
canvas.drawText(label, xPos, yPos, whiteLabels);
}
}
for (int stringIndex = 0; stringIndex < strings.length; stringIndex++) {
- int yPos = LABELOFFSET + stringIndex * PlaybackView.TILEY / 2;
+ int yPos = LABELOFFSET + stringIndex * PlaybackView.TILE_SCALE / 2;
canvas.drawText(strings[stringIndex], 0, yPos, whiteLabels);
}
}
diff --git a/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java b/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java
index f104eac..edc8643 100644
--- a/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java
+++ b/tests/TileBenchmark/src/com/test/tilebenchmark/PlaybackView.java
@@ -16,6 +16,9 @@
package com.test.tilebenchmark;
+import android.animation.ArgbEvaluator;
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -30,8 +33,9 @@
import java.util.ArrayList;
public class PlaybackView extends View {
- public static final int TILEX = 300;
- public static final int TILEY = 300;
+ public static final int TILE_SCALE = 300;
+ private static final int INVAL_FLAG = -2;
+ private static final int INVAL_CYCLE = 250;
private Paint levelPaint = null, coordPaint = null, goldPaint = null;
private PlaybackGraphs mGraphs;
@@ -39,28 +43,46 @@
private ArrayList<ShapeDrawable> mTempShapes = new ArrayList<ShapeDrawable>();
private TileData mProfData[][] = null;
private GestureDetector mGestureDetector = null;
- private String mRenderStrings[] = new String[3];
+ private String mRenderStrings[] = new String[4];
private class TileDrawable extends ShapeDrawable {
TileData tile;
+ String label;
- public TileDrawable(TileData t) {
- int tileColorId = t.isReady ? R.color.ready_tile
- : R.color.unready_tile;
- getPaint().setColor(getResources().getColor(tileColorId));
-
- setBounds(t.x * TILEX, t.y * TILEY, (t.x + 1) * TILEX, (t.y + 1)
- * TILEY);
+ public TileDrawable(TileData t, int colorId) {
this.tile = t;
+ getPaint().setColor(getResources().getColor(colorId));
+ if (colorId == R.color.ready_tile
+ || colorId == R.color.unready_tile) {
+
+ label = (int) (t.left / TILE_SCALE) + ", "
+ + (int) (t.top / TILE_SCALE);
+ // ignore scale value for tiles
+ setBounds(t.left, t.top,
+ t.right, t.bottom);
+ } else {
+ setBounds((int) (t.left * t.scale),
+ (int) (t.top * t.scale),
+ (int) (t.right * t.scale),
+ (int) (t.bottom * t.scale));
+ }
+ }
+
+ @SuppressWarnings("unused")
+ public void setColor(int color) {
+ getPaint().setColor(color);
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
- canvas.drawText(Integer.toString(tile.level), getBounds().left,
- getBounds().bottom, levelPaint);
- canvas.drawText(tile.x + "," + tile.y, getBounds().left,
- ((getBounds().bottom + getBounds().top) / 2), coordPaint);
+ if (label != null) {
+ canvas.drawText(Integer.toString(tile.level), getBounds().left,
+ getBounds().bottom, levelPaint);
+ canvas.drawText(label, getBounds().left,
+ ((getBounds().bottom + getBounds().top) / 2),
+ coordPaint);
+ }
}
}
@@ -92,10 +114,10 @@
private void init() {
levelPaint = new Paint();
levelPaint.setColor(Color.WHITE);
- levelPaint.setTextSize(TILEY / 2);
+ levelPaint.setTextSize(TILE_SCALE / 2);
coordPaint = new Paint();
coordPaint.setColor(Color.BLACK);
- coordPaint.setTextSize(TILEY / 3);
+ coordPaint.setTextSize(TILE_SCALE / 3);
goldPaint = new Paint();
goldPaint.setColor(0xffa0e010);
mGraphs = new PlaybackGraphs();
@@ -110,6 +132,7 @@
}
mGraphs.draw(canvas, mTempShapes, mRenderStrings, getResources());
+ invalidate(); // may have animations, force redraw
}
public int setFrame(int frame) {
@@ -117,35 +140,66 @@
return 0;
}
- int readyTiles = 0, unreadyTiles = 0, unplacedTiles = 0;
+ int readyTiles = 0, unreadyTiles = 0, unplacedTiles = 0, numInvals = 0;
mTempShapes.clear();
- // draw actual tiles
- for (int tileID = 2; tileID < mProfData[frame].length; tileID++) {
- TileData t = mProfData[frame][tileID];
- mTempShapes.add(new TileDrawable(t));
- if (t.isReady) {
- readyTiles++;
+ // create tile shapes (as they're drawn on bottom)
+ for (TileData t : mProfData[frame]) {
+ if (t.level != INVAL_FLAG && t != mProfData[frame][0]) {
+ int colorId;
+ if (t.isReady) {
+ readyTiles++;
+ colorId = R.color.ready_tile;
+ } else {
+ unreadyTiles++;
+ colorId = R.color.unready_tile;
+ }
+ if (t.left < 0 || t.top < 0) {
+ unplacedTiles++;
+ }
+ mTempShapes.add(new TileDrawable(t, colorId));
} else {
- unreadyTiles++;
- }
- if (t.x < 0 || t.y < 0) {
- unplacedTiles++;
+ numInvals++;
}
}
+
+ // create invalidate shapes (drawn above tiles)
+ int invalId = 0;
+ for (TileData t : mProfData[frame]) {
+ if (t.level == INVAL_FLAG && t != mProfData[frame][0]) {
+ TileDrawable invalShape = new TileDrawable(t,
+ R.color.inval_region_start);
+ ValueAnimator tileAnimator = ObjectAnimator.ofInt(invalShape,
+ "color",
+ getResources().getColor(R.color.inval_region_start),
+ getResources().getColor(R.color.inval_region_stop));
+ tileAnimator.setDuration(numInvals * INVAL_CYCLE);
+ tileAnimator.setEvaluator(new ArgbEvaluator());
+ tileAnimator.setRepeatCount(ValueAnimator.INFINITE);
+ tileAnimator.setRepeatMode(ValueAnimator.RESTART);
+ float delay = (float) (invalId) * INVAL_CYCLE;
+ tileAnimator.setStartDelay((int) delay);
+ invalId++;
+ tileAnimator.start();
+
+ mTempShapes.add(invalShape);
+ }
+ }
+
mRenderStrings[0] = getResources().getString(R.string.format_stat_name,
getResources().getString(R.string.ready_tiles), readyTiles);
mRenderStrings[1] = getResources().getString(R.string.format_stat_name,
getResources().getString(R.string.unready_tiles), unreadyTiles);
mRenderStrings[2] = getResources().getString(R.string.format_stat_name,
- getResources().getString(R.string.unplaced_tiles), unplacedTiles);
+ getResources().getString(R.string.unplaced_tiles),
+ unplacedTiles);
+ mRenderStrings[3] = getResources().getString(R.string.format_stat_name,
+ getResources().getString(R.string.number_invalidates),
+ numInvals);
- // draw view rect (using first two TileData objects)
- ShapeDrawable viewShape = new ShapeDrawable();
- viewShape.getPaint().setColor(0xff0000ff);
- viewShape.setAlpha(64);
- viewShape.setBounds(mProfData[frame][0].x, mProfData[frame][0].y,
- mProfData[frame][1].x, mProfData[frame][1].y);
+ // draw view rect (using first TileData object, on top)
+ TileDrawable viewShape = new TileDrawable(mProfData[frame][0],
+ R.color.view);
mTempShapes.add(viewShape);
this.invalidate();
return frame;
diff --git a/tests/TileBenchmark/src/com/test/tilebenchmark/ProfileActivity.java b/tests/TileBenchmark/src/com/test/tilebenchmark/ProfileActivity.java
index 23b6275..1521807 100644
--- a/tests/TileBenchmark/src/com/test/tilebenchmark/ProfileActivity.java
+++ b/tests/TileBenchmark/src/com/test/tilebenchmark/ProfileActivity.java
@@ -38,6 +38,7 @@
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
+import android.widget.ToggleButton;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -58,11 +59,24 @@
// before test
Button mInspectButton;
+ ToggleButton mCaptureButton;
Spinner mVelocitySpinner;
+ Spinner mMovementSpinner;
EditText mUrl;
ProfiledWebView mWeb;
ProfileCallback mCallback;
+ LoggingWebViewClient mLoggingWebViewClient = new LoggingWebViewClient();
+ AutoLoggingWebViewClient mAutoLoggingWebViewClient = new AutoLoggingWebViewClient();
+
+ private enum TestingState {
+ NOT_TESTING,
+ PRE_TESTING,
+ START_TESTING,
+ STOP_TESTING,
+ SAVED_TESTING
+ };
+
private class VelocitySelectedListener implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
@@ -77,6 +91,31 @@
}
}
+ private class MovementSelectedListener implements OnItemSelectedListener {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view,
+ int position, long id) {
+ String movementStr = parent.getItemAtPosition(position).toString();
+ if (movementStr == getResources().getString(
+ R.string.movement_auto_scroll)
+ || movementStr == getResources().getString(
+ R.string.movement_auto_fling)) {
+ mWeb.setWebViewClient(mAutoLoggingWebViewClient);
+ mCaptureButton.setEnabled(false);
+ mVelocitySpinner.setEnabled(true);
+ } else if (movementStr == getResources().getString(
+ R.string.movement_manual)) {
+ mWeb.setWebViewClient(mLoggingWebViewClient);
+ mCaptureButton.setEnabled(true);
+ mVelocitySpinner.setEnabled(false);
+ }
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ }
+ }
+
private class LoggingWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
@@ -88,6 +127,9 @@
super.onPageStarted(view, url, favicon);
mUrl.setText(url);
}
+ }
+
+ private class AutoLoggingWebViewClient extends LoggingWebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
@@ -100,10 +142,16 @@
@Override
public void onFinish() {
- mWeb.startScrollTest(mCallback);
+ startViewProfiling(true);
}
}.start();
}
+
+ @Override
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
+ super.onPageStarted(view, url, favicon);
+ setTestingState(TestingState.PRE_TESTING);
+ }
}
private class StoreFileTask extends
@@ -125,24 +173,65 @@
@Override
protected void onPostExecute(Void v) {
- mUrl.setBackgroundResource(R.color.finished_url);
+ setTestingState(TestingState.SAVED_TESTING);
}
}
+ public void setTestingState(TestingState state) {
+ switch (state) {
+ case NOT_TESTING:
+ mUrl.setBackgroundResource(R.color.background_not_testing);
+ mInspectButton.setEnabled(true);
+ mMovementSpinner.setEnabled(true);
+ break;
+ case PRE_TESTING:
+ mInspectButton.setEnabled(false);
+ mMovementSpinner.setEnabled(false);
+ break;
+ case START_TESTING:
+ mUrl.setBackgroundResource(R.color.background_start_testing);
+ mInspectButton.setEnabled(false);
+ mMovementSpinner.setEnabled(false);
+ break;
+ case STOP_TESTING:
+ mUrl.setBackgroundResource(R.color.background_stop_testing);
+ break;
+ case SAVED_TESTING:
+ mInspectButton.setEnabled(true);
+ mMovementSpinner.setEnabled(true);
+ break;
+ }
+ }
+
+ /** auto - automatically scroll. */
+ private void startViewProfiling(boolean auto) {
+ if (!auto) {
+ // manual, toggle capture button to indicate capture state to user
+ mCaptureButton.setChecked(true);
+ }
+ mWeb.startScrollTest(mCallback, auto);
+ setTestingState(TestingState.START_TESTING);
+ }
+
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mInspectButton = (Button) findViewById(R.id.inspect);
+ mCaptureButton = (ToggleButton) findViewById(R.id.capture);
mVelocitySpinner = (Spinner) findViewById(R.id.velocity);
+ mMovementSpinner = (Spinner) findViewById(R.id.movement);
mUrl = (EditText) findViewById(R.id.url);
mWeb = (ProfiledWebView) findViewById(R.id.web);
mCallback = new ProfileCallback() {
@SuppressWarnings("unchecked")
@Override
public void profileCallback(TileData[][] data) {
- new StoreFileTask().execute(new Pair<String, TileData[][]>(TEMP_FILENAME, data));
+ new StoreFileTask().execute(new Pair<String, TileData[][]>(
+ TEMP_FILENAME, data));
+ mCaptureButton.setChecked(false);
+ setTestingState(TestingState.STOP_TESTING);
}
};
@@ -166,6 +255,33 @@
new VelocitySelectedListener());
mVelocitySpinner.setSelection(3);
+ // Movement spinner
+ String content[] = {
+ getResources().getString(R.string.movement_auto_scroll),
+ getResources().getString(R.string.movement_auto_fling),
+ getResources().getString(R.string.movement_manual)
+ };
+ adapter = new ArrayAdapter<CharSequence>(this,
+ android.R.layout.simple_spinner_item, content);
+ adapter.setDropDownViewResource(
+ android.R.layout.simple_spinner_dropdown_item);
+ mMovementSpinner.setAdapter(adapter);
+ mMovementSpinner.setOnItemSelectedListener(
+ new MovementSelectedListener());
+ mMovementSpinner.setSelection(0);
+
+ // Capture toggle button
+ mCaptureButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mCaptureButton.isChecked()) {
+ startViewProfiling(false);
+ } else {
+ mWeb.stopScrollTest();
+ }
+ }
+ });
+
// Custom profiling WebView
WebSettings settings = mWeb.getSettings();
settings.setJavaScriptEnabled(true);
@@ -180,12 +296,13 @@
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
String url = mUrl.getText().toString();
- mUrl.setBackgroundResource(R.color.unfinished_url);
mWeb.loadUrl(url);
mWeb.requestFocus();
return true;
}
});
+
+ setTestingState(TestingState.NOT_TESTING);
}
public void setCallback(ProfileCallback callback) {
diff --git a/tests/TileBenchmark/src/com/test/tilebenchmark/ProfiledWebView.java b/tests/TileBenchmark/src/com/test/tilebenchmark/ProfiledWebView.java
index 6560624..d3941be 100644
--- a/tests/TileBenchmark/src/com/test/tilebenchmark/ProfiledWebView.java
+++ b/tests/TileBenchmark/src/com/test/tilebenchmark/ProfiledWebView.java
@@ -59,12 +59,13 @@
}
/*
- * Called once the page is loaded to start scrolling for evaluating tiles
+ * Called once the page is loaded to start scrolling for evaluating tiles.
+ * If autoScrolling isn't set, stop must be called manually.
*/
- public void startScrollTest(ProfileCallback callback) {
- isScrolling = true;
+ public void startScrollTest(ProfileCallback callback, boolean autoScrolling) {
+ isScrolling = autoScrolling;
mCallback = callback;
- super.tileProfilingStart();
+ tileProfilingStart();
invalidate();
}
@@ -72,19 +73,31 @@
* Called once the page has stopped scrolling
*/
public void stopScrollTest() {
- float testRatio = super.tileProfilingStop();
+ super.tileProfilingStop();
+
+ if (mCallback == null) {
+ tileProfilingClear();
+ return;
+ }
TileData data[][] = new TileData[super.tileProfilingNumFrames()][];
for (int frame = 0; frame < data.length; frame++) {
data[frame] = new TileData[
- super.tileProfilingNumTilesInFrame(frame)];
+ tileProfilingNumTilesInFrame(frame)];
for (int tile = 0; tile < data[frame].length; tile++) {
- int x = super.tileProfilingGetX(frame, tile);
- int y = super.tileProfilingGetY(frame, tile);
- boolean isReady = super.tileProfilingGetReady(frame, tile);
- int level = super.tileProfilingGetLevel(frame, tile);
+ int left = tileProfilingGetInt(frame, tile, "left");
+ int top = tileProfilingGetInt(frame, tile, "top");
+ int right = tileProfilingGetInt(frame, tile, "right");
+ int bottom = tileProfilingGetInt(frame, tile, "bottom");
- data[frame][tile] = new TileData(x, y, isReady, level);
+ boolean isReady = super.tileProfilingGetInt(
+ frame, tile, "isReady") == 1;
+ int level = tileProfilingGetInt(frame, tile, "level");
+
+ float scale = tileProfilingGetFloat(frame, tile, "scale");
+
+ data[frame][tile] = new TileData(left, top, right, bottom,
+ isReady, level, scale);
}
}
super.tileProfilingClear();
diff --git a/tests/TileBenchmark/src/com/test/tilebenchmark/TileData.java b/tests/TileBenchmark/src/com/test/tilebenchmark/TileData.java
index 7d4bb9f..3e729a6 100644
--- a/tests/TileBenchmark/src/com/test/tilebenchmark/TileData.java
+++ b/tests/TileBenchmark/src/com/test/tilebenchmark/TileData.java
@@ -19,14 +19,24 @@
import java.io.Serializable;
public class TileData implements Serializable {
- public int x, y;
+ int left, top, right, bottom;
public boolean isReady;
public int level;
+ public float scale;
- public TileData(int x, int y, boolean isReady, int level) {
- this.x = x;
- this.y = y;
+ public TileData(int left, int top, int right, int bottom, boolean isReady,
+ int level, float scale) {
+ this.left = left;
+ this.right = right;
+ this.top = top;
+ this.bottom = bottom;
this.isReady = isReady;
this.level = level;
+ this.scale = scale;
+ }
+
+ public String toString() {
+ return "Tile (" + left + "," + top + ")->("
+ + right + "," + bottom + ")";
}
}
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java
index 49ddf1d..0e24cc0 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/DelegateClassAdapter.java
@@ -117,8 +117,10 @@
int accessDelegate = access;
// change access to public for the original one
- access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);
- access |= Opcodes.ACC_PUBLIC;
+ if (Main.sOptions.generatePublicAccess) {
+ access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);
+ access |= Opcodes.ACC_PUBLIC;
+ }
MethodVisitor mwOriginal = super.visitMethod(access, name + ORIGINAL_SUFFIX,
desc, signature, exceptions);
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
index ce48069..9bf52c7 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/Main.java
@@ -37,7 +37,7 @@
* which does:
* <pre>
* $ make layoutlib_create <bunch of framework jars>
- * $ out/host/linux-x86/framework/bin/layoutlib_create \
+ * $ java -jar out/host/linux-x86/framework/layoutlib_create.jar \
* out/host/common/obj/JAVA_LIBRARIES/temp_layoutlib_intermediates/javalib.jar \
* out/target/common/obj/JAVA_LIBRARIES/core_intermediates/classes.jar \
* out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes.jar
@@ -45,6 +45,12 @@
*/
public class Main {
+ public static class Options {
+ public boolean generatePublicAccess = true;
+ }
+
+ public static final Options sOptions = new Options();
+
public static void main(String[] args) {
Log log = new Log();
@@ -53,7 +59,7 @@
String[] osDestJar = { null };
if (!processArgs(log, args, osJarPath, osDestJar)) {
- log.error("Usage: layoutlib_create [-v] output.jar input.jar ...");
+ log.error("Usage: layoutlib_create [-v] [-p] output.jar input.jar ...");
System.exit(1);
}
@@ -136,6 +142,8 @@
String s = args[i];
if (s.equals("-v")) {
log.setVerbose(true);
+ } else if (s.equals("-p")) {
+ sOptions.generatePublicAccess = false;
} else if (!s.startsWith("-")) {
if (osDestJar[0] == null) {
osDestJar[0] = s;
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java
index f2d9755..5a0a44a4 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/TransformClassAdapter.java
@@ -72,8 +72,10 @@
name = mClassName;
// remove protected or private and set as public
- access = access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED);
- access |= Opcodes.ACC_PUBLIC;
+ if (Main.sOptions.generatePublicAccess) {
+ access = access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED);
+ access |= Opcodes.ACC_PUBLIC;
+ }
// remove final
access = access & ~Opcodes.ACC_FINAL;
// note: leave abstract classes as such
@@ -87,8 +89,10 @@
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
// remove protected or private and set as public
- access = access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED);
- access |= Opcodes.ACC_PUBLIC;
+ if (Main.sOptions.generatePublicAccess) {
+ access = access & ~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED);
+ access |= Opcodes.ACC_PUBLIC;
+ }
// remove final
access = access & ~Opcodes.ACC_FINAL;
// note: leave abstract classes as such
@@ -117,8 +121,10 @@
String methodSignature = mClassName.replace('/', '.') + "#" + name;
// change access to public
- access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);
- access |= Opcodes.ACC_PUBLIC;
+ if (Main.sOptions.generatePublicAccess) {
+ access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);
+ access |= Opcodes.ACC_PUBLIC;
+ }
// remove final
access = access & ~Opcodes.ACC_FINAL;
@@ -155,9 +161,10 @@
public FieldVisitor visitField(int access, String name, String desc, String signature,
Object value) {
// change access to public
- access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);
- access |= Opcodes.ACC_PUBLIC;
-
+ if (Main.sOptions.generatePublicAccess) {
+ access &= ~(Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE);
+ access |= Opcodes.ACC_PUBLIC;
+ }
return super.visitField(access, name, desc, signature, value);
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
* </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 @@
* </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 @@
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 @@
*/
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 @@
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 @@
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 @@
* 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 @@
* 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 @@
* 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 @@
}
// 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 @@
return;
}
if (state.equals("HANGED")) {
- mWifiStateMachine.notifyDriverHung();
+ mStateMachine.sendMessage(DRIVER_HUNG_EVENT);
}
}
@@ -326,7 +438,7 @@
break;
case SCAN_RESULTS:
- mWifiStateMachine.notifyScanResultsAvailable();
+ mStateMachine.sendMessage(SCAN_RESULTS_EVENT);
break;
case UNKNOWN:
@@ -335,6 +447,59 @@
}
/**
+ * 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 @@
if (newSupplicantState == SupplicantState.INVALID) {
Log.w(TAG, "Invalid supplicant state: " + newState);
}
- mWifiStateMachine.notifySupplicantStateChange(networkId, BSSID, newSupplicantState);
+ notifySupplicantStateChange(networkId, BSSID, newSupplicantState);
}
}
@@ -403,7 +568,40 @@
}
}
}
- 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 6e13d0f..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 @@
* 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 {
@@ -104,18 +118,30 @@
public native static boolean stopDriverCommand();
- /**
- * Start filtering out multicast packets, to reduce battery consumption
- * that would result from processing them, only to discard them.
- * @return {@code true} if the operation succeeded, {@code false} otherwise
- */
- public native static boolean startPacketFiltering();
/**
- * Stop filtering out multicast packets.
+ * Start filtering out Multicast V4 packets
* @return {@code true} if the operation succeeded, {@code false} otherwise
*/
- public native static boolean stopPacketFiltering();
+ public native static boolean startFilteringMulticastV4Packets();
+
+ /**
+ * Stop filtering out Multicast V4 packets.
+ * @return {@code true} if the operation succeeded, {@code false} otherwise
+ */
+ public native static boolean stopFilteringMulticastV4Packets();
+
+ /**
+ * Start filtering out Multicast V6 packets
+ * @return {@code true} if the operation succeeded, {@code false} otherwise
+ */
+ public native static boolean startFilteringMulticastV6Packets();
+
+ /**
+ * Stop filtering out Multicast V6 packets.
+ * @return {@code true} if the operation succeeded, {@code false} otherwise
+ */
+ public native static boolean stopFilteringMulticastV6Packets();
public native static boolean setPowerModeCommand(int mode);
@@ -174,4 +200,141 @@
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 12efeb1..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.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.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;
@@ -82,12 +85,21 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicBoolean;
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 {
@@ -96,7 +108,7 @@
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;
@@ -160,9 +172,16 @@
/* Tracks current frequency mode */
private AtomicInteger mFrequencyBand = new AtomicInteger(WifiManager.WIFI_FREQUENCY_BAND_AUTO);
+ /* Tracks if we are filtering Multicast v4 packets. Default is to filter. */
+ private AtomicBoolean mFilteringMulticastV4Packets = new AtomicBoolean(true);
+
// 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;
@@ -204,27 +223,10 @@
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 ? */
@@ -285,6 +287,11 @@
static final int CMD_START_PACKET_FILTERING = BASE + 84;
/* Clear packet filter */
static final int CMD_STOP_PACKET_FILTERING = BASE + 85;
+
+ /* arg1 values to CMD_STOP_PACKET_FILTERING and CMD_START_PACKET_FILTERING */
+ static final int MULTICAST_V6 = 1;
+ static final int MULTICAST_V4 = 0;
+
/* Connect to a specified network (network id
* or WifiConfiguration) This involves increasing
* the priority of the network, enabling the network
@@ -321,6 +328,10 @@
/* 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;
@@ -412,8 +423,13 @@
/* 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();
/**
@@ -504,13 +520,9 @@
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));
@@ -550,6 +562,8 @@
addState(mDriverStoppedState, mSupplicantStartedState);
addState(mSupplicantStoppingState, mDefaultState);
addState(mSoftApStartedState, mDefaultState);
+ addState(mTetheredState, mSoftApStartedState);
+ addState(mWaitForP2pDisableState, mDefaultState);
setInitialState(mInitialState);
@@ -868,17 +882,33 @@
}
/**
- * Start packet filtering
+ * Start filtering Multicast v4 packets
*/
- public void startPacketFiltering() {
- sendMessage(CMD_START_PACKET_FILTERING);
+ public void startFilteringMulticastV4Packets() {
+ mFilteringMulticastV4Packets.set(true);
+ sendMessage(obtainMessage(CMD_START_PACKET_FILTERING, MULTICAST_V4, 0));
}
/**
- * Stop packet filtering
+ * Stop filtering Multicast v4 packets
*/
- public void stopPacketFiltering() {
- sendMessage(CMD_STOP_PACKET_FILTERING);
+ public void stopFilteringMulticastV4Packets() {
+ mFilteringMulticastV4Packets.set(false);
+ sendMessage(obtainMessage(CMD_STOP_PACKET_FILTERING, MULTICAST_V4, 0));
+ }
+
+ /**
+ * Start filtering Multicast v4 packets
+ */
+ public void startFilteringMulticastV6Packets() {
+ sendMessage(obtainMessage(CMD_START_PACKET_FILTERING, MULTICAST_V6, 0));
+ }
+
+ /**
+ * Stop filtering Multicast v4 packets
+ */
+ public void stopFilteringMulticastV6Packets() {
+ sendMessage(obtainMessage(CMD_STOP_PACKET_FILTERING, MULTICAST_V6, 0));
}
/**
@@ -1023,14 +1053,17 @@
* 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();
@@ -1052,18 +1085,43 @@
} 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!");
+ }
}
/**
@@ -1591,12 +1649,15 @@
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);
@@ -1606,105 +1667,6 @@
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
*******************************************************/
@@ -1714,6 +1676,18 @@
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);
@@ -1749,18 +1723,19 @@
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:
@@ -1777,11 +1752,20 @@
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;
@@ -1808,6 +1792,11 @@
else {
transitionTo(mDriverUnloadedState);
}
+
+ //Connect to WifiP2pService
+ mWifiP2pManager = (WifiP2pManager) mContext.getSystemService(Context.WIFI_P2P_SERVICE);
+ mWifiP2pChannel.connect(mContext, getHandler(), mWifiP2pManager.getMessenger());
+
}
}
@@ -2023,7 +2012,11 @@
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;
@@ -2057,7 +2050,7 @@
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;
@@ -2074,13 +2067,10 @@
WifiConfigStore.initialize(mContext);
- //TODO: initialize and fix multicast filtering
- //mWM.initializeMulticastFiltering();
-
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();
@@ -2143,7 +2133,7 @@
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();
@@ -2155,7 +2145,7 @@
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();
@@ -2257,10 +2247,10 @@
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);
@@ -2300,7 +2290,7 @@
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
@@ -2313,10 +2303,10 @@
/* 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:
@@ -2359,6 +2349,16 @@
/* initialize network state */
setNetworkDetailedState(DetailedState.DISCONNECTED);
+ /* Remove any filtering on Multicast v6 at start */
+ WifiNative.stopFilteringMulticastV6Packets();
+
+ /* Reset Multicast v4 filtering state */
+ if (mFilteringMulticastV4Packets.get()) {
+ WifiNative.startFilteringMulticastV4Packets();
+ } else {
+ WifiNative.stopFilteringMulticastV4Packets();
+ }
+
if (mIsScanMode) {
WifiNative.setScanResultHandlingCommand(SCAN_ONLY_MODE);
WifiNative.disconnectCommand();
@@ -2419,10 +2419,22 @@
mWakeLock.release();
break;
case CMD_START_PACKET_FILTERING:
- WifiNative.startPacketFiltering();
+ if (message.arg1 == MULTICAST_V6) {
+ WifiNative.startFilteringMulticastV6Packets();
+ } else if (message.arg1 == MULTICAST_V4) {
+ WifiNative.startFilteringMulticastV4Packets();
+ } else {
+ Log.e(TAG, "Illegal arugments to CMD_START_PACKET_FILTERING");
+ }
break;
case CMD_STOP_PACKET_FILTERING:
- WifiNative.stopPacketFiltering();
+ if (message.arg1 == MULTICAST_V6) {
+ WifiNative.stopFilteringMulticastV6Packets();
+ } else if (message.arg1 == MULTICAST_V4) {
+ WifiNative.stopFilteringMulticastV4Packets();
+ } else {
+ Log.e(TAG, "Illegal arugments to CMD_STOP_PACKET_FILTERING");
+ }
break;
default:
return NOT_HANDLED;
@@ -2451,7 +2463,7 @@
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);
@@ -2495,7 +2507,7 @@
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
@@ -2541,9 +2553,9 @@
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;
@@ -2564,14 +2576,14 @@
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 */
@@ -2613,12 +2625,12 @@
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;
@@ -2632,7 +2644,7 @@
sendNetworkStateChangeBroadcast(mLastBssid);
transitionTo(mConnectingState);
break;
- case NETWORK_DISCONNECTION_EVENT:
+ case WifiMonitor.NETWORK_DISCONNECTION_EVENT:
Log.d(TAG,"Network connection lost");
handleNetworkDisconnect();
transitionTo(mDisconnectedState);
@@ -2719,7 +2731,7 @@
deferMessage(message);
break;
/* Ignore */
- case NETWORK_CONNECTION_EVENT:
+ case WifiMonitor.NETWORK_CONNECTION_EVENT:
break;
case CMD_STOP_DRIVER:
sendMessage(CMD_DISCONNECT);
@@ -2784,10 +2796,7 @@
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:
@@ -2829,7 +2838,7 @@
}
break;
/* Ignore */
- case NETWORK_CONNECTION_EVENT:
+ case WifiMonitor.NETWORK_CONNECTION_EVENT:
break;
case CMD_RSSI_POLL:
eventLoggingEnabled = false;
@@ -2890,7 +2899,7 @@
}
break;
/* Handle in DisconnectedState */
- case SUPPLICANT_STATE_CHANGE_EVENT:
+ case WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT:
deferMessage(message);
break;
default:
@@ -2975,9 +2984,9 @@
}
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 */
@@ -2989,7 +2998,7 @@
}
/* 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);
@@ -3032,10 +3041,10 @@
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;
@@ -3065,16 +3074,9 @@
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()");
}
@@ -3096,6 +3098,17 @@
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;
}
@@ -3103,4 +3116,68 @@
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 0eb73b7..fa7cf21 100644
--- a/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiWatchdogStateMachine.java
@@ -16,11 +16,15 @@
package android.net.wifi;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.res.Resources;
import android.database.ContentObserver;
import android.net.ConnectivityManager;
import android.net.DnsPinger;
@@ -29,7 +33,7 @@
import android.os.Message;
import android.os.SystemClock;
import android.provider.Settings;
-import android.text.TextUtils;
+import android.provider.Settings.Secure;
import android.util.Slog;
import com.android.internal.util.Protocol;
@@ -45,6 +49,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
+import java.util.regex.Pattern;
/**
* {@link WifiWatchdogStateMachine} monitors the initial connection to a Wi-Fi
@@ -62,6 +67,7 @@
*/
public class WifiWatchdogStateMachine extends StateMachine {
+
private static final boolean VDBG = false;
private static final boolean DBG = true;
private static final String WWSM_TAG = "WifiWatchdogStateMachine";
@@ -72,18 +78,22 @@
*/
private static final int LOW_SIGNAL_CUTOFF = 1;
- private static final long MIN_LOW_SIGNAL_CHECK_INTERVAL_MS = 2 * 60 * 1000;
- private static final long MIN_SINGLE_DNS_CHECK_INTERVAL_MS = 10 * 60 * 1000;
- private static final long MIN_WALLED_GARDEN_INTERVAL_MS = 30 * 60 * 1000;
+ private static final long DEFAULT_DNS_CHECK_SHORT_INTERVAL_MS = 2 * 60 * 1000;
+ private static final long DEFAULT_DNS_CHECK_LONG_INTERVAL_MS = 10 * 60 * 1000;
+ private static final long DEFAULT_WALLED_GARDEN_INTERVAL_MS = 30 * 60 * 1000;
- private static final int MAX_CHECKS_PER_SSID = 7;
- private static final int NUM_DNS_PINGS = 5;
- private static final double MIN_DNS_RESPONSE_RATE = 0.50;
-
- private static final int DNS_PING_TIMEOUT_MS = 800;
+ private static final int DEFAULT_MAX_SSID_BLACKLISTS = 7;
+ private static final int DEFAULT_NUM_DNS_PINGS = 5;
+ private static final int DEFAULT_MIN_DNS_RESPONSES = 3;
private static final long DNS_PING_INTERVAL_MS = 100;
- private static final long BLACKLIST_FOLLOWUP_INTERVAL_MS = 15 * 1000;
+ private static final int DEFAULT_DNS_PING_TIMEOUT_MS = 1500;
+
+ private static final long DEFAULT_BLACKLIST_FOLLOWUP_INTERVAL_MS = 15 * 1000;
+
+ private static final String DEFAULT_WALLED_GARDEN_URL = "http://www.google.com/";
+ private static final String DEFAULT_WALLED_GARDEN_PATTERN = "<title>.*Google.*</title>";
+
private static final int BASE = Protocol.BASE_WIFI_WATCHDOG;
@@ -104,6 +114,7 @@
private static final int EVENT_RSSI_CHANGE = BASE + 3;
private static final int EVENT_SCAN_RESULTS_AVAILABLE = BASE + 4;
private static final int EVENT_WIFI_RADIO_STATE_CHANGE = BASE + 5;
+ private static final int EVENT_WATCHDOG_SETTINGS_CHANGE = BASE + 6;
private static final int MESSAGE_CHECK_STEP = BASE + 100;
private static final int MESSAGE_HANDLE_WALLED_GARDEN = BASE + 101;
@@ -132,6 +143,19 @@
private WalledGardenState mWalledGardenState = new WalledGardenState();
private BlacklistedApState mBlacklistedApState = new BlacklistedApState();
+ private long mDnsCheckShortIntervalMs;
+ private long mDnsCheckLongIntervalMs;
+ private long mWalledGardenIntervalMs;
+ private int mMaxSsidBlacklists;
+ private int mNumDnsPings;
+ private int mMinDnsResponses;
+ private int mDnsPingTimeoutMs;
+ private long mBlacklistFollowupIntervalMs;
+ private boolean mWalledGardenTestEnabled;
+ private String mWalledGardenUrl;
+ private Pattern mWalledGardenPattern;
+
+ private boolean mShowDisabledNotification;
/**
* The {@link WifiInfo} object passed to WWSM on network broadcasts
*/
@@ -142,7 +166,7 @@
* Currently maintained but not used, TODO
*/
private HashSet<String> mBssids = new HashSet<String>();
- private int mNumFullDNSchecks = 0;
+ private int mNumCheckFailures = 0;
private Long mLastWalledGardenCheckTime = null;
@@ -158,7 +182,7 @@
* / \
* Disabled Enabled
* / \
- * Disconnected Connected
+ * NotConnected Connected
* /---------\
* (all other states)
*/
@@ -174,6 +198,7 @@
// The content observer to listen needs a handler
registerForSettingsChanges();
+ registerForWatchdogToggle();
addState(mDefaultState);
addState(mWatchdogDisabledState, mDefaultState);
addState(mWatchdogEnabledState, mDefaultState);
@@ -186,6 +211,9 @@
addState(mOnlineWatchState, mConnectedState);
setInitialState(mWatchdogDisabledState);
+ updateSettings();
+ mShowDisabledNotification = getSettingsBoolean(mContentResolver,
+ Settings.Secure.WIFI_WATCHDOG_SHOW_DISABLED_NETWORK_POPUP, true);
}
public static WifiWatchdogStateMachine makeWifiWatchdogStateMachine(Context context) {
@@ -228,7 +256,7 @@
/**
* Observes the watchdog on/off setting, and takes action when changed.
*/
- private void registerForSettingsChanges() {
+ private void registerForWatchdogToggle() {
ContentObserver contentObserver = new ContentObserver(this.getHandler()) {
@Override
public void onChange(boolean selfChange) {
@@ -242,6 +270,54 @@
}
/**
+ * Observes watchdogs secure setting changes.
+ */
+ private void registerForSettingsChanges() {
+ ContentObserver contentObserver = new ContentObserver(this.getHandler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ sendMessage(EVENT_WATCHDOG_SETTINGS_CHANGE);
+ }
+ };
+
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(
+ Settings.Secure.WIFI_WATCHDOG_DNS_CHECK_SHORT_INTERVAL_MS),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_DNS_CHECK_LONG_INTERVAL_MS),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_INTERVAL_MS),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_MAX_SSID_BLACKLISTS),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_NUM_DNS_PINGS),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_MIN_DNS_RESPONSES),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_DNS_PING_TIMEOUT_MS),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(
+ Settings.Secure.WIFI_WATCHDOG_BLACKLIST_FOLLOWUP_INTERVAL_MS),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_TEST_ENABLED),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_URL),
+ false, contentObserver);
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_PATTERN),
+ false, contentObserver);
+ }
+
+ /**
* DNS based detection techniques do not work at all hotspots. The one sure
* way to check a walled garden is to see if a URL fetch on a known address
* fetches the data we expect
@@ -250,11 +326,11 @@
InputStream in = null;
HttpURLConnection urlConnection = null;
try {
- URL url = new URL(getWalledGardenUrl());
+ URL url = new URL(mWalledGardenUrl);
urlConnection = (HttpURLConnection) url.openConnection();
in = new BufferedInputStream(urlConnection.getInputStream());
Scanner scanner = new Scanner(in);
- if (scanner.findInLine(getWalledGardenPattern()) != null) {
+ if (scanner.findInLine(mWalledGardenPattern) != null) {
return false;
} else {
return true;
@@ -281,49 +357,49 @@
pw.print("WatchdogStatus: ");
pw.print("State " + getCurrentState());
pw.println(", network [" + mInitialConnInfo + "]");
- pw.print("checkCount " + mNumFullDNSchecks);
+ pw.print("checkFailures " + mNumCheckFailures);
pw.println(", bssids: " + mBssids);
pw.println("lastSingleCheck: " + mOnlineWatchState.lastCheckTime);
}
- /**
- * @see android.provider.Settings.Secure#WIFI_WATCHDOG_WALLED_GARDEN_TEST_ENABLED
- */
- private Boolean isWalledGardenTestEnabled() {
- return Settings.Secure.getInt(mContentResolver,
- Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_TEST_ENABLED, 1) == 1;
- }
-
- /**
- * @see android.provider.Settings.Secure#WIFI_WATCHDOG_WALLED_GARDEN_URL
- */
- private String getWalledGardenUrl() {
- String url = Settings.Secure.getString(mContentResolver,
- Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_URL);
- if (TextUtils.isEmpty(url))
- return "http://www.google.com/";
- return url;
- }
-
- /**
- * @see android.provider.Settings.Secure#WIFI_WATCHDOG_WALLED_GARDEN_PATTERN
- */
- private String getWalledGardenPattern() {
- String pattern = Settings.Secure.getString(mContentResolver,
- Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_PATTERN);
- if (TextUtils.isEmpty(pattern))
- return "<title>.*Google.*</title>";
- return pattern;
- }
-
- /**
- * @see android.provider.Settings.Secure#WIFI_WATCHDOG_ON
- */
private boolean isWatchdogEnabled() {
- return Settings.Secure.getInt(mContentResolver,
- Settings.Secure.WIFI_WATCHDOG_ON, 1) == 1;
+ return getSettingsBoolean(mContentResolver, Settings.Secure.WIFI_WATCHDOG_ON, true);
}
+ private void updateSettings() {
+ mDnsCheckShortIntervalMs = Secure.getLong(mContentResolver,
+ Secure.WIFI_WATCHDOG_DNS_CHECK_SHORT_INTERVAL_MS,
+ DEFAULT_DNS_CHECK_SHORT_INTERVAL_MS);
+ mDnsCheckLongIntervalMs = Secure.getLong(mContentResolver,
+ Secure.WIFI_WATCHDOG_DNS_CHECK_LONG_INTERVAL_MS,
+ DEFAULT_DNS_CHECK_LONG_INTERVAL_MS);
+ mMaxSsidBlacklists = Secure.getInt(mContentResolver,
+ Secure.WIFI_WATCHDOG_MAX_SSID_BLACKLISTS,
+ DEFAULT_MAX_SSID_BLACKLISTS);
+ mNumDnsPings = Secure.getInt(mContentResolver,
+ Secure.WIFI_WATCHDOG_NUM_DNS_PINGS,
+ DEFAULT_NUM_DNS_PINGS);
+ mMinDnsResponses = Secure.getInt(mContentResolver,
+ Secure.WIFI_WATCHDOG_MIN_DNS_RESPONSES,
+ DEFAULT_MIN_DNS_RESPONSES);
+ mDnsPingTimeoutMs = Secure.getInt(mContentResolver,
+ Secure.WIFI_WATCHDOG_DNS_PING_TIMEOUT_MS,
+ DEFAULT_DNS_PING_TIMEOUT_MS);
+ mBlacklistFollowupIntervalMs = Secure.getLong(mContentResolver,
+ Settings.Secure.WIFI_WATCHDOG_BLACKLIST_FOLLOWUP_INTERVAL_MS,
+ DEFAULT_BLACKLIST_FOLLOWUP_INTERVAL_MS);
+ mWalledGardenTestEnabled = getSettingsBoolean(mContentResolver,
+ Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_TEST_ENABLED, true);
+ mWalledGardenUrl = getSettingsStr(mContentResolver,
+ Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_URL,
+ DEFAULT_WALLED_GARDEN_URL);
+ mWalledGardenPattern = Pattern.compile(getSettingsStr(mContentResolver,
+ Settings.Secure.WIFI_WATCHDOG_WALLED_GARDEN_PATTERN,
+ DEFAULT_WALLED_GARDEN_PATTERN));
+ mWalledGardenIntervalMs = Secure.getLong(mContentResolver,
+ Secure.WIFI_WATCHDOG_WALLED_GARDEN_INTERVAL_MS,
+ DEFAULT_WALLED_GARDEN_INTERVAL_MS);
+ }
/**
* Helper to return wait time left given a min interval and last run
@@ -353,7 +429,7 @@
mInitialConnInfo = null;
mDisableAPNextFailure = false;
mLastWalledGardenCheckTime = null;
- mNumFullDNSchecks = 0;
+ mNumCheckFailures = 0;
mBssids.clear();
}
@@ -365,13 +441,43 @@
mContext.startActivity(intent);
}
- private void sendCheckStepMessage(long delay) {
- sendMessageDelayed(obtainMessage(MESSAGE_CHECK_STEP, mNetEventCounter, 0), delay);
+ private void displayDisabledNetworkNotification() {
+ Resources r = Resources.getSystem();
+ CharSequence title =
+ r.getText(com.android.internal.R.string.wifi_watchdog_network_disabled);
+ CharSequence msg =
+ r.getText(com.android.internal.R.string.wifi_watchdog_network_disabled_detailed);
+
+ Notification wifiDisabledWarning = new Notification.Builder(mContext)
+ .setSmallIcon(com.android.internal.R.drawable.stat_sys_warning)
+ .setDefaults(Notification.DEFAULT_ALL)
+ .setTicker(title)
+ .setContentTitle(title)
+ .setContentText(msg)
+ .setContentIntent(PendingIntent.getActivity(mContext, 0,
+ new Intent(Settings.ACTION_WIFI_IP_SETTINGS)
+ .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), 0))
+ .setWhen(System.currentTimeMillis())
+ .setAutoCancel(true)
+ .getNotification();
+
+ NotificationManager notificationManager = (NotificationManager) mContext
+ .getSystemService(Context.NOTIFICATION_SERVICE);
+
+ notificationManager.notify("WifiWatchdog", wifiDisabledWarning.icon, wifiDisabledWarning);
}
class DefaultState extends State {
@Override
public boolean processMessage(Message msg) {
+ switch (msg.what) {
+ case EVENT_WATCHDOG_SETTINGS_CHANGE:
+ updateSettings();
+ if (VDBG) {
+ Slog.d(WWSM_TAG, "Updating wifi-watchdog secure settings");
+ }
+ return HANDLED;
+ }
if (VDBG) {
Slog.v(WWSM_TAG, "Caught message " + msg.what + " in state " +
getCurrentState().getName());
@@ -509,6 +615,10 @@
mBssids.add(result.BSSID);
}
return HANDLED;
+ case EVENT_WATCHDOG_SETTINGS_CHANGE:
+ // Stop current checks, but let state update
+ transitionTo(mOnlineWatchState);
+ return NOT_HANDLED;
}
return NOT_HANDLED;
}
@@ -522,13 +632,12 @@
@Override
public void enter() {
- mNumFullDNSchecks++;
dnsCheckSuccesses = 0;
dnsCheckTries = 0;
if (DBG) {
Slog.d(WWSM_TAG, "Starting DNS pings at " + SystemClock.elapsedRealtime());
- dnsCheckLogStr = String.format("Dns Check %d. Pinging %s on ssid [%s]: ",
- mNumFullDNSchecks, mDnsPinger.getDns(), mInitialConnInfo.getSSID());
+ dnsCheckLogStr = String.format("Pinging %s on ssid [%s]: ",
+ mDnsPinger.getDns(), mInitialConnInfo.getSSID());
}
sendCheckStepMessage(0);
@@ -545,7 +654,7 @@
}
long pingResponseTime = mDnsPinger.pingDns(mDnsPinger.getDns(),
- DNS_PING_TIMEOUT_MS);
+ mDnsPingTimeoutMs);
dnsCheckTries++;
if (pingResponseTime >= 0)
@@ -567,14 +676,12 @@
* After a full ping count, if we have more responses than this
* cutoff, the outcome is success; else it is 'failure'.
*/
- double pingResponseCutoff = MIN_DNS_RESPONSE_RATE * NUM_DNS_PINGS;
- int remainingChecks = NUM_DNS_PINGS - dnsCheckTries;
/**
* Our final success count will be at least this big, so we're
* guaranteed to succeed.
*/
- if (dnsCheckSuccesses >= pingResponseCutoff) {
+ if (dnsCheckSuccesses >= mMinDnsResponses) {
// DNS CHECKS OK, NOW WALLED GARDEN
if (DBG) {
Slog.d(WWSM_TAG, dnsCheckLogStr + "| SUCCESS");
@@ -603,7 +710,8 @@
* Our final count will be at most the current count plus the
* remaining pings - we're guaranteed to fail.
*/
- if (remainingChecks + dnsCheckSuccesses < pingResponseCutoff) {
+ int remainingChecks = mNumDnsPings - dnsCheckTries;
+ if (remainingChecks + dnsCheckSuccesses < mMinDnsResponses) {
if (DBG) {
Slog.d(WWSM_TAG, dnsCheckLogStr + "| FAILURE");
}
@@ -617,12 +725,12 @@
}
private boolean shouldCheckWalledGarden() {
- if (!isWalledGardenTestEnabled()) {
+ if (!mWalledGardenTestEnabled) {
if (VDBG)
Slog.v(WWSM_TAG, "Skipping walled garden check - disabled");
return false;
}
- long waitTime = waitTime(MIN_WALLED_GARDEN_INTERVAL_MS,
+ long waitTime = waitTime(mWalledGardenIntervalMs,
mLastWalledGardenCheckTime);
if (waitTime > 0) {
if (DBG) {
@@ -634,6 +742,10 @@
return true;
}
+ private void sendCheckStepMessage(long delay) {
+ sendMessageDelayed(obtainMessage(MESSAGE_CHECK_STEP, mNetEventCounter, 0), delay);
+ }
+
}
class OnlineWatchState extends State {
@@ -698,7 +810,7 @@
}
lastCheckTime = SystemClock.elapsedRealtime();
long responseTime = mDnsPinger.pingDns(mDnsPinger.getDns(),
- DNS_PING_TIMEOUT_MS);
+ mDnsPingTimeoutMs);
if (responseTime >= 0) {
if (VDBG) {
Slog.v(WWSM_TAG, "Ran a single DNS ping. Response time: "
@@ -720,15 +832,15 @@
}
/**
- * Times a dns check with an interval based on {@link #curSignalStable}
+ * Times a dns check with an interval based on {@link #signalUnstable}
*/
private void triggerSingleDnsCheck() {
long waitInterval;
if (signalUnstable) {
- waitInterval = MIN_LOW_SIGNAL_CHECK_INTERVAL_MS;
+ waitInterval = mDnsCheckShortIntervalMs;
unstableSignalChecks = true;
} else {
- waitInterval = MIN_SINGLE_DNS_CHECK_INTERVAL_MS;
+ waitInterval = mDnsCheckLongIntervalMs;
}
sendMessageDelayed(obtainMessage(MESSAGE_SINGLE_DNS_CHECK, checkGuard, 0),
waitTime(waitInterval, lastCheckTime));
@@ -738,6 +850,7 @@
class DnsCheckFailureState extends State {
@Override
public void enter() {
+ mNumCheckFailures++;
obtainMessage(MESSAGE_HANDLE_BAD_AP, mNetEventCounter, 0).sendToTarget();
}
@@ -754,16 +867,22 @@
return HANDLED;
}
- if (mDisableAPNextFailure || mNumFullDNSchecks >= MAX_CHECKS_PER_SSID) {
+ if (mDisableAPNextFailure || mNumCheckFailures >= mMaxSsidBlacklists) {
// TODO : Unban networks if they had low signal ?
Slog.i(WWSM_TAG, "Disabling current SSID " + wifiInfoToStr(mInitialConnInfo)
- + ". " +
- "numChecks " + mNumFullDNSchecks + ", numAPs " + mBssids.size());
+ + ". " + "numCheckFailures " + mNumCheckFailures
+ + ", numAPs " + mBssids.size());
mWifiManager.disableNetwork(mInitialConnInfo.getNetworkId());
+ if (mShowDisabledNotification) {
+ displayDisabledNetworkNotification();
+ mShowDisabledNotification = false;
+ putSettingsBoolean(mContentResolver,
+ Settings.Secure.WIFI_WATCHDOG_SHOW_DISABLED_NETWORK_POPUP, false);
+ }
transitionTo(mNotConnectedState);
} else {
- Slog.i(WWSM_TAG, "Blacklisting current BSSID. " + wifiInfoToStr(mInitialConnInfo) +
- "numChecks " + mNumFullDNSchecks + ", numAPs " + mBssids.size());
+ Slog.i(WWSM_TAG, "Blacklisting current BSSID. " + wifiInfoToStr(mInitialConnInfo)
+ + "numCheckFailures " + mNumCheckFailures + ", numAPs " + mBssids.size());
mWifiManager.addToBlacklist(mInitialConnInfo.getBSSID());
mWifiManager.reassociate();
@@ -802,7 +921,7 @@
public void enter() {
mDisableAPNextFailure = true;
sendMessageDelayed(obtainMessage(MESSAGE_NETWORK_FOLLOWUP, mNetEventCounter, 0),
- BLACKLIST_FOLLOWUP_INTERVAL_MS);
+ mBlacklistFollowupIntervalMs);
}
@Override
@@ -822,4 +941,57 @@
return HANDLED;
}
}
+
+
+ /**
+ * Convenience function for retrieving a single secure settings value
+ * as a string with a default value.
+ *
+ * @param cr The ContentResolver to access.
+ * @param name The name of the setting to retrieve.
+ * @param def Value to return if the setting is not defined.
+ *
+ * @return The setting's current value, or 'def' if it is not defined
+ */
+ private static String getSettingsStr(ContentResolver cr, String name, String def) {
+ String v = Settings.Secure.getString(cr, name);
+ return v != null ? v : def;
+ }
+
+ /**
+ * Convenience function for retrieving a single secure settings value
+ * as a boolean. Note that internally setting values are always
+ * stored as strings; this function converts the string to a boolean
+ * for you. The default value will be returned if the setting is
+ * not defined or not a valid boolean.
+ *
+ * @param cr The ContentResolver to access.
+ * @param name The name of the setting to retrieve.
+ * @param def Value to return if the setting is not defined.
+ *
+ * @return The setting's current value, or 'def' if it is not defined
+ * or not a valid boolean.
+ */
+ private static boolean getSettingsBoolean(ContentResolver cr, String name, boolean def) {
+ return Settings.Secure.getInt(cr, name, def ? 1 : 0) == 1;
+ }
+
+ /**
+ * Convenience function for updating a single settings value as an
+ * integer. This will either create a new entry in the table if the
+ * given name does not exist, or modify the value of the existing row
+ * with that name. Note that internally setting values are always
+ * stored as strings, so this function converts the given value to a
+ * string before storing it.
+ *
+ * @param cr The ContentResolver to access.
+ * @param name The name of the setting to modify.
+ * @param value The new value for the setting.
+ * @return true if the value was set, false on database errors
+ */
+ private static boolean putSettingsBoolean(ContentResolver cr, String name, boolean value) {
+ return Settings.Secure.putInt(cr, name, value ? 1 : 0);
+ }
+
+
}
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 @@
*/
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 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 @@
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 @@
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 @@
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];
+ }
+ };
+}