Add preferences/settings management script 26/106826/3
authorSeok Hong <seok85.hong@samsung.com>
Fri, 23 Dec 2016 07:21:15 +0000 (16:21 +0900)
committerJaemin Ryu <jm77.ryu@samsung.com>
Mon, 26 Dec 2016 00:24:24 +0000 (09:24 +0900)
Change-Id: Idf6adb04b376a454fc965c135e4dcefadd329342
Signed-off-by: Seok Hong <seok85.hong@samsung.com>
Signed-off-by: Jaemin Ryu <jm77.ryu@samsung.com>
packaging/device-policy-manager.spec
tools/cli/CMakeLists.txt
tools/cli/dpm-preference [new file with mode: 0755]

index c9e3dbb..6a23b6c 100755 (executable)
@@ -56,6 +56,7 @@ managing device policies.
 %attr(755,root,root) %{_bindir}/device-policy-manager
 %attr(700,root,root) %{_bindir}/dpm-admin-cli
 %attr(755,root,root) %{_bindir}/dpm-syspopup
+%attr(755,root,root) %{_bindir}/dpm-preference
 %{_unitdir}/device-policy-manager.service
 %{_unitdir}/multi-user.target.wants/device-policy-manager.service
 
index 17c9f29..6c40d16 100644 (file)
@@ -14,7 +14,8 @@
 # limitations under the License.
 #
 SET(DPM_ADMIN_CLI_TARGET       "dpm-admin-cli")
-SET(DPM_SYSPOPUP_TARGET        "dpm-syspopup")
+SET(DPM_SYSPOPUP_TARGET                "dpm-syspopup")
+SET(DPM_PREFERENCE_TARGET      "dpm-preference")
 
 SET(DPM_ADMIN_CLI_SOURCES dpm-admin-cli.cpp)
 
@@ -24,5 +25,6 @@ INCLUDE_DIRECTORIES(SYSTEM ${DPM_LIBS})
 
 TARGET_LINK_LIBRARIES(${DPM_ADMIN_CLI_TARGET} dpm)
 
+INSTALL(FILES ${DPM_PREFERENCE_TARGET} DESTINATION bin)
 INSTALL(FILES ${DPM_SYSPOPUP_TARGET} DESTINATION bin)
 INSTALL(TARGETS ${DPM_ADMIN_CLI_TARGET} DESTINATION bin)
diff --git a/tools/cli/dpm-preference b/tools/cli/dpm-preference
new file mode 100755 (executable)
index 0000000..9fcdf9b
--- /dev/null
@@ -0,0 +1,56 @@
+#! /bin/bash
+
+PATH=/usr/bin:/bin/usr/sbin:/sbin
+
+DB_PATH="/opt/dbspace/.dpm.db"
+
+usage()
+{
+       /bin/cat << EOF
+usage:
+       $1 [-a|--admin=<pkgid>]
+
+Options:
+       -a,--admin      Declare device policy admin package
+       -u,--user       Admin package owner id(must be uid)
+       -h,--help       print this help
+EOF
+       return 0
+}
+
+options=$(getopt -o ha:u: -l help,admin:,user: -- "$@")
+if [ $? -ne 0 ]; then
+       usage $(basename $0)
+       exit 1
+fi
+eval set -- "$options"
+
+while true
+do
+    case "$1" in
+        -h|--help)      usage $0 && exit 0;;
+        -a|--admin)     admin=$2; shift 2;;
+        -u|--user)      uid=$2; shift 2;;
+        --)             shift 1; break ;;
+        *)              break ;;
+    esac
+done
+
+if [ -z "$admin" ]; then
+       echo "'admin' parameter is required"
+fi
+
+if [ -z "$uid" ]; then
+       echo "'user' parameter is required"
+fi
+
+# Execution
+sqlite3 ${DB_PATH} \
+"CREATE TABLE IF NOT EXISTS admin (       \
+    id INTEGER PRIMARY KEY AUTOINCREMENT, \
+    pkg TEXT NOT NULL,                    \
+    uid INTEGER,                          \
+    key TEXT,                             \
+    removable INTEGER                     \
+);                                        \
+INSERT INTO admin (pkg, uid, key, removable) VALUES ('$admin', $uid, '', 0);"