diff options
| author | 2024-01-22 08:02:38 +0000 | |
|---|---|---|
| committer | 2024-01-22 08:17:56 +0000 | |
| commit | 6467e27724732ad857c577cee2f67bb0a322a4c4 (patch) | |
| tree | bb5bfc694001d624607fae35d3c258f85d04be1b | |
| parent | d9d1cadac4196297c187699fa63f03201e9f13de (diff) | |
Optimize memory used for creating saved recording notification
Updated the SavedRecording object to save the icon for notification
thumbnail, instead of bitmap, as bitmap is later converted to Icon.
Updated the size of the thumbnail to match the size required for the
notification, to avoid multiple resizings.
memory profile -
before http://screen/mDN2iC5SsFDYdi5 29MB
after http://screen/AxhE9HoAWqwGyqG 10MB
Test: manually tested
Fixes: http://b/278223891
Flag: None
Change-Id: I4f65a8ed542819d741968ed0e44d430307369fd0
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java | 6 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java | 31 |
2 files changed, 26 insertions, 11 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java index 7aa0dadba16c..b5a13138a278 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java @@ -25,7 +25,6 @@ import android.app.Service; import android.content.Context; import android.content.Intent; import android.content.res.Resources; -import android.graphics.Bitmap; import android.graphics.drawable.Icon; import android.media.MediaRecorder; import android.net.Uri; @@ -379,10 +378,9 @@ public class RecordingService extends Service implements ScreenMediaRecorderList .addExtras(extras); // Add thumbnail if available - Bitmap thumbnailBitmap = recording.getThumbnail(); - if (thumbnailBitmap != null) { + if (recording.getThumbnail() != null) { Notification.BigPictureStyle pictureStyle = new Notification.BigPictureStyle() - .bigPicture(thumbnailBitmap) + .bigPicture(recording.getThumbnail()) .showBigPictureWhenCollapsed(true); builder.setStyle(pictureStyle); } diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java index a170d0dac100..5469a4e9da08 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java @@ -23,10 +23,12 @@ import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC; import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.MIC_AND_INTERNAL; import android.annotation.Nullable; +import android.app.ActivityManager; import android.content.ContentResolver; import android.content.ContentValues; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.drawable.Icon; import android.hardware.display.DisplayManager; import android.hardware.display.VirtualDisplay; import android.media.MediaCodec; @@ -51,6 +53,7 @@ import android.util.Size; import android.view.Surface; import android.view.WindowManager; +import com.android.internal.R; import com.android.systemui.mediaprojection.MediaProjectionCaptureTarget; import java.io.Closeable; @@ -361,14 +364,27 @@ public class ScreenMediaRecorder extends MediaProjection.Callback { Files.copy(mTempVideoFile.toPath(), os); os.close(); if (mTempAudioFile != null) mTempAudioFile.delete(); - DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); - Size size = new Size(metrics.widthPixels, metrics.heightPixels); - SavedRecording recording = new SavedRecording(itemUri, mTempVideoFile, size); + SavedRecording recording = new SavedRecording( + itemUri, mTempVideoFile, getRequiredThumbnailSize()); mTempVideoFile.delete(); return recording; } /** + * Returns the required {@code Size} of the thumbnail. + */ + private Size getRequiredThumbnailSize() { + boolean isLowRam = ActivityManager.isLowRamDeviceStatic(); + int thumbnailIconHeight = mContext.getResources().getDimensionPixelSize(isLowRam + ? R.dimen.notification_big_picture_max_height_low_ram + : R.dimen.notification_big_picture_max_height); + int thumbnailIconWidth = mContext.getResources().getDimensionPixelSize(isLowRam + ? R.dimen.notification_big_picture_max_width_low_ram + : R.dimen.notification_big_picture_max_width); + return new Size(thumbnailIconWidth, thumbnailIconHeight); + } + + /** * Release the resources without saving the data */ protected void release() { @@ -386,13 +402,14 @@ public class ScreenMediaRecorder extends MediaProjection.Callback { public class SavedRecording { private Uri mUri; - private Bitmap mThumbnailBitmap; + private Icon mThumbnailIcon; protected SavedRecording(Uri uri, File file, Size thumbnailSize) { mUri = uri; try { - mThumbnailBitmap = ThumbnailUtils.createVideoThumbnail( + Bitmap thumbnailBitmap = ThumbnailUtils.createVideoThumbnail( file, thumbnailSize, null); + mThumbnailIcon = Icon.createWithBitmap(thumbnailBitmap); } catch (IOException e) { Log.e(TAG, "Error creating thumbnail", e); } @@ -402,8 +419,8 @@ public class ScreenMediaRecorder extends MediaProjection.Callback { return mUri; } - public @Nullable Bitmap getThumbnail() { - return mThumbnailBitmap; + public @Nullable Icon getThumbnail() { + return mThumbnailIcon; } } |