Adjust the sequece of checks in maybeStopDaemon
The method NsdService#maybeStopDaemon is currently being executed
regardless of whether the daemon has been started or not.
However, the mMDnsManager object is always null after Android V.
This means that the null check within the method will always be
triggered, resulting in a wtf log entry. To address this, the
sequence of checks should be adjusted so that the mMDnsManager
null check is performed only after verifying that the daemon has
indeed started up.
Fix: 318874425
Test: Run the NsdManagerTest and check no wtf logs.
Change-Id: Id5bba3a5c6b54df214761ad382f81a6f0a79a907
diff --git a/service-t/src/com/android/server/NsdService.java b/service-t/src/com/android/server/NsdService.java
index 76481c8..b7fd9a8 100644
--- a/service-t/src/com/android/server/NsdService.java
+++ b/service-t/src/com/android/server/NsdService.java
@@ -542,13 +542,13 @@
}
private void maybeStartDaemon() {
- if (mMDnsManager == null) {
- Log.wtf(TAG, "maybeStartDaemon: mMDnsManager is null");
+ if (mIsDaemonStarted) {
+ if (DBG) Log.d(TAG, "Daemon is already started.");
return;
}
- if (mIsDaemonStarted) {
- if (DBG) Log.d(TAG, "Daemon is already started.");
+ if (mMDnsManager == null) {
+ Log.wtf(TAG, "maybeStartDaemon: mMDnsManager is null");
return;
}
mMDnsManager.registerEventListener(mMDnsEventCallback);
@@ -559,13 +559,13 @@
}
private void maybeStopDaemon() {
- if (mMDnsManager == null) {
- Log.wtf(TAG, "maybeStopDaemon: mMDnsManager is null");
+ if (!mIsDaemonStarted) {
+ if (DBG) Log.d(TAG, "Daemon has not been started.");
return;
}
- if (!mIsDaemonStarted) {
- if (DBG) Log.d(TAG, "Daemon has not been started.");
+ if (mMDnsManager == null) {
+ Log.wtf(TAG, "maybeStopDaemon: mMDnsManager is null");
return;
}
mMDnsManager.unregisterEventListener(mMDnsEventCallback);