Unlock keyguard for screen recording action

Fixes: 159134871
Test: RecordingServiceTest
Change-Id: Iad0eccf79655a8980221121e915b87de150b66b9
This commit is contained in:
Jay Aliomer
2020-07-20 23:10:47 -04:00
parent 730a1c4b0b
commit 2d0d2d1847
2 changed files with 36 additions and 23 deletions

View File

@@ -42,6 +42,7 @@ import com.android.internal.logging.UiEventLogger;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.dagger.qualifiers.LongRunning; import com.android.systemui.dagger.qualifiers.LongRunning;
import com.android.systemui.settings.CurrentUserContextTracker; import com.android.systemui.settings.CurrentUserContextTracker;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@@ -72,7 +73,7 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis
private static final String ACTION_DELETE = "com.android.systemui.screenrecord.DELETE"; private static final String ACTION_DELETE = "com.android.systemui.screenrecord.DELETE";
private final RecordingController mController; private final RecordingController mController;
private final KeyguardDismissUtil mKeyguardDismissUtil;
private ScreenRecordingAudioSource mAudioSource; private ScreenRecordingAudioSource mAudioSource;
private boolean mShowTaps; private boolean mShowTaps;
private boolean mOriginalShowTaps; private boolean mOriginalShowTaps;
@@ -85,12 +86,13 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis
@Inject @Inject
public RecordingService(RecordingController controller, @LongRunning Executor executor, public RecordingService(RecordingController controller, @LongRunning Executor executor,
UiEventLogger uiEventLogger, NotificationManager notificationManager, UiEventLogger uiEventLogger, NotificationManager notificationManager,
CurrentUserContextTracker userContextTracker) { CurrentUserContextTracker userContextTracker, KeyguardDismissUtil keyguardDismissUtil) {
mController = controller; mController = controller;
mLongExecutor = executor; mLongExecutor = executor;
mUiEventLogger = uiEventLogger; mUiEventLogger = uiEventLogger;
mNotificationManager = notificationManager; mNotificationManager = notificationManager;
mUserContextTracker = userContextTracker; mUserContextTracker = userContextTracker;
mKeyguardDismissUtil = keyguardDismissUtil;
} }
/** /**
@@ -170,33 +172,36 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis
Intent shareIntent = new Intent(Intent.ACTION_SEND) Intent shareIntent = new Intent(Intent.ACTION_SEND)
.setType("video/mp4") .setType("video/mp4")
.putExtra(Intent.EXTRA_STREAM, shareUri); .putExtra(Intent.EXTRA_STREAM, shareUri);
String shareLabel = getResources().getString(R.string.screenrecord_share_label); mKeyguardDismissUtil.executeWhenUnlocked(() -> {
String shareLabel = getResources().getString(R.string.screenrecord_share_label);
startActivity(Intent.createChooser(shareIntent, shareLabel)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
// Remove notification
mNotificationManager.cancelAsUser(null, NOTIFICATION_VIEW_ID, currentUser);
return false;
}, false);
// Close quick shade // Close quick shade
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
// Remove notification
mNotificationManager.cancelAsUser(null, NOTIFICATION_VIEW_ID, currentUser);
startActivity(Intent.createChooser(shareIntent, shareLabel)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
break; break;
case ACTION_DELETE: case ACTION_DELETE:
// Close quick shade mKeyguardDismissUtil.executeWhenUnlocked(() -> {
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); // Close quick shade
sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
ContentResolver resolver = getContentResolver();
Uri uri = Uri.parse(intent.getStringExtra(EXTRA_PATH));
resolver.delete(uri, null, null);
ContentResolver resolver = getContentResolver(); Toast.makeText(
Uri uri = Uri.parse(intent.getStringExtra(EXTRA_PATH)); this,
resolver.delete(uri, null, null); R.string.screenrecord_delete_description,
Toast.LENGTH_LONG).show();
Log.d(TAG, "Deleted recording " + uri);
Toast.makeText( // Remove notification
this, mNotificationManager.cancelAsUser(null, NOTIFICATION_VIEW_ID, currentUser);
R.string.screenrecord_delete_description, return false;
Toast.LENGTH_LONG).show(); }, false);
// Remove notification
mNotificationManager.cancelAsUser(null, NOTIFICATION_VIEW_ID, currentUser);
Log.d(TAG, "Deleted recording " + uri);
break; break;
} }
return Service.START_STICKY; return Service.START_STICKY;

View File

@@ -32,7 +32,9 @@ import androidx.test.filters.SmallTest;
import com.android.internal.logging.UiEventLogger; import com.android.internal.logging.UiEventLogger;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.settings.CurrentUserContextTracker; import com.android.systemui.settings.CurrentUserContextTracker;
import com.android.systemui.statusbar.phone.KeyguardDismissUtil;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -61,6 +63,12 @@ public class RecordingServiceTest extends SysuiTestCase {
private Executor mExecutor; private Executor mExecutor;
@Mock @Mock
private CurrentUserContextTracker mUserContextTracker; private CurrentUserContextTracker mUserContextTracker;
private KeyguardDismissUtil mKeyguardDismissUtil = new KeyguardDismissUtil() {
public void executeWhenUnlocked(ActivityStarter.OnDismissAction action,
boolean requiresShadeOpen) {
action.onDismiss();
}
};
private RecordingService mRecordingService; private RecordingService mRecordingService;
@@ -68,7 +76,7 @@ public class RecordingServiceTest extends SysuiTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mRecordingService = Mockito.spy(new RecordingService(mController, mExecutor, mUiEventLogger, mRecordingService = Mockito.spy(new RecordingService(mController, mExecutor, mUiEventLogger,
mNotificationManager, mUserContextTracker)); mNotificationManager, mUserContextTracker, mKeyguardDismissUtil));
// Return actual context info // Return actual context info
doReturn(mContext).when(mRecordingService).getApplicationContext(); doReturn(mContext).when(mRecordingService).getApplicationContext();