Skip to content

Commit

Permalink
Fix tv-casting-app implementation of commissioner discovery/resolution (
Browse files Browse the repository at this point in the history
project-chip#23787)

* tv-casting-app/darwin: fixing condition checked before returning from the CommissionableDataProviderImpl

* tv-casting-app/android: resolving deadlock in using the NsdManager

* Reusing one ExecutorService per chrisdecenzo's feedback
  • Loading branch information
sharadb-amazon authored Nov 29, 2022
1 parent d2483ef commit fe7b5d0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.util.Log;
import chip.platform.NsdManagerServiceResolver;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class NsdDiscoveryListener implements NsdManager.DiscoveryListener {
private static final String TAG = NsdDiscoveryListener.class.getSimpleName();
Expand All @@ -33,6 +35,7 @@ public class NsdDiscoveryListener implements NsdManager.DiscoveryListener {
private final SuccessCallback<DiscoveredNodeData> successCallback;
private final FailureCallback failureCallback;
private final NsdManagerServiceResolver.NsdManagerResolverAvailState nsdManagerResolverAvailState;
private final ExecutorService resolutionExecutor;

public NsdDiscoveryListener(
NsdManager nsdManager,
Expand All @@ -49,6 +52,7 @@ public NsdDiscoveryListener(
this.successCallback = successCallback;
this.failureCallback = failureCallback;
this.nsdManagerResolverAvailState = nsdManagerResolverAvailState;
this.resolutionExecutor = Executors.newSingleThreadExecutor();
}

@Override
Expand All @@ -58,24 +62,32 @@ public void onDiscoveryStarted(String regType) {

@Override
public void onServiceFound(NsdServiceInfo service) {
Log.d(TAG, "Service discovery success. " + service);
if (service.getServiceType().equals(targetServiceType)) {
if (nsdManagerResolverAvailState != null) {
nsdManagerResolverAvailState.acquireResolver();
}
nsdManager.resolveService(
service,
new NsdResolveListener(
nsdManager,
deviceTypeFilter,
preCommissionedVideoPlayers,
successCallback,
failureCallback,
nsdManagerResolverAvailState,
1));
} else {
Log.d(TAG, "Ignoring discovered service: " + service.toString());
}
this.resolutionExecutor.execute(
new Runnable() {
@Override
public void run() {
Log.d(TAG, "Service discovery success. " + service);
if (service.getServiceType().equals(targetServiceType)) {
if (nsdManagerResolverAvailState != null) {
nsdManagerResolverAvailState.acquireResolver();
}

Log.d(TAG, "Calling NsdManager.resolveService for " + service);
nsdManager.resolveService(
service,
new NsdResolveListener(
nsdManager,
deviceTypeFilter,
preCommissionedVideoPlayers,
successCallback,
failureCallback,
nsdManagerResolverAvailState,
1));
} else {
Log.d(TAG, "Ignoring discovered service: " + service.toString());
}
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CommissionableDataProviderImpl : public CommissionableDataProvider

CHIP_ERROR GetSpake2pIterationCount(uint32_t & iterationCount) override
{
if (mSetupDiscriminator > 0)
if (mSpake2pIterationCount > 0)
{
iterationCount = mSpake2pIterationCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
CoreData,
"-Wl,-unexported_symbol,\"__Z*\"",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.matter.TvCasting-sharadb";
PRODUCT_BUNDLE_IDENTIFIER = com.matter.TvCasting;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -467,7 +467,7 @@
"-Wformat-nonliteral",
"-Wformat-security",
);
PRODUCT_BUNDLE_IDENTIFIER = "com.matter.TvCasting-sharadb";
PRODUCT_BUNDLE_IDENTIFIER = com.matter.TvCasting;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ struct TvCastingApp: App {
}
appParameters.rotatingDeviceIdUniqueId = Data(rotatingDeviceIdUniqueId)

let onboardingParameters: OnboardingPayload = OnboardingPayload()
onboardingParameters.setupPasscode = 20202021
onboardingParameters.setupDiscriminator = 3840

appParameters.onboardingPayload = onboardingParameters

castingServerBridge.initApp(appParameters, clientQueue: DispatchQueue.main, initAppStatusHandler: { (result: Bool) -> () in
self.Log.info("initApp result \(result)")
})
Expand Down

0 comments on commit fe7b5d0

Please sign in to comment.