Skip to content

Commit

Permalink
Merge branch 'master' into feature/update_android_docker_java
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 authored Feb 7, 2025
2 parents c7c91e0 + f53be4f commit 475265b
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 185 deletions.
2 changes: 1 addition & 1 deletion examples/chef/common/chef-concentration-measurement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void emberAfPm1ConcentrationMeasurementClusterInitCallback(EndpointId endpoint)
void emberAfPm10ConcentrationMeasurementClusterInitCallback(EndpointId endpoint)
{
gPm10ConcentrationMeasurementInstance[EndpointId(endpoint)] = new Instance<true, true, true, true, true, true>(
EndpointId(endpoint), Pm10ConcentrationMeasurement::Id, MeasurementMediumEnum::kAir, MeasurementUnitEnum::kPpm);
EndpointId(endpoint), Pm10ConcentrationMeasurement::Id, MeasurementMediumEnum::kAir, MeasurementUnitEnum::kUgm3);
gPm10ConcentrationMeasurementInstance[EndpointId(endpoint)]->Init();
gPm10ConcentrationMeasurementInstance[EndpointId(endpoint)]->SetMeasuredValue(MakeNullable(50.0f));
gPm10ConcentrationMeasurementInstance[EndpointId(endpoint)]->SetMinMeasuredValue(MakeNullable(1.0f));
Expand Down
1 change: 1 addition & 0 deletions integrations/docker/images/base/chip-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ RUN set -x \
unzip \
wget \
zlib1g-dev \
zstd \
&& rm -rf /var/lib/apt/lists/ \
&& git lfs install \
&& : # last line
Expand Down
2 changes: 1 addition & 1 deletion integrations/docker/images/base/chip-build/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
110 : [Android] Update android sdk and java version
111 : [Android] Update android sdk and java version
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ import chip.devicecontroller.model.NodeState;
import chip.devicecontroller.model.Status;

