Make GlobalActionsDialogLite directly injectable

When GlobalActionsDialogLite was made injectable by
commit c88a2d7f3d, it was
in the form of a dagger.Lazy. This was probably a mistake, as
a local reference to the content of this dagger.Lazy was also
kept, and this messes up the lifecycle and may, in strange
cases, allow the use of a Dialog that has been destroyed,
with consequences that are difficult to predict.

A direct injection of the GlobalActionsDialogLite is
probably more appropriate.

Test: manual
Change-Id: I1646c883b9a15db737bfc897c41dd26fb584d539
This commit is contained in:
Andreas Bexell
2021-11-03 09:08:33 +01:00
committed by Ed Savage-Jones
parent 7a25b6f379
commit c666c5e761

View File

@@ -41,26 +41,23 @@ import com.android.systemui.statusbar.policy.KeyguardStateController;
import javax.inject.Inject;
import dagger.Lazy;
public class GlobalActionsImpl implements GlobalActions, CommandQueue.Callbacks {
private final Context mContext;
private final Lazy<GlobalActionsDialogLite> mGlobalActionsDialogLazy;
private final KeyguardStateController mKeyguardStateController;
private final DeviceProvisionedController mDeviceProvisionedController;
private final BlurUtils mBlurUtils;
private final CommandQueue mCommandQueue;
private GlobalActionsDialogLite mGlobalActionsDialog;
private final GlobalActionsDialogLite mGlobalActionsDialog;
private boolean mDisabled;
@Inject
public GlobalActionsImpl(Context context, CommandQueue commandQueue,
Lazy<GlobalActionsDialogLite> globalActionsDialogLazy, BlurUtils blurUtils,
GlobalActionsDialogLite globalActionsDialog, BlurUtils blurUtils,
KeyguardStateController keyguardStateController,
DeviceProvisionedController deviceProvisionedController) {
mContext = context;
mGlobalActionsDialogLazy = globalActionsDialogLazy;
mGlobalActionsDialog = globalActionsDialog;
mKeyguardStateController = keyguardStateController;
mDeviceProvisionedController = deviceProvisionedController;
mCommandQueue = commandQueue;
@@ -71,16 +68,12 @@ public class GlobalActionsImpl implements GlobalActions, CommandQueue.Callbacks
@Override
public void destroy() {
mCommandQueue.removeCallback(this);
if (mGlobalActionsDialog != null) {
mGlobalActionsDialog.destroy();
mGlobalActionsDialog = null;
}
mGlobalActionsDialog.destroy();
}
@Override
public void showGlobalActions(GlobalActionsManager manager) {
if (mDisabled) return;
mGlobalActionsDialog = mGlobalActionsDialogLazy.get();
mGlobalActionsDialog.showOrHideDialog(mKeyguardStateController.isShowing(),
mDeviceProvisionedController.isDeviceProvisioned());
}
@@ -189,7 +182,7 @@ public class GlobalActionsImpl implements GlobalActions, CommandQueue.Callbacks
final boolean disabled = (state2 & DISABLE2_GLOBAL_ACTIONS) != 0;
if (displayId != mContext.getDisplayId() || disabled == mDisabled) return;
mDisabled = disabled;
if (disabled && mGlobalActionsDialog != null) {
if (disabled) {
mGlobalActionsDialog.dismissDialog();
}
}