class BackgroundLocationManager implements LocationClient.LocationClientListener, LocationListener {

    public BackgroundLocationMessage activityDisplayed() {
        switch (currentState) {
            case NO_BACKGROUND_LOCATION_NEEDED:
                // After system-initiated process death, state is reset. The form did not get
                // reloaded and user messaging has already been displayed so go straight to
                // requesting location.
                if (helper.isCurrentFormSet() && helper.currentFormAuditsLocation()) {
                    startLocationRequests();

                    if (currentState != BackgroundLocationState.RECEIVING_LOCATIONS) {
                        // The form requests background location and some precondition failed. Change
                        // the state to STOPPED so that if preconditions change, location tracking
                        // will resume.
                        currentState = BackgroundLocationState.STOPPED;
                    }
                }
                break;

            case PENDING_PRECONDITION_CHECKS:
                // Separate out user message so that any failed precondition is written to the audit
                // log. If Play Services are unavailable AND the location preference is disabled,
                // show the Play Services unavailable message only.
                BackgroundLocationMessage userMessage = null;

                if (!helper.isBackgroundLocationPreferenceEnabled()) {
                    helper.logAuditEvent(AuditEvent.AuditEventType.LOCATION_TRACKING_DISABLED);
                    userMessage = BackgroundLocationMessage.LOCATION_PREF_DISABLED;
                }

                if (!helper.arePlayServicesAvailable()) {
                    helper.logAuditEvent(AuditEvent.AuditEventType.GOOGLE_PLAY_SERVICES_NOT_AVAILABLE);
                    userMessage = BackgroundLocationMessage.PLAY_SERVICES_UNAVAILABLE;
                }

                if (userMessage == null) {
                    helper.logAuditEvent(AuditEvent.AuditEventType.LOCATION_TRACKING_ENABLED);
                    currentState = BackgroundLocationState.PENDING_PERMISSION_CHECK;
                } else {
                    currentState = BackgroundLocationState.STOPPED;
                }

                return userMessage;

            case STOPPED:
                // All preconditions could be met either because we were collecting location, hid
                // the activity and showed it again or because a precondition became met.
                startLocationRequests();
                break;
        }

        return null;
    }

    public  BackgroundLocationManager(LocationClient locationClient, BackgroundLocationHelper helper);

}