Skip to content

Commit

Permalink
Restyled by google-java-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits committed May 20, 2022
1 parent 56bb8b4 commit 27c0f3d
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
import chip.setuppayload.DiscoveryCapability;
import chip.setuppayload.SetupPayload;
import chip.setuppayload.SetupPayloadParser;

import com.matter.tv.server.model.ContentApp;
import com.matter.tv.server.receivers.ContentAppDiscoveryService;
import com.matter.tv.server.service.ContentAppAgentService;
import com.matter.tv.server.service.MatterServant;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map.Entry;

public class MainActivity extends AppCompatActivity {

Expand Down Expand Up @@ -111,7 +107,9 @@ public void onStopTrackingTouch(SeekBar seekBar) {}
}

ContentAppDiscoveryService.getReceiverInstance().registerSelf(this.getApplicationContext());
ArrayList<String> lst = new ArrayList<String>(ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().keySet());
ArrayList<String> lst =
new ArrayList<String>(
ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().keySet());
ContentAppListAdapter adapter = new ContentAppListAdapter(this, R.layout.applist_item, lst);

pkgUpdatesView = findViewById(R.id.pkgUpdates);
Expand All @@ -126,9 +124,13 @@ private void registerReceiver(ArrayAdapter adapter) {
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String packageName = intent.getStringExtra("com.matter.tv.server.appagent.add.pkg");
if (action.equals("com.matter.tv.server.appagent.add") || action.equals("com.matter.tv.server.appagent.remove")) {
if (action.equals("com.matter.tv.server.appagent.add")
|| action.equals("com.matter.tv.server.appagent.remove")) {
adapter.clear();
adapter.addAll(ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().entrySet());
adapter.addAll(
ContentAppDiscoveryService.getReceiverInstance()
.getDiscoveredContentApps()
.entrySet());
adapter.notifyDataSetChanged();
}
}
Expand All @@ -142,9 +144,7 @@ private class ContentAppListAdapter extends ArrayAdapter<String> {
private int layout;

public ContentAppListAdapter(
@NonNull Context context,
int resource,
@NonNull ArrayList<String> packages) {
@NonNull Context context, int resource, @NonNull ArrayList<String> packages) {
super(context, resource, packages);
layout = resource;
}
Expand All @@ -166,10 +166,13 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
@Override
public void onClick(View view) {
Log.i(TAG, "Button was clicked for " + position);
for (ContentApp app : ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().values()) {
if (app.getAppName().equals(getItem(position))) {
MatterServant.get().sendTestMessage(app.getEndpointId(), "My Native Message");
}
for (ContentApp app :
ContentAppDiscoveryService.getReceiverInstance()
.getDiscoveredContentApps()
.values()) {
if (app.getAppName().equals(getItem(position))) {
MatterServant.get().sendTestMessage(app.getEndpointId(), "My Native Message");
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,30 @@

import android.content.Context;
import android.util.Log;

import com.matter.tv.server.model.ContentApp;
import com.matter.tv.server.receivers.ContentAppDiscoveryService;
import com.matter.tv.server.service.ContentAppAgentService;
import com.matter.tv.server.service.MatterServant;
import com.tcl.chip.tvapp.ContentAppEndpointManager;

public class ContentAppEndpointManagerImpl implements ContentAppEndpointManager {

private static final String TAG = "MatterMainActivity";
private final Context context;
private static final String TAG = "MatterMainActivity";
private final Context context;

public ContentAppEndpointManagerImpl(Context context){
this.context = context;
}
public ContentAppEndpointManagerImpl(Context context) {
this.context = context;
}

public String sendCommand(int endpointId, String commandPayload) {
Log.d(TAG, "Received a command for endpointId " + endpointId + ". Message " + commandPayload);
for (ContentApp app : ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().values()) {
if (app.getEndpointId() == endpointId) {
Log.d(TAG, "Sending a command for endpointId " + endpointId + ". Message " + commandPayload);
ContentAppAgentService.sendCommand(context, app.getAppName(), commandPayload);
}
}
return "Success";
public String sendCommand(int endpointId, String commandPayload) {
Log.d(TAG, "Received a command for endpointId " + endpointId + ". Message " + commandPayload);
for (ContentApp app :
ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().values()) {
if (app.getEndpointId() == endpointId) {
Log.d(
TAG, "Sending a command for endpointId " + endpointId + ". Message " + commandPayload);
ContentAppAgentService.sendCommand(context, app.getAppName(), commandPayload);
}
}

return "Success";
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,56 @@
package com.matter.tv.server.model;

import com.matter.tv.app.api.SupportedCluster;

import java.util.Collections;
import java.util.Set;

public class ContentApp {

private String appName;
private String vendorName;
private int vendorId;
private int productId;
private Set<SupportedCluster> supportedClusters;
private int endpoint;

public ContentApp(String appName, String vendorName, int vendorId, int productId, Set<SupportedCluster> supportedClusters) {
this.vendorName = vendorName;
this.appName = appName;
this.vendorId = vendorId;
this.productId = productId;
this.supportedClusters = supportedClusters;
}

public String getAppName() {
return appName;
}

public String getVendorName() {
return vendorName;
}

public int getVendorId() {
return vendorId;
}

public int getProductId() {
return productId;
}

public int getEndpointId() {
return endpoint;
}

public void setEndpointId(int endpoint) {
this.endpoint = endpoint;
}

public Set<SupportedCluster> getSupportedClusters() {
return Collections.unmodifiableSet(supportedClusters);
}

private String appName;
private String vendorName;
private int vendorId;
private int productId;
private Set<SupportedCluster> supportedClusters;
private int endpoint;

public ContentApp(
String appName,
String vendorName,
int vendorId,
int productId,
Set<SupportedCluster> supportedClusters) {
this.vendorName = vendorName;
this.appName = appName;
this.vendorId = vendorId;
this.productId = productId;
this.supportedClusters = supportedClusters;
}

public String getAppName() {
return appName;
}

public String getVendorName() {
return vendorName;
}

public int getVendorId() {
return vendorId;
}

public int getProductId() {
return productId;
}

public int getEndpointId() {
return endpoint;
}

public void setEndpointId(int endpoint) {
this.endpoint = endpoint;
}

public Set<SupportedCluster> getSupportedClusters() {
return Collections.unmodifiableSet(supportedClusters);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.JsonReader;
import android.util.Log;
import com.matter.tv.app.api.MatterIntentConstants;
import com.matter.tv.app.api.SupportedCluster;
import com.matter.tv.server.model.ContentApp;
import com.matter.tv.server.utils.ResourceUtils;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -31,9 +28,11 @@ public class ContentAppDiscoveryService extends BroadcastReceiver {
static final String MATTER_VENDOR_ID_METADATA_KEY = "com.matter.tv.app.api.vendor_id";
static final String MATTER_PRODUCT_ID_METADATA_KEY = "com.matter.tv.app.api.product_id";

private static final String ANDROID_PACKAGE_REMOVED_ACTION = "android.intent.action.PACKAGE_REMOVED";
private static final String ANDROID_PACKAGE_REMOVED_ACTION =
"android.intent.action.PACKAGE_REMOVED";
private static final String ANDROID_PACKAGE_ADDED_ACTION = "android.intent.action.PACKAGE_ADDED";
private static final String ANDROID_PACKAGE_REPLACED_ACTION = "android.intent.action.PACKAGE_REPLACED";
private static final String ANDROID_PACKAGE_REPLACED_ACTION =
"android.intent.action.PACKAGE_REPLACED";

private static ResourceUtils resourceUtils = ResourceUtils.getInstance();

Expand Down Expand Up @@ -90,13 +89,12 @@ private void handlePackageAdded(Context context, String pkg) {
int productId = appInfo.metaData.getInt(MATTER_PRODUCT_ID_METADATA_KEY, -1);
String vendorName = appInfo.metaData.getString(MATTER_VENDOR_NAME_METADATA_KEY, "");


if(vendorId == -1 || productId == -1) {
if (vendorId == -1 || productId == -1) {
return;
}

Set<SupportedCluster> supportedClusters;
Log.d(TAG, "got static capability for package " + pkg + ", resourceId: " + resId);
Log.d(TAG, "got static capability for package " + pkg + ", resourceId: " + resId);
if (resId != 0) {
Resources res = pm.getResourcesForApplication(appInfo);
supportedClusters = resourceUtils.getSupportedClusters(res, resId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import chip.platform.NsdManagerServiceResolver;
import chip.platform.PreferencesConfigurationManager;
import chip.platform.PreferencesKeyValueStoreManager;

import com.matter.tv.server.handlers.ContentAppEndpointManagerImpl;
import com.matter.tv.server.model.ContentApp;
import com.tcl.chip.tvapp.ChannelManagerStub;
Expand Down Expand Up @@ -149,7 +148,13 @@ public void updateLevel(int value) {
}

public int addContentApp(ContentApp app) {
return mTvApp.addContentApp(app.getVendorName(), app.getVendorId(), app.getAppName(), app.getProductId(), "1.0", new ContentAppEndpointManagerImpl(context));
return mTvApp.addContentApp(
app.getVendorName(),
app.getVendorId(),
app.getAppName(),
app.getProductId(),
"1.0",
new ContentAppEndpointManagerImpl(context));
}

public void sendTestMessage(int endpoint, String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public void onCreate() {

// Register for packages updates
ContentAppDiscoveryService.getReceiverInstance().registerSelf(this.getApplicationContext());
for (ContentApp app : ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().values()) {
for (ContentApp app :
ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().values()) {
app.setEndpointId(MatterServant.get().addContentApp(app));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.matter.tv.server.utils;

import android.content.Intent;
import android.content.res.Resources;
import android.util.JsonReader;
import android.util.Log;

import com.matter.tv.app.api.SupportedCluster;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
Expand All @@ -31,19 +27,8 @@ public static ResourceUtils getInstance() {
}

/**
{
"clusters": [
{
"identifier": 1234,
"features": ["CS"]
},
{
"identifier": 1235,
"features": ["AS"],
"optionalCommands" : [4, 5]
}
]
}
* { "clusters": [ { "identifier": 1234, "features": ["CS"] }, { "identifier": 1235, "features":
* ["AS"], "optionalCommands" : [4, 5] } ] }
*/

/**
Expand All @@ -52,8 +37,8 @@ public static ResourceUtils getInstance() {
*
* @param resources Resources object containing the resource
* @param resId resourceId
* @return Set<SupportedCluster> containing the clusters defined in the resource file.
* Empty set if there is a parsing error.
* @return Set<SupportedCluster> containing the clusters defined in the resource file. Empty set
* if there is a parsing error.
*/
public Set<SupportedCluster> getSupportedClusters(final Resources resources, final int resId) {
Set<SupportedCluster> supportedClusters = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

public interface ContentAppEndpointManager {

public String sendCommand(int endpointId, String commandPayload);

public String sendCommand(int endpointId, String commandPayload);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.tcl.chip.tvapp;

public class ContentAppEndpointManagerStub implements ContentAppEndpointManager{
public class ContentAppEndpointManagerStub implements ContentAppEndpointManager {

ContentAppEndpointManager delegate;
ContentAppEndpointManager delegate;

public ContentAppEndpointManagerStub(ContentAppEndpointManager delegate){
this.delegate = delegate;
}

@Override
public String sendCommand(int endpointId, String commandPayload) {
return delegate.sendCommand(endpointId, commandPayload);
}
public ContentAppEndpointManagerStub(ContentAppEndpointManager delegate) {
this.delegate = delegate;
}

@Override
public String sendCommand(int endpointId, String commandPayload) {
return delegate.sendCommand(endpointId, commandPayload);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ private void postClusterInit(int clusterId, int endpoint) {

public native void setDACProvider(DACProvider provider);

public native int addContentApp(String vendorName, int vendorId, String appName, int productId, String appVersion, ContentAppEndpointManager manager);
public native int addContentApp(
String vendorName,
int vendorId,
String appName,
int productId,
String appVersion,
ContentAppEndpointManager manager);

public native void sendTestMessage(int endpoint, String message);

Expand Down

0 comments on commit 27c0f3d

Please sign in to comment.