Merge "Add traces to WallpaperManagerService and WallpaperService." into tm-qpr-dev

This commit is contained in:
Yasin Kilicdere
2022-11-10 17:57:36 +00:00
committed by Android (Google) Code Review
2 changed files with 73 additions and 12 deletions

View File

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

View File

@@ -1157,6 +1157,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
Slog.w(TAG, "WallpaperService is not connected yet"); Slog.w(TAG, "WallpaperService is not connected yet");
return; return;
} }
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.connectLocked-" + wallpaper.wallpaperComponent);
if (DEBUG) Slog.v(TAG, "Adding window token: " + mToken); if (DEBUG) Slog.v(TAG, "Adding window token: " + mToken);
mWindowManagerInternal.addWindowToken(mToken, TYPE_WALLPAPER, mDisplayId, mWindowManagerInternal.addWindowToken(mToken, TYPE_WALLPAPER, mDisplayId,
null /* options */); null /* options */);
@@ -1173,6 +1175,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
false /* fromUser */, wallpaper, null /* reply */); false /* fromUser */, wallpaper, null /* reply */);
} }
} }
t.traceEnd();
} }
void disconnectLocked() { void disconnectLocked() {
@@ -1322,6 +1325,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.onServiceConnected-" + name);
synchronized (mLock) { synchronized (mLock) {
if (mWallpaper.connection == this) { if (mWallpaper.connection == this) {
mService = IWallpaperService.Stub.asInterface(service); mService = IWallpaperService.Stub.asInterface(service);
@@ -1337,6 +1342,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
mContext.getMainThreadHandler().removeCallbacks(mTryToRebindRunnable); mContext.getMainThreadHandler().removeCallbacks(mTryToRebindRunnable);
} }
} }
t.traceEnd();
} }
@Override @Override
@@ -1544,6 +1550,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
public void engineShown(IWallpaperEngine engine) { public void engineShown(IWallpaperEngine engine) {
synchronized (mLock) { synchronized (mLock) {
if (mReply != null) { if (mReply != null) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.mReply.sendResult");
final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity();
try { try {
mReply.sendResult(null); mReply.sendResult(null);
@@ -1551,6 +1559,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident);
Slog.d(TAG, "failed to send callback!", e); Slog.d(TAG, "failed to send callback!", e);
} }
t.traceEnd();
mReply = null; mReply = null;
} }
} }
@@ -3049,6 +3058,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
return true; return true;
} }
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.bindWallpaperComponentLocked-" + componentName);
try { try {
if (componentName == null) { if (componentName == null) {
componentName = mDefaultWallpaperComponent; componentName = mDefaultWallpaperComponent;
@@ -3181,6 +3192,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
} }
Slog.w(TAG, msg); Slog.w(TAG, msg);
return false; return false;
} finally {
t.traceEnd();
} }
return true; return true;
} }
@@ -3225,7 +3238,10 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
} }
private void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) { private void attachServiceLocked(WallpaperConnection conn, WallpaperData wallpaper) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.attachServiceLocked");
conn.forEachDisplayConnector(connector-> connector.connectLocked(conn, wallpaper)); conn.forEachDisplayConnector(connector-> connector.connectLocked(conn, wallpaper));
t.traceEnd();
} }
private void notifyCallbacksLocked(WallpaperData wallpaper) { private void notifyCallbacksLocked(WallpaperData wallpaper) {
@@ -3351,6 +3367,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
} }
void saveSettingsLocked(int userId) { void saveSettingsLocked(int userId) {
TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
t.traceBegin("WPMS.saveSettingsLocked-" + userId);
JournaledFile journal = makeJournaledFile(userId); JournaledFile journal = makeJournaledFile(userId);
FileOutputStream fstream = null; FileOutputStream fstream = null;
try { try {
@@ -3379,6 +3397,7 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
IoUtils.closeQuietly(fstream); IoUtils.closeQuietly(fstream);
journal.rollback(); journal.rollback();
} }
t.traceEnd();
} }