io.particle.android.sdk.utils.Preconditions Java Examples

The following examples show how to use io.particle.android.sdk.utils.Preconditions. 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: NextActivitySelector.java    From particle-android with Apache License 2.0 5 votes vote down vote up
private NextActivitySelector(ParticleCloud cloud,
                             SensitiveDataStorage credStorage,
                             SetupCompleteIntentBuilder setupCompleteIntentBuilder) {
    Preconditions.checkNotNull(setupCompleteIntentBuilder, "SetupCompleteIntentBuilder instance is null");

    this.cloud = cloud;
    this.credStorage = credStorage;
    this.setupCompleteIntentBuilder = setupCompleteIntentBuilder;
}
 
Example #2
Source File: EnsureSoftApNotVisible.java    From particle-android with Apache License 2.0 5 votes vote down vote up
EnsureSoftApNotVisible(StepConfig stepConfig, SSID softApSSID, WifiFacade wifiFacade) {
    super(stepConfig);
    Preconditions.checkNotNull(softApSSID, "softApSSID cannot be null.");
    this.wifiFacade = wifiFacade;
    this.softApName = softApSSID;
    this.matchesSoftApSSID = softApName::equals;
}
 
Example #3
Source File: ParticleDeviceSetupLibrary.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
/**
 * Start the device setup process.
 *
 * @deprecated Use {@link ParticleDeviceSetupLibrary#startDeviceSetup(Context, Class)}
 * or {@link ParticleDeviceSetupLibrary#startDeviceSetup(Context, SetupCompleteIntentBuilder)} instead.
 */
@Deprecated
public static void startDeviceSetup(Context ctx) {
    Preconditions.checkNotNull(instance.setupCompleteIntentBuilder,
            "SetupCompleteIntentBuilder instance is null");

    ctx.startActivity(new Intent(ctx, GetReadyActivity.class));
}
 
Example #4
Source File: ParticleDeviceSetupLibrary.java    From particle-android with Apache License 2.0 5 votes vote down vote up
/**
 * Start the device setup process.
 *
 * @deprecated Use {@link ParticleDeviceSetupLibrary#startDeviceSetup(Context, Class)}
 * or {@link ParticleDeviceSetupLibrary#startDeviceSetup(Context, SetupCompleteIntentBuilder)} instead.
 */
@Deprecated
public static void startDeviceSetup(Context ctx) {
    Preconditions.checkNotNull(instance.setupCompleteIntentBuilder,
            "SetupCompleteIntentBuilder instance is null");

    ctx.startActivity(new Intent(ctx, GetReadyActivity.class));
}
 
Example #5
Source File: ParticleUser.java    From particle-android with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize ParticleUser class with new credentials and store session in keychain
 */
public static synchronized ParticleUser fromNewCredentials(String user, String password) {
    Preconditions.checkArgument(truthy(user), "Username cannot be empty or null");
    Preconditions.checkArgument(truthy(password), "Password cannot be empty or null");

    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.saveUser(user);
    sensitiveDataStorage.savePassword(password);

    return new ParticleUser(user, password);
}
 
Example #6
Source File: ParticleDevice.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Call a function on the device
 *
 * @param functionName Function name
 * @param args         Array of arguments to pass to the function on the device.
 *                     Arguments must not be more than MAX_PARTICLE_FUNCTION_ARG_LENGTH chars
 *                     in length. If any arguments are longer, a runtime exception will be thrown.
 * @return result code: a value of 1 indicates success
 */
@WorkerThread
public int callFunction(String functionName, @Nullable List<String> args)
        throws ParticleCloudException, IOException, FunctionDoesNotExistException {
    // TODO: check response of calling a non-existent function
    if (!deviceState.functions.contains(functionName)) {
        throw new FunctionDoesNotExistException(functionName);
    }

    // null is accepted here, but it won't be in the Retrofit API call later
    if (args == null) {
        args = list();
    }

    String argsString = ParticleInternalStringUtils.join(args, ',');
    Preconditions.checkArgument(argsString.length() < MAX_PARTICLE_FUNCTION_ARG_LENGTH,
            String.format("Arguments '%s' exceed max args length of %d",
                    argsString, MAX_PARTICLE_FUNCTION_ARG_LENGTH));

    Responses.CallFunctionResponse response;
    try {
        response = mainApi.callFunction(deviceState.deviceId, functionName,
                new FunctionArgs(argsString));
    } catch (RetrofitError e) {
        throw new ParticleCloudException(e);
    }

    if (!response.connected) {
        cloud.onDeviceNotConnected(deviceState);
        throw new IOException("Device is not connected.");
    } else {
        return response.returnValue;
    }
}
 
