diff options
7 files changed, 88 insertions, 63 deletions
diff --git a/core/java/android/service/dreams/DreamService.java b/core/java/android/service/dreams/DreamService.java index 92647f0..38b0439 100644 --- a/core/java/android/service/dreams/DreamService.java +++ b/core/java/android/service/dreams/DreamService.java @@ -967,6 +967,9 @@ public class DreamService extends Service implements Window.Callback { | (mScreenBright ? WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON : 0) ); mWindow.setAttributes(lp); + // Workaround: Currently low-profile and in-window system bar backgrounds don't go + // along well. Dreams usually don't need such bars anyways, so disable them by default. + mWindow.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); mWindow.setWindowManager(null, windowToken, "dream", true); applySystemUiVisibilityFlags( diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 13170ad..08bda1f 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -81,6 +81,13 @@ <!-- Show camera affordance on Keyguard --> <bool name="config_keyguardShowCameraAffordance">true</bool> + <!-- Whether we should use SRC drawing mode when drawing the scrim behind. If this flag is set, + we change the canvas opacity so libhwui doesn't call glClear on our surface, and then we + draw the scrim with SRC to overwrite the whole buffer, which saves us a layer of overdraw. + However, SRC performs poorly on some devices, where it is more efficient to + glClear + SRC_OVER, in which case this flag should be disabled. --> + <bool name="config_status_bar_scrim_behind_use_src">true</bool> + <!-- The length of the vibration when the notification pops open. --> <integer name="one_finger_pop_duration_ms">10</integer> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java index 2353425..682676b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java @@ -33,7 +33,7 @@ import android.view.animation.Interpolator; public class ScrimView extends View { private int mScrimColor; - private boolean mIsEmpty; + private boolean mIsEmpty = true; private boolean mDrawAsSrc; private float mViewAlpha = 1.0f; private ValueAnimator mAlphaAnimator; @@ -70,7 +70,7 @@ public class ScrimView extends View @Override protected void onDraw(Canvas canvas) { - if (mDrawAsSrc || !mIsEmpty) { + if (mDrawAsSrc || (!mIsEmpty && mViewAlpha > 0f)) { PorterDuff.Mode mode = mDrawAsSrc ? PorterDuff.Mode.SRC : PorterDuff.Mode.SRC_OVER; int color = mScrimColor; color = Color.argb((int) (Color.alpha(color) * mViewAlpha), Color.red(color), 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 71fef65..0651708 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -430,6 +430,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, private boolean mVisible; private boolean mWaitingForKeyguardExit; private boolean mDozing; + private boolean mScrimSrcModeEnabled; private Interpolator mLinearOutSlowIn; private Interpolator mLinearInterpolator = new LinearInterpolator(); @@ -569,6 +570,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, mDisplay = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay(); updateDisplaySize(); + mScrimSrcModeEnabled = mContext.getResources().getBoolean( + R.bool.config_status_bar_scrim_behind_use_src); super.start(); // calls createAndAddWindows() mMediaSessionManager @@ -737,7 +740,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, ScrimView scrimBehind = (ScrimView) mStatusBarWindow.findViewById(R.id.scrim_behind); ScrimView scrimInFront = (ScrimView) mStatusBarWindow.findViewById(R.id.scrim_in_front); - mScrimController = new ScrimController(scrimBehind, scrimInFront); + mScrimController = new ScrimController(scrimBehind, scrimInFront, mScrimSrcModeEnabled); mScrimController.setBackDropView(mBackdrop); mStatusBarView.setScrimController(mScrimController); @@ -1870,7 +1873,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (mBackdropBack.getDrawable() != null) { Drawable drawable = mBackdropBack.getDrawable(); mBackdropFront.setImageDrawable(drawable); - mBackdropFront.getDrawable().mutate().setXfermode(mSrcOverXferMode); + if (mScrimSrcModeEnabled) { + mBackdropFront.getDrawable().mutate().setXfermode(mSrcOverXferMode); + } mBackdropFront.setAlpha(1f); mBackdropFront.setVisibility(View.VISIBLE); } else { @@ -1885,7 +1890,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } else { mBackdropBack.setImageBitmap(artworkBitmap); } - mBackdropBack.getDrawable().mutate().setXfermode(mSrcXferMode); + if (mScrimSrcModeEnabled) { + mBackdropBack.getDrawable().mutate().setXfermode(mSrcXferMode); + } if (mBackdropFront.getVisibility() == View.VISIBLE) { if (DEBUG_MEDIA) { @@ -2134,6 +2141,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, return mMediaNotificationKey; } + public boolean isScrimSrcModeEnabled() { + return mScrimSrcModeEnabled; + } + /** * All changes to the status bar and notifications funnel through here and are batched. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java index 5353f25..6793f69 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java @@ -74,8 +74,9 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener { private final Interpolator mInterpolator = new DecelerateInterpolator(); private final Interpolator mLinearOutSlowInInterpolator; private BackDropView mBackDropView; + private boolean mScrimSrcEnabled; - public ScrimController(ScrimView scrimBehind, ScrimView scrimInFront) { + public ScrimController(ScrimView scrimBehind, ScrimView scrimInFront, boolean scrimSrcEnabled) { mScrimBehind = scrimBehind; mScrimInFront = scrimInFront; final Context context = scrimBehind.getContext(); @@ -83,6 +84,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener { mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in); mDozeParameters = new DozeParameters(context); + mScrimSrcEnabled = scrimSrcEnabled; } public void setKeyguardShowing(boolean showing) { @@ -384,7 +386,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener { } private void updateScrimBehindDrawingMode() { - boolean asSrc = mBackDropView.getVisibility() != View.VISIBLE; + boolean asSrc = mBackDropView.getVisibility() != View.VISIBLE && mScrimSrcEnabled; mScrimBehind.setDrawAsSrc(asSrc); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java index 4c86990..242f1b7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarWindowView.java @@ -55,7 +55,6 @@ public class StatusBarWindowView extends FrameLayout { public StatusBarWindowView(Context context, AttributeSet attrs) { super(context, attrs); setMotionEventSplittingEnabled(false); - setWillNotDraw(false); mTransparentSrcPaint.setColor(0); mTransparentSrcPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC)); } @@ -105,11 +104,16 @@ public class StatusBarWindowView extends FrameLayout { // We need to ensure that our window doesn't suffer from overdraw which would normally // occur if our window is translucent. Since we are drawing the whole window anyway with // the scrim, we don't need the window to be cleared in the beginning. - IBinder windowToken = getWindowToken(); - WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams(); - lp.token = windowToken; - setLayoutParams(lp); - WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true); + if (mService.isScrimSrcModeEnabled()) { + IBinder windowToken = getWindowToken(); + WindowManager.LayoutParams lp = (WindowManager.LayoutParams) getLayoutParams(); + lp.token = windowToken; + setLayoutParams(lp); + WindowManagerGlobal.getInstance().changeCanvasOpacity(windowToken, true); + setWillNotDraw(false); + } else { + setWillNotDraw(!DEBUG); + } } @Override @@ -199,23 +203,25 @@ public class StatusBarWindowView extends FrameLayout { @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); - // We need to ensure that our window is always drawn fully even when we have paddings, - // since we simulate it to be opaque. - int paddedBottom = getHeight() - getPaddingBottom(); - int paddedRight = getWidth() - getPaddingRight(); - if (getPaddingTop() != 0) { - canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint); - } - if (getPaddingBottom() != 0) { - canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint); - } - if (getPaddingLeft() != 0) { - canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom, - mTransparentSrcPaint); - } - if (getPaddingRight() != 0) { - canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom, - mTransparentSrcPaint); + if (mService.isScrimSrcModeEnabled()) { + // We need to ensure that our window is always drawn fully even when we have paddings, + // since we simulate it to be opaque. + int paddedBottom = getHeight() - getPaddingBottom(); + int paddedRight = getWidth() - getPaddingRight(); + if (getPaddingTop() != 0) { + canvas.drawRect(0, 0, getWidth(), getPaddingTop(), mTransparentSrcPaint); + } + if (getPaddingBottom() != 0) { + canvas.drawRect(0, paddedBottom, getWidth(), getHeight(), mTransparentSrcPaint); + } + if (getPaddingLeft() != 0) { + canvas.drawRect(0, getPaddingTop(), getPaddingLeft(), paddedBottom, + mTransparentSrcPaint); + } + if (getPaddingRight() != 0) { + canvas.drawRect(paddedRight, getPaddingTop(), getWidth(), paddedBottom, + mTransparentSrcPaint); + } } if (DEBUG) { Paint pt = new Paint(); diff --git a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java index 6e2a8ad..11d00cf 100644 --- a/services/core/java/com/android/server/notification/ValidateNotificationPeople.java +++ b/services/core/java/com/android/server/notification/ValidateNotificationPeople.java @@ -231,7 +231,7 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { if (lookupResult == null || lookupResult.isExpired()) { pendingLookups.add(handle); } else { - if (DEBUG) Slog.d(TAG, "using cached lookupResult: " + lookupResult.mId); + if (DEBUG) Slog.d(TAG, "using cached lookupResult"); } if (lookupResult != null) { affinity = Math.max(affinity, lookupResult.getAffinity()); @@ -336,11 +336,14 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { Cursor c = null; try { c = context.getContentResolver().query(lookupUri, LOOKUP_PROJECTION, null, null, null); - if (c != null && c.getCount() > 0) { - c.moveToFirst(); - lookupResult.readContact(c); + if (c == null) { + Slog.w(TAG, "Null cursor from contacts query."); + return lookupResult; } - } catch(Throwable t) { + while (c.moveToNext()) { + lookupResult.mergeContact(c); + } + } catch (Throwable t) { Slog.w(TAG, "Problem getting content resolver or performing contacts query.", t); } finally { if (c != null) { @@ -352,61 +355,54 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor { private static class LookupResult { private static final long CONTACT_REFRESH_MILLIS = 60 * 60 * 1000; // 1hr - public static final int INVALID_ID = -1; private final long mExpireMillis; - private int mId; - private boolean mStarred; + private float mAffinity = NONE; public LookupResult() { - mId = INVALID_ID; - mStarred = false; mExpireMillis = System.currentTimeMillis() + CONTACT_REFRESH_MILLIS; } - public void readContact(Cursor cursor) { + public void mergeContact(Cursor cursor) { + mAffinity = Math.max(mAffinity, VALID_CONTACT); + + // Contact ID + int id; final int idIdx = cursor.getColumnIndex(Contacts._ID); if (idIdx >= 0) { - mId = cursor.getInt(idIdx); - if (DEBUG) Slog.d(TAG, "contact _ID is: " + mId); + id = cursor.getInt(idIdx); + if (DEBUG) Slog.d(TAG, "contact _ID is: " + id); } else { - if (DEBUG) Slog.d(TAG, "invalid cursor: no _ID"); + id = -1; + Slog.i(TAG, "invalid cursor: no _ID"); } + + // Starred final int starIdx = cursor.getColumnIndex(Contacts.STARRED); if (starIdx >= 0) { - mStarred = cursor.getInt(starIdx) != 0; - if (DEBUG) Slog.d(TAG, "contact STARRED is: " + mStarred); + boolean isStarred = cursor.getInt(starIdx) != 0; + if (isStarred) { + mAffinity = Math.max(mAffinity, STARRED_CONTACT); + } + if (DEBUG) Slog.d(TAG, "contact STARRED is: " + isStarred); } else { if (DEBUG) Slog.d(TAG, "invalid cursor: no STARRED"); } } - public boolean isExpired() { + private boolean isExpired() { return mExpireMillis < System.currentTimeMillis(); } - public boolean isInvalid() { - return mId == INVALID_ID || isExpired(); + private boolean isInvalid() { + return mAffinity == NONE || isExpired(); } public float getAffinity() { if (isInvalid()) { return NONE; - } else if (mStarred) { - return STARRED_CONTACT; - } else { - return VALID_CONTACT; } - } - - public LookupResult setStarred(boolean starred) { - mStarred = starred; - return this; - } - - public LookupResult setId(int id) { - mId = id; - return this; + return mAffinity; } } |