├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── apps ├── .gitignore ├── bareapp │ ├── appinfo.json │ ├── icon.png │ ├── img.jpg │ └── index.html ├── com.webos.app.sam-native-registered │ ├── appinfo.json │ ├── child.sh │ ├── icon.png │ └── main.sh ├── com.webos.app.sam-native │ ├── .main.sh.swp │ ├── appinfo.json │ ├── child.sh │ ├── icon.png │ └── main.sh ├── com.webos.app.sam-qml │ ├── appinfo.json │ ├── icon.png │ └── main.qml └── generate.sh ├── doc └── Doxyfile.in ├── files ├── conf │ └── sam-conf.json.in ├── schema │ ├── ApplicationDescription.schema │ ├── applicationManager.addLaunchPoint.schema │ ├── applicationManager.addVirtualApp.schema │ ├── applicationManager.closeByAppId.schema │ ├── applicationManager.getAppBasePath.schema │ ├── applicationManager.getAppInfo.schema │ ├── applicationManager.getAppStatus.schema │ ├── applicationManager.getForegroundAppInfo.schema │ ├── applicationManager.getHandlerForExtension.schema │ ├── applicationManager.getHandlerForMimeType.schema │ ├── applicationManager.getHandlerForUrl.schema │ ├── applicationManager.getHandlerForUrlByVerb.schema │ ├── applicationManager.launch.schema │ ├── applicationManager.launchVirtualApp.schema │ ├── applicationManager.listAllHandlersForMime.schema │ ├── applicationManager.listAllHandlersForMultipleMime.schema │ ├── applicationManager.listAllHandlersForMultipleUrlPattern.schema │ ├── applicationManager.listAllHandlersForUrl.schema │ ├── applicationManager.listAllHandlersForUrlByVerb.schema │ ├── applicationManager.listAllHandlersForUrlPattern.schema │ ├── applicationManager.listApps.schema │ ├── applicationManager.listLaunchPoints.schema │ ├── applicationManager.lockApp.schema │ ├── applicationManager.mimeTypeForExtension.schema │ ├── applicationManager.notifyAlertClosed.schema │ ├── applicationManager.open.schema │ ├── applicationManager.registerApp.schema │ ├── applicationManager.removeLaunchPoint.schema │ ├── applicationManager.removeVirtualApp.schema │ ├── applicationManager.running.schema │ ├── applicationManager.searchApps.schema │ ├── applicationManager.updateLaunchPoint.schema │ ├── deletedSystemAppList.schema │ ├── foregroundAppInfo.schema │ └── sam-conf.schema └── sysbus │ ├── com.webos.sam.api.json │ ├── com.webos.sam.groups.json │ ├── com.webos.sam.perm.json │ ├── com.webos.sam.role.json.in │ └── com.webos.sam.service.in ├── oss-pkg-info.yaml └── src ├── Environment.h.in ├── Main.cpp ├── MainDaemon.cpp ├── MainDaemon.h ├── base ├── AppDescription.cpp ├── AppDescription.h ├── AppDescriptionList.cpp ├── AppDescriptionList.h ├── LaunchPoint.cpp ├── LaunchPoint.h ├── LaunchPointList.cpp ├── LaunchPointList.h ├── LunaTask.cpp ├── LunaTask.h ├── LunaTaskList.cpp ├── LunaTaskList.h ├── RunningApp.cpp ├── RunningApp.h ├── RunningAppList.cpp └── RunningAppList.h ├── bus ├── client │ ├── AbsLifeHandler.cpp │ ├── AbsLifeHandler.h │ ├── AbsLunaClient.cpp │ ├── AbsLunaClient.h │ ├── AppInstallService.cpp │ ├── AppInstallService.h │ ├── Bootd.cpp │ ├── Bootd.h │ ├── Configd.cpp │ ├── Configd.h │ ├── DB8.cpp │ ├── DB8.h │ ├── LSM.cpp │ ├── LSM.h │ ├── MemoryManager.cpp │ ├── MemoryManager.h │ ├── NativeContainer.cpp │ ├── NativeContainer.h │ ├── Notification.cpp │ ├── Notification.h │ ├── SettingService.cpp │ ├── SettingService.h │ ├── WAM.cpp │ └── WAM.h └── service │ ├── ApplicationManager.cpp │ ├── ApplicationManager.h │ ├── SchemaChecker.cpp │ ├── SchemaChecker.h │ └── compat │ └── ApplicationManagerCompat.h ├── conf ├── .gitignore ├── RuntimeInfo.cpp ├── RuntimeInfo.h ├── SAMConf.cpp └── SAMConf.h ├── interface ├── IClassName.h ├── IInitializable.h ├── ISerializable.h └── ISingleton.h ├── manager ├── PolicyManager.cpp └── PolicyManager.h └── util ├── File.cpp ├── File.h ├── JValueUtil.cpp ├── JValueUtil.h ├── Logger.cpp ├── Logger.h ├── NativeProcess.cpp ├── NativeProcess.h ├── Time.cpp └── Time.h /.gitignore: -------------------------------------------------------------------------------- 1 | BUILD* 2 | build 3 | .vscode 4 | code.sh 5 | *.kdev4 6 | build-sam.stamp 7 | resources 8 | screenlog* 9 | *ipk 10 | sa8155* -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012-2024 LG Electronics, Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # SPDX-License-Identifier: Apache-2.0 16 | 17 | # 18 | # sam/CMakeLists.txt 19 | # 20 | 21 | cmake_minimum_required(VERSION 2.8.7) 22 | 23 | project(sam C CXX) 24 | 25 | include(webOS/webOS) 26 | 27 | webos_modules_init(1 0 0 QUALIFIER RC4) 28 | webos_component(2 0 0) 29 | webos_add_compiler_flags(ALL -Wall -std=gnu++0x) 30 | webos_add_compiler_flags(ALL -DBOOST_SIGNALS_NO_DEPRECATION_WARNING) 31 | 32 | add_definitions(-DLOGGER_ENABLED) 33 | 34 | include(FindPkgConfig) 35 | 36 | pkg_check_modules(GLIB2 REQUIRED glib-2.0) 37 | include_directories(${GLIB2_INCLUDE_DIRS}) 38 | webos_add_compiler_flags(ALL ${GLIB2_CFLAGS_OTHER}) 39 | 40 | pkg_check_modules(GIO2 REQUIRED gio-2.0) 41 | include_directories(${GIO2_INCLUDE_DIRS}) 42 | webos_add_compiler_flags(ALL ${GIO2_CFLAGS_OTHER}) 43 | 44 | pkg_check_modules(PBNJSON_C REQUIRED pbnjson_c) 45 | include_directories(${PBNJSON_C_INCLUDE_DIRS}) 46 | webos_add_compiler_flags(ALL ${PBNJSON_C_CFLAGS_OTHER}) 47 | 48 | pkg_check_modules(PBNJSON_CPP REQUIRED pbnjson_cpp) 49 | include_directories(${PBNJSON_CPP_INCLUDE_DIRS}) 50 | webos_add_compiler_flags(ALL ${PBNJSON_CPP_CFLAGS_OTHER}) 51 | 52 | pkg_check_modules(PMLOG REQUIRED PmLogLib) 53 | include_directories(${PMLOG_INCLUDE_DIRS}) 54 | webos_add_compiler_flags(ALL ${PMLOG_CFLAGS_OTHER}) 55 | 56 | pkg_check_modules(LUNASERVICE2 REQUIRED luna-service2) 57 | include_directories(${LUNASERVICE2_INCLUDE_DIRS}) 58 | webos_add_compiler_flags(ALL ${LUNASERVICE2_CFLAGS_OTHER}) 59 | 60 | pkg_check_modules(LUNASERVICE2CPP REQUIRED luna-service2++) 61 | include_directories(${LUNASERVICE2CPP_INCLUDE_DIRS}) 62 | webos_add_compiler_flags(ALL ${LUNASERVICE2CPP_CFLAGS_OTHER}) 63 | 64 | find_package(Boost REQUIRED COMPONENTS regex system filesystem) 65 | include_directories(${Boost_INCLUDE_DIRS}) 66 | webos_add_compiler_flags(ALL ${Boost_CFLAGS_OTHER}) 67 | 68 | find_library(ICU NAMES icuuc) 69 | if(ICU STREQUAL "ICU-NOTFOUND") 70 | message(FATAL_ERROR "Failed to find ICU4C libraries. Please install.") 71 | endif() 72 | 73 | find_library(RT NAMES rt) 74 | if(RT STREQUAL "RT-NOTFOUND") 75 | message(FATAL_ERROR "Failed to find rt libraries. Please link.") 76 | endif() 77 | 78 | # Require that all undefined symbols are satisfied by the libraries from target_link_libraries() 79 | webos_add_linker_options(ALL --no-undefined) 80 | 81 | # Build the sam executable 82 | file(GLOB_RECURSE SOURCES src/*.cpp) 83 | 84 | webos_configure_source_files(cfg ${PROJECT_SOURCE_DIR}/src/Environment.h) 85 | 86 | include_directories(src) 87 | include_directories(${PROJECT_BINARY_DIR}/Configured/src) 88 | add_executable(${CMAKE_PROJECT_NAME} ${SOURCES}) 89 | 90 | set(LIBS 91 | ${GLIB2_LDFLAGS} 92 | ${GIO2_LDFLAGS} 93 | ${PBNJSON_C_LDFLAGS} 94 | ${PBNJSON_CPP_LDFLAGS} 95 | ${LUNASERVICE2_LDFLAGS} 96 | ${LUNASERVICE2CPP_LDFLAGS} 97 | ${PMLOG_LDFLAGS} 98 | ${Boost_LIBRARIES} 99 | ${ICU} 100 | ${RT} 101 | ) 102 | target_link_libraries(${CMAKE_PROJECT_NAME} ${LIBS}) 103 | 104 | webos_build_system_bus_files() 105 | 106 | file(GLOB_RECURSE SCHEMAS files/schema/*.schema) 107 | install(FILES ${SCHEMAS} DESTINATION ${WEBOS_INSTALL_WEBOS_SYSCONFDIR}/schemas/sam) 108 | install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${WEBOS_INSTALL_SBINDIR}) 109 | 110 | # sam conf files 111 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/files/conf/sam-conf.json.in ${CMAKE_CURRENT_BINARY_DIR}/files/conf/sam-conf.json) 112 | 113 | file(GLOB_RECURSE SAM_CONF_FILES ${CMAKE_CURRENT_BINARY_DIR}/files/conf/*) 114 | install(FILES ${SAM_CONF_FILES} DESTINATION ${WEBOS_INSTALL_WEBOS_SYSCONFDIR}) 115 | 116 | webos_config_build_doxygen(doc Doxyfile) 117 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Summary 2 | ------- 3 | SAM is responsible for systems and application management 4 | 5 | Description 6 | ----------- 7 | 8 | SAM is responsible for 9 | * Managing the running of applications 10 | * Managing the installation and removal of applications 11 | 12 | Dependencies 13 | --------------------- 14 | 15 | Below are the tools and libraries required to build SAM: 16 | 17 | * cmake 18 | * gcc 19 | * glib-2.0 20 | * make 21 | * pkg-config 22 | * Boost library (signals and regex) 23 | * libicu-dev 24 | * webosose/cmake-modules-webos 25 | * webosose/pmloglib 26 | * webosose/libpbnjson 27 | * webosose/luna-service2 28 | 29 | ## Building 30 | 31 | Once you have downloaded the source, enter the following to build it (after 32 | changing into the directory under which it was downloaded): 33 | 34 | $ mkdir BUILD 35 | $ cd BUILD 36 | $ cmake .. 37 | $ make 38 | 39 | Copyright and License Information 40 | ================================= 41 | Unless otherwise specified, all content, including all source code files and 42 | documentation files in this repository are: 43 | 44 | Copyright (c) 2012-2018 LG Electronics, Inc. 45 | 46 | Licensed under the Apache License, Version 2.0 (the "License"); 47 | you may not use this file except in compliance with the License. 48 | You may obtain a copy of the License at 49 | 50 | http://www.apache.org/licenses/LICENSE-2.0 51 | 52 | Unless required by applicable law or agreed to in writing, software 53 | distributed under the License is distributed on an "AS IS" BASIS, 54 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 55 | See the License for the specific language governing permissions and 56 | limitations under the License. 57 | 58 | SPDX-License-Identifier: Apache-2.0 59 | -------------------------------------------------------------------------------- /apps/.gitignore: -------------------------------------------------------------------------------- 1 | *.ipk 2 | -------------------------------------------------------------------------------- /apps/bareapp/appinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "bareapp", 3 | "version": "99.99.99", 4 | "vendor": "LG Electronics, Inc.", 5 | "type": "web", 6 | "main": "index.html", 7 | "title": "Bare App", 8 | "uiRevision": "2", 9 | "miniicon": "icon.png", 10 | "largeIcon": "icon.png", 11 | "icon": "icon.png" 12 | } 13 | -------------------------------------------------------------------------------- /apps/bareapp/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webosose/sam/96161d3e50670fb21daccfb12a75c35fe406ce0e/apps/bareapp/icon.png -------------------------------------------------------------------------------- /apps/bareapp/img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webosose/sam/96161d3e50670fb21daccfb12a75c35fe406ce0e/apps/bareapp/img.jpg -------------------------------------------------------------------------------- /apps/bareapp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Bare App 6 | 7 | 8 | 9 | 10 | 26 | 27 | 28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native-registered/appinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "com.webos.app.sam-native-registered", 3 | "title": "SAM Native Registered", 4 | "vendor": "LGE", 5 | "type": "native", 6 | "version": "1.0.0", 7 | "main": "main.sh", 8 | "icon": "icon.png", 9 | "iconColor":"#289CE4", 10 | "uiRevision": 2 11 | } 12 | -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native-registered/child.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | sleep 100 3 | -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native-registered/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webosose/sam/96161d3e50670fb21daccfb12a75c35fe406ce0e/apps/com.webos.app.sam-native-registered/icon.png -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native-registered/main.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo '' 3 | echo '== Step 1 : Export Grobal variables ==' 4 | export 5 | sleep 2 6 | 7 | echo '' 8 | echo '== Step 2 : Fork Child Process ==' 9 | . ./child.sh & 10 | . ./invalid.sh & 11 | sleep 2 12 | 13 | echo '' 14 | echo '== Step 3 : Check Resister Native App ==' 15 | luna-send -a com.webos.app.sam-native-registered -f -n 2 luna://com.webos.service.applicationmanager/registerApp '{}' 16 | sleep 100 17 | -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native/.main.sh.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webosose/sam/96161d3e50670fb21daccfb12a75c35fe406ce0e/apps/com.webos.app.sam-native/.main.sh.swp -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native/appinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "com.webos.app.sam-native", 3 | "title": "SAM Native", 4 | "vendor": "LGE", 5 | "type": "native", 6 | "version": "1.0.0", 7 | "main": "main.sh", 8 | "icon": "icon.png", 9 | "iconColor":"#289CE4", 10 | "uiRevision": 2 11 | } 12 | -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native/child.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | sleep 100 3 | -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webosose/sam/96161d3e50670fb21daccfb12a75c35fe406ce0e/apps/com.webos.app.sam-native/icon.png -------------------------------------------------------------------------------- /apps/com.webos.app.sam-native/main.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo '' 3 | echo '== Step 1 : Print Grobal variables ==' 4 | export 5 | sleep 2 6 | 7 | echo '== Step 2 : Sleep 100 ==' 8 | sleep 100 9 | -------------------------------------------------------------------------------- /apps/com.webos.app.sam-qml/appinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "com.webos.app.sam-qml", 3 | "title": "SAM QML", 4 | "vendor": "LGE", 5 | "type": "qml", 6 | "version": "1.0.0", 7 | "main": "main.qml", 8 | "icon": "icon.png", 9 | "iconColor":"#289CE4" 10 | } 11 | -------------------------------------------------------------------------------- /apps/com.webos.app.sam-qml/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webosose/sam/96161d3e50670fb21daccfb12a75c35fe406ce0e/apps/com.webos.app.sam-qml/icon.png -------------------------------------------------------------------------------- /apps/com.webos.app.sam-qml/main.qml: -------------------------------------------------------------------------------- 1 | import QtQuick 2.4 2 | import Eos.Window 0.1 3 | import QtQuick.Window 2.2 4 | 5 | WebOSWindow { 6 | id: root 7 | title: "Bare Eos Window" 8 | displayAffinity: params["displayAffinity"] 9 | width: 1920 10 | height: 1080 11 | visible: true 12 | color: "yellow" 13 | } 14 | -------------------------------------------------------------------------------- /apps/generate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ares-package com.webos.app.sam-native 3 | ares-package com.webos.app.sam-native-registered 4 | ares-package com.webos.app.sam-qml 5 | ares-package bareapp 6 | -------------------------------------------------------------------------------- /files/conf/sam-conf.json.in: -------------------------------------------------------------------------------- 1 | { 2 | "ApplicationPaths": [ 3 | { 4 | "typeByDir": "system_builtin", 5 | "path": "@WEBOS_INSTALL_MNTDIR@/otycabi/usr/palm/applications" 6 | }, 7 | { 8 | "typeByDir": "system_builtin", 9 | "path": "@WEBOS_INSTALL_MNTDIR@/otncabi/usr/palm/applications" 10 | }, 11 | { 12 | "typeByDir": "system_builtin", 13 | "path": "@WEBOS_INSTALL_WEBOS_APPLICATIONSDIR@" 14 | }, 15 | { 16 | "typeByDir": "system_updatable", 17 | "path": "@WEBOS_INSTALL_MEDIADIR@/system/apps/usr/palm/applications" 18 | }, 19 | { 20 | "typeByDir": "store", 21 | "path": "@WEBOS_INSTALL_INSTALLEDAPPSDIR@" 22 | }, 23 | { 24 | "typeByDir": "dev", 25 | "path": "@WEBOS_INSTALL_MEDIADIR@/developer/apps/usr/palm/applications" 26 | } 27 | ], 28 | 29 | "DevModePath": "@WEBOS_INSTALL_SYSMGR_LOCALSTATEDIR@/preferences/devmode_enabled", 30 | "JailModePath": "@WEBOS_INSTALL_SYSMGR_LOCALSTATEDIR@/preferences/jailer_disabled", 31 | "JailerPath": "@WEBOS_INSTALL_BINDIR@/jailer", 32 | "QmlRunnerPath": "@WEBOS_INSTALL_BINDIR@/qml-runner", 33 | "AppShellRunnerPath": "@WEBOS_INSTALL_BINDIR@/app-shell/run_app_shell", 34 | "BrowserShellRunnerPath" :"@WEBOS_INSTALL_BINDIR@/browser-shell/run_browser_shell", 35 | 36 | "FullscreenWindowType": [ 37 | "_WEBOS_WINDOW_TYPE_CARD", 38 | "_WEBOS_WINDOW_TYPE_RESTRICTED" 39 | ], 40 | 41 | "NoJailApps" : [ 42 | "com.webos.app.voiceagent", 43 | "com.webos.app.voiceview", 44 | "com.webos.app.multiview", 45 | "com.webos.app.livemenu", 46 | "com.webos.app.factorywin", 47 | "com.webos.app.fingergesture", 48 | "com.webos.app.livetv", 49 | "com.webos.app.inputcommon", 50 | "com.webos.app.externalinput.component", 51 | "com.webos.app.hdmi1", 52 | "com.webos.app.hdmi2", 53 | "com.webos.app.hdmi3", 54 | "com.webos.app.hdmi4", 55 | "com.webos.app.tvhotkey", 56 | "com.webos.app.voice", 57 | "com.webos.app.searchanddiscovery", 58 | "com.webos.app.externalinput.av1", 59 | "com.webos.app.externalinput.av2", 60 | "com.webos.app.externalinput.scart", 61 | "com.webos.app.livezoom-inhdmi1", 62 | "com.webos.app.livezoom-inhdmi2", 63 | "com.webos.app.livezoom-inhdmi3", 64 | "com.webos.app.livezoom-inhdmi4", 65 | "com.webos.app.livezoom-intv", 66 | "com.webos.app.livezoom-inphotovideo", 67 | "com.webos.app.twinzoom-inhdmi1", 68 | "com.webos.app.twinzoom-inhdmi2", 69 | "com.webos.app.twinzoom-inhdmi3", 70 | "com.webos.app.twinzoom-inhdmi4", 71 | "com.webos.app.twinzoom-intv", 72 | "com.webos.app.dvrpopup", 73 | "com.webos.app.smhl", 74 | "com.webos.app.tips", 75 | "com.webos.app.livezoom-inrecordings", 76 | "com.webos.app.externalinput.rgb", 77 | "com.webos.app.ism" 78 | ], 79 | 80 | "keepAliveApps":[ 81 | "com.webos.app.home" 82 | ], 83 | 84 | "HostAppsForAlias":[ 85 | "com.webos.app.webapphost" 86 | ], 87 | 88 | "ReservedResource": { 89 | "mime": [ 90 | "application/vnd.lge.appstore" 91 | ] 92 | }, 93 | 94 | "LaunchPointDBKind": { 95 | "id":"com.webos.applicationManager.launchpoints:2", 96 | "owner":"com.webos.applicationManager", 97 | "schema":{ 98 | "properties":{ 99 | "id":{"type":"string", "description":"unique id of app", "optional":false}, 100 | "type":{"type":"string", "description":"type of launchpoint", "optional":false}, 101 | "launchPointId":{"type":"string", "description":"unique id of launchpoint", "optional":false}, 102 | "title":{"type":"string", "description":"title of app", "optional":true}, 103 | "icon":{"type":"string", "description":"path of icon", "optional":true}, 104 | "bgImage":{"type":"string", "description":"path of backgroundImage", "optional":true}, 105 | "bgImages":{"type":"array", "items":{"type":"string"}, "description":"path for multiple backgroundImages", "optional":true}, 106 | "bgColor":{"type":"string", "description":"backgroundColor", "optional":true}, 107 | "imageForRecents":{"type":"string","description":"location of bitmap : displayed in the recent apps list","optional":true}, 108 | "iconColor":{"type":"string", "description":"indicates color of the icon of the launchpoint", "optional":true}, 109 | "largeIcon":{"type":"string", "description":"path of largeIcon", "optional":true}, 110 | "favicon":{"type":"string", "description":"path of favicon", "optional":true}, 111 | "appDescription":{"type":"string", "description": "A short tagline for the app", "optional":true}, 112 | "params":{"type":"object", "description":"parameters", "optional":true}, 113 | "userData":{"type":"string", "description": "Additional data that may be used by clients", "optional":true}, 114 | "tileSize":{"type":"string", "enum": [ "normal", "large" ], "default": "normal", "description": "Hint for UI tiling size", "optional": true}, 115 | "unmovable":{"type":"boolean", "description": "Hint that item should not be editable by user", "optional": true} 116 | } 117 | }, 118 | 119 | "indexes":[ 120 | {"name":"id", "props":[{"name":"id"}]}, 121 | {"name":"type", "props":[{"name":"type"}]}, 122 | {"name":"launchPointId", "props":[{"name":"launchPointId"}]}, 123 | {"name":"revision", "props":[{"name":"_rev"}]} 124 | ] 125 | }, 126 | 127 | "LaunchPointDBPermissions": { 128 | "permissions": [ 129 | { 130 | "type" : "db.kind", 131 | "object" : "com.webos.applicationManager.launchpoints:2", 132 | "caller" : "com.webos.applicationManager", 133 | "operations": { 134 | "create" : "allow", 135 | "read" : "allow", 136 | "update" : "allow", 137 | "delete" : "allow" 138 | } 139 | } 140 | ] 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /files/schema/applicationManager.addLaunchPoint.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.addLaunchPoint", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "ID of application to generate launch point" 8 | }, 9 | "title": { 10 | "type": "string", 11 | "description": "Title for the launch point" 12 | }, 13 | "icon": { 14 | "type": "string", 15 | "description": "Path to icon" 16 | }, 17 | "bgImage": { 18 | "type": "string", 19 | "description": "This field is the location of a bitmap. The bitmap is displayed to the user when the user hovers over the launch point with the system pointer." 20 | }, 21 | "bgImages": { 22 | "type": "array", 23 | "items": { 24 | "type": "string" 25 | }, 26 | "default" : [], 27 | "description": "Locations of bitmaps that may be displayed to the user when the user hovers over the launch point with the system pointer." 28 | }, 29 | "bgColor": { 30 | "type": "string", 31 | "description": "This field is the color to be displayed to the user when the user hovers over the launch point with the system pointer. This is used in the absence of the backgroundImage." 32 | }, 33 | "imageForRecents": { 34 | "type": "string", 35 | "description": "This field is the location of a bitmap. The bitmap is displayed in the recent apps list." 36 | }, 37 | "iconColor": { 38 | "type": "string", 39 | "description": "indicates color of the icon of the launch point." 40 | }, 41 | "largeIcon": { 42 | "type": "string", 43 | "description": "path to largeIcon" 44 | }, 45 | "appDescription": { 46 | "type": "string", 47 | "description": "A short tagline for the application" 48 | }, 49 | "params": { 50 | "type": "object", 51 | "description": "Parameters to pass to the application" 52 | }, 53 | "userData": { 54 | "type": "string", 55 | "description": "Additional data that may be used by clients, such as an identifier for analytics purposes" 56 | }, 57 | "tileSize": { 58 | "type": "string", 59 | "enum": [ "normal", "large" ], 60 | "default": "normal", 61 | "description": "Hint for sizing of UI tiles: normal or large, large may be used for a promotional item" 62 | }, 63 | "unmovable": { 64 | "type": "boolean", 65 | "default": false, 66 | "description": "Hint that an item should never be moved from it's given position" 67 | }, 68 | "supportI18nTitle": { 69 | "type": "boolean", 70 | "default": true, 71 | "description": "Hint that i18n will be supported for title" 72 | } 73 | }, 74 | "required": [ 75 | "id" 76 | ] 77 | } 78 | -------------------------------------------------------------------------------- /files/schema/applicationManager.addVirtualApp.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.addVirtualApp", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "virtual application ID to be created." 8 | }, 9 | "hostId": { 10 | "type": "string", 11 | "description": "host application id for virtual application." 12 | }, 13 | "appInfo": { 14 | "type": "object", 15 | "description": "appInfo for virtual application.", 16 | "default": {} 17 | }, 18 | "params": { 19 | "type": "object", 20 | "description": "params to be passed to host application as launch params.", 21 | "default": {} 22 | } 23 | }, 24 | "required": [ 25 | "id", 26 | "hostId", 27 | "params" 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /files/schema/applicationManager.closeByAppId.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.closeByAppId", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "Application ID to be closed." 8 | } 9 | }, 10 | "required": [ 11 | "id" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.getAppBasePath.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.getAppBasePath", 3 | "type": "object", 4 | "properties": { 5 | "appId": { 6 | "type": "string", 7 | "description": "Get application base path for a given application ID." 8 | } 9 | }, 10 | "required": [ 11 | "appId" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.getAppInfo.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.getAppInfo", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "Get application information for a given application ID." 8 | }, 9 | "properties": { 10 | "type": "array", 11 | "description": "Get application information for service-user selected properties." 12 | } 13 | }, 14 | "required": [ 15 | "id" 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /files/schema/applicationManager.getAppStatus.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.getAppStatus", 3 | "type": "object", 4 | "properties": { 5 | "appId": { 6 | "type": "string" 7 | }, 8 | "appInfo": { 9 | "type": "boolean", 10 | "default": false 11 | } 12 | }, 13 | "required": [ 14 | "appId" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /files/schema/applicationManager.getForegroundAppInfo.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.getForegroundAppInfo", 3 | "type": "object", 4 | "properties": { 5 | "extraInfo": { 6 | "type": "boolean", 7 | "description": "If set to true, returns all foreground apps as an array. Otherwise, returns only a full screen app (e.g. card type)" 8 | }, 9 | "subscribe": { 10 | "type": "boolean" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.getHandlerForExtension.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.getHandlerForExtension", 3 | "type": "object", 4 | "properties": { 5 | "extension": { 6 | "type": "string", 7 | "description": "The extension for getting handler application." 8 | } 9 | }, 10 | "required": [ 11 | "extension" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.getHandlerForMimeType.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.getHandlerForMimeType", 3 | "type": "object", 4 | "properties": { 5 | "mimeType": { 6 | "type": "string", 7 | "description": "The mime type for getting handler application." 8 | } 9 | }, 10 | "required": [ 11 | "mimeType" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.getHandlerForUrl.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.getHandlerForUrl", 3 | "type": "object", 4 | "properties": { 5 | "url": { 6 | "type": "string", 7 | "description": "The url for getting handler application." 8 | } 9 | }, 10 | "required": [ 11 | "url" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.getHandlerForUrlByVerb.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.getHandlerForUrlByVerb", 3 | "type": "object", 4 | "properties": { 5 | "url": { 6 | "type": "string", 7 | "description": "The url for getting handler application by verb." 8 | }, 9 | "mime": { 10 | "type": "string", 11 | "description": "The mime for getting handler application by verb." 12 | }, 13 | "verb": { 14 | "type": "string", 15 | "description": "The verb for getting handler application." 16 | } 17 | }, 18 | "required": [ 19 | "verb" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /files/schema/applicationManager.launch.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.launch", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "Application ID to be launched." 8 | }, 9 | "launchPointId": { 10 | "type": "string", 11 | "description": "LaunchPoint ID to be launched." 12 | }, 13 | "instanceId": { 14 | "type": "string", 15 | "description": "Instance ID to be relaunched." 16 | }, 17 | "checkUpdateOnLaunch": {"type" : "boolean"}, 18 | "params" : {"type" : "object"}, 19 | "target" : {"type" : "string"}, 20 | "noSplash" : {"type" : "boolean"}, 21 | "spinner" : {"type" : "boolean"}, 22 | "launchHidden" : {"type" : "boolean"}, 23 | "keepAlive" : {"type" : "boolean"}, 24 | "autoInstallation" : {"type" : "boolean"}, 25 | "containerBasedApp " : {"type" : "boolean"}, 26 | "launchFirstApp" : {"type" : "boolean"}, 27 | "preload": { 28 | "type": "string", 29 | "enum": ["full", "semi-full", "partial", "minimal"], 30 | "description": "App will be launched in background if preload is filled in" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /files/schema/applicationManager.launchVirtualApp.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.launchVirtualApp", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "virtual application ID to be launched." 8 | }, 9 | "hostId": { 10 | "type": "string", 11 | "description": "Host app id for virtual application." 12 | }, 13 | "appInfo": { 14 | "type": "object", 15 | "description": "appInfo for virtual application", 16 | "default": {} 17 | }, 18 | "params": { 19 | "type": "object", 20 | "description": "params to be passed to host application as params", 21 | "default": {} 22 | }, 23 | "noSplash": { 24 | "type": "boolean" 25 | }, 26 | "spinner": { 27 | "type": "boolean" 28 | }, 29 | "preload": { 30 | "type": "string", 31 | "enum": ["full", "semi-full", "partial", "minimal"], 32 | "description": "App will be launched in background if preload is filled in" 33 | }, 34 | "launchHidden": { 35 | "type": "boolean" 36 | }, 37 | "keepAlive": { 38 | "type": "boolean" 39 | } 40 | }, 41 | "required": [ 42 | "id", 43 | "hostId", 44 | "params" 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /files/schema/applicationManager.listAllHandlersForMime.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.listAllHandlersForMime", 3 | "type": "object", 4 | "properties": { 5 | "mime": { 6 | "type": "string", 7 | "description": "The mime for getting handler application by verb." 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /files/schema/applicationManager.listAllHandlersForMultipleMime.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.listAllHandlersForMultipleMime", 3 | "type": "object", 4 | "properties": { 5 | "mimes": { 6 | "type": "array", 7 | "description": "The mimes type for getting handler application." 8 | } 9 | }, 10 | "required": [ 11 | "mimes" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.listAllHandlersForMultipleUrlPattern.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.listAllHandlersForMultipleUrlPattern", 3 | "type": "object", 4 | "properties": { 5 | "urls": { 6 | "type": "array", 7 | "description": "The urls for getting handler application." 8 | } 9 | }, 10 | "required": [ 11 | "urls" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.listAllHandlersForUrl.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.listAllHandlersForUrl", 3 | "type": "object", 4 | "properties": { 5 | "url": { 6 | "type": "string", 7 | "description": "The url for getting handler application by verb." 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /files/schema/applicationManager.listAllHandlersForUrlByVerb.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.listAllHandlersForUrlByVerb", 3 | "type": "object", 4 | "properties": { 5 | "url": { 6 | "type": "string", 7 | "description": "The url for getting handler application by verb." 8 | }, 9 | "mime": { 10 | "type": "string", 11 | "description": "The mime for getting handler application by verb." 12 | }, 13 | "verb": { 14 | "type": "string", 15 | "description": "The verb for getting handler application." 16 | } 17 | }, 18 | "required": [ 19 | "verb" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /files/schema/applicationManager.listAllHandlersForUrlPattern.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.listAllHandlersForUrlPattern", 3 | "type": "object", 4 | "properties": { 5 | "urlPattern": { 6 | "type": "string", 7 | "description": "The mimes type for getting handler application." 8 | } 9 | }, 10 | "required": [ 11 | "urlPattern" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.listApps.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.listApps", 3 | "type": "object", 4 | "properties": { 5 | "properties": { 6 | "type": "array", 7 | "description": "Get application information for service-user selected properties." 8 | }, 9 | "subscribe": { 10 | "type": "boolean", 11 | "description": "listApps support subscription to notify when Apps are updated, i.e., an app is installed or removed or edit" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /files/schema/applicationManager.listLaunchPoints.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.listLaunchPoints", 3 | "type": "object", 4 | "properties": { 5 | "subscribe": { 6 | "type": "boolean", 7 | "description": "listLaunchPoints support subscription to notify when launch points are updated, i.e., an app is installed or removed" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /files/schema/applicationManager.lockApp.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.lockApp", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "ID of application to be locked." 8 | }, 9 | "lock": { 10 | "type": "boolean", 11 | "description" : "When set the application is not allowed to launch" 12 | } 13 | }, 14 | "required": [ 15 | "id", 16 | "lock" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /files/schema/applicationManager.mimeTypeForExtension.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.mimeTypeForExtension", 3 | "type": "object", 4 | "properties": { 5 | "extension": { 6 | "type": "string", 7 | "description": "The extension of file for getting mime type." 8 | } 9 | }, 10 | "required": [ 11 | "extension" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.notifyAlertClosed.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.notifyAlertClosed", 3 | "type": "object", 4 | "properties": { 5 | "alertId": { 6 | "type": "string", 7 | "description": "The update-popup ID. This is randomly generated by SAM when reqeusting an update-popup." 8 | }, 9 | "action": { 10 | "type": "string", 11 | "enum": [ "launch", "update", "cancel" ], 12 | "description" : "The action that the user can choose." 13 | } 14 | }, 15 | "required": [ 16 | "alertId", 17 | "action" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /files/schema/applicationManager.open.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.launch", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "ID of application to be launched." 8 | }, 9 | "target": { 10 | "type": "string", 11 | "description": "A target URL. If id is not specified, this URL is opened in an appropriate application, if there is one." 12 | }, 13 | "mime": { 14 | "type": "string", 15 | "description": "Mime type for target." 16 | }, 17 | "params" : { 18 | "type": "object", 19 | "description": "Additional launch parameters for the application." 20 | }, 21 | "authToken" : { 22 | "type" : "object", 23 | "description": "Authorization token given to download manager when opening a remote file. deviceId is required with this." 24 | }, 25 | "deviceId" : { 26 | "type" : "object", 27 | "description": "Device ID given to download manager when opening a remote file. authToken is required with this." 28 | }, 29 | "overrideHandlerAppId": { 30 | "type": "string", 31 | "description": "If specified, this appid will be used to open a resource." 32 | }, 33 | "fileName": { 34 | "type": "string", 35 | "description": "File name of target." 36 | }, 37 | "subcsribe": { 38 | "type": "boolean", 39 | "description": "When true, the message is a subscription request." 40 | }, 41 | "noSplash": { 42 | "type": "boolean", 43 | "description": "When true, there will be no splash screen." 44 | }, 45 | "launchFirstApp" : { 46 | "type" : "boolean", 47 | "description": "When true, the app is set to first launched app after booting." 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /files/schema/applicationManager.registerApp.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.registerApp", 3 | "type": "object", 4 | "properties": { 5 | "subscribe": { 6 | "type": "boolean" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /files/schema/applicationManager.removeLaunchPoint.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.removeLaunchPoint", 3 | "type": "object", 4 | "properties": { 5 | "launchPointId": { 6 | "type": "string", 7 | "description": "ID of launch point to be removed" 8 | } 9 | }, 10 | "required": [ 11 | "launchPointId" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.removeVirtualApp.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.removeVirtualApp", 3 | "type": "object", 4 | "properties": { 5 | "id": { 6 | "type": "string", 7 | "description": "virtual application ID to be removed" 8 | } 9 | }, 10 | "required": [ 11 | "id" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.running.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.running", 3 | "type": "object", 4 | "properties": { 5 | "subscribe": { 6 | "type": "boolean" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /files/schema/applicationManager.searchApps.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.searchApps", 3 | "type": "object", 4 | "properties": { 5 | "keyword": { 6 | "type": "string", 7 | "description": "Keyword to search with" 8 | } 9 | }, 10 | "required": [ 11 | "keyword" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /files/schema/applicationManager.updateLaunchPoint.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "applicationManager.updateLaunchPoint", 3 | "type": "object", 4 | "properties": { 5 | "launchPointId": { 6 | "type": "string", 7 | "description": "ID of launch point to be updated" 8 | }, 9 | "title": { 10 | "type": "string", 11 | "description": "Title for the launch point to be updated" 12 | }, 13 | "icon": { 14 | "type": "string", 15 | "description": "Path to icon for the launch point to be updated" 16 | }, 17 | "bgImage": { 18 | "type": "string", 19 | "description": "This field is the location of a bitmap. The bitmap is displayed to the user when the user hovers over the launch point with the system pointer." 20 | }, 21 | "bgImages": { 22 | "type": "array", 23 | "items": { 24 | "type": "string" 25 | }, 26 | "description": "Locations of bitmaps that may be displayed to the user when the user hovers over the launch point with the system pointer." 27 | }, 28 | "bgColor": { 29 | "type": "string", 30 | "description": "This field is the color to be displayed to the user when the user hovers over the launch point with the system pointer. This is used in the absence of the backgroundImage." 31 | }, 32 | "imageForRecents": { 33 | "type": "string", 34 | "description": "This field is the location of a bitmap. The bitmap is displayed in the recent apps list." 35 | }, 36 | "iconColor": { 37 | "type": "string", 38 | "description": "indicates color of the icon of the launch point." 39 | }, 40 | "largeIcon": { 41 | "type": "string", 42 | "description": "path to largeIcon" 43 | }, 44 | "appDescription": { 45 | "type": "string", 46 | "description": "A short tagline for the application" 47 | }, 48 | "params": { 49 | "type": "object", 50 | "description": "Parameters to pass to the application" 51 | }, 52 | "userData": { 53 | "type": "string", 54 | "description": "Additional data that may be used by clients, such as an identifier for analytics purposes" 55 | }, 56 | "tileSize": { 57 | "type": "string", 58 | "enum": [ "normal", "large" ], 59 | "description": "Hint for sizing of UI tiles: normal or large, large may be used for a promotional item" 60 | }, 61 | "unmovable": { 62 | "type": "boolean", 63 | "description": "Hint that an item should never be moved from it's given position" 64 | } 65 | }, 66 | "required": [ 67 | "launchPointId" 68 | ] 69 | } 70 | -------------------------------------------------------------------------------- /files/schema/deletedSystemAppList.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "deletedSystemAppList", 3 | "type": "object", 4 | "properties": { 5 | "deletedList": { 6 | "type": "array", 7 | "items": { 8 | "type": "string" 9 | }, 10 | "description": "deleted preinstalled app IDs" 11 | } 12 | }, 13 | "required": [ 14 | "deletedList" 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /files/schema/foregroundAppInfo.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "foregroundAppInfo", 3 | "type": "object", 4 | "properties": { 5 | "appId": { 6 | "type": "string", 7 | "description": "Application ID of application in foreground." 8 | }, 9 | "processId": { 10 | "type": "string", 11 | "description": "Process ID of application in foreground." 12 | }, 13 | "windowType": { 14 | "type": "string", 15 | "description": "Describe type of window : maximized, maximized, pip, popup, overay" 16 | } 17 | }, 18 | "required": [ 19 | "appId", 20 | "processId" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /files/schema/sam-conf.schema: -------------------------------------------------------------------------------- 1 | { 2 | "id": "Settings", 3 | "type": "object", 4 | "properties": { 5 | "ApplicationPaths": { 6 | "type": "array", 7 | "items": { 8 | "type": "object", 9 | "properties": { 10 | "typeByDir": { 11 | "type": "string", 12 | "enum": [ 13 | "system_builtin", 14 | "system_updatable", 15 | "store", 16 | "dev", 17 | "alias", 18 | "tmp_alias" 19 | ], 20 | "description": "It explains apps are preinstalled, downloaedFromStore or installed in Devmode" 21 | }, 22 | "path": { 23 | "type": "string", 24 | "description": "Absolute path the directory" 25 | } 26 | }, 27 | "required": ["typeByDir", "path"] 28 | }, 29 | "description" : "Application directory paths in sam-conf.json file." 30 | }, 31 | "DevModePath": { 32 | "type": "string", 33 | "description": "If this file exists, it indicates it's working on development mode." 34 | }, 35 | "JailModePath": { 36 | "type": "string", 37 | "description": "If this file exists, it means Native apps should be launched through Jailer" 38 | }, 39 | "JailerPath": { 40 | "type": "string", 41 | "description": "Location of Jailer binary" 42 | }, 43 | "QmlRunnerPath": { 44 | "type": "string", 45 | "description": "Location of Qml Runner binary" 46 | }, 47 | "AppShellRunnerPath": { 48 | "type": "string", 49 | "description": "Location of AppShell Runner binary" 50 | }, 51 | "BrowserShellRunnerPath": { 52 | "type": "string", 53 | "description": "Location of BrowserShell Runner binary" 54 | }, 55 | "RespawnedPath": { 56 | "type": "string", 57 | "description": "If this file exists, it means sam already starts" 58 | }, 59 | "NoJailApps": { 60 | "type": "array", 61 | "items": { 62 | "type": "string" 63 | }, 64 | "description": "This is a white list for jailer. If an app is on this list, it' will be launched out of jail" 65 | }, 66 | "SecurityEnabled": { 67 | "type": "boolean", 68 | "description": "If true, SAM checks security policy, such as DRM... etc." 69 | }, 70 | "UsePartialKeywordMatchForAppSearch": { 71 | "type": "boolean", 72 | "description": "This field indicates that app searching is available." 73 | }, 74 | "KeepAliveApps" : { 75 | "type": "array", 76 | "items": { 77 | "type" : "string" 78 | }, 79 | "description": "Applications which are to be kept alive." 80 | }, 81 | "BootTimeApps" : { 82 | "type": "array", 83 | "items": { 84 | "type": "string" 85 | }, 86 | "description": "TV input apps for parental control bypassing" 87 | }, 88 | "ReservedResource": { 89 | "type": "object", 90 | "properties": { 91 | "mime": { 92 | "type": "array", 93 | "items": { 94 | "type": "string" 95 | } 96 | } 97 | }, 98 | "description": "3rd-party apps can not have any of the values listed here" 99 | }, 100 | "LaunchPointDBKind" : { 101 | "type": "object", 102 | "description": "DBKind of LaunchPoint" 103 | }, 104 | "LaunchPointDBPermissions" : { 105 | "type": "object", 106 | "description": "DBPermissions of LaunchPoint" 107 | } 108 | }, 109 | "required": [ 110 | "ApplicationPaths", 111 | "JailerPath", 112 | "LaunchPointDBKind", 113 | "LaunchPointDBPermissions" 114 | ] 115 | } 116 | -------------------------------------------------------------------------------- /files/sysbus/com.webos.sam.api.json: -------------------------------------------------------------------------------- 1 | { 2 | "application.operation": [ 3 | "com.webos.applicationManager/getAppBasePath", 4 | "com.webos.service.applicationManager/getAppBasePath", 5 | "com.webos.service.applicationmanager/getAppBasePath", 6 | "com.webos.applicationManager/registerNativeApp", 7 | "com.webos.service.applicationManager/registerNativeApp", 8 | "com.webos.service.applicationmanager/registerNativeApp", 9 | "com.webos.applicationManager/registerApp", 10 | "com.webos.service.applicationManager/registerApp", 11 | "com.webos.service.applicationmanager/registerApp", 12 | "com.webos.applicationManager/getAppStatus", 13 | "com.webos.service.applicationManager/getAppStatus", 14 | "com.webos.service.applicationmanager/getAppStatus", 15 | "com.webos.applicationManager/getAppInfo", 16 | "com.webos.service.applicationManager/getAppInfo", 17 | "com.webos.service.applicationmanager/getAppInfo", 18 | "com.webos.applicationManager/getAppLifeEvents", 19 | "com.webos.service.applicationManager/getAppLifeEvents", 20 | "com.webos.service.applicationmanager/getAppLifeEvents", 21 | "com.webos.applicationManager/getAppLifeStatus", 22 | "com.webos.service.applicationManager/getAppLifeStatus", 23 | "com.webos.service.applicationmanager/getAppLifeStatus", 24 | "com.webos.applicationManager/getForegroundAppInfo", 25 | "com.webos.service.applicationManager/getForegroundAppInfo", 26 | "com.webos.service.applicationmanager/getForegroundAppInfo", 27 | "com.webos.applicationManager/listApps", 28 | "com.webos.service.applicationManager/listApps", 29 | "com.webos.service.applicationmanager/listApps", 30 | "com.webos.applicationManager/listLaunchPoints", 31 | "com.webos.service.applicationManager/listLaunchPoints", 32 | "com.webos.service.applicationmanager/listLaunchPoints" 33 | ], 34 | "application.devmode": [ 35 | "com.webos.applicationManager/dev/closeByAppId", 36 | "com.webos.service.applicationManager/dev/closeByAppId", 37 | "com.webos.service.applicationmanager/dev/closeByAppId", 38 | "com.webos.applicationManager/dev/listApps", 39 | "com.webos.service.applicationManager/dev/listApps", 40 | "com.webos.service.applicationmanager/dev/listApps", 41 | "com.webos.applicationManager/dev/running", 42 | "com.webos.service.applicationManager/dev/running", 43 | "com.webos.service.applicationmanager/dev/running", 44 | "com.webos.applicationManager/dev/close", 45 | "com.webos.service.applicationManager/dev/close", 46 | "com.webos.service.applicationmanager/dev/close", 47 | "com.webos.applicationManager/dev/managerInfo", 48 | "com.webos.service.applicationmanager/dev/managerInfo", 49 | "com.webos.service.applicationManager/dev/managerInfo" 50 | ], 51 | "application.launcher": [ 52 | "com.webos.applicationManager/launch", 53 | "com.webos.service.applicationManager/launch", 54 | "com.webos.service.applicationmanager/launch", 55 | "com.webos.applicationManager/addLaunchPoint", 56 | "com.webos.service.applicationManager/addLaunchPoint", 57 | "com.webos.service.applicationmanager/addLaunchPoint", 58 | "com.webos.applicationManager/close", 59 | "com.webos.service.applicationManager/close", 60 | "com.webos.service.applicationmanager/close", 61 | "com.webos.applicationManager/closeByAppId", 62 | "com.webos.service.applicationManager/closeByAppId", 63 | "com.webos.service.applicationmanager/closeByAppId", 64 | "com.webos.applicationManager/lockApp", 65 | "com.webos.service.applicationManager/lockApp", 66 | "com.webos.service.applicationmanager/lockApp", 67 | "com.webos.applicationManager/pause", 68 | "com.webos.service.applicationManager/pause", 69 | "com.webos.service.applicationmanager/pause", 70 | "com.webos.applicationManager/removeLaunchPoint", 71 | "com.webos.service.applicationManager/removeLaunchPoint", 72 | "com.webos.service.applicationmanager/removeLaunchPoint", 73 | "com.webos.applicationManager/running", 74 | "com.webos.service.applicationManager/running", 75 | "com.webos.service.applicationmanager/running", 76 | "com.webos.applicationManager/updateLaunchPoint", 77 | "com.webos.service.applicationManager/updateLaunchPoint", 78 | "com.webos.service.applicationmanager/updateLaunchPoint" 79 | ] 80 | } 81 | -------------------------------------------------------------------------------- /files/sysbus/com.webos.sam.groups.json: -------------------------------------------------------------------------------- 1 | { 2 | "allowedNames" : ["com.webos.service.applicationmanager","com.webos.applicationManager","com.webos.service.applicationManager"], 3 | "application.operation": ["dev"], 4 | "application.launcher": ["oem"], 5 | "application.devmode": ["dev"] 6 | } 7 | -------------------------------------------------------------------------------- /files/sysbus/com.webos.sam.perm.json: -------------------------------------------------------------------------------- 1 | { 2 | "com.webos.applicationManager" : [ 3 | "applicationinstall.management", 4 | "applicationinstall.devmode", 5 | "boot.query", 6 | "systemconfig.query", 7 | "database.operation", 8 | "surfacemanager.query", 9 | "memorymanager.management", 10 | "notification.operation", 11 | "settings.query", 12 | "settings.management", 13 | "webapplication.management" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /files/sysbus/com.webos.sam.role.json.in: -------------------------------------------------------------------------------- 1 | { 2 | "exeName":"@WEBOS_INSTALL_SBINDIR@/sam", 3 | "type": "regular", 4 | "trustLevel" : "oem", 5 | "allowedNames": [ 6 | "com.webos.service.applicationmanager", 7 | "com.webos.applicationManager", 8 | "com.webos.service.applicationManager", 9 | "com.webos.service.systemmanager" 10 | ], 11 | "permissions": [ 12 | { 13 | "service":"com.webos.applicationManager", 14 | "outbound":[ 15 | "*", 16 | "com.webos.appInstallService", 17 | "com.webos.booster", 18 | "com.webos.bootManager", 19 | "com.webos.memorymanager", 20 | "com.webos.notification", 21 | "com.webos.service.attachedstoragemanager", 22 | "com.webos.service.bus", 23 | "com.webos.service.config", 24 | "com.webos.service.db", 25 | "com.webos.service.downloadmanager", 26 | "com.webos.service.power2", 27 | "com.webos.service.sdx", 28 | "com.webos.service.sm", 29 | "com.webos.service.tvpower", 30 | "com.palm.webappmanager", 31 | "com.webos.settingsservice", 32 | "com.webos.surfacemanager" 33 | ] 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /files/sysbus/com.webos.sam.service.in: -------------------------------------------------------------------------------- 1 | [D-BUS Service] 2 | Name=com.webos.service.applicationmanager;com.webos.applicationManager;com.webos.service.applicationManager;com.webos.service.systemmanager 3 | Exec=@WEBOS_INSTALL_SBINDIR@/sam 4 | Type=static 5 | -------------------------------------------------------------------------------- /oss-pkg-info.yaml: -------------------------------------------------------------------------------- 1 | Open Source Software Package: 2 | - name: webOSOSE 3 | source: https://github.com/webosose 4 | license: Apache-2.0 5 | -------------------------------------------------------------------------------- /src/Environment.h.in: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2024 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef ENVIRONMENT_H_ 18 | #define ENVIRONMENT_H_ 19 | 20 | static const char* const PATH_RO_SAM_CONF = "@WEBOS_INSTALL_WEBOS_SYSCONFDIR@/sam-conf.json"; 21 | static const char* const PATH_RW_SAM_CONF = "@WEBOS_INSTALL_PREFERENCESDIR@/sam-conf.json"; 22 | static const char* const PATH_SAM_SCHEMAS = "@WEBOS_INSTALL_WEBOS_SYSCONFDIR@/schemas/sam/"; 23 | static const char* const PATH_BLOCKED_LIST = "@WEBOS_INSTALL_SYSMGR_LOCALSTATEDIR@/preferences/blockedList.json"; 24 | static const char* const PATH_LOCALE_INFO = "@WEBOS_INSTALL_SYSMGR_LOCALSTATEDIR@/preferences/localeInfo"; 25 | static const char* const PATH_RUNTIME_INFO = "/tmp/sam_runtime"; 26 | static const char* const PATH_NATIVE_LOG = "/var/log"; 27 | 28 | #endif // ENVIRONMENT_H_ 29 | -------------------------------------------------------------------------------- /src/Main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "MainDaemon.h" 25 | #include "util/Logger.h" 26 | #include "util/File.h" 27 | 28 | static const char* CLASS_NAME = "Main"; 29 | 30 | void signal_handler(int signal, siginfo_t *siginfo, void *context) 31 | { 32 | string buf; 33 | stringstream stream; 34 | string sender_pid, sender_cmdline; 35 | int si_code; 36 | 37 | // abstract sender_pid from struct 38 | stream << siginfo->si_pid; 39 | sender_pid = stream.str(); 40 | sender_cmdline = "/proc/" + sender_pid + "/cmdline"; 41 | si_code = siginfo->si_code; 42 | 43 | Logger::warning(CLASS_NAME, __FUNCTION__, Logger::format("signal(%d) si_code(%d) sender_pid(%s) sender_cmdline(%s)", signal, si_code, sender_pid.c_str(), sender_cmdline.c_str())); 44 | buf = File::readFile(sender_cmdline.c_str()); 45 | if (buf.empty()) { 46 | Logger::warning(CLASS_NAME, __FUNCTION__, Logger::format("signal(%d) si_code(%d) si_pid(%d), si_uid(%d)", signal, si_code, siginfo->si_pid, siginfo->si_uid)); 47 | goto Done; 48 | } 49 | 50 | Logger::warning(CLASS_NAME, __FUNCTION__, Logger::format("signal(%d) si_code(%d) sender(%s) si_pid(%d), si_uid(%d)", signal, si_code, buf.c_str(), siginfo->si_pid, siginfo->si_uid)); 51 | 52 | Done: 53 | if (signal == SIGHUP || signal == SIGINT || signal == SIGPIPE) { 54 | Logger::warning(CLASS_NAME, __FUNCTION__, "Ignore received signal"); 55 | return; 56 | } else { 57 | Logger::warning(CLASS_NAME, __FUNCTION__, "Try to terminate SAM process"); 58 | } 59 | 60 | MainDaemon::getInstance().stop(); 61 | } 62 | 63 | int main(int argc, char **argv) 64 | { 65 | Logger::info(CLASS_NAME, __FUNCTION__, "Start SAM process"); 66 | 67 | // tracking sender if we get some signal 68 | struct sigaction act; 69 | sigemptyset(&act.sa_mask); 70 | act.sa_sigaction = signal_handler; 71 | act.sa_flags = SA_SIGINFO; 72 | 73 | // we will ignore this signal 74 | sigaction(SIGHUP, &act, NULL); 75 | sigaction(SIGINT, &act, NULL); 76 | sigaction(SIGPIPE, &act, NULL); 77 | 78 | // we don't change the default action 79 | sigaction(SIGTERM, &act, NULL); 80 | sigaction(SIGQUIT, &act, NULL); 81 | sigaction(SIGABRT, &act, NULL); 82 | sigaction(SIGFPE, &act, NULL); 83 | 84 | try { 85 | MainDaemon::getInstance().initialize(); 86 | MainDaemon::getInstance().start(); 87 | MainDaemon::getInstance().finalize(); 88 | } catch(...) { 89 | Logger::info(CLASS_NAME, __FUNCTION__, "Failed to start SAM"); 90 | } 91 | return EXIT_SUCCESS; 92 | } 93 | -------------------------------------------------------------------------------- /src/MainDaemon.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "MainDaemon.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "base/AppDescriptionList.h" 29 | #include "bus/client/AppInstallService.h" 30 | #include "bus/client/Bootd.h" 31 | #include "bus/client/Configd.h" 32 | #include "bus/client/DB8.h" 33 | #include "bus/client/LSM.h" 34 | #include "bus/client/MemoryManager.h" 35 | #include "bus/client/NativeContainer.h" 36 | #include "bus/client/Notification.h" 37 | #include "bus/client/SettingService.h" 38 | #include "bus/client/WAM.h" 39 | #include "bus/service/ApplicationManager.h" 40 | #include "conf/RuntimeInfo.h" 41 | #include "conf/SAMConf.h" 42 | #include "util/File.h" 43 | #include "util/JValueUtil.h" 44 | 45 | 46 | MainDaemon::MainDaemon() 47 | : m_isCBDGenerated(false), 48 | m_isConfigsReceived(false) 49 | { 50 | setClassName("MainDaemon"); 51 | m_mainLoop = g_main_loop_new(NULL, FALSE); 52 | } 53 | 54 | MainDaemon::~MainDaemon() 55 | { 56 | if (m_mainLoop) { 57 | g_main_loop_unref(m_mainLoop); 58 | } 59 | } 60 | 61 | void MainDaemon::initialize() 62 | { 63 | RuntimeInfo::getInstance().initialize(); 64 | SAMConf::getInstance().initialize(); 65 | AppDescriptionList::getInstance().scanFull(); 66 | 67 | if (!ApplicationManager::getInstance().attach(m_mainLoop)) 68 | return; 69 | 70 | AppInstallService::getInstance().initialize(); 71 | Bootd::getInstance().initialize(); 72 | Configd::getInstance().initialize(); 73 | DB8::getInstance().initialize(); 74 | LSM::getInstance().initialize(); 75 | MemoryManager::getInstance().initialize(); 76 | NativeContainer::getInstance().initialize(); 77 | Notification::getInstance().initialize(); 78 | SettingService::getInstance().initialize(); 79 | WAM::getInstance().initialize(); 80 | 81 | Bootd::getInstance().EventGetBootStatus.connect(boost::bind(&MainDaemon::onGetBootStatus, this, boost::placeholders::_1)); 82 | Configd::getInstance().EventGetConfigs.connect(boost::bind(&MainDaemon::onGetConfigs, this, boost::placeholders::_1)); 83 | } 84 | 85 | void MainDaemon::finalize() 86 | { 87 | AppInstallService::getInstance().finalize(); 88 | Bootd::getInstance().finalize(); 89 | Configd::getInstance().finalize(); 90 | DB8::getInstance().finalize(); 91 | LSM::getInstance().finalize(); 92 | MemoryManager::getInstance().finalize(); 93 | Notification::getInstance().finalize(); 94 | SettingService::getInstance().finalize(); 95 | WAM::getInstance().finalize(); 96 | 97 | ApplicationManager::getInstance().detach(); 98 | } 99 | 100 | void MainDaemon::start() 101 | { 102 | Logger::info(getClassName(), __FUNCTION__, "Start event handler thread"); 103 | g_main_loop_run(m_mainLoop); 104 | } 105 | 106 | void MainDaemon::stop() 107 | { 108 | if (m_mainLoop) 109 | g_main_loop_quit(m_mainLoop); 110 | } 111 | 112 | void MainDaemon::onGetBootStatus(const JValue& subscriptionPayload) 113 | { 114 | bool coreBootDone; 115 | if (!JValueUtil::getValue(subscriptionPayload, "signals", "core-boot-done", coreBootDone) && !coreBootDone) { 116 | return; 117 | } 118 | m_isCBDGenerated = true; 119 | checkPreconditions(); 120 | } 121 | 122 | void MainDaemon::onGetConfigs(const JValue& responsePayload) 123 | { 124 | JValue sysAssetFallbackPrecedence; 125 | JValue keepAliveApps; 126 | JValue lifeCycle; 127 | 128 | if (JValueUtil::getValue(responsePayload, "configs", "system.sysAssetFallbackPrecedence", sysAssetFallbackPrecedence) && sysAssetFallbackPrecedence.isArray()) { 129 | SAMConf::getInstance().setSysAssetFallbackPrecedence(sysAssetFallbackPrecedence); 130 | } 131 | if (JValueUtil::getValue(responsePayload, "configs", "com.webos.applicationManager.keepAliveApps", keepAliveApps) && keepAliveApps.isArray()) { 132 | SAMConf::getInstance().setKeepAliveApps(keepAliveApps); 133 | } 134 | m_isConfigsReceived = true; 135 | checkPreconditions(); 136 | } 137 | 138 | void MainDaemon::checkPreconditions() 139 | { 140 | static bool isFired = false; 141 | if (isFired) 142 | return; 143 | 144 | if (!m_isConfigsReceived) { 145 | Logger::info(getClassName(), __FUNCTION__, "Wait for receiving 'getConfigs' response"); 146 | return; 147 | } 148 | if (!m_isCBDGenerated) { 149 | Logger::info(getClassName(), __FUNCTION__, "Wait for receiving 'getBootStatus' response"); 150 | return; 151 | } 152 | Logger::info(getClassName(), __FUNCTION__, "All initial components are ready"); 153 | isFired = true; 154 | 155 | ApplicationManager::getInstance().enablePosting(); 156 | } 157 | 158 | -------------------------------------------------------------------------------- /src/MainDaemon.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef MAIN_DAEMON_H 18 | #define MAIN_DAEMON_H 19 | 20 | #include 21 | 22 | #include "base/LunaTask.h" 23 | #include "interface/ISingleton.h" 24 | #include "interface/IClassName.h" 25 | 26 | class MainDaemon : public ISingleton, 27 | public IClassName { 28 | friend class ISingleton; 29 | public: 30 | virtual ~MainDaemon(); 31 | 32 | void initialize(); 33 | void finalize(); 34 | 35 | void start(); 36 | void stop(); 37 | 38 | private: 39 | MainDaemon(); 40 | 41 | void onGetBootStatus(const JValue& subscriptionPayload); 42 | void onGetConfigs(const JValue& subscriptionPayload); 43 | 44 | void checkPreconditions(); 45 | 46 | bool m_isCBDGenerated; 47 | bool m_isConfigsReceived; 48 | 49 | GMainLoop *m_mainLoop; 50 | 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/base/AppDescriptionList.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BASE_APPDESCRIPTIONLIST_H_ 18 | #define BASE_APPDESCRIPTIONLIST_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AppDescription.h" 25 | #include "interface/IClassName.h" 26 | #include "interface/ISingleton.h" 27 | 28 | using namespace std; 29 | 30 | class AppDescriptionList : public ISingleton, 31 | public IClassName { 32 | friend class ISingleton; 33 | public: 34 | static bool compare(AppDescriptionPtr me, AppDescriptionPtr another); 35 | 36 | virtual ~AppDescriptionList(); 37 | 38 | void changeLocale(); 39 | 40 | void scanApp(const string& appId); 41 | void scanFull(); 42 | void scanDir(const string& path, const AppLocation& appLocation); 43 | 44 | AppDescriptionPtr create(const string& appId); 45 | AppDescriptionPtr getByAppId(const string& appId); 46 | 47 | bool add(AppDescriptionPtr appDesc); 48 | void removeByAppId(const string& appId); 49 | void removeByObject(AppDescriptionPtr appDesc); 50 | 51 | bool isExist(const string& appId); 52 | void toJson(JValue& json, JValue& properties, bool devmode = false); 53 | 54 | private: 55 | AppDescriptionList(); 56 | 57 | void onRemove(AppDescriptionPtr appDesc); 58 | 59 | map m_map; 60 | }; 61 | 62 | #endif /* BASE_APPDESCRIPTIONLIST_H_ */ 63 | -------------------------------------------------------------------------------- /src/base/LaunchPoint.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "base/LaunchPoint.h" 18 | #include "bus/client/DB8.h" 19 | #include "util/JValueUtil.h" 20 | 21 | string LaunchPoint::toString(const LaunchPointType type) 22 | { 23 | switch (type) { 24 | case LaunchPointType::LaunchPoint_DEFAULT: 25 | return string("default"); 26 | 27 | case LaunchPointType::LaunchPoint_BOOKMARK: 28 | return string("bookmark"); 29 | 30 | default: 31 | break; 32 | } 33 | 34 | return string(""); 35 | } 36 | 37 | LaunchPointType LaunchPoint::toEnum(const string& type) 38 | { 39 | if (type == "default") 40 | return LaunchPointType::LaunchPoint_DEFAULT; 41 | else if (type == "bookmark") 42 | return LaunchPointType::LaunchPoint_BOOKMARK; 43 | return LaunchPointType::LaunchPoint_UNKNOWN; 44 | } 45 | 46 | LaunchPoint::LaunchPoint(AppDescriptionPtr appDesc, const string& launchPointId) 47 | : m_type(LaunchPointType::LaunchPoint_UNKNOWN), 48 | m_appDesc(std::move(appDesc)), 49 | m_launchPointId(launchPointId), 50 | m_isDirty(false) 51 | { 52 | m_database = pbnjson::Object(); 53 | } 54 | 55 | LaunchPoint::~LaunchPoint() 56 | { 57 | } 58 | 59 | void LaunchPoint::syncDatabase() 60 | { 61 | if (m_isDirty == false) { 62 | return; 63 | } 64 | 65 | JValue json = m_database.duplicate(); 66 | 67 | json.put("id", m_appDesc->getAppId()); 68 | json.put("type", toString(getType())); 69 | json.put("launchPointId", m_launchPointId); 70 | 71 | bool isOld = (json.hasKey("_id") && json.hasKey("_rev") && json.hasKey("_kind")); 72 | 73 | if (isOld) { 74 | if (DB8::getInstance().updateLaunchPoint(json)) { 75 | m_isDirty = false; 76 | } 77 | } else { 78 | if (DB8::getInstance().insertLaunchPoint(json)) { 79 | m_isDirty = false; 80 | } 81 | } 82 | } 83 | 84 | void LaunchPoint::setDatabase(const JValue& database) 85 | { 86 | // This method should be called by DB8 instance 87 | m_database = database.duplicate(); 88 | } 89 | 90 | void LaunchPoint::updateDatabase(const JValue& json) 91 | { 92 | for (JValue::KeyValue obj : json.children()) { 93 | string key = obj.first.asString(); 94 | 95 | if (!m_database.hasKey(key)) { 96 | m_database.put(key, obj.second); 97 | m_isDirty = true; 98 | continue; 99 | } 100 | 101 | if (m_database[key] != obj.second) { 102 | m_database.put(key, obj.second); 103 | m_isDirty = true; 104 | } 105 | } 106 | } 107 | 108 | void LaunchPoint::toJson(JValue& json) const 109 | { 110 | m_appDesc->toJson(json); 111 | for (JValue::KeyValue obj : m_database.children()) { 112 | string key = obj.first.asString(); 113 | 114 | if (key == "_id" || key == "_rev" || key == "_kind") 115 | continue; 116 | 117 | if (!json.hasKey(key)) { 118 | json.put(key, obj.second); 119 | continue; 120 | } 121 | 122 | if (json[key] != obj.second) { 123 | json.put(key, obj.second); 124 | } 125 | } 126 | 127 | json.put("launchPointId", getLaunchPointId()); 128 | json.put("lptype", toString(m_type)); 129 | 130 | // Need to convert fullpath 131 | json.put("favicon", getFavicon()); 132 | json.put("icon", getIcon()); 133 | json.put("bgImage", getBgImage()); 134 | json.put("imageForRecents", getImageForRecents()); 135 | json.put("largeIcon", getLargeIcon()); 136 | } 137 | -------------------------------------------------------------------------------- /src/base/LaunchPoint.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef LAUNCH_POINT_H 18 | #define LAUNCH_POINT_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "base/AppDescription.h" 28 | #include "util/JValueUtil.h" 29 | 30 | using namespace std; 31 | using namespace pbnjson; 32 | 33 | class LaunchPoint; 34 | class LaunchPointList; 35 | 36 | typedef shared_ptr LaunchPointPtr; 37 | 38 | enum class LaunchPointType : int8_t { 39 | LaunchPoint_UNKNOWN = 0, 40 | LaunchPoint_DEFAULT, 41 | LaunchPoint_BOOKMARK 42 | }; 43 | 44 | class LaunchPoint { 45 | friend class LaunchPointList; 46 | public: 47 | static string toString(const LaunchPointType type); 48 | static LaunchPointType toEnum(const string& type); 49 | 50 | static bool compareTitle(LaunchPointPtr a, LaunchPointPtr b) 51 | { 52 | return a->getTitle() < b->getTitle(); 53 | } 54 | 55 | LaunchPoint(AppDescriptionPtr appDesc, const string& launchPointId); 56 | virtual ~LaunchPoint(); 57 | 58 | LaunchPointType getType() const 59 | { 60 | return m_type; 61 | } 62 | void setType(const LaunchPointType type) 63 | { 64 | m_type = type; 65 | } 66 | 67 | AppDescriptionPtr getAppDesc() const 68 | { 69 | return m_appDesc; 70 | } 71 | void setAppDesc(AppDescriptionPtr appDesc) 72 | { 73 | m_appDesc = std::move(appDesc); 74 | } 75 | 76 | const string getAppId() const 77 | { 78 | return m_appDesc->getAppId(); 79 | } 80 | 81 | const string& getLaunchPointId() const 82 | { 83 | return m_launchPointId; 84 | } 85 | 86 | void syncDatabase(); 87 | void setDatabase(const JValue& database); 88 | void updateDatabase(const JValue& json); 89 | 90 | const string getBgColor() const 91 | { 92 | string bgColor = ""; 93 | if (JValueUtil::getValue(m_database, "bgColor", bgColor)) { 94 | return bgColor; 95 | } 96 | return m_appDesc->getBgColor(); 97 | } 98 | 99 | const string getBgImage() const 100 | { 101 | string bgImage = ""; 102 | if (!JValueUtil::getValue(m_database, "bgImage", bgImage)) 103 | bgImage = m_appDesc->getBgImage(); 104 | m_appDesc->applyFolderPath(bgImage); 105 | return bgImage; 106 | } 107 | 108 | const JValue getBgImages() const 109 | { 110 | return m_database["bgImages"]; 111 | } 112 | 113 | const string getFavicon() const 114 | { 115 | string favicon = ""; 116 | if (JValueUtil::getValue(m_database, "favicon", favicon)) 117 | m_appDesc->applyFolderPath(favicon); 118 | return favicon; 119 | } 120 | 121 | const string getIcon() const 122 | { 123 | string icon = ""; 124 | if (!JValueUtil::getValue(m_database, "icon", icon)) 125 | icon = m_appDesc->getIcon(); 126 | m_appDesc->applyFolderPath(icon); 127 | return icon; 128 | } 129 | 130 | const string getImageForRecents() const 131 | { 132 | string imageForRecents = ""; 133 | if (JValueUtil::getValue(m_database, "imageForRecents", imageForRecents)) 134 | m_appDesc->applyFolderPath(imageForRecents); 135 | return imageForRecents; 136 | } 137 | 138 | const string getLargeIcon() const 139 | { 140 | string largeIcon = ""; 141 | if (!JValueUtil::getValue(m_database, "largeIcon", largeIcon)) 142 | largeIcon = m_appDesc->getLargeIcon(); 143 | m_appDesc->applyFolderPath(largeIcon); 144 | return largeIcon; 145 | } 146 | 147 | JValue getParams() const 148 | { 149 | JValue params; 150 | if (JValueUtil::getValue(m_database, "params", params)) { 151 | return params.duplicate(); 152 | } else { 153 | return pbnjson::Object(); 154 | } 155 | } 156 | 157 | const string getTitle() const 158 | { 159 | string title = ""; 160 | if (JValueUtil::getValue(m_database, "title", title)) { 161 | return title; 162 | } 163 | return m_appDesc->getTitle(); 164 | } 165 | 166 | bool isRemovable() const 167 | { 168 | if (m_type == LaunchPointType::LaunchPoint_BOOKMARK) 169 | return true; 170 | return m_appDesc->isRemovable(); 171 | } 172 | 173 | bool isSystemApp() const 174 | { 175 | if (m_type == LaunchPointType::LaunchPoint_BOOKMARK) 176 | return false; 177 | return m_appDesc->isSystemApp(); 178 | } 179 | 180 | bool isUnmovable() const 181 | { 182 | bool unmovable = false; 183 | if (JValueUtil::getValue(m_database, "unmovable", unmovable)) { 184 | return unmovable; 185 | } 186 | return m_appDesc->isUnmovable(); 187 | } 188 | 189 | bool isVisible() const 190 | { 191 | if (m_type == LaunchPointType::LaunchPoint_BOOKMARK) 192 | return true; 193 | return m_appDesc->isVisible(); 194 | } 195 | 196 | void toJson(JValue& json) const; 197 | 198 | private: 199 | LaunchPoint(const LaunchPoint&); 200 | LaunchPoint& operator=(const LaunchPoint&) const; 201 | 202 | LaunchPointType m_type; 203 | AppDescriptionPtr m_appDesc; 204 | string m_launchPointId; 205 | 206 | bool m_isDirty; 207 | JValue m_database; 208 | 209 | }; 210 | 211 | #endif /* LAUNCH_POINT_H */ 212 | -------------------------------------------------------------------------------- /src/base/LaunchPointList.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BASE_LAUNCHPOINTLIST_H_ 18 | #define BASE_LAUNCHPOINTLIST_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "base/LunaTask.h" 24 | #include "interface/ISingleton.h" 25 | #include "interface/IClassName.h" 26 | #include "LaunchPoint.h" 27 | 28 | using namespace std; 29 | 30 | class LaunchPointList : public ISingleton, 31 | public IClassName { 32 | friend class ISingleton; 33 | public: 34 | virtual ~LaunchPointList(); 35 | 36 | void clear(); 37 | void sort(); 38 | 39 | LaunchPointPtr createBootmarkByAPI(AppDescriptionPtr appDesc, const JValue& database); 40 | LaunchPointPtr createBootmarkByDB(AppDescriptionPtr appDesc, const JValue& database); 41 | LaunchPointPtr createDefault(AppDescriptionPtr appDesc); 42 | 43 | LaunchPointPtr getByLunaTask(LunaTaskPtr lunaTask); 44 | LaunchPointPtr getByAppId(const string& appId); 45 | LaunchPointPtr getByLaunchPointId(const string& launchPointId); 46 | 47 | bool add(LaunchPointPtr launchPoint); 48 | bool update(AppDescriptionPtr prevAppDesc, AppDescriptionPtr currAppDesc); 49 | bool remove(LaunchPointPtr launchPoint); 50 | void removeByAppDesc(AppDescriptionPtr appDesc); 51 | void removeByAppId(const string& appId); 52 | void removeByLaunchPointId(const string& launchPointId); 53 | 54 | bool isExist(const string& launchPointId); 55 | void toJson(JValue& json); 56 | 57 | private: 58 | string generateLaunchPointId(LaunchPointType type, const string& appId); 59 | 60 | LaunchPointList(); 61 | 62 | void onAdd(LaunchPointPtr launchPoint); 63 | void onUpdate(LaunchPointPtr launchPoint); 64 | void onRemove(LaunchPointPtr launchPoint); 65 | 66 | list m_list; 67 | }; 68 | 69 | #endif /* BASE_LAUNCHPOINTLIST_H_ */ 70 | -------------------------------------------------------------------------------- /src/base/LunaTask.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "LunaTask.h" 18 | 19 | #include "AppDescriptionList.h" 20 | #include "RunningAppList.h" 21 | #include "util/JValueUtil.h" 22 | 23 | #define LOG_NAME "LunaTask" 24 | 25 | int LunaTask::getDisplayId() 26 | { 27 | int displayId = -1; 28 | if (!JValueUtil::getValue(m_requestPayload, "displayId", displayId)) 29 | JValueUtil::getValue(m_requestPayload, "params", "displayAffinity", displayId); 30 | return displayId; 31 | } 32 | 33 | void LunaTask::setDisplayId(const int displayId) 34 | { 35 | int oldDisplayId = getDisplayId(); 36 | if (oldDisplayId != -1 && oldDisplayId != displayId) { 37 | Logger::warning(LOG_NAME, __FUNCTION__, Logger::format("DisplayId is not empty: Old(%d) New(%d)", oldDisplayId, displayId)); 38 | } 39 | m_requestPayload.put("displayId", displayId); 40 | if (!m_requestPayload.hasKey("params")) { 41 | m_requestPayload.put("params", pbnjson::Object()); 42 | } 43 | m_requestPayload["params"].put("displayAffinity", displayId); 44 | } 45 | -------------------------------------------------------------------------------- /src/base/LunaTask.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BASE_LUNATASK_H_ 18 | #define BASE_LUNATASK_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | #include "util/Logger.h" 30 | #include "util/JValueUtil.h" 31 | #include "util/Time.h" 32 | 33 | using namespace std; 34 | using namespace pbnjson; 35 | 36 | class LunaTask; 37 | class LunaTaskList; 38 | 39 | typedef shared_ptr LunaTaskPtr; 40 | typedef boost::function LunaTaskCallback; 41 | 42 | class LunaTask { 43 | friend class LunaTaskList; 44 | public: 45 | LunaTask(LS::Message& request, JValue& requestPayload, LSMessage* message) 46 | : m_instanceId(""), 47 | m_launchPointId(""), 48 | m_appId(""), 49 | m_request(request), 50 | m_token(0), 51 | m_requestPayload(requestPayload), 52 | m_responsePayload(pbnjson::Object()), 53 | m_errorCode(ErrCode_NOERROR), 54 | m_errorText(""), 55 | m_reason("") 56 | { 57 | JValueUtil::getValue(m_requestPayload, "instanceId", m_instanceId); 58 | JValueUtil::getValue(m_requestPayload, "launchPointId", m_launchPointId); 59 | JValueUtil::getValue(m_requestPayload, "id", m_appId); 60 | } 61 | 62 | virtual ~LunaTask() 63 | { 64 | 65 | } 66 | 67 | const string& getInstanceId() const 68 | { 69 | return m_instanceId; 70 | } 71 | void setInstanceId(const string& instanceId) 72 | { 73 | m_instanceId = instanceId; 74 | } 75 | 76 | const string& getLaunchPointId() const 77 | { 78 | return m_launchPointId; 79 | } 80 | void setLaunchPointId(const string& launchPointId) 81 | { 82 | m_launchPointId = launchPointId; 83 | } 84 | 85 | const string& getAppId() const 86 | { 87 | return m_appId; 88 | } 89 | void setAppId(const string& appId) 90 | { 91 | m_appId = appId; 92 | } 93 | 94 | const string& getId() const 95 | { 96 | if (!m_instanceId.empty()) 97 | return m_instanceId; 98 | if (!m_launchPointId.empty()) 99 | return m_launchPointId; 100 | return m_appId; 101 | } 102 | 103 | LS::Message& getRequest() 104 | { 105 | return m_request; 106 | } 107 | 108 | LSMessage* getMessage() 109 | { 110 | return m_request.get(); 111 | } 112 | 113 | LSMessageToken getToken() const 114 | { 115 | return m_token; 116 | } 117 | void setToken(LSMessageToken token) 118 | { 119 | m_token = token; 120 | } 121 | 122 | const JValue& getRequestPayload() const 123 | { 124 | return m_requestPayload; 125 | } 126 | 127 | JValue& getResponsePayload() 128 | { 129 | return m_responsePayload; 130 | } 131 | 132 | JValue getParams() 133 | { 134 | if (m_requestPayload.hasKey("params")) 135 | return m_requestPayload["params"].duplicate(); 136 | else 137 | return pbnjson::Object(); 138 | } 139 | void setParams(JValue params) 140 | { 141 | m_requestPayload.put("params", params.duplicate()); 142 | } 143 | 144 | void setErrCodeAndText(int errorCode, string errorText) 145 | { 146 | m_errorCode = errorCode; 147 | m_errorText = errorText; 148 | m_responsePayload.put("returnValue", false); 149 | Logger::warning("LunaTask", __FUNCTION__, Logger::format("errorCode(%d) errorText(%s)", errorCode, errorText.c_str())); 150 | } 151 | 152 | int getDisplayId(); 153 | void setDisplayId(const int displayId); 154 | 155 | const string getCaller() const 156 | { 157 | if (m_request.getApplicationID() != nullptr) { 158 | return m_request.getApplicationID(); 159 | } else if (m_request.getSenderServiceName() != nullptr){ 160 | return m_request.getSenderServiceName(); 161 | } else { 162 | return "unknown"; 163 | } 164 | } 165 | 166 | bool isLaunchedHidden() 167 | { 168 | bool launchedHidden = false; 169 | JValueUtil::getValue(m_requestPayload, "params", "launchedHidden", launchedHidden); 170 | return launchedHidden; 171 | } 172 | 173 | const string& getReason() 174 | { 175 | if (!m_reason.empty()) 176 | return m_reason; 177 | 178 | JValueUtil::getValue(m_requestPayload, "reason", m_reason); 179 | if (m_reason.empty()) { 180 | m_reason = getCaller(); 181 | } 182 | return m_reason; 183 | } 184 | void setReason(const string& reason) 185 | { 186 | m_reason = reason; 187 | } 188 | 189 | void setSuccessCallback(LunaTaskCallback callback) 190 | { 191 | m_successCallback = std::move(callback); 192 | } 193 | bool hasSuccessCallback() 194 | { 195 | return !m_successCallback.empty(); 196 | } 197 | void success(LunaTaskPtr lunaTask) 198 | { 199 | if (!m_successCallback.empty()) { 200 | m_successCallback(std::move(lunaTask)); 201 | } 202 | } 203 | 204 | void setErrorCallback(LunaTaskCallback callback) 205 | { 206 | m_errorCallback = std::move(callback); 207 | } 208 | bool hasErrorCallback() 209 | { 210 | return !m_successCallback.empty(); 211 | } 212 | void error(LunaTaskPtr lunaTask) 213 | { 214 | if (!m_errorCallback.empty()) { 215 | m_errorCallback(std::move(lunaTask)); 216 | } 217 | } 218 | 219 | const string& getNextStep() const 220 | { 221 | return m_nextStep; 222 | } 223 | void setNextStep(const string& next) 224 | { 225 | m_nextStep = next; 226 | } 227 | 228 | bool isDevmodeRequest() 229 | { 230 | return (strcmp(m_request.getCategory(), "/dev") == 0); 231 | } 232 | 233 | void toAPIJson(JValue& json) 234 | { 235 | if (json.isNull()) 236 | json = pbnjson::Object(); 237 | 238 | json.put("caller", getCaller()); 239 | json.put("kind", this->getRequest().getKind()); 240 | } 241 | 242 | void fillIds(JValue& json) 243 | { 244 | json.put("instanceId", getInstanceId()); 245 | json.put("launchPointId", getLaunchPointId()); 246 | json.put("appId", getAppId()); 247 | if (getDisplayId() != -1) 248 | json.put("displayId", getDisplayId()); 249 | } 250 | 251 | private: 252 | LunaTask& operator=(const LunaTask& lunaTask) = delete; 253 | LunaTask(const LunaTask& lunaTask) = delete; 254 | 255 | void reply() 256 | { 257 | bool returnValue = true; 258 | if (!m_errorText.empty() && !m_responsePayload.hasKey("errorText")) { 259 | m_responsePayload.put("errorText", m_errorText); 260 | returnValue = false; 261 | } 262 | if (m_errorCode != 0 && !m_responsePayload.hasKey("errorCode")) { 263 | m_responsePayload.put("errorCode", m_errorCode); 264 | returnValue = false; 265 | } 266 | m_responsePayload.put("returnValue", returnValue); 267 | m_request.respond(m_responsePayload.stringify().c_str()); 268 | } 269 | 270 | string m_instanceId; 271 | string m_launchPointId; 272 | string m_appId; 273 | 274 | LS::Message m_request; 275 | LSMessageToken m_token; 276 | 277 | JValue m_requestPayload; 278 | JValue m_responsePayload; 279 | 280 | int m_errorCode; 281 | string m_errorText; 282 | 283 | string m_reason; 284 | 285 | LunaTaskCallback m_successCallback; 286 | LunaTaskCallback m_errorCallback; 287 | 288 | string m_nextStep; 289 | }; 290 | 291 | #endif // BASE_LUNATASK_H_ 292 | -------------------------------------------------------------------------------- /src/base/LunaTaskList.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "base/LunaTaskList.h" 18 | 19 | #include 20 | 21 | LunaTaskList::LunaTaskList() 22 | { 23 | } 24 | 25 | LunaTaskList::~LunaTaskList() 26 | { 27 | m_list.clear(); 28 | } 29 | 30 | LunaTaskPtr LunaTaskList::getByKindAndId(const char* kind, const string& appId) 31 | { 32 | for (auto it = m_list.begin(); it != m_list.end(); ++it) { 33 | if (strcmp((*it)->getRequest().getKind(), kind) == 0 && (*it)->getAppId() == appId) 34 | return *it; 35 | } 36 | return nullptr; 37 | } 38 | 39 | LunaTaskPtr LunaTaskList::getByInstanceId(const string& instanceId) 40 | { 41 | for (auto it = m_list.begin(); it != m_list.end(); ++it) { 42 | if ((*it)->getInstanceId() == instanceId) 43 | return *it; 44 | } 45 | return nullptr; 46 | } 47 | 48 | LunaTaskPtr LunaTaskList::getByToken(const LSMessageToken& token) 49 | { 50 | for (auto it = m_list.begin(); it != m_list.end(); ++it) { 51 | if ((*it)->getToken() == token) 52 | return *it; 53 | } 54 | return nullptr; 55 | } 56 | 57 | bool LunaTaskList::add(LunaTaskPtr lunaTask) 58 | { 59 | m_list.push_back(lunaTask); 60 | return true; 61 | } 62 | 63 | void LunaTaskList::removeAfterReply(LunaTaskPtr lunaTask, bool fillIds) 64 | { 65 | if (lunaTask == nullptr) return; 66 | 67 | for (auto it = m_list.begin(); it != m_list.end(); ++it) { 68 | if ((*it) == lunaTask) { 69 | if (fillIds) { 70 | (*it)->fillIds((*it)->getResponsePayload()); 71 | } 72 | (*it)->reply(); 73 | m_list.erase(it); 74 | return; 75 | } 76 | } 77 | return; 78 | } 79 | 80 | void LunaTaskList::toJson(JValue& array) 81 | { 82 | if (!array.isArray()) 83 | return; 84 | 85 | for (auto it = m_list.begin(); it != m_list.end(); ++it) { 86 | JValue object = pbnjson::Object(); 87 | (*it)->toAPIJson(object); 88 | array.append(object); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/base/LunaTaskList.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BASE_LUNATASKLIST_H_ 18 | #define BASE_LUNATASKLIST_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include "interface/ISingleton.h" 24 | #include "LunaTask.h" 25 | 26 | using namespace std; 27 | 28 | class LunaTaskList : public ISingleton { 29 | friend class ISingleton; 30 | public: 31 | virtual ~LunaTaskList(); 32 | 33 | LunaTaskPtr create(); 34 | 35 | LunaTaskPtr getByKindAndId(const char* kind, const string& appId); 36 | LunaTaskPtr getByInstanceId(const string& instanceId); 37 | LunaTaskPtr getByToken(const LSMessageToken& token); 38 | 39 | bool add(LunaTaskPtr lunaTask); 40 | void removeAfterReply(LunaTaskPtr lunaTask, bool fillIds = false); 41 | 42 | void toJson(JValue& array); 43 | 44 | private: 45 | LunaTaskList(); 46 | 47 | list m_list; 48 | }; 49 | 50 | #endif /* BASE_LUNATASKLIST_H_ */ 51 | -------------------------------------------------------------------------------- /src/base/RunningAppList.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BASE_RUNNINGAPPLIST_H_ 18 | #define BASE_RUNNINGAPPLIST_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "interface/ISingleton.h" 25 | #include "interface/IClassName.h" 26 | #include "RunningApp.h" 27 | 28 | using namespace std; 29 | 30 | class RunningAppList : public ISingleton, 31 | public IClassName { 32 | friend class ISingleton; 33 | public: 34 | virtual ~RunningAppList(); 35 | 36 | RunningAppPtr createByLunaTask(LunaTaskPtr lunaTask); 37 | RunningAppPtr createByJson(const JValue& json); 38 | RunningAppPtr createByAppId(const string& appId); 39 | RunningAppPtr createByLaunchPointId(const string& launchPointId); 40 | 41 | RunningAppPtr getByLunaTask(LunaTaskPtr lunaTask, bool verifyLaunchPointId = true); 42 | RunningAppPtr getByIds(const string& instanceId, const string& appId, const int displayId = -1); 43 | RunningAppPtr getByInstanceId(const string& instanceId); 44 | RunningAppPtr getByAppId(const string& appId, const int displayId = -1); 45 | RunningAppPtr getByToken(const LSMessageToken& token); 46 | RunningAppPtr getByLS2Name(const string& ls2name); 47 | RunningAppPtr getByPid(const pid_t pid); 48 | RunningAppPtr getByWebprocessid(const string& webprocessid); 49 | 50 | bool add(RunningAppPtr runningApp); 51 | 52 | void removeByObject(RunningAppPtr runningApp); 53 | void removeByInstanceId(const string& instanceId); 54 | void removeByPid(const pid_t pid); 55 | void removeAllByType(AppType type); 56 | void removeAllByConext(AppType type, const int context); 57 | void removeAllByLaunchPoint(LaunchPointPtr launchPoint); 58 | 59 | bool setConext(AppType type, const int context); 60 | bool isTransition(bool devmodeOnly); 61 | void toJson(JValue& array, bool devmodeOnly = false); 62 | 63 | private: 64 | void onAdd(RunningAppPtr runningApp); 65 | void onRemove(RunningAppPtr runningApp); 66 | 67 | RunningAppList(); 68 | 69 | map m_map; 70 | }; 71 | 72 | #endif /* BASE_RUNNINGAPPLIST_H_ */ 73 | -------------------------------------------------------------------------------- /src/bus/client/AbsLifeHandler.cpp: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2020 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #include "AbsLifeHandler.h" 15 | #include "NativeContainer.h" 16 | #include "WAM.h" 17 | 18 | AbsLifeHandler& AbsLifeHandler::getLifeHandler(RunningAppPtr runningApp) 19 | { 20 | AppType type = runningApp->getLaunchPoint()->getAppDesc()->getAppType(); 21 | // handler_type 22 | switch (type) { 23 | case AppType::AppType_Web: 24 | return WAM::getInstance(); 25 | 26 | case AppType::AppType_Native: 27 | case AppType::AppType_Native_AppShell: 28 | case AppType::AppType_Native_BrowserShell: 29 | case AppType::AppType_Native_Builtin: 30 | case AppType::AppType_Native_Mvpd: 31 | case AppType::AppType_Native_Qml: 32 | return NativeContainer::getInstance(); 33 | 34 | // TODO stub app handler should be defined. 35 | case AppType::AppType_Stub: 36 | default: 37 | return NativeContainer::getInstance(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/bus/client/AbsLifeHandler.h: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2020 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #ifndef BUS_CLIENT_ABSLIFEHANDLER_H_ 15 | #define BUS_CLIENT_ABSLIFEHANDLER_H_ 16 | 17 | #include 18 | 19 | #include "base/RunningApp.h" 20 | 21 | using namespace std; 22 | 23 | class AbsLifeHandler { 24 | public: 25 | static AbsLifeHandler& getLifeHandler(RunningAppPtr runningApp); 26 | 27 | AbsLifeHandler() {}; 28 | virtual ~AbsLifeHandler() {}; 29 | 30 | virtual void launch(RunningAppPtr runningApp, LunaTaskPtr lunaTask) = 0; 31 | virtual void pause(RunningAppPtr runningApp, LunaTaskPtr lunaTask) = 0; 32 | virtual void close(RunningAppPtr runningApp, LunaTaskPtr lunaTask) = 0; 33 | virtual void kill(RunningAppPtr runningApp) = 0; 34 | 35 | protected: 36 | 37 | private: 38 | 39 | }; 40 | 41 | #endif /* BUS_CLIENT_ABSLIFEHANDLER_H_ */ 42 | -------------------------------------------------------------------------------- /src/bus/client/AbsLunaClient.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "AbsLunaClient.h" 18 | 19 | JValue& AbsLunaClient::getEmptyPayload() 20 | { 21 | static JValue empty; 22 | 23 | if (empty.isNull()) { 24 | empty = pbnjson::Object(); 25 | } 26 | return empty; 27 | } 28 | 29 | JValue& AbsLunaClient::getSubscriptionPayload() 30 | { 31 | static JValue subscription; 32 | if (subscription.isNull()) { 33 | subscription = pbnjson::Object(); 34 | subscription.put("subscribe", true); 35 | } 36 | return subscription; 37 | } 38 | 39 | bool AbsLunaClient::_onServerStatus(LSHandle* sh, LSMessage* message, void* context) 40 | { 41 | AbsLunaClient* client = static_cast(context); 42 | 43 | Message response(message); 44 | JValue subscriptionPayload = JDomParser::fromString(response.getPayload()); 45 | 46 | if (subscriptionPayload.isNull()) 47 | return true; 48 | 49 | bool connected = false; 50 | if (!JValueUtil::getValue(subscriptionPayload, "connected", connected)) { 51 | return true; 52 | } 53 | 54 | if (connected) 55 | Logger::info(client->getClassName(), __FUNCTION__, "Service is up"); 56 | else 57 | Logger::info(client->getClassName(), __FUNCTION__, "Service is down"); 58 | 59 | client->m_serverStatusCount++; 60 | client->m_isConnected = connected; 61 | client->EventServiceStatusChanged(connected); 62 | client->onServerStatusChanged(connected); 63 | return true; 64 | } 65 | 66 | AbsLunaClient::AbsLunaClient(const string& name) 67 | : m_serverStatusCount(0), 68 | m_name(name), 69 | m_isConnected(false) 70 | { 71 | setClassName("AbsLunaClient"); 72 | } 73 | 74 | AbsLunaClient::~AbsLunaClient() 75 | { 76 | } 77 | 78 | void AbsLunaClient::initialize() 79 | { 80 | JValue requestPayload = pbnjson::Object(); 81 | requestPayload.put("serviceName", getName()); 82 | m_statusCall = ApplicationManager::getInstance().callMultiReply( 83 | "luna://com.webos.service.bus/signal/registerServerStatus", 84 | requestPayload.stringify().c_str(), 85 | _onServerStatus, 86 | this 87 | ); 88 | 89 | onInitialzed(); 90 | } 91 | 92 | void AbsLunaClient::finalize() 93 | { 94 | m_statusCall.cancel(); 95 | onFinalized(); 96 | } 97 | -------------------------------------------------------------------------------- /src/bus/client/AbsLunaClient.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_ABSLUNACLIENT_H_ 18 | #define BUS_CLIENT_ABSLUNACLIENT_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "bus/service/ApplicationManager.h" 26 | #include "interface/IClassName.h" 27 | #include "util/JValueUtil.h" 28 | 29 | using namespace std; 30 | using namespace LS; 31 | using namespace pbnjson; 32 | 33 | class LSErrorSafe: public LSError { 34 | public: 35 | LSErrorSafe() 36 | { 37 | LSErrorInit(this); 38 | } 39 | 40 | ~LSErrorSafe() 41 | { 42 | LSErrorFree(this); 43 | } 44 | }; 45 | 46 | class AbsLunaClient : public IClassName { 47 | public: 48 | static JValue& getEmptyPayload(); 49 | static JValue& getSubscriptionPayload(); 50 | 51 | AbsLunaClient(const string& name); 52 | virtual ~AbsLunaClient(); 53 | 54 | virtual void initialize() final; 55 | virtual void finalize() final; 56 | 57 | const string& getName() 58 | { 59 | return m_name; 60 | } 61 | 62 | bool isConnected() 63 | { 64 | return m_isConnected; 65 | } 66 | 67 | boost::signals2::signal EventServiceStatusChanged; 68 | 69 | protected: 70 | virtual void onInitialzed() = 0; 71 | virtual void onFinalized() = 0; 72 | virtual void onServerStatusChanged(bool isConnected) = 0; 73 | 74 | int m_serverStatusCount; 75 | 76 | private: 77 | static bool _onServerStatus(LSHandle* sh, LSMessage* message, void* context); 78 | 79 | string m_name; 80 | bool m_isConnected; 81 | Call m_statusCall; 82 | }; 83 | 84 | #endif /* BUS_CLIENT_ABSLUNACLIENT_H_ */ 85 | -------------------------------------------------------------------------------- /src/bus/client/AppInstallService.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "base/LaunchPointList.h" 18 | #include "base/AppDescriptionList.h" 19 | #include "base/RunningAppList.h" 20 | #include "bus/client/AppInstallService.h" 21 | #include "bus/service/ApplicationManager.h" 22 | 23 | bool AppInstallService::onStatus(LSHandle* sh, LSMessage* message, void* context) 24 | { 25 | Message response(message); 26 | JValue subscriptionPayload = JDomParser::fromString(response.getPayload()); 27 | Logger::logSubscriptionResponse(getInstance().getClassName(), __FUNCTION__, response, subscriptionPayload); 28 | 29 | if (subscriptionPayload.isNull()) 30 | return true; 31 | 32 | int statusValue; 33 | string id = ""; 34 | string packageId = ""; 35 | 36 | JValueUtil::getValue(subscriptionPayload, "id", id); 37 | JValueUtil::getValue(subscriptionPayload, "details", "packageId", packageId); 38 | JValueUtil::getValue(subscriptionPayload, "statusValue", statusValue); 39 | 40 | if ((packageId.empty() && id.empty())) { 41 | return true; 42 | } 43 | string appId = packageId.empty() ? id : packageId; 44 | AppDescriptionPtr appDesc = nullptr; 45 | 46 | switch (statusValue) { 47 | case 22: // Install operation is cancelled 48 | case 23: // Install operation is complete with error during download 49 | case 24: // Install operation is complete with error during installing ipk 50 | case 25: // Remove operation is complete with error 51 | case 30: // All install operations are complete successfully 52 | case 31: // uninstalled 53 | AppDescriptionList::getInstance().scanApp(appId); 54 | break; 55 | 56 | default: 57 | return true; 58 | } 59 | return true; 60 | } 61 | 62 | AppInstallService::AppInstallService() 63 | : AbsLunaClient("com.webos.appInstallService") 64 | { 65 | setClassName("AppInstallService"); 66 | } 67 | 68 | AppInstallService::~AppInstallService() 69 | { 70 | } 71 | 72 | void AppInstallService::onInitialzed() 73 | { 74 | 75 | } 76 | 77 | void AppInstallService::onFinalized() 78 | { 79 | m_statusCall.cancel(); 80 | } 81 | 82 | void AppInstallService::onServerStatusChanged(bool isConnected) 83 | { 84 | static string method = string("luna://") + getName() + string("/status"); 85 | if (isConnected) { 86 | m_statusCall = ApplicationManager::getInstance().callMultiReply( 87 | method.c_str(), 88 | AbsLunaClient::getSubscriptionPayload().stringify().c_str(), 89 | onStatus, 90 | this 91 | ); 92 | } else { 93 | m_statusCall.cancel(); 94 | } 95 | } 96 | 97 | bool AppInstallService::onRemove(LSHandle* sh, LSMessage *message, void* context) 98 | { 99 | Message response(message); 100 | JValue responsePayload = JDomParser::fromString(response.getPayload()); 101 | Logger::logCallResponse(getInstance().getClassName(), __FUNCTION__, response, responsePayload); 102 | 103 | if (responsePayload.isNull()) 104 | return true; 105 | 106 | return true; 107 | } 108 | 109 | Call AppInstallService::remove(const string& appId) 110 | { 111 | static string method = string("luna://") + getName() + string("/remove"); 112 | 113 | JValue requestPayload = pbnjson::Object(); 114 | requestPayload.put("id", appId); 115 | requestPayload.put("subscribe", false); 116 | 117 | Call call = ApplicationManager::getInstance().callOneReply(method.c_str(), requestPayload.stringify().c_str(), onRemove, nullptr); 118 | return call; 119 | } 120 | -------------------------------------------------------------------------------- /src/bus/client/AppInstallService.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_APPINSTALLSERVICE_H_ 18 | #define BUS_CLIENT_APPINSTALLSERVICE_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "interface/ISingleton.h" 26 | #include "util/JValueUtil.h" 27 | #include "util/Logger.h" 28 | 29 | using namespace LS; 30 | using namespace pbnjson; 31 | 32 | class AppInstallService : public ISingleton, 33 | public AbsLunaClient { 34 | friend class ISingleton; 35 | public: 36 | virtual ~AppInstallService(); 37 | 38 | static bool onRemove(LSHandle* sh, LSMessage *message, void* context); 39 | Call remove(const string& appId); 40 | 41 | protected: 42 | // AbsLunaClient 43 | virtual void onInitialzed() override; 44 | virtual void onFinalized() override; 45 | virtual void onServerStatusChanged(bool isConnected) override; 46 | 47 | private: 48 | static bool onStatus(LSHandle* sh, LSMessage* message, void* context); 49 | 50 | AppInstallService(); 51 | 52 | Call m_statusCall; 53 | }; 54 | 55 | #endif // BUS_CLIENT_APPINSTALLSERVICE_H_ 56 | 57 | -------------------------------------------------------------------------------- /src/bus/client/Bootd.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "Bootd.h" 18 | 19 | Bootd::Bootd() 20 | : AbsLunaClient("com.webos.bootManager") 21 | { 22 | setClassName("Bootd"); 23 | } 24 | 25 | Bootd::~Bootd() 26 | { 27 | } 28 | 29 | void Bootd::onInitialzed() 30 | { 31 | 32 | } 33 | 34 | void Bootd::onFinalized() 35 | { 36 | m_getBootStatusCall.cancel(); 37 | } 38 | 39 | void Bootd::onServerStatusChanged(bool isConnected) 40 | { 41 | static string method = string("luna://") + getName() + string("/getBootStatus"); 42 | 43 | if (isConnected) { 44 | m_getBootStatusCall = ApplicationManager::getInstance().callMultiReply( 45 | method.c_str(), 46 | AbsLunaClient::getSubscriptionPayload().stringify().c_str(), 47 | onGetBootStatus, 48 | this 49 | ); 50 | Logger::logSubscriptionRequest(getClassName(), __FUNCTION__, method, AbsLunaClient::getSubscriptionPayload()); 51 | } else { 52 | m_getBootStatusCall.cancel(); 53 | } 54 | } 55 | 56 | bool Bootd::onGetBootStatus(LSHandle* sh, LSMessage* message, void* context) 57 | { 58 | Message response(message); 59 | JValue subscriptionPayload = JDomParser::fromString(response.getPayload()); 60 | Logger::logSubscriptionResponse(getInstance().getClassName(), __FUNCTION__, response, subscriptionPayload); 61 | 62 | if (subscriptionPayload.isNull()) 63 | return true; 64 | 65 | Bootd::getInstance().EventGetBootStatus(subscriptionPayload); 66 | return true; 67 | } 68 | -------------------------------------------------------------------------------- /src/bus/client/Bootd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_BOOTD_H_ 18 | #define BUS_CLIENT_BOOTD_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "interface/ISingleton.h" 26 | #include "util/JValueUtil.h" 27 | #include "util/Logger.h" 28 | 29 | using namespace LS; 30 | using namespace pbnjson; 31 | 32 | class Bootd : public ISingleton, 33 | public AbsLunaClient { 34 | friend class ISingleton; 35 | public: 36 | virtual ~Bootd(); 37 | 38 | boost::signals2::signal EventGetBootStatus; 39 | 40 | protected: 41 | // AbsLunaClient 42 | virtual void onInitialzed() override; 43 | virtual void onFinalized() override; 44 | virtual void onServerStatusChanged(bool isConnected) override; 45 | 46 | private: 47 | static bool onGetBootStatus(LSHandle* sh, LSMessage* message, void* context); 48 | 49 | Bootd(); 50 | 51 | Call m_getBootStatusCall; 52 | }; 53 | 54 | #endif // BUS_CLIENT_BOOTD_H_ 55 | 56 | -------------------------------------------------------------------------------- /src/bus/client/Configd.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "Configd.h" 18 | 19 | Configd::Configd() 20 | : AbsLunaClient("com.webos.service.config") 21 | { 22 | setClassName("Configd"); 23 | 24 | configNames = pbnjson::Array(); 25 | configNames.append("system.sysAssetFallbackPrecedence"); 26 | configNames.append("com.webos.applicationManager.keepAliveApps"); 27 | configNames.append("com.webos.applicationManager.lifeCycle"); 28 | } 29 | 30 | Configd::~Configd() 31 | { 32 | } 33 | 34 | void Configd::onInitialzed() 35 | { 36 | 37 | } 38 | 39 | void Configd::onFinalized() 40 | { 41 | m_getConfigsCall.cancel(); 42 | } 43 | 44 | void Configd::onServerStatusChanged(bool isConnected) 45 | { 46 | static string method = string("luna://") + getName() + string("/getConfigs"); 47 | 48 | if (isConnected) { 49 | JValue requestPayload = pbnjson::Object(); 50 | requestPayload.put("subscribe", true); 51 | requestPayload.put("configNames", configNames); 52 | 53 | m_getConfigsCall = ApplicationManager::getInstance().callMultiReply( 54 | method.c_str(), 55 | requestPayload.stringify().c_str(), 56 | onGetConfigs, 57 | nullptr 58 | ); 59 | } else { 60 | m_getConfigsCall.cancel(); 61 | } 62 | } 63 | 64 | bool Configd::onGetConfigs(LSHandle* sh, LSMessage* message, void* context) 65 | { 66 | Message response(message); 67 | JValue subscriptionPayload = JDomParser::fromString(response.getPayload()); 68 | Logger::logSubscriptionResponse(getInstance().getClassName(), __FUNCTION__, response, subscriptionPayload); 69 | 70 | if (subscriptionPayload.isNull()) 71 | return false; 72 | 73 | Configd::getInstance().EventGetConfigs(subscriptionPayload); 74 | return true; 75 | } 76 | -------------------------------------------------------------------------------- /src/bus/client/Configd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_CONFIGD_H_ 18 | #define BUS_CLIENT_CONFIGD_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "interface/ISingleton.h" 26 | #include "util/Logger.h" 27 | 28 | using namespace std; 29 | using namespace LS; 30 | using namespace pbnjson; 31 | 32 | class Configd : public ISingleton, 33 | public AbsLunaClient { 34 | friend class ISingleton; 35 | public: 36 | virtual ~Configd(); 37 | 38 | void addRequiredKey(const string& key) 39 | { 40 | m_configNames.push_back(key); 41 | } 42 | 43 | boost::signals2::signal EventGetConfigs; 44 | 45 | protected: 46 | // AbsLunaClient 47 | virtual void onInitialzed() override; 48 | virtual void onFinalized() override; 49 | virtual void onServerStatusChanged(bool isConnected) override; 50 | 51 | private: 52 | static bool onGetConfigs(LSHandle* sh, LSMessage* response, void* context); 53 | 54 | Configd(); 55 | 56 | vector m_configNames; 57 | JValue configNames; 58 | Call m_getConfigsCall; 59 | }; 60 | 61 | #endif // BUS_CLIENT_CONFIGD_H_ 62 | 63 | -------------------------------------------------------------------------------- /src/bus/client/DB8.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_DB8_H_ 18 | #define BUS_CLIENT_DB8_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "interface/ISingleton.h" 26 | 27 | using namespace LS; 28 | using namespace pbnjson; 29 | 30 | class DB8 : public ISingleton, 31 | public AbsLunaClient { 32 | friend class ISingleton; 33 | public: 34 | virtual ~DB8(); 35 | 36 | bool insertLaunchPoint(JValue& json); 37 | bool updateLaunchPoint(const JValue& json); 38 | void deleteLaunchPoint(const string& launchPointId); 39 | 40 | protected: 41 | // AbsLunaClient 42 | virtual void onInitialzed() override; 43 | virtual void onFinalized() override; 44 | virtual void onServerStatusChanged(bool isConnected) override; 45 | 46 | private: 47 | static const char* KIND_NAME; 48 | 49 | static bool onResponse(LSHandle* sh, LSMessage* message, void* context); 50 | 51 | static bool onFind(LSHandle* sh, LSMessage* message, void* context); 52 | void find(); 53 | 54 | static bool onPutKind(LSHandle* sh, LSMessage* message, void* context); 55 | void putKind(); 56 | 57 | static bool onPutPermissions(LSHandle* sh, LSMessage* message, void* context); 58 | void putPermissions(); 59 | 60 | DB8(); 61 | 62 | }; 63 | 64 | #endif /* BUS_CLIENT_DB8_H_ */ 65 | -------------------------------------------------------------------------------- /src/bus/client/LSM.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2025 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "LSM.h" 18 | 19 | #include "base/AppDescription.h" 20 | #include "base/LaunchPointList.h" 21 | #include "base/LaunchPoint.h" 22 | #include "base/RunningApp.h" 23 | #include "base/RunningAppList.h" 24 | #include "bus/service/ApplicationManager.h" 25 | #include "util/JValueUtil.h" 26 | 27 | bool LSM::isFullscreenWindowType(const JValue& foregroundInfo) 28 | { 29 | bool windowGroup = false; 30 | bool windowGroupOwner = false; 31 | string windowType = ""; 32 | 33 | JValueUtil::getValue(foregroundInfo, "windowGroup", windowGroup); 34 | JValueUtil::getValue(foregroundInfo, "windowGroupOwner", windowGroupOwner); 35 | JValueUtil::getValue(foregroundInfo, "windowType", windowType); 36 | 37 | if (!windowGroup) 38 | windowGroupOwner = true; 39 | if (!windowGroupOwner) 40 | return false; 41 | 42 | return SAMConf::getInstance().isFullscreenWindowTypes(std::move(windowType)); 43 | } 44 | 45 | LSM::LSM() 46 | : AbsLunaClient("com.webos.surfacemanager") 47 | { 48 | setClassName("LSM"); 49 | m_foregroundInfo = pbnjson::Array(); 50 | } 51 | 52 | LSM::~LSM() 53 | { 54 | 55 | } 56 | 57 | void LSM::onInitialzed() 58 | { 59 | 60 | } 61 | 62 | void LSM::onFinalized() 63 | { 64 | m_getForegroundAppInfoCall.cancel(); 65 | } 66 | 67 | void LSM::onServerStatusChanged(bool isConnected) 68 | { 69 | static string method = string("luna://") + getName() + string("/getForegroundAppInfo"); 70 | 71 | if (isConnected) { 72 | m_getForegroundAppInfoCall = ApplicationManager::getInstance().callMultiReply( 73 | method.c_str(), 74 | AbsLunaClient::getSubscriptionPayload().stringify().c_str(), 75 | onGetForegroundAppInfo, 76 | nullptr 77 | ); 78 | Logger::logSubscriptionRequest(getClassName(), __FUNCTION__, method, AbsLunaClient::getSubscriptionPayload()); 79 | } else { 80 | m_getForegroundAppInfoCall.cancel(); 81 | } 82 | } 83 | 84 | bool LSM::onGetForegroundAppInfo(LSHandle* sh, LSMessage* message, void* context) 85 | { 86 | Message response(message); 87 | JValue subscriptionPayload = JDomParser::fromString(response.getPayload()); 88 | Logger::logSubscriptionResponse(getInstance().getClassName(), __FUNCTION__, response, subscriptionPayload); 89 | 90 | if (subscriptionPayload.isNull()) 91 | return true; 92 | 93 | JValue orgForegroundAppInfo; 94 | if (!JValueUtil::getValue(subscriptionPayload, "foregroundAppInfo", orgForegroundAppInfo)) { 95 | Logger::error(getInstance().getClassName(), __FUNCTION__, "Failed to get 'foregroundAppInfo'"); 96 | return true; 97 | } 98 | 99 | string newFullWindowAppId = ""; 100 | vector newForegroundAppIds; 101 | JValue newForegroundAppInfo = pbnjson::Array(); 102 | 103 | for (int i = 0; i < orgForegroundAppInfo.arraySize(); ++i) { 104 | string appId; 105 | int displayId = -1; 106 | string processId; 107 | 108 | JValueUtil::getValue(orgForegroundAppInfo[i], "appId", appId); 109 | JValueUtil::getValue(orgForegroundAppInfo[i], "displayId", displayId); 110 | JValueUtil::getValue(orgForegroundAppInfo[i], "processId", processId); 111 | 112 | RunningAppPtr runningApp = RunningAppList::getInstance().getByAppId(appId, displayId); 113 | if (runningApp == nullptr) { 114 | Logger::info(getInstance().getClassName(), __FUNCTION__, "Cannot find RunningApp. Respawned or Skipped for other sessions"); 115 | continue; 116 | } 117 | 118 | // TODO This is ambiguous multiple display env. We need to find better way 119 | if (isFullscreenWindowType(orgForegroundAppInfo[i])) { 120 | newFullWindowAppId = appId; 121 | } 122 | 123 | // TODO following *instanceId* should be passed by LSM 124 | if (!runningApp->getInstanceId().empty()) { 125 | orgForegroundAppInfo[i].put("instanceId", runningApp->getInstanceId()); 126 | orgForegroundAppInfo[i].put("launchPointId", runningApp->getLaunchPointId()); 127 | } 128 | 129 | // SAM knows its child pid better than LSM. 130 | // This code is needed specially in container environment. 131 | if (runningApp->getLaunchPoint()->getAppDesc()->getAppType() == AppType::AppType_Web) { 132 | runningApp->setProcessId(atoi(processId.c_str())); 133 | } 134 | runningApp->setLifeStatus(LifeStatus::LifeStatus_FOREGROUND); 135 | if (runningApp->isFirstLaunch()) 136 | Logger::info(getInstance().getClassName(), __FUNCTION__, runningApp->getAppId(), Logger::format("Foreground Time: %lld ms", runningApp->getTimeStamp())); 137 | newForegroundAppInfo.append(orgForegroundAppInfo[i].duplicate()); 138 | newForegroundAppIds.push_back(std::move(appId)); 139 | } 140 | 141 | // set background 142 | for (auto& oldAppId : getInstance().m_foregroundAppIds) { 143 | bool found = false; 144 | for (auto& newAppId : newForegroundAppIds) { 145 | if (oldAppId == newAppId) { 146 | found = true; 147 | break; 148 | } 149 | } 150 | 151 | if (found == false) { 152 | RunningAppPtr runningApp = RunningAppList::getInstance().getByAppId(oldAppId); 153 | if (runningApp && runningApp->getLifeStatus() == LifeStatus::LifeStatus_FOREGROUND) { 154 | runningApp->setLifeStatus(LifeStatus::LifeStatus_BACKGROUND); 155 | } 156 | } 157 | } 158 | 159 | bool extraInfoOnly = false; 160 | if (getInstance().m_fullWindowAppId == newFullWindowAppId) { 161 | extraInfoOnly = true; 162 | } 163 | 164 | getInstance().m_fullWindowAppId = std::move(newFullWindowAppId); 165 | getInstance().m_foregroundAppIds = std::move(newForegroundAppIds); 166 | getInstance().m_foregroundInfo = std::move(newForegroundAppInfo); 167 | 168 | ApplicationManager::getInstance().postRunning(nullptr); 169 | ApplicationManager::getInstance().postGetForegroundAppInfo(extraInfoOnly); 170 | return true; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /src/bus/client/LSM.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_LSM_H_ 18 | #define BUS_CLIENT_LSM_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "interface/ISingleton.h" 26 | #include "util/Logger.h" 27 | 28 | using namespace LS; 29 | using namespace pbnjson; 30 | 31 | class LSM : public ISingleton, 32 | public AbsLunaClient { 33 | friend class ISingleton; 34 | public: 35 | virtual ~LSM(); 36 | 37 | boost::signals2::signal EventRecentsAppListChanged; 38 | 39 | void getForegroundInfoById(const string& appId, JValue& info) 40 | { 41 | if (!m_foregroundInfo.isArray() || m_foregroundInfo.arraySize() < 1) 42 | return; 43 | 44 | for (auto item : m_foregroundInfo.items()) { 45 | if (!item.hasKey("appId") || !item["appId"].isString()) 46 | continue; 47 | 48 | if (item["appId"].asString() == appId) { 49 | info = item.duplicate(); 50 | return; 51 | } 52 | } 53 | } 54 | 55 | const string& getFullWindowAppId() 56 | { 57 | return m_fullWindowAppId; 58 | } 59 | 60 | const JValue& getForegroundInfo() const 61 | { 62 | return m_foregroundInfo; 63 | } 64 | 65 | protected: 66 | // AbsLunaClient 67 | virtual void onInitialzed() override; 68 | virtual void onFinalized() override; 69 | virtual void onServerStatusChanged(bool isConnected) override; 70 | 71 | private: 72 | static bool isFullscreenWindowType(const JValue& foreground_info); 73 | static bool onGetForegroundAppInfo(LSHandle* sh, LSMessage* message, void* context); 74 | 75 | LSM(); 76 | 77 | Call m_getForegroundAppInfoCall; 78 | 79 | string m_fullWindowAppId; 80 | vector m_foregroundAppIds; 81 | JValue m_foregroundInfo; 82 | 83 | }; 84 | 85 | #endif 86 | 87 | -------------------------------------------------------------------------------- /src/bus/client/MemoryManager.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "MemoryManager.h" 18 | 19 | MemoryManager::MemoryManager() 20 | : AbsLunaClient("com.webos.service.memorymanager") 21 | { 22 | setClassName("MemoryManager"); 23 | } 24 | 25 | MemoryManager::~MemoryManager() 26 | { 27 | } 28 | 29 | void MemoryManager::onInitialzed() 30 | { 31 | 32 | } 33 | 34 | void MemoryManager::onFinalized() 35 | { 36 | 37 | } 38 | 39 | void MemoryManager::onServerStatusChanged(bool isConnected) 40 | { 41 | } 42 | 43 | bool MemoryManager::onRequireMemory(LSHandle* sh, LSMessage* message, void* context) 44 | { 45 | Message response(message); 46 | JValue responsePayload = pbnjson::JDomParser::fromString(response.getPayload()); 47 | Logger::logCallResponse(getInstance().getClassName(), __FUNCTION__, response, responsePayload); 48 | 49 | LSMessageToken token = LSMessageGetResponseToken(message); 50 | LunaTaskPtr lunaTask = LunaTaskList::getInstance().getByToken(token); 51 | RunningAppPtr runningApp = RunningAppList::getInstance().getByToken(token); 52 | if (lunaTask == nullptr) { 53 | Logger::error(getInstance().getClassName(), __FUNCTION__, "Cannot find lunaTask"); 54 | return false; 55 | } 56 | if (runningApp == nullptr) { 57 | Logger::error(getInstance().getClassName(), __FUNCTION__, "Cannot find runningApp"); 58 | return false; 59 | } 60 | 61 | int errorCode = 0; 62 | string errorText = ""; 63 | bool returnValue = true; 64 | 65 | JValueUtil::getValue(responsePayload, "errorCode", errorCode); 66 | JValueUtil::getValue(responsePayload, "errorText", errorText); 67 | JValueUtil::getValue(responsePayload, "returnValue", returnValue); 68 | 69 | if (!returnValue) { 70 | RunningAppList::getInstance().removeByInstanceId(runningApp->getInstanceId()); 71 | lunaTask->setErrCodeAndText(errorCode, std::move(errorText)); 72 | lunaTask->error(lunaTask); 73 | return true; 74 | } 75 | 76 | lunaTask->success(lunaTask); 77 | return true; 78 | } 79 | 80 | void MemoryManager::requireMemory(RunningAppPtr runningApp, LunaTaskPtr lunaTask) 81 | { 82 | static string method = string("luna://") + getName() + string("/requireMemory"); 83 | JValue requestPayload = pbnjson::Object(); 84 | 85 | if (!isConnected()) { 86 | Logger::warning(getClassName(), __FUNCTION__, "MemoryManager is not running. Skip memory reclaiming"); 87 | lunaTask->success(lunaTask); 88 | return; 89 | } 90 | 91 | // TODO : 150MB should be extended based on appinfo.json 92 | requestPayload.put("requiredMemory", 150); 93 | 94 | LSErrorSafe error; 95 | LSMessageToken token = 0; 96 | Logger::logCallRequest(getClassName(), __FUNCTION__, method, requestPayload); 97 | if (!LSCallOneReply( 98 | ApplicationManager::getInstance().get(), 99 | method.c_str(), 100 | requestPayload.stringify().c_str(), 101 | onRequireMemory, 102 | nullptr, 103 | &token, 104 | &error 105 | )) { 106 | // If calling MM is failed, just skip it. 107 | lunaTask->success(lunaTask); 108 | return; 109 | } 110 | lunaTask->setToken(token); 111 | runningApp->setToken(token); 112 | } 113 | -------------------------------------------------------------------------------- /src/bus/client/MemoryManager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_MEMORYMANAGER_H_ 18 | #define BUS_CLIENT_MEMORYMANAGER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "base/LunaTask.h" 26 | #include "interface/ISingleton.h" 27 | #include "util/Logger.h" 28 | 29 | using namespace LS; 30 | using namespace pbnjson; 31 | 32 | class MemoryManager : public ISingleton, 33 | public AbsLunaClient { 34 | friend class ISingleton; 35 | public: 36 | virtual ~MemoryManager(); 37 | 38 | void requireMemory(RunningAppPtr runningApp, LunaTaskPtr lunaTask); 39 | 40 | protected: 41 | // AbsLunaClient 42 | virtual void onInitialzed() override; 43 | virtual void onFinalized() override; 44 | virtual void onServerStatusChanged(bool isConnected) override; 45 | 46 | private: 47 | static bool onRequireMemory(LSHandle* sh, LSMessage* message, void* context); 48 | 49 | MemoryManager(); 50 | }; 51 | 52 | #endif /* BUS_CLIENT_MEMORYMANAGER_H_ */ 53 | -------------------------------------------------------------------------------- /src/bus/client/NativeContainer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_NATIVECONTAINER_H_ 18 | #define BUS_CLIENT_NATIVECONTAINER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "base/LaunchPointList.h" 25 | #include "base/LunaTaskList.h" 26 | #include "base/RunningAppList.h" 27 | #include "interface/ISingleton.h" 28 | #include "interface/IClassName.h" 29 | #include "AbsLifeHandler.h" 30 | #include "util/NativeProcess.h" 31 | 32 | class NativeContainer : public ISingleton, 33 | public IClassName, 34 | public AbsLifeHandler { 35 | friend class ISingleton; 36 | public: 37 | static void onKillChildProcess(GPid pid, gint status, gpointer data); 38 | 39 | virtual ~NativeContainer(); 40 | 41 | virtual void initialize(); 42 | 43 | // AbsLifeHandler 44 | virtual void launch(RunningAppPtr runningApp, LunaTaskPtr lunaTask) override; 45 | virtual void pause(RunningAppPtr runningApp, LunaTaskPtr lunaTask) override; 46 | virtual void close(RunningAppPtr runningApp, LunaTaskPtr lunaTask) override; 47 | virtual void kill(RunningAppPtr runningApp) override; 48 | 49 | private: 50 | static const string KEY_NATIVE_RUNNING_APPS; 51 | 52 | static int s_instanceCounter; 53 | 54 | NativeContainer(); 55 | 56 | virtual void removeItem(GPid pid); 57 | virtual void addItem(const string& instanceId, const string& launchPointId, const int processId, const int displayId); 58 | 59 | map m_environments; 60 | JValue m_nativeRunninApps; 61 | 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/bus/client/Notification.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "bus/client/Notification.h" 18 | 19 | #include "util/Logger.h" 20 | #include "util/JValueUtil.h" 21 | 22 | Notification::Notification() 23 | : AbsLunaClient("com.webos.notification") 24 | { 25 | setClassName("Notification"); 26 | } 27 | 28 | Notification::~Notification() 29 | { 30 | } 31 | 32 | void Notification::onInitialzed() 33 | { 34 | 35 | } 36 | 37 | void Notification::onFinalized() 38 | { 39 | 40 | } 41 | 42 | void Notification::onServerStatusChanged(bool isConnected) 43 | { 44 | 45 | } 46 | 47 | bool Notification::onCreatePincodePrompt(LSHandle* sh, LSMessage* message, void* context) 48 | { 49 | JValue responsePayload = pbnjson::JDomParser::fromString(LSMessageGetPayload(message)); 50 | bool returnValue = false; 51 | bool matched = false; 52 | 53 | if (!JValueUtil::getValue(responsePayload, "returnValue", returnValue) || !JValueUtil::getValue(responsePayload, "matched", matched)) { 54 | Logger::error(getInstance().getClassName(), __FUNCTION__, "Failed to get required params"); 55 | return true; 56 | } 57 | 58 | 59 | if (matched == false) { 60 | Logger::info(getInstance().getClassName(), __FUNCTION__, "uninstallation is canceled because of invalid pincode"); 61 | } else { 62 | // TODO: appId should be passed 63 | // AppPackageManager::getInstance().removeApp(appId, false, AppStatusChangeEvent::AppStatusChangeEvent_Uninstalled); 64 | } 65 | return true; 66 | } 67 | 68 | Call Notification::createPincodePrompt(LSFilterFunc func) 69 | { 70 | static string method = string("luna://") + getName() + string("/createPincodePrompt"); 71 | 72 | JValue requestPayload = pbnjson::Object(); 73 | requestPayload.put("promptType", "parental"); 74 | 75 | Call call = ApplicationManager::getInstance().callOneReply(method.c_str(), requestPayload.stringify().c_str(), func, nullptr); 76 | return call; 77 | } 78 | -------------------------------------------------------------------------------- /src/bus/client/Notification.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_NOTIFICATION_H_ 18 | #define BUS_CLIENT_NOTIFICATION_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "interface/ISingleton.h" 26 | 27 | using namespace LS; 28 | using namespace pbnjson; 29 | 30 | class Notification : public ISingleton, 31 | public AbsLunaClient { 32 | friend class ISingleton; 33 | public: 34 | virtual ~Notification(); 35 | 36 | // APIs 37 | static bool onCreatePincodePrompt(LSHandle* sh, LSMessage* message, void* context); 38 | Call createPincodePrompt(LSFilterFunc func); 39 | 40 | protected: 41 | // AbsLunaClient 42 | virtual void onInitialzed() override; 43 | virtual void onFinalized() override; 44 | virtual void onServerStatusChanged(bool isConnected) override; 45 | 46 | private: 47 | static const string NAME; 48 | 49 | Notification(); 50 | }; 51 | 52 | #endif /* BUS_CLIENT_NOTIFICATION_H_ */ 53 | -------------------------------------------------------------------------------- /src/bus/client/SettingService.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "SettingService.h" 18 | 19 | #include 20 | #include 21 | 22 | #include "base/AppDescriptionList.h" 23 | #include "bus/service/ApplicationManager.h" 24 | #include "conf/SAMConf.h" 25 | #include "util/JValueUtil.h" 26 | 27 | SettingService::SettingService() 28 | : AbsLunaClient("com.webos.settingsservice") 29 | { 30 | setClassName("SettingService"); 31 | 32 | JValue localeInfo = JDomParser::fromFile(PATH_LOCALE_INFO); 33 | updateLocaleInfo(localeInfo); 34 | } 35 | 36 | SettingService::~SettingService() 37 | { 38 | } 39 | 40 | void SettingService::onInitialzed() 41 | { 42 | 43 | } 44 | 45 | void SettingService::onFinalized() 46 | { 47 | m_getSystemSettingsCall.cancel(); 48 | } 49 | 50 | void SettingService::onServerStatusChanged(bool isConnected) 51 | { 52 | static string method = string("luna://") + getName() + string("/getSystemSettings"); 53 | 54 | if (isConnected) { 55 | JValue requestPayload = pbnjson::Object(); 56 | requestPayload.put("subscribe", true); 57 | requestPayload.put("key", "localeInfo"); 58 | 59 | m_getSystemSettingsCall = ApplicationManager::getInstance().callMultiReply( 60 | method.c_str(), 61 | requestPayload.stringify().c_str(), 62 | onLocaleChanged, 63 | nullptr 64 | ); 65 | } else { 66 | m_getSystemSettingsCall.cancel(); 67 | } 68 | } 69 | 70 | bool SettingService::onCheckParentalLock(LSHandle* sh, LSMessage* message, void* context) 71 | { 72 | Message response(message); 73 | JValue responsePayload = pbnjson::JDomParser::fromString(response.getPayload()); 74 | Logger::logCallResponse(getInstance().getClassName(), __FUNCTION__, response, responsePayload); 75 | 76 | if (responsePayload.isNull()) 77 | return true; 78 | 79 | bool returnValue = false; 80 | string errorText; 81 | 82 | bool isParentalControlValid = false; 83 | bool parentalControl = false; 84 | bool isApplockPerAppValid = false; 85 | bool applockPerApp = false; 86 | 87 | JValueUtil::getValue(responsePayload, "returnValue", returnValue); 88 | JValueUtil::getValue(responsePayload, "errorText", errorText); 89 | 90 | if (!responsePayload.hasKey("results") || !responsePayload["results"].isArray()) { 91 | Logger::debug(getInstance().getClassName(), __FUNCTION__, Logger::format("result fail: %s", responsePayload.stringify().c_str())); 92 | goto Done; 93 | } 94 | 95 | for (int i = 0; i < responsePayload["results"].arraySize(); ++i) { 96 | if (!responsePayload["results"][i].hasKey("settings") || !responsePayload["results"][i]["settings"].isObject()) 97 | continue; 98 | 99 | if (responsePayload["results"][i]["settings"].hasKey("parentalControl") && responsePayload["results"][i]["settings"]["parentalControl"].isBoolean()) { 100 | parentalControl = responsePayload["results"][i]["settings"]["parentalControl"].asBool(); 101 | isParentalControlValid = true; 102 | } 103 | 104 | if (responsePayload["results"][i]["settings"].hasKey("applockPerApp") && responsePayload["results"][i]["settings"]["applockPerApp"].isBoolean()) { 105 | applockPerApp = responsePayload["results"][i]["settings"]["applockPerApp"].asBool(); 106 | isApplockPerAppValid = true; 107 | } 108 | } 109 | 110 | if (!isParentalControlValid || !isApplockPerAppValid) { 111 | Logger::debug("CheckAppLockStatus", __FUNCTION__, Logger::format("receiving valid result fail: %s", responsePayload.stringify().c_str())); 112 | goto Done; 113 | } 114 | 115 | if (parentalControl && applockPerApp) { 116 | // Notification::getInstance().createPincodePrompt(onCreatePincodePrompt); 117 | return true; 118 | } 119 | 120 | Done: 121 | // TODO: appId should be passed 122 | // AppPackageManager::getInstance().removeApp(appId, false, AppStatusChangeEvent::AppStatusChangeEvent_Uninstalled); 123 | return true; 124 | } 125 | 126 | Call SettingService::checkParentalLock(LSFilterFunc func, const string& appId) 127 | { 128 | static string method = string("luna://") + getName() + string("/batch"); 129 | JValue requestPayload = pbnjson::Object(); 130 | JValue operations = pbnjson::Array(); 131 | 132 | JValue parentalControl = pbnjson::Object(); 133 | parentalControl.put("method", "getSystemSettings"); 134 | parentalControl.put("params", pbnjson::Object()); 135 | parentalControl["params"].put("category", "lock"); 136 | parentalControl["params"].put("key", "parentalControl"); 137 | operations.append(parentalControl); 138 | 139 | JValue applockPerApp = pbnjson::Object(); 140 | applockPerApp.put("method", "getSystemSettings"); 141 | applockPerApp.put("params", pbnjson::Object()); 142 | applockPerApp["params"].put("category", "lock"); 143 | applockPerApp["params"].put("key", "applockPerApp"); 144 | applockPerApp["params"].put("appId", appId); 145 | operations.append(applockPerApp); 146 | 147 | requestPayload.put("operations", operations); 148 | 149 | Call call = ApplicationManager::getInstance().callOneReply(method.c_str(), requestPayload.stringify().c_str(), func, nullptr); 150 | return call; 151 | } 152 | 153 | bool SettingService::onLocaleChanged(LSHandle* sh, LSMessage* message, void* context) 154 | { 155 | Message response(message); 156 | JValue subscriptionPayload = JDomParser::fromString(response.getPayload()); 157 | Logger::logSubscriptionResponse(getInstance().getClassName(), __FUNCTION__, response, subscriptionPayload); 158 | 159 | if (subscriptionPayload.isNull()) 160 | return true; 161 | 162 | bool returnValue = true; 163 | if (!JValueUtil::getValue(subscriptionPayload, "returnValue", returnValue) || !returnValue) { 164 | Logger::warning(getInstance().getClassName(), __FUNCTION__, "received invaild message from settings service"); 165 | return true; 166 | } 167 | 168 | if (!subscriptionPayload["settings"].isObject()) { 169 | return true; 170 | } 171 | 172 | SettingService::getInstance().updateLocaleInfo(subscriptionPayload["settings"]); 173 | return true; 174 | } 175 | 176 | void SettingService::updateLocaleInfo(const JValue& settings) 177 | { 178 | string localeInfo; 179 | 180 | if (settings.isNull() || !settings.isObject()) { 181 | return; 182 | } 183 | 184 | if (!JValueUtil::getValue(settings, "localeInfo", "locales", "UI", localeInfo)) { 185 | return; 186 | } 187 | 188 | if (localeInfo.empty() || localeInfo == m_localeInfo) { 189 | return; 190 | } 191 | 192 | m_localeInfo = std::move(localeInfo); 193 | string language; 194 | string script; 195 | string region; 196 | 197 | if (m_localeInfo.empty()) { 198 | language = ""; 199 | script = ""; 200 | region = ""; 201 | } else { 202 | icu::Locale icu_UI_locale = icu::Locale::createFromName(m_localeInfo.c_str()); 203 | language = icu_UI_locale.getLanguage(); 204 | script = icu_UI_locale.getScript(); 205 | region = icu_UI_locale.getCountry(); 206 | } 207 | 208 | if (language == SAMConf::getInstance().getLanguage() && 209 | script == SAMConf::getInstance().getScript() && 210 | region == SAMConf::getInstance().getRegion()) { 211 | Logger::info(getClassName(), __FUNCTION__, "Same localization info"); 212 | return; 213 | } 214 | 215 | Logger::info(getClassName(), __FUNCTION__, "Changed Locale", 216 | Logger::format("language(%s=>%s) script(%s=>%s) region(%s=>%s)", 217 | SAMConf::getInstance().getLanguage().c_str(), language.c_str(), 218 | SAMConf::getInstance().getScript().c_str(), script.c_str(), 219 | SAMConf::getInstance().getRegion().c_str(), region.c_str())); 220 | 221 | SAMConf::getInstance().setLocale(language, script, region); 222 | AppDescriptionList::getInstance().changeLocale(); 223 | 224 | } 225 | -------------------------------------------------------------------------------- /src/bus/client/SettingService.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_SETTINGSERVICE_H_ 18 | #define BUS_CLIENT_SETTINGSERVICE_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "interface/ISingleton.h" 26 | #include "util/Logger.h" 27 | 28 | using namespace LS; 29 | using namespace pbnjson; 30 | 31 | class SettingService : public ISingleton, 32 | public AbsLunaClient { 33 | friend class ISingleton; 34 | public: 35 | virtual ~SettingService(); 36 | 37 | // API 38 | static bool onCheckParentalLock(LSHandle* sh, LSMessage* message, void* context); 39 | Call checkParentalLock(LSFilterFunc func, const string& appId); 40 | 41 | const string& localeInfo() const 42 | { 43 | return m_localeInfo; 44 | } 45 | 46 | protected: 47 | // AbsLunaClient 48 | virtual void onInitialzed() override; 49 | virtual void onFinalized() override; 50 | virtual void onServerStatusChanged(bool isConnected) override; 51 | 52 | private: 53 | static bool onLocaleChanged(LSHandle* sh, LSMessage* message, void* context); 54 | 55 | SettingService(); 56 | 57 | void updateLocaleInfo(const JValue& localeInfo); 58 | 59 | string m_localeInfo; 60 | 61 | Call m_getSystemSettingsCall; 62 | 63 | }; 64 | #endif // BUS_CLIENT_SETTINGSERVICE_H_ 65 | 66 | -------------------------------------------------------------------------------- /src/bus/client/WAM.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_CLIENT_WAM_H_ 18 | #define BUS_CLIENT_WAM_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include "AbsLunaClient.h" 25 | #include "AbsLifeHandler.h" 26 | #include "base/LunaTask.h" 27 | #include "interface/ISingleton.h" 28 | #include "interface/IClassName.h" 29 | #include "util/Logger.h" 30 | 31 | using namespace LS; 32 | using namespace pbnjson; 33 | 34 | class WAM : public ISingleton, 35 | public AbsLunaClient, 36 | public AbsLifeHandler { 37 | friend class ISingleton; 38 | public: 39 | virtual ~WAM(); 40 | 41 | // AbsLifeHandler 42 | void launch(RunningAppPtr runningApp, LunaTaskPtr lunaTask) override; 43 | void pause(RunningAppPtr runningApp, LunaTaskPtr lunaTask) override; 44 | void close(RunningAppPtr runningApp, LunaTaskPtr lunaTask) override; 45 | void kill(RunningAppPtr runningApp) override; 46 | 47 | void killApp(RunningAppPtr runningApp, LunaTaskPtr lunaTask = nullptr); 48 | 49 | protected: 50 | // AbsLunaClient 51 | virtual void onInitialzed() override; 52 | virtual void onFinalized() override; 53 | virtual void onServerStatusChanged(bool isConnected) override; 54 | 55 | private: 56 | static const int CONTEXT_STOP = 0; 57 | static const int CONTEXT_RUNNING = 1; 58 | 59 | static bool onListRunningApps(LSHandle* sh, LSMessage* message, void* context); 60 | static bool onDiscardCodeCache(LSHandle* sh, LSMessage* message, void* context); 61 | static bool onLaunchApp(LSHandle* sh, LSMessage* message, void* context); 62 | static bool onPauseApp(LSHandle* sh, LSMessage* message, void* context); 63 | static bool onKillApp(LSHandle* sh, LSMessage* message, void* context); 64 | 65 | WAM(); 66 | 67 | Call m_listRunningAppsCall; 68 | Call m_discardCodeCacheCall; 69 | 70 | }; 71 | 72 | #endif /* BUS_CLIENT_WAM_H_ */ 73 | -------------------------------------------------------------------------------- /src/bus/service/ApplicationManager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_SERVICE_APPLICATIONMANAGER_H_ 18 | #define BUS_SERVICE_APPLICATIONMANAGER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "base/AppDescriptionList.h" 29 | #include "base/LunaTask.h" 30 | #include "base/LaunchPoint.h" 31 | #include "base/LaunchPointList.h" 32 | #include "base/RunningApp.h" 33 | #include "base/RunningAppList.h" 34 | #include "bus/service/compat/ApplicationManagerCompat.h" 35 | #include "conf/SAMConf.h" 36 | #include "interface/IClassName.h" 37 | #include "interface/ISingleton.h" 38 | #include "util/Logger.h" 39 | #include "util/File.h" 40 | 41 | using namespace LS; 42 | 43 | typedef boost::function LunaApiHandler; 44 | 45 | class ApplicationManager : public LS::Handle, 46 | public ISingleton, 47 | public IClassName { 48 | friend class ISingleton ; 49 | public: 50 | static const char* CATEGORY_ROOT; 51 | static const char* CATEGORY_DEV; 52 | 53 | static const char* METHOD_LAUNCH; 54 | static const char* METHOD_PAUSE; 55 | static const char* METHOD_CLOSE; 56 | static const char* METHOD_CLOSE_BY_APPID; 57 | static const char* METHOD_RUNNING; 58 | static const char* METHOD_GET_APP_LIFE_EVENTS; 59 | static const char* METHOD_GET_APP_LIFE_STATUS; 60 | static const char* METHOD_GET_FOREGROUND_APPINFO; 61 | static const char* METHOD_LOCK_APP; 62 | static const char* METHOD_REGISTER_APP; 63 | static const char* METHOD_REGISTER_NATIVE_APP; 64 | 65 | static const char* METHOD_LIST_APPS; 66 | static const char* METHOD_GET_APP_STATUS; 67 | static const char* METHOD_GET_APP_INFO; 68 | static const char* METHOD_GET_APP_BASE_PATH; 69 | 70 | static const char* METHOD_ADD_LAUNCHPOINT; 71 | static const char* METHOD_UPDATE_LAUNCHPOINT; 72 | static const char* METHOD_REMOVE_LAUNCHPOINT; 73 | static const char* METHOD_LIST_LAUNCHPOINTS; 74 | 75 | static const char* METHOD_MANAGER_INFO; 76 | 77 | virtual ~ApplicationManager(); 78 | 79 | virtual bool attach(GMainLoop* gml); 80 | virtual void detach(); 81 | 82 | // APIs 83 | void launch(LunaTaskPtr lunaTask); 84 | void pause(LunaTaskPtr lunaTask); 85 | void close(LunaTaskPtr lunaTask); 86 | void running(LunaTaskPtr lunaTask); 87 | void getAppLifeEvents(LunaTaskPtr lunaTask); 88 | void getAppLifeStatus(LunaTaskPtr lunaTask); 89 | void getForegroundAppInfo(LunaTaskPtr lunaTask); 90 | void lockApp(LunaTaskPtr lunaTask); 91 | void registerApp(LunaTaskPtr lunaTask); 92 | 93 | void listApps(LunaTaskPtr lunaTask); 94 | void getAppStatus(LunaTaskPtr lunaTask); 95 | void getAppInfo(LunaTaskPtr lunaTask); 96 | void getAppBasePath(LunaTaskPtr lunaTask); 97 | 98 | void addLaunchPoint(LunaTaskPtr lunaTask); 99 | void updateLaunchPoint(LunaTaskPtr lunaTask); 100 | void removeLaunchPoint(LunaTaskPtr lunaTask); 101 | void listLaunchPoints(LunaTaskPtr lunaTask); 102 | 103 | void managerInfo(LunaTaskPtr lunaTask); 104 | 105 | // Post 106 | void postGetAppLifeEvents(RunningApp& runningApp); 107 | void postGetAppLifeStatus(RunningApp& runningApp); 108 | void postGetAppStatus(AppDescriptionPtr appDesc, AppStatusEvent event); 109 | void postGetForegroundAppInfo(bool isOverlayEvent); 110 | void postListApps(AppDescriptionPtr appDesc, const string& change, const string& changeReason); 111 | void postListLaunchPoints(LaunchPointPtr launchPoint, string change); 112 | void postRunning(RunningAppPtr runningApp); 113 | 114 | // make 115 | void makeGetForegroundAppInfo(JValue& payload); 116 | void makeRunning(JValue& payload, bool isDevmode); 117 | 118 | void enablePosting() 119 | { 120 | if (m_enableSubscription) 121 | return; 122 | 123 | m_enableSubscription = true; 124 | postGetForegroundAppInfo(false); 125 | postRunning(nullptr); 126 | postListApps(nullptr, "", ""); 127 | postListLaunchPoints(nullptr, ""); 128 | } 129 | 130 | void disablePosting() 131 | { 132 | m_enableSubscription = false; 133 | } 134 | 135 | private: 136 | static bool onAPICalled(LSHandle* sh, LSMessage* message, void* context); 137 | 138 | ApplicationManager(); 139 | 140 | void registerApiHandler(const string& category, const string& method, LunaApiHandler handler) 141 | { 142 | string api = File::join(category, method); 143 | m_APIHandlers[api] = std::move(handler); 144 | } 145 | 146 | static LSMethod METHODS_ROOT[]; 147 | static LSMethod METHODS_DEV[]; 148 | 149 | map m_APIHandlers; 150 | 151 | LS::SubscriptionPoint* m_getAppLifeEvents; 152 | LS::SubscriptionPoint* m_getAppLifeStatus; 153 | LS::SubscriptionPoint* m_getForgroundAppInfo; 154 | LS::SubscriptionPoint* m_getForgroundAppInfoExtraInfo; 155 | LS::SubscriptionPoint* m_listLaunchPointsPoint; 156 | LS::SubscriptionPoint* m_listAppsPoint; 157 | LS::SubscriptionPoint* m_listAppsCompactPoint; 158 | LS::SubscriptionPoint* m_listDevAppsPoint; 159 | LS::SubscriptionPoint* m_listDevAppsCompactPoint; 160 | LS::SubscriptionPoint* m_running; 161 | LS::SubscriptionPoint* m_runningDev; 162 | 163 | bool m_enableSubscription; 164 | 165 | // TODO: Following should be deleted 166 | ApplicationManagerCompat m_compat1; 167 | ApplicationManagerCompat m_compat2; 168 | 169 | 170 | }; 171 | 172 | #endif 173 | -------------------------------------------------------------------------------- /src/bus/service/SchemaChecker.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "SchemaChecker.h" 18 | 19 | #include "ApplicationManager.h" 20 | #include "Environment.h" 21 | 22 | SchemaChecker::SchemaChecker() 23 | { 24 | m_APISchemaFiles[ApplicationManager::METHOD_LAUNCH] = "applicationManager.launch"; 25 | m_APISchemaFiles[ApplicationManager::METHOD_PAUSE] = ""; 26 | m_APISchemaFiles[ApplicationManager::METHOD_CLOSE] = ""; 27 | m_APISchemaFiles[ApplicationManager::METHOD_CLOSE_BY_APPID] = "applicationManager.closeByAppId"; 28 | m_APISchemaFiles[ApplicationManager::METHOD_RUNNING] = "applicationManager.running"; 29 | m_APISchemaFiles[ApplicationManager::METHOD_GET_APP_LIFE_EVENTS] = ""; 30 | m_APISchemaFiles[ApplicationManager::METHOD_GET_APP_LIFE_STATUS] = ""; 31 | m_APISchemaFiles[ApplicationManager::METHOD_GET_FOREGROUND_APPINFO] = "applicationManager.getForegroundAppInfo"; 32 | m_APISchemaFiles[ApplicationManager::METHOD_LOCK_APP] = "applicationManager.lockApp"; 33 | m_APISchemaFiles[ApplicationManager::METHOD_REGISTER_APP] = "applicationManager.registerApp"; 34 | m_APISchemaFiles[ApplicationManager::METHOD_LIST_APPS] = "applicationManager.listApps"; 35 | m_APISchemaFiles[ApplicationManager::METHOD_GET_APP_STATUS] = "applicationManager.getAppStatus"; 36 | m_APISchemaFiles[ApplicationManager::METHOD_GET_APP_INFO] = "applicationManager.getAppInfo"; 37 | m_APISchemaFiles[ApplicationManager::METHOD_GET_APP_BASE_PATH] = "applicationManager.getAppBasePath"; 38 | m_APISchemaFiles[ApplicationManager::METHOD_ADD_LAUNCHPOINT] = "applicationManager.addLaunchPoint"; 39 | m_APISchemaFiles[ApplicationManager::METHOD_UPDATE_LAUNCHPOINT] = "applicationManager.updateLaunchPoint"; 40 | m_APISchemaFiles[ApplicationManager::METHOD_REMOVE_LAUNCHPOINT] = "applicationManager.removeLaunchPoint"; 41 | m_APISchemaFiles[ApplicationManager::METHOD_LIST_LAUNCHPOINTS] = "applicationManager.listLaunchPoints"; 42 | } 43 | 44 | SchemaChecker::~SchemaChecker() 45 | { 46 | m_APISchemaFiles.clear(); 47 | } 48 | 49 | JValue SchemaChecker::getRequestPayloadWithSchema(Message& request) 50 | { 51 | string method = request.getMethod(); 52 | JValue requestPayload; 53 | if (m_APISchemaFiles.find(method) == m_APISchemaFiles.end() || m_APISchemaFiles[method].empty()) { 54 | requestPayload = JDomParser::fromString(request.getPayload()); 55 | return requestPayload; 56 | } 57 | 58 | string path = PATH_SAM_SCHEMAS + m_APISchemaFiles[method] + ".schema"; 59 | requestPayload = JDomParser::fromString(request.getPayload(), JSchema::fromFile(path.c_str())); 60 | return requestPayload; 61 | } 62 | -------------------------------------------------------------------------------- /src/bus/service/SchemaChecker.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_SERVICE_SCHEMACHECKER_H_ 18 | #define BUS_SERVICE_SCHEMACHECKER_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "interface/ISingleton.h" 26 | 27 | using namespace std; 28 | using namespace LS; 29 | using namespace pbnjson; 30 | 31 | class SchemaChecker : public ISingleton { 32 | friend class ISingleton; 33 | public: 34 | virtual ~SchemaChecker(); 35 | 36 | JValue getRequestPayloadWithSchema(Message& request); 37 | string getAPISchemaFilePath(const string& method); 38 | 39 | private: 40 | SchemaChecker(); 41 | 42 | map m_APISchemaFiles; 43 | }; 44 | 45 | #endif /* BUS_SERVICE_SCHEMACHECKER_H_ */ 46 | -------------------------------------------------------------------------------- /src/bus/service/compat/ApplicationManagerCompat.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef BUS_SERVICE_COMPAT_APPLICATIONMANAGERCOMPAT_H_ 18 | #define BUS_SERVICE_COMPAT_APPLICATIONMANAGERCOMPAT_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | using namespace std; 25 | using namespace LS; 26 | using namespace pbnjson; 27 | 28 | class ApplicationManagerCompat : public LS::Handle { 29 | public: 30 | ApplicationManagerCompat(string name) 31 | : LS::Handle(LS::registerService(name.c_str())) 32 | { 33 | 34 | } 35 | 36 | virtual ~ApplicationManagerCompat() 37 | { 38 | 39 | } 40 | }; 41 | 42 | #endif /* BUS_SERVICE_COMPAT_APPLICATIONMANAGERCOMPAT_H_ */ 43 | -------------------------------------------------------------------------------- /src/conf/.gitignore: -------------------------------------------------------------------------------- 1 | SettingsConf.h 2 | -------------------------------------------------------------------------------- /src/conf/RuntimeInfo.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "RuntimeInfo.h" 18 | 19 | #include 20 | 21 | RuntimeInfo::RuntimeInfo() 22 | : m_displayId(-1), 23 | m_isInContainer(false) 24 | { 25 | setClassName("RuntimeInfo"); 26 | } 27 | 28 | RuntimeInfo::~RuntimeInfo() 29 | { 30 | } 31 | 32 | void RuntimeInfo::initialize() 33 | { 34 | char* displayId = getenv("DISPLAY_ID"); 35 | char* deviceType = getenv("DEVICE_TYPE"); 36 | char* user = getenv("USER"); 37 | char* home = getenv("HOME"); 38 | char* container = getenv("container"); 39 | 40 | if (displayId != nullptr) { 41 | m_displayId = stoi(displayId); 42 | } 43 | if (deviceType != nullptr) { 44 | m_deviceType = deviceType; 45 | } 46 | if (user != nullptr) { 47 | m_user = user; 48 | } 49 | if (home != nullptr) { 50 | m_home = home; 51 | } 52 | if (container != nullptr) { 53 | m_isInContainer = true; 54 | } 55 | Logger::info(getClassName(), __FUNCTION__, 56 | Logger::format("DisplayId(%d) DeviceType(%s) IsInContainer(%s)", 57 | m_displayId, m_deviceType.c_str(), Logger::toString(m_isInContainer))); 58 | load(); 59 | } 60 | 61 | bool RuntimeInfo::getValue(const string& key, JValue& value) 62 | { 63 | if (!m_database.hasKey(key)) 64 | return false; 65 | value = m_database[key]; 66 | return true; 67 | } 68 | 69 | bool RuntimeInfo::setValue(const string& key, JValue& value) 70 | { 71 | if (!m_database.put(key, value.duplicate())) 72 | return false; 73 | return save(); 74 | } 75 | 76 | bool RuntimeInfo::save() 77 | { 78 | if (!File::writeFile(PATH_RUNTIME_INFO, m_database.stringify(" "))) { 79 | Logger::warning(getClassName(), __FUNCTION__, PATH_RUNTIME_INFO, "Failed to save RuntimeInfo"); 80 | return false; 81 | } 82 | return true; 83 | } 84 | 85 | bool RuntimeInfo::load() 86 | { 87 | m_database = JDomParser::fromFile(PATH_RUNTIME_INFO); 88 | if (m_database.isNull()) { 89 | m_database = pbnjson::Object(); 90 | save(); 91 | } 92 | return true; 93 | } 94 | -------------------------------------------------------------------------------- /src/conf/RuntimeInfo.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef CONF_RUNTIMEINFO_H_ 18 | #define CONF_RUNTIMEINFO_H_ 19 | 20 | #include 21 | 22 | #include 23 | 24 | #include "Environment.h" 25 | #include "interface/IClassName.h" 26 | #include "interface/ISingleton.h" 27 | #include "util/JValueUtil.h" 28 | #include "util/Logger.h" 29 | #include "util/File.h" 30 | 31 | using namespace std; 32 | using namespace pbnjson; 33 | 34 | class RuntimeInfo : public ISingleton, 35 | public IClassName { 36 | friend class ISingleton ; 37 | public: 38 | virtual ~RuntimeInfo(); 39 | 40 | void initialize(); 41 | 42 | bool getValue(const string& key, JValue& value); 43 | bool setValue(const string& key, JValue& value); 44 | 45 | int getDisplayId() 46 | { 47 | return m_displayId; 48 | } 49 | 50 | const string& getDeviceType() 51 | { 52 | return m_deviceType; 53 | } 54 | 55 | const string& getUser() 56 | { 57 | return m_user; 58 | } 59 | 60 | const string& getHome() 61 | { 62 | return m_home; 63 | } 64 | 65 | bool isInContainer() 66 | { 67 | return m_isInContainer; 68 | } 69 | 70 | private: 71 | RuntimeInfo(); 72 | 73 | bool save(); 74 | bool load(); 75 | 76 | JValue m_database; 77 | 78 | int m_displayId; 79 | string m_deviceType; 80 | string m_user; 81 | string m_home; 82 | bool m_isInContainer; 83 | 84 | }; 85 | 86 | #endif /* CONF_RUNTIMEINFO_H_ */ 87 | -------------------------------------------------------------------------------- /src/conf/SAMConf.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "SAMConf.h" 18 | 19 | #include "RuntimeInfo.h" 20 | 21 | SAMConf::SAMConf() 22 | : m_isRespawned(false), 23 | m_isDevmodeEnabled(false), 24 | m_isJailerDisabled(true) 25 | { 26 | setClassName("Settings"); 27 | } 28 | 29 | SAMConf::~SAMConf() 30 | { 31 | } 32 | 33 | void SAMConf::initialize() 34 | { 35 | loadReadOnlyConf(); 36 | loadReadWriteConf(); 37 | loadBlockedList(); 38 | 39 | // TODO this should be moved in RuntimeInfo 40 | m_isRespawned = File::isFile(this->getRespawnedPath()); 41 | 42 | if (File::isFile(this->getDevModePath())) 43 | m_isDevmodeEnabled = true; 44 | 45 | if (File::isFile(this->getJailModePath())) 46 | m_isJailerDisabled = true; 47 | 48 | if (!m_isRespawned) { 49 | if (!File::createFile(this->getRespawnedPath())) { 50 | Logger::info(getClassName(), __FUNCTION__, "Failed to create respawned file"); 51 | } 52 | } 53 | 54 | Logger::info(getClassName(), __FUNCTION__, 55 | Logger::format("isDevmodeEnabled(%s) isRespawned(%s) isJailerDisabled(%s)", 56 | Logger::toString(m_isDevmodeEnabled), Logger::toString(m_isRespawned), Logger::toString(m_isJailerDisabled))); 57 | } 58 | 59 | void SAMConf::loadReadOnlyConf() 60 | { 61 | m_readOnlyDatabase = JDomParser::fromFile(PATH_RO_SAM_CONF, JValueUtil::getSchema("sam-conf")); 62 | if (m_readOnlyDatabase.isNull()) { 63 | Logger::warning(getClassName(), __FUNCTION__, PATH_RO_SAM_CONF, "Failed to parse read-only sam-conf"); 64 | } 65 | } 66 | 67 | void SAMConf::loadReadWriteConf() 68 | { 69 | string path = ""; 70 | 71 | if (!RuntimeInfo::getInstance().getHome().empty()) { 72 | path = RuntimeInfo::getInstance().getHome() + "/.config"; 73 | File::makeDirectory(path); 74 | path += "/sam-conf.json"; 75 | } else { 76 | path = PATH_RW_SAM_CONF; 77 | } 78 | m_readWriteDatabase = JDomParser::fromFile(path.c_str()); 79 | if (m_readWriteDatabase.isNull()) { 80 | m_readWriteDatabase = pbnjson::Object(); 81 | saveReadWriteConf(); 82 | } 83 | } 84 | 85 | void SAMConf::saveReadWriteConf() 86 | { 87 | string path = ""; 88 | 89 | if (!RuntimeInfo::getInstance().getHome().empty()) { 90 | path = RuntimeInfo::getInstance().getHome() + "/.config/sam-conf.json"; 91 | } else { 92 | path = PATH_RW_SAM_CONF; 93 | } 94 | 95 | if (!File::writeFile(path, m_readWriteDatabase.stringify(" ").c_str())) { 96 | Logger::warning(getClassName(), __FUNCTION__, PATH_RO_SAM_CONF, "Failed to save read-write sam-conf"); 97 | } 98 | } 99 | 100 | void SAMConf::loadBlockedList() 101 | { 102 | m_blockedListDatabase = JDomParser::fromFile(PATH_BLOCKED_LIST); 103 | if (m_blockedListDatabase.isNull()) { 104 | Logger::warning(getClassName(), __FUNCTION__, PATH_RO_SAM_CONF, "Failed to parse blocked-file sam-conf"); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/interface/IClassName.h: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2024 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #ifndef INTERFACE_ICLASSNAME_H_ 15 | #define INTERFACE_ICLASSNAME_H_ 16 | 17 | #include 18 | #include 19 | 20 | using namespace std; 21 | 22 | class IClassName { 23 | public: 24 | IClassName() : m_name("Unknown") {}; 25 | virtual ~IClassName() {}; 26 | 27 | string& getClassName() 28 | { 29 | return m_name; 30 | } 31 | 32 | void setClassName(string name) 33 | { 34 | m_name = std::move(name); 35 | } 36 | 37 | private: 38 | string m_name; 39 | 40 | }; 41 | 42 | #endif /* INTERFACE_ICLASSNAME_H_ */ 43 | -------------------------------------------------------------------------------- /src/interface/IInitializable.h: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2019 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #ifndef INTERFACE_IINITIALIZABLE_H_ 15 | #define INTERFACE_IINITIALIZABLE_H_ 16 | 17 | #include 18 | #include 19 | 20 | #include "IClassName.h" 21 | #include "util/Logger.h" 22 | 23 | using namespace std; 24 | 25 | class IInitializable : public IClassName { 26 | public: 27 | virtual ~IInitializable() {}; 28 | 29 | virtual bool initialize(GMainLoop* mainloop) final 30 | { 31 | Logger::info(getClassName(), "Start initialization"); 32 | m_mainloop = mainloop; 33 | m_isInitalized = onInitialization(); 34 | Logger::info(getClassName(), "End initialization"); 35 | return m_isInitalized; 36 | } 37 | 38 | virtual bool finalize() final 39 | { 40 | Logger::info(getClassName(), "Start finalization"); 41 | m_isFinalized = onFinalization(); 42 | Logger::info(getClassName(), "End finalization"); 43 | return m_isFinalized; 44 | } 45 | 46 | virtual bool isReady() 47 | { 48 | return m_isReady; 49 | } 50 | 51 | virtual bool isInitalized() 52 | { 53 | return m_isInitalized; 54 | } 55 | 56 | virtual bool isFinalized() 57 | { 58 | return m_isFinalized; 59 | } 60 | 61 | virtual bool onInitialization() = 0; 62 | virtual bool onFinalization() = 0; 63 | 64 | protected: 65 | IInitializable() 66 | : m_mainloop(nullptr) 67 | , m_isReady(false) 68 | , m_isInitalized(false) 69 | , m_isFinalized(false) 70 | { 71 | }; 72 | 73 | void ready() 74 | { 75 | Logger::info(getClassName(), "Ready"); 76 | m_isReady = true; 77 | } 78 | 79 | GMainLoop* m_mainloop; 80 | 81 | private: 82 | bool m_isReady; 83 | bool m_isInitalized; 84 | bool m_isFinalized; 85 | 86 | }; 87 | 88 | 89 | #endif /* INTERFACE_IINITIALIZABLE_H_ */ 90 | -------------------------------------------------------------------------------- /src/interface/ISerializable.h: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2019 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #ifndef INTERFACE_ISERIALIZABLE_H_ 15 | #define INTERFACE_ISERIALIZABLE_H_ 16 | 17 | #include 18 | 19 | using namespace pbnjson; 20 | 21 | class ISerializable { 22 | public: 23 | ISerializable() {}; 24 | virtual ~ISerializable() {}; 25 | 26 | virtual bool fromJson(const JValue& json) 27 | { 28 | m_json = json.duplicate(); 29 | return true; 30 | } 31 | 32 | virtual bool toJson(JValue& json) 33 | { 34 | json = m_json.duplicate(); 35 | return true; 36 | } 37 | 38 | JValue& getJson() 39 | { 40 | return m_json; 41 | } 42 | 43 | private: 44 | JValue m_json; 45 | 46 | }; 47 | 48 | #endif /* INTERFACE_ISERIALIZABLE_H_ */ 49 | -------------------------------------------------------------------------------- /src/interface/ISingleton.h: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2019 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #ifndef INTERFACE_ISINGLETON_H_ 15 | #define INTERFACE_ISINGLETON_H_ 16 | 17 | #include 18 | 19 | using namespace std; 20 | 21 | template 22 | class ISingleton { 23 | public: 24 | virtual ~ISingleton() {}; 25 | 26 | static T& getInstance() 27 | { 28 | static T _instance; 29 | return _instance; 30 | } 31 | 32 | protected: 33 | ISingleton() {}; 34 | 35 | }; 36 | 37 | #endif /* INTERFACE_ISINGLETON_H_ */ 38 | -------------------------------------------------------------------------------- /src/manager/PolicyManager.h: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2024 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #ifndef MANAGER_POLICYMANAGER_H_ 15 | #define MANAGER_POLICYMANAGER_H_ 16 | 17 | #include 18 | #include 19 | 20 | #include "base/AppDescription.h" 21 | #include "base/AppDescriptionList.h" 22 | #include "base/LaunchPoint.h" 23 | #include "base/LaunchPointList.h" 24 | #include "base/LunaTask.h" 25 | #include "base/LunaTaskList.h" 26 | #include "base/RunningApp.h" 27 | #include "base/RunningAppList.h" 28 | #include "interface/ISingleton.h" 29 | #include "interface/IClassName.h" 30 | 31 | using namespace std; 32 | 33 | class PolicyManager : public ISingleton, 34 | public IClassName { 35 | friend class ISingleton ; 36 | public: 37 | virtual ~PolicyManager(); 38 | 39 | void launch(LunaTaskPtr lunaTask); 40 | void pause(LunaTaskPtr lunaTask); 41 | void close(LunaTaskPtr lunaTask); 42 | void relaunch(LunaTaskPtr lunaTask); 43 | 44 | void removeLaunchPoint(LunaTaskPtr lunaTask); 45 | 46 | private: 47 | PolicyManager(); 48 | 49 | void onRequireMemory(LunaTaskPtr lunaTask); 50 | void onCloseForRemove(LunaTaskPtr lunaTask); 51 | 52 | void pre(LunaTaskPtr lunaTask); 53 | void onReplyWithIds(LunaTaskPtr lunaTask); 54 | void onReplyWithoutIds(LunaTaskPtr lunaTask); 55 | }; 56 | 57 | #endif /* MANAGER_POLICYMANAGER_H_ */ 58 | -------------------------------------------------------------------------------- /src/util/File.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2025 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "File.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | void File::set_slash_to_base_path(string& path) 25 | { 26 | if (!path.empty() && path[path.length() - 1] == '/') 27 | return; 28 | 29 | path.append("/"); 30 | } 31 | 32 | string File::readFile(const string& file_name) 33 | { 34 | ifstream file(file_name.c_str(), ifstream::in); 35 | string file_contents; 36 | 37 | if (file.is_open() && file.good()) { 38 | stringstream buf; 39 | buf << file.rdbuf(); 40 | file_contents = buf.str(); 41 | } 42 | 43 | return file_contents; 44 | } 45 | 46 | bool File::writeFile(const string &path, const string& buffer) 47 | { 48 | ofstream file(path.c_str()); 49 | if (file.is_open()) { 50 | file << buffer; 51 | file.close(); 52 | } else { 53 | return false; 54 | } 55 | return true; 56 | } 57 | 58 | bool File::concatToFilename(const string originPath, string& returnPath, const string addingStr) 59 | { 60 | if (originPath.empty() || addingStr.empty()) 61 | return false; 62 | 63 | returnPath = ""; 64 | 65 | string dir_path, filename, name_only, ext; 66 | size_t pos_dir = originPath.find_last_of("/"); 67 | 68 | if (string::npos == pos_dir) { 69 | filename = std::move(originPath); 70 | } else { 71 | pos_dir = pos_dir + 1; 72 | dir_path = originPath.substr(0, pos_dir); 73 | filename = originPath.substr(pos_dir); 74 | } 75 | 76 | size_t pos_ext = filename.find_last_of("."); 77 | 78 | if (string::npos == pos_ext) 79 | return false; 80 | 81 | name_only = filename.substr(0, pos_ext); 82 | ext = filename.substr(pos_ext); 83 | 84 | if (ext.length() < 2) 85 | return false; 86 | 87 | returnPath = dir_path + name_only + addingStr + ext; 88 | 89 | return true; 90 | } 91 | 92 | bool File::isDirectory(const string& path) 93 | { 94 | struct stat dirStat; 95 | if (stat(path.c_str(), &dirStat) != 0) { 96 | return false; 97 | } 98 | if ((dirStat.st_mode & S_IFDIR) == 0) { 99 | return false; 100 | } 101 | return true; 102 | } 103 | 104 | bool File::isFile(const string& path) 105 | { 106 | struct stat fileStat; 107 | 108 | if (stat(path.c_str(), &fileStat) != 0 || (fileStat.st_mode & S_IFREG) == 0) { 109 | return false; 110 | } 111 | return true; 112 | } 113 | 114 | bool File::makeDirectory(const string& path) 115 | { 116 | if (g_mkdir_with_parents(path.c_str(), 0700) == 0) 117 | return true; 118 | return false; 119 | } 120 | 121 | bool File::createFile(const string& path) 122 | { 123 | return File::writeFile(path, ""); 124 | } 125 | 126 | bool File::deleteFile(const string& path) 127 | { 128 | if(unlink(path.c_str()) == -1) { 129 | return false; 130 | } 131 | return true; 132 | } 133 | 134 | string File::join(const string& a, const string& b) 135 | { 136 | string path = ""; 137 | 138 | if (!a.empty() && a.back() == '/') { 139 | if (!b.empty() && b.front() == '/') { 140 | path = a + b.substr(1); 141 | } 142 | else { 143 | path = a + b; 144 | } 145 | } else { 146 | if (!b.empty() && b.front() == '/') { 147 | path = a + b; 148 | } 149 | else { 150 | path = a + "/" + b; 151 | } 152 | } 153 | return path; 154 | } 155 | 156 | File::File() 157 | { 158 | } 159 | 160 | File::~File() 161 | { 162 | } 163 | -------------------------------------------------------------------------------- /src/util/File.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2025 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef UTIL_FILE_H_ 18 | #define UTIL_FILE_H_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | using namespace std; 28 | 29 | class File { 30 | public: 31 | static void set_slash_to_base_path(string& path); 32 | static string readFile(const string& file_name); 33 | static bool writeFile(const string& filePath, const string& buffer); 34 | static bool concatToFilename(const string originPath, string& returnPath, const string addingStr); 35 | 36 | static bool isDirectory(const string& path); 37 | static bool isFile(const string& path); 38 | static bool makeDirectory(const string& path); 39 | static bool createFile(const string& path); 40 | static bool deleteFile(const string& path); 41 | 42 | static string join(const string& a, const string& b); 43 | 44 | static void trimPath(string &path) 45 | { 46 | if (!path.empty() && path.back() == '/') 47 | path.erase(prev(path.end())); 48 | } 49 | 50 | File(); 51 | virtual ~File(); 52 | 53 | }; 54 | 55 | #endif /* UTIL_FILE_H_ */ 56 | -------------------------------------------------------------------------------- /src/util/JValueUtil.cpp: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2019 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #include "util/JValueUtil.h" 15 | #include "Environment.h" 16 | 17 | map JValueUtil::s_schemas; 18 | 19 | void JValueUtil::addUniqueItemToArray(pbnjson::JValue& array, string& item) 20 | { 21 | if (array.isNull() || !array.isArray() || item.empty()) 22 | return; 23 | 24 | for (int i = 0; i < array.arraySize(); ++i) { 25 | if (array[i].isString() && 0 == item.compare(array[i].asString())) 26 | return; 27 | } 28 | 29 | array.append(item); 30 | } 31 | 32 | JSchema JValueUtil::getSchema(string name) 33 | { 34 | if (name.empty()) 35 | return JSchema::AllSchema(); 36 | 37 | auto it = s_schemas.find(name); 38 | if (it != s_schemas.end()) 39 | return it->second; 40 | 41 | string path = PATH_SAM_SCHEMAS + name + ".schema"; 42 | pbnjson::JSchema schema = JSchema::fromFile(path.c_str()); 43 | if (!schema.isInitialized()) 44 | return JSchema::AllSchema(); 45 | 46 | s_schemas.insert(pair(name, schema)); 47 | return schema; 48 | } 49 | 50 | bool JValueUtil::convertValue(const JValue& json, JValue& value) 51 | { 52 | value = json; 53 | return true; 54 | } 55 | 56 | bool JValueUtil::convertValue(const JValue& json, string& value) 57 | { 58 | if (!json.isString()) 59 | return false; 60 | if (json.asString(value) != CONV_OK) { 61 | value = ""; 62 | return false; 63 | } 64 | return true; 65 | } 66 | 67 | bool JValueUtil::convertValue(const JValue& json, int& value) 68 | { 69 | if (!json.isNumber()) 70 | return false; 71 | if (json.asNumber(value) != CONV_OK) { 72 | value = 0; 73 | return false; 74 | } 75 | return true; 76 | } 77 | 78 | bool JValueUtil::convertValue(const JValue& json, bool& value) 79 | { 80 | if (!json.isBoolean()) 81 | return false; 82 | if (json.asBool(value) != CONV_OK) { 83 | value = false; 84 | return false; 85 | } 86 | return true; 87 | } 88 | -------------------------------------------------------------------------------- /src/util/JValueUtil.h: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2019 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #ifndef UTIL_JVALUEUTIL_H_ 15 | #define UTIL_JVALUEUTIL_H_ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | using namespace std; 22 | using namespace pbnjson; 23 | 24 | class JValueUtil { 25 | public: 26 | JValueUtil() {} 27 | virtual ~JValueUtil() {} 28 | 29 | static void addUniqueItemToArray(JValue& arr, string& str); 30 | static JSchema getSchema(string name); 31 | 32 | template 33 | static bool getValue(const JValue& json, const string& key, T& value) { 34 | if (!json) 35 | return false; 36 | if (!json.hasKey(key)) 37 | return false; 38 | return convertValue(json[key], value); 39 | } 40 | 41 | template 42 | static bool getValue(const JValue& json, const string& key, const string& nextKey, Args& ...rest) { 43 | if (!json) 44 | return false; 45 | if (!json.hasKey(key)) 46 | return false; 47 | if (!json[key].isObject()) 48 | return false; 49 | return getValue(json[key], nextKey, rest...); 50 | } 51 | 52 | template 53 | static bool hasKey(const JValue& json, Args ...rest) { 54 | JValue value; 55 | return getValue(json, rest..., value); 56 | } 57 | 58 | private: 59 | static bool convertValue(const JValue& json, JValue& value); 60 | static bool convertValue(const JValue& json, string& value); 61 | static bool convertValue(const JValue& json, int& value); 62 | static bool convertValue(const JValue& json, bool& value); 63 | 64 | private: 65 | static map s_schemas; 66 | }; 67 | 68 | #endif /* UTIL_JVALUEUTIL_H_ */ 69 | -------------------------------------------------------------------------------- /src/util/Logger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef UTIL_LOGGER_H_ 18 | #define UTIL_LOGGER_H_ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | using namespace LS; 28 | using namespace pbnjson; 29 | 30 | enum ErrCode { 31 | ErrCode_NOERROR = 0, 32 | ErrCode_UNKNOWN = 1, 33 | ErrCode_GENERAL = 2, 34 | ErrCode_INVALID_PAYLOAD = 3, 35 | ErrCode_LAUNCH = 10, 36 | ErrCode_LAUNCH_APP_LOCKED = 11, 37 | ErrCode_RELAUNCH = 20, 38 | ErrCode_PAUSE = 30, 39 | ErrCode_CLOSE = 40, 40 | ErrCode_DEPRECATED = 999 41 | }; 42 | 43 | enum LogLevel { 44 | LogLevel_DEBUG, 45 | LogLevel_INFO, 46 | LogLevel_WARNING, 47 | LogLevel_ERROR, 48 | }; 49 | 50 | enum LogType { 51 | LogType_CONSOLE, 52 | LogType_PMLOG 53 | }; 54 | 55 | class Logger { 56 | public: 57 | template 58 | static const string format(const string& format, Args ... args) 59 | { 60 | static char buffer[1024]; 61 | snprintf(buffer, 1024, format.c_str(), args ... ); 62 | return string(buffer); 63 | } 64 | 65 | static const char* toString(bool BOOL) 66 | { 67 | static const char* TStr = "true"; 68 | static const char* FStr = "false"; 69 | 70 | if (BOOL) 71 | return TStr; 72 | else 73 | return FStr; 74 | } 75 | 76 | static bool isVerbose() 77 | { 78 | return s_isVerbose; 79 | } 80 | 81 | static void logAPIRequest(const string& className, const string& functionName, Message& request, JValue& requestPayload); 82 | static void logAPIResponse(const string& className, const string& functionName, Message& request, JValue& responsePayload); 83 | 84 | static void logCallRequest(const string& className, const string& functionName, const string& method, JValue& requestPayload); 85 | static void logCallResponse(const string& className, const string& functionName, Message& response, JValue& responsePayload); 86 | 87 | static void logSubscriptionRequest(const string& className, const string& functionName, const string& method, JValue& requestPayload); 88 | static void logSubscriptionResponse(const string& className, const string& functionName, Message& response, JValue& subscriptionPayload); 89 | static void logSubscriptionPost(const string& className, const string& functionName, const LS::SubscriptionPoint& point, JValue& subscriptionPayload); 90 | static void logSubscriptionPost(const string& className, const string& functionName, const string& key, JValue& subscriptionPayload); 91 | 92 | static void debug(const string& className, const string& functionName, const string& what); 93 | static void info(const string& className, const string& functionName, const string& what); 94 | static void warning(const string& className, const string& functionName, const string& what); 95 | static void error(const string& className, const string& functionName, const string& what); 96 | 97 | static void debug(const string& className, const string& functionName, const string& who, const string& what, const string& detail = EMPTY); 98 | static void info(const string& className, const string& functionName, const string& who, const string& what, const string& detail = EMPTY); 99 | static void warning(const string& className, const string& functionName, const string& who, const string& what, const string& detail = EMPTY); 100 | static void error(const string& className, const string& functionName, const string& who, const string& what, const string& detail = EMPTY); 101 | 102 | virtual ~Logger(); 103 | 104 | static Logger& getInstance() 105 | { 106 | static Logger _instance; 107 | return _instance; 108 | } 109 | 110 | void setLevel(enum LogLevel level); 111 | void setType(enum LogType type); 112 | 113 | private: 114 | static const string EMPTY; 115 | static bool s_isVerbose; 116 | 117 | static const string& toString(const enum LogLevel& level); 118 | 119 | Logger(); 120 | 121 | void write(const enum LogLevel& level, const string& className, const string& functionName, const string& who, const string& what, const string& detail); 122 | void writeConsole(const enum LogLevel& level, const string& className, const string& functionName, const string& who, const string& what, const string& detail); 123 | void writePmlog(const enum LogLevel& level, const string& className, const string& functionName, const string& who, const string& what, const string& detail); 124 | 125 | enum LogLevel m_level; 126 | enum LogType m_type; 127 | }; 128 | 129 | #endif /* UTIL_LOGGER_H_ */ 130 | -------------------------------------------------------------------------------- /src/util/NativeProcess.cpp: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2020-2025 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "util/NativeProcess.h" 20 | #include "util/Logger.h" 21 | 22 | const string NativeProcess::CLASS_NAME = "NativeProcess"; 23 | 24 | void NativeProcess::convertEnvToStr(map& src, vector& dest) 25 | { 26 | for (auto it = src.begin(); it != src.end(); ++it) { 27 | dest.push_back(it->first + "=" + it->second); 28 | } 29 | } 30 | 31 | void NativeProcess::prepareSpawn(gpointer user_data) 32 | { 33 | // This function is called in child context. 34 | // setpgid is needed to kill all processes which are created by application at once 35 | int result = setpgid(getpid(), 0); 36 | if (result == -1) { 37 | Logger::error(CLASS_NAME, __FUNCTION__, strerror(errno)); 38 | } 39 | } 40 | 41 | NativeProcess::NativeProcess() 42 | : m_workingDirectory("/"), 43 | m_command(""), 44 | m_pid(-1), 45 | m_stdFd(-1), 46 | m_isTracked(false) 47 | { 48 | 49 | } 50 | 51 | NativeProcess::~NativeProcess() 52 | { 53 | 54 | } 55 | 56 | void NativeProcess::addArgument(const string& argument) 57 | { 58 | m_arguments.push_back(argument); 59 | } 60 | 61 | void NativeProcess::addArgument(const string& option, const string& value) 62 | { 63 | m_arguments.push_back(option); 64 | m_arguments.push_back(value); 65 | } 66 | 67 | void NativeProcess::addEnv(map& environments) 68 | { 69 | for (auto it = environments.begin(); it != environments.end(); ++it) { 70 | m_environments[it->first] = it->second; 71 | } 72 | } 73 | 74 | void NativeProcess::addEnv(const string& variable, const string& value) 75 | { 76 | m_environments[variable] = value; 77 | } 78 | 79 | void NativeProcess::openStdFile(const string& stdFile) 80 | { 81 | closeStdFd(); 82 | m_stdFile = stdFile; 83 | m_stdFd = ::open(stdFile.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0644); 84 | } 85 | 86 | void NativeProcess::closeStdFd() 87 | { 88 | if (m_stdFd >= 0) 89 | close(m_stdFd); 90 | } 91 | 92 | bool NativeProcess::run() 93 | { 94 | char* argv[MAX_ARGS] = { 0, }; 95 | char* envp[MAX_ENVP] = { 0, }; 96 | string params = ""; 97 | unsigned int index = 0; 98 | 99 | GError* gerr = NULL; 100 | argv[0] = strdup(m_command.c_str()); 101 | index = 1; 102 | for (auto it = m_arguments.begin(); it != m_arguments.end() && index < MAX_ARGS; ++it) { 103 | params += *it + " "; 104 | argv[index++] = strdup(it->c_str()); 105 | } 106 | 107 | vector finalEnvironments; 108 | convertEnvToStr(m_environments, finalEnvironments); 109 | index = 0; 110 | for (auto it = finalEnvironments.begin(); it != finalEnvironments.end() && index < MAX_ENVP; ++it) { 111 | envp[index++] = strdup(it->c_str()); 112 | } 113 | 114 | Logger::info(CLASS_NAME, __FUNCTION__, m_command, params); 115 | gboolean result = g_spawn_async_with_fds( 116 | m_workingDirectory.c_str(), 117 | argv, 118 | envp, 119 | G_SPAWN_DO_NOT_REAP_CHILD, 120 | prepareSpawn, 121 | this, 122 | &m_pid, 123 | -1, 124 | m_stdFd, 125 | m_stdFd, 126 | &gerr 127 | ); 128 | if (gerr) { 129 | Logger::error(CLASS_NAME, __FUNCTION__, gerr->message); 130 | g_error_free(gerr); 131 | gerr = NULL; 132 | return false; 133 | } 134 | if (!result || m_pid <= 0) { 135 | Logger::error(CLASS_NAME, __FUNCTION__, "Failed to folk child process"); 136 | return false; 137 | } 138 | return true; 139 | } 140 | 141 | bool NativeProcess::term() 142 | { 143 | if (m_pid <= 0) { 144 | Logger::error(CLASS_NAME, __FUNCTION__, "Process is not running"); 145 | return false; 146 | } 147 | int result = killpg(m_pid, SIGTERM); 148 | if (result == -1) { 149 | Logger::error(CLASS_NAME, __FUNCTION__, strerror(errno)); 150 | return false; 151 | } 152 | return true; 153 | } 154 | 155 | bool NativeProcess::kill() 156 | { 157 | if (m_pid <= 0) { 158 | Logger::error(CLASS_NAME, __FUNCTION__, "Process is not running"); 159 | return false; 160 | } 161 | int result = killpg(m_pid, SIGKILL); 162 | if (result == -1) { 163 | Logger::error(CLASS_NAME, __FUNCTION__, strerror(errno)); 164 | return false; 165 | } 166 | return true; 167 | } 168 | -------------------------------------------------------------------------------- /src/util/NativeProcess.h: -------------------------------------------------------------------------------- 1 | /* @@@LICENSE 2 | * 3 | * Copyright (c) 2020 LG Electronics, Inc. 4 | * 5 | * Confidential computer software. Valid license from LG required for 6 | * possession, use or copying. Consistent with FAR 12.211 and 12.212, 7 | * Commercial Computer Software, Computer Software Documentation, and 8 | * Technical Data for Commercial Items are licensed to the U.S. Government 9 | * under vendor's standard commercial license. 10 | * 11 | * LICENSE@@@ 12 | */ 13 | 14 | #ifndef UTIL_NATIVEPROCESS_H_ 15 | #define UTIL_NATIVEPROCESS_H_ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "File.h" 23 | 24 | using namespace std; 25 | 26 | class NativeProcess { 27 | public: 28 | NativeProcess(); 29 | virtual ~NativeProcess(); 30 | 31 | void setWorkingDirectory(const string& directory) 32 | { 33 | m_workingDirectory = directory; 34 | } 35 | 36 | void setCommand(const string& command) 37 | { 38 | m_command = command; 39 | } 40 | const string& getCommand() 41 | { 42 | return m_command; 43 | } 44 | 45 | void addArgument(const string& argument); 46 | void addArgument(const string& option, const string& value); 47 | void addEnv(map& environments); 48 | void addEnv(const string& variable, const string& value); 49 | 50 | pid_t getPid() const 51 | { 52 | return m_pid; 53 | } 54 | void setPid(pid_t pid) 55 | { 56 | m_pid = pid; 57 | } 58 | 59 | void openStdFile(const string& stdFile); 60 | const string& getStdFile() 61 | { 62 | return m_stdFile; 63 | } 64 | 65 | void closeStdFd(); 66 | 67 | bool run(); 68 | bool term(); 69 | bool kill(); 70 | 71 | void track() 72 | { 73 | m_isTracked = true; 74 | } 75 | 76 | bool isTracked() 77 | { 78 | return m_isTracked; 79 | } 80 | 81 | bool isRunning() 82 | { 83 | return File::isDirectory("/proc/" + std::to_string(m_pid)); 84 | } 85 | 86 | private: 87 | static const string CLASS_NAME; 88 | static const int MAX_ARGS = 16; 89 | static const int MAX_ENVP = 128; 90 | 91 | static void convertEnvToStr(map& src, vector& dest); 92 | static void prepareSpawn(gpointer user_data); 93 | 94 | string m_workingDirectory; 95 | string m_command; 96 | 97 | vector m_arguments; 98 | map m_environments; 99 | 100 | pid_t m_pid; 101 | string m_stdFile; 102 | gint m_stdFd; 103 | 104 | bool m_isTracked; 105 | 106 | }; 107 | 108 | #endif /* UTIL_NATIVEPROCESS_H_ */ 109 | -------------------------------------------------------------------------------- /src/util/Time.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #include "Time.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | Time::Time() 25 | { 26 | } 27 | 28 | Time::~Time() 29 | { 30 | } 31 | 32 | long long Time::getCurrentTime() 33 | { 34 | timespec now; 35 | if (clock_gettime(CLOCK_MONOTONIC, &now) == -1) 36 | return -1; 37 | return (now.tv_sec * 1000) + (now.tv_nsec / 1000000); 38 | } 39 | 40 | string Time::generateUid() 41 | { 42 | boost::uuids::uuid uid = boost::uuids::random_generator()(); 43 | return string(boost::lexical_cast(uid)); 44 | } 45 | -------------------------------------------------------------------------------- /src/util/Time.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2019-2020 LG Electronics, Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | // 15 | // SPDX-License-Identifier: Apache-2.0 16 | 17 | #ifndef UTIL_TIME_H_ 18 | #define UTIL_TIME_H_ 19 | 20 | #include 21 | 22 | using namespace std; 23 | 24 | class Time { 25 | public: 26 | static long long getCurrentTime(); 27 | static string generateUid(); 28 | 29 | Time(); 30 | virtual ~Time(); 31 | }; 32 | 33 | #endif /* UTIL_TIME_H_ */ 34 | --------------------------------------------------------------------------------