Skip to content

Commit

Permalink
Snap for 6377241 from 27393d9 to qt-qpr3-release
Browse files Browse the repository at this point in the history
Change-Id: If021581c4b6d36e5e53c6f114f1b499c143921bc
  • Loading branch information
android-build-team Robot committed Apr 8, 2020
2 parents fb54ea7 + 27393d9 commit 81ee102
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
57 changes: 43 additions & 14 deletions packages/SystemUI/src/com/android/systemui/ImageWallpaper.java
Expand Up @@ -18,12 +18,14 @@

import android.app.ActivityManager;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.HandlerThread;
import android.os.Trace;
import android.service.wallpaper.WallpaperService;
import android.util.Log;
import android.util.Size;
import android.view.DisplayInfo;
import android.view.SurfaceHolder;

import com.android.internal.annotations.VisibleForTesting;
Expand Down Expand Up @@ -84,27 +86,34 @@ class GLEngine extends Engine implements GLWallpaperRenderer.SurfaceProxy, State
private StatusBarStateController mController;
private final Runnable mFinishRenderingTask = this::finishRendering;
private final boolean mNeedTransition;
private boolean mShouldStopTransition;
private final boolean mIsHighEndGfx;
private final boolean mDisplayNeedsBlanking;
private final DisplayInfo mDisplayInfo = new DisplayInfo();
private final Object mMonitor = new Object();
private boolean mNeedRedraw;
// This variable can only be accessed in synchronized block.
private boolean mWaitingForRendering;

GLEngine(Context context) {
mNeedTransition = ActivityManager.isHighEndGfx()
&& !DozeParameters.getInstance(context).getDisplayNeedsBlanking();
mIsHighEndGfx = ActivityManager.isHighEndGfx();
mDisplayNeedsBlanking = DozeParameters.getInstance(context).getDisplayNeedsBlanking();
mNeedTransition = mIsHighEndGfx && !mDisplayNeedsBlanking;

// We will preserve EGL context when we are in lock screen or aod
// to avoid janking in following transition, we need to release when back to home.
mController = Dependency.get(StatusBarStateController.class);
if (mController != null) {
mController.addCallback(this /* StateListener */);
}
mEglHelper = new EglHelper();
mRenderer = new ImageWallpaperRenderer(context, this /* SurfaceProxy */);
}

@Override
public void onCreate(SurfaceHolder surfaceHolder) {
mEglHelper = new EglHelper();
// Deferred init renderer because we need to get wallpaper by display context.
mRenderer = new ImageWallpaperRenderer(getDisplayContext(), this /* SurfaceProxy */);
getDisplayContext().getDisplay().getDisplayInfo(mDisplayInfo);
setFixedSizeAllowed(true);
setOffsetNotificationsEnabled(true);
updateSurfaceSize();
Expand All @@ -118,6 +127,26 @@ private void updateSurfaceSize() {
holder.setFixedSize(width, height);
}

/**
* Check if necessary to stop transition with current wallpaper on this device. <br/>
* This should only be invoked after {@link #onSurfaceCreated(SurfaceHolder)}}
* is invoked since it needs display context and surface frame size.
*
* @return true if need to stop transition
*/
@VisibleForTesting
boolean checkIfShouldStopTransition() {
int orientation = getDisplayContext().getResources().getConfiguration().orientation;
boolean portrait = orientation == Configuration.ORIENTATION_PORTRAIT;
Rect frame = getSurfaceHolder().getSurfaceFrame();
int frameWidth = frame.width();
int frameHeight = frame.height();
int displayWidth = portrait ? mDisplayInfo.logicalWidth : mDisplayInfo.logicalHeight;
int displayHeight = portrait ? mDisplayInfo.logicalHeight : mDisplayInfo.logicalWidth;
return mNeedTransition
&& (frameWidth < displayWidth || frameHeight < displayHeight);
}

@Override
public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep,
float yOffsetStep, int xPixelOffset, int yPixelOffset) {
Expand All @@ -128,12 +157,14 @@ public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep,
@Override
public void onAmbientModeChanged(boolean inAmbientMode, long animationDuration) {
if (mWorker == null || !mNeedTransition) return;
final long duration = mShouldStopTransition ? 0 : animationDuration;
if (DEBUG) {
Log.d(TAG, "onAmbientModeChanged: inAmbient=" + inAmbientMode
+ ", duration=" + animationDuration);
+ ", duration=" + duration
+ ", mShouldStopTransition=" + mShouldStopTransition);
}
mWorker.getThreadHandler().post(
() -> mRenderer.updateAmbientMode(inAmbientMode, animationDuration));
() -> mRenderer.updateAmbientMode(inAmbientMode, duration));
if (inAmbientMode && animationDuration == 0) {
// This means that we are transiting from home to aod, to avoid
// race condition between window visibility and transition,
Expand Down Expand Up @@ -169,13 +200,13 @@ public void onDestroy() {
mRenderer = null;
mEglHelper.finish();
mEglHelper = null;
getSurfaceHolder().getSurface().hwuiDestroy();
});
}

