<commit_before>package mdl.sinlov.andorid.device_mark;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

/**
 * for APP create device UUID
 * <pre>
 *     sinlov
 *
 *     /\__/\
 *    /`    '\
 *  ≈≈≈ 0  0 ≈≈≈ Hello world!
 *    \  --  /
 *   /        \
 *  /          \
 * |            |
 *  \  ||  ||  /
 *   \_oo__oo_/≡≡≡≡≡≡≡≡o
 *
 * </pre>
 * Created by "sinlov" on 16/9/1.
 */
public class DeviceIDFactory {

    private static StringBuilder deviceId;
    private static String uuid32;
    private static String wifiMac;
    private static String imei;
    private static String sn;

    /**
     * this info will mark by &key#value by wifi imei sn uuid
     *
     * @param context    {@link Context}
     * @param channelTag {@link String}
     * @return {@link String}
     */
    public static String getDeviceId(Context context, String channelTag) {
        if (null == deviceId) {
            deviceId = new StringBuilder();
        } else {
            deviceId.setLength(0);
        }
        String wifiMac = getDeviceIDByMac(context, true);
        if (!TextUtils.isEmpty(wifiMac)) {
            deviceId.append("&wifi#");
            deviceId.append(wifiMac);
        }
        String imei = getDeviceIDByIMEI(context);
        if (!TextUtils.isEmpty(imei)) {
            deviceId.append("&imei#");
            deviceId.append(imei);
        }
        String sn = getDeviceIDBySN(context);
        if (!TextUtils.isEmpty(sn)) {
            deviceId.append("&sn#");
            deviceId.append(sn);
        }
        String uuid = getUUID(context);
        if (!TextUtils.isEmpty(uuid)) {
            deviceId.append("&uuid#");
            deviceId.append(uuid);
        }
        deviceId.append(channelTag);
        return deviceId.toString();
    }

    private static String bytesToString(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
        StringBuilder buf = new StringBuilder();
        for (byte b : bytes) {
            buf.append(String.format("%02X:", b));
        }
        if (buf.length() > 0) {
            buf.deleteCharAt(buf.length() - 1);
        }
        return buf.toString();
    }

