Merge "Add traces to WallpaperManagerService and WallpaperService." into tm-qpr-dev am: e9bad1ca98 am: 454de9ddfc

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20426606

Change-Id: Ia0f04ab5a1b1d1645178eb75eb6801ac861324fc
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yasin Kilicdere
2022-11-10 18:54:50 +00:00
committed by Automerger Merge Worker
2 changed files with 73 additions and 12 deletions

View File

@@ -575,6 +575,7 @@ public abstract class WallpaperService extends Service {
*/
public void reportEngineShown(boolean waitForEngineShown) {
if (mIWallpaperEngine.mShownReported) return;
Trace.beginSection("WPMS.reportEngineShown-" + waitForEngineShown);
Log.d(TAG, "reportEngineShown: shouldWait=" + waitForEngineShown);
if (!waitForEngineShown) {
Message message = mCaller.obtainMessage(MSG_REPORT_SHOWN);
@@ -587,6 +588,7 @@ public abstract class WallpaperService extends Service {
mCaller.sendMessageDelayed(message, TimeUnit.SECONDS.toMillis(5));
}
}
Trace.endSection();
}
/**
@@ -1259,7 +1261,9 @@ public abstract class WallpaperService extends Service {
didSurface = true;
if (DEBUG) Log.v(TAG, "onSurfaceCreated("
+ mSurfaceHolder + "): " + this);
Trace.beginSection("WPMS.Engine.onSurfaceCreated");
onSurfaceCreated(mSurfaceHolder);
Trace.endSection();
SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
if (callbacks != null) {
for (SurfaceHolder.Callback c : callbacks) {
@@ -1285,8 +1289,10 @@ public abstract class WallpaperService extends Service {
+ ", " + mCurWidth + ", " + mCurHeight
+ "): " + this);
didSurface = true;
Trace.beginSection("WPMS.Engine.onSurfaceChanged");
onSurfaceChanged(mSurfaceHolder, mFormat,
mCurWidth, mCurHeight);
Trace.endSection();
SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
if (callbacks != null) {
for (SurfaceHolder.Callback c : callbacks) {
@@ -1303,11 +1309,15 @@ public abstract class WallpaperService extends Service {
if (DEBUG) {
Log.v(TAG, "dispatching insets=" + windowInsets);
}
Trace.beginSection("WPMS.Engine.onApplyWindowInsets");
onApplyWindowInsets(windowInsets);
Trace.endSection();
}
if (redrawNeeded) {
Trace.beginSection("WPMS.Engine.onSurfaceRedrawNeeded");
onSurfaceRedrawNeeded(mSurfaceHolder);
Trace.endSection();
SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
if (callbacks != null) {
for (SurfaceHolder.Callback c : callbacks) {
@@ -1332,11 +1342,15 @@ public abstract class WallpaperService extends Service {
// the state to get them to notice.
if (DEBUG) Log.v(TAG, "onVisibilityChanged(true) at surface: "
+ this);
Trace.beginSection("WPMS.Engine.onVisibilityChanged-true");
onVisibilityChanged(true);
Trace.endSection();
}
if (DEBUG) Log.v(TAG, "onVisibilityChanged(false) at surface: "
+ this);
Trace.beginSection("WPMS.Engine.onVisibilityChanged-false");
onVisibilityChanged(false);
Trace.endSection();
}
} finally {
mIsCreating = false;
@@ -1421,12 +1435,16 @@ public abstract class WallpaperService extends Service {
mDisplayState = mDisplay.getState();
if (DEBUG) Log.v(TAG, "onCreate(): " + this);
Trace.beginSection("WPMS.Engine.onCreate");
onCreate(mSurfaceHolder);
Trace.endSection();
mInitializing = false;
mReportedVisible = false;
Trace.beginSection("WPMS.Engine.updateSurface");
updateSurface(false, false, false);
Trace.endSection();
}
/**
@@ -2236,14 +2254,15 @@ public abstract class WallpaperService extends Service {
public void reportShown() {
if (!mShownReported) {
mShownReported = true;
Trace.beginSection("WPMS.mConnection.engineShown");
try {
mConnection.engineShown(this);
Log.d(TAG, "Wallpaper has updated the surface:"
+ mWallpaperManager.getWallpaperInfo());
} catch (RemoteException e) {
Log.w(TAG, "Wallpaper host disappeared", e);
return;
}
Trace.endSection();
}
}
@@ -2285,6 +2304,27 @@ public abstract class WallpaperService extends Service {
return mEngine == null ? null : SurfaceControl.mirrorSurface(mEngine.mSurfaceControl);
}
private void doAttachEngine() {
Trace.beginSection("WPMS.onCreateEngine");
Engine engine = onCreateEngine();
Trace.endSection();
mEngine = engine;
Trace.beginSection("WPMS.mConnection.attachEngine-" + mDisplayId);
try {
mConnection.attachEngine(this, mDisplayId);
} catch (RemoteException e) {
engine.detach();
Log.w(TAG, "Wallpaper host disappeared", e);
return;
} finally {
Trace.endSection();
}
mActiveEngines.add(engine);
Trace.beginSection("WPMS.engine.attach");
engine.attach(this);
Trace.endSection();
}
private void doDetachEngine() {
mActiveEngines.remove(mEngine);
mEngine.detach();
@@ -2310,21 +2350,15 @@ public abstract class WallpaperService extends Service {
}
switch (message.what) {
case DO_ATTACH: {
Engine engine = onCreateEngine();
mEngine = engine;
try {
mConnection.attachEngine(this, mDisplayId);
} catch (RemoteException e) {
engine.detach();
Log.w(TAG, "Wallpaper host disappeared", e);
return;
}
mActiveEngines.add(engine);
engine.attach(this);
Trace.beginSection("WPMS.DO_ATTACH");
doAttachEngine();
Trace.endSection();
return;
}
case DO_DETACH: {
Trace.beginSection("WPMS.DO_DETACH");
doDetachEngine();
Trace.endSection();
return;
}
case DO_SET_DESIRED_SIZE: {
@@ -2405,7 +2439,9 @@ public abstract class WallpaperService extends Service {
}
} break;
case MSG_REPORT_SHOWN: {
Trace.beginSection("WPMS.MSG_REPORT_SHOWN");
reportShown();
Trace.endSection();
} break;
default :
Log.w(TAG, "Unknown message type " + message.what);
@@ -2429,8 +2465,10 @@ public abstract class WallpaperService extends Service {
public void attach(IWallpaperConnection conn, IBinder windowToken,
int windowType, boolean isPreview, int reqWidth, int reqHeight, Rect padding,
int displayId, @SetWallpaperFlags int which) {
Trace.beginSection("WPMS.ServiceWrapper.attach");
mEngineWrapper = new IWallpaperEngineWrapper(mTarget, conn, windowToken,
windowType, isPreview, reqWidth, reqHeight, padding, displayId);
Trace.endSection();
}
@Override
@@ -2441,16 +2479,20 @@ public abstract class WallpaperService extends Service {
@Override
public void onCreate() {
Trace.beginSection("WPMS.onCreate");
super.onCreate();
Trace.endSection();
}
@Override
public void onDestroy() {
Trace.beginSection("WPMS.onDestroy");
super.onDestroy();
for (int i=0; i<mActiveEngines.size(); i++) {
mActiveEngines.get(i).detach();
}
mActiveEngines.clear();
Trace.endSection();
}
/**

View File

@@ -1157,6 +1157,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
Slog.w(TAG, "WallpaperService is not connected yet");
return;
}
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.connectLocked-" + wallpaper.wallpaperComponent);
if (DEBUG) Slog.v(TAG, "Adding window token: " + mToken);
mWindowManagerInternal.addWindowToken(mToken, TYPE_WALLPAPER, mDisplayId,
null /* options */);
@@ -1173,6 +1175,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
false /* fromUser */, wallpaper, null /* reply */);
}
}
t.traceEnd();
}
void disconnectLocked() {
@@ -1322,6 +1325,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.onServiceConnected-" + name);
synchronized (mLock) {
if (mWallpaper.connection == this) {
mService = IWallpaperService.Stub.asInterface(service);
@@ -1338,6 +1343,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
mContext.getMainThreadHandler().removeCallbacks(mDisconnectRunnable);
}
}
t.traceEnd();
}
@Override
@@ -1545,6 +1551,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
public void engineShown(IWallpaperEngine engine) {
synchronized (mLock) {
if (mReply != null) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.mReply.sendResult");
final long ident = Binder.clearCallingIdentity();
try {
mReply.sendResult(null);
@@ -1553,6 +1561,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
} finally {
Binder.restoreCallingIdentity(ident);
}
t.traceEnd();
mReply = null;
}
}
@@ -3058,6 +3067,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
return true;
}
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.bindWallpaperComponentLocked-" + componentName);
try {
if (componentName == null) {
componentName = mDefaultWallpaperComponent;
@@ -3190,6 +3201,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
Slog.w(TAG, msg);
return false;
} finally {
t.traceEnd();
}
return true;
}
@@ -3234,7 +3247,10 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
private void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.attachServiceLocked");
conn.forEachDisplayConnector(connector-> connector.connectLocked(conn, wallpaper));
t.traceEnd();
}
private void notifyCallbacksLocked(WallpaperData wallpaper) {
@@ -3360,6 +3376,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
}
void saveSettingsLocked(int userId) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.saveSettingsLocked-" + userId);
JournaledFile journal = makeJournaledFile(userId);
FileOutputStream fstream = null;
try {
@@ -3388,6 +3406,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
IoUtils.closeQuietly(fstream);
journal.rollback();
}
t.traceEnd();
}