Search in sources :

Example 1 with DobbyEvent

use of com.inceptai.dobby.eventbus.DobbyEvent in project dobby-android by InceptAi.

the class WifiAnalyzer method updateWifiStatsDetailedState.

protected void updateWifiStatsDetailedState(NetworkInfo.DetailedState detailedState) {
    @WifiState.WifiLinkMode int oldProblemMode = wifiState.getWifiProblemMode();
    @WifiState.WifiLinkMode int newProblemMode = wifiState.updateDetailedWifiStateInfo(detailedState, System.currentTimeMillis());
    if (oldProblemMode != newProblemMode) {
        @DobbyEvent.EventType int eventTypeToBroadcast = convertWifiStateProblemToDobbyEventType(newProblemMode);
        if (eventTypeToBroadcast != DobbyEvent.EventType.WIFI_STATE_UNKNOWN) {
            eventBus.postEvent(new DobbyEvent(eventTypeToBroadcast));
        }
    }
//Utils.PercentileStats stats = wifiState.getStatsForDetailedState(detailedState, GAP_FOR_GETTING_DETAILED_NETWORK_STATE_STATS_MS);
//DobbyLog.v("updateDetailedWifiStateInfo State: " + detailedState.name() + " stats: " + stats.toString());
}
Also used : DobbyEvent(com.inceptai.dobby.eventbus.DobbyEvent)

Example 2 with DobbyEvent

use of com.inceptai.dobby.eventbus.DobbyEvent in project dobby-android by InceptAi.

the class FakeWifiAnalyzer method updateWifiStatsDetailedState.

@Override
protected void updateWifiStatsDetailedState(NetworkInfo.DetailedState detailedState) {
    @WifiState.WifiLinkMode int problemMode = FAKE_WIFI_SCAN_CONFIG.fakeWifiProblemMode;
    wifiState.setCurrentWifiProblemMode(problemMode);
    @DobbyEvent.EventType int eventTypeToBroadcast = convertWifiStateProblemToDobbyEventType(problemMode);
    if (eventTypeToBroadcast != DobbyEvent.EventType.WIFI_STATE_UNKNOWN) {
        eventBus.postEvent(new DobbyEvent(eventTypeToBroadcast));
    }
}
Also used : DobbyEvent(com.inceptai.dobby.eventbus.DobbyEvent)

Example 3 with DobbyEvent

use of com.inceptai.dobby.eventbus.DobbyEvent in project dobby-android by InceptAi.

the class ConnectivityAnalyzer method updateWifiConnectivityMode.

private synchronized void updateWifiConnectivityMode(final int scheduleCount) {
    @WifiConnectivityMode int currentWifiMode = WifiConnectivityMode.UNKNOWN;
    if (isWifiOnline()) {
        DobbyLog.v("CA In updateWifiConnectivityMode with scheduleCount " + scheduleCount + " but returning since already Online");
        return;
    }
    DobbyLog.v("Update wifi connectivity mode, scheduleCount =" + scheduleCount);
    final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    // Reschedule network check if requested to do so and we have a null NetworkInfo.
    if (scheduleCount > 0 && activeNetwork == null) {
        rescheduleConnectivityTest(scheduleCount - 1);
        return;
    }
    DobbyLog.v("active network is not null, activeNetwork:" + activeNetwork.toString());
    try {
        currentWifiMode = performConnectivityAndPortalTest(activeNetwork);
    } catch (IllegalStateException e) {
        DobbyLog.v("Exception while checking connectivity: " + e);
    }
    //Set the wifiConnectivityMode
    if (currentWifiMode != WifiConnectivityMode.UNKNOWN) {
        wifiConnectivityMode = currentWifiMode;
    }
    if (isWifiOnline()) {
        eventBus.postEvent(new DobbyEvent(DobbyEvent.EventType.WIFI_INTERNET_CONNECTIVITY_ONLINE));
    } else if (isWifiInCaptivePortal()) {
        eventBus.postEvent(new DobbyEvent(DobbyEvent.EventType.WIFI_INTERNET_CONNECTIVITY_CAPTIVE_PORTAL));
    } else if (isWifiDisconnected()) {
    } else {
        eventBus.postEvent(new DobbyEvent(DobbyEvent.EventType.WIFI_INTERNET_CONNECTIVITY_OFFLINE));
    }
    //TODO: Move this to the end.
    if (scheduleCount > 0 && !isWifiOnline()) {
        // Try once more before quitting.
        rescheduleConnectivityTest(0);
    }
}
Also used : NetworkInfo(android.net.NetworkInfo) DobbyEvent(com.inceptai.dobby.eventbus.DobbyEvent)

Example 4 with DobbyEvent

use of com.inceptai.dobby.eventbus.DobbyEvent in project dobby-android by InceptAi.

the class FakePingAnalyzer method scheduleEssentialPingTestsAsync.

@Override
protected ListenableFuture<HashMap<String, PingStats>> scheduleEssentialPingTestsAsync(int maxAgeToReTriggerPingMs) throws IllegalStateException {
    eventBus.postEvent(new DobbyEvent(DobbyEvent.EventType.PING_STARTED));
    if (ipLayerInfo == null) {
        //Try to get new iplayerInfo
        eventBus.postEvent(new DobbyEvent(DobbyEvent.EventType.PING_FAILED));
        throw new IllegalStateException("Cannot schedule pings when iplayerInfo is null or own IP is 0.0.0.0");
    }
    fakePingResultsFuture = dobbyThreadpool.getListeningScheduledExecutorService().schedule(new Callable<HashMap<String, PingStats>>() {

        @Override
        public HashMap<String, PingStats> call() {
            HashMap<String, PingStats> pingStatsHashMap = generateFakePingStats();
            ipLayerPingStats = pingStatsHashMap;
            DobbyLog.v("FAKE IP Layer Ping Stats " + ipLayerPingStats.toString());
            eventBus.postEvent(new DobbyEvent(DobbyEvent.EventType.PING_INFO_AVAILABLE));
            return pingStatsHashMap;
        }
    }, PING_LATENCY_MS, TimeUnit.MILLISECONDS);
    return fakePingResultsFuture;
}
Also used : PingStats(com.inceptai.dobby.model.PingStats) DobbyEvent(com.inceptai.dobby.eventbus.DobbyEvent) Callable(java.util.concurrent.Callable)

Example 5 with DobbyEvent

use of com.inceptai.dobby.eventbus.DobbyEvent in project dobby-android by InceptAi.

the class WifiAnalyzer method postToEventBus.

private void postToEventBus(@DobbyEvent.EventType int eventType) {
    eventBus.postEvent(new DobbyEvent(eventType));
    publishedWifiState = true;
}
Also used : DobbyEvent(com.inceptai.dobby.eventbus.DobbyEvent)

Aggregations

DobbyEvent (com.inceptai.dobby.eventbus.DobbyEvent)9 NetworkInfo (android.net.NetworkInfo)2 DhcpInfo (android.net.DhcpInfo)1 WifiInfo (android.net.wifi.WifiInfo)1 DobbyWifiInfo (com.inceptai.dobby.model.DobbyWifiInfo)1 PingStats (com.inceptai.dobby.model.PingStats)1 Callable (java.util.concurrent.Callable)1