فهرست منبع

增加本地U盘播放和app安装功能

wjg 1 سال پیش
والد
کامیت
064174e88f

+ 10 - 0
app/src/main/AndroidManifest.xml

@@ -36,6 +36,16 @@
             </intent-filter>
         </activity>
 
+        <provider
+            android:name="androidx.core.content.FileProvider"
+            android:authorities="com.ch.jedge.llm.filter.glm.FileProvider"
+            android:exported="false"
+            android:grantUriPermissions="true">
+            <meta-data
+                android:name="android.support.FILE_PROVIDER_PATHS"
+                android:resource="@xml/provider_paths" />
+        </provider>
+
         <service
             android:name=".service.MgsService"
             android:exported="false">

+ 6 - 1
app/src/main/assets/cfg/picker/mediaAcc/command.tpl

@@ -2,6 +2,7 @@
         "queryMovie": "咨询电影相关信息",
         "queryMovieUSB": "咨询U盘中的内容",
         "playMovie": "播放电影",
+        "installUSBApp": "安装U盘中的APP",
         "playUSB": "播放U盘里面的内容",
         "copyUSB": "拷贝U盘内容到电视",
         "quitUSB": "退出USB设备",
@@ -23,7 +24,7 @@
 步骤4:将生产的一系列取值,按照指定格式输出
 
 从用户输入内容中抽取分用户的意图,按先后顺序对动作意图和参数进行分析,匹配对应的动作取值,并提取对应参数
-请从"queryMovie,queryMovieUSB,playMovie,playUSB,copyUSB,quitUSB,mdHelp,others"中区分用户动作意图,
+请从"queryMovie,queryMovieUSB,playMovie,playUSB,installUSBApp,copyUSB,quitUSB,mdHelp,others"中区分用户动作意图,
 动作意图取值只在上述取值依据中提取,如果不能识别的动作意图,或者动作意图与参数不能严格对应时,不要输出,
 没有匹配参数时,param设置为空,
 输出格式如下所示,应将全部取值封装为一个list对象:
