Skip to content

Commit

Permalink
Addressed comments by sharadb-amazon
Browse files Browse the repository at this point in the history
  • Loading branch information
pgregorr-amazon committed Dec 28, 2023
1 parent 0ab3b25 commit aadb0e3
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 248 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>

<application
android:allowBackup="true"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
import java.net.InetAddress;
import java.util.List;

/**
* The CastingPlayer interface defines a Matter commissioner that is able to play media to a
* physical output or to a display screen which is part of the device (e.g. TV). It is discovered on
* the local network using Matter Commissioner discovery over DNS. It contains all the information
* about the service discovered/resolved.
*/
public interface CastingPlayer {
boolean isConnected();

Expand All @@ -42,7 +48,11 @@ public interface CastingPlayer {

int getDeviceType();

boolean discoveredCastingPlayerHasSameSource(Object o);
String toString();

boolean equals(Object o);

int hashCode();

// TODO: Implement in following PRs. Related to player connection implementation.
// List<Endpoint> getEndpoints();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,94 @@
package com.matter.casting.core;

import android.util.Log;
import com.matter.casting.support.MatterError;
import java.util.List;

/**
* The CastingPlayerDiscovery interface defines the API to control Matter Casting Player discovery
* over DNS-SD, and to collect discovery results. Discovery is centrally managed by the native C++
* layer in the Matter SDK. This class exposes native functions to add and remove a
* CastingPlayerChangeListener, which contains the C++ to Java callbacks for when Casting Players
* are discovered, updated, or lost from the network. This class is a singleton.
*/
public interface CastingPlayerDiscovery {

/**
* @return a list of Casting Players discovered during the current discovery session. This list is
* cleared when discovery stops.
*/
List<CastingPlayer> getCastingPlayers();

com.matter.casting.support.MatterError startDiscovery();
/**
* Starts Casting Players discovery or returns an error.
*
* @param discoveryTargetDeviceType the target device type to be discovered using DNS-SD. 35
* represents device type of Matter Casting Player.
* @return a specific MatterError if the the operation failed or NO_ERROR if succeeded.
*/
MatterError startDiscovery(int discoveryTargetDeviceType);

com.matter.casting.support.MatterError stopDiscovery();
/**
* Stops Casting Players discovery or returns an error.
*
* @return a specific MatterError if the the operation failed or NO_ERROR if succeeded.
*/
MatterError stopDiscovery();

com.matter.casting.support.MatterError addCastingPlayerChangeListener(
CastingPlayerChangeListener listener);
/**
* Adds a CastingPlayerChangeListener instance to be used during discovery. The
* CastingPlayerChangeListener contains the C++ to Java callbacks for when Casting Players are
* discovered, updated, or lost from the network. Should be called prior to calling
* MatterCastingPlayerDiscovery.startDiscovery().
*
* @param listener an instance of the CastingPlayerChangeListener to be implemented by the APIs
* consumer.
* @return a specific MatterError if the the operation failed or NO_ERROR if succeeded.
*/
MatterError addCastingPlayerChangeListener(CastingPlayerChangeListener listener);

com.matter.casting.support.MatterError removeCastingPlayerChangeListener(
CastingPlayerChangeListener listener);
/**
* Removes CastingPlayerChangeListener from the native layer.
*
* @param listener the specific instance of CastingPlayerChangeListener to be removed.
* @return a specific MatterError if the the operation failed or NO_ERROR if succeeded.
*/
MatterError removeCastingPlayerChangeListener(CastingPlayerChangeListener listener);

/**
* The Casting Client discovers CastingPlayers using Matter Commissioner discovery over DNS-SD by
* listening for CastingPlayer events as they are discovered, updated, or lost from the network.
* The CastingPlayerChangeListener can discover CastingPlayers by implementing the onAdded,
* onChanged and onRemoved callbacks which are called as CastingPlayers, are discovered, updated,
* or lost from the network. The onAdded(), onChanged() and onRemoved() callbacks must be
* implemented by the APIs client.
*/
abstract class CastingPlayerChangeListener {
static final String TAG = CastingPlayerChangeListener.class.getSimpleName();

/**
* Called by the native C++ layer when a Casting Player is added to the local network.
*
* @param castingPlayer the Casting Player added.
*/
public abstract void onAdded(CastingPlayer castingPlayer);

/**
* Called by the native C++ layer when a Casting Player on the local network is changed.
*
* @param castingPlayer the Casting Player changed.
*/
public abstract void onChanged(CastingPlayer castingPlayer);

/**
* Called by the native C++ layer when a Casting Player is removed from the local network.
*
* @param castingPlayer the Casting Player removed.
*/
public abstract void onRemoved(CastingPlayer castingPlayer);

/**
* The following methods are used to catch possible exceptions thrown by the methods above, when
* not implemented correctly.
*/
protected final void _onAdded(CastingPlayer castingPlayer) {
try {
onAdded(castingPlayer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
*/
package com.matter.casting.core;

import android.util.Log;
import java.net.InetAddress;
import java.util.List;
import java.util.Objects;

/** The Matter Commissioner (e.g. TV) discovered using Matter Commissioner discovery. */
/**
* A Matter Casting Player represents a Matter commissioner that is able to play media to a physical
* output or to a display screen which is part of the device (e.g. TV). It is discovered on the
* local network using Matter Commissioner discovery over DNS. It contains all the information about
* the service discovered/resolved.
*/
public class MatterCastingPlayer implements CastingPlayer {
private static final String TAG = MatterCastingPlayer.class.getSimpleName();
private boolean connected;
private String deviceId;
private String deviceName;
Expand All @@ -48,8 +51,6 @@ public MatterCastingPlayer(
int productId,
int vendorId,
int deviceType) {
Log.d(TAG, "MatterCastingPlayer() constructor, building player with deviceId: " + deviceId);
Log.d(TAG, "MatterCastingPlayer() constructor, building player with deviceName: " + deviceName);
this.connected = connected;
this.deviceId = deviceId;
this.hostName = hostName;
Expand All @@ -63,11 +64,19 @@ public MatterCastingPlayer(
this.deviceType = deviceType;
}

/**
* @return a boolean indicating whether a Casting Player instance is connected to the TV Casting
* App.
*/
@Override
public boolean isConnected() {
return this.connected;
}

/**
* @return a String representing the Casting Player device ID which is a concatenation of the
* device's IP address and port number.
*/
@Override
public String getDeviceId() {
return this.deviceId;
Expand All @@ -88,11 +97,13 @@ public String getInstanceName() {
return this.instanceName;
}

/** @return an int, corresponding to the number of valid IP addresses for this Casting PLayer. */
@Override
public int getNumberIPs() {
return this.numberIPs;
}

/** @return a list of valid IP addresses for this Casting PLayer. */
@Override
public List<InetAddress> getIpAddresses() {
return this.ipAddresses;
Expand All @@ -119,10 +130,20 @@ public int getDeviceType() {
}

@Override
public boolean discoveredCastingPlayerHasSameSource(Object o) {
public String toString() {
return this.deviceId;
}

@Override
public int hashCode() {
return this.deviceId.hashCode();
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MatterCastingPlayer that = (MatterCastingPlayer) o;
return Objects.equals(deviceId, that.deviceId) && vendorId == that.vendorId;
return Objects.equals(this.deviceId, that.deviceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,72 @@
*/
package com.matter.casting.core;

import android.util.Log;
import com.matter.casting.support.MatterError;
import java.util.List;

/**
* MatterCastingPlayerDiscovery provides an API to control Matter Casting Player discovery over
* DNS-SD, and to collect discovery results. Discovery is centrally managed by the native C++ layer
* in the Matter SDK. This class exposes native functions to add and remove a
* CastingPlayerChangeListener, which contains the C++ to Java callbacks for when Casting Players
* are discovered, updated, or lost from the network. This class is a singleton.
*/
public final class MatterCastingPlayerDiscovery implements CastingPlayerDiscovery {
private static final String TAG = MatterCastingPlayerDiscovery.class.getSimpleName();
private static MatterCastingPlayerDiscovery matterCastingPlayerDiscoveryInstance;

// Methods:
public static MatterCastingPlayerDiscovery getInstance() {
Log.d(TAG, "MatterCastingPlayerDiscovery.getInstance() called");
if (matterCastingPlayerDiscoveryInstance == null) {
matterCastingPlayerDiscoveryInstance = new MatterCastingPlayerDiscovery();
}
return matterCastingPlayerDiscoveryInstance;
};

/**
* @return a list of Casting Players discovered during the current discovery session. This list is
* cleared when discovery stops.
*/
@Override
public native List<CastingPlayer> getCastingPlayers();

/**
* Starts Casting Players discovery or returns an error.
*
* @param discoveryTargetDeviceType the target device type to be discovered using DNS-SD. 35
* represents device type of Matter Casting Player.
* @return a specific MatterError if the the operation failed or NO_ERROR if succeeded.
*/
@Override
public native com.matter.casting.support.MatterError startDiscovery();
public native MatterError startDiscovery(int discoveryTargetDeviceType);

/**
* Stops Casting Players discovery or returns an error.
*
* @return a specific MatterError if the the operation failed or NO_ERROR if succeeded.
*/
@Override
public native com.matter.casting.support.MatterError stopDiscovery();
public native MatterError stopDiscovery();

/**
* Adds a CastingPlayerChangeListener instance to be used during discovery. The
* CastingPlayerChangeListener contains the C++ to Java callbacks for when Casting Players are
* discovered, updated, or lost from the network. Should be called prior to calling
* MatterCastingPlayerDiscovery.startDiscovery().
*
* @param listener an instance of the CastingPlayerChangeListener to be implemented by the APIs
* consumer.
* @return a specific MatterError if the the operation failed or NO_ERROR if succeeded.
*/
@Override
public native com.matter.casting.support.MatterError addCastingPlayerChangeListener(
CastingPlayerChangeListener listener);
public native MatterError addCastingPlayerChangeListener(CastingPlayerChangeListener listener);

/**
* Removes CastingPlayerChangeListener from the native layer.
*
* @param listener the specific instance of CastingPlayerChangeListener to be removed.
* @return a specific MatterError if the the operation failed or NO_ERROR if succeeded.
*/
@Override
public native com.matter.casting.support.MatterError removeCastingPlayerChangeListener(
CastingPlayerChangeListener listener);
public native MatterError removeCastingPlayerChangeListener(CastingPlayerChangeListener listener);
}
Loading

0 comments on commit aadb0e3

Please sign in to comment.