Java Code Examples for io.particle.android.sdk.utils.EZ#threadSleep()

The following examples show how to use io.particle.android.sdk.utils.EZ#threadSleep() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WaitForCloudConnectivityStep.java    From particle-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRunStep() throws SetupStepException {
    // Wait for just a couple seconds for a WifiFacade connection if possible, in case we
    // flip from the soft AP, to mobile data, and then to WifiFacade in rapid succession.
    EZ.threadSleep(2000);
    int reachabilityRetries = 0;
    boolean isAPIHostReachable = checkIsApiHostAvailable();
    while (!isAPIHostReachable && reachabilityRetries <= MAX_RETRIES_REACHABILITY) {
        EZ.threadSleep(2000);
        isAPIHostReachable = checkIsApiHostAvailable();
        log.d("Checked for reachability " + reachabilityRetries + " times");
        reachabilityRetries++;
    }
    if (!isAPIHostReachable) {
        throw new SetupStepException("Unable to reach API host");
    }
}
 
Example 2
Source File: EnsureSoftApNotVisible.java    From particle-android with Apache License 2.0 6 votes vote down vote up
private void onStepNeverYetFulfilled() throws SetupStepException {
    for (int i = 0; i < 16; i++) {
        if (!isSoftApVisible()) {
            // it's gone!
            wasFulfilledOnce = true;
            return;
        }

        if (i % 6 == 0) {
            wifiFacade.startScan();
        }

        EZ.threadSleep(250);
    }
    throw new SetupStepException("Wi-Fi credentials appear to be incorrect or an error has occurred");
}
 
Example 3
Source File: WaitForDisconnectionFromDeviceStep.java    From particle-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRunStep() throws SetupStepException, SetupProcessException {
    for (int i = 0; i <= 5; i++) {
        if (isConnectedToSoftAp()) {
            // wait and try again
            EZ.threadSleep(200);
        } else {
            EZ.threadSleep(1000);
            // success, no longer connected.
            wasDisconnected = true;
            if (EZ.isUsingOlderWifiStack()) {
                // for some reason Lollipop doesn't need this??
                reenablePreviousWifi();
            }
            return;
        }
    }

    // Still connected after the above completed: fail
    throw new SetupStepException("Not disconnected from soft AP");
}
 
Example 4
Source File: SetupStepsRunnerTask.java    From particle-android with Apache License 2.0 6 votes vote down vote up
private void runSteps() throws SetupStepException, SetupProcessException {
    for (SetupStep step : steps) {

        throwIfCancelled();

        publishProgress(new StepProgress(
                step.getStepConfig().getStepId(),
                StepProgress.STARTING));

        try {
            EZ.threadSleep(1000);
            throwIfCancelled();

            step.runStep();

        } catch (SetupStepException e) {
            // give it a moment before trying again.
            EZ.threadSleep(2000);
            throw e;
        }

        publishProgress(new StepProgress(
                step.getStepConfig().getStepId(),
                StepProgress.SUCCEEDED));
    }
}
 
Example 5
Source File: WaitForCloudConnectivityStep.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRunStep() throws SetupStepException {
    // Wait for just a couple seconds for a WifiFacade connection if possible, in case we
    // flip from the soft AP, to mobile data, and then to WifiFacade in rapid succession.
    EZ.threadSleep(2000);
    int reachabilityRetries = 0;
    boolean isAPIHostReachable = checkIsApiHostAvailable();
    while (!isAPIHostReachable && reachabilityRetries <= MAX_RETRIES_REACHABILITY) {
        EZ.threadSleep(2000);
        isAPIHostReachable = checkIsApiHostAvailable();
        log.d("Checked for reachability " + reachabilityRetries + " times");
        reachabilityRetries++;
    }
    if (!isAPIHostReachable) {
        throw new SetupStepException("Unable to reach API host");
    }
}
 
Example 6
Source File: EnsureSoftApNotVisible.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void onStepNeverYetFulfilled() throws SetupStepException {
    for (int i = 0; i < 16; i++) {
        if (!isSoftApVisible()) {
            // it's gone!
            wasFulfilledOnce = true;
            return;
        }

        if (i % 6 == 0) {
            wifiFacade.startScan();
        }

        EZ.threadSleep(250);
    }
    throw new SetupStepException("Wi-Fi credentials appear to be incorrect or an error has occurred");
}
 
Example 7
Source File: WaitForDisconnectionFromDeviceStep.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onRunStep() throws SetupStepException, SetupProcessException {
    for (int i = 0; i <= 5; i++) {
        if (isConnectedToSoftAp()) {
            // wait and try again
            EZ.threadSleep(200);
        } else {
            EZ.threadSleep(1000);
            // success, no longer connected.
            wasDisconnected = true;
            if (EZ.isUsingOlderWifiStack()) {
                // for some reason Lollipop doesn't need this??
                reenablePreviousWifi();
            }
            return;
        }
    }

    // Still connected after the above completed: fail
    throw new SetupStepException("Not disconnected from soft AP");
}
 
Example 8
Source File: SetupStepsRunnerTask.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void runSteps() throws SetupStepException, SetupProcessException {
    for (SetupStep step : steps) {

        throwIfCancelled();

        publishProgress(new StepProgress(
                step.getStepConfig().getStepId(),
                StepProgress.STARTING));

        try {
            EZ.threadSleep(1000);
            throwIfCancelled();

            step.runStep();

        } catch (SetupStepException e) {
            // give it a moment before trying again.
            EZ.threadSleep(2000);
            throw e;
        }

        publishProgress(new StepProgress(
                step.getStepConfig().getStepId(),
                StepProgress.SUCCEEDED));
    }
}