@@ -40,6 +41,10 @@
 输出:[{"command":"playMovie", "param":{"name":"纪录片宇宙"}]
 输入:'''退出USB硬盘'''
 输出:[{"command":"quitUSB"]
+输入:'''安装U盘中的支付宝app'''
+输出:[{"command":"installUSBApp", "param":{"name":"支付宝"}}}]
+输入:'''安装U盘中的微信软件'''
+输出:[{"command":"installUSBApp", "param":{"name":"微信"}}}]
 输入:'''怎么找片子?'''
 输出:[{"command":"mdHelp"]
 

+ 23 - 11
app/src/main/java/com/ch/jedge/bots/tvass/JedgeTVAssistant.java

@@ -1,6 +1,5 @@
 package com.ch.jedge.bots.tvass;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ch.jedge.jbot2.intent.JDataGetter;
 import com.ch.jedge.jbot2.intent.JbotApi;
@@ -12,7 +11,6 @@ import com.ch.jedge.tvmufis.JeageTVBridge;
 import com.changhong.jedge.JMgbusModual;
 import com.changhong.jedge.JMgbusUtil;
 import com.changhong.jedge.MgbusApi;
-import com.changhong.qlib.QData;
 import com.changhong.qlib.intf.QIData;
 
 import java.util.ArrayList;
@@ -38,8 +36,11 @@ public class JedgeTVAssistant extends JBotAppBase {
             module.warnLog("Remote call %s", eMsg);
             String cmd = eMsg.getString("command");
             JSONObject param = eMsg.getJsonObject("param");
-            if("miPlay".equals(cmd))
-                playMedia(param);
+            if("playUSB".equals(cmd))
+                playUSBMedia(param);
+            else if("installUSBApp".equals(cmd))
+                installUSBApp(param);
+
             return JMgbusUtil.MgbusResult(200, "已知悉,但暂未实现完整功能");
         }
 
@@ -149,15 +150,26 @@ public class JedgeTVAssistant extends JBotAppBase {
         tvBridge.TVsetPictureMode(mode);
 
     }
-    private static void playMedia(JSONObject param) {
+    private static void playUSBMedia(JSONObject param) {
         if(param.isEmpty())
             return;
 
-//        Object obj = param.get(0);
-//        if (obj instanceof String) {
-//            String mode = obj.toString();
-            JeageTVBridge tvBridge = JeageTVBridge.getInstance();
-            tvBridge.TVplayVideo("");
-//        }
+        String name = param.getString("name");
+        if(name == null)
+            return;
+        JeageTVBridge tvBridge = JeageTVBridge.getInstance();
+        tvBridge.TVplayUSBVideo(name);
+
+    }
+    private static void installUSBApp(JSONObject param) {
+        if(param.isEmpty())
+            return;
+
+        String name = param.getString("name");
+        if(name == null)
+            return;
+        JeageTVBridge tvBridge = JeageTVBridge.getInstance();
+        tvBridge.TVinstallUSBApp(name);
+
     }
 }

+ 6 - 1
app/src/main/java/com/ch/jedge/jbot2/JedgeBotGptService.java

@@ -7,6 +7,7 @@ import com.ch.jedge.jbot2.llm.JedgeLLMContext;
 import com.ch.jedge.jbot2.context.JedgeTalkSession;
 import com.ch.jedge.jbot2.context.JedgeSmartTaskContext;
 import com.ch.jedge.jbot2.llm.debug.JedgeLLMDataRecorder;
+import com.ch.jedge.tvmufis.JeageTVBridge;
 import com.ch.jedge.utils.JedgeBotConst;
 import com.ch.jedge.utils.JedgeLlmUtil;
 import com.changhong.jedge.JMgbusModual;
@@ -160,6 +161,10 @@ public class JedgeBotGptService extends JMgbusService {
         msg.putString("text", prompt);
         postServiceMessage("tvmufis", "/tvmfs/usermsg", msg);
 
+//        JeageTVBridge tvBridge = JeageTVBridge.getInstance();
+//        tvBridge.TVplayVideo("视频3");
+//        tvBridge.TVinstallApp("app-debug");
+
         JedgeTalkSession s = findSession(req, prompt);
 
         if(!s.isStream) {  //非流式请求,目前只针对chatGPT
@@ -180,7 +185,7 @@ public class JedgeBotGptService extends JMgbusService {
         });
 
         QIData resp = JedgeLlmUtil.simpleOk();
-        resp.put("sid", s.sid);
+        resp.put("sid", "134244");//s.sid);
         return resp;
     }
 

+ 1 - 1
app/src/main/java/com/ch/jedge/jbot2/intent/JedgeJBotCBService.java

@@ -47,7 +47,7 @@ public class JedgeJBotCBService extends JMgbusService {
             String host = msg.getString("host");
             int port = msg.getInteger("port");
             is_online_ = true;
-            watchMgbusEvent("online", "jbot!", qiData -> {
+            watchMgbusEvent("online", "jbot", qiData -> {
                 synchronized (quitCtrl) {
                     if (!is_active_) {
                         is_active_= true;

+ 72 - 7
app/src/main/java/com/ch/jedge/llm/filter/glm/MainActivity.java

@@ -8,10 +8,13 @@ import androidx.recyclerview.widget.RecyclerView;
 import android.annotation.SuppressLint;
 import android.content.BroadcastReceiver;
 import android.content.Context;
+import android.content.ComponentName;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.media.MediaPlayer;
 import android.os.Bundle;
 import android.util.Log;
+import android.widget.Toast;
 
 import com.ch.jedge.llm.filter.glm.asserts.QAssetsCopyer;
 import com.ch.jedge.llm.filter.glm.service.BaseJedgeService;
@@ -23,9 +26,17 @@ import com.ch.jedge.llm.filter.glm.service.TVAgentService;
 import com.ch.jedge.llm.filter.glm.service.TVMufisService;
 import com.ch.jedge.tvmufis.JeageTVBridge;
 import com.changhong.qlib.util.file.FileUtils;
+import com.changhong.tvos.common.IResourceManager;
+import com.changhong.tvos.common.ISourceManager;
+import com.changhong.tvos.common.TVManager;
+import com.changhong.tvos.common.exception.TVManagerNotInitException;
+import com.changhong.tvos.model.EnumResource;
 
+import java.io.IOException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 public class MainActivity extends AppCompatActivity {
 
@@ -38,6 +49,8 @@ public class MainActivity extends AppCompatActivity {
     private IntentFilter filter = new IntentFilter("intent.jedge.glm.msg");
     private IntentFilter asr_filter = new IntentFilter("com.ch.jedge.llm.filter.glm.asr");
 
+    private String dir, jedgeBasePath;
+
     @SuppressLint("UnspecifiedRegisterReceiverFlag")
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -62,14 +75,22 @@ public class MainActivity extends AppCompatActivity {
         }
         String dir = FileUtils.contactPath(jedgeBasePath, "mgs");
         String jik_dir = FileUtils.contactPath(dir, "jik");
-        QAssetsCopyer.copyAssetFolder(getAssets(), "jik", jik_dir);
+//        QAssetsCopyer.copyAssetFolder(getAssets(), "jik", jik_dir);
+
+        this.dir = dir;
+        this.jedgeBasePath = jedgeBasePath;
 
-        BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "mgs", MgsService.class);
-        BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "jbot", JBotService.class);
-        BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "llm", JGlmService.class);
-        BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "tvass", TVAgentService.class);
-        BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "tvmufis", TVMufisService.class);
-        BaseJedgeService.startJedgeService(this , dir, jedgeBasePath, "jsmart", PanleAgentService.class);
+        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "mgs", MgsService.class);
+        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jbot", JBotService.class);
+        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "llm", JGlmService.class);
+        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvmufis", TVMufisService.class);
+
+//        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "mgs", MgsService.class);
+//        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jbot", JBotService.class);
+//        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "llm", JGlmService.class);
+        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvass", TVAgentService.class);
+//        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvmufis", TVMufisService.class);
+        BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jsmart", PanleAgentService.class);
 
         //注册广播
         registerReceiver(new AsrMsgReceiver(), asr_filter);
@@ -86,6 +107,22 @@ public class MainActivity extends AppCompatActivity {
     protected void onResume() {
         super.onResume();
         LocalBroadcastManager.getInstance(this).registerReceiver(msgReceiver, filter);
+
+//        Thread thread = new Thread(new Runnable() {
+//            @Override
+//            public void run() {
+//                try {
+//                    Thread.sleep(20000);
+//                    BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "tvass", TVAgentService.class);
+//                    BaseJedgeService.startJedgeService(MainActivity.this , dir, jedgeBasePath, "jsmart", PanleAgentService.class);
+//
+//                } catch (InterruptedException e) {
+//                    throw new RuntimeException(e);
+//                }
+//            }
+//        });
+//        thread.start();
+
     }
 
     private void initMsg() {
@@ -104,6 +141,8 @@ public class MainActivity extends AppCompatActivity {
 
         //将RecyclerView定位到最后一行
         mRecyclerView.scrollToPosition(mMsgList.size() - 1);
+        String s = content.getContent();
+        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
     }
 
     class MsgReceiver extends BroadcastReceiver {
@@ -136,4 +175,30 @@ public class MainActivity extends AppCompatActivity {
             bridge.senduserMsg(content);
         }
     }
+
+//    public void startVideoPlayer(String file) {
+//        if (!file.isEmpty()) {
+//            Intent intent = new Intent();
+//            ComponentName comp = new ComponentName("com.changhong.mmp.fileexplorer", "com.changhong.mmp.videoplayer.ChangHongVideoPlayerActivity");
+//            intent.setComponent(comp);
+//            ArrayList<Map<String, Object>> videoPlayNodeList = new ArrayList<Map<String, Object>>();
+//
+//            HashMap<String, Object> movieNode = new HashMap<String, Object>();
+//            movieNode.put("title", "文件名称");
+//            movieNode.put("cn", 1);
+//            String[] str = new String[]{file};
+//            movieNode.put("playUrls", str);
+//            videoPlayNodeList.add(movieNode);
+//
+//            Bundle mData = new Bundle();
+//            mData.putInt("playSourceType", 0);
+//            mData.putInt("curPos", 0);
+//            intent.putExtra("movieNode", videoPlayNodeList);
+//            intent.putExtras(mData);
+//            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+//                    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+//            startActivity(intent);
+//        }
+//    }
+
 }

+ 81 - 57
app/src/main/java/com/ch/jedge/tvmufis/JeageTVBridge.java

@@ -1,37 +1,36 @@
 package com.ch.jedge.tvmufis;
 
+import android.content.ComponentName;
 import android.content.Context;
+import android.content.Intent;
 import android.media.AudioManager;
-import android.media.MediaPlayer;
+
+import android.net.Uri;
+import android.os.Bundle;
 import android.util.Log;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
+
+import androidx.core.content.FileProvider;
+
 import com.ch.jedge.llm.filter.glm.service.TVMufisService;
 import com.changhong.qlib.QData;
 import com.changhong.qlib.intf.QIData;
 import com.changhong.tvos.common.*;
 import com.changhong.tvos.common.exception.IllegalValueException;
-import com.changhong.tvos.common.exception.SourceNotFoundException;
 import com.changhong.tvos.common.exception.TVManagerNotInitException;
 import com.changhong.tvos.model.ChOsType;
-import com.changhong.tvos.model.EnumInputSource;
-import com.changhong.tvos.model.EnumResource;
 
 import java.io.File;
-import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 public class JeageTVBridge {
 
     private static JeageTVBridge bridge = null;
     private TVMufisService tvMufisService;
 
-    private ISourceManager srcm;
-    private MediaPlayerListenner mPlayerListerner;
-    private MediaPlayer mplayer;
-
     private JeageTVBridge(){
 
     }
@@ -172,57 +171,82 @@ public class JeageTVBridge {
 //            throw new RuntimeException(e);
 //        }
 //    }
-    public void TVplayVideo(String name) {
-//        List<HashMap<String, String>> mapList = USBFileManager.GetVideoFile(tvMufisService);
-//        if (mapList.isEmpty())
-//            return;
-//
-//        String file = "";
-//        if(name.isEmpty())
-//            file = mapList.get(0).get("path");
-//        else {
-//            for(HashMap<String, String>hmap : mapList){
-//                String fname = hmap.get("name");
-//                if(name.equals(fname)) {
-//                    file = hmap.get("path");
-//                    break;
-//                }
-//            }
-//        }
-//
-//        if(file.isEmpty())
-//            return;
-        String file = "/storage/8688-F2B5/vedio/视频2.mp4";
-//        String file = "/sdcard/Movies/5.mp4";
-        TVManager tvm = TVManager.getInstance(tvMufisService);
-        try {
+    public void TVplayUSBVideo(String name) {
+        List<HashMap<String, String>> mapList = USBFileManager.GetNeedFile(tvMufisService, "video");
+        if (mapList.isEmpty())
+            return;
 
-            srcm = tvm.getSourceManager();
-            srcm.requestResource(EnumResource.CH_RESOURCE_MMP, "player");
-            mPlayerListerner = new MediaPlayerListenner();
-            srcm.registerResourceListener(mPlayerListerner);
-            if(mplayer != null) {
-                mplayer.reset();
+        String file = "";
+        if(name.isEmpty())
+            file = mapList.get(0).get("path");
+        else {
+            for(HashMap<String, String>hmap : mapList){
+                String fname = hmap.get("name");
+                if(name.equals(fname)) {
+                    file = hmap.get("path");
+                    break;
+                }
             }
-            else
-                mplayer = new MediaPlayer();
-
-            mplayer.setDataSource(file);
-            mplayer.prepare();
-            mplayer.start();
-        } catch (TVManagerNotInitException | IOException e) {
-            throw new RuntimeException(e);
         }
+
+        if(file.isEmpty())
+            return;
+
+        Intent intent = new Intent();
+        ComponentName comp = new ComponentName("com.changhong.mmp.fileexplorer", "com.changhong.mmp.videoplayer.ChangHongVideoPlayerActivity");
+        intent.setComponent(comp);
+        ArrayList<Map<String, Object>> videoPlayNodeList = new ArrayList<Map<String, Object>>();
+
+        HashMap<String, Object> movieNode = new HashMap<String, Object>();
+        movieNode.put("title", name);
+        movieNode.put("cn", 1);
+        String[] str = new String[]{file};
+        movieNode.put("playUrls", str);
+        videoPlayNodeList.add(movieNode);
+
+        Bundle mData = new Bundle();
+        mData.putInt("playSourceType", 0);
+        mData.putInt("curPos", 0);
+        intent.putExtra("movieNode", videoPlayNodeList);
+        intent.putExtras(mData);
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+        tvMufisService.startActivity(intent);
     }
-    class MediaPlayerListenner implements IResourceManager.IResourceListener {
-        @Override
-        public void onResourceLose() {
-            if(mplayer != null){
-                mplayer.stop();
-                mplayer.release();
-                mplayer = null;
+
+    public void TVinstallUSBApp(String name) {
+        List<HashMap<String, String>> mapList = USBFileManager.GetNeedFile(tvMufisService, "app");
+        if (mapList.isEmpty())
+            return;
+
+        String file = "";
+        if(name.isEmpty())
+            file = mapList.get(0).get("path");
+        else {
+            for(HashMap<String, String>hmap : mapList){
+                String fname = hmap.get("name");
+                if(name.equals(fname)) {
+                    file = hmap.get("path");
+                    break;
+                }
             }
-            srcm.unRegisterResourceListener(mPlayerListerner);
         }
+
+        if(file.isEmpty())
+            return;
+
+        Uri uri =  FileProvider.getUriForFile(tvMufisService,"com.ch.jedge.llm.filter.glm.FileProvider", new File(file));
+
+        Intent intent = new Intent();
+        intent.setAction(Intent.ACTION_INSTALL_PACKAGE);
+//        intent.setAction(Intent.ACTION_VIEW);
+        intent.setDataAndType(uri, "application/vnd.android.package-archive");
+        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+                | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
+                |Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+//        intent.putExtra(Intent.EXTRA_RETURN_RESULT,true);
+        intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE,true);
+        tvMufisService.startActivity(intent);
     }
 }

+ 39 - 14
app/src/main/java/com/ch/jedge/tvmufis/USBFileManager.java

@@ -14,6 +14,7 @@ import java.util.Map;
 public class USBFileManager {
     private static List<String> usbPaths = new ArrayList<>();
     private static List<HashMap<String, String>> videoFiles = new ArrayList<>();
+    private static List<HashMap<String, String>> appFiles = new ArrayList<>();
 
     USBFileManager(){
 
@@ -36,9 +37,16 @@ public class USBFileManager {
         }
     }
 
-    public static List<HashMap<String, String>> GetVideoFile(Context context) {
-        if(!videoFiles.isEmpty())
-            return videoFiles;
+    public static List<HashMap<String, String>> GetNeedFile(Context context, String type) {
+        if("video".equals(type)) {
+            if(!videoFiles.isEmpty())
+                return videoFiles;
+        }
+
+        if("app".equals(type)) {
+            if(!appFiles.isEmpty())
+                return appFiles;
+        }
 
         if(usbPaths.isEmpty())
             getUsbPath(context);
@@ -48,32 +56,49 @@ public class USBFileManager {
             File usbDirectory = new File(usbDrivePath);
             if (usbDirectory.exists() && usbDirectory.isDirectory()) {
                 // 递归遍历文件夹并查找视频文件
-                searchForVideos(usbDirectory);
+                searchForFiles(usbDirectory, type);
             }
         }
 
+        if("app".equals(type))
+            return appFiles;
+
         return videoFiles;
     }
 
-    private static void searchForVideos(File directory) {
+    private static void searchForFiles(File directory, String type) {
         File[] files = directory.listFiles();
         if (files != null) {
             for (File file : files) {
                 if (file.isDirectory()) {
                         // 递归遍历子目录
-                    searchForVideos(file);
+                    searchForFiles(file, type);
                 }
                 else {
                         // 检查文件扩展名以确定是否为视频文件
+
                     String fileName = file.getName().toLowerCase();
-                    if (fileName.endsWith(".mp4") || fileName.endsWith(".mkv") || fileName.endsWith(".avi")) {
-                        HashMap<String, String> hmap = new HashMap<>();
-                        String fname = file.getName();
-                        int dotIndex = fname.indexOf('.');
-                        String name = fname.substring(0, dotIndex);
-                        hmap.put("name", name);
-                        hmap.put("path", file.getAbsolutePath());
-                        videoFiles.add(hmap);
+                    if("video".equals(type)) {
+                        if (fileName.endsWith(".mp4") || fileName.endsWith(".mkv") || fileName.endsWith(".avi")) {
+                            HashMap<String, String> hmap = new HashMap<>();
+                            String fname = file.getName();
+                            int dotIndex = fname.indexOf('.');
+                            String name = fname.substring(0, dotIndex);
+                            hmap.put("name", name);
+                            hmap.put("path", file.getAbsolutePath());
+                            videoFiles.add(hmap);
+                        }
+                    }
+                    else if("app".equals(type)) {
+                        if (fileName.endsWith(".apk")) {
+                            HashMap<String, String> hmap = new HashMap<>();
+                            String fname = file.getName();
+                            int dotIndex = fname.indexOf('.');
+                            String name = fname.substring(0, dotIndex);
+                            hmap.put("name", name);
+                            hmap.put("path", file.getAbsolutePath());
+                            appFiles.add(hmap);
+                        }
                     }
                 }
             }

+ 11 - 0
app/src/main/res/xml/provider_paths.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resource>
+    <paths xmlns:android="http://schemas.android.com/apk/res/android">
+        <root-path name="root" path="" />
+        <files-path name="files" path="" />
+        <cache-path name="cache" path="" />
+        <external-path name="external" path="" />
+        <external-files-path name="external_file" path="" />
+        <external-cache-path name="external_cache" path="" />
+    </paths>
+</resource>