/** * Checks to see if both the UI is gone and the service is disconnected. If so, tear it all down. */ private void attemptCleanup() { boolean shouldCleanup = (mInCallActivity == null && !mServiceConnected && mInCallState == InCallState.NO_CALLS); Log.i(this, "attemptCleanup? " + shouldCleanup); if (shouldCleanup) { mIsActivityPreviouslyStarted = false; // blow away stale contact info so that we get fresh data on // the next set of calls if (mContactInfoCache != null) { mContactInfoCache.clearCache(); } mContactInfoCache = null; if (mProximitySensor != null) { removeListener(mProximitySensor); mProximitySensor.tearDown(); } mProximitySensor = null; mAccelerometerListener = null; mAudioModeProvider = null; if (mStatusBarNotifier != null) { removeListener(mStatusBarNotifier); } mStatusBarNotifier = null; if (mCallList != null) { mCallList.removeListener(this); } mCallList = null; mContext = null; mInCallActivity = null; mListeners.clear(); mIncomingCallListeners.clear(); Log.d(this, "Finished InCallPresenter.CleanUp"); } }