Update app clips package style.

Bug: 269403503
Test: atest AppClipsActivityTest AppClipsTrampolineActivityTest
AppClipsViewModelTest

Change-Id: I41b84f07f528b49820bc5ba60d31bd9e5db6f687
This commit is contained in:
Ajinkya Chalke
2023-03-03 16:18:15 +00:00
parent 27fb0488c0
commit 618e47a27b
12 changed files with 86 additions and 63 deletions

View File

@@ -23,9 +23,9 @@ import com.android.systemui.hdmi.HdmiCecSetMenuLanguageActivity;
import com.android.systemui.keyguard.WorkLockActivity;
import com.android.systemui.people.PeopleSpaceActivity;
import com.android.systemui.people.widget.LaunchConversationActivity;
import com.android.systemui.screenshot.AppClipsActivity;
import com.android.systemui.screenshot.AppClipsTrampolineActivity;
import com.android.systemui.screenshot.LongScreenshotActivity;
import com.android.systemui.screenshot.appclips.AppClipsActivity;
import com.android.systemui.screenshot.appclips.AppClipsTrampolineActivity;
import com.android.systemui.sensorprivacy.SensorUseStartedActivity;
import com.android.systemui.sensorprivacy.television.TvSensorPrivacyChangedActivity;
import com.android.systemui.sensorprivacy.television.TvUnblockSensorActivity;

View File

@@ -17,7 +17,7 @@ package com.android.systemui.notetask
import com.android.systemui.notetask.quickaffordance.NoteTaskQuickAffordanceConfig
import com.android.systemui.notetask.shortcut.LaunchNoteTaskActivity
import com.android.systemui.screenshot.AppClipsTrampolineActivity
import com.android.systemui.screenshot.appclips.AppClipsTrampolineActivity
/**
* Supported entry points for [NoteTaskController.showNoteTask].

View File

@@ -14,15 +14,15 @@
* limitations under the License.
*/
package com.android.systemui.screenshot;
package com.android.systemui.screenshot.appclips;
import static com.android.systemui.screenshot.AppClipsTrampolineActivity.ACTION_FINISH_FROM_TRAMPOLINE;
import static com.android.systemui.screenshot.AppClipsTrampolineActivity.EXTRA_CALLING_PACKAGE_NAME;
import static com.android.systemui.screenshot.AppClipsTrampolineActivity.EXTRA_RESULT_RECEIVER;
import static com.android.systemui.screenshot.AppClipsTrampolineActivity.EXTRA_SCREENSHOT_URI;
import static com.android.systemui.screenshot.AppClipsTrampolineActivity.PERMISSION_SELF;
import static com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_FOR_NOTE_ACCEPTED;
import static com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_FOR_NOTE_CANCELLED;
import static com.android.systemui.screenshot.appclips.AppClipsEvent.SCREENSHOT_FOR_NOTE_ACCEPTED;
import static com.android.systemui.screenshot.appclips.AppClipsEvent.SCREENSHOT_FOR_NOTE_CANCELLED;
import static com.android.systemui.screenshot.appclips.AppClipsTrampolineActivity.ACTION_FINISH_FROM_TRAMPOLINE;
import static com.android.systemui.screenshot.appclips.AppClipsTrampolineActivity.EXTRA_CALLING_PACKAGE_NAME;
import static com.android.systemui.screenshot.appclips.AppClipsTrampolineActivity.EXTRA_RESULT_RECEIVER;
import static com.android.systemui.screenshot.appclips.AppClipsTrampolineActivity.EXTRA_SCREENSHOT_URI;
import static com.android.systemui.screenshot.appclips.AppClipsTrampolineActivity.PERMISSION_SELF;
import android.app.Activity;
import android.content.BroadcastReceiver;
@@ -52,6 +52,8 @@ import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEventLogger.UiEventEnum;
import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.screenshot.CropView;
import com.android.systemui.screenshot.MagnifierView;
import com.android.systemui.settings.UserTracker;
import javax.inject.Inject;

View File

