summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/res/res/values/config.xml7
-rw-r--r--core/res/res/values/symbols.xml1
-rw-r--r--libs/hwui/DeferredDisplayList.cpp131
-rw-r--r--libs/hwui/DeferredDisplayList.h48
-rw-r--r--libs/hwui/DisplayList.h4
-rw-r--r--libs/hwui/DisplayListOp.h129
-rw-r--r--libs/hwui/DisplayListRenderer.cpp9
-rw-r--r--libs/hwui/OpenGLRenderer.h17
-rw-r--r--services/java/com/android/server/power/DisplayPowerController.java100
-rw-r--r--services/java/com/android/server/power/PowerManagerService.java58
-rw-r--r--wifi/java/android/net/wifi/WifiConfigStore.java46
-rw-r--r--wifi/java/android/net/wifi/WifiNative.java16
12 files changed, 356 insertions, 210 deletions
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index ab95d40..83e5ae9 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -450,6 +450,13 @@
The default is false. -->
<bool name="config_lidControlsSleep">false</bool>
+ <!-- Indicate whether to allow the device to suspend when the screen is off
+ due to the proximity sensor. This resource should only be set to true
+ if the sensor HAL correctly handles the proximity sensor as a wake-up source.
+ Otherwise, the device may fail to wake out of suspend reliably.
+ The default is false. -->
+ <bool name="config_suspendWhenScreenOffDueToProximity">false</bool>
+
<!-- Control the behavior when the user long presses the power button.
0 - Nothing
1 - Global actions menu
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 39e7127..96216f6 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -260,6 +260,7 @@
<java-symbol type="bool" name="config_sip_wifi_only" />
<java-symbol type="bool" name="config_sms_capable" />
<java-symbol type="bool" name="config_sms_utf8_support" />
+ <java-symbol type="bool" name="config_suspendWhenScreenOffDueToProximity" />
<java-symbol type="bool" name="config_swipeDisambiguation" />
<java-symbol type="bool" name="config_syncstorageengine_masterSyncAutomatically" />
<java-symbol type="bool" name="config_telephony_use_own_number_for_voicemail" />
diff --git a/libs/hwui/DeferredDisplayList.cpp b/libs/hwui/DeferredDisplayList.cpp
index 7ce15c5..fd9257a 100644
--- a/libs/hwui/DeferredDisplayList.cpp
+++ b/libs/hwui/DeferredDisplayList.cpp
@@ -66,23 +66,23 @@ public:
virtual ~DrawBatch() { mOps.clear(); }
- virtual void add(DrawOp* op, bool opaqueOverBounds) {
+ virtual void add(DrawOp* op, const DeferredDisplayState* state, bool opaqueOverBounds) {
// NOTE: ignore empty bounds special case, since we don't merge across those ops
- mBounds.unionWith(op->state.mBounds);
+ mBounds.unionWith(state->mBounds);
mAllOpsOpaque &= opaqueOverBounds;
- mOps.add(op);
+ mOps.add(OpStatePair(op, state));
}
- bool intersects(Rect& rect) {
+ bool intersects(const Rect& rect) {
if (!rect.intersects(mBounds)) return false;
for (unsigned int i = 0; i < mOps.size(); i++) {
- if (rect.intersects(mOps[i]->state.mBounds)) {
+ if (rect.intersects(mOps[i].state->mBounds)) {
#if DEBUG_DEFER
- DEFER_LOGD("op intersects with op %p with bounds %f %f %f %f:", mOps[i],
- mOps[i]->state.mBounds.left, mOps[i]->state.mBounds.top,
- mOps[i]->state.mBounds.right, mOps[i]->state.mBounds.bottom);
- mOps[i]->output(2);
+ DEFER_LOGD("op intersects with op %p with bounds %f %f %f %f:", mOps[i].op,
+ mOps[i].state->mBounds.left, mOps[i].state->mBounds.top,
+ mOps[i].state->mBounds.right, mOps[i].state->mBounds.bottom);
+ mOps[i].op->output(2);
#endif
return true;
}
@@ -97,9 +97,9 @@ public:
status_t status = DrawGlInfo::kStatusDone;
DisplayListLogBuffer& logBuffer = DisplayListLogBuffer::getInstance();
for (unsigned int i = 0; i < mOps.size(); i++) {
- DrawOp* op = mOps[i];
-
- renderer.restoreDisplayState(op->state);
+ DrawOp* op = mOps[i].op;
+ const DeferredDisplayState* state = mOps[i].state;
+ renderer.restoreDisplayState(*state);
#if DEBUG_DISPLAY_LIST_OPS_AS_EVENTS
renderer.eventMark(op->name());
@@ -108,7 +108,7 @@ public:
status |= op->applyDraw(renderer, dirty);
#if DEBUG_MERGE_BEHAVIOR
- Rect& bounds = mOps[i]->state.mBounds;
+ const Rect& bounds = state->mBounds;
int batchColor = 0x1f000000;
if (getBatchId() & 0x1) batchColor |= 0x0000ff;
if (getBatchId() & 0x2) batchColor |= 0x00ff00;
@@ -127,7 +127,7 @@ public:
Region uncovered(android::Rect(bounds.left, bounds.top, bounds.right, bounds.bottom));
for (unsigned int i = 0; i < mOps.size(); i++) {
- Rect &r = mOps[i]->state.mBounds;
+ const Rect &r = mOps[i].state->mBounds;
uncovered.subtractSelf(android::Rect(r.left, r.top, r.right, r.bottom));
}
return uncovered.isEmpty();
@@ -138,7 +138,7 @@ public:
inline int count() const { return mOps.size(); }
protected:
- Vector<DrawOp*> mOps;
+ Vector<OpStatePair> mOps;
Rect mBounds; // union of bounds of contained ops
private:
bool mAllOpsOpaque;
@@ -184,19 +184,19 @@ public:
* False positives can lead to information from the paints of subsequent merged operations being
* dropped, so we make simplifying qualifications on the ops that can merge, per op type.
*/
- bool canMergeWith(DrawOp* op) {
+ bool canMergeWith(const DrawOp* op, const DeferredDisplayState* state) {
bool isTextBatch = getBatchId() == DeferredDisplayList::kOpBatch_Text ||
getBatchId() == DeferredDisplayList::kOpBatch_ColorText;
// Overlapping other operations is only allowed for text without shadow. For other ops,
// multiDraw isn't guaranteed to overdraw correctly
- if (!isTextBatch || op->state.mDrawModifiers.mHasShadow) {
- if (intersects(op->state.mBounds)) return false;
+ if (!isTextBatch || state->mDrawModifiers.mHasShadow) {
+ if (intersects(state->mBounds)) return false;
}
- const DeferredDisplayState& lhs = op->state;
- const DeferredDisplayState& rhs = mOps[0]->state;
+ const DeferredDisplayState* lhs = state;
+ const DeferredDisplayState* rhs = mOps[0].state;
- if (NEQ_FALPHA(lhs.mAlpha, rhs.mAlpha)) return false;
+ if (NEQ_FALPHA(lhs->mAlpha, rhs->mAlpha)) return false;
/* Clipping compatibility check
*
@@ -204,9 +204,9 @@ public:
* clip for that side.
*/
const int currentFlags = mClipSideFlags;
- const int newFlags = op->state.mClipSideFlags;
+ const int newFlags = state->mClipSideFlags;
if (currentFlags != kClipSide_None || newFlags != kClipSide_None) {
- const Rect& opBounds = op->state.mBounds;
+ const Rect& opBounds = state->mBounds;
float boundsDelta = mBounds.left - opBounds.left;
if (!checkSide(currentFlags, newFlags, kClipSide_Left, boundsDelta)) return false;
boundsDelta = mBounds.top - opBounds.top;
@@ -220,9 +220,9 @@ public:
}
// if paints are equal, then modifiers + paint attribs don't need to be compared
- if (op->mPaint == mOps[0]->mPaint) return true;
+ if (op->mPaint == mOps[0].op->mPaint) return true;
- if (op->getPaintAlpha() != mOps[0]->getPaintAlpha()) return false;
+ if (op->getPaintAlpha() != mOps[0].op->getPaintAlpha()) return false;
/* Draw Modifiers compatibility check
*
@@ -236,8 +236,8 @@ public:
*
* These ignore cases prevent us from simply memcmp'ing the drawModifiers
*/
- const DrawModifiers& lhsMod = lhs.mDrawModifiers;
- const DrawModifiers& rhsMod = rhs.mDrawModifiers;
+ const DrawModifiers& lhsMod = lhs->mDrawModifiers;
+ const DrawModifiers& rhsMod = rhs->mDrawModifiers;
if (lhsMod.mShader != rhsMod.mShader) return false;
if (lhsMod.mColorFilter != rhsMod.mColorFilter) return false;
@@ -249,15 +249,15 @@ public:
return true;
}
- virtual void add(DrawOp* op, bool opaqueOverBounds) {
- DrawBatch::add(op, opaqueOverBounds);
+ virtual void add(DrawOp* op, DeferredDisplayState* state, bool opaqueOverBounds) {
+ DrawBatch::add(op, state, opaqueOverBounds);
- const int newClipSideFlags = op->state.mClipSideFlags;
+ const int newClipSideFlags = state->mClipSideFlags;
mClipSideFlags |= newClipSideFlags;
- if (newClipSideFlags & kClipSide_Left) mClipRect.left = op->state.mClip.left;
- if (newClipSideFlags & kClipSide_Top) mClipRect.top = op->state.mClip.top;
- if (newClipSideFlags & kClipSide_Right) mClipRect.right = op->state.mClip.right;
- if (newClipSideFlags & kClipSide_Bottom) mClipRect.bottom = op->state.mClip.bottom;
+ if (newClipSideFlags & kClipSide_Left) mClipRect.left = state->mClip.left;
+ if (newClipSideFlags & kClipSide_Top) mClipRect.top = state->mClip.top;
+ if (newClipSideFlags & kClipSide_Right) mClipRect.right = state->mClip.right;
+ if (newClipSideFlags & kClipSide_Bottom) mClipRect.bottom = state->mClip.bottom;
}
virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) {
@@ -271,7 +271,7 @@ public:
// clipping in the merged case is done ahead of time since all ops share the clip (if any)
renderer.setupMergedMultiDraw(mClipSideFlags ? &mClipRect : NULL);
- DrawOp* op = mOps[0];
+ DrawOp* op = mOps[0].op;
DisplayListLogBuffer& buffer = DisplayListLogBuffer::getInstance();
buffer.writeCommand(0, "multiDraw");
buffer.writeCommand(1, op->name());
@@ -297,11 +297,11 @@ private:
class StateOpBatch : public Batch {
public:
// creates a single operation batch
- StateOpBatch(StateOp* op) : mOp(op) {}
+ StateOpBatch(const StateOp* op, const DeferredDisplayState* state) : mOp(op), mState(state) {}
virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) {
DEFER_LOGD("replaying state op batch %p", this);
- renderer.restoreDisplayState(mOp->state);
+ renderer.restoreDisplayState(*mState);
// use invalid save count because it won't be used at flush time - RestoreToCountOp is the
// only one to use it, and we don't use that class at flush time, instead calling
@@ -313,16 +313,18 @@ public:
private:
const StateOp* mOp;
+ const DeferredDisplayState* mState;
};
class RestoreToCountBatch : public Batch {
public:
- RestoreToCountBatch(StateOp* op, int restoreCount) : mOp(op), mRestoreCount(restoreCount) {}
+ RestoreToCountBatch(const StateOp* op, const DeferredDisplayState* state, int restoreCount) :
+ mOp(op), mState(state), mRestoreCount(restoreCount) {}
virtual status_t replay(OpenGLRenderer& renderer, Rect& dirty, int index) {
DEFER_LOGD("batch %p restoring to count %d", this, mRestoreCount);
- renderer.restoreDisplayState(mOp->state);
+ renderer.restoreDisplayState(*mState);
renderer.restoreToCount(mRestoreCount);
return DrawGlInfo::kStatusDone;
}
@@ -330,6 +332,8 @@ public:
private:
// we use the state storage for the RestoreToCountOp, but don't replay the op itself
const StateOp* mOp;
+ const DeferredDisplayState* mState;
+
/*
* The count used here represents the flush() time saveCount. This is as opposed to the
* DisplayList record time, or defer() time values (which are RestoreToCountOp's mCount, and
@@ -480,12 +484,27 @@ void DeferredDisplayList::addRestoreToCount(OpenGLRenderer& renderer, StateOp* o
}
void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) {
- if (renderer.storeDisplayState(op->state, getDrawOpDeferFlags())) {
+ /* 1: op calculates local bounds */
+ DeferredDisplayState* const state = createState();
+ if (op->getLocalBounds(renderer.getDrawModifiers(), state->mBounds)) {
+ if (state->mBounds.isEmpty()) {
+ // valid empty bounds, don't bother deferring
+ tryRecycleState(state);
+ return;
+ }
+ } else {
+ state->mBounds.setEmpty();
+ }
+
+ /* 2: renderer calculates global bounds + stores state */
+ if (renderer.storeDisplayState(*state, getDrawOpDeferFlags())) {
+ tryRecycleState(state);
return; // quick rejected
}
+ /* 3: ask op for defer info, given renderer state */
DeferInfo deferInfo;
- op->onDefer(renderer, deferInfo);
+ op->onDefer(renderer, deferInfo, *state);
// complex clip has a complex set of expectations on the renderer state - for now, avoid taking
// the merge path in those cases
@@ -493,8 +512,8 @@ void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) {
deferInfo.opaqueOverBounds &= !recordingComplexClip() && mSaveStack.isEmpty();
if (CC_LIKELY(mAvoidOverdraw) && mBatches.size() &&
- op->state.mClipSideFlags != kClipSide_ConservativeFull &&
- deferInfo.opaqueOverBounds && op->state.mBounds.contains(mBounds)) {
+ state->mClipSideFlags != kClipSide_ConservativeFull &&
+ deferInfo.opaqueOverBounds && state->mBounds.contains(mBounds)) {
// avoid overdraw by resetting drawing state + discarding drawing ops
discardDrawingBatches(mBatches.size() - 1);
resetBatchingState();
@@ -503,7 +522,7 @@ void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) {
if (CC_UNLIKELY(renderer.getCaches().drawReorderDisabled)) {
// TODO: elegant way to reuse batches?
DrawBatch* b = new DrawBatch(deferInfo);
- b->add(op, deferInfo.opaqueOverBounds);
+ b->add(op, state, deferInfo.opaqueOverBounds);
mBatches.add(b);
return;
}
@@ -515,10 +534,10 @@ void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) {
// (eventually, should be similar shader)
int insertBatchIndex = mBatches.size();
if (!mBatches.isEmpty()) {
- if (op->state.mBounds.isEmpty()) {
+ if (state->mBounds.isEmpty()) {
// don't know the bounds for op, so add to last batch and start from scratch on next op
DrawBatch* b = new DrawBatch(deferInfo);
- b->add(op, deferInfo.opaqueOverBounds);
+ b->add(op, state, deferInfo.opaqueOverBounds);
mBatches.add(b);
resetBatchingState();
#if DEBUG_DEFER
@@ -531,7 +550,7 @@ void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) {
if (deferInfo.mergeable) {
// Try to merge with any existing batch with same mergeId.
if (mMergingBatches[deferInfo.batchId].get(deferInfo.mergeId, targetBatch)) {
- if (!((MergingDrawBatch*) targetBatch)->canMergeWith(op)) {
+ if (!((MergingDrawBatch*) targetBatch)->canMergeWith(op, state)) {
targetBatch = NULL;
}
}
@@ -554,14 +573,14 @@ void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) {
if (!targetBatch) break; // found insert position, quit
}
- if (overBatch->intersects(op->state.mBounds)) {
+ if (overBatch->intersects(state->mBounds)) {
// NOTE: it may be possible to optimize for special cases where two operations
// of the same batch/paint could swap order, such as with a non-mergeable
// (clipped) and a mergeable text operation
targetBatch = NULL;
#if DEBUG_DEFER
- DEFER_LOGD("op couldn't join batch %d, was intersected by batch %d",
- targetIndex, i);
+ DEFER_LOGD("op couldn't join batch %p, was intersected by batch %d",
+ targetBatch, i);
op->output(2);
#endif
break;
@@ -586,14 +605,15 @@ void DeferredDisplayList::addDrawOp(OpenGLRenderer& renderer, DrawOp* op) {
mBatches.insertAt(targetBatch, insertBatchIndex);
}
- targetBatch->add(op, deferInfo.opaqueOverBounds);
+ targetBatch->add(op, state, deferInfo.opaqueOverBounds);
}
void DeferredDisplayList::storeStateOpBarrier(OpenGLRenderer& renderer, StateOp* op) {
DEFER_LOGD("%p adding state op barrier at pos %d", this, mBatches.size());
- renderer.storeDisplayState(op->state, getStateOpDeferFlags());
- mBatches.add(new StateOpBatch(op));
+ DeferredDisplayState* state = createState();
+ renderer.storeDisplayState(*state, getStateOpDeferFlags());
+ mBatches.add(new StateOpBatch(op, state));
resetBatchingState();
}
@@ -604,8 +624,9 @@ void DeferredDisplayList::storeRestoreToCountBarrier(OpenGLRenderer& renderer, S
// store displayState for the restore operation, as it may be associated with a saveLayer that
// doesn't have kClip_SaveFlag set
- renderer.storeDisplayState(op->state, getStateOpDeferFlags());
- mBatches.add(new RestoreToCountBatch(op, newSaveCount));
+ DeferredDisplayState* state = createState();
+ renderer.storeDisplayState(*state, getStateOpDeferFlags());
+ mBatches.add(new RestoreToCountBatch(op, state, newSaveCount));
resetBatchingState();
}
diff --git a/libs/hwui/DeferredDisplayList.h b/libs/hwui/DeferredDisplayList.h
index 1ef0152..3dcbd0b 100644
--- a/libs/hwui/DeferredDisplayList.h
+++ b/libs/hwui/DeferredDisplayList.h
@@ -18,11 +18,13 @@
#define ANDROID_HWUI_DEFERRED_DISPLAY_LIST_H
#include <utils/Errors.h>
+#include <utils/LinearAllocator.h>
#include <utils/Vector.h>
+#include <utils/TinyHashMap.h>
#include "Matrix.h"
+#include "OpenGLRenderer.h"
#include "Rect.h"
-#include "utils/TinyHashMap.h"
class SkBitmap;
@@ -34,6 +36,8 @@ class DrawOp;
class SaveOp;
class SaveLayerOp;
class StateOp;
+
+class DeferredDisplayState;
class OpenGLRenderer;
class Batch;
@@ -42,6 +46,38 @@ class MergingDrawBatch;
typedef const void* mergeid_t;
+class DeferredDisplayState {
+public:
+ /** static void* operator new(size_t size); PURPOSELY OMITTED **/
+ static void* operator new(size_t size, LinearAllocator& allocator) {
+ return allocator.alloc(size);
+ }
+
+ // global op bounds, mapped by mMatrix to be in screen space coordinates, clipped
+ Rect mBounds;
+
+ // the below are set and used by the OpenGLRenderer at record and deferred playback
+ bool mClipValid;
+ Rect mClip;
+ int mClipSideFlags; // specifies which sides of the bounds are clipped, unclipped if cleared
+ bool mClipped;
+ mat4 mMatrix;
+ DrawModifiers mDrawModifiers;
+ float mAlpha;
+};
+
+class OpStatePair {
+public:
+ OpStatePair()
+ : op(NULL), state(NULL) {}
+ OpStatePair(DrawOp* newOp, const DeferredDisplayState* newState)
+ : op(newOp), state(newState) {}
+ OpStatePair(const OpStatePair& other)
+ : op(other.op), state(other.state) {}
+ DrawOp* op;
+ const DeferredDisplayState* state;
+};
+
class DeferredDisplayList {
public:
DeferredDisplayList(const Rect& bounds, bool avoidOverdraw = true) :
@@ -84,6 +120,14 @@ public:
void addDrawOp(OpenGLRenderer& renderer, DrawOp* op);
private:
+ DeferredDisplayState* createState() {
+ return new (mAllocator) DeferredDisplayState();
+ }
+
+ void tryRecycleState(DeferredDisplayState* state) {
+ mAllocator.rewindIfLastAlloc(state, sizeof(DeferredDisplayState));
+ }
+
/**
* Resets the batching back-pointers, creating a barrier in the operation stream so that no ops
* added in the future will be inserted into a batch that already exist.
@@ -131,6 +175,8 @@ private:
* collide, which avoids the need to resolve mergeid collisions.
*/
TinyHashMap<mergeid_t, DrawBatch*> mMergingBatches[kOpBatch_Count];
+
+ LinearAllocator mAllocator;
};
/**
diff --git a/libs/hwui/DisplayList.h b/libs/hwui/DisplayList.h
index 194be9e..1cd5f1c 100644
--- a/libs/hwui/DisplayList.h
+++ b/libs/hwui/DisplayList.h
@@ -26,6 +26,7 @@
#include <private/hwui/DrawGlInfo.h>
+#include <utils/LinearAllocator.h>
#include <utils/RefBase.h>
#include <utils/SortedVector.h>
#include <utils/String8.h>
@@ -35,8 +36,6 @@
#include <androidfw/ResourceTypes.h>
-#include "utils/LinearAllocator.h"
-
#include "Debug.h"
#define TRANSLATION 0x0001
@@ -114,7 +113,6 @@ public:
void initFromDisplayListRenderer(const DisplayListRenderer& recorder, bool reusing = false);
-
void defer(DeferStateStruct& deferStruct, const int level);
void replay(ReplayStateStruct& replayStruct, const int level);
diff --git a/libs/hwui/DisplayListOp.h b/libs/hwui/DisplayListOp.h
index 42e11d0..a17942e 100644
--- a/libs/hwui/DisplayListOp.h
+++ b/libs/hwui/DisplayListOp.h
@@ -82,15 +82,6 @@ public:
// NOTE: it would be nice to declare constants and overriding the implementation in each op to
// point at the constants, but that seems to require a .cpp file
virtual const char* name() = 0;
-
- /**
- * Stores the relevant canvas state of the object between deferral and replay (if the canvas
- * state supports being stored) See OpenGLRenderer::simpleClipAndState()
- *
- * TODO: don't reserve space for StateOps that won't be deferred
- */
- DeferredDisplayState state;
-
};
class StateOp : public DisplayListOp {
@@ -129,14 +120,6 @@ public:
return;
}
- if (getLocalBounds(state.mBounds)) {
- // valid empty bounds, don't bother deferring
- if (state.mBounds.isEmpty()) return;
- } else {
- // empty bounds signify bounds can't be calculated
- state.mBounds.setEmpty();
- }
-
deferStruct.mDeferredList.addDrawOp(deferStruct.mRenderer, this);
}
@@ -159,11 +142,11 @@ public:
* reducing which operations are tagged as mergeable.
*/
virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty,
- const Vector<DrawOp*>& ops, const Rect& bounds) {
+ const Vector<OpStatePair>& ops, const Rect& bounds) {
status_t status = DrawGlInfo::kStatusDone;
for (unsigned int i = 0; i < ops.size(); i++) {
- renderer.restoreDisplayState(ops[i]->state, true);
- status |= ops[i]->applyDraw(renderer, dirty);
+ renderer.restoreDisplayState(*(ops[i].state), true);
+ status |= ops[i].op->applyDraw(renderer, dirty);
}
return status;
}
@@ -178,20 +161,23 @@ public:
*
* if a subclass can set deferInfo.mergeable to true, it should implement multiDraw()
*/
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {}
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {}
/**
* Query the conservative, local bounds (unmapped) bounds of the op.
*
* returns true if bounds exist
*/
- virtual bool getLocalBounds(Rect& localBounds) { return false; }
+ virtual bool getLocalBounds(const DrawModifiers& drawModifiers, Rect& localBounds) {
+ return false;
+ }
// TODO: better refine localbounds usage
void setQuickRejected(bool quickRejected) { mQuickRejected = quickRejected; }
bool getQuickRejected() { return mQuickRejected; }
- inline int getPaintAlpha() {
+ inline int getPaintAlpha() const {
return OpenGLRenderer::getAlphaDirect(mPaint);
}
@@ -208,7 +194,7 @@ protected:
// Helper method for determining op opaqueness. Assumes op fills its bounds in local
// coordinates, and that paint's alpha is used
- inline bool isOpaqueOverBounds() {
+ inline bool isOpaqueOverBounds(const DeferredDisplayState& state) {
// ensure that local bounds cover mapped bounds
if (!state.mMatrix.isSimple()) return false;
@@ -251,12 +237,13 @@ public:
// default empty constructor for bounds, to be overridden in child constructor body
DrawBoundedOp(SkPaint* paint): DrawOp(paint) { }
- bool getLocalBounds(Rect& localBounds) {
+ bool getLocalBounds(const DrawModifiers& drawModifiers, Rect& localBounds) {
localBounds.set(mLocalBounds);
- if (state.mDrawModifiers.mHasShadow) {
+ if (drawModifiers.mHasShadow) {
+ // TODO: inspect paint's looper directly
Rect shadow(mLocalBounds);
- shadow.translate(state.mDrawModifiers.mShadowDx, state.mDrawModifiers.mShadowDy);
- shadow.outset(state.mDrawModifiers.mShadowRadius);
+ shadow.translate(drawModifiers.mShadowDx, drawModifiers.mShadowDy);
+ shadow.outset(drawModifiers.mShadowRadius);
localBounds.unionWith(shadow);
}
return true;
@@ -777,8 +764,10 @@ public:
* the current layer, if any.
*/
virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty,
- const Vector<DrawOp*>& ops, const Rect& bounds) {
- renderer.restoreDisplayState(state, true); // restore all but the clip
+ const Vector<OpStatePair>& ops, const Rect& bounds) {
+ const DeferredDisplayState& firstState = *(ops[0].state);
+ renderer.restoreDisplayState(firstState, true); // restore all but the clip
+
TextureVertex vertices[6 * ops.size()];
TextureVertex* vertex = &vertices[0];
@@ -788,14 +777,15 @@ public:
// TODO: manually handle rect clip for bitmaps by adjusting texCoords per op,
// and allowing them to be merged in getBatchId()
for (unsigned int i = 0; i < ops.size(); i++) {
- const Rect& opBounds = ops[i]->state.mBounds;
+ const DeferredDisplayState& state = *(ops[i].state);
+ const Rect& opBounds = state.mBounds;
// When we reach multiDraw(), the matrix can be either
// pureTranslate or simple (translate and/or scale).
// If the matrix is not pureTranslate, then we have a scale
- if (!ops[i]->state.mMatrix.isPureTranslate()) transformed = true;
+ if (state.mMatrix.isPureTranslate()) transformed = true;
Rect texCoords(0, 0, 1, 1);
- ((DrawBitmapOp*) ops[i])->mUvMapper.map(texCoords);
+ ((DrawBitmapOp*) ops[i].op)->mUvMapper.map(texCoords);
SET_TEXTURE(vertex, opBounds, bounds, texCoords, left, top);
SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, top);
@@ -806,8 +796,7 @@ public:
SET_TEXTURE(vertex, opBounds, bounds, texCoords, right, bottom);
if (hasLayer) {
- const Rect& dirty = ops[i]->state.mBounds;
- renderer.dirtyLayer(dirty.left, dirty.top, dirty.right, dirty.bottom);
+ renderer.dirtyLayer(opBounds.left, opBounds.top, opBounds.right, opBounds.bottom);
}
}
@@ -821,7 +810,8 @@ public:
virtual const char* name() { return "DrawBitmap"; }
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
deferInfo.mergeId = getAtlasEntry() ? (mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap;
@@ -861,7 +851,8 @@ public:
virtual const char* name() { return "DrawBitmapMatrix"; }
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
}
@@ -890,7 +881,8 @@ public:
virtual const char* name() { return "DrawBitmapRect"; }
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
}
@@ -915,7 +907,8 @@ public:
virtual const char* name() { return "DrawBitmapData"; }
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
}
};
@@ -939,7 +932,8 @@ public:
virtual const char* name() { return "DrawBitmapMesh"; }
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
deferInfo.batchId = DeferredDisplayList::kOpBatch_Bitmap;
}
@@ -989,15 +983,16 @@ public:
* is also responsible for dirtying the current layer, if any.
*/
virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty,
- const Vector<DrawOp*>& ops, const Rect& bounds) {
- renderer.restoreDisplayState(state, true);
+ const Vector<OpStatePair>& ops, const Rect& bounds) {
+ const DeferredDisplayState& firstState = *(ops[0].state);
+ renderer.restoreDisplayState(firstState, true); // restore all but the clip
// Batches will usually contain a small number of items so it's
// worth performing a first iteration to count the exact number
// of vertices we need in the new mesh
uint32_t totalVertices = 0;
for (unsigned int i = 0; i < ops.size(); i++) {
- totalVertices += ((DrawPatchOp*) ops[i])->getMesh(renderer)->verticesCount;
+ totalVertices += ((DrawPatchOp*) ops[i].op)->getMesh(renderer)->verticesCount;
}
const bool hasLayer = renderer.hasLayer();
@@ -1012,7 +1007,8 @@ public:
// enforces ops drawn by this function to have a pure translate or
// identity matrix
for (unsigned int i = 0; i < ops.size(); i++) {
- DrawPatchOp* patchOp = (DrawPatchOp*) ops[i];
+ DrawPatchOp* patchOp = (DrawPatchOp*) ops[i].op;
+ const DeferredDisplayState* state = ops[i].state;
const Patch* opMesh = patchOp->getMesh(renderer);
uint32_t vertexCount = opMesh->verticesCount;
if (vertexCount == 0) continue;
@@ -1020,9 +1016,9 @@ public:
// We use the bounds to know where to translate our vertices
// Using patchOp->state.mBounds wouldn't work because these
// bounds are clipped
- const float tx = (int) floorf(patchOp->state.mMatrix.getTranslateX() +
+ const float tx = (int) floorf(state->mMatrix.getTranslateX() +
patchOp->mLocalBounds.left + 0.5f);
- const float ty = (int) floorf(patchOp->state.mMatrix.getTranslateY() +
+ const float ty = (int) floorf(state->mMatrix.getTranslateY() +
patchOp->mLocalBounds.top + 0.5f);
// Copy & transform all the vertices for the current operation
@@ -1074,12 +1070,13 @@ public:
virtual const char* name() { return "DrawPatch"; }
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
deferInfo.batchId = DeferredDisplayList::kOpBatch_Patch;
deferInfo.mergeId = getAtlasEntry() ? (mergeid_t) mEntry->getMergeId() : (mergeid_t) mBitmap;
deferInfo.mergeable = state.mMatrix.isPureTranslate() &&
OpenGLRenderer::getXfermodeDirect(mPaint) == SkXfermode::kSrcOver_Mode;
- deferInfo.opaqueOverBounds = isOpaqueOverBounds() && mBitmap->isOpaque();
+ deferInfo.opaqueOverBounds = isOpaqueOverBounds(state) && mBitmap->isOpaque();
}
private:
@@ -1119,7 +1116,7 @@ public:
DrawStrokableOp(float left, float top, float right, float bottom, SkPaint* paint)
: DrawBoundedOp(left, top, right, bottom, paint) {};
- bool getLocalBounds(Rect& localBounds) {
+ bool getLocalBounds(const DrawModifiers& drawModifiers, Rect& localBounds) {
localBounds.set(mLocalBounds);
if (mPaint && mPaint->getStyle() != SkPaint::kFill_Style) {
localBounds.outset(strokeWidthOutset());
@@ -1127,7 +1124,8 @@ public:
return true;
}
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
if (mPaint->getPathEffect()) {
deferInfo.batchId = DeferredDisplayList::kOpBatch_AlphaMaskTexture;
} else {
@@ -1152,9 +1150,10 @@ public:
OP_LOG("Draw Rect "RECT_STRING, RECT_ARGS(mLocalBounds));
}
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
- DrawStrokableOp::onDefer(renderer, deferInfo);
- deferInfo.opaqueOverBounds = isOpaqueOverBounds() &&
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
+ DrawStrokableOp::onDefer(renderer, deferInfo, state);
+ deferInfo.opaqueOverBounds = isOpaqueOverBounds(state) &&
mPaint->getStyle() == SkPaint::kFill_Style;
}
@@ -1177,7 +1176,8 @@ public:
virtual const char* name() { return "DrawRects"; }
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
deferInfo.batchId = DeferredDisplayList::kOpBatch_Vertices;
}
@@ -1289,7 +1289,8 @@ public:
return renderer.drawPath(mPath, getPaint(renderer));
}
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
SkPaint* paint = getPaint(renderer);
renderer.getCaches().pathCache.precache(mPath, paint);
@@ -1324,7 +1325,8 @@ public:
virtual const char* name() { return "DrawLines"; }
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
deferInfo.batchId = mPaint->isAntiAlias() ?
DeferredDisplayList::kOpBatch_AlphaVertices :
DeferredDisplayList::kOpBatch_Vertices;
@@ -1360,7 +1362,8 @@ public:
OP_LOG("Draw some text, %d bytes", mBytesCount);
}
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
SkPaint* paint = getPaint(renderer);
FontRenderer& fontRenderer = renderer.getCaches().fontRenderer->getFontRenderer(paint);
fontRenderer.precache(paint, mText, mCount, mat4::identity());
@@ -1425,7 +1428,8 @@ public:
memset(&mPrecacheTransform.data[0], 0xff, 16 * sizeof(float));
}
- virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo) {
+ virtual void onDefer(OpenGLRenderer& renderer, DeferInfo& deferInfo,
+ const DeferredDisplayState& state) {
SkPaint* paint = getPaint(renderer);
FontRenderer& fontRenderer = renderer.getCaches().fontRenderer->getFontRenderer(paint);
const mat4& transform = renderer.findBestFontTransform(state.mMatrix);
@@ -1448,19 +1452,20 @@ public:
virtual status_t applyDraw(OpenGLRenderer& renderer, Rect& dirty) {
Rect bounds;
- getLocalBounds(bounds);
+ getLocalBounds(renderer.getDrawModifiers(), bounds);
return renderer.drawText(mText, mBytesCount, mCount, mX, mY,
mPositions, getPaint(renderer), mTotalAdvance, bounds);
}
virtual status_t multiDraw(OpenGLRenderer& renderer, Rect& dirty,
- const Vector<DrawOp*>& ops, const Rect& bounds) {
+ const Vector<OpStatePair>& ops, const Rect& bounds) {
status_t status = DrawGlInfo::kStatusDone;
for (unsigned int i = 0; i < ops.size(); i++) {
+ const DeferredDisplayState& state = *(ops[i].state);
DrawOpMode drawOpMode = (i == ops.size() - 1) ? kDrawOpMode_Flush : kDrawOpMode_Defer;
- renderer.restoreDisplayState(ops[i]->state, true); // restore all but the clip
+ renderer.restoreDisplayState(state, true); // restore all but the clip
- DrawTextOp& op = *((DrawTextOp*)ops[i]);
+ DrawTextOp& op = *((DrawTextOp*)ops[i].op);
// quickReject() will not occure in drawText() so we can use mLocalBounds
// directly, we do not need to account for shadow by calling getLocalBounds()
status |= renderer.drawText(op.mText, op.mBytesCount, op.mCount, op.mX, op.mY,
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 90dcf93..8866029 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -505,17 +505,12 @@ void DisplayListRenderer::addStateOp(StateOp* op) {
void DisplayListRenderer::addDrawOp(DrawOp* op) {
Rect localBounds;
- if (mDrawModifiers.mHasShadow) {
- op->state.mDrawModifiers = mDrawModifiers;
- }
- if (op->getLocalBounds(localBounds)) {
+ if (op->getLocalBounds(mDrawModifiers, localBounds)) {
bool rejected = quickRejectNoScissor(localBounds.left, localBounds.top,
localBounds.right, localBounds.bottom);
op->setQuickRejected(rejected);
}
- if (mDrawModifiers.mHasShadow) {
- op->state.mDrawModifiers.reset();
- }
+
mHasDrawOps = true;
addOpInternal(op);
}
diff --git a/libs/hwui/OpenGLRenderer.h b/libs/hwui/OpenGLRenderer.h
index 54f6d76..f74df97 100644
--- a/libs/hwui/OpenGLRenderer.h
+++ b/libs/hwui/OpenGLRenderer.h
@@ -98,24 +98,11 @@ enum ClipSideFlags {
kClipSide_ConservativeFull = 0x1F
};
-struct DeferredDisplayState {
- // global op bounds, mapped by mMatrix to be in screen space coordinates, clipped
- Rect mBounds;
-
- // the below are set and used by the OpenGLRenderer at record and deferred playback
- bool mClipValid;
- Rect mClip;
- int mClipSideFlags; // specifies which sides of the bounds are clipped, unclipped if cleared
- bool mClipped;
- mat4 mMatrix;
- DrawModifiers mDrawModifiers;
- float mAlpha;
-};
-
///////////////////////////////////////////////////////////////////////////////
// Renderer
///////////////////////////////////////////////////////////////////////////////
+class DeferredDisplayState;
class DisplayList;
class TextSetupFunctor;
class VertexBuffer;
@@ -423,7 +410,7 @@ public:
return getXfermode(paint->getXfermode());
}
- static inline int getAlphaDirect(SkPaint* paint) {
+ static inline int getAlphaDirect(const SkPaint* paint) {
if (!paint) return 255;
return paint->getAlpha();
}
diff --git a/services/java/com/android/server/power/DisplayPowerController.java b/services/java/com/android/server/power/DisplayPowerController.java
index b5010f2..976a328 100644
--- a/services/java/com/android/server/power/DisplayPowerController.java
+++ b/services/java/com/android/server/power/DisplayPowerController.java
@@ -29,7 +29,6 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
-import android.hardware.SystemSensorManager;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -119,7 +118,7 @@ final class DisplayPowerController {
// Proximity sensor debounce delay in milliseconds for positive or negative transitions.
private static final int PROXIMITY_SENSOR_POSITIVE_DEBOUNCE_DELAY = 0;
- private static final int PROXIMITY_SENSOR_NEGATIVE_DEBOUNCE_DELAY = 500;
+ private static final int PROXIMITY_SENSOR_NEGATIVE_DEBOUNCE_DELAY = 250;
// Trigger proximity if distance is less than 5 cm.
private static final float TYPICAL_PROXIMITY_THRESHOLD = 5.0f;
@@ -164,6 +163,10 @@ final class DisplayPowerController {
// Notifier for sending asynchronous notifications.
private final Notifier mNotifier;
+ // The display suspend blocker.
+ // Held while there are pending state change notifications.
+ private final SuspendBlocker mDisplaySuspendBlocker;
+
// The display blanker.
private final DisplayBlanker mDisplayBlanker;
@@ -271,7 +274,7 @@ final class DisplayPowerController {
// The raw non-debounced proximity sensor state.
private int mPendingProximity = PROXIMITY_UNKNOWN;
- private long mPendingProximityDebounceTime;
+ private long mPendingProximityDebounceTime = -1; // -1 if fully debounced
// True if the screen was turned off because of the proximity sensor.
// When the screen turns on again, we report user activity to the power manager.
@@ -346,10 +349,11 @@ final class DisplayPowerController {
public DisplayPowerController(Looper looper, Context context, Notifier notifier,
LightsService lights, TwilightService twilight, SensorManager sensorManager,
DisplayManagerService displayManager,
- DisplayBlanker displayBlanker,
+ SuspendBlocker displaySuspendBlocker, DisplayBlanker displayBlanker,
Callbacks callbacks, Handler callbackHandler) {
mHandler = new DisplayControllerHandler(looper);
mNotifier = notifier;
+ mDisplaySuspendBlocker = displaySuspendBlocker;
mDisplayBlanker = displayBlanker;
mCallbacks = callbacks;
mCallbackHandler = callbackHandler;
@@ -601,7 +605,7 @@ final class DisplayPowerController {
if (!mScreenOffBecauseOfProximity
&& mProximity == PROXIMITY_POSITIVE) {
mScreenOffBecauseOfProximity = true;
- sendOnProximityPositive();
+ sendOnProximityPositiveWithWakelock();
setScreenOn(false);
}
} else if (mWaitingForNegativeProximity
@@ -616,7 +620,7 @@ final class DisplayPowerController {
if (mScreenOffBecauseOfProximity
&& mProximity != PROXIMITY_POSITIVE) {
mScreenOffBecauseOfProximity = false;
- sendOnProximityNegative();
+ sendOnProximityNegativeWithWakelock();
}
} else {
mWaitingForNegativeProximity = false;
@@ -737,7 +741,7 @@ final class DisplayPowerController {
}
}
}
- sendOnStateChanged();
+ sendOnStateChangedWithWakelock();
}
}
@@ -810,49 +814,67 @@ final class DisplayPowerController {
private void setProximitySensorEnabled(boolean enable) {
if (enable) {
if (!mProximitySensorEnabled) {
+ // Register the listener.
+ // Proximity sensor state already cleared initially.
mProximitySensorEnabled = true;
- mPendingProximity = PROXIMITY_UNKNOWN;
mSensorManager.registerListener(mProximitySensorListener, mProximitySensor,
SensorManager.SENSOR_DELAY_NORMAL, mHandler);
}
} else {
if (mProximitySensorEnabled) {
+ // Unregister the listener.
+ // Clear the proximity sensor state for next time.
mProximitySensorEnabled = false;
mProximity = PROXIMITY_UNKNOWN;
+ mPendingProximity = PROXIMITY_UNKNOWN;
mHandler.removeMessages(MSG_PROXIMITY_SENSOR_DEBOUNCED);
mSensorManager.unregisterListener(mProximitySensorListener);
+ clearPendingProximityDebounceTime(); // release wake lock (must be last)
}
}
}
private void handleProximitySensorEvent(long time, boolean positive) {
- if (mPendingProximity == PROXIMITY_NEGATIVE && !positive) {
- return; // no change
- }
- if (mPendingProximity == PROXIMITY_POSITIVE && positive) {
- return; // no change
- }
+ if (mProximitySensorEnabled) {
+ if (mPendingProximity == PROXIMITY_NEGATIVE && !positive) {
+ return; // no change
+ }
+ if (mPendingProximity == PROXIMITY_POSITIVE && positive) {
+ return; // no change
+ }
- // Only accept a proximity sensor reading if it remains
- // stable for the entire debounce delay.
- mHandler.removeMessages(MSG_PROXIMITY_SENSOR_DEBOUNCED);
- if (positive) {
- mPendingProximity = PROXIMITY_POSITIVE;
- mPendingProximityDebounceTime = time + PROXIMITY_SENSOR_POSITIVE_DEBOUNCE_DELAY;
- } else {
- mPendingProximity = PROXIMITY_NEGATIVE;
- mPendingProximityDebounceTime = time + PROXIMITY_SENSOR_NEGATIVE_DEBOUNCE_DELAY;
+ // Only accept a proximity sensor reading if it remains
+ // stable for the entire debounce delay. We hold a wake lock while
+ // debouncing the sensor.
+ mHandler.removeMessages(MSG_PROXIMITY_SENSOR_DEBOUNCED);
+ if (positive) {
+ mPendingProximity = PROXIMITY_POSITIVE;
+ setPendingProximityDebounceTime(
+ time + PROXIMITY_SENSOR_POSITIVE_DEBOUNCE_DELAY); // acquire wake lock
+ } else {
+ mPendingProximity = PROXIMITY_NEGATIVE;
+ setPendingProximityDebounceTime(
+ time + PROXIMITY_SENSOR_NEGATIVE_DEBOUNCE_DELAY); // acquire wake lock
+ }
+
+ // Debounce the new sensor reading.
+ debounceProximitySensor();
}
- debounceProximitySensor();
}
private void debounceProximitySensor() {
- if (mPendingProximity != PROXIMITY_UNKNOWN) {
+ if (mProximitySensorEnabled
+ && mPendingProximity != PROXIMITY_UNKNOWN
+ && mPendingProximityDebounceTime >= 0) {
final long now = SystemClock.uptimeMillis();
if (mPendingProximityDebounceTime <= now) {
+ // Sensor reading accepted. Apply the change then release the wake lock.
mProximity = mPendingProximity;
- sendUpdatePowerState();
+ updatePowerState();
+ clearPendingProximityDebounceTime(); // release wake lock (must be last)
} else {
+ // Need to wait a little longer.
+ // Debounce again later. We continue holding a wake lock while waiting.
Message msg = mHandler.obtainMessage(MSG_PROXIMITY_SENSOR_DEBOUNCED);
msg.setAsynchronous(true);
mHandler.sendMessageAtTime(msg, mPendingProximityDebounceTime);
@@ -860,6 +882,20 @@ final class DisplayPowerController {
}
}
+ private void clearPendingProximityDebounceTime() {
+ if (mPendingProximityDebounceTime >= 0) {
+ mPendingProximityDebounceTime = -1;
+ mDisplaySuspendBlocker.release(); // release wake lock
+ }
+ }
+
+ private void setPendingProximityDebounceTime(long debounceTime) {
+ if (mPendingProximityDebounceTime < 0) {
+ mDisplaySuspendBlocker.acquire(); // acquire wake lock
+ }
+ mPendingProximityDebounceTime = debounceTime;
+ }
+
private void setLightSensorEnabled(boolean enable, boolean updateAutoBrightness) {
if (enable) {
if (!mLightSensorEnabled) {
@@ -1120,7 +1156,8 @@ final class DisplayPowerController {
return x + (y - x) * alpha;
}
- private void sendOnStateChanged() {
+ private void sendOnStateChangedWithWakelock() {
+ mDisplaySuspendBlocker.acquire();
mCallbackHandler.post(mOnStateChangedRunnable);
}
@@ -1128,10 +1165,12 @@ final class DisplayPowerController {
@Override
public void run() {
mCallbacks.onStateChanged();
+ mDisplaySuspendBlocker.release();
}
};
- private void sendOnProximityPositive() {
+ private void sendOnProximityPositiveWithWakelock() {
+ mDisplaySuspendBlocker.acquire();
mCallbackHandler.post(mOnProximityPositiveRunnable);
}
@@ -1139,10 +1178,12 @@ final class DisplayPowerController {
@Override
public void run() {
mCallbacks.onProximityPositive();
+ mDisplaySuspendBlocker.release();
}
};
- private void sendOnProximityNegative() {
+ private void sendOnProximityNegativeWithWakelock() {
+ mDisplaySuspendBlocker.acquire();
mCallbackHandler.post(mOnProximityNegativeRunnable);
}
@@ -1150,6 +1191,7 @@ final class DisplayPowerController {
@Override
public void run() {
mCallbacks.onProximityNegative();
+ mDisplaySuspendBlocker.release();
}
};
diff --git a/services/java/com/android/server/power/PowerManagerService.java b/services/java/com/android/server/power/PowerManagerService.java
index 2167f67..fe09a33 100644
--- a/services/java/com/android/server/power/PowerManagerService.java
+++ b/services/java/com/android/server/power/PowerManagerService.java
@@ -63,7 +63,6 @@ import android.util.TimeUtils;
import android.view.WindowManagerPolicy;
import java.io.FileDescriptor;
-import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -287,6 +286,9 @@ public final class PowerManagerService extends IPowerManager.Stub
// True if the device should wake up when plugged or unplugged.
private boolean mWakeUpWhenPluggedOrUnpluggedConfig;
+ // True if the device should suspend when the screen is off due to proximity.
+ private boolean mSuspendWhenScreenOffDueToProximityConfig;
+
// True if dreams are supported on this device.
private boolean mDreamsSupportedConfig;
@@ -447,7 +449,7 @@ public final class PowerManagerService extends IPowerManager.Stub
// own handler thread to ensure timely operation.
mDisplayPowerController = new DisplayPowerController(mHandler.getLooper(),
mContext, mNotifier, mLightsService, twilight, sensorManager,
- mDisplayManagerService, mDisplayBlanker,
+ mDisplayManagerService, mDisplaySuspendBlocker, mDisplayBlanker,
mDisplayPowerControllerCallbacks, mHandler);
mWirelessChargerDetector = new WirelessChargerDetector(sensorManager,
@@ -514,6 +516,8 @@ public final class PowerManagerService extends IPowerManager.Stub
mWakeUpWhenPluggedOrUnpluggedConfig = resources.getBoolean(
com.android.internal.R.bool.config_unplugTurnsOnScreen);
+ mSuspendWhenScreenOffDueToProximityConfig = resources.getBoolean(
+ com.android.internal.R.bool.config_suspendWhenScreenOffDueToProximity);
mDreamsSupportedConfig = resources.getBoolean(
com.android.internal.R.bool.config_dreamsSupported);
mDreamsEnabledByDefaultConfig = resources.getBoolean(
@@ -639,6 +643,7 @@ public final class PowerManagerService extends IPowerManager.Stub
}
}
+ @SuppressWarnings("deprecation")
private static boolean isScreenLock(final WakeLock wakeLock) {
switch (wakeLock.mFlags & PowerManager.WAKE_LOCK_LEVEL_MASK) {
case PowerManager.FULL_WAKE_LOCK:
@@ -817,6 +822,7 @@ public final class PowerManagerService extends IPowerManager.Stub
}
}
+ @SuppressWarnings("deprecation")
private boolean isWakeLockLevelSupportedInternal(int level) {
synchronized (mLock) {
switch (level) {
@@ -1005,6 +1011,7 @@ public final class PowerManagerService extends IPowerManager.Stub
}
}
+ @SuppressWarnings("deprecation")
private boolean goToSleepNoUpdateLocked(long eventTime, int reason) {
if (DEBUG_SPEW) {
Slog.d(TAG, "goToSleepNoUpdateLocked: eventTime=" + eventTime + ", reason=" + reason);
@@ -1261,6 +1268,7 @@ public final class PowerManagerService extends IPowerManager.Stub
*
* This function must have no other side-effects.
*/
+ @SuppressWarnings("deprecation")
private void updateWakeLockSummaryLocked(int dirty) {
if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_WAKEFULNESS)) != 0) {
mWakeLockSummary = 0;
@@ -1299,7 +1307,7 @@ public final class PowerManagerService extends IPowerManager.Stub
break;
case PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK:
if (mWakefulness != WAKEFULNESS_ASLEEP) {
- mWakeLockSummary |= WAKE_LOCK_CPU | WAKE_LOCK_PROXIMITY_SCREEN_OFF;
+ mWakeLockSummary |= WAKE_LOCK_PROXIMITY_SCREEN_OFF;
}
break;
}
@@ -1458,7 +1466,11 @@ public final class PowerManagerService extends IPowerManager.Stub
/**
* Returns true if the device is being kept awake by a wake lock, user activity
- * or the stay on while powered setting.
+ * or the stay on while powered setting. We also keep the phone awake when
+ * the proximity sensor returns a positive result so that the device does not
+ * lock while in a phone call. This function only controls whether the device
+ * will go to sleep or dream which is independent of whether it will be allowed
+ * to suspend.
*/
private boolean isBeingKeptAwakeLocked() {
return mStayOn
@@ -1749,10 +1761,8 @@ public final class PowerManagerService extends IPowerManager.Stub
* This function must have no other side-effects.
*/
private void updateSuspendBlockerLocked() {
- final boolean needWakeLockSuspendBlocker = (mWakeLockSummary != 0);
- final boolean needDisplaySuspendBlocker = (mUserActivitySummary != 0
- || mDisplayPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF
- || !mDisplayReady || !mBootCompleted);
+ final boolean needWakeLockSuspendBlocker = ((mWakeLockSummary & WAKE_LOCK_CPU) != 0);
+ final boolean needDisplaySuspendBlocker = needDisplaySuspendBlocker();
// First acquire suspend blockers if needed.
if (needWakeLockSuspendBlocker && !mHoldingWakeLockSuspendBlocker) {
@@ -1775,6 +1785,27 @@ public final class PowerManagerService extends IPowerManager.Stub
}
}
+ /**
+ * Return true if we must keep a suspend blocker active on behalf of the display.
+ * We do so if the screen is on or is in transition between states.
+ */
+ private boolean needDisplaySuspendBlocker() {
+ if (!mDisplayReady) {
+ return true;
+ }
+ if (mDisplayPowerRequest.screenState != DisplayPowerRequest.SCREEN_STATE_OFF) {
+ // If we asked for the screen to be on but it is off due to the proximity
+ // sensor then we may suspend but only if the configuration allows it.
+ // On some hardware it may not be safe to suspend because the proximity
+ // sensor may not be correctly configured as a wake-up source.
+ if (!mDisplayPowerRequest.useProximitySensor || !mProximityPositive
+ || !mSuspendWhenScreenOffDueToProximityConfig) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@Override // Binder call
public boolean isScreenOn() {
final long ident = Binder.clearCallingIdentity();
@@ -2115,7 +2146,7 @@ public final class PowerManagerService extends IPowerManager.Stub
*
* @param brightness The overridden brightness.
*
- * @see Settings.System#SCREEN_BRIGHTNESS
+ * @see android.provider.Settings.System#SCREEN_BRIGHTNESS
*/
@Override // Binder call
public void setTemporaryScreenBrightnessSettingOverride(int brightness) {
@@ -2255,7 +2286,16 @@ public final class PowerManagerService extends IPowerManager.Stub
pw.println();
pw.println("Settings and Configuration:");
+ pw.println(" mWakeUpWhenPluggedOrUnpluggedConfig="
+ + mWakeUpWhenPluggedOrUnpluggedConfig);
+ pw.println(" mSuspendWhenScreenOffDueToProximityConfig="
+ + mSuspendWhenScreenOffDueToProximityConfig);
pw.println(" mDreamsSupportedConfig=" + mDreamsSupportedConfig);
+ pw.println(" mDreamsEnabledByDefaultConfig=" + mDreamsEnabledByDefaultConfig);
+ pw.println(" mDreamsActivatedOnSleepByDefaultConfig="
+ + mDreamsActivatedOnSleepByDefaultConfig);
+ pw.println(" mDreamsActivatedOnDockByDefaultConfig="
+ + mDreamsActivatedOnDockByDefaultConfig);
pw.println(" mDreamsEnabledSetting=" + mDreamsEnabledSetting);
pw.println(" mDreamsActivateOnSleepSetting=" + mDreamsActivateOnSleepSetting);
pw.println(" mDreamsActivateOnDockSetting=" + mDreamsActivateOnDockSetting);
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index ea7904c..f79a4a6 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -115,6 +115,7 @@ class WifiConfigStore {
private Context mContext;
private static final String TAG = "WifiConfigStore";
private static final boolean DBG = true;
+ private static final boolean VDBG = false;
private static final String SUPPLICANT_CONFIG_FILE = "/data/misc/wifi/wpa_supplicant.conf";
@@ -154,7 +155,7 @@ class WifiConfigStore {
private static final String EOS = "eos";
private final LocalLog mLocalLog;
- WpaConfigFileObserver mFileObserver;
+ private final WpaConfigFileObserver mFileObserver;
private WifiNative mWifiNative;
private final KeyStore mKeyStore = KeyStore.getInstance();
@@ -163,10 +164,13 @@ class WifiConfigStore {
mContext = c;
mWifiNative = wn;
- if (DBG) {
+ if (VDBG) {
mLocalLog = mWifiNative.getLocalLog();
mFileObserver = new WpaConfigFileObserver();
mFileObserver.startWatching();
+ } else {
+ mLocalLog = null;
+ mFileObserver = null;
}
}
@@ -180,7 +184,7 @@ class WifiConfigStore {
public void onEvent(int event, String path) {
if (event == CLOSE_WRITE) {
File file = new File(SUPPLICANT_CONFIG_FILE);
- localLog("wpa_supplicant.conf changed; new size = " + file.length());
+ if (VDBG) localLog("wpa_supplicant.conf changed; new size = " + file.length());
}
}
}
@@ -245,7 +249,7 @@ class WifiConfigStore {
* @return false if the network id is invalid
*/
boolean selectNetwork(int netId) {
- localLog("selectNetwork", netId);
+ if (VDBG) localLog("selectNetwork", netId);
if (netId == INVALID_NETWORK_ID) return false;
// Reset the priority of each network at start or if it goes too high.
@@ -282,7 +286,7 @@ class WifiConfigStore {
* @return network update result
*/
NetworkUpdateResult saveNetwork(WifiConfiguration config) {
- localLog("saveNetwork", config.networkId);
+ if (VDBG) localLog("saveNetwork", config.networkId);
// A new network cannot have null SSID
if (config == null || (config.networkId == INVALID_NETWORK_ID &&
config.SSID == null)) {
@@ -331,7 +335,7 @@ class WifiConfigStore {
* @return {@code true} if it succeeds, {@code false} otherwise
*/
boolean forgetNetwork(int netId) {
- localLog("forgetNetwork", netId);
+ if (VDBG) localLog("forgetNetwork", netId);
if (mWifiNative.removeNetwork(netId)) {
mWifiNative.saveConfig();
removeConfigAndSendBroadcastIfNeeded(netId);
@@ -352,7 +356,7 @@ class WifiConfigStore {
* @return network Id
*/
int addOrUpdateNetwork(WifiConfiguration config) {
- localLog("addOrUpdateNetwork", config.networkId);
+ if (VDBG) localLog("addOrUpdateNetwork", config.networkId);
NetworkUpdateResult result = addOrUpdateNetworkNative(config);
if (result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID) {
sendConfiguredNetworksChangedBroadcast(mConfiguredNetworks.get(result.getNetworkId()),
@@ -372,7 +376,7 @@ class WifiConfigStore {
* @return {@code true} if it succeeds, {@code false} otherwise
*/
boolean removeNetwork(int netId) {
- localLog("removeNetwork", netId);
+ if (VDBG) localLog("removeNetwork", netId);
boolean ret = mWifiNative.removeNetwork(netId);
if (ret) {
removeConfigAndSendBroadcastIfNeeded(netId);
@@ -407,10 +411,10 @@ class WifiConfigStore {
boolean enableNetwork(int netId, boolean disableOthers) {
boolean ret = enableNetworkWithoutBroadcast(netId, disableOthers);
if (disableOthers) {
- localLog("enableNetwork(disableOthers=true) ", netId);
+ if (VDBG) localLog("enableNetwork(disableOthers=true) ", netId);
sendConfiguredNetworksChangedBroadcast();
} else {
- localLog("enableNetwork(disableOthers=false) ", netId);
+ if (VDBG) localLog("enableNetwork(disableOthers=false) ", netId);
WifiConfiguration enabledNetwork = null;
synchronized(mConfiguredNetworks) {
enabledNetwork = mConfiguredNetworks.get(netId);
@@ -437,7 +441,7 @@ class WifiConfigStore {
}
void disableAllNetworks() {
- localLog("disableAllNetworks");
+ if (VDBG) localLog("disableAllNetworks");
boolean networkDisabled = false;
for(WifiConfiguration config : mConfiguredNetworks.values()) {
if(config != null && config.status != Status.DISABLED) {
@@ -470,7 +474,7 @@ class WifiConfigStore {
* @return {@code true} if it succeeds, {@code false} otherwise
*/
boolean disableNetwork(int netId, int reason) {
- localLog("disableNetwork", netId);
+ if (VDBG) localLog("disableNetwork", netId);
boolean ret = mWifiNative.disableNetwork(netId);
WifiConfiguration network = null;
WifiConfiguration config = mConfiguredNetworks.get(netId);
@@ -683,33 +687,33 @@ class WifiConfigStore {
if (mNetworkIds.containsKey(configKey(config))) {
// That SSID is already known, just ignore this duplicate entry
- localLog("discarded duplicate network", config.networkId);
+ if (VDBG) localLog("discarded duplicate network", config.networkId);
} else {
mConfiguredNetworks.put(config.networkId, config);
mNetworkIds.put(configKey(config), config.networkId);
- localLog("loaded configured network", config.networkId);
+ if (VDBG) localLog("loaded configured network", config.networkId);
}
}
readIpAndProxyConfigurations();
sendConfiguredNetworksChangedBroadcast();
- localLog("loadConfiguredNetworks loaded " + mNetworkIds.size() + " networks");
+ if (VDBG) localLog("loadConfiguredNetworks loaded " + mNetworkIds.size() + " networks");
if (mNetworkIds.size() == 0) {
// no networks? Lets log if the wpa_supplicant.conf file contents
BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(SUPPLICANT_CONFIG_FILE));
- localLog("--- Begin wpa_supplicant.conf Contents ---");
+ if (VDBG) localLog("--- Begin wpa_supplicant.conf Contents ---");
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
- localLog(line);
+ if (VDBG) localLog(line);
}
- localLog("--- End wpa_supplicant.conf Contents ---");
+ if (VDBG) localLog("--- End wpa_supplicant.conf Contents ---");
} catch (FileNotFoundException e) {
- localLog("Could not open " + SUPPLICANT_CONFIG_FILE + ", " + e);
+ if (VDBG) localLog("Could not open " + SUPPLICANT_CONFIG_FILE + ", " + e);
} catch (IOException e) {
- localLog("Could not read " + SUPPLICANT_CONFIG_FILE + ", " + e);
+ if (VDBG) localLog("Could not read " + SUPPLICANT_CONFIG_FILE + ", " + e);
} finally {
try {
if (reader != null) {
@@ -1050,7 +1054,7 @@ class WifiConfigStore {
* refer to an existing configuration.
*/
- localLog("addOrUpdateNetworkNative " + config.getPrintableSsid());
+ if (VDBG) localLog("addOrUpdateNetworkNative " + config.getPrintableSsid());
int netId = config.networkId;
boolean newNetwork = false;
diff --git a/wifi/java/android/net/wifi/WifiNative.java b/wifi/java/android/net/wifi/WifiNative.java
index 3deac1b..2ce44a4 100644
--- a/wifi/java/android/net/wifi/WifiNative.java
+++ b/wifi/java/android/net/wifi/WifiNative.java
@@ -117,12 +117,12 @@ public class WifiNative {
public boolean connectToSupplicant() {
// No synchronization necessary .. it is implemented in WifiMonitor
- localLog(mInterfacePrefix + "connectToSupplicant");
+ if (VDBG) localLog(mInterfacePrefix + "connectToSupplicant");
return connectToSupplicantNative();
}
public void closeSupplicantConnection() {
- localLog(mInterfacePrefix + "closeSupplicantConnection");
+ if (VDBG) localLog(mInterfacePrefix + "closeSupplicantConnection");
closeSupplicantConnectionNative();
}
@@ -135,9 +135,9 @@ public class WifiNative {
if (DBG) Log.d(mTAG, "doBoolean: " + command);
synchronized (mLock) {
int cmdId = getNewCmdIdLocked();
- localLog(cmdId + "->" + mInterfacePrefix + command);
+ if (VDBG) localLog(cmdId + "->" + mInterfacePrefix + command);
boolean result = doBooleanCommandNative(mInterfacePrefix + command);
- localLog(cmdId + "<-" + result);
+ if (VDBG) localLog(cmdId + "<-" + result);
if (DBG) Log.d(mTAG, " returned " + result);
return result;
}
@@ -147,9 +147,9 @@ public class WifiNative {
if (DBG) Log.d(mTAG, "doInt: " + command);
synchronized (mLock) {
int cmdId = getNewCmdIdLocked();
- localLog(cmdId + "->" + mInterfacePrefix + command);
+ if (VDBG) localLog(cmdId + "->" + mInterfacePrefix + command);
int result = doIntCommandNative(mInterfacePrefix + command);
- localLog(cmdId + "<-" + result);
+ if (VDBG) localLog(cmdId + "<-" + result);
if (DBG) Log.d(mTAG, " returned " + result);
return result;
}
@@ -159,9 +159,9 @@ public class WifiNative {
if (DBG) Log.d(mTAG, "doString: " + command);
synchronized (mLock) {
int cmdId = getNewCmdIdLocked();
- localLog(cmdId + "->" + mInterfacePrefix + command);
+ if (VDBG) localLog(cmdId + "->" + mInterfacePrefix + command);
String result = doStringCommandNative(mInterfacePrefix + command);
- localLog(cmdId + "<-" + result);
+ if (VDBG) localLog(cmdId + "<-" + result);
if (DBG) Log.d(mTAG, " returned " + result);
return result;
}