Skip to content

Commit

Permalink
Merge pull request #164 from CleverTap/develop
Browse files Browse the repository at this point in the history
SDK-710 CT Android SDK Releases
  • Loading branch information
piyush-kukadiya authored Apr 13, 2021
2 parents 15a4beb + 85614b3 commit 30199cf
Show file tree
Hide file tree
Showing 376 changed files with 15,102 additions and 22,177 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## CHANGE LOG

### April 13, 2021

* [CleverTap Android SDK v4.1.0](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTCORECHANGELOG.md)
* [CleverTap Geofence SDK v1.0.2](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTGEOFENCECHANGELOG.md)
* [CleverTap Xiaomi Push SDK v1.0.1](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTXIAOMIPUSHCHANGELOG.md)
* [CleverTap Huawei Push SDK v1.0.1](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTHUAWEIPUSHCHANGELOG.md)

### February 21, 2021

* [CleverTap Android SDK v4.0.3](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTCORECHANGELOG.md)
Expand Down
30 changes: 8 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
<p align="center">
<img src="https://github.com/CleverTap/clevertap-android-sdk/blob/master/static/clevertap-logo.png" width="300"/>
<img src="https://github.com/CleverTap/clevertap-ios-sdk/blob/master/docs/images/clevertap-logo.png" height="220"/>
</p>

