Merge "Remove #createScreenshotNotificationSmartActionsProvider from SystemUIFactory" into tm-qpr-dev

This commit is contained in:
Dave Mankoff
2022-07-13 18:06:06 +00:00
committed by Android (Google) Code Review
14 changed files with 75 additions and 53 deletions

View File

@@ -28,14 +28,12 @@ import com.android.systemui.dagger.DaggerGlobalRootComponent;
import com.android.systemui.dagger.GlobalRootComponent;
import com.android.systemui.dagger.SysUIComponent;
import com.android.systemui.dagger.WMComponent;
import com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider;
import com.android.wm.shell.dagger.WMShellConcurrencyModule;
import com.android.wm.shell.transition.ShellTransitions;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import javax.inject.Provider;
@@ -239,14 +237,4 @@ public class SystemUIFactory {
public Map<Class<?>, Provider<CoreStartable>> getStartableComponentsPerUser() {
return mSysUIComponent.getPerUserStartables();
}
/**
* Creates an instance of ScreenshotNotificationSmartActionsProvider.
* This method is overridden in vendor specific implementation of Sys UI.
*/
public ScreenshotNotificationSmartActionsProvider
createScreenshotNotificationSmartActionsProvider(
Context context, Executor executor, Handler uiHandler) {
return new ScreenshotNotificationSmartActionsProvider();
}
}

View File

@@ -44,6 +44,7 @@ import com.android.systemui.qs.dagger.QSModule;
import com.android.systemui.qs.tileimpl.QSFactoryImpl;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsImplementation;
import com.android.systemui.screenshot.ReferenceScreenshotModule;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationLockscreenUserManagerImpl;
@@ -99,6 +100,7 @@ import dagger.Provides;
MediaModule.class,
PowerModule.class,
QSModule.class,
ReferenceScreenshotModule.class,
StartCentralSurfacesModule.class,
VolumeModule.class
})

View File

@@ -102,7 +102,7 @@ public class ActionProxyReceiver extends BroadcastReceiver {
? ACTION_TYPE_EDIT
: ACTION_TYPE_SHARE;
mScreenshotSmartActions.notifyScreenshotAction(
context, intent.getStringExtra(EXTRA_ID), actionType, false, null);
intent.getStringExtra(EXTRA_ID), actionType, false, null);
}
}
}

View File

@@ -62,7 +62,7 @@ public class DeleteScreenshotReceiver extends BroadcastReceiver {
});
if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) {
mScreenshotSmartActions.notifyScreenshotAction(
context, intent.getStringExtra(EXTRA_ID), ACTION_TYPE_DELETE, false, null);
intent.getStringExtra(EXTRA_ID), ACTION_TYPE_DELETE, false, null);
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (C) 2022 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;
import dagger.Module;
import dagger.Provides;
/**
*
*/
@Module
public interface ReferenceScreenshotModule {
/** */
@Provides
static ScreenshotNotificationSmartActionsProvider providesScrnshtNotifSmartActionsProvider() {
return new ScreenshotNotificationSmartActionsProvider();
}
}

View File

@@ -38,7 +38,6 @@ import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -49,7 +48,6 @@ import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
import com.android.systemui.R;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.screenshot.ScreenshotController.SavedImageData.ActionTransition;
import com.google.common.util.concurrent.ListenableFuture;
@@ -89,7 +87,10 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
SaveImageInBackgroundTask(Context context, ImageExporter exporter,
ScreenshotSmartActions screenshotSmartActions,
ScreenshotController.SaveImageInBackgroundData data,
Supplier<ActionTransition> sharedElementTransition) {
Supplier<ActionTransition> sharedElementTransition,
ScreenshotNotificationSmartActionsProvider
screenshotNotificationSmartActionsProvider
) {
mContext = context;
mScreenshotSmartActions = screenshotSmartActions;
mImageData = new ScreenshotController.SavedImageData();
@@ -103,15 +104,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
// Initialize screenshot notification smart actions provider.
mSmartActionsEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SYSTEMUI,
SystemUiDeviceConfigFlags.ENABLE_SCREENSHOT_NOTIFICATION_SMART_ACTIONS, true);
if (mSmartActionsEnabled) {
mSmartActionsProvider =
SystemUIFactory.getInstance()
.createScreenshotNotificationSmartActionsProvider(
context, THREAD_POOL_EXECUTOR, new Handler());
} else {
// If smart actions is not enabled use empty implementation.
mSmartActionsProvider = new ScreenshotNotificationSmartActionsProvider();
}
mSmartActionsProvider = screenshotNotificationSmartActionsProvider;
}
@Override

View File

