Skip to content

Commit dd8b002

Browse files
Re-route deprecated android casting APIs to new ones (#35136)
1 parent 62bf76b commit dd8b002

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1566
-4601
lines changed

examples/tv-casting-app/android/App/app/build.gradle

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77

88
defaultConfig {
99
applicationId "com.chip.casting"
10-
minSdk 24
10+
minSdk 26
1111
targetSdk 30
1212
versionCode 1
1313
versionName "1.0"
@@ -47,6 +47,8 @@ android {
4747
java.srcDirs = [
4848
'src/main/java',
4949
'src/main/jni',
50+
'src/compat/java',
51+
'src/compat/jni',
5052
]
5153

5254
// uncomment this code to debug

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CastingContext.java examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CastingContext.java

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import androidx.fragment.app.FragmentActivity;
66
import com.R;
77

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

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CertTestFragment.java examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CertTestFragment.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,17 @@ private void runCertTests(Activity activity) {
313313
"messages_presentMessages",
314314
successFailureCallback,
315315
() -> {
316-
tvCastingApp.messages_presentMessages(kTVApp, "CastingAppTestMessage", callback);
316+
final byte[] messageID = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5};
317+
tvCastingApp.messages_presentMessages(
318+
kTVApp,
319+
messageID,
320+
0,
321+
0,
322+
(long) 0,
323+
(long) 60 * 1000,
324+
"CastingAppTestMessage",
325+
Optional.empty(),
326+
callback);
317327
});
318328

319329
runAndWait(

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissionerDiscoveryFragment.java examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/CommissionerDiscoveryFragment.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
import java.util.concurrent.ScheduledFuture;
2929
import java.util.concurrent.TimeUnit;
3030

31-
/** A {@link Fragment} to discover commissioners on the network */
31+
/**
32+
* @deprecated Refer to com.matter.casting.DiscoveryExampleFragment.
33+
* <p>A {@link Fragment} to discover commissioners on the network
34+
*/
35+
@Deprecated
3236
public class CommissionerDiscoveryFragment extends Fragment {
3337
private static final String TAG = CommissionerDiscoveryFragment.class.getSimpleName();
3438
private static final long DISCOVERY_POLL_INTERVAL_MS = 15000;

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/ConnectionFragment.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@
2121
import com.chip.casting.util.GlobalCastingConstants;
2222
import java.util.concurrent.Executors;
2323

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

2833
private final TvCastingApp tvCastingApp;
2934
private final DiscoveredNodeData selectedCommissioner;
@@ -189,7 +194,8 @@ public void handle(MatterError error) {
189194
+ " port: "
190195
+ selectedCommissioner.getPort());
191196

192-
this.sendUdcSuccess = tvCastingApp.sendCommissioningRequest(selectedCommissioner);
197+
this.sendUdcSuccess =
198+
tvCastingApp.sendCommissioningRequest(selectedCommissioner, targetContentAppVendorId);
193199
updateUiOnConnectionSuccess();
194200
}
195201
} else {

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ContentLauncherFragment.java examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/ContentLauncherFragment.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
import com.chip.casting.MatterError;
1616
import com.chip.casting.TvCastingApp;
1717

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

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/MediaPlaybackFragment.java examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/MediaPlaybackFragment.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
import com.chip.casting.SuccessCallback;
1919
import com.chip.casting.TvCastingApp;
2020

21-
/** A {@link Fragment} for the Media Playback cluster */
21+
/**
22+
* @deprecated Refer to com.matter.casting.MediaPlaybackSubscribeToCurrentStateExampleFragment.
23+
* <p>A {@link Fragment} for the Media Playback cluster
24+
*/
25+
@Deprecated
2226
public class MediaPlaybackFragment extends Fragment {
2327
private static final String TAG = MediaPlaybackFragment.class.getSimpleName();
2428

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/SelectClusterFragment.java examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/app/SelectClusterFragment.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import com.R;
1111
import com.chip.casting.TvCastingApp;
1212

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

examples/tv-casting-app/android/App/app/src/main/java/com/chip/casting/util/DACProviderStub.java examples/tv-casting-app/android/App/app/src/compat/java/com/chip/casting/util/DACProviderStub.java

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import java.security.spec.ECParameterSpec;
1212
import java.security.spec.ECPrivateKeySpec;
1313

14+
/** @deprecated Refer to com.matter.casting.DACProviderStub. */
15+
@Deprecated
1416
public class DACProviderStub implements DACProvider {
1517

1618
private String kDevelopmentDAC_Cert_FFF1_8001 =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.chip.casting.util;
2+
3+
public class GlobalCastingConstants {
4+
public static final int CommissioningWindowDurationSecs = 3 * 60;
5+
public static final int SetupPasscode = 20202021;
6+
public static final int Discriminator = 0xF00;
7+
8+
// set to true, to demo the simplified casting APIs.
9+
// Otherwise, the deprecated casting APIs are invoked
10+
public static final boolean ChipCastingSimplified = true;
11+
}

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/AppParameters.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/AppParameters.java

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import java.math.BigInteger;
2323
import java.util.Arrays;
2424

25+
/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
26+
@Deprecated
2527
public class AppParameters {
2628
private static final String TAG = AppParameters.class.getSimpleName();
2729
public static final int MIN_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH = 16;

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/CommissioningCallbacks.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/CommissioningCallbacks.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package com.chip.casting;
1919

20+
/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
21+
@Deprecated
2022
public class CommissioningCallbacks {
2123
/**
2224
* This is called when the PBKDFParamRequest is received and indicates the start of the session

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentApp.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/ContentApp.java

+37
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717
*/
1818
package com.chip.casting;
1919

20+
import chip.devicecontroller.ChipClusters;
21+
import com.matter.casting.core.Endpoint;
22+
import java.util.ArrayList;
2023
import java.util.List;
2124
import java.util.Objects;
2225

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

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

41+
ContentApp(Endpoint endpoint) {
42+
this.endpoint = endpoint;
43+
this.endpointId = (short) endpoint.getId();
44+
this.clusterIds = new ArrayList<>();
45+
if (endpoint.getCluster(ChipClusters.ApplicationBasicCluster.class) != null) {
46+
this.clusterIds.add((int) ChipClusters.ApplicationBasicCluster.CLUSTER_ID);
47+
}
48+
if (endpoint.getCluster(ChipClusters.ApplicationLauncherCluster.class) != null) {
49+
this.clusterIds.add((int) ChipClusters.ApplicationLauncherCluster.CLUSTER_ID);
50+
}
51+
if (endpoint.getCluster(ChipClusters.ContentLauncherCluster.class) != null) {
52+
this.clusterIds.add((int) ChipClusters.ContentLauncherCluster.CLUSTER_ID);
53+
}
54+
if (endpoint.getCluster(ChipClusters.KeypadInputCluster.class) != null) {
55+
this.clusterIds.add((int) ChipClusters.KeypadInputCluster.CLUSTER_ID);
56+
}
57+
if (endpoint.getCluster(ChipClusters.MediaPlaybackCluster.class) != null) {
58+
this.clusterIds.add((int) ChipClusters.MediaPlaybackCluster.CLUSTER_ID);
59+
}
60+
if (endpoint.getCluster(ChipClusters.OnOffCluster.class) != null) {
61+
this.clusterIds.add((int) ChipClusters.OnOffCluster.CLUSTER_ID);
62+
}
63+
if (endpoint.getCluster(ChipClusters.TargetNavigatorCluster.class) != null) {
64+
this.clusterIds.add((int) ChipClusters.TargetNavigatorCluster.CLUSTER_ID);
65+
}
66+
}
67+
3568
public boolean equals(Object object) {
3669
if (this == object) return true;
3770
if (object == null || getClass() != object.getClass()) return false;
@@ -49,6 +82,10 @@ public java.lang.String toString() {
4982
return "endpointId=" + endpointId;
5083
}
5184

85+
Endpoint getEndpoint() {
86+
return endpoint;
87+
}
88+
5289
public short getEndpointId() {
5390
return endpointId;
5491
}

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/ContentLauncherTypes.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/ContentLauncherTypes.java

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.ArrayList;
2121
import java.util.Optional;
2222

23+
/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
24+
@Deprecated
2325
public class ContentLauncherTypes {
2426
public static class AdditionalInfo {
2527
public String name;

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DACProvider.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/DACProvider.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package com.chip.casting;
1919

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

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/DiscoveredNodeData.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/DiscoveredNodeData.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,26 @@
1919

2020
import android.net.nsd.NsdServiceInfo;
2121
import android.util.Log;
22+
import com.matter.casting.core.CastingPlayer;
2223
import java.net.InetAddress;
2324
import java.nio.charset.StandardCharsets;
2425
import java.util.Arrays;
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.Objects;
2829

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

32-
private static final int MAX_IP_ADDRESSES = 5;
3335
private static final int MAX_ROTATING_ID_LEN = 50;
3436
private static final String KEY_DEVICE_NAME = "DN";
3537
private static final String KEY_DEVICE_TYPE = "DT";
3638
private static final String KEY_VENDOR_PRODUCT = "VP";
3739

40+
private CastingPlayer castingPlayer;
41+
3842
private String hostName;
3943
private String instanceName;
4044
private long longDiscriminator;
@@ -119,10 +123,30 @@ public DiscoveredNodeData(VideoPlayer player) {
119123
this.port = player.getPort();
120124
}
121125

126+
DiscoveredNodeData(CastingPlayer castingPlayer) {
127+
this.castingPlayer = castingPlayer;
128+
this.deviceName = castingPlayer.getDeviceName();
129+
this.ipAddresses = castingPlayer.getIpAddresses();
130+
this.numIPs =
131+
castingPlayer.getIpAddresses() != null ? castingPlayer.getIpAddresses().size() : 0;
132+
this.deviceType = castingPlayer.getDeviceType();
133+
this.hostName = castingPlayer.getHostName();
134+
this.vendorId = castingPlayer.getVendorId();
135+
this.productId = castingPlayer.getProductId();
136+
this.instanceName = castingPlayer.getInstanceName();
137+
if (castingPlayer.isConnected()) {
138+
this.connectableVideoPlayer = new VideoPlayer(castingPlayer);
139+
}
140+
}
141+
122142
void setConnectableVideoPlayer(VideoPlayer videoPlayer) {
123143
this.connectableVideoPlayer = videoPlayer;
124144
}
125145

146+
CastingPlayer getCastingPlayer() {
147+
return castingPlayer;
148+
}
149+
126150
public boolean isPreCommissioned() {
127151
return connectableVideoPlayer != null;
128152
}

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/FailureCallback.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/FailureCallback.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919

2020
import android.util.Log;
2121

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

2527
public abstract void handle(MatterError err);
2628

27-
protected final void handleInternal(int errorCode, String errorMessage) {
29+
protected final void handleInternal(MatterError err) {
2830
try {
29-
handle(new MatterError(errorCode, errorMessage));
31+
handle(err);
3032
} catch (Throwable t) {
3133
Log.e(TAG, "FailureCallback::Caught an unhandled Throwable from the client: " + t);
3234
}

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterCallbackHandler.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MatterCallbackHandler.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@
1919

2020
import android.util.Log;
2121

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

2527
public abstract void handle(MatterError err);
2628

27-
protected final void handleInternal(int errorCode, String errorMessage) {
29+
protected final void handleInternal(MatterError err) {
2830
try {
29-
handle(new MatterError(errorCode, errorMessage));
31+
handle(err);
3032
} catch (Throwable t) {
3133
Log.e(TAG, "MatterCallbackHandler::Caught an unhandled Throwable from the client: " + t);
3234
}

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MatterError.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MatterError.java

+9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,24 @@
1919

2020
import java.util.Objects;
2121

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

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

31+
public static final MatterError MATTER_INTERNAL_ERROR = new MatterError(0xac, "Internal error.");
32+
2933
public static final MatterError NO_ERROR = new MatterError(0, null);
3034

35+
MatterError(com.matter.casting.support.MatterError err) {
36+
this.errorCode = err.getErrorCode();
37+
this.errorMessage = err.getErrorMessage();
38+
}
39+
3140
public MatterError(long errorCode, String errorMessage) {
3241
this.errorCode = errorCode;
3342
this.errorMessage = errorMessage;

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/MediaPlaybackTypes.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/MediaPlaybackTypes.java

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package com.chip.casting;
1919

20+
/** @deprecated Use the APIs described in /examples/tv-casting-app/APIs.md instead. */
21+
@Deprecated
2022
public class MediaPlaybackTypes {
2123
public enum PlaybackStateEnum {
2224
Playing,

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/SubscriptionEstablishedCallback.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/SubscriptionEstablishedCallback.java

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import android.util.Log;
2121

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

examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/SuccessCallback.java examples/tv-casting-app/android/App/app/src/compat/jni/com/chip/casting/SuccessCallback.java

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import android.util.Log;
2121

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

0 commit comments

Comments
 (0)