Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development'
Browse files Browse the repository at this point in the history
  • Loading branch information
dsilhavy committed Jan 25, 2024
2 parents 9562d85 + 5722422 commit 99bc51d
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 34 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions app/build.gradle
Expand Up @@ -13,7 +13,7 @@ android {
minSdk 29
targetSdk 32
versionCode 1
versionName "1.0.2"
versionName "1.1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -38,7 +38,7 @@ publishing {
release(MavenPublication) {
groupId = 'com.fivegmag'
artifactId = 'a5gmscommonlibrary'
version = '1.0.2'
version = '1.1.0'

afterEvaluate {
from components.release
Expand All @@ -63,6 +63,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation "androidx.media3:media3-exoplayer:1.0.2"
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.1'
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin:2.12.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
@@ -0,0 +1,42 @@
/*
License: 5G-MAG Public License (v1.0)
Author: Daniel Silhavy
Copyright: (C) 2023 Fraunhofer FOKUS
For full license terms please see the LICENSE file distributed with this
program. If this file is missing then the license can be retrieved from
https://drive.google.com/file/d/1cinCiA778IErENZ3JN52VFW-1ffHpx7Z/view
*/

package com.fivegmag.a5gmscommonlibrary.consumptionReporting

import android.os.Parcelable
import com.fasterxml.jackson.annotation.JsonFilter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fivegmag.a5gmscommonlibrary.models.EndpointAddress
import com.fivegmag.a5gmscommonlibrary.models.TypedLocation
import kotlinx.parcelize.Parcelize

@Parcelize
@JsonIgnoreProperties(ignoreUnknown = true)
data class ConsumptionReport(
val mediaPlayerEntry: String,
val reportingClientId: String,
val consumptionReportingUnits: ArrayList<ConsumptionReportingUnit>
) : Parcelable

@Parcelize
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonFilter("consumptionReportingUnitFilter")
data class ConsumptionReportingUnit(
val mediaConsumed: String,
var clientEndpointAddress: EndpointAddress? = null,
var serverEndpointAddress: EndpointAddress? = null,
val startTime: String,
var duration: Int,
var locations: ArrayList<TypedLocation>? = ArrayList(),
@JsonIgnore
var mimeType: String? = null,
@JsonIgnore
var finished: Boolean = false
) : Parcelable
@@ -1,4 +1,26 @@
package com.fivegmag.a5gmscommonlibrary.eventbus

import android.telephony.CellInfo
import androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime
import androidx.media3.exoplayer.source.LoadEventInfo
import androidx.media3.exoplayer.source.MediaLoadData

class DownstreamFormatChangedEvent(val mediaLoadData: MediaLoadData)
class DownstreamFormatChangedEvent(
val eventTime: EventTime,
val mediaLoadData: MediaLoadData
)

class PlaybackStateChangedEvent(
val eventTime: EventTime,
val playbackState: String
)

class LoadStartedEvent(
val eventTime: EventTime,
val loadEventInfo: LoadEventInfo,
val mediaLoadData: MediaLoadData
)

class CellInfoUpdatedEvent(
val cellInfoList: MutableList<CellInfo>
)
Expand Up @@ -37,6 +37,9 @@ object SessionHandlerMessageTypes {
const val UPDATE_LOOKUP_TABLE = 8
const val SET_M5_ENDPOINT = 9
const val START_PLAYBACK_BY_SERVICE_LIST_ENTRY_MESSAGE = 10
const val GET_CONSUMPTION_REPORT = 11
const val CONSUMPTION_REPORT = 12
const val UPDATE_PLAYBACK_CONSUMPTION_REPORTING_CONFIGURATION = 13
}

object SessionHandlerEvents {
Expand All @@ -54,4 +57,10 @@ object ContentTypes {
object UserAgentTokens {
const val FIVE_G_MS_REL_17_MEDIA_STREAM_HANDLER = "5GMSMediaStreamHandler/17"
const val FIVE_G_MS_REL_17_MEDIA_SESSION_HANDLER = "5GMSMediaSessionHandler/17"
}

object HostInfoTypes {
const val IP_V4 = "ipv4"
const val IP_V6 = "ipv6"
const val DOMAIN_NAME = "domain_name"
}
112 changes: 111 additions & 1 deletion app/src/main/java/com/fivegmag/a5gmscommonlibrary/helpers/Utils.kt
@@ -1,11 +1,18 @@
package com.fivegmag.a5gmscommonlibrary.helpers

import com.fivegmag.a5gmscommonlibrary.models.EndpointAddress
import com.fivegmag.a5gmscommonlibrary.models.HostInfo
import java.text.SimpleDateFormat
import java.time.Duration
import java.util.Date
import java.util.Random
import java.util.TimeZone
import okhttp3.Headers
import java.net.NetworkInterface
import java.net.URL
import java.time.Instant
import java.util.Locale
import java.util.UUID

class Utils {

Expand All @@ -25,6 +32,23 @@ class Utils {
return dateFormat.format(date)
}

fun generateUUID(): String {
val uuid = UUID.randomUUID()
return uuid.toString()
}

fun formatDateToOpenAPIFormat(date: Date): String {
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault())
return format.format(date)
}

fun calculateTimestampDifferenceInSeconds(timestamp1: String, timestamp2: String): Long {
val instant1 = Instant.parse(timestamp1)
val instant2 = Instant.parse(timestamp2)
val duration = Duration.between(instant1, instant2)
return duration.seconds
}

fun getCurrentXsDateTime(): String {
val currentTimestamp = getCurrentTimestamp()

Expand Down Expand Up @@ -69,7 +93,7 @@ class Utils {
}
val headersToValidate = arrayOf("last-modified", "etag")

return headersToValidate.all { header ->
return headersToValidate.any { header ->
hasHeaderChanged(
headers.get(header),
previousResponseHeaders.get(header)
Expand All @@ -80,4 +104,90 @@ class Utils {
private fun hasHeaderChanged(headerA: String?, headerB: String?): Boolean {
return headerA == null || headerB == null || headerA != headerB
}

fun getIpAddress(ipVer: Int): String? {
val interfaces = NetworkInterface.getNetworkInterfaces()
while (interfaces.hasMoreElements()) {
val networkInterface = interfaces.nextElement()
val addresses = networkInterface.inetAddresses
while (addresses.hasMoreElements()) {
val address = addresses.nextElement()
if (!address.isLoopbackAddress && address.isSiteLocalAddress) {
if ((ipVer == 4 && address.hostAddress.contains(".")) ||
(ipVer == 6 && address.hostAddress.contains(":"))
) {
return address.hostAddress.toString()
}
}
}
}

return null
}

fun getHostInfo(urlString: String): HostInfo? {
try {
val url = URL(urlString)
val host = url.host

// Check if it's a valid IPv4 address
val ipv4Regex = """^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$""".toRegex()
if (ipv4Regex.matches(host)) {
return HostInfo(HostInfoTypes.IP_V4, host)
}

// Check if it's a valid IPv6 address
val ipv6Regex = """^\[([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}\]$""".toRegex()
if (ipv6Regex.matches(host)) {
return HostInfo(HostInfoTypes.IP_V6, host)
}

// Remove leading "www." from the domain
val domain = if (host.startsWith("www.")) host.substring(4) else host

// Assume it's a domain name
return HostInfo(HostInfoTypes.DOMAIN_NAME, domain)
} catch (e: Exception) {
return null
}
}

fun getPort(url: String): Int? {
try {
val url = URL(url)
val port = url.port
if (port == -1) {
return url.defaultPort
}

return port
} catch (e: Exception) {
return null
}
}

fun getEndpointAddressByRequestUrl(
requestUrl: String
): EndpointAddress? {
try {
val hostInfo = getHostInfo(requestUrl)
val port = getPort(requestUrl)

if (hostInfo != null && port != null) {
return when (hostInfo.type) {
HostInfoTypes.IP_V4 -> EndpointAddress(null, hostInfo.host, null, port)
HostInfoTypes.IP_V6 -> EndpointAddress(null, null, hostInfo.host, port)
HostInfoTypes.DOMAIN_NAME -> EndpointAddress(hostInfo.host, null, null, port)
else -> null
}
}

return null

} catch (e: Exception) {
return null
}

}

}

This file was deleted.

@@ -0,0 +1,16 @@
package com.fivegmag.a5gmscommonlibrary.models

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class PlaybackRequest(
val entryPoints: ArrayList<EntryPoint>,
val playbackConsumptionReportingConfiguration: PlaybackConsumptionReportingConfiguration
) : Parcelable

@Parcelize
data class PlaybackConsumptionReportingConfiguration(
var accessReporting : Boolean? = false,
var locationReporting : Boolean? = false
) : Parcelable
Expand Up @@ -16,10 +16,20 @@ import kotlinx.parcelize.Parcelize
data class ServiceAccessInformation(
val provisioningSessionId : String,
val provisioningSessionType: String?,
val streamingAccess: StreamingAccess
val streamingAccess: StreamingAccess,
var clientConsumptionReportingConfiguration: ClientConsumptionReportingConfiguration?
) : Parcelable

@Parcelize
data class StreamingAccess(
val entryPoints: ArrayList<EntryPoint>?
) : Parcelable

@Parcelize
data class ClientConsumptionReportingConfiguration(
val serverAddresses : ArrayList<String>,
val locationReporting: Boolean,
val samplePercentage: Float,
val reportingInterval: Int? = null,
val accessReporting: Boolean
) : Parcelable
Expand Up @@ -9,13 +9,30 @@ https://drive.google.com/file/d/1cinCiA778IErENZ3JN52VFW-1ffHpx7Z/view

package com.fivegmag.a5gmscommonlibrary.models

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class TypedLocation(
val locationIdentifierType: String,
val locationIdentifierType: CellIdentifierType,
val location: String
)
) : Parcelable

@Parcelize
data class EndpointAddress(
val domainName: String? = null,
val ipv4Addr: String? = null,
val ipv6Addr: String? = null,
val portNumber: UInt
val portNumber: Int
) : Parcelable

@Parcelize
enum class CellIdentifierType : Parcelable {
CGI,
ECGI,
NCGI
}
data class HostInfo(
val type: String,
val host: String
)

0 comments on commit 99bc51d

Please sign in to comment.