Skip to content

Commit

Permalink
Re-route deprecated android casting APIs to new ones
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed Aug 21, 2024
1 parent f485e4a commit 28f2610
Show file tree
Hide file tree
Showing 50 changed files with 1,566 additions and 4,601 deletions.
4 changes: 3 additions & 1 deletion examples/tv-casting-app/android/App/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {

defaultConfig {
applicationId "com.chip.casting"
minSdk 24
minSdk 26
targetSdk 30
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -47,6 +47,8 @@ android {
java.srcDirs = [
'src/main/java',
'src/main/jni',
'src/compat/java',
'src/compat/jni',
]

// uncomment this code to debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import androidx.fragment.app.FragmentActivity;
import com.R;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public class CastingContext {
private FragmentActivity fragmentActivity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,17 @@ private void runCertTests(Activity activity) {
"messages_presentMessages",
successFailureCallback,
() -> {
tvCastingApp.messages_presentMessages(kTVApp, "CastingAppTestMessage", callback);
final byte[] messageID = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
tvCastingApp.messages_presentMessages(
kTVApp,
messageID,
0,
0,
(long) 0,
(long) 60 * 1000,
"CastingAppTestMessage",
Optional.empty(),
callback);
});

runAndWait(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/** A {@link Fragment} to discover commissioners on the network */
/**
* @deprecated Refer to com.matter.casting.DiscoveryExampleFragment.
* <p>A {@link Fragment} to discover commissioners on the network
*/
@Deprecated
public class CommissionerDiscoveryFragment extends Fragment {
private static final String TAG = CommissionerDiscoveryFragment.class.getSimpleName();
private static final long DISCOVERY_POLL_INTERVAL_MS = 15000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@
import com.chip.casting.util.GlobalCastingConstants;
import java.util.concurrent.Executors;

/** A {@link Fragment} to get the TV Casting App commissioned / connected. */
/**
* @deprecated Refer to com.matter.casting.ConnectionExampleFragment.
* <p>A {@link Fragment} to get the TV Casting App commissioned / connected
*/
@Deprecated
public class ConnectionFragment extends Fragment {
private static final String TAG = ConnectionFragment.class.getSimpleName();
private static final Integer targetContentAppVendorId = 65521;

private final TvCastingApp tvCastingApp;
private final DiscoveredNodeData selectedCommissioner;
Expand Down Expand Up @@ -189,7 +194,8 @@ public void handle(MatterError error) {
+ " port: "
+ selectedCommissioner.getPort());

this.sendUdcSuccess = tvCastingApp.sendCommissioningRequest(selectedCommissioner);
this.sendUdcSuccess =
tvCastingApp.sendCommissioningRequest(selectedCommissioner, targetContentAppVendorId);
updateUiOnConnectionSuccess();
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import com.chip.casting.MatterError;
import com.chip.casting.TvCastingApp;

/** A {@link Fragment} to send Content Launcher commands from the TV Casting App. */
/**
* @deprecated Refer to com.matter.casting.ContentLauncherLaunchURLExampleFragment.
* <p>A {@link Fragment} to send Content Launcher commands from the TV Casting App.
*/
@Deprecated
public class ContentLauncherFragment extends Fragment {
private static final String TAG = ContentLauncherFragment.class.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import com.chip.casting.SuccessCallback;
import com.chip.casting.TvCastingApp;

/** A {@link Fragment} for the Media Playback cluster */
/**
* @deprecated Refer to com.matter.casting.MediaPlaybackSubscribeToCurrentStateExampleFragment.
* <p>A {@link Fragment} for the Media Playback cluster
*/
@Deprecated
public class MediaPlaybackFragment extends Fragment {
private static final String TAG = MediaPlaybackFragment.class.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import com.R;
import com.chip.casting.TvCastingApp;

/** An interstitial {@link Fragment} to select one of the supported media actions to perform */
/**
* @deprecated Refer to com.matter.casting.ActionSelectorFragment.
* <p>An interstitial {@link Fragment} to select one of the supported media actions to perform
*/
@Deprecated
public class SelectClusterFragment extends Fragment {
private static final String TAG = SelectClusterFragment.class.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.security.spec.ECParameterSpec;
import java.security.spec.ECPrivateKeySpec;

/** @deprecated Refer to com.matter.casting.DACProviderStub. */
@Deprecated
public class DACProviderStub implements DACProvider {

private String kDevelopmentDAC_Cert_FFF1_8001 =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.chip.casting.util;

public class GlobalCastingConstants {
public static final int CommissioningWindowDurationSecs = 3 * 60;
public static final int SetupPasscode = 20202021;
public static final int Discriminator = 0xF00;

// set to true, to demo the simplified casting APIs.
// Otherwise, the deprecated casting APIs are invoked
public static final boolean ChipCastingSimplified = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.math.BigInteger;
import java.util.Arrays;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public class AppParameters {
private static final String TAG = AppParameters.class.getSimpleName();
public static final int MIN_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH = 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package com.chip.casting;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public class CommissioningCallbacks {
/**
* This is called when the PBKDFParamRequest is received and indicates the start of the session
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
*/
package com.chip.casting;

import chip.devicecontroller.ChipClusters;
import com.matter.casting.core.Endpoint;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public class ContentApp {
private Endpoint endpoint;
private short endpointId;
private List<Integer> clusterIds;

Expand All @@ -32,6 +38,33 @@ public ContentApp(short endpointId, List<Integer> clusterIds) {
this.isInitialized = true;
}

ContentApp(Endpoint endpoint) {
this.endpoint = endpoint;
this.endpointId = (short) endpoint.getId();
this.clusterIds = new ArrayList<>();
if (endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) != null) {
this.clusterIds.add((int) ChipClusters.ApplicationBasicCluster.CLUSTER_ID);
}
if (endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class) != null) {
this.clusterIds.add((int) ChipClusters.ApplicationLauncherCluster.CLUSTER_ID);
}
if (endpoint.getCluster(ChipClusters.ContentLauncherCluster.class) != null) {
this.clusterIds.add((int) ChipClusters.ContentLauncherCluster.CLUSTER_ID);
}
if (endpoint.getCluster(ChipClusters.KeypadInputCluster.class) != null) {
this.clusterIds.add((int) ChipClusters.KeypadInputCluster.CLUSTER_ID);
}
if (endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) != null) {
this.clusterIds.add((int) ChipClusters.MediaPlaybackCluster.CLUSTER_ID);
}
if (endpoint.getCluster(ChipClusters.OnOffCluster.class) != null) {
this.clusterIds.add((int) ChipClusters.OnOffCluster.CLUSTER_ID);
}
if (endpoint.getCluster(ChipClusters.TargetNavigatorCluster.class) != null) {
this.clusterIds.add((int) ChipClusters.TargetNavigatorCluster.CLUSTER_ID);
}
}

public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
Expand All @@ -49,6 +82,10 @@ public java.lang.String toString() {
return "endpointId=" + endpointId;
}

Endpoint getEndpoint() {
return endpoint;
}

public short getEndpointId() {
return endpointId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.ArrayList;
import java.util.Optional;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public class ContentLauncherTypes {
public static class AdditionalInfo {
public String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package com.chip.casting;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public interface DACProvider {
byte[] GetCertificationDeclaration();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@

import android.net.nsd.NsdServiceInfo;
import android.util.Log;
import com.matter.casting.core.CastingPlayer;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public class DiscoveredNodeData {
private static final String TAG = DiscoveredNodeData.class.getSimpleName();

private static final int MAX_IP_ADDRESSES = 5;
private static final int MAX_ROTATING_ID_LEN = 50;
private static final String KEY_DEVICE_NAME = "DN";
private static final String KEY_DEVICE_TYPE = "DT";
private static final String KEY_VENDOR_PRODUCT = "VP";

private CastingPlayer castingPlayer;

private String hostName;
private String instanceName;
private long longDiscriminator;
Expand Down Expand Up @@ -119,10 +123,30 @@ public DiscoveredNodeData(VideoPlayer player) {
this.port = player.getPort();
}

DiscoveredNodeData(CastingPlayer castingPlayer) {
this.castingPlayer = castingPlayer;
this.deviceName = castingPlayer.getDeviceName();
this.ipAddresses = castingPlayer.getIpAddresses();
this.numIPs =
castingPlayer.getIpAddresses() != null ? castingPlayer.getIpAddresses().size() : 0;
this.deviceType = castingPlayer.getDeviceType();
this.hostName = castingPlayer.getHostName();
this.vendorId = castingPlayer.getVendorId();
this.productId = castingPlayer.getProductId();
this.instanceName = castingPlayer.getInstanceName();
if (castingPlayer.isConnected()) {
this.connectableVideoPlayer = new VideoPlayer(castingPlayer);
}
}

void setConnectableVideoPlayer(VideoPlayer videoPlayer) {
this.connectableVideoPlayer = videoPlayer;
}

CastingPlayer getCastingPlayer() {
return castingPlayer;
}

public boolean isPreCommissioned() {
return connectableVideoPlayer != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

import android.util.Log;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public abstract class FailureCallback {
private static final String TAG = FailureCallback.class.getSimpleName();

public abstract void handle(MatterError err);

protected final void handleInternal(int errorCode, String errorMessage) {
protected final void handleInternal(MatterError err) {
try {
handle(new MatterError(errorCode, errorMessage));
handle(err);
} catch (Throwable t) {
Log.e(TAG, "FailureCallback::Caught an unhandled Throwable from the client: " + t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@

import android.util.Log;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public abstract class MatterCallbackHandler {
private static final String TAG = MatterCallbackHandler.class.getSimpleName();

public abstract void handle(MatterError err);

protected final void handleInternal(int errorCode, String errorMessage) {
protected final void handleInternal(MatterError err) {
try {
handle(new MatterError(errorCode, errorMessage));
handle(err);
} catch (Throwable t) {
Log.e(TAG, "MatterCallbackHandler::Caught an unhandled Throwable from the client: " + t);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@

import java.util.Objects;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public class MatterError {
private long errorCode;
private String errorMessage;

public static final MatterError DISCOVERY_SERVICE_LOST =
new MatterError(4L, "Discovery service was lost.");

public static final MatterError MATTER_INTERNAL_ERROR = new MatterError(0xac, "Internal error.");

public static final MatterError NO_ERROR = new MatterError(0, null);

MatterError(com.matter.casting.support.MatterError err) {
this.errorCode = err.getErrorCode();
this.errorMessage = err.getErrorMessage();
}

public MatterError(long errorCode, String errorMessage) {
this.errorCode = errorCode;
this.errorMessage = errorMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package com.chip.casting;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public class MediaPlaybackTypes {
public enum PlaybackStateEnum {
Playing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import android.util.Log;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public abstract class SubscriptionEstablishedCallback {
private static final String TAG = SubscriptionEstablishedCallback.class.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import android.util.Log;

/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
@Deprecated
public abstract class SuccessCallback<R> {
private static final String TAG = SuccessCallback.class.getSimpleName();

Expand Down
Loading

0 comments on commit 28f2610

Please sign in to comment.