Skip to content

Commit

Permalink
Update persistence to handle app uninstalls. (#22958)
Browse files Browse the repository at this point in the history
* Update persistence to handle app uninstalls. complete some other media clusters for the response path.

* Remove unused file

* Restyled by whitespace

* Restyled by google-java-format

* Restyled by clang-format

* Remove unused files.

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Mar 9, 2023
1 parent a610d66 commit 1195163
Show file tree
Hide file tree
Showing 19 changed files with 825 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ parcelable SupportedCluster {

int clusterIdentifier;

String[] features;
int features;

int[] optionalCommandIdentifiers;

int[] optionalAttributesIdentifiers;
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,260 @@
package com.matter.tv.app.api;

/**
* Helper class to hold the IDs and corresponding constants for media related clusters. TODO : Add
* the rest of the media clusters TODO : Maybe generate using ZAP tool
*/
public class Clusters {
// Clusters
public static class MediaPlayback {
public static final int Id = 1286;
public static final int Id = 0x0506;

public static class Commands {
public static class Play {
public static final int ID = 0x00;
}

public static class Pause {
public static final int ID = 0x01;
}

public static class StopPlayback {
public static final int ID = 0x02;
}

public static class StartOver {
public static final int ID = 0x03;
}

public static class Previous {
public static final int ID = 0x04;
}

public static class Next {
public static final int ID = 0x05;
}

public static class Rewind {
public static final int ID = 0x06;
}

public static class FastForward {
public static final int ID = 0x07;
}

public static class SkipForward {
public static final int ID = 0x08;

public static class Fields {
public static final int DeltaPositionMilliseconds = 0x00;
}
}

public static class SkipBackward {
public static final int ID = 0x09;

public static class Fields {
public static final int DeltaPositionMilliseconds = 0x00;
}
}

public static class Seek {
public static final int ID = 0x0B;

public static class Fields {
public static final int Position = 0x00;
}
}

public static class PlaybackResponse {
public static final int ID = 0x0A;

public static class Fields {
public static final int Status = 0x00;
public static final int Data = 0x01;
}
}
}

public static class Attributes {
public static final int CurrentState = 0;
public static final int CurrentState = 0x00;
public static final int StartTime = 0x01;
public static final int Duration = 0x02;
public static final int SampledPosition = 0x03;
public static final int PlaybackSpeed = 0x04;
public static final int SeekRangeEnd = 0x05;
public static final int SeekRangeStart = 0x06;
}

public static class PlaybackStateEnum {
public static final int Playing = 0;
public static final int Paused = 1;
public static final int NotPlaying = 2;
public static final int Buffering = 3;
public static class Types {
public static class PlaybackStateEnum {
public static final int Playing = 0x00;
public static final int Paused = 0x01;
public static final int NotPlaying = 0x02;
public static final int Buffering = 0x03;
}

public static class StatusEnum {
public static final int Success = 0x00;
public static final int InvalidStateForCommand = 0x01;
public static final int NotAllowed = 0x02;
public static final int NotActive = 0x03;
public static final int SpeedOutOfRange = 0x04;
public static final int SeekOutOfRange = 0x05;
}

public static class PlaybackPosition {
public static final int UpdatedAt = 0x00;
public static final int Position = 0x01;
}
}
}

public static class ContentLauncher {
public static final int Id = 1290;
public static final int Id = 0x050A;

public static class Commands {
public static class LaunchContent {
public static final int ID = 0x00;

public static class Fields {
public static final int Search = 0x00;
public static final int AutoPlay = 0x01;
public static final int Data = 0x02;
}
}

public static class LaunchURL {
public static final int ID = 0x01;

public static class Fields {
public static final int ContentURL = 0x00;
public static final int DisplayString = 0x01;
public static final int BrandingInformation = 0x02;
}
}

public static class LaunchResponse {
public static final int ID = 0x02;

public static class Fields {
public static final int Status = 0x00;
public static final int Data = 0x01;
}
}
}

public static class Attributes {
public static final int AcceptHeader = 0x00;
public static final int SupportedStreamingProtocols = 0x01;
}

public static class Types {
public static class ContentSearch {
public static final int ParameterList = 0x00;
}

public static class StatusEnum {
public static final int Success = 0x00;
public static final int UrlNotAvailable = 0x01;
public static final int AuthFailed = 0x02;
}

public static class Parameter {
public static final int Type = 0x00;
public static final int Value = 0x01;
public static final int ExternalIDList = 0x02;
}

public static class ParameterEnum {
public static final int Actor = 0x00;
public static final int Channel = 0x01;
public static final int Character = 0x02;
public static final int Director = 0x03;
public static final int Event = 0x04;
public static final int Franchise = 0x05;
public static final int Genre = 0x06;
public static final int League = 0x07;
public static final int Popularity = 0x08;
public static final int Provider = 0x09;
public static final int Sport = 0x0A;
public static final int SportsTeam = 0x0B;
public static final int Type = 0x0C;
public static final int Video = 0x0D;
}

public static class AdditionalInfo {
public static final int Name = 0x00;
public static final int Value = 0x01;
}

public static class BrandingInformation {
public static final int ProviderName = 0x00;
public static final int Background = 0x01;
public static final int Logo = 0x02;
public static final int ProgressBar = 0x03;
public static final int Splash = 0x04;
public static final int WaterMark = 0x05;
}

public static class StyleInformation {
public static final int ProviderName = 0x00;
public static final int Background = 0x01;
public static final int Logo = 0x02;
}

public static class Dimension {
public static final int ImageUrl = 0x00;
public static final int Color = 0x01;
public static final int Size = 0x02;
}

public static class MetricTypeEnum {
public static final int Pixels = 0x00;
public static final int Percentage = 0x01;
}
}
}

public static class TargetNavigator {
public static final int Id = 0x0505;

public static class Commands {
public static class NavigateTarget {
public static final int ID = 0x00;

public static class Fields {
public static final int Target = 0x00;
public static final int Data = 0x01;
}
}

public static class NavigateTargetResponse {
public static final int ID = 0x01;

public static class Fields {
public static final int Status = 0x00;
public static final int Data = 0x01;
}
}
}

public static class Attributes {
public static final int AcceptHeader = 0;
public static final int SupportedStreamingProtocols = 1;
public static final int TargetList = 0x00;
public static final int CurrentTarget = 0x01;
}

public static class Types {
public static class TargetInfo {
public static final int Identifier = 0x00;
public static final int Name = 0x01;
}

public static class StatusEnum {
public static final int Success = 0x00;
public static final int TargetNotFound = 0x01;
public static final int NotAllowed = 0x02;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<receiver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.contentapp;

import com.matter.tv.app.api.Clusters;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -8,7 +9,24 @@ public class AttributeHolder {
private static AttributeHolder instance = new AttributeHolder();
private Map<Long, Map<Long, Object>> attributeValues = new HashMap<>();

private AttributeHolder() {};
private AttributeHolder() {
// Setting up attribute defaults
setAttributeValue(
Clusters.ContentLauncher.Id,
Clusters.ContentLauncher.Attributes.AcceptHeader,
"[\"video/mp4\", \"application/x-mpegURL\", \"application/dash+xml\"]");
setAttributeValue(
Clusters.ContentLauncher.Id,
Clusters.ContentLauncher.Attributes.SupportedStreamingProtocols,
3);
setAttributeValue(Clusters.MediaPlayback.Id, Clusters.MediaPlayback.Attributes.CurrentState, 2);
setAttributeValue(
Clusters.TargetNavigator.Id,
Clusters.TargetNavigator.Attributes.TargetList,
"[{\"0\":1, \"1\":\"Home\"},{\"0\":2, \"1\":\"Settings\"},{\"0\":3, \"1\":\"Casting Home\"}]");
setAttributeValue(
Clusters.TargetNavigator.Id, Clusters.TargetNavigator.Attributes.CurrentTarget, 1);
};

public static AttributeHolder getInstance() {
return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
.setAttributeValue(
Clusters.MediaPlayback.Id,
Clusters.MediaPlayback.Attributes.CurrentState,
Clusters.MediaPlayback.PlaybackStateEnum.Playing);
Clusters.MediaPlayback.Types.PlaybackStateEnum.Playing);
reportAttributeChange(
Clusters.MediaPlayback.Id, Clusters.MediaPlayback.Attributes.CurrentState);
break;
Expand All @@ -58,7 +58,7 @@ protected void onCreate(Bundle savedInstanceState) {
.setAttributeValue(
Clusters.MediaPlayback.Id,
Clusters.MediaPlayback.Attributes.CurrentState,
Clusters.MediaPlayback.PlaybackStateEnum.Paused);
Clusters.MediaPlayback.Types.PlaybackStateEnum.Paused);
reportAttributeChange(
Clusters.MediaPlayback.Id, Clusters.MediaPlayback.Attributes.CurrentState);
break;
Expand All @@ -67,7 +67,7 @@ protected void onCreate(Bundle savedInstanceState) {
.setAttributeValue(
Clusters.MediaPlayback.Id,
Clusters.MediaPlayback.Attributes.CurrentState,
Clusters.MediaPlayback.PlaybackStateEnum.Buffering);
Clusters.MediaPlayback.Types.PlaybackStateEnum.Buffering);
reportAttributeChange(
Clusters.MediaPlayback.Id, Clusters.MediaPlayback.Attributes.CurrentState);
break;
Expand All @@ -76,7 +76,7 @@ protected void onCreate(Bundle savedInstanceState) {
.setAttributeValue(
Clusters.MediaPlayback.Id,
Clusters.MediaPlayback.Attributes.CurrentState,
Clusters.MediaPlayback.PlaybackStateEnum.NotPlaying);
Clusters.MediaPlayback.Types.PlaybackStateEnum.NotPlaying);
reportAttributeChange(
Clusters.MediaPlayback.Id, Clusters.MediaPlayback.Attributes.CurrentState);
break;
Expand All @@ -91,21 +91,6 @@ protected void onCreate(Bundle savedInstanceState) {

MatterAgentClient matterAgentClient = MatterAgentClient.getInstance();
executorService.execute(matterAgentClient::reportClusters);

// Setting up attribute defaults
AttributeHolder.getInstance()
.setAttributeValue(
Clusters.ContentLauncher.Id,
Clusters.ContentLauncher.Attributes.AcceptHeader,
"[\"video/mp4\", \"application/x-mpegURL\", \"application/dash+xml\"]");
AttributeHolder.getInstance()
.setAttributeValue(
Clusters.ContentLauncher.Id,
Clusters.ContentLauncher.Attributes.SupportedStreamingProtocols,
3);
AttributeHolder.getInstance()
.setAttributeValue(
Clusters.MediaPlayback.Id, Clusters.MediaPlayback.Attributes.CurrentState, 2);
}

private void reportAttributeChange(final int clusterId, final int attributeId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void onReceive(Context context, Intent intent) {

Intent in = new Intent(context, MainActivity.class);
in.putExtra(MatterIntentConstants.EXTRA_COMMAND_PAYLOAD, command);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(in);

Log.d(TAG, "Started activity. Now sending response");
Expand Down
Loading

0 comments on commit 1195163

Please sign in to comment.