Merge "Fix long screenshots actions for work profile." into tm-qpr-dev
This commit is contained in:
@@ -32,7 +32,7 @@ import android.view.WindowManagerGlobal
|
|||||||
import com.android.internal.infra.ServiceConnector
|
import com.android.internal.infra.ServiceConnector
|
||||||
import com.android.systemui.dagger.SysUISingleton
|
import com.android.systemui.dagger.SysUISingleton
|
||||||
import com.android.systemui.dagger.qualifiers.Application
|
import com.android.systemui.dagger.qualifiers.Application
|
||||||
import com.android.systemui.dagger.qualifiers.Background
|
import com.android.systemui.dagger.qualifiers.Main
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CompletableDeferred
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
@@ -45,7 +45,7 @@ class ActionIntentExecutor
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
@Application private val applicationScope: CoroutineScope,
|
@Application private val applicationScope: CoroutineScope,
|
||||||
@Background private val bgDispatcher: CoroutineDispatcher,
|
@Main private val mainDispatcher: CoroutineDispatcher,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
@@ -70,11 +70,10 @@ constructor(
|
|||||||
userId: Int,
|
userId: Int,
|
||||||
overrideTransition: Boolean,
|
overrideTransition: Boolean,
|
||||||
) {
|
) {
|
||||||
withContext(bgDispatcher) {
|
|
||||||
dismissKeyguard()
|
dismissKeyguard()
|
||||||
|
|
||||||
if (userId == UserHandle.myUserId()) {
|
if (userId == UserHandle.myUserId()) {
|
||||||
context.startActivity(intent, bundle)
|
withContext(mainDispatcher) { context.startActivity(intent, bundle) }
|
||||||
} else {
|
} else {
|
||||||
launchCrossProfileIntent(userId, intent, bundle)
|
launchCrossProfileIntent(userId, intent, bundle)
|
||||||
}
|
}
|
||||||
@@ -89,7 +88,6 @@ constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private val proxyConnector: ServiceConnector<IScreenshotProxy> =
|
private val proxyConnector: ServiceConnector<IScreenshotProxy> =
|
||||||
ServiceConnector.Impl(
|
ServiceConnector.Impl(
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ import com.android.internal.logging.UiEventLogger;
|
|||||||
import com.android.systemui.R;
|
import com.android.systemui.R;
|
||||||
import com.android.systemui.dagger.qualifiers.Background;
|
import com.android.systemui.dagger.qualifiers.Background;
|
||||||
import com.android.systemui.dagger.qualifiers.Main;
|
import com.android.systemui.dagger.qualifiers.Main;
|
||||||
|
import com.android.systemui.flags.FeatureFlags;
|
||||||
|
import com.android.systemui.flags.Flags;
|
||||||
import com.android.systemui.screenshot.ScrollCaptureController.LongScreenshot;
|
import com.android.systemui.screenshot.ScrollCaptureController.LongScreenshot;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@@ -67,6 +69,7 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
private static final String TAG = LogConfig.logTag(LongScreenshotActivity.class);
|
private static final String TAG = LogConfig.logTag(LongScreenshotActivity.class);
|
||||||
|
|
||||||
public static final String EXTRA_CAPTURE_RESPONSE = "capture-response";
|
public static final String EXTRA_CAPTURE_RESPONSE = "capture-response";
|
||||||
|
public static final String EXTRA_SCREENSHOT_USER_HANDLE = "screenshot-userhandle";
|
||||||
private static final String KEY_SAVED_IMAGE_PATH = "saved-image-path";
|
private static final String KEY_SAVED_IMAGE_PATH = "saved-image-path";
|
||||||
|
|
||||||
private final UiEventLogger mUiEventLogger;
|
private final UiEventLogger mUiEventLogger;
|
||||||
@@ -74,6 +77,8 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
private final Executor mBackgroundExecutor;
|
private final Executor mBackgroundExecutor;
|
||||||
private final ImageExporter mImageExporter;
|
private final ImageExporter mImageExporter;
|
||||||
private final LongScreenshotData mLongScreenshotHolder;
|
private final LongScreenshotData mLongScreenshotHolder;
|
||||||
|
private final ActionIntentExecutor mActionExecutor;
|
||||||
|
private final FeatureFlags mFeatureFlags;
|
||||||
|
|
||||||
private ImageView mPreview;
|
private ImageView mPreview;
|
||||||
private ImageView mTransitionView;
|
private ImageView mTransitionView;
|
||||||
@@ -85,6 +90,7 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
private CropView mCropView;
|
private CropView mCropView;
|
||||||
private MagnifierView mMagnifierView;
|
private MagnifierView mMagnifierView;
|
||||||
private ScrollCaptureResponse mScrollCaptureResponse;
|
private ScrollCaptureResponse mScrollCaptureResponse;
|
||||||
|
private UserHandle mScreenshotUserHandle;
|
||||||
private File mSavedImagePath;
|
private File mSavedImagePath;
|
||||||
|
|
||||||
private ListenableFuture<File> mCacheSaveFuture;
|
private ListenableFuture<File> mCacheSaveFuture;
|
||||||
@@ -103,12 +109,15 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
@Inject
|
@Inject
|
||||||
public LongScreenshotActivity(UiEventLogger uiEventLogger, ImageExporter imageExporter,
|
public LongScreenshotActivity(UiEventLogger uiEventLogger, ImageExporter imageExporter,
|
||||||
@Main Executor mainExecutor, @Background Executor bgExecutor,
|
@Main Executor mainExecutor, @Background Executor bgExecutor,
|
||||||
LongScreenshotData longScreenshotHolder) {
|
LongScreenshotData longScreenshotHolder, ActionIntentExecutor actionExecutor,
|
||||||
|
FeatureFlags featureFlags) {
|
||||||
mUiEventLogger = uiEventLogger;
|
mUiEventLogger = uiEventLogger;
|
||||||
mUiExecutor = mainExecutor;
|
mUiExecutor = mainExecutor;
|
||||||
mBackgroundExecutor = bgExecutor;
|
mBackgroundExecutor = bgExecutor;
|
||||||
mImageExporter = imageExporter;
|
mImageExporter = imageExporter;
|
||||||
mLongScreenshotHolder = longScreenshotHolder;
|
mLongScreenshotHolder = longScreenshotHolder;
|
||||||
|
mActionExecutor = actionExecutor;
|
||||||
|
mFeatureFlags = featureFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -139,6 +148,11 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
|
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
mScrollCaptureResponse = intent.getParcelableExtra(EXTRA_CAPTURE_RESPONSE);
|
mScrollCaptureResponse = intent.getParcelableExtra(EXTRA_CAPTURE_RESPONSE);
|
||||||
|
mScreenshotUserHandle = intent.getParcelableExtra(EXTRA_SCREENSHOT_USER_HANDLE,
|
||||||
|
UserHandle.class);
|
||||||
|
if (mScreenshotUserHandle == null) {
|
||||||
|
mScreenshotUserHandle = Process.myUserHandle();
|
||||||
|
}
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
String savedImagePath = savedInstanceState.getString(KEY_SAVED_IMAGE_PATH);
|
String savedImagePath = savedInstanceState.getString(KEY_SAVED_IMAGE_PATH);
|
||||||
@@ -318,6 +332,14 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doEdit(Uri uri) {
|
private void doEdit(Uri uri) {
|
||||||
|
if (mFeatureFlags.isEnabled(Flags.SCREENSHOT_WORK_PROFILE_POLICY) && mScreenshotUserHandle
|
||||||
|
!= Process.myUserHandle()) {
|
||||||
|
// TODO: Fix transition for work profile. Omitting it in the meantime.
|
||||||
|
mActionExecutor.launchIntentAsync(
|
||||||
|
ActionIntentCreator.INSTANCE.createEditIntent(uri, this),
|
||||||
|
null,
|
||||||
|
mScreenshotUserHandle.getIdentifier(), false);
|
||||||
|
} else {
|
||||||
String editorPackage = getString(R.string.config_screenshotEditor);
|
String editorPackage = getString(R.string.config_screenshotEditor);
|
||||||
Intent intent = new Intent(Intent.ACTION_EDIT);
|
Intent intent = new Intent(Intent.ACTION_EDIT);
|
||||||
if (!TextUtils.isEmpty(editorPackage)) {
|
if (!TextUtils.isEmpty(editorPackage)) {
|
||||||
@@ -337,8 +359,14 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
ActivityOptions.makeSceneTransitionAnimation(this, mTransitionView,
|
ActivityOptions.makeSceneTransitionAnimation(this, mTransitionView,
|
||||||
ChooserActivity.FIRST_IMAGE_PREVIEW_TRANSITION_NAME).toBundle());
|
ChooserActivity.FIRST_IMAGE_PREVIEW_TRANSITION_NAME).toBundle());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void doShare(Uri uri) {
|
private void doShare(Uri uri) {
|
||||||
|
if (mFeatureFlags.isEnabled(Flags.SCREENSHOT_WORK_PROFILE_POLICY)) {
|
||||||
|
Intent shareIntent = ActionIntentCreator.INSTANCE.createShareIntent(uri, null);
|
||||||
|
mActionExecutor.launchIntentAsync(shareIntent, null,
|
||||||
|
mScreenshotUserHandle.getIdentifier(), false);
|
||||||
|
} else {
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
intent.setType("image/png");
|
intent.setType("image/png");
|
||||||
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
intent.putExtra(Intent.EXTRA_STREAM, uri);
|
||||||
@@ -349,6 +377,7 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
|
|
||||||
startActivityAsUser(sharingChooserIntent, UserHandle.CURRENT);
|
startActivityAsUser(sharingChooserIntent, UserHandle.CURRENT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void onClicked(View v) {
|
private void onClicked(View v) {
|
||||||
int id = v.getId();
|
int id = v.getId();
|
||||||
@@ -389,8 +418,8 @@ public class LongScreenshotActivity extends Activity {
|
|||||||
mOutputBitmap = renderBitmap(drawable, bounds);
|
mOutputBitmap = renderBitmap(drawable, bounds);
|
||||||
ListenableFuture<ImageExporter.Result> exportFuture = mImageExporter.export(
|
ListenableFuture<ImageExporter.Result> exportFuture = mImageExporter.export(
|
||||||
mBackgroundExecutor, UUID.randomUUID(), mOutputBitmap, ZonedDateTime.now(),
|
mBackgroundExecutor, UUID.randomUUID(), mOutputBitmap, ZonedDateTime.now(),
|
||||||
// TODO: Owner must match the owner of the captured window.
|
mFeatureFlags.isEnabled(Flags.SCREENSHOT_WORK_PROFILE_POLICY)
|
||||||
Process.myUserHandle());
|
? mScreenshotUserHandle : Process.myUserHandle());
|
||||||
exportFuture.addListener(() -> onExportCompleted(action, exportFuture), mUiExecutor);
|
exportFuture.addListener(() -> onExportCompleted(action, exportFuture), mUiExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -591,7 +591,7 @@ public class ScreenshotController {
|
|||||||
// Wait until this window is attached to request because it is
|
// Wait until this window is attached to request because it is
|
||||||
// the reference used to locate the target window (below).
|
// the reference used to locate the target window (below).
|
||||||
withWindowAttached(() -> {
|
withWindowAttached(() -> {
|
||||||
requestScrollCapture();
|
requestScrollCapture(owner);
|
||||||
mWindow.peekDecorView().getViewRootImpl().setActivityConfigCallback(
|
mWindow.peekDecorView().getViewRootImpl().setActivityConfigCallback(
|
||||||
new ViewRootImpl.ActivityConfigCallback() {
|
new ViewRootImpl.ActivityConfigCallback() {
|
||||||
@Override
|
@Override
|
||||||
@@ -603,11 +603,11 @@ public class ScreenshotController {
|
|||||||
mScreenshotView.hideScrollChip();
|
mScreenshotView.hideScrollChip();
|
||||||
// Delay scroll capture eval a bit to allow the underlying activity
|
// Delay scroll capture eval a bit to allow the underlying activity
|
||||||
// to set up in the new orientation.
|
// to set up in the new orientation.
|
||||||
mScreenshotHandler.postDelayed(
|
mScreenshotHandler.postDelayed(() -> {
|
||||||
ScreenshotController.this::requestScrollCapture, 150);
|
requestScrollCapture(owner);
|
||||||
|
}, 150);
|
||||||
mScreenshotView.updateInsets(
|
mScreenshotView.updateInsets(
|
||||||
mWindowManager.getCurrentWindowMetrics()
|
mWindowManager.getCurrentWindowMetrics().getWindowInsets());
|
||||||
.getWindowInsets());
|
|
||||||
// Screenshot animation calculations won't be valid anymore,
|
// Screenshot animation calculations won't be valid anymore,
|
||||||
// so just end
|
// so just end
|
||||||
if (mScreenshotAnimation != null
|
if (mScreenshotAnimation != null
|
||||||
@@ -655,7 +655,7 @@ public class ScreenshotController {
|
|||||||
mScreenshotHandler.cancelTimeout(); // restarted after animation
|
mScreenshotHandler.cancelTimeout(); // restarted after animation
|
||||||
}
|
}
|
||||||
|
|
||||||
private void requestScrollCapture() {
|
private void requestScrollCapture(UserHandle owner) {
|
||||||
if (!allowLongScreenshots()) {
|
if (!allowLongScreenshots()) {
|
||||||
Log.d(TAG, "Long screenshots not supported on this device");
|
Log.d(TAG, "Long screenshots not supported on this device");
|
||||||
return;
|
return;
|
||||||
@@ -668,10 +668,11 @@ public class ScreenshotController {
|
|||||||
mScrollCaptureClient.request(DEFAULT_DISPLAY);
|
mScrollCaptureClient.request(DEFAULT_DISPLAY);
|
||||||
mLastScrollCaptureRequest = future;
|
mLastScrollCaptureRequest = future;
|
||||||
mLastScrollCaptureRequest.addListener(() ->
|
mLastScrollCaptureRequest.addListener(() ->
|
||||||
onScrollCaptureResponseReady(future), mMainExecutor);
|
onScrollCaptureResponseReady(future, owner), mMainExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onScrollCaptureResponseReady(Future<ScrollCaptureResponse> responseFuture) {
|
private void onScrollCaptureResponseReady(Future<ScrollCaptureResponse> responseFuture,
|
||||||
|
UserHandle owner) {
|
||||||
try {
|
try {
|
||||||
if (mLastScrollCaptureResponse != null) {
|
if (mLastScrollCaptureResponse != null) {
|
||||||
mLastScrollCaptureResponse.close();
|
mLastScrollCaptureResponse.close();
|
||||||
@@ -701,7 +702,7 @@ public class ScreenshotController {
|
|||||||
mScreenshotView.prepareScrollingTransition(response, mScreenBitmap, newScreenshot,
|
mScreenshotView.prepareScrollingTransition(response, mScreenBitmap, newScreenshot,
|
||||||
mScreenshotTakenInPortrait);
|
mScreenshotTakenInPortrait);
|
||||||
// delay starting scroll capture to make sure the scrim is up before the app moves
|
// delay starting scroll capture to make sure the scrim is up before the app moves
|
||||||
mScreenshotView.post(() -> runBatchScrollCapture(response));
|
mScreenshotView.post(() -> runBatchScrollCapture(response, owner));
|
||||||
});
|
});
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
Log.e(TAG, "requestScrollCapture failed", e);
|
Log.e(TAG, "requestScrollCapture failed", e);
|
||||||
@@ -710,7 +711,7 @@ public class ScreenshotController {
|
|||||||
|
|
||||||
ListenableFuture<ScrollCaptureController.LongScreenshot> mLongScreenshotFuture;
|
ListenableFuture<ScrollCaptureController.LongScreenshot> mLongScreenshotFuture;
|
||||||
|
|
||||||
private void runBatchScrollCapture(ScrollCaptureResponse response) {
|
private void runBatchScrollCapture(ScrollCaptureResponse response, UserHandle owner) {
|
||||||
// Clear the reference to prevent close() in dismissScreenshot
|
// Clear the reference to prevent close() in dismissScreenshot
|
||||||
mLastScrollCaptureResponse = null;
|
mLastScrollCaptureResponse = null;
|
||||||
|
|
||||||
@@ -744,6 +745,8 @@ public class ScreenshotController {
|
|||||||
longScreenshot));
|
longScreenshot));
|
||||||
|
|
||||||
final Intent intent = new Intent(mContext, LongScreenshotActivity.class);
|
final Intent intent = new Intent(mContext, LongScreenshotActivity.class);
|
||||||
|
intent.putExtra(LongScreenshotActivity.EXTRA_SCREENSHOT_USER_HANDLE,
|
||||||
|
owner);
|
||||||
intent.setFlags(
|
intent.setFlags(
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user