Example #7
Source File: ParticleUser.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize ParticleUser class with new credentials and store session in keychain
 */
public static synchronized ParticleUser fromNewCredentials(String user, String password) {
    Preconditions.checkArgument(truthy(user), "Username cannot be empty or null");
    Preconditions.checkArgument(truthy(password), "Password cannot be empty or null");

    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    sensitiveDataStorage.saveUser(user);
    sensitiveDataStorage.savePassword(password);

    return new ParticleUser(user, password);
}
 
Example #8
Source File: NextActivitySelector.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private NextActivitySelector(ParticleCloud cloud,
                             SensitiveDataStorage credStorage,
                             SetupCompleteIntentBuilder setupCompleteIntentBuilder) {
    Preconditions.checkNotNull(setupCompleteIntentBuilder, "SetupCompleteIntentBuilder instance is null");

    this.cloud = cloud;
    this.credStorage = credStorage;
    this.setupCompleteIntentBuilder = setupCompleteIntentBuilder;
}
 
Example #9
Source File: EnsureSoftApNotVisible.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
EnsureSoftApNotVisible(StepConfig stepConfig, SSID softApSSID, WifiFacade wifiFacade) {
    super(stepConfig);
    Preconditions.checkNotNull(softApSSID, "softApSSID cannot be null.");
    this.wifiFacade = wifiFacade;
    this.softApName = softApSSID;
    this.matchesSoftApSSID = softApName::equals;
}
 
Example #10
Source File: ParticleDeviceSetupLibrary.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
public static ParticleDeviceSetupLibrary getInstance() {
    Preconditions.checkNotNull(instance,
            "Library instance is null: did you call ParticleDeviceSetupLibrary.init()?");
    return instance;
}
 
Example #11
Source File: StepConfig.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
public StepConfig build() {
    Preconditions.checkArgument(maxAttempts > 0, "Max attempts must be > 0");
    Preconditions.checkArgument(stepId != 0, "Step ID cannot be unset or set to 0");
    Preconditions.checkArgument(resultCode != 0, "Result code cannot be unset or set to 0");
    return new StepConfig(maxAttempts, stepId, resultCode);
}
 
Example #12
Source File: WaitForDisconnectionFromDeviceStep.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
WaitForDisconnectionFromDeviceStep(StepConfig stepConfig, SSID softApSSID, WifiFacade wifiFacade) {
    super(stepConfig);
    Preconditions.checkNotNull(softApSSID, "softApSSID cannot be null.");
    this.softApName = softApSSID;
    this.wifiFacade = wifiFacade;
}
 
Example #13
Source File: SetCommand.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
public SetCommand(String key, String value) {
    Preconditions.checkNotNull(key, "Key cannot be null");
    Preconditions.checkNotNull(value, "Value cannot be null");
    this.key = key;
    this.value = value;
}
 
Example #14
Source File: ParticleDeviceSetupLibrary.java    From particle-android with Apache License 2.0 4 votes vote down vote up
public static ParticleDeviceSetupLibrary getInstance() {
    Preconditions.checkNotNull(instance,
            "Library instance is null: did you call ParticleDeviceSetupLibrary.init()?");
    return instance;
}
 
Example #15
Source File: StepConfig.java    From particle-android with Apache License 2.0 4 votes vote down vote up
public StepConfig build() {
    Preconditions.checkArgument(maxAttempts > 0, "Max attempts must be > 0");
    Preconditions.checkArgument(stepId != 0, "Step ID cannot be unset or set to 0");
    Preconditions.checkArgument(resultCode != 0, "Result code cannot be unset or set to 0");
    return new StepConfig(maxAttempts, stepId, resultCode);
}
 
Example #16
Source File: WaitForDisconnectionFromDeviceStep.java    From particle-android with Apache License 2.0 4 votes vote down vote up
WaitForDisconnectionFromDeviceStep(StepConfig stepConfig, SSID softApSSID, WifiFacade wifiFacade) {
    super(stepConfig);
    Preconditions.checkNotNull(softApSSID, "softApSSID cannot be null.");
    this.softApName = softApSSID;
    this.wifiFacade = wifiFacade;
}
 
Example #17
Source File: SetCommand.java    From particle-android with Apache License 2.0 4 votes vote down vote up
public SetCommand(String key, String value) {
    Preconditions.checkNotNull(key, "Key cannot be null");
    Preconditions.checkNotNull(value, "Value cannot be null");
    this.key = key;
    this.value = value;
}