Welcome to mirror list, hosted at ThFree Co, Russian Federation.

blanket « ui « build - github.com/ClusterM/kindle-lightfix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 15d99036275038ed7534412e146a33c7f71ff839 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#
# Optional Setting:
#
# LOG_DOMAIN - The domain that logging statements will go under.  If unset, this will default
#              to "ota_install"
#
# Requires that the following have been sourced:
# * /etc/upstart/functions
#

[ -z ${LOG_DOMAIN} ] && LOG_DOMAIN="ota_install"

export _BLANKET_PERCENT_COMPLETE=0

blanket()
{
    local BLANKET=com.lab126.blanket
    local OTAMODULE="${BLANKET}.ota"
    local RES=

    if [ "${1}" != "isloaded" ]; then
        if ! blanket isloaded ; then
            case "${1}" in
                progress|success|error|fail|end)
                    f_log W ${LOG_DOMAIN} guisetup "blanket=unloaded" "blanket not loaded - $@ not executing"
                    return 1
                    ;;
                begin)
                    # Load the OTA module in Blanket and display the splash screen.
                    lipc-set-prop $BLANKET load ota
                    RES=$?
                    if [ ${RES} -ne 0 ]; then
                        f_log W ${LOG_DOMAIN} guiload "load=ota" "unable to load ota blanket module"
                        return ${RES}
                    fi

                    lipc-send-event $OTAMODULE otaSplashInit
                    RES=$?
                    if [ ${RES} -ne 0 ]; then
                        f_log W ${LOG_DOMAIN} guiinit "init=ota" "unable to send init event to ota blanket module"
                        return ${RES}
                    fi
                    return 0
                    ;;
                *)
                    ;;
            esac
        fi
    fi

    case "${1}" in
        progress)
            # Update the progress indicator in the OTA splash screen.
            lipc-send-event $OTAMODULE otaSplashProgress -i ${3}
            RES=$?
            if [ ${RES} -eq 0 ]; then
                f_log D ${LOG_DOMAIN} guiprogress "progress=${3}" "update progress indicator"
            else
                f_log W ${LOG_DOMAIN} guiprogress "progress=${3},status=fail" "update progress indicator"
            fi
            ;;
        success)
            # Display a successful installation in the OTA splash screen.
            lipc-send-event $OTAMODULE otaSplashSuccess
            RES=$?
            if [ ${RES} -eq 0 ]; then
                f_log D ${LOG_DOMAIN} guisuccess "" "display success screen"
            else
                f_log W ${LOG_DOMAIN} guisuccess "status=fail" "display success screen"
            fi
            ;;
        error|fail)
            # Display an error and error string.
            lipc-send-event $OTAMODULE otaSplashError -s "${3}"
            RES=$?
            if [ ${RES} -eq 0 ]; then
                f_log D ${LOG_DOMAIN} guierror "" "display error screen : ${3}"
            else
                f_log W ${LOG_DOMAIN} guierror "status=fail" "display error screen : ${3}"
            fi
            ;;
        end)
            # Remove the splash screen and unload the OTA module from Blanket.
            lipc-send-event $OTAMODULE otaSplashCleanup
            RES=$?
            if [ ${RES} -eq 0 ]; then
                f_log D ${LOG_DOMAIN} guicleanup "" "cleanup ota module"
            else
                f_log W ${LOG_DOMAIN} guicleanup "status=fail" "cleanup ota module"
            fi
            lipc-set-prop $BLANKET unload ota
            RES=$?
            if [ ${RES} -eq 0 ]; then
                f_log D ${LOG_DOMAIN} guiunload "" "unload blanket ota module"
            else
                f_log W ${LOG_DOMAIN} guiunload "status=fail" "unload blanket ota module"
            fi
            ;;
        isloaded)
            lipc-get-prop $BLANKET load | grep -q '\bota\b'
            return $?
            ;;
        *) ;;
    esac
}

display_error_code()
{
    blanket error -i ${1#U}
}

display_stage_data()
{
    local xpos=48
    local ypos=38
    local lpad=$(( $xpos - $(expr length "${1}") ))
    local lbuf=$(printf "%${lpad}s")
    eips 1 $ypos "${lbuf}${1}"
}

display_failure_screen()
{
    display_error_code ${1:-U001}
}

display_success_screen()
{
    blanket success
}

display_update_screen()
{
    blanket begin
    blanket progress -i 0
}

update_percent_complete()
{
    local x=$(printf "%d" $1 2>/dev/null)
    [ -z ${x} ] && x=0

    # Even though the underlying progressbar code doesn't support
    # going forwards & backwards, allow it here
    if [ ${x} -ne 0 ]; then
        _BLANKET_PERCENT_COMPLETE=$((${_BLANKET_PERCENT_COMPLETE} + $x))
        __check_bounds
        blanket progress -i ${_BLANKET_PERCENT_COMPLETE}
    fi
}

reset_progressbar()
{
    _BLANKET_PERCENT_COMPLETE=0
    blanket end
    [ $# -eq 0 ] && display_update_screen
}

set_percent_complete()
{
    local x=${_BLANKET_PERCENT_COMPLETE}
    _BLANKET_PERCENT_COMPLETE=$(printf "%d" ${1} 2>/dev/null)
    [ -z ${_BLANKET_PERCENT_COMPLETE} ] && _BLANKET_PERCENT_COMPLETE=0
    __check_bounds
    if [ ${x} -ne ${_BLANKET_PERCENT_COMPLETE} ]; then
        blanket progress -i ${1}
    fi
}

__check_bounds()
{
    if [ ${_BLANKET_PERCENT_COMPLETE} -gt 100 ]; then
        _BLANKET_PERCENT_COMPLETE=100
    elif [ ${_BLANKET_PERCENT_COMPLETE} -lt 0 ]; then
        _BLANKET_PERCENT_COMPLETE=0
    fi
}