From 27c0f3d1bdf55a485855f547a9602b48e52ac888 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 20 May 2022 22:25:33 +0000 Subject: [PATCH] Restyled by google-java-format --- .../com/matter/tv/server/MainActivity.java | 31 ++++--- .../ContentAppEndpointManagerImpl.java | 33 ++++--- .../matter/tv/server/model/ContentApp.java | 91 ++++++++++--------- .../receivers/ContentAppDiscoveryService.java | 14 ++- .../tv/server/service/MatterServant.java | 9 +- .../server/service/MatterServantService.java | 3 +- .../matter/tv/server/utils/ResourceUtils.java | 23 +---- .../chip/tvapp/ContentAppEndpointManager.java | 3 +- .../tvapp/ContentAppEndpointManagerStub.java | 19 ++-- .../java/src/com/tcl/chip/tvapp/TvApp.java | 8 +- 10 files changed, 116 insertions(+), 118 deletions(-) diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MainActivity.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MainActivity.java index 0fc14edd7a8746..569b99501d353f 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MainActivity.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/MainActivity.java @@ -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 { @@ -111,7 +107,9 @@ public void onStopTrackingTouch(SeekBar seekBar) {} } ContentAppDiscoveryService.getReceiverInstance().registerSelf(this.getApplicationContext()); - ArrayList lst = new ArrayList(ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().keySet()); + ArrayList lst = + new ArrayList( + ContentAppDiscoveryService.getReceiverInstance().getDiscoveredContentApps().keySet()); ContentAppListAdapter adapter = new ContentAppListAdapter(this, R.layout.applist_item, lst); pkgUpdatesView = findViewById(R.id.pkgUpdates); @@ -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(); } } @@ -142,9 +144,7 @@ private class ContentAppListAdapter extends ArrayAdapter { private int layout; public ContentAppListAdapter( - @NonNull Context context, - int resource, - @NonNull ArrayList packages) { + @NonNull Context context, int resource, @NonNull ArrayList packages) { super(context, resource, packages); layout = resource; } @@ -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"); + } } } }); diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/handlers/ContentAppEndpointManagerImpl.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/handlers/ContentAppEndpointManagerImpl.java index 1c8d1d5c9ed1c5..035e7cd84e8c44 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/handlers/ContentAppEndpointManagerImpl.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/handlers/ContentAppEndpointManagerImpl.java @@ -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"; + } } diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/model/ContentApp.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/model/ContentApp.java index 0fa89e28d8fc7d..5d021c198f5830 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/model/ContentApp.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/model/ContentApp.java @@ -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 supportedClusters; - private int endpoint; - - public ContentApp(String appName, String vendorName, int vendorId, int productId, Set 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 getSupportedClusters() { - return Collections.unmodifiableSet(supportedClusters); - } - + private String appName; + private String vendorName; + private int vendorId; + private int productId; + private Set supportedClusters; + private int endpoint; + + public ContentApp( + String appName, + String vendorName, + int vendorId, + int productId, + Set 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 getSupportedClusters() { + return Collections.unmodifiableSet(supportedClusters); + } } diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/receivers/ContentAppDiscoveryService.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/receivers/ContentAppDiscoveryService.java index ceff8532cb09e2..0c4555db2b86e0 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/receivers/ContentAppDiscoveryService.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/receivers/ContentAppDiscoveryService.java @@ -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; @@ -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(); @@ -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 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); diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/MatterServant.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/MatterServant.java index e3a5f1196f9aed..30d8bdf2edcf4e 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/MatterServant.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/MatterServant.java @@ -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; @@ -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) { diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/MatterServantService.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/MatterServantService.java index b2415461afa963..cc68f49c09be07 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/MatterServantService.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/service/MatterServantService.java @@ -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)); } } diff --git a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java index c33520d92797a2..71ccc02f1799b2 100644 --- a/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java +++ b/examples/tv-app/android/App/platform-app/src/main/java/com/matter/tv/server/utils/ResourceUtils.java @@ -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; @@ -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] } ] } */ /** @@ -52,8 +37,8 @@ public static ResourceUtils getInstance() { * * @param resources Resources object containing the resource * @param resId resourceId - * @return Set containing the clusters defined in the resource file. - * Empty set if there is a parsing error. + * @return Set containing the clusters defined in the resource file. Empty set + * if there is a parsing error. */ public Set getSupportedClusters(final Resources resources, final int resId) { Set supportedClusters = new HashSet<>(); diff --git a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ContentAppEndpointManager.java b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ContentAppEndpointManager.java index 596a05af2ff2ef..09bf1f0a0f8b54 100644 --- a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ContentAppEndpointManager.java +++ b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ContentAppEndpointManager.java @@ -2,6 +2,5 @@ public interface ContentAppEndpointManager { - public String sendCommand(int endpointId, String commandPayload); - + public String sendCommand(int endpointId, String commandPayload); } diff --git a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ContentAppEndpointManagerStub.java b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ContentAppEndpointManagerStub.java index b8c52af768e4de..3de920ef95f938 100644 --- a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ContentAppEndpointManagerStub.java +++ b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/ContentAppEndpointManagerStub.java @@ -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); + } } diff --git a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/TvApp.java b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/TvApp.java index 48e90804a4b8f2..3b341a2a3ce8af 100644 --- a/examples/tv-app/android/java/src/com/tcl/chip/tvapp/TvApp.java +++ b/examples/tv-app/android/java/src/com/tcl/chip/tvapp/TvApp.java @@ -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);