
function GC_VoiceControlScreen(){
var list=null;
try{
list=system.voice_control.list();}catch(e){}
if(!list)return;
var uprof=system.user_profile.get({"mhc":{}});
try{
if(uprof.mhc.all.length<0)throw ("none");}catch(e){
uprof={mhc:{all:[]}};}
for(var i=0;i<list.length;i++){
try{
var usrprof_id=null;
var tmp_usrprof_id=list[i].match(VOICE_CONTROL_PREFIX+"([^/]+)$");
if(tmp_usrprof_id)
usrprof_id=parseInt(tmp_usrprof_id[1]);
if(uprof.mhc.all.indexOf(usrprof_id)==-1){
system.voice_control.unset({"filename":list[i]});
continue;}
var path=system.voice_control.get({"filename":list[i]});
var screen_key=getScreenKeyByFilepath(path);
var info=HOME.getScreenInfo(screen_key);
if(!(info&&info.usrprof_id==usrprof_id)){
system.voice_control.unset({"filename":list[i]});
continue;}
}catch(e){
console.log(e.message);}
}
}
function storeVoiceControlScreen(usrprof_id,screen_key){
if(!(isNumber(usrprof_id)&&isScreenKey(screen_key)))
return false;
GC_VoiceControlScreen();
try{
var from=null;
var to=VOICE_CONTROL_PATH+VOICE_CONTROL_PREFIX+usrprof_id;
if(screen_key==null){
system.voice_control.unset({"filename":to});}else if(isDLScreen(screen_key)){
var screen_install_id=getScreenInstallId(screen_key);
from=SCREEN_PATH+screen_install_id+"/screen";
system.voice_control.set({"from":from,"to":to});}else{
from=APPS_DATA_PATH+"home/screen"+screen_key;
system.voice_control.set({"from":from,"to":to});}
}catch(e){
console.log(e.message);
return false;}
return true;}
function getVoiceControlScreen(usrprof_id){
var screen_key=null;
if(!(isNumber(usrprof_id)))
return null;
try{
var filename=VOICE_CONTROL_PATH+VOICE_CONTROL_PREFIX+usrprof_id;
var path=system.voice_control.get({"filename":filename});
if(path){
var tmp_screen_key=getScreenKeyByFilepath(path);
var info=HOME.getScreenInfo(tmp_screen_key);
if(info&&info.usrprof_id==usrprof_id)
screen_key=tmp_screen_key;}
}catch(e){
console.log(e.message);}
console.log("[voice control] usrprof_id:"+usrprof_id+", screen_key:"+screen_key);
return screen_key;}
provide("startup_voice_control_util");
