Clear DreamOverlayCallback reference on destroy.

This changelist ensures DreamService doesn't reference
DreamOverlayCallback after it's destroyed, allowing it to be garbage
collected before the DreamService.

Test: manual - ensured dream and overly properly entered and exited
across invocations and selections.
Fixed: b/291723667

Change-Id: I54309e539f4417655e0d1dd47c5190494b5c6715
This commit is contained in:
Bryce Lee
2023-07-18 23:43:47 +00:00
parent 804840c51c
commit 078e715cd4

View File

@@ -244,13 +244,7 @@ public class DreamService extends Service implements Window.Callback {
private DreamOverlayConnectionHandler mOverlayConnection;
private final IDreamOverlayCallback mOverlayCallback = new IDreamOverlayCallback.Stub() {
@Override
public void onExitRequested() {
// Simply finish dream when exit is requested.
mHandler.post(() -> finish());
}
};
private IDreamOverlayCallback mOverlayCallback;
public DreamService() {
@@ -877,6 +871,13 @@ public class DreamService extends Service implements Window.Callback {
mDreamComponent = new ComponentName(this, getClass());
mShouldShowComplications = fetchShouldShowComplications(this /*context*/,
fetchServiceInfo(this /*context*/, mDreamComponent));
mOverlayCallback = new IDreamOverlayCallback.Stub() {
@Override
public void onExitRequested() {
// Simply finish dream when exit is requested.
mHandler.post(() -> finish());
}
};
super.onCreate();
}
@@ -1083,7 +1084,7 @@ public class DreamService extends Service implements Window.Callback {
// Just in case destroy came in before detach, let's take care of that now
detach();
mOverlayCallback = null;
super.onDestroy();
}