Skip to content

Commit

Permalink
Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarkov committed Jul 9, 2024
1 parent 40074d2 commit c84abe9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion examples/common/m5stack-tft/repo
13 changes: 13 additions & 0 deletions examples/tv-app/android/App/.idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
tools:ignore="QueryAllPackagesPermission" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<uses-permission android:name="android.permission.GET_TASKS" />


<application
android:allowBackup="true"
android:extractNativeLibs="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.matter.tv.server.handlers;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.matter.tv.app.api.Clusters;
import com.matter.tv.server.model.ContentApp;
Expand All @@ -9,6 +11,7 @@
import com.matter.tv.server.tvapp.ContentAppEndpointManager;
import com.matter.tv.server.utils.EndpointsDataStore;
import java.util.Collection;
import java.util.List;

public class ContentAppEndpointManagerImpl implements ContentAppEndpointManager {

Expand All @@ -20,25 +23,26 @@ public ContentAppEndpointManagerImpl(Context context) {
}

private boolean isForegroundCommand(long clusterId, long commandId) {
switch (clusterId) {
switch ((int)clusterId) {
case Clusters.ContentLauncher.Id:
return commandId == Clusters.ContentLauncher.Commands.LaunchContent.Id;
return commandId == Clusters.ContentLauncher.Commands.LaunchContent.ID ||
commandId == Clusters.ContentLauncher.Commands.LaunchURL.ID;
case Clusters.TargetNavigator.Id:
return commandId == Clusters.TargetNavigator.Commands.NavigateTarget.Id;
return commandId == Clusters.TargetNavigator.Commands.NavigateTarget.ID;
default:
return false;
}
}

private boolean isAppInForeground(String contentAppPackageName) {
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
if (tasks != null && !tasks.isEmpty()) {
ActivityManager.RunningTaskInfo taskInfo = tasks.get(0);
String packageName = taskInfo.topActivity.getPackageName();
return packageName.equals(contentAppPackageName);
}
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
if (tasks != null && !tasks.isEmpty()) {
ActivityManager.RunningTaskInfo taskInfo = tasks.get(0);
String packageName = taskInfo.topActivity != null ? taskInfo.topActivity.getPackageName() : "";
return packageName.equals(contentAppPackageName);
}
return false;
}

Expand All @@ -57,7 +61,7 @@ public String sendCommand(int endpointId, long clusterId, long commandId, String
Intent launchIntent =
context.getPackageManager().getLaunchIntentForPackage(discoveredApp.getAppName());
if (launchIntent != null) {
startActivity(launchIntent);
context.startActivity(launchIntent);
}
}
}
Expand Down

0 comments on commit c84abe9

Please sign in to comment.