@@ -32,12 +32,12 @@ import javax.inject.Inject;
/** An intermediary singleton object to help communicating with the cross process service. */
@SysUISingleton
public class AppClipsCrossProcessHelper {
class AppClipsCrossProcessHelper {
private final ServiceConnector<IAppClipsScreenshotHelperService> mProxyConnector;
@Inject
public AppClipsCrossProcessHelper(@Application Context context) {
AppClipsCrossProcessHelper(@Application Context context) {
mProxyConnector = new ServiceConnector.Impl<IAppClipsScreenshotHelperService>(context,
new Intent(context, AppClipsScreenshotHelperService.class),
Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY
@@ -52,7 +52,7 @@ public class AppClipsCrossProcessHelper {
* pass around but not a {@link Bitmap}.
*/
@Nullable
public Bitmap takeScreenshot() {
Bitmap takeScreenshot() {
try {
AndroidFuture<ScreenshotHardwareBufferInternal> future =
mProxyConnector.postForResult(

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2023 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.
*/
package com.android.systemui.screenshot.appclips;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
enum AppClipsEvent implements UiEventLogger.UiEventEnum {
@UiEvent(doc = "Notes application triggered the screenshot for notes")
SCREENSHOT_FOR_NOTE_TRIGGERED(1308),
@UiEvent(doc = "User accepted the screenshot to be sent to the notes app")
SCREENSHOT_FOR_NOTE_ACCEPTED(1309),
@UiEvent(doc = "User cancelled the screenshot for notes app flow")
SCREENSHOT_FOR_NOTE_CANCELLED(1310);
private final int mId;
AppClipsEvent(int id) {
mId = id;
}
@Override
public int getId() {
return mId;
}
}

View File

@@ -24,7 +24,6 @@ import android.window.ScreenCapture.ScreenshotSync;
import androidx.annotation.Nullable;
import com.android.systemui.screenshot.AppClipsActivity;
import com.android.wm.shell.bubbles.Bubbles;
import java.util.Optional;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.systemui.screenshot;
package com.android.systemui.screenshot.appclips;
import static android.content.Intent.CAPTURE_CONTENT_FOR_NOTE_BLOCKED_BY_ADMIN;
import static android.content.Intent.CAPTURE_CONTENT_FOR_NOTE_FAILED;
@@ -24,7 +24,7 @@ import static android.content.Intent.EXTRA_CAPTURE_CONTENT_FOR_NOTE_STATUS_CODE;
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
import static com.android.systemui.flags.Flags.SCREENSHOT_APP_CLIPS;
import static com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_FOR_NOTE_TRIGGERED;
import static com.android.systemui.screenshot.appclips.AppClipsEvent.SCREENSHOT_FOR_NOTE_TRIGGERED;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;

View File

@@ -14,12 +14,10 @@
* limitations under the License.
*/
package com.android.systemui.screenshot;
package com.android.systemui.screenshot.appclips;
import static android.content.Intent.CAPTURE_CONTENT_FOR_NOTE_FAILED;
import static androidx.annotation.VisibleForTesting.PACKAGE_PRIVATE;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.HardwareRenderer;
@@ -31,7 +29,6 @@ import android.net.Uri;
import android.os.Process;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
@@ -39,11 +36,10 @@ import androidx.lifecycle.ViewModelProvider;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.screenshot.appclips.AppClipsCrossProcessHelper;
import com.android.systemui.screenshot.ImageExporter;
import com.google.common.util.concurrent.ListenableFuture;
import java.time.ZonedDateTime;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
@@ -52,8 +48,7 @@ import java.util.concurrent.Executor;
import javax.inject.Inject;
/** A {@link ViewModel} to help with the App Clips screenshot flow. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public final class AppClipsViewModel extends ViewModel {
final class AppClipsViewModel extends ViewModel {
private final AppClipsCrossProcessHelper mAppClipsCrossProcessHelper;
private final ImageExporter mImageExporter;
@@ -80,8 +75,7 @@ public final class AppClipsViewModel extends ViewModel {
}
/** Grabs a screenshot and updates the {@link Bitmap} set in screenshot {@link LiveData}. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public void performScreenshot() {
void performScreenshot() {
mBgExecutor.execute(() -> {
Bitmap screenshot = mAppClipsCrossProcessHelper.takeScreenshot();
mMainExecutor.execute(() -> {
@@ -95,14 +89,12 @@ public final class AppClipsViewModel extends ViewModel {
}
/** Returns a {@link LiveData} that holds the captured screenshot. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public LiveData<Bitmap> getScreenshot() {
LiveData<Bitmap> getScreenshot() {
return mScreenshotLiveData;
}
/** Returns a {@link LiveData} that holds the {@link Uri} where screenshot is saved. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public LiveData<Uri> getResultLiveData() {
LiveData<Uri> getResultLiveData() {
return mResultLiveData;
}
@@ -110,8 +102,7 @@ public final class AppClipsViewModel extends ViewModel {
* Returns a {@link LiveData} that holds the error codes for
* {@link Intent#EXTRA_CAPTURE_CONTENT_FOR_NOTE_STATUS_CODE}.
*/
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public LiveData<Integer> getErrorLiveData() {
LiveData<Integer> getErrorLiveData() {
return mErrorLiveData;
}
@@ -119,8 +110,7 @@ public final class AppClipsViewModel extends ViewModel {
* Saves the provided {@link Drawable} to storage then informs the result {@link Uri} to
* {@link LiveData}.
*/
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public void saveScreenshotThenFinish(Drawable screenshotDrawable, Rect bounds) {
void saveScreenshotThenFinish(Drawable screenshotDrawable, Rect bounds) {
mBgExecutor.execute(() -> {
// Render the screenshot bitmap in background.
Bitmap screenshotBitmap = renderBitmap(screenshotDrawable, bounds);
@@ -128,7 +118,7 @@ public final class AppClipsViewModel extends ViewModel {
// Export and save the screenshot in background.
// TODO(b/267310185): Save to work profile UserHandle.
ListenableFuture<ImageExporter.Result> exportFuture = mImageExporter.export(
mBgExecutor, UUID.randomUUID(), screenshotBitmap, ZonedDateTime.now(),
mBgExecutor, UUID.randomUUID(), screenshotBitmap,
Process.myUserHandle());
// Get the result and update state on main thread.
@@ -160,8 +150,7 @@ public final class AppClipsViewModel extends ViewModel {
}
/** Helper factory to help with injecting {@link AppClipsViewModel}. */
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public static final class Factory implements ViewModelProvider.Factory {
static final class Factory implements ViewModelProvider.Factory {
private final AppClipsCrossProcessHelper mAppClipsCrossProcessHelper;
private final ImageExporter mImageExporter;

View File

@@ -28,7 +28,7 @@ import android.window.ScreenCapture.ScreenshotHardwareBuffer;
* An internal version of {@link ScreenshotHardwareBuffer} that helps with parceling the information
* necessary for creating a {@link Bitmap}.
*/
public class ScreenshotHardwareBufferInternal implements Parcelable {
class ScreenshotHardwareBufferInternal implements Parcelable {
public static final Creator<ScreenshotHardwareBufferInternal> CREATOR =
new Creator<>() {
@@ -45,7 +45,7 @@ public class ScreenshotHardwareBufferInternal implements Parcelable {
private final HardwareBuffer mHardwareBuffer;
private final ParcelableColorSpace mParcelableColorSpace;
public ScreenshotHardwareBufferInternal(
ScreenshotHardwareBufferInternal(
ScreenshotHardwareBuffer screenshotHardwareBuffer) {
mHardwareBuffer = screenshotHardwareBuffer.getHardwareBuffer();
mParcelableColorSpace = new ParcelableColorSpace(
@@ -65,7 +65,7 @@ public class ScreenshotHardwareBufferInternal implements Parcelable {
* {@link Bitmap#wrapHardwareBuffer(HardwareBuffer, ColorSpace)} and
* {@link HardwareBuffer#close()} for more information.
*/
public Bitmap createBitmapThenCloseBuffer() {
Bitmap createBitmapThenCloseBuffer() {
Bitmap bitmap = Bitmap.wrapHardwareBuffer(mHardwareBuffer,
mParcelableColorSpace.getColorSpace());
mHardwareBuffer.close();

View File

@@ -18,8 +18,8 @@ package com.android.systemui.screenshot.appclips;
import static android.app.Activity.RESULT_OK;
import static com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_FOR_NOTE_ACCEPTED;
import static com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_FOR_NOTE_CANCELLED;
import static com.android.systemui.screenshot.appclips.AppClipsEvent.SCREENSHOT_FOR_NOTE_ACCEPTED;
import static com.android.systemui.screenshot.appclips.AppClipsEvent.SCREENSHOT_FOR_NOTE_CANCELLED;
import static com.google.common.truth.Truth.assertThat;
@@ -50,9 +50,6 @@ import androidx.test.runner.intercepting.SingleActivityFactory;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.screenshot.AppClipsActivity;
import com.android.systemui.screenshot.AppClipsTrampolineActivity;
import com.android.systemui.screenshot.AppClipsViewModel;
import com.android.systemui.settings.UserTracker;
import org.junit.After;

View File

@@ -25,7 +25,8 @@ import static android.content.Intent.CAPTURE_CONTENT_FOR_NOTE_WINDOW_MODE_UNSUPP
import static android.content.Intent.EXTRA_CAPTURE_CONTENT_FOR_NOTE_STATUS_CODE;
import static com.android.systemui.flags.Flags.SCREENSHOT_APP_CLIPS;
import static com.android.systemui.screenshot.AppClipsTrampolineActivity.EXTRA_SCREENSHOT_URI;
import static com.android.systemui.screenshot.appclips.AppClipsEvent.SCREENSHOT_FOR_NOTE_TRIGGERED;
import static com.android.systemui.screenshot.appclips.AppClipsTrampolineActivity.EXTRA_SCREENSHOT_URI;
import static com.google.common.truth.Truth.assertThat;
@@ -59,8 +60,6 @@ import com.android.systemui.SysuiTestCase;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.notetask.NoteTaskController;
import com.android.systemui.screenshot.AppClipsTrampolineActivity;
import com.android.systemui.screenshot.ScreenshotEvent;
import com.android.systemui.settings.UserTracker;
import com.android.wm.shell.bubbles.Bubbles;
@@ -262,8 +261,7 @@ public final class AppClipsTrampolineActivityTest extends SysuiTestCase {
mActivityRule.launchActivity(mActivityIntent);
waitForIdleSync();
verify(mUiEventLogger).log(ScreenshotEvent.SCREENSHOT_FOR_NOTE_TRIGGERED, TEST_UID,
TEST_CALLING_PACKAGE);
verify(mUiEventLogger).log(SCREENSHOT_FOR_NOTE_TRIGGERED, TEST_UID, TEST_CALLING_PACKAGE);
}
private void mockToSatisfyAllPrerequisites() throws NameNotFoundException {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.systemui.screenshot;
package com.android.systemui.screenshot.appclips;
import static android.content.Intent.CAPTURE_CONTENT_FOR_NOTE_FAILED;
@@ -36,7 +36,7 @@ import android.os.UserHandle;
import androidx.test.runner.AndroidJUnit4;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.screenshot.appclips.AppClipsCrossProcessHelper;
import com.android.systemui.screenshot.ImageExporter;
import com.google.common.util.concurrent.Futures;
@@ -46,7 +46,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.time.ZonedDateTime;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
@@ -62,7 +61,7 @@ public final class AppClipsViewModelTest extends SysuiTestCase {
@Mock private AppClipsCrossProcessHelper mAppClipsCrossProcessHelper;
@Mock private ImageExporter mImageExporter;
private com.android.systemui.screenshot.AppClipsViewModel mViewModel;
private AppClipsViewModel mViewModel;
@Before
public void setUp() {
@@ -99,8 +98,8 @@ public final class AppClipsViewModelTest extends SysuiTestCase {
@Test
public void saveScreenshot_throwsError_shouldUpdateErrorWithFailed() {
when(mImageExporter.export(any(Executor.class), any(UUID.class), eq(null), any(
ZonedDateTime.class), any(UserHandle.class))).thenReturn(
when(mImageExporter.export(any(Executor.class), any(UUID.class), eq(null),
any(UserHandle.class))).thenReturn(
Futures.immediateFailedFuture(new ExecutionException(new Throwable())));
mViewModel.saveScreenshotThenFinish(FAKE_DRAWABLE, FAKE_RECT);
@@ -113,9 +112,9 @@ public final class AppClipsViewModelTest extends SysuiTestCase {
@Test
public void saveScreenshot_failsSilently_shouldUpdateErrorWithFailed() {
when(mImageExporter.export(any(Executor.class), any(UUID.class), eq(null), any(
ZonedDateTime.class), any(UserHandle.class))).thenReturn(
Futures.immediateFuture(new ImageExporter.Result()));
when(mImageExporter.export(any(Executor.class), any(UUID.class), eq(null),
any(UserHandle.class))).thenReturn(
Futures.immediateFuture(new ImageExporter.Result()));
mViewModel.saveScreenshotThenFinish(FAKE_DRAWABLE, FAKE_RECT);
waitForIdleSync();
@@ -129,9 +128,8 @@ public final class AppClipsViewModelTest extends SysuiTestCase {
public void saveScreenshot_succeeds_shouldUpdateResultWithUri() {
ImageExporter.Result result = new ImageExporter.Result();
result.uri = FAKE_URI;
when(mImageExporter.export(any(Executor.class), any(UUID.class), eq(null), any(
ZonedDateTime.class), any(UserHandle.class))).thenReturn(
Futures.immediateFuture(result));
when(mImageExporter.export(any(Executor.class), any(UUID.class), eq(null),
any(UserHandle.class))).thenReturn(Futures.immediateFuture(result));
mViewModel.saveScreenshotThenFinish(FAKE_DRAWABLE, FAKE_RECT);
waitForIdleSync();