import javax.annotation.Nullable;
import java.lang.ref.Cleaner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -170,23 +169,10 @@ public class ChipClusters {

private Optional<Long> timeoutMillis = Optional.empty();

private final Cleaner.Cleanable cleanable;

public BaseChipCluster(long devicePtr, int endpointId, long clusterId) {
this.devicePtr = devicePtr;
this.endpointId = endpointId;
this.clusterId = clusterId;

this.cleanable =
Cleaner.create()
.register(
this,
() -> {
if (chipClusterPtr != 0) {
deleteCluster(chipClusterPtr);
chipClusterPtr = 0;
}
});
}

/**
Expand Down Expand Up @@ -255,6 +241,15 @@ public class ChipClusters {

@Deprecated
public void deleteCluster(long chipClusterPtr) {}
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();

if (chipClusterPtr != 0) {
deleteCluster(chipClusterPtr);
chipClusterPtr = 0;
}
}
}

abstract static class ReportCallbackImpl implements ReportCallback, SubscriptionEstablishedCallback, ResubscriptionAttemptCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import chip.devicecontroller.model.Status;

import javax.annotation.Nullable;
import java.lang.ref.Cleaner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -93,23 +92,10 @@ public static abstract class BaseChipCluster {

private Optional<Long> timeoutMillis = Optional.empty();

private final Cleaner.Cleanable cleanable;

public BaseChipCluster(long devicePtr, int endpointId, long clusterId) {
this.devicePtr = devicePtr;
this.endpointId = endpointId;
this.clusterId = clusterId;

this.cleanable =
Cleaner.create()
.register(
this,
() -> {
if (chipClusterPtr != 0) {
deleteCluster(chipClusterPtr);
chipClusterPtr = 0;
}
});
}

/**
Expand Down Expand Up @@ -178,6 +164,15 @@ protected void invoke(

@Deprecated
public void deleteCluster(long chipClusterPtr) {}
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();

if (chipClusterPtr != 0) {
deleteCluster(chipClusterPtr);
chipClusterPtr = 0;
}
}
}

abstract static class ReportCallbackImpl implements ReportCallback, SubscriptionEstablishedCallback, ResubscriptionAttemptCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import chip.devicecontroller.model.Status;

import javax.annotation.Nullable;
import java.lang.ref.Cleaner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -93,23 +92,10 @@ public static abstract class BaseChipCluster {

private Optional<Long> timeoutMillis = Optional.empty();

private final Cleaner.Cleanable cleanable;

public BaseChipCluster(long devicePtr, int endpointId, long clusterId) {
this.devicePtr = devicePtr;
this.endpointId = endpointId;
this.clusterId = clusterId;

this.cleanable =
Cleaner.create()
.register(
this,
() -> {
if (chipClusterPtr != 0) {
deleteCluster(chipClusterPtr);
chipClusterPtr = 0;
}
});
}

/**
Expand Down Expand Up @@ -178,6 +164,15 @@ protected void invoke(

@Deprecated
public void deleteCluster(long chipClusterPtr) {}
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();

if (chipClusterPtr != 0) {
deleteCluster(chipClusterPtr);
chipClusterPtr = 0;
}
}
}

abstract static class ReportCallbackImpl implements ReportCallback, SubscriptionEstablishedCallback, ResubscriptionAttemptCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,17 @@

import chip.devicecontroller.model.InvokeResponseData;
import chip.devicecontroller.model.NoInvokeResponseData;
import java.lang.ref.Cleaner;
import java.util.Optional;
import javax.annotation.Nullable;

/** JNI wrapper callback class for {@link InvokeCallback}. */
public final class BatchInvokeCallbackJni {
private final BatchInvokeCallbackJni wrappedBatchInvokeCallback;
public final class ExtendableInvokeCallbackJni {
private final ExtendableInvokeCallback wrappedExtendableInvokeCallback;
private long callbackHandle;

private final Cleaner.Cleanable cleanable;

public BatchInvokeCallbackJni(BatchInvokeCallback wrappedBatchInvokeCallback) {
this.wrappedBatchInvokeCallback = wrappedBatchInvokeCallback;
public ExtendableInvokeCallbackJni(ExtendableInvokeCallback wrappedExtendableInvokeCallback) {
this.wrappedExtendableInvokeCallback = wrappedExtendableInvokeCallback;
this.callbackHandle = newCallback();

this.cleanable =
Cleaner.create()
.register(
this,
() -> {
if (chipClusterPtr != 0) {
deleteCluster(chipClusterPtr);
chipClusterPtr = 0;
}
});
}

long getCallbackHandle() {
Expand All @@ -55,7 +41,7 @@ long getCallbackHandle() {
private native void deleteCallback(long callbackHandle);

private void onError(Exception e) {
wrappedBatchInvokeCallback.onError(e);
wrappedExtendableInvokeCallback.onError(e);
}

private void onResponse(
Expand Down Expand Up @@ -88,10 +74,21 @@ private void onResponse(
}

private void onNoResponse(int commandRef) {
wrappedBatchInvokeCallback.onNoResponse(NoInvokeResponseData.newInstance(commandRef));
wrappedExtendableInvokeCallback.onNoResponse(NoInvokeResponseData.newInstance(commandRef));
}

private void onDone() {
wrappedBatchInvokeCallback.onDone();
wrappedExtendableInvokeCallback.onDone();
}

// TODO(#8578): Replace finalizer with PhantomReference.
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();

if (callbackHandle != 0) {
deleteCallback(callbackHandle);
callbackHandle = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import chip.devicecontroller.model.ChipEventPath;
import chip.devicecontroller.model.DataVersionFilter;
import chip.devicecontroller.model.InvokeElement;
import java.lang.ref.Cleaner;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Calendar;
Expand All @@ -45,8 +44,6 @@ public class ChipDeviceController {
private ScanNetworksListener scanNetworksListener;
private NOCChainIssuer nocChainIssuer;

private final Cleaner.Cleanable cleanable;

/**
* To load class and jni, we need to new AndroidChipPlatform after jni load but before new
* ChipDeviceController
Expand All @@ -70,17 +67,6 @@ public ChipDeviceController(ControllerParams params) {
throw new NullPointerException("params cannot be null");
}
deviceControllerPtr = newDeviceController(params);

this.cleanable =
Cleaner.create()
.register(
this,
() -> {
if (deviceControllerPtr != 0) {
deleteDeviceController(deviceControllerPtr);
deviceControllerPtr = 0;
}
});
}

public void setCompletionListener(CompletionListener listener) {
Expand Down Expand Up @@ -1787,6 +1773,16 @@ private native void updateCommissioningICDRegistrationInfo(
System.loadLibrary("CHIPController");
}

@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();

if (deviceControllerPtr != 0) {
deleteDeviceController(deviceControllerPtr);
deviceControllerPtr = 0;
}
}

/** Interface to implement custom operational credentials issuer (NOC chain generation). */
public interface NOCChainIssuer {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import chip.devicecontroller.model.InvokeResponseData;
import chip.devicecontroller.model.NoInvokeResponseData;
import java.lang.ref.Cleaner;
import java.util.Optional;
import javax.annotation.Nullable;

Expand All @@ -28,22 +27,9 @@ public final class ExtendableInvokeCallbackJni {
private final ExtendableInvokeCallback wrappedExtendableInvokeCallback;
private long callbackHandle;

private final Cleaner.Cleanable cleanable;

public ExtendableInvokeCallbackJni(ExtendableInvokeCallback wrappedExtendableInvokeCallback) {
this.wrappedExtendableInvokeCallback = wrappedExtendableInvokeCallback;
this.callbackHandle = newCallback();

this.cleanable =
Cleaner.create()
.register(
this,
() -> {
if (callbackHandle != 0) {
deleteCallback(callbackHandle);
callbackHandle = 0;
}
});
}

long getCallbackHandle() {
Expand Down Expand Up @@ -94,4 +80,15 @@ private void onNoResponse(int commandRef) {
private void onDone() {
wrappedExtendableInvokeCallback.onDone();
}

// TODO(#8578): Replace finalizer with PhantomReference.
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();

if (callbackHandle != 0) {
deleteCallback(callbackHandle);
callbackHandle = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,14 @@
*/
package chip.devicecontroller;

import java.lang.ref.Cleaner;

/** JNI wrapper callback class for getting a connected device. */
public class GetConnectedDeviceCallbackJni {
private final GetConnectedDeviceCallback wrappedCallback;
private long callbackHandle;

private final Cleaner.Cleanable cleanable;

public GetConnectedDeviceCallbackJni(GetConnectedDeviceCallback wrappedCallback) {
this.wrappedCallback = wrappedCallback;
this.callbackHandle = newCallback(wrappedCallback);

this.cleanable =
Cleaner.create()
.register(
this,
() -> {
if (callbackHandle != 0) {
deleteCallback(callbackHandle);
callbackHandle = 0;
}
});
}

long getCallbackHandle() {
Expand All @@ -50,6 +35,17 @@ long getCallbackHandle() {

private native void deleteCallback(long callbackHandle);

// TODO(#8578): Replace finalizer with PhantomReference.
@SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();

if (callbackHandle != 0) {
deleteCallback(callbackHandle);
callbackHandle = 0;
}
}

/** Callbacks for getting a device connected with PASE or CASE, depending on the context. */
public interface GetConnectedDeviceCallback {
void onDeviceConnected(long devicePointer);
Expand Down
Loading

0 comments on commit 475265b

Please sign in to comment.