# CleverTap Android SDKs
[![Build Status](https://app.bitrise.io/app/09efc6b9404a6341/status.svg?token=TejL3E1NHyTiR5ajHKGJ6Q)](https://app.bitrise.io/app/09efc6b9404a6341)
[![codebeat badge](https://codebeat.co/badges/49b05fa0-4228-443c-9f1c-d11efa6d2ef8)](https://codebeat.co/projects/github-com-clevertap-clevertap-android-sdk-master)
[ ![Download](https://api.bintray.com/packages/clevertap/Maven/CleverTapAndroidSDK/images/download.svg) ](https://bintray.com/clevertap/Maven/CleverTapAndroidSDK/_latestVersion)

## ⍗ Table of contents
* [Introduction](#-introduction)
* [Installation](#-installation)
* [Dependencies](#-dependencies)
* [Integration](#-integration)
* [Initialization](#-initialization)
* [Example Usage](#-example-usage)
* [CleverTap Geofence SDK](#-clevertap-geofence-sdk)
* [CleverTap Xiaomi Push SDK](#-clevertap-xiaomi-push-sdk)
* [CleverTap Huawei Push SDK](#-clevertap-huawei-push-sdk)
* [License](#-license)
[![Download](https://api.bintray.com/packages/clevertap/Maven/CleverTapAndroidSDK/images/download.svg) ](https://bintray.com/clevertap/Maven/CleverTapAndroidSDK/_latestVersion)

## 👋 Introduction
[(Back to top)](#-table-of-contents)
Expand All @@ -33,19 +20,19 @@ To get started, sign up [here](https://clevertap.com/live-product-demo/)
## 🎉 Installation
[(Back to top)](#-table-of-contents)

We publish the SDK to `jcenter` and `mavenCentral` as an `AAR` file. Just declare it as dependency in your `build.gradle` file.
We publish the SDK to `mavenCentral` as an `AAR` file. Just declare it as dependency in your `build.gradle` file.

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:4.0.4"
implementation "com.clevertap.android:clevertap-android-sdk:4.1.0"
}
```

Alternatively, you can download and add the AAR file included in this repo in your Module libs directory and tell gradle to install it like this:

```groovy
dependencies {
implementation (name: "clevertap-android-sdk-4.0.4", ext: 'aar')
implementation (name: "clevertap-android-sdk-4.1.0", ext: 'aar')
}
```

Expand All @@ -57,7 +44,7 @@ Add the Firebase Messaging library and Android Support Library v4 as dependencie

```groovy
dependencies {
implementation "com.clevertap.android:clevertap-android-sdk:4.0.4"
implementation "com.clevertap.android:clevertap-android-sdk:4.1.0"
implementation "androidx.core:core:1.3.0"
implementation "com.google.firebase:firebase-messaging:20.2.4"
implementation "com.google.android.gms:play-services-ads:19.4.0" // Required only if you enable Google ADID collection in the SDK (turned off by default).
Expand All @@ -73,7 +60,7 @@ Also be sure to include the `google-services.json` classpath in your Project lev
buildscript {
repositories {
google()
jcenter()
mavenCentral()
// if you are including the aar file manually in your Module libs directory add this:
flatDir {
Expand Down Expand Up @@ -104,7 +91,7 @@ Interstitial InApp Notification templates support Audio and Video with the help
implementation "com.google.android.exoplayer:exoplayer-ui:2.11.5"
```

Once you've updated your module `build.gradle` file, make sure you have specified `jcenter()` and `google()` as a repositories in your project `build.gradle` and then sync your project in File -> Sync Project with Gradle Files.
Once you've updated your module `build.gradle` file, make sure you have specified `mavenCentral()` and `google()` as a repositories in your project `build.gradle` and then sync your project in File -> Sync Project with Gradle Files.

## 🎉 Integration
[(Back to top)](#-table-of-contents)
Expand Down Expand Up @@ -195,7 +182,6 @@ CleverTap Xiaomi Push SDK provides an out of the box service to use the Xiaomi P

CleverTap Huawei Push SDK provides an out of the box service to use the Huawei Messaging Service. Find the integration steps for the CleverTap Huawei Push SDK [here](https://github.com/CleverTap/clevertap-android-sdk/blob/master/docs/CTHUAWEIPUSH.md)


## 📄 License
[(Back to top)](#-table-of-contents)
CleverTap Android SDK is MIT licensed, as found in the [LICENSE](https://github.com/CleverTap/clevertap-android-sdk/blob/master/LICENSE) file.
22 changes: 17 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
apply plugin: 'org.sonarqube'

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
// do not change order of apply
Expand All @@ -6,32 +8,42 @@ buildscript {

repositories {
google()// Google's Maven repository
jcenter()
maven { url 'http://developer.huawei.com/repo/' }
mavenCentral()
gradlePluginPortal()
maven { url 'http://developer.huawei.com/repo/' }

}
dependencies {
classpath "com.android.tools.build:gradle:$gradlePluginVersion"
classpath "com.google.gms:google-services:$googleServicesPluginVersion"// Google Services plugin
classpath "com.github.dcendents:android-maven-gradle-plugin:$mavenPluginVersion"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintrayPluginVersion"
classpath "com.huawei.agconnect:agcp:$huaweiPluginVersion"// Huawei Push Plugin
classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1.1"
}
}

allprojects {
repositories {
jcenter()
google()
mavenCentral()
gradlePluginPortal()
maven { url 'http://developer.huawei.com/repo/' }
flatDir {
dirs 'libs'
}
}
}

sonarqube {
properties {
property "sonar.projectKey", "CleverTap_clevertap-android-sdk"
property "sonar.organization", "clevertap"
property "sonar.host.url", "https://sonarcloud.io"
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Expand All @@ -51,4 +63,4 @@ task copyTemplates {
expand('ext': project.ext.properties)
}
}
}
}
13 changes: 9 additions & 4 deletions clevertap-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ ext {
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]

minSdkVersionVal = 16
}

apply from: "../gradle-scripts/commons.gradle"
Expand All @@ -31,7 +29,14 @@ dependencies {

// Unit testing dependencies
testImplementation project(':test_shared')
testImplementation deps.androidXCoreKTX
testImplementation deps.kotlinStdlib
testImplementation deps.firebaseMessaging
}

sonarqube {
properties {
property "sonar.projectKey", "CleverTap_clevertap-android-sdk"
property "sonar.organization", "clevertap"
property "sonar.host.url", "https://sonarcloud.io"
}
}

2 changes: 1 addition & 1 deletion clevertap-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:theme="@android:style/Theme.Translucent.NoTitleBar" />

<activity
android:name="com.clevertap.android.sdk.CTInboxActivity"
android:name="com.clevertap.android.sdk.inbox.CTInboxActivity"
android:configChanges="keyboardHidden"
android:theme="@style/Theme.AppCompat.DayNight.DarkActionBar" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
package com.clevertap.android.sdk;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import com.android.installreferrer.api.InstallReferrerClient;
import com.android.installreferrer.api.InstallReferrerStateListener;
import com.android.installreferrer.api.ReferrerDetails;
import com.clevertap.android.sdk.events.BaseEventQueueManager;
import com.clevertap.android.sdk.inapp.InAppController;
import com.clevertap.android.sdk.pushnotification.PushProviders;
import com.clevertap.android.sdk.task.CTExecutorFactory;
import com.clevertap.android.sdk.task.Task;
import java.util.concurrent.Callable;

class ActivityLifeCycleManager {

private final AnalyticsManager analyticsManager;

private final BaseEventQueueManager baseEventQueueManager;

private final BaseCallbackManager callbackManager;

private final CleverTapInstanceConfig config;

private final Context context;

private final CoreMetaData coreMetaData;

private final InAppController inAppController;

private final PushProviders pushProviders;

private final SessionManager sessionManager;

ActivityLifeCycleManager(Context context,
CleverTapInstanceConfig config,
AnalyticsManager analyticsManager,
CoreMetaData coreMetaData,
SessionManager sessionManager,
PushProviders pushProviders,
BaseCallbackManager callbackManager,
InAppController inAppController,
BaseEventQueueManager baseEventQueueManager) {
this.context = context;
this.config = config;
this.analyticsManager = analyticsManager;
this.coreMetaData = coreMetaData;
this.sessionManager = sessionManager;
this.pushProviders = pushProviders;
this.callbackManager = callbackManager;
this.inAppController = inAppController;
this.baseEventQueueManager = baseEventQueueManager;
}

//Lifecycle
public void activityPaused() {
CoreMetaData.setAppForeground(false);
sessionManager.setAppLastSeen(System.currentTimeMillis());
config.getLogger().verbose(config.getAccountId(), "App in background");
final int now = (int) (System.currentTimeMillis() / 1000);
if (coreMetaData.inCurrentSession()) {
try {
StorageHelper
.putInt(context,
StorageHelper.storageKeyWithSuffix(config, Constants.LAST_SESSION_EPOCH),
now);
config.getLogger().verbose(config.getAccountId(), "Updated session time: " + now);
} catch (Throwable t) {
config.getLogger()
.verbose(config.getAccountId(), "Failed to update session time time: " + t.getMessage());
}
}
}

//Lifecycle
public void activityResumed(Activity activity) {
config.getLogger().verbose(config.getAccountId(), "App in foreground");
sessionManager.checkTimeoutSession();
//Anything in this If block will run once per App Launch.
//Will not run for Apps which disable App Launched event
if (!coreMetaData.isAppLaunchPushed()) {

analyticsManager.pushAppLaunchedEvent();
analyticsManager.fetchFeatureFlags();
pushProviders.onTokenRefresh();
Task<Void> task = CTExecutorFactory.executors(config).postAsyncSafelyTask();
task.execute("HandlingInstallReferrer",new Callable<Void>() {
@Override
public Void call() {
if (!coreMetaData.isInstallReferrerDataSent() && coreMetaData
.isFirstSession()) {
handleInstallReferrerOnFirstInstall();
}
return null;
}
});

try {
if (callbackManager.getGeofenceCallback() != null) {
callbackManager.getGeofenceCallback().triggerLocation();
}
} catch (IllegalStateException e) {
config.getLogger().verbose(config.getAccountId(), e.getLocalizedMessage());
} catch (Exception e) {
config.getLogger().verbose(config.getAccountId(), "Failed to trigger location");
}
}
baseEventQueueManager.pushInitialEventsAsync();
inAppController.checkExistingInAppNotifications(activity);
inAppController.checkPendingInAppNotifications(activity);
}

public void onActivityCreated(final Bundle notification, final Uri deepLink) {
try {
boolean shouldProcess = config.isDefaultInstance();

if (shouldProcess) {
if (notification != null && !notification.isEmpty() && notification
.containsKey(Constants.NOTIFICATION_TAG)) {
analyticsManager.pushNotificationClickedEvent(notification);
}

if (deepLink != null) {
try {
analyticsManager.pushDeepLink(deepLink, false);
} catch (Throwable t) {
// no-op
}
}
}
} catch (Throwable t) {
Logger.v("Throwable - " + t.getLocalizedMessage());
}
}

private void handleInstallReferrerOnFirstInstall() {
config.getLogger().verbose(config.getAccountId(), "Starting to handle install referrer");
try {
final InstallReferrerClient referrerClient = InstallReferrerClient.newBuilder(context).build();
referrerClient.startConnection(new InstallReferrerStateListener() {
@Override
public void onInstallReferrerServiceDisconnected() {
if (!coreMetaData.isInstallReferrerDataSent()) {
handleInstallReferrerOnFirstInstall();
}
}

@Override
public void onInstallReferrerSetupFinished(int responseCode) {
switch (responseCode) {
case InstallReferrerClient.InstallReferrerResponse.OK:
// Connection established.
ReferrerDetails response;
try {
response = referrerClient.getInstallReferrer();
String referrerUrl = response.getInstallReferrer();
coreMetaData
.setReferrerClickTime(response.getReferrerClickTimestampSeconds());
coreMetaData
.setAppInstallTime(response.getInstallBeginTimestampSeconds());
analyticsManager.pushInstallReferrer(referrerUrl);
coreMetaData.setInstallReferrerDataSent(true);
config.getLogger().debug(config.getAccountId(),
"Install Referrer data set [Referrer URL-" + referrerUrl + "]");
} catch (RemoteException e) {
config.getLogger().debug(config.getAccountId(),
"Remote exception caused by Google Play Install Referrer library - " + e
.getMessage());
referrerClient.endConnection();
coreMetaData.setInstallReferrerDataSent(false);
}
referrerClient.endConnection();
break;
case InstallReferrerClient.InstallReferrerResponse.FEATURE_NOT_SUPPORTED:
// API not available on the current Play Store app.
config.getLogger().debug(config.getAccountId(),
"Install Referrer data not set, API not supported by Play Store on device");
break;
case InstallReferrerClient.InstallReferrerResponse.SERVICE_UNAVAILABLE:
// Connection couldn't be established.
config.getLogger().debug(config.getAccountId(),
"Install Referrer data not set, connection to Play Store unavailable");
break;
}
}
});
} catch (Throwable t) {
config.getLogger().verbose(config.getAccountId(),
"Google Play Install Referrer's InstallReferrerClient Class not found - " + t
.getLocalizedMessage()
+ " \n Please add implementation 'com.android.installreferrer:installreferrer:2.1' to your build.gradle");
}
}
}
Loading

0 comments on commit 30199cf

Please sign in to comment.