Skip to content

Commit

Permalink
Merge pull request #268 from adjust/v4111
Browse files Browse the repository at this point in the history
V4111
  • Loading branch information
nonelse authored Feb 27, 2017
2 parents decf3fd + 06f73de commit c25dd1a
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Adjust/adjust/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.library'

def getVersionName() {
return "4.11.0"
return "4.11.1"
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Handler;
import android.util.*;

import java.io.InputStream;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -164,7 +165,7 @@ private ActivityHandler(AdjustConfig adjustConfig) {

logger.lockLogLevel();

scheduledExecutor = new CustomScheduledExecutor("ActivityHandler");
scheduledExecutor = new CustomScheduledExecutor("ActivityHandler", false);
internalState = new InternalState();

// enabled by default
Expand Down Expand Up @@ -664,7 +665,7 @@ private void initI() {
}
}

foregroundTimer = new TimerCycle(scheduledExecutor,
foregroundTimer = new TimerCycle(
new Runnable() {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void teardown() {
public AttributionHandler(IActivityHandler activityHandler,
ActivityPackage attributionPackage,
boolean startsSending) {
scheduledExecutor = new CustomScheduledExecutor("AttributionHandler");
scheduledExecutor = new CustomScheduledExecutor("AttributionHandler", false);
logger = AdjustFactory.getLogger();

timer = new TimerOnce(scheduledExecutor, new Runnable() {
Expand Down
2 changes: 1 addition & 1 deletion Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface Constants {
String BASE_URL = "https://app.adjust.com";
String SCHEME = "https";
String AUTHORITY = "app.adjust.com";
String CLIENT_SDK = "android4.11.0";
String CLIENT_SDK = "android4.11.1";
String LOGTAG = "Adjust";
String REFTAG = "reftag";
String DEEPLINK = "deeplink";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,38 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
//import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.*;

/**
* Created by pfms on 05/08/2016.
*/
public class CustomScheduledExecutor {
private ScheduledThreadPoolExecutor executor;
public final class CustomScheduledExecutor {
private String source;
// private AtomicInteger threadCounter = new AtomicInteger(1);
private ScheduledThreadPoolExecutor executor;
private final AtomicInteger threadCounter = new AtomicInteger(1);


public CustomScheduledExecutor(final String source) {
executor = new ScheduledThreadPoolExecutor(1, // Single thread
public CustomScheduledExecutor(final String source, boolean doKeepAlive) {
this.source = source;

executor = new ScheduledThreadPoolExecutor(1, // Single thread
new ThreadFactory() { // Creator of daemon threads
@Override
public Thread newThread(Runnable runnable) {
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
Thread thread = Executors.defaultThreadFactory().newThread(new RunnableWrapper(runnable));

thread.setPriority(Thread.MIN_PRIORITY);
thread.setName(Constants.THREAD_PREFIX + thread.getName() + source);
thread.setName(Constants.THREAD_PREFIX + thread.getName() + "-" + source);
thread.setDaemon(true);

thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread th, Throwable tr) {
AdjustFactory.getLogger().error("Thread %s with error %s", th.getName(), tr.getMessage());
}
});
// AdjustFactory.getLogger().verbose("Thread %s created", thread.getName());

//AdjustFactory.getLogger().verbose("Thread %s created", thread.getName());
return thread;
}
}, new RejectedExecutionHandler() { // Logs rejected runnables rejected from the entering the pool
Expand All @@ -43,9 +49,11 @@ public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
}
}
);
this.source = source;
executor.setKeepAliveTime(10L, TimeUnit.MILLISECONDS);
executor.allowCoreThreadTimeOut(true);

if (!doKeepAlive) {
executor.setKeepAliveTime(10L, TimeUnit.MILLISECONDS);
executor.allowCoreThreadTimeOut(true);
}
}

public Future<?> submit(Runnable task) {
Expand All @@ -59,12 +67,12 @@ public void shutdownNow() {
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
// AdjustFactory.getLogger().verbose("CustomScheduledExecutor scheduleWithFixedDelay from %s source, with %d delay and %d initial delay",
// source, delay, initialDelay);
return executor.scheduleWithFixedDelay(new RunnableWrapper(command), initialDelay, delay, unit);
return executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
}

public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
// AdjustFactory.getLogger().verbose("CustomScheduledExecutor schedule from %s source, with %d delay", source, delay);
return executor.schedule(new RunnableWrapper(command), delay, unit);
return executor.schedule(command, delay, unit);
}

private class RunnableWrapper implements Runnable {
Expand All @@ -87,6 +95,7 @@ public void run() {
runnable.run();
// long after = System.currentTimeMillis();
// AdjustFactory.getLogger().verbose("RunnableWrapper %d from %s source, after running at %d", threadNumber, source, after);

} catch (Throwable t) {
AdjustFactory.getLogger().error("Runnable error %s", t.getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion Adjust/adjust/src/main/java/com/adjust/sdk/DeviceInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private String getAppVersion(Context context) {
String name = context.getPackageName();
PackageInfo info = packageManager.getPackageInfo(name, 0);
return info.versionName;
} catch (PackageManager.NameNotFoundException e) {
} catch (Exception e) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void teardown(boolean deleteState) {
public PackageHandler(IActivityHandler activityHandler,
Context context,
boolean startsSending) {
this.scheduledExecutor = new CustomScheduledExecutor("PackageHandler");
this.scheduledExecutor = new CustomScheduledExecutor("PackageHandler", false);
this.logger = AdjustFactory.getLogger();
this.backoffStrategy = AdjustFactory.getPackageHandlerBackoffStrategy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class RequestHandler implements IRequestHandler {

public RequestHandler(IPackageHandler packageHandler) {
this.logger = AdjustFactory.getLogger();
this.scheduledExecutor = new CustomScheduledExecutor("RequestHandler");
this.scheduledExecutor = new CustomScheduledExecutor("RequestHandler", false);
init(packageHandler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void teardown() {
public SdkClickHandler(boolean startsSending) {
init(startsSending);
this.logger = AdjustFactory.getLogger();
this.scheduledExecutor = new CustomScheduledExecutor("SdkClickHandler");
this.scheduledExecutor = new CustomScheduledExecutor("SdkClickHandler", false);
this.backoffStrategy = AdjustFactory.getSdkClickBackoffStrategy();
}

Expand Down
28 changes: 13 additions & 15 deletions Adjust/adjust/src/main/java/com/adjust/sdk/TimerCycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* Created by pfms on 08/05/15.
*/
public class TimerCycle {
private WeakReference<CustomScheduledExecutor> scheduledExecutorWeakRef;
private CustomScheduledExecutor executor;

private ScheduledFuture waitingTask;
private String name;
private Runnable command;
Expand All @@ -17,8 +18,8 @@ public class TimerCycle {
private boolean isPaused;
private ILogger logger;

public TimerCycle(CustomScheduledExecutor scheduler, Runnable command, long initialDelay, long cycleDelay, String name) {
this.scheduledExecutorWeakRef = new WeakReference<CustomScheduledExecutor>(scheduler);
public TimerCycle(Runnable command, long initialDelay, long cycleDelay, String name) {
this.executor = new CustomScheduledExecutor(name, true);

this.name = name;
this.command = command;
Expand All @@ -40,17 +41,9 @@ public void start() {
return;
}

CustomScheduledExecutor scheduledExecutor = scheduledExecutorWeakRef.get();
if (scheduledExecutor == null) {
return;
}

//String initialDelaySeconds = Util.SecondsDisplayFormat.format(initialDelay / 1000.0);
//logger.verbose("%s starting in %s seconds and cycle every %s seconds", name, initialDelaySeconds, cycleDelaySeconds);

logger.verbose("%s starting", name);

waitingTask = scheduledExecutor.scheduleWithFixedDelay(new Runnable() {
waitingTask = executor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
logger.verbose("%s fired", name);
Expand Down Expand Up @@ -90,9 +83,14 @@ private void cancel(boolean mayInterruptIfRunning) {

public void teardown() {
cancel(true);
if (scheduledExecutorWeakRef != null) {
scheduledExecutorWeakRef.clear();

if (executor != null) {
try {
executor.shutdownNow();
} catch (SecurityException ignored) {
}
}
scheduledExecutorWeakRef = null;

executor = null;
}
}
2 changes: 1 addition & 1 deletion Adjust/example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {
// running mvn package
//compile fileTree(dir: '../target', include: ['*.jar'])
// using maven repository
//compile 'com.adjust.sdk:adjust-android:4.11.0'
//compile 'com.adjust.sdk:adjust-android:4.11.1'

debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import android.widget.Button;
import android.widget.Toast;

import com.adjust.sdk.Adjust;
import com.adjust.sdk.AdjustEvent;
import com.adjust.sdk.*;

public class MainActivity extends AppCompatActivity {
private static final String EVENT_TOKEN_SIMPLE = "g3mfiw";
Expand Down
2 changes: 1 addition & 1 deletion Adjust/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>adjust-android</artifactId>
<groupId>com.adjust.sdk</groupId>
<version>4.11.0</version>
<version>4.11.1</version>
<packaging>jar</packaging>
<name>Adjust Android SDK</name>
<url>https://github.com/adjust/android_sdk</url>
Expand Down
2 changes: 1 addition & 1 deletion Adjust/pom_criteo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>adjust-android-criteo</artifactId>
<groupId>com.adjust.sdk</groupId>
<version>4.11.0</version>
<version>4.11.1</version>
<packaging>jar</packaging>
<name>Adjust Android SDK</name>
<url>https://github.com/adjust/android_sdk</url>
Expand Down
2 changes: 1 addition & 1 deletion Adjust/pom_sociomantic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>adjust-android-sociomantic</artifactId>
<groupId>com.adjust.sdk</groupId>
<version>4.11.0</version>
<version>4.11.1</version>
<packaging>jar</packaging>
<name>Adjust Android SDK</name>
<url>https://github.com/adjust/android_sdk</url>
Expand Down
2 changes: 1 addition & 1 deletion Adjust/pom_trademob.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>adjust-android-trademob</artifactId>
<groupId>com.adjust.sdk</groupId>
<version>4.11.0</version>
<version>4.11.1</version>
<packaging>jar</packaging>
<name>Adjust Android SDK</name>
<url>https://github.com/adjust/android_sdk</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TestActivityPackage(ActivityPackage activityPackage) {
// default values
appToken = "123456789012";
environment = "sandbox";
clientSdk = "android4.11.0";
clientSdk = "android4.11.1";
suffix = "";
attribution = new AdjustAttribution();
playServices = true;
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Version 4.11.1 (27th February 2017)
#### Fixed
- Prevent multiple created threads mentioned in android_sdk#265
- Protect Package Manager from throwing unexpected exceptions like in android_sdk#266

---

### Version 4.11.0 (14th December 2016)
#### Added
- Added sending of Amazon Fire Advertising Identifier.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ compile project(":adjust")
If you are using Maven, add this line instead:

```
compile 'com.adjust.sdk:adjust-android:4.11.0'
compile 'com.adjust.sdk:adjust-android:4.11.1'
```

### <a id="sdk-gps"></a>Add Google Play Services
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.11.0
4.11.1
2 changes: 1 addition & 1 deletion doc/english/criteo_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Add the dependency of the adjust sdk with the Criteo plugin:

```
compile 'com.adjust.sdk:adjust-android-criteo:4.11.0'
compile 'com.adjust.sdk:adjust-android-criteo:4.11.1'
```

Or integrate adjust with Criteo events by following these steps:
Expand Down
2 changes: 1 addition & 1 deletion doc/english/migrate.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Migrate your adjust SDK for Android to 4.11.0 from 3.6.2
## Migrate your adjust SDK for Android to 4.11.1 from 3.6.2

### The Application class

Expand Down
2 changes: 1 addition & 1 deletion doc/english/sociomantic_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Add the dependency of the adjust sdk with the Sociomantic plugin:

```
compile 'com.adjust.sdk:adjust-android-sociomantic:4.11.0'
compile 'com.adjust.sdk:adjust-android-sociomantic:4.11.1'
```

Or integrate adjust with Sociomantic events by following these steps:
Expand Down
2 changes: 1 addition & 1 deletion doc/english/trademob_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Add the dependency of the adjust sdk with the Trademob plugin:

```
compile 'com.adjust.sdk:adjust-android-trademob:4.11.0'
compile 'com.adjust.sdk:adjust-android-trademob:4.11.1'
```

Or integrate adjust with Trademob events by following these steps:
Expand Down

0 comments on commit c25dd1a

Please sign in to comment.