code: @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
      public static String generateDeviceId(@NonNull Context context) {
  
          String deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
  
          if (TextUtils.isEmpty(deviceId)) {
              deviceId = getMacAddress(context);
          }
  
          if (TextUtils.isEmpty(deviceId)) {
              try {
                  deviceId = FirebaseInstanceId.getInstance().getId();
              } catch (IllegalStateException e) {
                  //Continue.
              }
          }
  
          if (TextUtils.isEmpty(deviceId)) {
              deviceId = UUID.randomUUID().toString();
          }
  
          return deviceId;
      }
docs: Generates unique device id.
  
  @return Device unique identifier.