    /**
     * typ get by {@link #getDeviceIDByMac()} first
     * if not has use {@link #getDeviceIDByMac(Context, boolean)}
     * even return empty or 02:00:00:00:00:00 return {@link #getUUID(Context)}
     *
     * @param context {@link Context}
     * @param force   force get
     * @return
     */
    public static String getDeviceIDByMac(Context context, boolean force) {
        if (force) {
            DeviceIDFactory.wifiMac = null;
        }
        if (!TextUtils.isEmpty(wifiMac)) {
            return wifiMac;
        }
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = getDeviceIDByMac();
            }
        }
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = readMacAddressByLinuxClassNetWlan();
            }
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = getMacAddressFromWifiManager(context);
            }
        }
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = readMacAddressByLinuxClassNetWlan();
            }
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = getMacAddressFromWifiManager(context);
            }
        }
        if (TextUtils.isEmpty(wifiMac)) {
            wifiMac = getUUID(context);
        } else {
            if (wifiMac.equals("FA:B7:F4:52:68:9E")) {
                Log.w("DeviceMac", "error get: 02:00:00:00:00:00");
                wifiMac = getUUID(context);
            }
            if (wifiMac.equals("02:00:00:00:00:00")) {
                Log.w("DeviceMac", "error get: 02:00:00:00:00:00");
                wifiMac = getUUID(context);
            }
        }
        return wifiMac;
    }

    /**
     * need open WIFI add at uses-permission android:name="android.permission.ACCESS_WIFI_STATE"
     * <p>
     * read getMacAddressByIP
     * read getDevicesHardwareAddress
     * else
     * <p>
     * finally read readMacAddressByLinuxClassNet
     *
     * @return {@link String} this will return null
     */
    public static String getDeviceIDByMac() {<commit_msg>remove over mark MAC Address<commit_after>package mdl.sinlov.andorid.device_mark;

import android.annotation.SuppressLint;
import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

/**
 * for APP create device UUID
 * <pre>
 *     sinlov
 *
 *     /\__/\
 *    /`    '\
 *  ≈≈≈ 0  0 ≈≈≈ Hello world!
 *    \  --  /
 *   /        \
 *  /          \
 * |            |
 *  \  ||  ||  /
 *   \_oo__oo_/≡≡≡≡≡≡≡≡o
 *
 * </pre>
 * Created by "sinlov" on 16/9/1.
 */
public class DeviceIDFactory {

    private static StringBuilder deviceId;
    private static String uuid32;
    private static String wifiMac;
    private static String imei;
    private static String sn;

    /**
     * this info will mark by &key#value by wifi imei sn uuid
     *
     * @param context    {@link Context}
     * @param channelTag {@link String}
     * @return {@link String}
     */
    public static String getDeviceId(Context context, String channelTag) {
        if (null == deviceId) {
            deviceId = new StringBuilder();
        } else {
            deviceId.setLength(0);
        }
        String wifiMac = getDeviceIDByMac(context, true);
        if (!TextUtils.isEmpty(wifiMac)) {
            deviceId.append("&wifi#");
            deviceId.append(wifiMac);
        }
        String imei = getDeviceIDByIMEI(context);
        if (!TextUtils.isEmpty(imei)) {
            deviceId.append("&imei#");
            deviceId.append(imei);
        }
        String sn = getDeviceIDBySN(context);
        if (!TextUtils.isEmpty(sn)) {
            deviceId.append("&sn#");
            deviceId.append(sn);
        }
        String uuid = getUUID(context);
        if (!TextUtils.isEmpty(uuid)) {
            deviceId.append("&uuid#");
            deviceId.append(uuid);
        }
        deviceId.append(channelTag);
        return deviceId.toString();
    }

    private static String bytesToString(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
        StringBuilder buf = new StringBuilder();
        for (byte b : bytes) {
            buf.append(String.format("%02X:", b));
        }
        if (buf.length() > 0) {
            buf.deleteCharAt(buf.length() - 1);
        }
        return buf.toString();
    }

    /**
     * typ get by {@link #getDeviceIDByMac()} first
     * if not has use {@link #getDeviceIDByMac(Context, boolean)}
     * even return empty or 02:00:00:00:00:00 return {@link #getUUID(Context)}
     *
     * @param context {@link Context}
     * @param force   force get
     * @return
     */
    public static String getDeviceIDByMac(Context context, boolean force) {
        if (force) {
            DeviceIDFactory.wifiMac = null;
        }
        if (!TextUtils.isEmpty(wifiMac)) {
            return wifiMac;
        }
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = getDeviceIDByMac();
            }
        }
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) {
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = readMacAddressByLinuxClassNetWlan();
            }
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = getMacAddressFromWifiManager(context);
            }
        }
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = readMacAddressByLinuxClassNetWlan();
            }
            if (TextUtils.isEmpty(wifiMac)) {
                wifiMac = getMacAddressFromWifiManager(context);
            }
        }
        if (TextUtils.isEmpty(wifiMac)) {
            wifiMac = getUUID(context);
        } else {
            if (wifiMac.equals("02:00:00:00:00:00")) {
                Log.w("DeviceMac", "error get: 02:00:00:00:00:00");
                wifiMac = getUUID(context);
            }
        }
        return wifiMac;
    }

    /**
     * need open WIFI add at uses-permission android:name="android.permission.ACCESS_WIFI_STATE"
     * <p>
     * read getMacAddressByIP
     * read getDevicesHardwareAddress
     * else
     * <p>
     * finally read readMacAddressByLinuxClassNet
     *
     * @return {@link String} this will return null
     */
    public static String getDeviceIDByMac() {
{'fraction_non_alphanumeric': 0.12181742910370524, 'fraction_numerical': 0.012316290623059408, 'mean_word_length': 1.999068901303538, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '6723148', 'n_tokens_mistral': 3021, 'n_tokens_neox': 2960, 'n_words': 600}