Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e97a0b2 authored by Yasin Kilicdere's avatar Yasin Kilicdere
Browse files

Add traces to the code where wallpaper is loaded during a user switch.

Bug: 316331405
Test: Perfetto UI
Flag: NONE
Change-Id: I51580b66d07274a14793a014a3885e7b545834db
parent 9481b2b3
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.os.Trace;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -612,11 +613,14 @@ public class WallpaperManager {
                ColorManagementProxy cmProxy) {
            if (mService != null) {
                try {
                    Trace.beginSection("WPMS.isWallpaperSupported");
                    if (!mService.isWallpaperSupported(context.getOpPackageName())) {
                        return null;
                    }
                } catch (RemoteException e) {
                    throw e.rethrowFromSystemServer();
                } finally {
                    Trace.endSection();
                }
            }
            synchronized (this) {
@@ -627,6 +631,7 @@ public class WallpaperManager {
                mCachedWallpaper = null;
                Bitmap currentWallpaper = null;
                try {
                    Trace.beginSection("WPMS.getCurrentWallpaperLocked");
                    currentWallpaper = getCurrentWallpaperLocked(
                            context, which, userId, hardware, cmProxy);
                } catch (OutOfMemoryError e) {
@@ -652,6 +657,8 @@ public class WallpaperManager {
                        // Post-O apps really most sincerely need the permission.
                        throw e;
                    }
                } finally {
                    Trace.endSection();
                }
                if (currentWallpaper != null) {
                    mCachedWallpaper = new CachedWallpaper(currentWallpaper, userId, which);
@@ -730,9 +737,11 @@ public class WallpaperManager {

            try {
                Bundle params = new Bundle();
                Trace.beginSection("WPMS.getWallpaperWithFeature_" + which);
                ParcelFileDescriptor pfd = mService.getWallpaperWithFeature(
                        context.getOpPackageName(), context.getAttributionTag(), this, which,
                        params, userId, /* getCropped = */ true);
                Trace.endSection();

                if (pfd != null) {
                    try (BufferedInputStream bis = new BufferedInputStream(
@@ -762,13 +771,18 @@ public class WallpaperManager {
        }

        private Bitmap getDefaultWallpaper(Context context, @SetWallpaperFlags int which) {
            Trace.beginSection("WPMS.getDefaultWallpaper_" + which);
            Bitmap defaultWallpaper = mDefaultWallpaper;
            if (defaultWallpaper == null || defaultWallpaper.isRecycled()) {
                defaultWallpaper = null;
                Trace.beginSection("WPMS.openDefaultWallpaper");
                try (InputStream is = openDefaultWallpaper(context, which)) {
                    Trace.endSection();
                    if (is != null) {
                        BitmapFactory.Options options = new BitmapFactory.Options();
                        Trace.beginSection("WPMS.decodeStream");
                        defaultWallpaper = BitmapFactory.decodeStream(is, null, options);
                        Trace.endSection();
                    }
                } catch (OutOfMemoryError | IOException e) {
                    Log.w(TAG, "Can't decode stream", e);
@@ -777,6 +791,7 @@ public class WallpaperManager {
            synchronized (this) {
                mDefaultWallpaper = defaultWallpaper;
            }
            Trace.endSection();
            return defaultWallpaper;
        }

+17 −1
Original line number Diff line number Diff line
@@ -317,10 +317,11 @@ public class ImageWallpaper extends WallpaperService {
        }

        private void loadWallpaperAndDrawFrameInternal() {
            Trace.beginSection("ImageWallpaper.CanvasEngine#loadWallpaper");
            Trace.beginSection("WPMS.ImageWallpaper.CanvasEngine#loadWallpaper");
            boolean loadSuccess = false;
            Bitmap bitmap;
            try {
                Trace.beginSection("WPMS.getBitmapAsUser");
                bitmap = mWallpaperManager.getBitmapAsUser(
                        mUserTracker.getUserId(), false, getSourceFlag(), true);
                if (bitmap != null
@@ -333,15 +334,22 @@ public class ImageWallpaper extends WallpaperService {
                // be loaded, we will go into a cycle. Don't do a build where the
                // default wallpaper can't be loaded.
                Log.w(TAG, "Unable to load wallpaper!", exception);
                Trace.beginSection("WPMS.clearWallpaper");
                mWallpaperManager.clearWallpaper(getWallpaperFlags(), mUserTracker.getUserId());
                Trace.endSection();

                try {
                    Trace.beginSection("WPMS.getBitmapAsUser_defaultWallpaper");
                    bitmap = mWallpaperManager.getBitmapAsUser(
                            mUserTracker.getUserId(), false, getSourceFlag(), true);
                } catch (RuntimeException | OutOfMemoryError e) {
                    Log.w(TAG, "Unable to load default wallpaper!", e);
                    bitmap = null;
                } finally {
                    Trace.endSection();
                }
            } finally {
                Trace.endSection();
            }

            if (bitmap == null) {
@@ -355,15 +363,23 @@ public class ImageWallpaper extends WallpaperService {
                loadSuccess = true;
                // recycle the previously loaded bitmap
                if (mBitmap != null) {
                    Trace.beginSection("WPMS.mBitmap.recycle");
                    mBitmap.recycle();
                    Trace.endSection();
                }
                mBitmap = bitmap;
                Trace.beginSection("WPMS.wallpaperSupportsWcg");
                mWideColorGamut = mWallpaperManager.wallpaperSupportsWcg(getSourceFlag());
                Trace.endSection();

                // +2 usages for the color extraction and the delayed unload.
                mBitmapUsages += 2;
                Trace.beginSection("WPMS.recomputeColorExtractorMiniBitmap");
                recomputeColorExtractorMiniBitmap();
                Trace.endSection();
                Trace.beginSection("WPMS.drawFrameInternal");
                drawFrameInternal();
                Trace.endSection();

                /*
                 * after loading, the bitmap will be unloaded after all these conditions: