Make mScreenshotController final and @NonNull

Simplifies the code by removing the need to null check altogether.
Until the service is onDestroy()'d, it should be capable of handling
requests, since it may be rebound before this. Nulling the field
in onDestroy is also unneccesary. Making the field final removes
the risk of NPE entirely.

Note: this also allows mScreenshot.onDestroy() to actually be called,
as is this is never executed.

(This was part of my change introduced in commit b283231)

Test: manual; Take screenshots, dismiss and immediately take another
Test: monkey test, see bug
Fix: 242881882
Change-Id: I2a25fd4311f2fc7d5802a5d2a9bd8af64f845868
This commit is contained in:
Mark Renouf
2022-08-18 21:11:18 -04:00
parent a53fd2a5cd
commit 326f44e1a4

View File

@@ -69,7 +69,7 @@ import javax.inject.Inject;
public class TakeScreenshotService extends Service {
private static final String TAG = logTag(TakeScreenshotService.class);
private ScreenshotController mScreenshot;
private final ScreenshotController mScreenshot;
private final UserManager mUserManager;
private final DevicePolicyManager mDevicePolicyManager;
@@ -150,10 +150,7 @@ public class TakeScreenshotService extends Service {
if (DEBUG_SERVICE) {
Log.d(TAG, "onUnbind");
}
if (mScreenshot != null) {
mScreenshot.removeWindow();
mScreenshot = null;
}
mScreenshot.removeWindow();
unregisterReceiver(mCloseSystemDialogs);
return false;
}
@@ -161,10 +158,7 @@ public class TakeScreenshotService extends Service {
@Override
public void onDestroy() {
super.onDestroy();
if (mScreenshot != null) {
mScreenshot.onDestroy();
mScreenshot = null;
}
mScreenshot.onDestroy();
if (DEBUG_SERVICE) {
Log.d(TAG, "onDestroy");
}