Check out the friends_check_friendship() function in /bp-friends.php.
The parameters are:
friends_check_friendship( $user_id, $possible_friend_id )
And it returns true if the person is a friend.
Example:
global $bp;
$is_friend = friends_check_friendship( $bp->loggedin_user->id, $bp->displayed_user->id );
if ( $is_friend ) {
run your custom code;
}