@@ -263,6 +263,8 @@ public class ScreenshotController {
private final ScrollCaptureController mScrollCaptureController;
private final LongScreenshotData mLongScreenshotHolder;
private final boolean mIsLowRamDevice;
private final ScreenshotNotificationSmartActionsProvider
mScreenshotNotificationSmartActionsProvider;
private final TimeoutHandler mScreenshotHandler;
private ScreenshotView mScreenshotView;
@@ -298,7 +300,9 @@ public class ScreenshotController {
LongScreenshotData longScreenshotHolder,
ActivityManager activityManager,
TimeoutHandler timeoutHandler,
BroadcastSender broadcastSender) {
BroadcastSender broadcastSender,
ScreenshotNotificationSmartActionsProvider screenshotNotificationSmartActionsProvider
) {
mScreenshotSmartActions = screenshotSmartActions;
mNotificationsController = screenshotNotificationsController;
mScrollCaptureClient = scrollCaptureClient;
@@ -308,6 +312,7 @@ public class ScreenshotController {
mScrollCaptureController = scrollCaptureController;
mLongScreenshotHolder = longScreenshotHolder;
mIsLowRamDevice = activityManager.isLowRamDevice();
mScreenshotNotificationSmartActionsProvider = screenshotNotificationSmartActionsProvider;
mBgExecutor = Executors.newSingleThreadExecutor();
mBroadcastSender = broadcastSender;
@@ -956,7 +961,8 @@ public class ScreenshotController {
}
mSaveInBgTask = new SaveImageInBackgroundTask(mContext, mImageExporter,
mScreenshotSmartActions, data, getActionTransitionSupplier());
mScreenshotSmartActions, data, getActionTransitionSupplier(),
mScreenshotNotificationSmartActionsProvider);
mSaveInBgTask.execute();
}

View File

@@ -16,8 +16,6 @@
package com.android.systemui.screenshot;
import static android.os.AsyncTask.THREAD_POOL_EXECUTOR;
import static com.android.systemui.screenshot.LogConfig.DEBUG_ACTIONS;
import static com.android.systemui.screenshot.LogConfig.logTag;
import static com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider.ScreenshotSmartActionType;
@@ -25,17 +23,14 @@ import static com.android.systemui.screenshot.ScreenshotNotificationSmartActions
import android.app.ActivityManager;
import android.app.Notification;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Handler;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.shared.system.ActivityManagerWrapper;
@@ -46,6 +41,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.inject.Inject;
import javax.inject.Provider;
/**
* Collects the static functions for retrieving and acting on smart actions.
@@ -53,9 +49,17 @@ import javax.inject.Inject;
@SysUISingleton
public class ScreenshotSmartActions {
private static final String TAG = logTag(ScreenshotSmartActions.class);
private final Provider<ScreenshotNotificationSmartActionsProvider>
mScreenshotNotificationSmartActionsProviderProvider;
@Inject
public ScreenshotSmartActions() {}
public ScreenshotSmartActions(
Provider<ScreenshotNotificationSmartActionsProvider>
screenshotNotificationSmartActionsProviderProvider
) {
mScreenshotNotificationSmartActionsProviderProvider =
screenshotNotificationSmartActionsProviderProvider;
}
@VisibleForTesting
CompletableFuture<List<Notification.Action>> getSmartActionsFuture(
@@ -165,12 +169,11 @@ public class ScreenshotSmartActions {
}
}
void notifyScreenshotAction(Context context, String screenshotId, String action,
void notifyScreenshotAction(String screenshotId, String action,
boolean isSmartAction, Intent intent) {
try {
ScreenshotNotificationSmartActionsProvider provider =
SystemUIFactory.getInstance().createScreenshotNotificationSmartActionsProvider(
context, THREAD_POOL_EXECUTOR, new Handler());
mScreenshotNotificationSmartActionsProviderProvider.get();
if (DEBUG_ACTIONS) {
Log.d(TAG, String.format("%s notifyAction: %s id=%s, isSmartAction=%b",
provider.getClass(), action, screenshotId, isSmartAction));

View File

@@ -60,7 +60,7 @@ public class SmartActionsReceiver extends BroadcastReceiver {
}
mScreenshotSmartActions.notifyScreenshotAction(
context, intent.getStringExtra(EXTRA_ID), actionType, true,
intent.getStringExtra(EXTRA_ID), actionType, true,
pendingIntent.getIntent());
}
}

View File

@@ -46,6 +46,7 @@ import com.android.systemui.qs.dagger.QSModule;
import com.android.systemui.qs.tileimpl.QSFactoryImpl;
import com.android.systemui.recents.Recents;
import com.android.systemui.recents.RecentsImplementation;
import com.android.systemui.screenshot.ReferenceScreenshotModule;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
@@ -91,6 +92,7 @@ import dagger.multibindings.IntoSet;
GestureModule.class,
PowerModule.class,
QSModule.class,
ReferenceScreenshotModule.class,
VolumeModule.class,
},
subcomponents = {

View File

@@ -32,7 +32,6 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.testing.AndroidTestingRunner;
@@ -115,7 +114,7 @@ public class ActionProxyReceiverTest extends SysuiTestCase {
actionProxyReceiver.onReceive(mContext, mIntent);
verify(mMockScreenshotSmartActions, never())
.notifyScreenshotAction(any(Context.class), anyString(), anyString(), anyBoolean(),
.notifyScreenshotAction(anyString(), anyString(), anyBoolean(),
any(Intent.class));
}
@@ -129,7 +128,7 @@ public class ActionProxyReceiverTest extends SysuiTestCase {
actionProxyReceiver.onReceive(mContext, mIntent);
verify(mMockScreenshotSmartActions).notifyScreenshotAction(
mContext, testId, ACTION_TYPE_SHARE, false, null);
testId, ACTION_TYPE_SHARE, false, null);
}
private ActionProxyReceiver constructActionProxyReceiver(boolean withStatusBar) {

View File

@@ -31,7 +31,6 @@ import static org.mockito.Mockito.verify;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
@@ -81,7 +80,7 @@ public class DeleteScreenshotReceiverTest extends SysuiTestCase {
verify(mMockExecutor, never()).execute(any(Runnable.class));
verify(mMockScreenshotSmartActions, never()).notifyScreenshotAction(
any(Context.class), any(String.class), any(String.class), anyBoolean(),
any(String.class), any(String.class), anyBoolean(),
any(Intent.class));
}
@@ -113,7 +112,7 @@ public class DeleteScreenshotReceiverTest extends SysuiTestCase {
}
// ensure smart actions not called by default
verify(mMockScreenshotSmartActions, never()).notifyScreenshotAction(any(Context.class),
verify(mMockScreenshotSmartActions, never()).notifyScreenshotAction(
any(String.class), any(String.class), anyBoolean(), any(Intent.class));
}
@@ -129,7 +128,7 @@ public class DeleteScreenshotReceiverTest extends SysuiTestCase {
mDeleteScreenshotReceiver.onReceive(mContext, intent);
verify(mMockExecutor).execute(any(Runnable.class));
verify(mMockScreenshotSmartActions).notifyScreenshotAction(mContext, testId,
verify(mMockScreenshotSmartActions).notifyScreenshotAction(testId,
ACTION_TYPE_DELETE, false, null);
}

View File

@@ -43,7 +43,6 @@ import android.testing.AndroidTestingRunner;
import androidx.test.filters.SmallTest;
import com.android.systemui.SystemUIFactory;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.screenshot.ScreenshotController.SavedImageData.ActionTransition;
@@ -71,7 +70,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
public void setup() {
mSmartActionsProvider = mock(
ScreenshotNotificationSmartActionsProvider.class);
mScreenshotSmartActions = new ScreenshotSmartActions();
mScreenshotSmartActions = new ScreenshotSmartActions(() -> mSmartActionsProvider);
mHandler = mock(Handler.class);
}
@@ -158,8 +157,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
Bitmap bitmap = mock(Bitmap.class);
when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
ScreenshotNotificationSmartActionsProvider actionsProvider =
SystemUIFactory.getInstance().createScreenshotNotificationSmartActionsProvider(
mContext, null, mHandler);
new ScreenshotNotificationSmartActionsProvider();
CompletableFuture<List<Notification.Action>> smartActionsFuture =
mScreenshotSmartActions.getSmartActionsFuture("", null, bitmap,
actionsProvider, REGULAR_SMART_ACTIONS,
@@ -183,7 +181,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
data.mActionsReadyListener = null;
SaveImageInBackgroundTask task =
new SaveImageInBackgroundTask(mContext, null, mScreenshotSmartActions, data,
ActionTransition::new);
ActionTransition::new, mSmartActionsProvider);
Notification.Action shareAction = task.createShareAction(mContext, mContext.getResources(),
Uri.parse("Screenshot_123.png")).get().action;
@@ -211,7 +209,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
data.mActionsReadyListener = null;
SaveImageInBackgroundTask task =
new SaveImageInBackgroundTask(mContext, null, mScreenshotSmartActions, data,
ActionTransition::new);
ActionTransition::new, mSmartActionsProvider);
Notification.Action editAction = task.createEditAction(mContext, mContext.getResources(),
Uri.parse("Screenshot_123.png")).get().action;
@@ -239,7 +237,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
data.mActionsReadyListener = null;
SaveImageInBackgroundTask task =
new SaveImageInBackgroundTask(mContext, null, mScreenshotSmartActions, data,
ActionTransition::new);
ActionTransition::new, mSmartActionsProvider);
Notification.Action deleteAction = task.createDeleteAction(mContext,
mContext.getResources(),

View File

@@ -74,6 +74,6 @@ public class SmartActionsReceiverTest extends SysuiTestCase {
verify(mMockPendingIntent).send(
eq(mContext), eq(0), isNull(), isNull(), isNull(), isNull(), any(Bundle.class));
verify(mMockScreenshotSmartActions).notifyScreenshotAction(
mContext, testId, testActionType, true, intent);
testId, testActionType, true, intent);
}
}