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"); }