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

Unverified Commit 7be17755 authored by ezio84's avatar ezio84 Committed by Michael Bestas
Browse files

Screenrecord: add low quality option

Add a low quality option that still gives a good recording
reducing a lot the final file size (useful when sharing the screenrecord
on data connections).

old commits ref:
https://github.com/ezio84/abc_frameworks_base/commit/6092d9ca8b0949d64c1b87d6cd53d66daf002e14
https://github.com/ezio84/abc_frameworks_base/commit/b50c7caf8b46c731093b11f5647028a23346f937
https://github.com/ezio84/abc_frameworks_base/commit/91c00e8fb70cb17b8658678bf476452f96cd44d1

Change-Id: If413241c3fa533650690cf3b7df5c05fb2f8c8ed
parent fa4a7314
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ public class RecordingServiceTest extends SysuiTestCase {

    @Test
    public void testLogStartFullScreenRecording() {
        Intent startIntent = RecordingService.getStartIntent(mContext, 0, 0, false, null);
        Intent startIntent = RecordingService.getStartIntent(mContext, 0, 0, false, null, false);
        mRecordingService.onStartCommand(startIntent, 0, 0);

        verify(mUiEventLogger, times(1)).log(Events.ScreenRecordEvent.SCREEN_RECORD_START);
@@ -158,7 +158,7 @@ public class RecordingServiceTest extends SysuiTestCase {
    public void testLogStartPartialRecording() {
        MediaProjectionCaptureTarget target =
                new MediaProjectionCaptureTarget(new LaunchCookie(), 12345);
        Intent startIntent = RecordingService.getStartIntent(mContext, 0, 0, false, target);
        Intent startIntent = RecordingService.getStartIntent(mContext, 0, 0, false, target, false);
        mRecordingService.onStartCommand(startIntent, 0, 0);

        verify(mUiEventLogger, times(1)).log(Events.ScreenRecordEvent.SCREEN_RECORD_START);
@@ -191,7 +191,7 @@ public class RecordingServiceTest extends SysuiTestCase {
        // When the screen recording does not start properly
        doThrow(new RuntimeException("fail")).when(mScreenMediaRecorder).start();

        Intent startIntent = RecordingService.getStartIntent(mContext, 0, 0, false, null);
        Intent startIntent = RecordingService.getStartIntent(mContext, 0, 0, false, null, false);
        mRecordingService.onStartCommand(startIntent, 0, 0);

        assertUpdateState(false);
@@ -316,7 +316,7 @@ public class RecordingServiceTest extends SysuiTestCase {
    @Test
        public void testSecondaryDisplayRecording() throws IOException {
        Intent startIntent =
                RecordingService.getStartIntent(mContext, 0, 0, false, 200, null);
                RecordingService.getStartIntent(mContext, 0, 0, false, 200, null, false);
        assertEquals(startIntent.getIntExtra("extra_displayId", -1), 200);
    }

+31 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (C) 2020 The Android Open Source Project

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
        android:fillColor="#FF000000"
        android:pathData="M7,15h3c0.55,0 1,-0.45 1,-1v-1.5c0,-0.55 -0.45,-1 -1,-1H7.5v-1h2V11H11v-1c0,-0.55 -0.45,-1 -1,-1H7c-0.55,0 -1,0.45 -1,1v1.5c0,0.55 0.45,1 1,1h2.5v1h-2V13H6v1C6,14.55 6.45,15 7,15z"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M18,14v-4c0,-0.55 -0.45,-1 -1,-1h-4v6h4C17.55,15 18,14.55 18,14zM16.5,13.5h-2v-3h2V13.5z"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M20,4H4C2.89,4 2,4.9 2,6v12c0,1.1 0.89,2 2,2h16c1.1,0 2,-0.9 2,-2V6C22,4.9 21.1,4 20,4zM20,18H4V6h16V18z"/>
</vector>
+47 −0
Original line number Diff line number Diff line
@@ -85,4 +85,51 @@
            style="@style/ScreenRecord.Switch"
            android:importantForAccessibility="yes" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/show_lowquality"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:layout_marginTop="@dimen/screenrecord_option_padding">
        <ImageView
            android:layout_width="@dimen/screenrecord_option_icon_size"
            android:layout_height="@dimen/screenrecord_option_icon_size"
            android:src="@drawable/ic_sr_quality"
            android:tint="?android:attr/textColorSecondary"
            android:layout_marginRight="@dimen/screenrecord_option_padding"
            android:importantForAccessibility="no"/>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:minHeight="48dp"
            android:layout_weight="1"
            android:orientation="vertical">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@*android:string/config_bodyFontFamily"
                android:text="@string/screenrecord_lowquality_label"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="?android:attr/textColorPrimary"
                android:contentDescription="@string/screenrecord_lowquality_label"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:importantForAccessibility="no"
                android:fontFamily="@*android:string/config_bodyFontFamily"
                android:text="@string/screenrecord_lowquality_summary"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="?android:textColorSecondary"/>
        </LinearLayout>

        <Switch
            android:layout_width="wrap_content"
            android:minWidth="48dp"
            android:layout_height="48dp"
            android:id="@+id/screenrecord_lowquality_switch"
            android:contentDescription="@string/screenrecord_lowquality_label"
            style="@style/ScreenRecord.Switch"
            android:importantForAccessibility="yes" />
    </LinearLayout>
</LinearLayout>
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
@@ -116,4 +116,8 @@
    <string name="screenshot_delete_label">Delete</string>
    <!-- Content description indicating that tapping the element will allow deleting the screenshot [CHAR LIMIT=NONE] -->
    <string name="screenshot_delete_description">Delete screenshot</string>

    <!-- Screen record -->
    <string name="screenrecord_lowquality_label">Lower quality</string>
    <string name="screenrecord_lowquality_summary">For smaller file size</string>
</resources>
+21 −4
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.util.Log;
import android.view.Display;
import android.widget.Toast;

import com.android.systemui.Prefs;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.dagger.qualifiers.LongRunning;
@@ -83,6 +84,7 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
    private static final String EXTRA_CAPTURE_TARGET = "extra_captureTarget";
    private static final String EXTRA_DISPLAY_ID = "extra_displayId";
    private static final String EXTRA_STOP_REASON = "extra_stopReason";
    private static final String EXTRA_LOW_QUALITY = "extra_lowQuality";

    protected static final String ACTION_START = "com.android.systemui.screenrecord.START";
    protected static final String ACTION_SHOW_START_NOTIF =
@@ -109,6 +111,8 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
    protected int mNotificationId = NOTIF_BASE_ID;
    private RecordingServiceStrings mStrings;

    private boolean mLowQuality;

    @Inject
    public RecordingService(ScreenRecordUxController controller, @LongRunning Executor executor,
            @Main Handler handler, UiEventLogger uiEventLogger,
@@ -139,13 +143,15 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
     */
    public static Intent getStartIntent(Context context, int resultCode,
            int audioSource, boolean showTaps,
            @Nullable MediaProjectionCaptureTarget captureTarget) {
            @Nullable MediaProjectionCaptureTarget captureTarget,
            boolean lowQuality) {
        return new Intent(context, RecordingService.class)
                .setAction(ACTION_START)
                .putExtra(EXTRA_RESULT_CODE, resultCode)
                .putExtra(EXTRA_AUDIO_SOURCE, audioSource)
                .putExtra(EXTRA_SHOW_TAPS, showTaps)
                .putExtra(EXTRA_CAPTURE_TARGET, captureTarget);
                .putExtra(EXTRA_CAPTURE_TARGET, captureTarget)
                .putExtra(EXTRA_LOW_QUALITY, lowQuality);
    }

    /**
@@ -167,8 +173,10 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
            int audioSource,
            boolean showTaps,
            int displayId,
            @Nullable MediaProjectionCaptureTarget captureTarget) {
        return getStartIntent(context, resultCode, audioSource, showTaps, captureTarget)
            @Nullable MediaProjectionCaptureTarget captureTarget,
            boolean lowQuality) {
        return getStartIntent(context, resultCode, audioSource, showTaps, captureTarget,
                lowQuality)
                .putExtra(EXTRA_DISPLAY_ID, displayId);
    }

@@ -198,6 +206,8 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
                        .values()[intent.getIntExtra(EXTRA_AUDIO_SOURCE, 0)];
                Log.d(getTag(), "recording with audio source " + mAudioSource);
                mShowTaps = intent.getBooleanExtra(EXTRA_SHOW_TAPS, false);
                mLowQuality = intent.getBooleanExtra(EXTRA_LOW_QUALITY, false);

                MediaProjectionCaptureTarget captureTarget =
                        intent.getParcelableExtra(EXTRA_CAPTURE_TARGET,
                                MediaProjectionCaptureTarget.class);
@@ -218,6 +228,7 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
                        displayId,
                        this
                );
                setLowQuality(mLowQuality);

                if (startRecording()) {
                    updateState(true);
@@ -582,6 +593,12 @@ public class RecordingService extends Service implements ScreenMediaRecorderList
        return new RecordingServiceStrings(getResources());
    }

    private void setLowQuality(boolean turnOn) {
        if (getRecorder() != null) {
            getRecorder().setLowQuality(turnOn);
        }
    }

    /**
     * Get an intent to stop the recording service.
     * @param context Context from the requesting activity
Loading