(function(){
var product_id=system.apps.get_direct_launch_product_id();
var args=system.apps.get_direct_launch_arg();
var sid=system.apps.get_direct_launch_dlna_sequence_id();
var lock="use_gwin";
var report={pos:"-1",action:"other"};
if(args){
if(args.indexOf("-l smapho:")!=-1){
report.action="smapho";}
}

switch(product_id){
case INSTALLER2_APPS:
try{
var jump_id=args.match("vmarket:jump=([^ ]+)")[1];
var lockedlist=getLockedList();
if((isString(lockedlist))&&isString(jump_id)&&
lockedlist.indexOf('"'+jump_id+'"')!=-1){
lock="locked";}
}catch(e){console.log(e.message);};
break;
case "0010000200000001":case "0010000200000002":if(args){
if(args.indexOf("-l smapho:")!=-1){
var ret=null;
var dial_arg=get_dial_arg(args);
try{
ret=args.match(new RegExp("-d ([^ ]+)"));}catch(e){};
var opt="";
if(ret&&ret.length==2){
opt="--viera-dial="+ret[1]+" ";}else {
opt="";}
if(dial_arg==null){
args="-Q source_type=10";var tmp=getInfoPlist(product_id,"arg_smapho");
if(tmp)args=tmp;
args=opt+args;}else{
args="-Q source_type=12";if(dial_arg!="")args+="&dial="+encodeURIComponent(dial_arg);
args=opt+args;}
}
else if(args.indexOf("-Q source_type=")!=-1){
}
else
{
args="-Q source_type=1";}
}
break;
case "0077777700140002":if(args){
if(args.indexOf("-l smapho:")!=-1){
var ret=null;
try{
ret=args.match(new RegExp("-d ([^ ]+)"));}catch(e){};
if(!(ret&&ret.length==2))
break;
var rval=read_file("file://"+ret[1]);
if(rval&&rval.indexOf("resource_id=1063")==-1){

weblink.set({"launch_from":weblink.CODE.ICON});
break;}
weblink.set({"launch_from":weblink.CODE.SMARTPHONE,"extra_data":rval});
break;}else if(args.indexOf("-l asr:")!=-1){
report.action="voice";
var c_idx=1;
var engine=0;
var word="";
var ret=null;
try{
ret=args.match(new RegExp("-d ([^ ]+)"));}catch(e){};
if(!(ret&&ret.length==2))
break;

var rval=read_file("file://"+ret[1]);
try{
eval("json_obj = "+rval);
c_idx=Number(json_obj.category);
engine=Number(json_obj.search_engine);
word=json_obj.keyword;}catch(e){};
weblink.set({"launch_from":weblink.CODE.VOICE_SEARCH,
"category":c_idx,
"search_engine":engine,
"keyword":word||""});
break;}else if(args.indexOf("-l recommend:")!=-1){
var ret=null;
var url=null;
try{
ret=args.match(new RegExp("-d ([^ ]+)"));}catch(e){};
if(!(ret&&ret.length==2))
break;
try{
var json_data=read_file("file://"+ret[1]);
eval("json_obj = "+json_data);
url=json_obj.url;}catch(e){};
if(url!=null){
weblink.set({"launch_from":weblink.CODE.BOOKMARK,"url":url,
"extra_data":"yes"});
break;}
}
}
weblink.set({"launch_from":weblink.CODE.ICON});
break
case "0040000800000007":
lock="pass";
break;
default:
break;}
var jsfile="gadget/direct_launch.js";
var exist=apps_nvram_file.apps_exist({product_id:product_id,filename:jsfile});
if(exist){
var body=read_file(APPLI_PATH+product_id+"/"+jsfile);
if(body){
var ret=false;
try{
ret=eval("(function(){"+body+"})();");}catch(e){
console.log("["+product_id+"][direct_launch] "+e.name+": "+e.message);}
if(ret==true)return true;}
}
applink.setFrom({"launch_from":"DIRECT"});
var pbrowser=getInfoPlist(product_id,"pbrowser");
var finished=function(){
var rval=apputil.launch_apl(product_id,args,lock,report,sid,null,null,null,pbrowser);
switch(product_id){
case "0387878700000001":if(rval==apputil.CODE.SUCCESS){
var player=new BroadcastPlayer();
player.df_disconnect();
player.osd_control(OSD_NORMAL);}
break;
default:
break;}
}
if(HOME._operator.components.length!=0&&system.is_enable_launch_appli())
return finished();
append_timer(apputil,40,function(obj,cnt){
if(HOME._operator.components.length==0&&cnt<25)
return;
if(!system.is_enable_launch_appli()&&cnt<125)
return;
delete_timer(obj);
return finished();});})();
