public static MobileDevice convertToMobileDevice(Device device) {
    MobileDevice mobileDevice = null;
    if (device != null) {
      mobileDevice = new MobileDevice();
      mobileDevice.setMobileDeviceId(device.getDeviceIdentifier());
      mobileDevice.setImei(getPropertyValue(device, MOBILE_DEVICE_IMEI));
      mobileDevice.setImsi(getPropertyValue(device, MOBILE_DEVICE_IMSI));
      mobileDevice.setModel(getPropertyValue(device, MOBILE_DEVICE_MODEL));
      mobileDevice.setOsVersion(getPropertyValue(device, MOBILE_DEVICE_OS_VERSION));
      mobileDevice.setVendor(getPropertyValue(device, MOBILE_DEVICE_VENDOR));
      mobileDevice.setLatitude(getPropertyValue(device, MOBILE_DEVICE_LATITUDE));
      mobileDevice.setLongitude(getPropertyValue(device, MOBILE_DEVICE_LONGITUDE));
      mobileDevice.setSerial(getPropertyValue(device, MOBILE_DEVICE_SERIAL));
      mobileDevice.setOsBuildDate(getPropertyValue(device, MOBILE_DEVICE_OS_BUILD_DATE));

      if (device.getProperties() != null) {
        Map<String, String> deviceProperties = new HashMap<String, String>();
        for (Device.Property deviceProperty : device.getProperties()) {
          deviceProperties.put(deviceProperty.getName(), deviceProperty.getValue());
        }

        mobileDevice.setDeviceProperties(deviceProperties);
      } else {
        mobileDevice.setDeviceProperties(new HashMap<String, String>());
      }
    }
    return mobileDevice;
  }
  public static Device convertToDevice(MobileDevice mobileDevice) {
    Device device = null;
    if (mobileDevice != null) {
      device = new Device();
      List<Device.Property> propertyList = new ArrayList<Device.Property>();
      propertyList.add(getProperty(MOBILE_DEVICE_IMEI, mobileDevice.getImei()));
      propertyList.add(getProperty(MOBILE_DEVICE_IMSI, mobileDevice.getImsi()));
      propertyList.add(getProperty(MOBILE_DEVICE_MODEL, mobileDevice.getModel()));
      propertyList.add(getProperty(MOBILE_DEVICE_OS_VERSION, mobileDevice.getOsVersion()));
      propertyList.add(getProperty(MOBILE_DEVICE_OS_BUILD_DATE, mobileDevice.getOsBuildDate()));
      propertyList.add(getProperty(MOBILE_DEVICE_VENDOR, mobileDevice.getVendor()));
      if (mobileDevice.getLatitude() != null) {
        propertyList.add(getProperty(MOBILE_DEVICE_LATITUDE, mobileDevice.getLatitude()));
      }
      if (mobileDevice.getLongitude() != null) {
        propertyList.add(getProperty(MOBILE_DEVICE_LONGITUDE, mobileDevice.getLongitude()));
      }
      propertyList.add(getProperty(MOBILE_DEVICE_SERIAL, mobileDevice.getSerial()));

      if (mobileDevice.getDeviceProperties() != null) {
        for (Map.Entry<String, String> deviceProperty :
            mobileDevice.getDeviceProperties().entrySet()) {
          propertyList.add(getProperty(deviceProperty.getKey(), deviceProperty.getValue()));
        }
      }

      device.setProperties(propertyList);
      device.setDeviceIdentifier(mobileDevice.getMobileDeviceId());
    }
    return device;
  }