forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tv-casting-app: Support for pre-commissioned state to Discovered Vide…
…o Player Nodes, new AppParams and Read Attribute APIs (project-chip#23303) * tv-casting-app: Support to pass in the new AppParameters (includes rotatingDeviceId) * tv-casting-app: Adding Read API for ApplicationBasic cluster * tv-casting-app: Exposing pre commissioned state and toConnectableVideoPlayer API
- Loading branch information
1 parent
2bc1a54
commit d0a3d57
Showing
43 changed files
with
1,682 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 0 additions & 129 deletions
129
...casting-app/android/App/app/src/main/java/com/chip/casting/app/CommissioningFragment.java
This file was deleted.
Oops, something went wrong.
155 changes: 155 additions & 0 deletions
155
...tv-casting-app/android/App/app/src/main/java/com/chip/casting/app/ConnectionFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package com.chip.casting.app; | ||
|
||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
import com.chip.casting.ContentApp; | ||
import com.chip.casting.DiscoveredNodeData; | ||
import com.chip.casting.FailureCallback; | ||
import com.chip.casting.MatterCallbackHandler; | ||
import com.chip.casting.MatterError; | ||
import com.chip.casting.SuccessCallback; | ||
import com.chip.casting.TvCastingApp; | ||
import com.chip.casting.VideoPlayer; | ||
import com.chip.casting.util.GlobalCastingConstants; | ||
|
||
/** A {@link Fragment} to get the TV Casting App commissioned / connected. */ | ||
public class ConnectionFragment extends Fragment { | ||
private static final String TAG = ConnectionFragment.class.getSimpleName(); | ||
|
||
private final TvCastingApp tvCastingApp; | ||
private final DiscoveredNodeData selectedCommissioner; | ||
|
||
private boolean verifyOrEstablishConnectionSuccess; | ||
private boolean openCommissioningWindowSuccess; | ||
private boolean sendUdcSuccess; | ||
|
||
public ConnectionFragment(TvCastingApp tvCastingApp, DiscoveredNodeData selectedCommissioner) { | ||
this.tvCastingApp = tvCastingApp; | ||
this.selectedCommissioner = selectedCommissioner; | ||
} | ||
|
||
/** | ||
* Use this factory method to create a new instance of this fragment using the provided | ||
* parameters. | ||
* | ||
* @return A new instance of fragment CommissioningFragment. | ||
*/ | ||
public static ConnectionFragment newInstance( | ||
TvCastingApp tvCastingApp, DiscoveredNodeData selectedCommissioner) { | ||
return new ConnectionFragment(tvCastingApp, selectedCommissioner); | ||
} | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
public View onCreateView( | ||
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
Callback callback = (ConnectionFragment.Callback) this.getActivity(); | ||
|
||
SuccessCallback<VideoPlayer> onConnectionSuccess = | ||
new SuccessCallback<VideoPlayer>() { | ||
@Override | ||
public void handle(VideoPlayer videoPlayer) { | ||
Log.d(TAG, "handle() called on OnConnectionSuccess with " + videoPlayer); | ||
callback.handleCommissioningComplete(); | ||
} | ||
}; | ||
|
||
FailureCallback onConnectionFailure = | ||
new FailureCallback() { | ||
@Override | ||
public void handle(MatterError matterError) { | ||
Log.d(TAG, "handle() called on OnConnectionFailure with " + matterError); | ||
} | ||
}; | ||
|
||
SuccessCallback<ContentApp> onNewOrUpdatedEndpoints = | ||
new SuccessCallback<ContentApp>() { | ||
@Override | ||
public void handle(ContentApp contentApp) { | ||
Log.d(TAG, "handle() called on OnNewOrUpdatedEndpoint with " + contentApp); | ||
} | ||
}; | ||
|
||
if (selectedCommissioner != null && selectedCommissioner.isPreCommissioned()) { | ||
VideoPlayer videoPlayer = selectedCommissioner.toConnectableVideoPlayer(); | ||
Log.d(TAG, "Calling verifyOrEstablishConnectionSuccess with VideoPlayer: " + videoPlayer); | ||
this.verifyOrEstablishConnectionSuccess = | ||
tvCastingApp.verifyOrEstablishConnection( | ||
videoPlayer, onConnectionSuccess, onConnectionFailure, onNewOrUpdatedEndpoints); | ||
} else { | ||
Log.d(TAG, "Running commissioning"); | ||
this.openCommissioningWindowSuccess = | ||
tvCastingApp.openBasicCommissioningWindow( | ||
GlobalCastingConstants.CommissioningWindowDurationSecs, | ||
new MatterCallbackHandler() { | ||
@Override | ||
public void handle(MatterError error) { | ||
Log.d(TAG, "handle() called on CommissioningComplete event with " + error); | ||
} | ||
}, | ||
onConnectionSuccess, | ||
onConnectionFailure, | ||
onNewOrUpdatedEndpoints); | ||
|
||
if (this.openCommissioningWindowSuccess) { | ||
if (selectedCommissioner != null && selectedCommissioner.getNumIPs() > 0) { | ||
String ipAddress = selectedCommissioner.getIpAddresses().get(0).getHostAddress(); | ||
Log.d( | ||
TAG, | ||
"ConnectionFragment calling tvCastingApp.sendUserDirectedCommissioningRequest with IP: " | ||
+ ipAddress | ||
+ " port: " | ||
+ selectedCommissioner.getPort()); | ||
|
||
this.sendUdcSuccess = tvCastingApp.sendCommissioningRequest(selectedCommissioner); | ||
} | ||
} | ||
} | ||
|
||
return inflater.inflate(R.layout.fragment_connection, container, false); | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
String commissioningWindowStatus = ""; | ||
if (selectedCommissioner != null && selectedCommissioner.isPreCommissioned()) { | ||
commissioningWindowStatus = "Establishing connection with selected Video Player"; | ||
} else { | ||
commissioningWindowStatus = "Failed to open commissioning window"; | ||
if (this.openCommissioningWindowSuccess) { | ||
commissioningWindowStatus = "Commissioning window has been opened. Commission manually."; | ||
if (this.sendUdcSuccess) { | ||
commissioningWindowStatus = | ||
"Commissioning window has been opened. Commissioning requested from " | ||
+ selectedCommissioner.getDeviceName(); | ||
} | ||
TextView onboardingPayloadView = getView().findViewById(R.id.onboardingPayload); | ||
onboardingPayloadView.setText( | ||
"Onboarding PIN: " | ||
+ GlobalCastingConstants.SetupPasscode | ||
+ "\nDiscriminator: " | ||
+ GlobalCastingConstants.Discriminator); | ||
} | ||
} | ||
|
||
TextView commissioningWindowStatusView = getView().findViewById(R.id.commissioningWindowStatus); | ||
commissioningWindowStatusView.setText(commissioningWindowStatus); | ||
} | ||
|
||
/** Interface for notifying the host. */ | ||
public interface Callback { | ||
/** Notifies listener to trigger transition on completion of commissioning */ | ||
void handleCommissioningComplete(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
examples/tv-casting-app/android/App/app/src/main/jni/com/chip/casting/AppParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
package com.chip.casting; | ||
|
||
public class AppParameters { | ||
public static final int MIN_ROTATING_DEVICE_ID_UNIQUE_ID_LENGTH = 16; | ||
|
||
private byte[] rotatingDeviceIdUniqueId; | ||
|
||
public void setRotatingDeviceIdUniqueId(byte[] rotatingDeviceIdUniqueId) { | ||
this.rotatingDeviceIdUniqueId = rotatingDeviceIdUniqueId; | ||
} | ||
|
||
public byte[] getRotatingDeviceIdUniqueId() { | ||
return rotatingDeviceIdUniqueId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.