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

The following examples show how to use io.particle.android.sdk.utils.Py. 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: ParticleAccessToken.java    From particle-android with Apache License 2.0 6 votes vote down vote up
@Nullable
public static synchronized ParticleAccessToken fromSavedSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    String accessToken = sensitiveDataStorage.getToken();
    String refreshToken = sensitiveDataStorage.getRefreshToken();
    Date expirationDate = sensitiveDataStorage.getTokenExpirationDate();

    // are either of the fields "falsey" or has the expr date passed?
    if (!Py.truthy(accessToken) || !Py.truthy(expirationDate) || expirationDate.before(new Date())) {
        return null;
    }

    ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
            new Handler(Looper.getMainLooper()));
    token.scheduleExpiration();
    return token;
}
 
Example #2
Source File: ParticleAccessToken.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
@Nullable
public static synchronized ParticleAccessToken fromSavedSession() {
    SensitiveDataStorage sensitiveDataStorage = SDKGlobals.getSensitiveDataStorage();
    String accessToken = sensitiveDataStorage.getToken();
    String refreshToken = sensitiveDataStorage.getRefreshToken();
    Date expirationDate = sensitiveDataStorage.getTokenExpirationDate();

    // are either of the fields "falsey" or has the expr date passed?
    if (!Py.truthy(accessToken) || !Py.truthy(expirationDate) || expirationDate.before(new Date())) {
        return null;
    }

    ParticleAccessToken token = new ParticleAccessToken(accessToken, expirationDate, refreshToken,
            new Handler(Looper.getMainLooper()));
    token.scheduleExpiration();
    return token;
}
 
Example #3
Source File: ConnectingProcessWorkerTask.java    From particle-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPostExecute(SetupProcessException error) {
    int resultCode;

    if (error != null) {
        resultCode = error.failedStep.getStepConfig().resultCode;

    } else {
        log.d("HUZZAH, VICTORY!");
        resultCode = SuccessActivity.RESULT_SUCCESS;

        if (!BaseActivity.setupOnly) {
            EZ.runAsync(() -> {
                try {
                    // collect a list of unique, non-null device names
                    Set<String> names = set(Funcy.transformList(
                            sparkCloud.getDevices(),
                            Funcy.notNull(),
                            ParticleDevice::getName,
                            Py::truthy
                    ));
                    ParticleDevice device = sparkCloud.getDevice(deviceId);
                    if (device != null && !truthy(device.getName())) {
                        device.setName(CoreNameGenerator.generateUniqueName(names));
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
    }

    Activity activity = activityReference.get();
    if (activity != null) {
        activity.startActivity(SuccessActivity.buildIntent(activity, resultCode, deviceId));
        activity.finish();
    }
}
 
Example #4
Source File: ParticleAccessToken.java    From particle-android with Apache License 2.0 5 votes vote down vote up
public static synchronized ParticleAccessToken fromNewSession(Responses.LogInResponse logInResponse) {
    if (!Py.truthy(logInResponse.getAccessToken()) || !"bearer".equalsIgnoreCase(logInResponse.getTokenType())) {
        throw new IllegalArgumentException("Invalid LogInResponse: " + logInResponse);
    }

    long expirationMillis = logInResponse.getExpiresInSeconds() * 1000;
    Date expirationDate = new Date(System.currentTimeMillis() + expirationMillis);
    return fromTokenData(expirationDate, logInResponse.getAccessToken(), logInResponse.getRefreshToken());
}
 
Example #5
Source File: ParticleAccessToken.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
public static synchronized ParticleAccessToken fromNewSession(Responses.LogInResponse logInResponse) {
    if (!Py.truthy(logInResponse.accessToken) || !"bearer".equalsIgnoreCase(logInResponse.tokenType)) {
        throw new IllegalArgumentException("Invalid LogInResponse: " + logInResponse);
    }

    long expirationMillis = logInResponse.expiresInSeconds * 1000;
    Date expirationDate = new Date(System.currentTimeMillis() + expirationMillis);
    return fromTokenData(expirationDate, logInResponse.accessToken, logInResponse.refreshToken);
}
 
Example #6
Source File: ConnectingProcessWorkerTask.java    From spark-setup-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(SetupProcessException error) {
    int resultCode;

    if (error != null) {
        resultCode = error.failedStep.getStepConfig().resultCode;

    } else {
        log.d("HUZZAH, VICTORY!");
        // FIXME: handle "success, no ownership" case
        resultCode = SuccessActivity.RESULT_SUCCESS;

        if (!BaseActivity.setupOnly) {
            EZ.runAsync(() -> {
                try {
                    // collect a list of unique, non-null device names
                    Set<String> names = set(Funcy.transformList(
                            sparkCloud.getDevices(),
                            Funcy.notNull(),
                            ParticleDevice::getName,
                            Py::truthy
                    ));
                    ParticleDevice device = sparkCloud.getDevice(deviceId);
                    if (device != null && !truthy(device.getName())) {
                        device.setName(CoreNameGenerator.generateUniqueName(names));
                    }
                } catch (Exception e) {
                    // FIXME: do real error handling here, and only
                    // handle ParticleCloudException instead of swallowing everything
                    e.printStackTrace();
                }
            });
        }
    }

    Activity activity = activityReference.get();
    if (activity != null) {
        activity.startActivity(SuccessActivity.buildIntent(activity, resultCode, deviceId));
        activity.finish();
    }
}