Fix small bug in DreamOverlayService destroy.

Currently we are registering the callback for the second time instead of
removing the callback.

Test: atest DreamOverlayService
Change-Id: I56aa05b52f85ce60b15cb73e9be3a25501534656
This commit is contained in:
Lucas Silva
2022-02-02 18:52:52 +00:00
parent d478d792e0
commit 9fbebce282
2 changed files with 15 additions and 2 deletions

View File

@@ -122,10 +122,12 @@ public class DreamOverlayService extends android.service.dreams.DreamOverlayServ
@Override
public void onDestroy() {
mKeyguardUpdateMonitor.registerCallback(mKeyguardCallback);
mKeyguardUpdateMonitor.removeCallback(mKeyguardCallback);
setCurrentState(Lifecycle.State.DESTROYED);
final WindowManager windowManager = mContext.getSystemService(WindowManager.class);
windowManager.removeView(mWindow.getDecorView());
if (mWindow != null) {
windowManager.removeView(mWindow.getDecorView());
}
mStateController.setOverlayActive(false);
super.onDestroy();
}

View File

@@ -31,6 +31,7 @@ import android.testing.AndroidTestingRunner;
import android.view.WindowManager;
import android.view.WindowManagerImpl;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.test.filters.SmallTest;
@@ -191,4 +192,14 @@ public class DreamOverlayServiceTest extends SysuiTestCase {
| Complication.COMPLICATION_TYPE_WEATHER;
verify(mStateController).setAvailableComplicationTypes(expectedTypes);
}
@Test
public void testDestroy() {
mService.onDestroy();
mMainExecutor.runAllReady();
verify(mKeyguardUpdateMonitor).removeCallback(any());
verify(mLifecycleRegistry).setCurrentState(Lifecycle.State.DESTROYED);
verify(mStateController).setOverlayActive(false);
}
}