/** * 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"); } }
public void setUp(Context context, CallList callList, AudioModeProvider audioModeProvider) { if (mServiceConnected) { Log.i(this, "New service connection replacing existing one."); // retain the current resources, no need to create new ones. Preconditions.checkState(context == mContext); Preconditions.checkState(callList == mCallList); Preconditions.checkState(audioModeProvider == mAudioModeProvider); return; } Preconditions.checkNotNull(context); mContext = context; mContactInfoCache = ContactInfoCache.getInstance(context); mStatusBarNotifier = new StatusBarNotifier(context, mContactInfoCache); addListener(mStatusBarNotifier); mAudioModeProvider = audioModeProvider; mProximitySensor = new ProximitySensor(context, mAudioModeProvider); addListener(mProximitySensor); mAccelerometerListener = new AccelerometerListener(context); mCallList = callList; // This only gets called by the service so this is okay. mServiceConnected = true; // The final thing we do in this set up is add ourselves as a listener to CallList. This // will kick off an update and the whole process can start. mCallList.addListener(this); Log.d(this, "Finished InCallPresenter.setUp"); }