<commit_before>package io.divide.client.android.security;

import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import io.divide.client.BackendUser;
import io.divide.client.data.ServerResponse;

/**
* Created by williamwebb on 3/20/14.
*/
public class UserUtils {
    private static final String ANONYMOUS_KEY = "anonymous_key";

    public static ServerResponse<BackendUser> getAnonymousUser(Context context){
        String id = UserUtils.getDeviceIdUnique(context);
        ServerResponse<BackendUser> response;

        response = BackendUser.signIn(id, id);
        if(!response.getStatus().isSuccess()){
            response = BackendUser.signUp(id, id, id);
            if(response.getStatus().isSuccess()){
                BackendUser user = response.get();
                user.put(ANONYMOUS_KEY,true);
                user.saveASync();
            }
        }
        return response;
    }

    public static String getDeviceIdUnique(Context context)
    {
        try {
            String a = getDeviceIdTm(context);
            String b = getDeviceIdAndroid(context);
            String c = getDeviceIdPseudo();

            if (a!=null && a.length()>0 && a.replace("0", "").length()>0)
                return a;
            else if (b!=null && b.length()>0 && b.equals("9774d56d682e549c")==false)
                return b;
            else if (c!=null && c.length()>0)
                return c;
            else
                return "";
        }
        catch(Exception ex)
        {
            return "";
        }
    }
<commit_msg>Changed UserUtils to us Observable<commit_after>package io.divide.client.android.security;

import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import io.divide.client.BackendUser;
import rx.Observable;
import rx.functions.Func1;

/**
* Created by williamwebb on 3/20/14.
*/
public class UserUtils {
    private static final String ANONYMOUS_KEY = "anonymous_key";

    public static Observable<BackendUser> getAnonymousUser(Context context){
        final String id = UserUtils.getDeviceIdUnique(context);

        return BackendUser.logInInBackground(id,id).flatMap(new Func1<BackendUser, Observable<BackendUser>>() {
            @Override
            public Observable<BackendUser> call(BackendUser user) {
                if(user != null) return Observable.from(user);
                return BackendUser.signUpInBackground(id,id,id);
            }
        }).map(new Func1<BackendUser, BackendUser>() {
            @Override
            public BackendUser call(BackendUser user) {
                user.put(ANONYMOUS_KEY,true);
                user.saveASync();
                return user;
            }
        });
    }

    public static String getDeviceIdUnique(Context context)
    {
        try {
            String a = getDeviceIdTm(context);
            String b = getDeviceIdAndroid(context);
            String c = getDeviceIdPseudo();

            if (a!=null && a.length()>0 && a.replace("0", "").length()>0)
                return a;
            else if (b!=null && b.length()>0 && b.equals("9774d56d682e549c")==false)
                return b;
            else if (c!=null && c.length()>0)
                return c;
            else
                return "";
        }
        catch(Exception ex)
        {
            return "";
        }
    }

{'fraction_non_alphanumeric': 0.11235632183908045, 'fraction_numerical': 0.013505747126436781, 'mean_word_length': 2.116383169203223, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3024608', 'n_tokens_mistral': 1011, 'n_tokens_neox': 971, 'n_words': 204}