Skip to content
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
5 changes: 0 additions & 5 deletions android/crt/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,12 @@ android {
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
// Enable desugaring so that Android lint doesn't flag `java.time` usage. Downstream
// consumers will need to enable desugaring to use this library.
// See: https://developer.android.com/studio/write/java8-support#library-desugaring
coreLibraryDesugaringEnabled true
}
}

build.dependsOn preBuild

dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
androidTestImplementation 'org.mockito:mockito-core:3.11.2'
androidTestImplementation 'androidx.appcompat:appcompat:1.3.1'
androidTestImplementation 'junit:junit:4.13.2'
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/software/amazon/awssdk/crt/CrtResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
import software.amazon.awssdk.crt.io.EventLoopGroup;
import software.amazon.awssdk.crt.io.HostResolver;

import java.time.Instant;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Condition;
Expand Down Expand Up @@ -96,7 +100,7 @@ public String toString() {
private long nativeHandle;
private AtomicInteger refCount = new AtomicInteger(1);
private long id = nextId.getAndAdd(1);
private Instant creationTime = Instant.now();
private String creationTime;
private String description;

static {
Expand All @@ -108,6 +112,13 @@ public String toString() {
* Default constructor
*/
public CrtResource() {
// Format the current time without java.time to support old Android versions
// without requiring API desugaring.
// See: https://developer.android.com/studio/write/java8-support#library-desugaring
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
creationTime = sdf.format(new Date());

if (debugNativeObjects) {
String canonicalName = this.getClass().getCanonicalName();

Expand Down Expand Up @@ -332,7 +343,7 @@ public void setDescription(String description) {
*/
public String getResourceLogDescription() {
StringBuilder builder = new StringBuilder();
builder.append(String.format("[Id %d, Class %s, Refs %d](%s) - %s", id, getClass().getSimpleName(), refCount.get(), creationTime.toString(), description != null ? description : "<null>"));
builder.append(String.format("[Id %d, Class %s, Refs %d](%s) - %s", id, getClass().getSimpleName(), refCount.get(), creationTime, description != null ? description : "<null>"));
synchronized(this) {
if (referencedResources.size() > 0) {
builder.append("\n Forward references by Id: ");
Expand Down
2 changes: 0 additions & 2 deletions src/test/android/testapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ android {
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
coreLibraryDesugaringEnabled true
}

kotlinOptions {
Expand All @@ -84,7 +83,6 @@ dependencies {
implementation 'androidx.core:core:1.2.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.5"

testImplementation 'junit:junit:4.13'

Expand Down