Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro benchmark tests for CT instance creation SDK-3721 #604

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmark-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
103 changes: 103 additions & 0 deletions benchmark-app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
id("com.android.application")
alias(libs.plugins.kotlinAndroid)
}

android {
namespace = "com.clevertap.android.benchmark.app"
compileSdk = 34

defaultConfig {
applicationId = "com.clevertap.android.benchmark.app"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildTypes {
release {
signingConfig = signingConfigs.getByName("debug")
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.1"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.lifecycle.runtime.ktx)
implementation(libs.activity.compose)
implementation(platform(libs.compose.bom))
implementation(libs.ui)
implementation(libs.ui.graphics)
implementation(libs.ui.tooling.preview)
implementation(libs.material3)
implementation(libs.profileinstaller)

/* implementation(project(":clevertap-core")) //CleverTap Android SDK, make sure the AAR file is in the libs folder
implementation(project(":clevertap-geofence")) // Geofence
implementation(project(":clevertap-xps")) // For Xiaomi Push use
implementation(project(":clevertap-pushtemplates"))
implementation(project(":clevertap-hms")) // For Huawei Push use*/

implementation("com.clevertap.android:clevertap-android-sdk:6.0.0")
implementation("com.clevertap.android:clevertap-geofence-sdk:1.3.0")
implementation("com.clevertap.android:clevertap-xiaomi-sdk:1.5.4")
implementation("com.clevertap.android:push-templates:1.2.3")
implementation("com.clevertap.android:clevertap-hms-sdk:1.3.4")

implementation("com.google.android.gms:play-services-location:21.0.0") // Needed for geofence
implementation("androidx.work:work-runtime:2.7.1") // Needed for geofence
implementation("androidx.concurrent:concurrent-futures:1.1.0") // Needed for geofence

implementation("com.google.firebase:firebase-messaging:23.0.6") //Needed for FCM
implementation("com.google.android.gms:play-services-ads:20.4.0") //Needed to use Google Ad Ids
//ExoPlayer Libraries for Audio/Video InApp Notifications
implementation("com.google.android.exoplayer:exoplayer:2.19.1")
implementation("com.google.android.exoplayer:exoplayer-hls:2.19.1")
implementation("com.google.android.exoplayer:exoplayer-ui:2.19.1")
implementation("com.github.bumptech.glide:glide:4.12.0")

//Mandatory if you are using Notification Inbox
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.fragment:fragment:1.3.6")
implementation("androidx.appcompat:appcompat:1.6.0-rc01")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("androidx.viewpager:viewpager:1.0.0")

implementation("com.android.installreferrer:installreferrer:2.2")

testImplementation(libs.test.junit)
androidTestImplementation(libs.test.ext.junit)
androidTestImplementation(libs.test.espresso.core)
androidTestImplementation(platform(libs.compose.bom))
androidTestImplementation(libs.ui.test.junit4)
debugImplementation(libs.ui.tooling)
debugImplementation(libs.ui.test.manifest)
}
21 changes: 21 additions & 0 deletions benchmark-app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.clevertap.android.benchmark.app

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {

@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.clevertap.android.benchmark.app", appContext.packageName)
}
}
95 changes: 95 additions & 0 deletions benchmark-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Clevertapandroidsdk">
<profileable
android:shell="true"
tools:targetApi="29" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this have to match with android api which we use?

<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Clevertapandroidsdk">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<!--<data
android:host="${applicationId}"
android:scheme="benchmark" />-->
</intent-filter>
</activity>

<meta-data
android:name="CLEVERTAP_ACCOUNT_ID"
android:value="67Z-RRK-696Z" />
<meta-data
android:name="CLEVERTAP_TOKEN"
android:value="322-1a6" />
<meta-data
android:name="CLEVERTAP_REGION"
android:value="eu1" />
Comment on lines +34 to +42
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove these secrets?

<meta-data
android:name="CLEVERTAP_XIAOMI_APP_KEY"
android:value="@string/xiaomi_app_key" />

<meta-data
android:name="CLEVERTAP_XIAOMI_APP_ID"
android:value="@string/xiaomi_app_id" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
<meta-data
android:name="CLEVERTAP_SSL_PINNING"
android:value="0" /> <!-- Add meta data for CleverTap Notification Icon -->
<meta-data
android:name="CLEVERTAP_NOTIFICATION_ICON"
android:value="ic_notification" />
<meta-data
android:name="CLEVERTAP_BACKGROUND_SYNC"
android:value="1" /> <!-- Add meta and set to 1 to raise Notification Viewed for Push Notifications -->
<meta-data
android:name="CLEVERTAP_RAISE_NOTIFICATION_VIEWED"
android:value="1" /> <!-- Add meta and set to 1 start using custom CleverTap ID -->
<meta-data
android:name="CLEVERTAP_USE_CUSTOM_ID"
android:value="0" /> <!-- Add CleverTap Push Notification Services & Install Referrer Receivers -->
<!-- <meta-data
android:name="CLEVERTAP_IDENTIFIER"
android:value="Email,Phone" />-->

<meta-data
android:name="CLEVERTAP_ENCRYPTION_LEVEL"
android:value="1" />

<service
android:name="com.clevertap.android.sdk.pushnotification.fcm.FcmMessageListenerService"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<service
android:name="com.clevertap.android.sdk.pushnotification.CTNotificationIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.clevertap.PUSH_EVENT" />
</intent-filter>
</service>


</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.clevertap.android.benchmark.app

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.os.trace
import com.clevertap.android.benchmark.app.ui.theme.ClevertapandroidsdkTheme
import com.clevertap.android.sdk.CleverTapAPI
import com.clevertap.android.sdk.CleverTapAPI.LogLevel.VERBOSE
import com.clevertap.android.sdk.CleverTapInstanceConfig

/**
* Empty activity showing some text used for performing Macro Benchmark tests.
*/
class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ClevertapandroidsdkTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Greeting("Android")
}
}
}
Comment on lines +27 to +34
Copy link
Collaborator

@CTLalit CTLalit Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add correct title and Logo as bare minimum?


CleverTapAPI.setDebugLevel(VERBOSE)

/**
* "bm(benchmark method)" is being passed from macro benchmark tests to tell the Activity which method to benchmark
*/
when(intent?.extras?.getString("bm") ?: ""){
"initCT" -> trace("init CT") {
// val measureNanoTime = measureNanoTime {
// cleverTapDefaultInstance = CleverTapAPI.getDefaultInstance(this)
val config = CleverTapInstanceConfig.createInstance(this, "TEST-R78-ZZK-955Z", "TEST-311-ba2")
val cleverTapDefaultInstance = CleverTapAPI.instanceWithConfig(this, config)
// }
// Logger.v("nano time ct init = $measureNanoTime")
}

"initCTD" -> trace("init CTD") {
// val measureNanoTime = measureNanoTime {
val cleverTapDefaultInstance = CleverTapAPI.getDefaultInstance(this)
// }
// Logger.v("nano time ct init = $measureNanoTime")
}
else -> Log.d("MainActivity","no method specified by benchmark module")
}



Comment on lines +36 to +61
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract in method. Format correctly.

}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
ClevertapandroidsdkTheme {
Greeting("Android")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.clevertap.android.benchmark.app.ui.theme

import androidx.compose.ui.graphics.Color

val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)

val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
Loading