@Override
public void onSurfaceCreated(SurfaceHolder holder) {
if (mWorker == null) return;
mShouldStopTransition = checkIfShouldStopTransition();
mWorker.getThreadHandler().post(() -> {
mEglHelper.init(holder);
mRenderer.onSurfaceCreated();
Expand Down Expand Up @@ -365,15 +396,13 @@ private boolean needPreserveEglContext() {
protected void dump(String prefix, FileDescriptor fd, PrintWriter out, String[] args) {
super.dump(prefix, fd, out, args);
out.print(prefix); out.print("Engine="); out.println(this);

boolean isHighEndGfx = ActivityManager.isHighEndGfx();
out.print(prefix); out.print("isHighEndGfx="); out.println(isHighEndGfx);

DozeParameters dozeParameters = DozeParameters.getInstance(getApplicationContext());
out.print(prefix); out.print("isHighEndGfx="); out.println(mIsHighEndGfx);
out.print(prefix); out.print("displayNeedsBlanking=");
out.println(dozeParameters != null ? dozeParameters.getDisplayNeedsBlanking() : "null");

out.println(mDisplayNeedsBlanking);
out.print(prefix); out.print("displayInfo="); out.print(mDisplayInfo);
out.print(prefix); out.print("mNeedTransition="); out.println(mNeedTransition);
out.print(prefix); out.print("mShouldStopTransition=");
out.println(mShouldStopTransition);
out.print(prefix); out.print("StatusBarState=");
out.println(mController != null ? mController.getState() : "null");

Expand Down
Expand Up @@ -31,7 +31,6 @@
import android.util.MathUtils;
import android.util.Size;
import android.view.DisplayInfo;
import android.view.WindowManager;

import com.android.systemui.R;

Expand Down Expand Up @@ -70,8 +69,7 @@ public ImageWallpaperRenderer(Context context, SurfaceProxy proxy) {
}

DisplayInfo displayInfo = new DisplayInfo();
WindowManager wm = context.getSystemService(WindowManager.class);
wm.getDefaultDisplay().getDisplayInfo(displayInfo);
context.getDisplay().getDisplayInfo(displayInfo);

// We only do transition in portrait currently, b/137962047.
int orientation = context.getResources().getConfiguration().orientation;
Expand Down Expand Up @@ -115,12 +113,7 @@ private boolean loadBitmap() {
mBitmap = mWallpaperManager.getBitmap();
mWallpaperManager.forgetLoadedWallpaper();
if (mBitmap != null) {
float scale = (float) mScissor.height() / mBitmap.getHeight();
int surfaceHeight = Math.max(mScissor.height(), mBitmap.getHeight());
int surfaceWidth = scale > 1f
? Math.round(mBitmap.getWidth() * scale)
: mBitmap.getWidth();
mSurfaceSize.set(0, 0, surfaceWidth, surfaceHeight);
mSurfaceSize.set(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
}
}
if (DEBUG) {
Expand Down
Expand Up @@ -319,7 +319,8 @@ public boolean onCreateSliceProvider() {
mZenModeController = new ZenModeControllerImpl(getContext(), mHandler);
mZenModeController.addCallback(this);
mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern);
mPendingIntent = PendingIntent.getActivity(getContext(), 0, new Intent(), 0);
mPendingIntent = PendingIntent.getActivity(getContext(), 0,
new Intent(getContext(), KeyguardSliceProvider.class), 0);
mMediaWakeLock = new SettableWakeLock(WakeLock.createPartial(getContext(), "media"),
"media");
KeyguardSliceProvider.sInstance = this;
Expand Down
2 changes: 1 addition & 1 deletion telephony/java/android/telephony/LocationAccessPolicy.java
Expand Up @@ -286,7 +286,7 @@ private static boolean checkSystemLocationAccess(@NonNull Context context, int u
}
// If the user or profile is current, permission is granted.
// Otherwise, uid must have INTERACT_ACROSS_USERS_FULL permission.
return isCurrentProfile(context, uid) || checkInteractAcrossUsersFull(context, uid, pid);
return isCurrentProfile(context, uid) || checkInteractAcrossUsersFull(context, pid, uid);
}

private static boolean isLocationModeEnabled(@NonNull Context context, @UserIdInt int userId) {
Expand Down

0 comments on commit 81ee102

Please sign in to comment.