WgtMgrSrvMain.c 104 KB
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*******************************************************************************
 * Filename:
 * ---------
 * WgtMgrSrvMain.c
 *
 * Project:
 * --------
 * MAUI
 *
 * Description:
 * ------------
 *
 *
 * Author:
 * -------
 * -------
 *
 *==============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *==============================================================================
 *******************************************************************************/
/************************************************************************/
/* Include Header                                                       */
/************************************************************************/
//#include "MMI_include.h"

#ifdef __GADGET_SUPPORT__
#include "MMIDataType.h"
#include "kal_general_types.h"
#include "kal_public_api.h"
#include "fs_type.h"
#include "fs_func.h"
#include "mmi_frm_nvram_gprot.h"
#include "GlobalResDef.h"
#include "PixcomFontEngine.h"
#include "string.h"
#include "mmi_frm_mem_gprot.h"
#include "DebugInitDef_Int.h"
#include "widget_adp_struct.h"
#include "stack_config.h"
#include "app_str.h"
#include "WgtMgrSrvGprot.h"
#include "WgtMgrSrvIprot.h"
#include "WgtMgrSrv.h"
#include "widget_api.h"
#include "certman_api.h"
#include "FileMgrSrvGProt.h"
#include "cbm_consts.h"
#include "gadget_adp_avplugin.h"
#include "DtcntSrvGprot.h"
#include "cbm_api.h"
#include "custom_data_account.h"
#include "UsbSrvGProt.h"
#include "mmi_rp_srv_wgtmgr_def.h"
#include "fs_errcode.h"
#include "mmi_rp_srv_dtcnt_def.h"
#include "MMI_features.h"
#include "mmi_rp_app_usbsrv_def.h"
#include "app_datetime.h"
#include "USBSrvGprot.h"
#include "mmi_cb_mgr_gprot.h"
#include "mmi_frm_events_gprot.h"
#include "custom_gadget_config.h"
#include "CbmSrvGprot.h"

#ifdef __PLUTO_MMI_PACKAGE__
#include "mmi_rp_app_wgtmgr_def.h"
#endif

#ifdef __PLUTO_MMI_PACKAGE__
#include "vapp_hs_def.h"
#include "vadp_p2v_hs.h"
#endif

#include "gadget_adp_log.h"

/************************************************************************/
/* Structure and Definition                                             */
/************************************************************************/
typedef enum
{
    SRV_WGTMGR_CHECK_WHILE_BOOT_UP,
    SRV_WGTMGR_CHECK_ALL_DOWNLOADED_WGT,
    SRV_WGTMGR_CHECK_ALL_MEMCARD_WGT
} srv_wgtmgr_check_mode_enum;


/************************************************************************/
/* Internal Function Declaration                                        */
/************************************************************************/
static S32 srv_wgtmgr_get_enabled_wgt_int(srv_wgtmgr_wgt_list_struct *list_ptr);
static void srv_wgtmgr_quick_sort(S32 left, S32 right);
static S32 srv_wgtmgt_sort_partition(S32 left, S32 right);
static void srv_wgtmgt_switch_position(S32 i, S32 j);
static S32 srv_wgtmgr_sort_compare_by_name(S32 left, S32 right);
static S32 srv_wgtmgr_sort_compare_by_installed_time(S32 left, S32 right);
static void srv_wgtmgr_check_all_downloaded_wgt(void);
static void srv_wgtmgr_check_all_downloaded_wgt_int(srv_wgtmgr_wgt_item_struct *dwgt_info, srv_wgtmgr_check_mode_enum mode);
static void srv_wgtmgr_memcard_insert_hdlr(void);
static void srv_wgtmgr_dtcnt_ready_callback(void);
static MMI_BOOL srv_wgtmgr_is_stamp_file_valid(S32 id);
static srv_wgtmgr_result_enum srv_wgtmgr_check_downloaded_wgt_int(S32 id);
mmi_ret srv_wgtmgr_bearer_event_notify_hdlr(mmi_event_struct *param);

/************************************************************************/
/* External Function Declaration                                        */
/************************************************************************/
extern void gadget_adp_mgr_get_engine_version(char *version);
extern void widget_unload_widget(int instance_id);

/************************************************************************/
/* Golbal Variable                                                      */
/************************************************************************/
const WCHAR g_srv_wgtmgr_folder[] = SRV_WGTMGR_FOLDER;
const WCHAR g_srv_wgtmgr_name_data[] = SRV_WGTMGR_NAME_DATA_FILE;
const WCHAR g_srv_wgtmgr_name_guard[] = SRV_WGTMGR_NAME_GUARD_FILE;
const WCHAR g_srv_wgtmgr_version_data[] = SRV_WGTMGR_VERSION_DATA_FILE;
const WCHAR g_srv_wgtmgr_version_guard[] = SRV_WGTMGR_VERSION_GUARD_FILE;
const WCHAR g_srv_wgtmgr_memcard_wgt_icon[] = SRV_WGTMGR_MEMCARD_WGT_ICON;
#ifdef __WGTMGR_SAVE_ICON_FILE__
const WCHAR g_srv_wgtmgr_icon_folder[] = SRV_WGTMGR_ICON_FOLDER;
#endif

static const unsigned char g_srv_wgt_memcard_wgt_icon_data[] = 
{
#ifdef __PLUTO_MMI_PACKAGE__
#ifdef __MMI_MAINLCD_320X480__
#include "mem_widget_icon_big.png.hex"
#else
#include "mem_widget_icon.png.hex"
#endif
#else
#include "cosmos_widget_icon.png.hex"
#endif
}; 

static srv_wgtmgr_cntx_struct g_srv_wgtmgr_cntx;
srv_wgtmgr_cntx_struct *g_srv_wgtmgr_cntx_p = &g_srv_wgtmgr_cntx;

srv_wgtmgr_sort_compare_func_type g_srv_wgtmgr_sort_compare_func;

/************************************************************************/
/* Local Function Definition                                                  */
/************************************************************************/
/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_enabled_wgt_int
 * DESCRIPTION
 *  this function is used to get id list of enabled widget 
 * PARAMETERS
 *  list_ptr : [OUT] the buffer to store id list 
 * RETURNS
 *  number of enabled widgets
 *****************************************************************************/
static S32 srv_wgtmgr_get_enabled_wgt_int(srv_wgtmgr_wgt_list_struct *list_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 i, num = 0;
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;	
    U8 *wgt_status_p;
#ifdef __WGTMGR_MGR_PHONE_WIDGET__
    S32 *pwgt_id_p = cntx_p->pwgt_id;
#endif	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    /* get number of enabled phone widget */
#ifdef __WGTMGR_MGR_PHONE_WIDGET__
    wgt_status_p = cntx_p->pwgt_status;
    for (i = 0; i < SRV_WGTMGR_MAX_PHONE_WGT_NUM; i++)
    {
        if (wgt_status_p[i] == SRV_WGTMGR_WGT_STATUS_ENABLED) 
      	{
            if (list_ptr != NULL)
            {
                list_ptr[num].type = SRV_WGTMGR_WGT_TYPE_PHONE;
                list_ptr[num].id = pwgt_id_p[i];
            }
            num++;
        }
    }
#endif
    /* if the phone is in mass storage mode, we don't have to provide 
	   downloaded widget info */
#if 0
#ifdef __USB_IN_NORMAL_MODE__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
#endif

    wgt_status_p = cntx_p->dwgt_status;

    /* get number of enabled downloaded widget */
    for (i = 0; i < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM; i++)
    {
        if (wgt_status_p[i] == SRV_WGTMGR_WGT_STATUS_ENABLED) 
      	{
            if (list_ptr != NULL)
            {
                list_ptr[num].type = SRV_WGTMGR_WGT_TYPE_DOWNLOADED;
                list_ptr[num].id = i;
            }
            num++;
        }
    }
    return num;

}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_mainmenu_wgt_int
 * DESCRIPTION
 *  this function is used to get id list of enabled widget 
 * PARAMETERS
 *  list_ptr : [OUT] the buffer to store id list 
 * RETURNS
 *  number of enabled widgets
 *****************************************************************************/
static S32 srv_wgtmgr_get_mainmenu_wgt_int(mmi_app_package_name_struct *list_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 i, num = 0;
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;	
    srv_wgtmgr_wgt_item_struct wgt_info;
    U8 *wgt_status_p = cntx_p->dwgt_status;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    

    /* get number of main menu downloaded widget */
    for (i = 0; i < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM; i++)
    {
        if (wgt_status_p[i] == SRV_WGTMGR_WGT_STATUS_ENABLED)
        {
            srv_wgtmgr_read_wgt_info_from_nvram_by_id(i, &wgt_info);    
            
            if (wgt_info.attribute & SRV_WGTMGR_ATTR_MAINMENU)
            {
                if (list_ptr != NULL)
                {
                    sprintf(list_ptr[num], "widget.mtk.%d", i);
                }
                num++;
            }
        }
    }
    return num;
}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_quick_sort
 * DESCRIPTION
 *  This function is to sort widget with quick sort algorithm
 * PARAMETERS
 *  left:  [IN] left position 
 *  right: [IN] right position
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_wgtmgr_quick_sort(S32 left, S32 right)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 q;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (left < right)
    {
        q = srv_wgtmgt_sort_partition(left, right);
        srv_wgtmgr_quick_sort(left, q - 1);
        srv_wgtmgr_quick_sort(q + 1, right);		
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgt_sort_partition
 * DESCRIPTION
 *  This is the partition function is quick sort
 * PARAMETERS  
 *  left:  [IN] left position 
 *  right: [IN] right position
 * RETURNS
 * 
 *****************************************************************************/
static S32 srv_wgtmgt_sort_partition(S32 left, S32 right)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 i = left - 1;
    S32 j;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (j = left; j < right; j++)
    {
        if (g_srv_wgtmgr_sort_compare_func(j, right) <= 0)
        {   
            i++;
            srv_wgtmgt_switch_position(i, j);
        }
    }

    i++;    
    srv_wgtmgt_switch_position(i, right);

	return i;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgt_switch_position
 * DESCRIPTION
 *  This is the partition function is quick sort
 * PARAMETERS  
 *  i: [IN] position i
 *  j: [IN] position j
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_wgtmgt_switch_position(S32 i, S32 j)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 temp_id;
    U16 *sort_id_list_p = g_srv_wgtmgr_cntx_p->asm_data->sort_id_list;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    temp_id = sort_id_list_p[i];
    sort_id_list_p[i] = sort_id_list_p[j];
    sort_id_list_p[j] = temp_id;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_sort_compare_by_name
 * DESCRIPTION
 *  This is the function to compare name
 * PARAMETERS
 *  left:  [IN] left position 
 *  right: [IN] right position 
 * RETURNS
 *  ret > 0 : left > right
 *  ret = 0 : left = right
 *  ret < 0 : left < right
 *****************************************************************************/
static S32 srv_wgtmgr_sort_compare_by_name(S32 left, S32 right)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_wgt_asm_data_struct *asm_data_p = g_srv_wgtmgr_cntx_p->asm_data;
    U16 *sort_id_list_p = asm_data_p->sort_id_list;
    WCHAR *left_name_p = NULL;
    WCHAR *right_name_p = NULL;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    left_name_p = asm_data_p->dwgt_name[sort_id_list_p[left]];
    right_name_p = asm_data_p->dwgt_name[sort_id_list_p[right]];
    return app_ucs2_wcsicmp(left_name_p, right_name_p);    
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_sort_compare_by_installed_time
 * DESCRIPTION
 *  This is the function to compare installed time
 * PARAMETERS
 *  left:  [IN] left position 
 *  right: [IN] right position 
 * RETURNS
 *  ret > 0 : left > right
 *  ret = 0 : left = right
 *  ret < 0 : left < right
 *****************************************************************************/
static S32 srv_wgtmgr_sort_compare_by_installed_time(S32 left, S32 right)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_wgt_item_struct *dwgt_p = g_srv_wgtmgr_cntx_p->asm_data->dwgt;
    U16 *sort_list_p = g_srv_wgtmgr_cntx_p->asm_data->sort_id_list;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    return (S32)dwgt_p[sort_list_p[left]].install_time - (S32)dwgt_p[sort_list_p[right]].install_time;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_check_all_downloaded_wgt
 * DESCRIPTION
 *  this funciton is used to check all downloaded widgets
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_wgtmgr_check_all_downloaded_wgt(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_wgt_item_struct *dwgt_info = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    dwgt_info = (srv_wgtmgr_wgt_item_struct*)OslMalloc(sizeof(srv_wgtmgr_wgt_item_struct) * SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM);

    /* read downloaded widget info from nvram */
    srv_wgtmgr_read_wgt_info_from_nvram(dwgt_info);

    srv_wgtmgr_check_all_downloaded_wgt_int(dwgt_info, SRV_WGTMGR_CHECK_ALL_DOWNLOADED_WGT);

    OslMfree(dwgt_info);

}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_check_downloaded_int
 * DESCRIPTION
 *  this funciton is to check all downloaded widgets
 * PARAMETERS
 *  dwgt_info: [IN] the widget info
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_wgtmgr_check_all_downloaded_wgt_int(srv_wgtmgr_wgt_item_struct *dwgt_info, srv_wgtmgr_check_mode_enum mode)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    U8 *dwgt_status_p = cntx_p->dwgt_status;
    U8 status = 0;
    WCHAR *icon_path, *main_view_path;
    S32 i = 0;
    U16 *delete_list_p;
    S32 num = 0;
    MMI_BOOL delete_wgt; 

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* we check the icon of each widget, if it is deleted and the widget is intalled in   *
     *  1. public drive: delete the widget                                                *
     *  2. memory card: (a) if memory card does not exist: disable the widget             *
     *                  (b) if memory card exists: delete the widget                      */

    icon_path = (WCHAR*) OslMalloc(SRV_WGTMGR_MAX_WGT_ICON_PATH_LEN * sizeof(WCHAR));
    main_view_path = (WCHAR*) OslMalloc(SRV_WGTMGR_MAX_WGT_MAIN_VIEW_PATH_LEN * sizeof(WCHAR));

    delete_list_p = (U16*)OslMalloc(SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM * sizeof(U16));

    if (icon_path == NULL || main_view_path == NULL || delete_list_p == NULL)
    {
        MMI_ASSERT(0);
    }

    for (i = 0; i < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM; i++)
    {
        status = dwgt_status_p[i];
        delete_wgt = MMI_FALSE;

        if ((status == SRV_WGTMGR_WGT_STATUS_NULL && mode == SRV_WGTMGR_CHECK_WHILE_BOOT_UP) ||
            (status == SRV_WGTMGR_WGT_STATUS_DELETING) ||
            (status == SRV_WGTMGR_WGT_STATUS_UPDATING) ||
            (srv_wgtmgr_is_preinstall_widget_finished() == MMI_FALSE))
        {
            delete_wgt = MMI_TRUE;
        }
        else if (status == SRV_WGTMGR_WGT_STATUS_ENABLED)
        {
            /* get icon path */
            srv_wgtmgr_get_path(i, SRV_WGTMGR_PATH_ICON_FILE, icon_path);
            srv_wgtmgr_get_path(i, SRV_WGTMGR_PATH_MAIN_VIEW, main_view_path);

            /* check if it exists*/
            if (FS_GetAttributes(icon_path) < 0 || FS_GetAttributes(main_view_path) < 0)
            {
                srv_wgtmgr_notify_evt_struct event;
                MMI_FRM_INIT_EVENT(&event, EVT_ID_SRV_WGTMGR_FILE_NOT_EXISTS_IND);
                event.id = i;
                MMI_FRM_CB_EMIT_POST_EVENT(&event);

            #ifdef __PLUTO_MMI_PACKAGE__
                dwgt_status_p[i] = SRV_WGTMGR_WGT_STATUS_DISABLED;
            #endif
            }
       	}

        if (delete_wgt == MMI_TRUE)
        {
            delete_list_p[num] = i;
            num++;
        }
   	}

    srv_wgtmgr_save_wgt_status_to_nvram();
    if (num > 0)
    {
        srv_wgtmgr_send_delete_wgt_multiple_req(num, delete_list_p);
    }

    OslMfree(icon_path);
    OslMfree(main_view_path);
    OslMfree(delete_list_p);
}





/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_memcard_insert_hdlr
 * DESCRIPTION
 *  this funciton is to check all downloaded widgets
 * PARAMETERS
 *  drive: [IN] the specified drive
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_wgtmgr_memcard_insert_hdlr(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __USB_IN_NORMAL_MODE__
    if(srv_usb_is_in_mass_storage_mode() == MMI_TRUE)
    {
        return;
    }    
#endif

    srv_wgtmgr_check_all_downloaded_wgt();

    if (cntx_p->is_start == MMI_TRUE)
    {
        srv_wgtmgr_read_wgt_info_from_nvram(cntx_p->asm_data->dwgt);

        /* sort installed widget */
        srv_wgtmgr_sort_wgt();
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_dtcnt_ready_callback
 * DESCRIPTION
 *  this funciton is to check data account
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void srv_wgtmgr_dtcnt_ready_callback(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    S32 i;
    cbm_sim_id_enum cbm_sim[] ={CBM_SIM_ID_SIM1, CBM_SIM_ID_SIM2, CBM_SIM_ID_SIM3, CBM_SIM_ID_SIM4};    

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for( i = 0; i < SRV_WGTMGR_SIM_NUM; i++)
    {
        if (srv_wgtmgr_dtcnt_acct_is_valid(cntx_p->data_account[i]) == MMI_FALSE)
        {
            U32 account_id = cbm_encode_data_account_id(
                                         CBM_DEFAULT_ACCT_ID,
                                         cbm_sim[i], 
                                         cntx_p->da_app_id, 
                                         KAL_FALSE);
            U32 acct_id_out = 0;
            srv_dtcnt_get_auto_acc_id(account_id, &acct_id_out);
            
            srv_wgtmgr_set_default_data_account(i, acct_id_out);
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_is_stamp_file_valid
 * DESCRIPTION
 *  This function is used to check the file's existence and validity of a widget
 * PARAMETERS
 *  id: [IN] widget id
 * RETURNS
 *  MMI_TRUE if yes
 *****************************************************************************/
static MMI_BOOL srv_wgtmgr_is_stamp_file_valid(S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/	
    char drive = srv_wgtmgr_get_drive_letter((srv_wgtmgr_wgt_drive_enum)g_srv_wgtmgr_cntx_p->dwgt_drive[id]);
    srv_wgtmgr_wgt_item_struct wgt_info;
    WCHAR* dst_path;
    MMI_BOOL ret = MMI_FALSE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* read widget info from nvram */
    srv_wgtmgr_read_wgt_info_from_nvram_by_id(id, &wgt_info);

    /* get the file path of stamp file */
    dst_path = (WCHAR*)OslMalloc(sizeof(WCHAR) * 50);
    kal_wsprintf(dst_path, "%c:\\@gadget\\%03d\\%d", drive, id, wgt_info.install_time);

    if ( FS_GetAttributes(dst_path) >= 0 )
    {
        ret = MMI_TRUE;
    }

    OslMfree(dst_path);
    return ret;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_check_downloaded_wgt_int
 * DESCRIPTION
 *  this funciton is used to check a downloaded widget
 * PARAMETERS
 *  id: [IN] widget instance id
 * RETURNS
 *  error code
 *****************************************************************************/
static srv_wgtmgr_result_enum srv_wgtmgr_check_downloaded_wgt_int(S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    WCHAR *path;
    srv_wgtmgr_result_enum ret = SRV_WGTMGR_RET_OK;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (srv_wgtmgr_is_stamp_file_valid(id) == MMI_FALSE)
    {
        return SRV_WGTMGR_RET_FILE_NOT_EXIST;
    }

    /* read downloaded widget info from nvram */
    path = (WCHAR*) OslMalloc(SRV_FMGR_PATH_MAX_LEN * sizeof(WCHAR));

    srv_wgtmgr_get_path(id, SRV_WGTMGR_PATH_ICON_FILE, path);
    if (FS_GetAttributes(path) < 0)
    {
        ret = SRV_WGTMGR_RET_FILE_NOT_EXIST;       
        goto end;
    }

    srv_wgtmgr_get_path(id, SRV_WGTMGR_PATH_MAIN_VIEW, path);
    if (FS_GetAttributes(path) < 0)
    {
        ret = SRV_WGTMGR_RET_FILE_NOT_EXIST;
        goto end;
    }

    srv_wgtmgr_get_path(id, SRV_WGTMGR_PATH_MANIFEST, path);
    if (FS_GetAttributes(path) < 0)
    {
        ret = SRV_WGTMGR_RET_FILE_NOT_EXIST;
        goto end;
    }

end:
    OslMfree(path);
    return ret;	
}



/************************************************************************/
/* Global Function Definition                                                  */
/************************************************************************/
/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_init
 * DESCRIPTION
 *  This function is used to init Widget Manager Service
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_init(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 error = 0;
    U16 temp = 0;
    S32 i = 0;
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    nvram_wgtmgr_lid_struct *lid_p = NULL;
    U8* wgt_status_p;
    U8 status;
    S32 fd;
    U32 written;	
    cbm_app_info_struct info; 
    cbm_sim_id_enum cbm_sim[] ={CBM_SIM_ID_SIM1, CBM_SIM_ID_SIM2, CBM_SIM_ID_SIM3, CBM_SIM_ID_SIM4};
    static U32 init = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (init == 1)
   	{
        return;
    }

    init = 1;

    kal_mem_set(cntx_p, 0, sizeof(srv_wgtmgr_cntx_struct));

    cntx_p->system_drive = SRV_FMGR_SYSTEM_DRV;
    cntx_p->public_drive = SRV_FMGR_PUBLIC_DRV;
    cntx_p->memcard_drive = SRV_FMGR_CARD_DRV;

    /* create Z:\\@wgtmgr if necessary */
    if (FS_GetAttributes(g_srv_wgtmgr_folder) < 0)
    {
        FS_CreateDir(g_srv_wgtmgr_folder);
    }

#ifdef __WGTMGR_SAVE_ICON_FILE__
    /* create Z:\\@wgtmgr\\icon if necessary */
    if (FS_GetAttributes(g_srv_wgtmgr_icon_folder) < 0)
    {
        FS_CreateDir(g_srv_wgtmgr_icon_folder);
    }
#endif


    /* set protocol event handler */
    srv_wgtmgr_set_protocol_event_handler();

    /* read sort order from NVRAM Cache */
    ReadValue(NVRAM_WGTMGR_WGT_SORT_ORDER, &(cntx_p->sort_order), DS_BYTE, &error);
    if (cntx_p->sort_order >= SRV_WGTMGR_SORT_BY_TOTAL_NUM)
    {
        cntx_p->sort_order = SRV_WGTMGR_SORT_BY_NAME;
    }	

    /* read data account from NVRAM Cache */
    ReadValue(NVRAM_WGTMGR_WGT_DATA_ACCOUNT_FIRST, &temp, DS_SHORT, &error);
    cntx_p->data_account[SRV_WGTMGR_SIM1] = temp << 16;
    ReadValue(NVRAM_WGTMGR_WGT_DATA_ACCOUNT_LAST, &temp, DS_SHORT, &error);
    cntx_p->data_account[SRV_WGTMGR_SIM1] += temp;

    /* read data account from NVRAM Cache */
    ReadValue(NVRAM_WGTMGR_WGT_DATA_ACCOUNT_2_FIRST, &temp, DS_SHORT, &error);
    cntx_p->data_account[SRV_WGTMGR_SIM2] = temp << 16;
    ReadValue(NVRAM_WGTMGR_WGT_DATA_ACCOUNT_2_LAST, &temp, DS_SHORT, &error);
    cntx_p->data_account[SRV_WGTMGR_SIM2] += temp;

    /* read data account from NVRAM Cache */
    ReadValue(NVRAM_WGTMGR_WGT_DATA_ACCOUNT_3_FIRST, &temp, DS_SHORT, &error);
    cntx_p->data_account[SRV_WGTMGR_SIM3] = temp << 16;
    ReadValue(NVRAM_WGTMGR_WGT_DATA_ACCOUNT_3_LAST, &temp, DS_SHORT, &error);
    cntx_p->data_account[SRV_WGTMGR_SIM3] += temp;

    /* read data account from NVRAM Cache */
    ReadValue(NVRAM_WGTMGR_WGT_DATA_ACCOUNT_4_FIRST, &temp, DS_SHORT, &error);
    cntx_p->data_account[SRV_WGTMGR_SIM4] = temp << 16;
    ReadValue(NVRAM_WGTMGR_WGT_DATA_ACCOUNT_4_LAST, &temp, DS_SHORT, &error);
    cntx_p->data_account[SRV_WGTMGR_SIM4] += temp;

    //TODO: add string for cosmos
#ifdef __PLUTO_MMI_PACKAGE__
    info.app_str_id = STR_ID_WGTMGR_WIDGET_MANAGER;
#endif

#if defined(__MMI_FTE_SUPPORT__) || defined(__MMI_MAINLCD_320X480__) || defined (__COSMOS_MMI_PACKAGE__)
    info.app_icon_id = IMG_NONE;
#else
    info.app_icon_id = IMG_ID_WGTMGR_APP;
#endif
    info.app_type = (DTCNT_APPTYPE_SKIP_CSD | DTCNT_APPTYPE_NO_PX);
    cbm_register_app_id_with_app_info(&info, &cntx_p->da_app_id);

    /* register bear disconnect and switch event */
    srv_cbm_register_bearer_event(
        SRV_CBM_BEARER_EVENT_DISCONNECT | SRV_CBM_BEARER_EVENT_SWITCH, 
        cntx_p->da_app_id,
        srv_wgtmgr_bearer_event_notify_hdlr,
        NULL);

    gadget_adp_log_prompt_trace("widget app id: %d", cntx_p->da_app_id);

    for ( i = 0; i < SRV_WGTMGR_SIM_NUM; i++)
    {
        U32 account_id = 0;
        U32 acct_id_out = 0;

        if (cntx_p->data_account[i] == 0xFFFFFFFF)
        {
            account_id = cbm_encode_data_account_id(
                                     CBM_DEFAULT_ACCT_ID,
                                     cbm_sim[i], 
                                     cntx_p->da_app_id, 
                                     KAL_FALSE);

            gadget_adp_log_prompt_trace("[1]widget account id [%d]: %d", i, account_id);

            srv_dtcnt_get_auto_acc_id(account_id, &acct_id_out);
            srv_wgtmgr_set_default_data_account(i, acct_id_out);

            gadget_adp_log_prompt_trace("[2]widget account id [%d]: %d", i, acct_id_out);
        }
        else
        {
            account_id = cbm_set_app_id(cntx_p->data_account[i], cntx_p->da_app_id);
            srv_wgtmgr_set_default_data_account(i, account_id);
            
            gadget_adp_log_prompt_trace("[3]widget account id [%d]: %d", i, account_id);
        }
        
    }

    /* read network access from NVRAM Cache */
    ReadValue(NVRAM_WGTMGR_WGT_NETWORK_ACCESS, &(cntx_p->network_access), DS_BYTE, &error);
    if (cntx_p->network_access >= SRV_WGTMGR_NETWORK_ACCESS_TOTAL_NUM)
    {
        cntx_p->network_access = SRV_WGTMGR_NETWORK_ACCESS_ALLOW;
    }	

    ReadValue(NVRAM_WGTMGR_WIFI_ONLY, &(cntx_p->wifi_only), DS_BYTE, &error);
    if (cntx_p->wifi_only == 0xFF)
    {
        cntx_p->wifi_only = MMI_FALSE;
    }

    cntx_p->preferred_sim = SRV_WGTMGR_SIM1;

    /* read need_update_data flag from NVRAM Cache */
    ReadValue(NVRAM_WGTMGR_WGT_NEED_UPDATE_NAME, &(cntx_p->need_update_data), DS_BYTE, &error);

    /* check whether version data file is corrupted */
    if (FS_GetAttributes(g_srv_wgtmgr_version_guard) >= 0)
    {
        srv_wgtmgr_set_data_need_update(SRV_WGTMGR_UPDATE_VERSION);
    }

    /* read widget language from NVRAM Cache */
    ReadValue(NVRAM_WGTMGR_WGT_PHONE_LANG, &(cntx_p->wgt_lang), DS_DOUBLE, &error);

    /* check if need update widget name data */
    if ((cntx_p->need_update_data & SRV_WGTMGR_UPDATE_NAME) ||
        (FS_GetAttributes(g_srv_wgtmgr_name_guard) >= 0) ||
        (FS_GetAttributes(g_srv_wgtmgr_name_data) < 0) ||
        (strcmp(cntx_p->wgt_lang, (const char*)Get_Current_Lang_CountryCode()) != 0))
    {
        cntx_p->req_table.send_name_req = MMI_TRUE;
        strcpy(cntx_p->wgt_lang, (const char*)Get_Current_Lang_CountryCode());
        srv_wgtmgr_send_name_req();
    }


    /* allocate memory for LID */
    lid_p = (nvram_wgtmgr_lid_struct*) OslMalloc(sizeof(nvram_wgtmgr_lid_struct));
    MMI_ASSERT(lid_p);
    
    /* read record from NVRAM LID */
    srv_wgtmgr_read_lid(lid_p);

#ifdef __WGTMGR_MGR_PHONE_WIDGET__
    /* copy widget status to global context structure */
    kal_mem_cpy(cntx_p->pwgt_status, lid_p->pwgt_status, sizeof(U8) * SRV_WGTMGR_MAX_PHONE_WGT_NUM);

    vadp_p2v_hs_widget_get_all_id((S32*)cntx_p->pwgt_id, sizeof(cntx_p->pwgt_id));

    wgt_status_p = cntx_p->pwgt_status;
    for (i = 0; i < SRV_WGTMGR_MAX_PHONE_WGT_NUM; i++)
    {
        if ((wgt_status_p[i] != SRV_WGTMGR_WGT_STATUS_ENABLED) &&
            (wgt_status_p[i] != SRV_WGTMGR_WGT_STATUS_DISABLED))
        {
            wgt_status_p[i] = SRV_WGTMGR_WGT_STATUS_ENABLED;
        }	
    }
#endif

    kal_mem_cpy(cntx_p->dwgt_status, lid_p->dwgt_status, sizeof(U8) * SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM);

    wgt_status_p = cntx_p->dwgt_status;

    for (i = 0; i < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM; i++)
    {
        status = wgt_status_p[i];
        cntx_p->dwgt_drive[i] = lid_p->dwgt[i].drive;		
        if (status >= SRV_WGTMGR_WGT_STATUS_TOTAL_NUM)
        {
            wgt_status_p[i] = SRV_WGTMGR_WGT_STATUS_NULL;
        }
		
        /* disable widgets installed in memory card if memory card does not exist */
    #ifdef __PLUTO_MMI_PACKAGE__
        if ((status == SRV_WGTMGR_WGT_STATUS_ENABLED) &&
            (lid_p->dwgt[i].drive == SRV_WGTMGR_DRIVE_MEMORY_CARD) &&
            (srv_wgtmgr_is_memcard_available() == MMI_FALSE))
        {
            wgt_status_p[i] = SRV_WGTMGR_WGT_STATUS_DISABLED;
        }
    #endif
    }

    /* check all downloaded widget folder */
    srv_wgtmgr_check_all_downloaded_wgt_int(lid_p->dwgt, SRV_WGTMGR_CHECK_WHILE_BOOT_UP);

    /* free control buffer */
    OslMfree(lid_p);

    if (FS_GetAttributes(g_srv_wgtmgr_memcard_wgt_icon) < 0)
    {
        fd = FS_Open(g_srv_wgtmgr_memcard_wgt_icon, FS_READ_WRITE | FS_CREATE | FS_OPEN_SHARED);
        FS_Write(fd, (void*)g_srv_wgt_memcard_wgt_icon_data, sizeof(g_srv_wgt_memcard_wgt_icon_data), &written);
        FS_Close(fd);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_init_evt_hdlr
 * DESCRIPTION
 *  This function is used to init Widget Manager Service
 * PARAMETERS
 *  evt : [IN] event
 * RETURNS
 *  void
 *****************************************************************************/
mmi_ret srv_wgtmgr_init_evt_hdlr(mmi_event_struct *evt)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_init();

    return MMI_RET_OK;	
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_start
 * DESCRIPTION
 *  This function is to start the native service of Widget Manager Serive
 * PARAMETERS
 *  mem_ptr : [IN] The pointer of ASM
 *  callback: [IN] The callback invoked when native service is ready
 *  user_data: [IN] The user data of application
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_start(void *mem_ptr, srv_wgtmgr_start_cb_func_ptr callback, void *user_data)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    cntx_p->is_start = MMI_TRUE;

    /* set ASM */
    if (cntx_p->asm_data != NULL)
    {
        MMI_ASSERT(0);
    }

    cntx_p->asm_data = mem_ptr;
    cntx_p->cb_table.start_cb = callback;
    cntx_p->cb_table.start_cb_user_data = user_data;
    srv_wgtmgr_start_cont();	
}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_start_cont
 * DESCRIPTION
 *  This function is to continue to start the native service of Widget Manager Serive
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_start_cont()
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    srv_wgtmgr_start_cb_func_ptr callback = cntx_p->cb_table.start_cb;
    void *user_data = cntx_p->cb_table.start_cb_user_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (cntx_p->is_start == MMI_FALSE)
    {
        return;
    }

    /* check if need update version file or it is updating now */
    if ((cntx_p->need_update_data & SRV_WGTMGR_UPDATE_VERSION) ||
        (FS_GetAttributes(g_srv_wgtmgr_version_guard) >= 0) ||
        (cntx_p->req_table.send_version_req == MMI_TRUE) ||
        (srv_wgtmgr_read_name_or_version_from_file(SRV_WGTMGR_UPDATE_VERSION) == MMI_FALSE))
    {
        if (cntx_p->req_table.send_version_req == MMI_FALSE)
        {
            cntx_p->req_table.send_version_req = MMI_TRUE;
            srv_wgtmgr_send_version_req();

        }
        return;
    }

    /* check if need update name file or it is updating now */
    if ((cntx_p->need_update_data & SRV_WGTMGR_UPDATE_NAME) ||
        (FS_GetAttributes(g_srv_wgtmgr_name_guard) >= 0) ||
        (strcmp(cntx_p->wgt_lang, (const char*)Get_Current_Lang_CountryCode()) != 0) ||
        (cntx_p->req_table.send_name_req == MMI_TRUE) ||
        (srv_wgtmgr_read_name_or_version_from_file(SRV_WGTMGR_UPDATE_NAME) == MMI_FALSE))
    {
        if (cntx_p->req_table.send_name_req == MMI_FALSE)
        {
            cntx_p->req_table.send_name_req = MMI_TRUE;
            strcpy(cntx_p->wgt_lang, (const char*)Get_Current_Lang_CountryCode());
            srv_wgtmgr_send_name_req();
        }
        return;
    }

    /* read widget info from nvram */
    srv_wgtmgr_read_wgt_info_from_nvram(cntx_p->asm_data->dwgt);

    /* sort installed widget */
    srv_wgtmgr_sort_wgt();

    /* invoke Widget Manager App's callback */	
    if (callback != NULL)
    {
        cntx_p->cb_table.start_cb = NULL;
        cntx_p->cb_table.start_cb_user_data = NULL;
        callback(user_data);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_stop
 * DESCRIPTION
 *  This function is to start the native service of Widget Manager Serive
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_stop(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* Release asm */
    if (cntx_p->asm_data != NULL)
    {
        cntx_p->asm_data = NULL;
    }

    cntx_p->is_start = MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_sort_wgt
 * DESCRIPTION
 *  This function is used to sort installed widget 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_sort_wgt(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 i = 0;
    U32 num = 0;
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    U16 *sort_list_p = cntx_p->asm_data->sort_id_list;
    U8 *wgt_status_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgt_status_p = cntx_p->dwgt_status;
    for (i = 0; i < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM; i++)
    {
        if (wgt_status_p[i] == SRV_WGTMGR_WGT_STATUS_ENABLED || 
            wgt_status_p[i] == SRV_WGTMGR_WGT_STATUS_DISABLED )
        {
            sort_list_p[num] = i;
            num++;
        }
    }


    if (cntx_p->sort_order == SRV_WGTMGR_SORT_BY_INSTALLED_TIME)
    {
        g_srv_wgtmgr_sort_compare_func = srv_wgtmgr_sort_compare_by_installed_time;
    }
    else
    {
        g_srv_wgtmgr_sort_compare_func = srv_wgtmgr_sort_compare_by_name;    
    }

    srv_wgtmgr_quick_sort(0, num - 1);

}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_enable_wgt
 * DESCRIPTION
 *  This function is used to enable a widget
 * PARAMETERS
 *  type:  [IN] The widget type
 *  id  :  [IN] The widget id
 * RETURNS
 *  The result of the operation
 *****************************************************************************/
S32 srv_wgtmgr_enable_wgt(srv_wgtmgr_wgt_type_enum type, S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;	
    S32 ret;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (srv_wgtmgr_get_enabled_wgt_num() >= SRV_WGTMGT_MAX_ENABLED_WGT_NUM)
    {
        return SRV_WGTMGR_RET_EXCEED_MAX_ENABLED_NUM;
    }

    if (type == SRV_WGTMGR_WGT_TYPE_PHONE)
    {
#ifdef __WGTMGR_MGR_PHONE_WIDGET__
        cntx_p->pwgt_status[id] = SRV_WGTMGR_WGT_STATUS_ENABLED;
#endif
    }
    else
    {
        MMI_ASSERT(id < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM);

        /* check if the widget is installed in memory card which is not present now */
        ret = srv_wgtmgr_check_downloaded_wgt(id);

        if (ret != SRV_WGTMGR_RET_OK)
        {
            return ret;
        }
        cntx_p->dwgt_status[id] = SRV_WGTMGR_WGT_STATUS_ENABLED;
    }
    srv_wgtmgr_save_nvram_lid();
    return SRV_WGTMGR_RET_OK;
 
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_disable_wgt
 * DESCRIPTION
 *  This function is used to disable a widget
 * PARAMETERS
 *  type:  [IN] The widget type
 *  id  :  [IN] The widget id
 * RETURNS
 *  The result of the operation
 *****************************************************************************/
S32 srv_wgtmgr_disable_wgt(srv_wgtmgr_wgt_type_enum type, S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (type == SRV_WGTMGR_WGT_TYPE_PHONE)
    {
    #ifdef __WGTMGR_MGR_PHONE_WIDGET__
        cntx_p->pwgt_status[id] = SRV_WGTMGR_WGT_STATUS_DISABLED;
    #endif	
    }
    else
    {
        MMI_ASSERT(id < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM);
        cntx_p->dwgt_status[id] = SRV_WGTMGR_WGT_STATUS_DISABLED;
        widget_unload_widget(id);
    }

    srv_wgtmgr_save_nvram_lid();
    return SRV_WGTMGR_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_wgt_num
 * DESCRIPTION
 *  This function is used to get number of widgets
 * PARAMETERS
 *  type : [IN] widget type
 * RETURNS
 *  The number of installed widgets
 *****************************************************************************/
S32 srv_wgtmgr_get_wgt_num(srv_wgtmgr_wgt_type_enum type)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (type == SRV_WGTMGR_WGT_TYPE_PHONE)
    {
    #ifdef __WGTMGR_MGR_PHONE_WIDGET__
        return SRV_WGTMGR_MAX_PHONE_WGT_NUM;
    #endif
    }
    else
    {
        U8 *dwgt_status_p = g_srv_wgtmgr_cntx_p->dwgt_status;	
        S32 i, num = 0;

        for (i = 0; i < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM; i++)
        {
            if (dwgt_status_p[i] == SRV_WGTMGR_WGT_STATUS_ENABLED ||
                dwgt_status_p[i] == SRV_WGTMGR_WGT_STATUS_DISABLED) 
      	    {
                num++;
            }
        }
		return num;
    }
    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_downloaded_wgt_list
 * DESCRIPTION
 *  This function is used to get total number of widgets
 * PARAMETERS
 *  type : [IN] widget type
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_get_downloaded_wgt_list(S32 *list)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    S32 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    for (i = 0; i < srv_wgtmgr_get_wgt_num(SRV_WGTMGR_WGT_TYPE_DOWNLOADED); i++)
    {
        list[i] = cntx_p->asm_data->sort_id_list[i];
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_enabled_wgt_num
 * DESCRIPTION
 *
 * PARAMETERS
 * 
 * RETURNS
 *
 *****************************************************************************/
S32 srv_wgtmgr_get_enabled_wgt_num(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    return srv_wgtmgr_get_enabled_wgt_int(NULL);
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_enabled_wgt_list
 * DESCRIPTION
 *
 * PARAMETERS
 * 
 * RETURNS
 *
 *****************************************************************************/
void srv_wgtmgr_get_enabled_wgt_list(srv_wgtmgr_wgt_list_struct *list_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    srv_wgtmgr_get_enabled_wgt_int(list_ptr);  
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_enabled_wgt_num
 * DESCRIPTION
 *
 * PARAMETERS
 * 
 * RETURNS
 *
 *****************************************************************************/
S32 srv_wgtmgr_get_mainmenu_wgt_num(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

#ifdef __WGTMGR_MAIN_MENU_SUPPORT__
    return srv_wgtmgr_get_mainmenu_wgt_int(NULL);
#else
    return 0;
#endif
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_enabled_wgt_list
 * DESCRIPTION
 *
 * PARAMETERS
 * 
 * RETURNS
 *
 *****************************************************************************/
void srv_wgtmgr_get_mainmenu_wgt_list(mmi_app_package_name_struct *list_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
#ifdef __WGTMGR_MAIN_MENU_SUPPORT__
    srv_wgtmgr_get_mainmenu_wgt_int(list_ptr);  
#else
    return ;
#endif
}



/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_downloaded_wgt_name
 * DESCRIPTION
 *  This function is used to get downloaded widget name
 * PARAMETERS
 *  id : [IN] widget id
 *  name : [OUT] buffer to store widget name
 *  size : [IN] size of buffer in byte
 * RETURNS
 *  MMI_TRUE if get name 
 *****************************************************************************/
MMI_BOOL srv_wgtmgr_get_downloaded_wgt_name(S32 id, WCHAR *name, S32 size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 offset = 0;
    FS_HANDLE fd;
    U32 read;    
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (id >= SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM)
    {
        ASSERT(0);
    }

    fd = FS_Open(g_srv_wgtmgr_name_data, FS_READ_ONLY);
    if (fd >= 0)
    {
        offset = sizeof(WCHAR) * id * (SRV_WGTMGR_MAX_WGT_NAME_LEN + 1);
        FS_Seek(fd, offset, FS_FILE_BEGIN);
        FS_Read(fd, name, size, &read);
        FS_Close(fd);
		return MMI_TRUE;
    }
    return MMI_FALSE;
}

#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef __WGTMGR_MGR_PHONE_WIDGET__
/* under construction !*/
/* under construction !*/
#endif
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#ifdef __WGTMGR_MGR_PHONE_WIDGET__
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif		
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_wgt_info
 * DESCRIPTION
 *  This is used to get the information of a widget for displaying on Widget Manager App
 * PARAMETERS
 *  type: [IN]  The widget type
 *  id  : [IN]  The widget id
 *  info: [OUT] The widget information
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_get_phone_wgt_info(S32 id, srv_wgtmgr_phone_wgt_info_struct *info)
{
#ifdef __WGTMGR_MGR_PHONE_WIDGET__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    S32 phone_wgt_id;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    phone_wgt_id = cntx_p->pwgt_id[id];
    info->name = vadp_p2v_hs_widget_get_name(phone_wgt_id);
    info->enabled = (cntx_p->pwgt_status[id] == SRV_WGTMGR_WGT_STATUS_ENABLED) ? MMI_TRUE : MMI_FALSE;
    info->attribute = 0;      
    if (vadp_p2v_hs_widget_need_network(phone_wgt_id) == MMI_TRUE)
   	{
        info->attribute |= SRV_WGTMGR_ATTR_NETWORK_ACCESS;
    }
#endif		
}




/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_downloaded_wgt_info
 * DESCRIPTION
 *  This is used to get the information of a widget for displaying on Widget Manager App
 * PARAMETERS
 *  type: [IN]  The widget type
 *  id  : [IN]  The widget id
 *  info: [OUT] The widget information
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_get_downloaded_wgt_info(S32 id, srv_wgtmgr_downloaded_wgt_info_struct *info)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    srv_wgtmgr_wgt_asm_data_struct *asm_data_p = cntx_p->asm_data;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    MMI_ASSERT(cntx_p->is_start == MMI_TRUE);

    MMI_ASSERT(cntx_p->dwgt_status[id] == SRV_WGTMGR_WGT_STATUS_ENABLED ||
        cntx_p->dwgt_status[id] == SRV_WGTMGR_WGT_STATUS_DISABLED);

    info->attribute = asm_data_p->dwgt[id].attribute;
    info->enabled = (cntx_p->dwgt_status[id] == SRV_WGTMGR_WGT_STATUS_ENABLED) ? MMI_TRUE : MMI_FALSE;

    kal_wsprintf(info->size, "%d KB", asm_data_p->dwgt[id].size);
    MMI_ASSERT(app_ucs2_strlen((kal_int8 *)info->size) <= SRV_WGTMGR_MAX_WGT_SIZE_LEN);

    app_ucs2_strncpy((kal_int8 *)info->version, (const kal_int8 *)asm_data_p->version[id], SRV_WGTMGR_MAX_WGT_VERSION_LEN);
    info->version[SRV_WGTMGR_MAX_WGT_VERSION_LEN] = '\0';

    app_ucs2_strncpy((kal_int8 *)info->name, (const kal_int8 *)asm_data_p->dwgt_name[id], SRV_WGTMGR_MAX_WGT_NAME_LEN);
    info->name[SRV_WGTMGR_MAX_WGT_NAME_LEN] = '\0';

    info->install_time = asm_data_p->dwgt[id].install_time;
}



/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_is_wgt_enabled
 * DESCRIPTION
 *  This function is used to check if a widget is enabled
 * PARAMETERS
 *  type: [IN] the type of widget
 *  id: [IN] the index of widget
 * RETURNS
 *  MMI_TRUE if the widget is enabled
 *****************************************************************************/
MMI_BOOL srv_wgtmgr_is_wgt_enabled(srv_wgtmgr_wgt_type_enum type, S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/ 
    if (type == SRV_WGTMGR_WGT_TYPE_PHONE)
    {
    #ifdef __WGTMGR_MGR_PHONE_WIDGET__
        if(cntx_p->pwgt_status[id] == SRV_WGTMGR_WGT_STATUS_ENABLED)
        {
            return MMI_TRUE;
        }
    #endif
   	}
    else if (type == SRV_WGTMGR_WGT_TYPE_DOWNLOADED)    
    {
        if(cntx_p->dwgt_status[id] == SRV_WGTMGR_WGT_STATUS_ENABLED)
        {
            return MMI_TRUE;
        }
    }
    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_phone_wgt_icon_id
 * DESCRIPTION
 *  This is used to get the information of a widget for displaying on Widget Manager App
 * PARAMETERS
 *  type: [IN]  The widget type
 *  id  : [OUT] The widget information
 * RETURNS
 *  void
 *****************************************************************************/
MMI_BOOL srv_wgtmgr_get_phone_wgt_icon_id(S32 index, S32 *id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __WGTMGR_MGR_PHONE_WIDGET__
    *id = vadp_p2v_hs_widget_get_icon(g_srv_wgtmgr_cntx_p->pwgt_id[index]);
    return MMI_TRUE;
#else
    return MMI_FALSE;
#endif
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_downloaded_wgt_icon_path
 * DESCRIPTION
 *  This is used to get the icon path of a downloaded widget by instance id
 * PARAMETERS
 *  id : [IN]  The instance id of the downloaded widget
 *  path        : [OUT] The path of icon
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_get_downloaded_wgt_icon_path(S32 id, WCHAR *path)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    srv_wgtmgr_get_path(id, SRV_WGTMGR_PATH_ICON_DISPLAY, path);
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_downloaded_widget_idle_view_size
 * DESCRIPTION
 *  This is used to get the idle view size of a downloaded widget by instance id
 * PARAMETERS
 *  id : [IN]  The instance id of the downloaded widget
 *  width       : [OUT] The width of idle view
 *  height      : [OUT] The height of idle view
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_get_downloaded_widget_idle_view_size(S32 id, S32 *width, S32 *height)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_wgt_item_struct wgt_info;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_read_wgt_info_from_nvram_by_id(id, &wgt_info);
    *width = wgt_info.idle_width;
    *height = wgt_info.idle_height;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgt_get_downloaded_widget_max_resolution
 * DESCRIPTION
 *  This is used to get the max. resolution of a downloaded widget by instance id
 * PARAMETERS
 *  id : [IN]  The instance id of the downloaded widget
 * RETURNS
 *  U8
 *
 *****************************************************************************/
U8 srv_wgt_get_downloaded_widget_max_resolution(S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_wgt_item_struct wgt_info;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_read_wgt_info_from_nvram_by_id(id, &wgt_info);
    return wgt_info.max_resolution;
}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_is_memcard_available
 * DESCRIPTION
 *  This is the function to check memory card status
 * PARAMETERS
 *  void
 * RETURNS
 *  MMI_TRUE if memory card is available
 *****************************************************************************/
MMI_BOOL srv_wgtmgr_is_memcard_available(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 ret;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    ret = FS_GetDevStatus(SRV_FMGR_CARD_DRV, FS_MOUNT_STATE_ENUM);
    if ( ret == FS_NO_ERROR || ret == FS_DEVICE_BUSY )
    {
        return MMI_TRUE;
    }
    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_is_wgt_setting_available
 * DESCRIPTION
 *  This is used to check if setting is available for a widget
 * PARAMETERS
 *  instance_id : [IN]  The instance id of the downloaded widget
 * RETURNS
 *  MMI_TRUE if yes, MMI_FALSE if not
 *****************************************************************************/
MMI_BOOL srv_wgtmgr_is_wgt_setting_available(S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    WCHAR path[50];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    srv_wgtmgr_get_path(id, SRV_WGTMGR_PATH_OPTIONS_FILE, path);

    if (FS_GetAttributes(path) >= 0)
   	{
        return MMI_TRUE;
    }
    return MMI_FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_check_data_account
 * DESCRIPTION
 *  This function is used to check the data account validity
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_check_data_account(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
//#ifdef __COSMOS_MMI_PACKAGE__
    srv_dtcnt_sim_type_enum sim;
//#endif
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (srv_wgtmgr_dtcnt_ready_check(srv_wgtmgr_dtcnt_ready_callback) == MMI_TRUE)
    {
        srv_wgtmgr_dtcnt_ready_callback();
    }
//#ifdef __COSMOS_MMI_PACKAGE__
    if (srv_dtcnt_get_sim_preference(&sim) == MMI_TRUE)
    {
        if (sim == SRV_DTCNT_SIM_TYPE_1)
        {
            g_srv_wgtmgr_cntx_p->preferred_sim = SRV_WGTMGR_SIM1;
        }
        else if (sim == SRV_DTCNT_SIM_TYPE_2)
        {
            g_srv_wgtmgr_cntx_p->preferred_sim = SRV_WGTMGR_SIM2;
        }
        else if (sim == SRV_DTCNT_SIM_TYPE_3)
        {
            g_srv_wgtmgr_cntx_p->preferred_sim = SRV_WGTMGR_SIM3;
        }
        else if (sim == SRV_DTCNT_SIM_TYPE_4)
        {
            g_srv_wgtmgr_cntx_p->preferred_sim = SRV_WGTMGR_SIM4;
        }
    }
//#endif    
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_data_account
 * DESCRIPTION
 *  This function is used to query the data account index of installed widgets
 * PARAMETERS
 *  void
 * RETURNS
 *  The data account index of installed widgets
 *****************************************************************************/
U32 srv_wgtmgr_get_data_account(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
#ifdef __COSMOS_MMI_PACKAGE__
    if (cntx_p->wifi_only == KAL_TRUE)
    {
        return cbm_encode_data_account_id(CBM_WIFI_ACCT_ID, CBM_SIM_ID_SIM1, cntx_p->da_app_id, KAL_FALSE);
    }
#endif

    gadget_adp_log_prompt_trace("[Get]widget account id [%d]: %d", 
        g_srv_wgtmgr_cntx_p->preferred_sim, cntx_p->data_account[g_srv_wgtmgr_cntx_p->preferred_sim]);

    return cntx_p->data_account[g_srv_wgtmgr_cntx_p->preferred_sim];
}



/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_default_data_account
 * DESCRIPTION
 *  This is used to get default data account of installed widgets.
 * PARAMETERS
 *  sim: [IN] sim id
 * RETURNS
 *  data account
 *****************************************************************************/
U32 srv_wgtmgr_get_default_data_account(srv_wgtmgr_sim_enum sim)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (srv_wgtmgr_dtcnt_ready_check(srv_wgtmgr_dtcnt_ready_callback) == MMI_TRUE)
    {
        srv_wgtmgr_dtcnt_ready_callback();
    }

    return g_srv_wgtmgr_cntx_p->data_account[sim];
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_set_default_data_account
 * DESCRIPTION
 *  This is used to set data account of installed widgets.
 * PARAMETERS
 *  sim: [IN] sim id
 *  account_id: [IN] data account id
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_set_default_data_account(srv_wgtmgr_sim_enum sim, U32 account_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 temp;
    S16 error;
    U16 nvram_id_first = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_FIRST, nvram_id_last = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_LAST;
 	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    
    if (g_srv_wgtmgr_cntx_p->data_account[sim] != account_id)
    {
        g_srv_wgtmgr_cntx_p->data_account[sim] = account_id;

        if (sim == SRV_WGTMGR_SIM1)
        {
            nvram_id_first = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_FIRST;
            nvram_id_last = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_LAST;
        }
        else if (sim == SRV_WGTMGR_SIM2)
        {
            nvram_id_first = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_2_FIRST;
            nvram_id_last = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_2_LAST;
        }
        else if (sim == SRV_WGTMGR_SIM3)
        {
            nvram_id_first = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_3_FIRST;
            nvram_id_last = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_3_LAST;
        }
        else if (sim == SRV_WGTMGR_SIM4)
        {
            nvram_id_first = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_4_FIRST;
            nvram_id_last = NVRAM_WGTMGR_WGT_DATA_ACCOUNT_4_LAST;
        }
        else
        {
            ASSERT(0);
        }

        temp = account_id >> 16;
        WriteValue(nvram_id_first, &temp, DS_SHORT, &error);

        temp = account_id << 16 >> 16;
        WriteValue(nvram_id_last, &temp, DS_SHORT, &error);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_set_data_account
 * DESCRIPTION
 *  This is used to set data account of installed widgets.
 * PARAMETERS
 *  index: [IN] data account index
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_set_data_account(U32 index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    srv_wgtmgr_set_default_data_account(SRV_WGTMGR_SIM1, index);
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_network_access
 * DESCRIPTION
 *  This function is used to query the network access setting of installed widgets
 * PARAMETERS
 *  void
 * RETURNS
 *  The network acess setting of installed widgets
 *****************************************************************************/
srv_wgtmgr_network_access_enum srv_wgtmgr_get_network_access(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    return (srv_wgtmgr_network_access_enum)g_srv_wgtmgr_cntx_p->network_access;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_set_network_access
 * DESCRIPTION
 *  This is used to set network access setting of installed widgets.
 * PARAMETERS
 *  index: [IN] network access setting
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_set_network_access(srv_wgtmgr_network_access_enum index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 temp = (U8)index;
    S16 error;
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (g_srv_wgtmgr_cntx_p->network_access != index)
    {
        g_srv_wgtmgr_cntx_p->network_access = index;
        WriteValue(NVRAM_WGTMGR_WGT_NETWORK_ACCESS, &temp, DS_BYTE, &error);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_set_wifi_only
 * DESCRIPTION
 *  This function is used to set if widgets connect network with WiFi only
 * PARAMETERS
 *  wifi_only : [IN]
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_set_wifi_only(MMI_BOOL wifi_only)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 temp = (U8)wifi_only;
    S16 error;
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (g_srv_wgtmgr_cntx_p->wifi_only != wifi_only)
    {
        g_srv_wgtmgr_cntx_p->wifi_only = wifi_only;
        WriteValue(NVRAM_WGTMGR_WIFI_ONLY, &temp, DS_BYTE, &error);
    }
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_is_wifi_only
 * DESCRIPTION
 *  This function is used to query if widgets connect network with WiFi only
 * PARAMETERS
 *  void
 * RETURNS
 *  MMI_BOOL
 *****************************************************************************/
MMI_BOOL srv_wgtmgr_is_wifi_only(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    return g_srv_wgtmgr_cntx_p->wifi_only;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_sort_order
 * DESCRIPTION
 *  This is used to get sort order of installed widgets.
 * PARAMETERS
 *  void
 * RETURNS
 *  sort order
 *****************************************************************************/
srv_wgtmgr_sort_order_enum srv_wgtmgr_get_sort_order(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    return (srv_wgtmgr_sort_order_enum)g_srv_wgtmgr_cntx_p->sort_order;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_set_sort_order
 * DESCRIPTION
 *  This is used to set sort order of installed widgets.
 * PARAMETERS
 *  index: [IN] the index of sort order
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_set_sort_order(srv_wgtmgr_sort_order_enum index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 temp = (U8)index;
    S16 error;
	
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    if (g_srv_wgtmgr_cntx_p->sort_order != index)
    {
        g_srv_wgtmgr_cntx_p->sort_order = index; 
        WriteValue(NVRAM_WGTMGR_WGT_SORT_ORDER, &temp, DS_BYTE, &error);
#ifdef __PLUTO_MMI_PACKAGE__
        srv_wgtmgr_sort_wgt();
#endif
	}		    
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_da_app_id
 * DESCRIPTION
 *   This is used to get data account app id of widget manager.
 * PARAMETERS
 *   void
 * RETURNS
 *   U8 data account app id
 *****************************************************************************/
U8 srv_wgtmgr_get_da_app_id(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/    
    return g_srv_wgtmgr_cntx_p->da_app_id;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_fmgr_notify_hdlr
 * DESCRIPTION
 *  the handler for file manager events
 * PARAMETERS
 *  param : [IN] event
 * RETURNS
 *  MMI_RET
 *****************************************************************************/
mmi_ret srv_wgtmgr_fmgr_notify_hdlr(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch(param->evt_id)
    {
        case EVT_ID_SRV_FMGR_NOTIFICATION_DEV_PLUG_IN:
        {
            srv_wgtmgr_recover_gadget_folder();
            srv_wgtmgr_memcard_insert_hdlr();
            break;
        }

        case EVT_ID_SRV_FMGR_NOTIFICATION_DEV_PLUG_OUT:
        {
            srv_fmgr_notification_dev_plug_event_struct *event = (srv_fmgr_notification_dev_plug_event_struct *)param;
            U32 i;

            for (i = 0; i < event->count; i++)
            {
                if (event->drv_letters[i] == cntx_p->memcard_drive)
                {
                    srv_wgtmgr_unload_and_disable_all_downloaded_wgt(SRV_WGTMGR_DRIVE_MEMORY_CARD);
                }
            }
            break;
        }

        case EVT_ID_SRV_FMGR_NOTIFICATION_FORMAT:
        {
            srv_fmgr_notification_format_event_struct *event = (srv_fmgr_notification_format_event_struct *)param;
            if (event->state == SRV_FMGR_NOTIFICATION_STATE_AFTER)
            {
                srv_wgtmgr_recover_gadget_folder();
                srv_wgtmgr_check_all_downloaded_wgt();
            }
            break;
        }
    }
	
    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_dtcnt_notify_hdlr
 * DESCRIPTION
 *  check data account status 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
mmi_ret srv_wgtmgr_dtcnt_notify_hdlr(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    cbm_account_info_struct info;
    U32 h, i, j;
    cbm_sim_id_enum cbm_sim[] ={CBM_SIM_ID_SIM1, CBM_SIM_ID_SIM2, CBM_SIM_ID_SIM3, CBM_SIM_ID_SIM4};

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (param->evt_id == EVT_ID_SRV_DTCNT_SIM_PREFERENCE_UPDATE_IND)
    {
        srv_dtcnt_sim_preference_update_ind_evt_struct *event = (srv_dtcnt_sim_preference_update_ind_evt_struct *)param;
        if (event->sim_id == SRV_DTCNT_SIM_TYPE_1)
        {
            cntx_p->preferred_sim = SRV_WGTMGR_SIM1;
        }
        else if (event->sim_id == SRV_DTCNT_SIM_TYPE_2)
        {
            cntx_p->preferred_sim = SRV_WGTMGR_SIM2;
        }
        else if (event->sim_id == SRV_DTCNT_SIM_TYPE_3)
        {
            cntx_p->preferred_sim = SRV_WGTMGR_SIM3;
        }
        else if (event->sim_id == SRV_DTCNT_SIM_TYPE_4)
        {
            cntx_p->preferred_sim = SRV_WGTMGR_SIM4;
        }        
        return MMI_RET_OK;
    }


    for (h = 0; h < SRV_WGTMGR_SIM_NUM; h++)
    {
        if (cbm_decode_data_account_id_ext(cntx_p->data_account[h], &info) == CBM_OK)
        {
            switch(param->evt_id)
            {
                case EVT_ID_SRV_DTCNT_ACCT_DELETE_IND:
                {
                    srv_dtcnt_acct_delete_ind_evt_struct *event = (srv_dtcnt_acct_delete_ind_evt_struct *)param;

                    for (i = 0; i < info.acct_num; i++)
                    {
                        for (j = 0; j < event->del_num; j++)
                        {
                            if (event->acc_id[j] == info.account[i].account_id)
                            {
                                U32 account_id = cbm_encode_data_account_id(
                                                         CBM_DEFAULT_ACCT_ID,
                                                         cbm_sim[h],
                                                         cntx_p->da_app_id,
                                                         KAL_FALSE);
                                srv_wgtmgr_set_default_data_account(h, account_id);
                            }
                        }
                    }
                }
                break;

                case EVT_ID_SRV_DTCNT_ACCT_UPDATE_IND:			
                {
                    srv_dtcnt_acct_update_ind_evt_struct *event = (srv_dtcnt_acct_update_ind_evt_struct *)param;

                    for (i = 0; i < info.acct_num; i++)
                    {
                        if (event->acc_id == info.account[i].account_id && event->cause ==  1)
                        {
                            srv_dtcnt_bearer_enum bearer = srv_dtcnt_get_bearer_type(event->acc_id, SRV_DTCNT_ACCOUNT_PRIMARY);
                            if (bearer != SRV_DTCNT_BEARER_GPRS && bearer != SRV_DTCNT_BEARER_WIFI)
                            {
                                U32 account_id = cbm_encode_data_account_id(
                                                 CBM_DEFAULT_ACCT_ID,
                                                 cbm_sim[h], 
                                                 cntx_p->da_app_id, 
                                                 KAL_FALSE);
                                srv_wgtmgr_set_default_data_account(h, account_id);
                            }
                        }
                    }
                }
                break;
            }
        }         
    }
    return MMI_RET_OK;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_usb_notify_hdlr
 * DESCRIPTION
 *  check memory 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
mmi_ret srv_wgtmgr_usb_notify_hdlr(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __MMI_USB_SUPPORT__
    switch(param->evt_id)
    {
        case EVT_ID_USB_EXIT_MS_MODE:
        {
            srv_wgtmgr_recover_gadget_folder();
            srv_wgtmgr_check_all_downloaded_wgt();
            break;
        }
    }
#endif	
    return MMI_RET_OK;
}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_bearer_event_notify_hdlr
 * DESCRIPTION
 *  check memory 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
mmi_ret srv_wgtmgr_bearer_event_notify_hdlr(mmi_event_struct *param)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_cbm_bearer_event_struct *event = (srv_cbm_bearer_event_struct *)param;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch(event->type)
    {
        case SRV_CBM_BEARER_EVENT_DISCONNECT:
        {
            gadget_adp_log_prompt_trace("widget received [SRV_CBM_BEARER_EVENT_DISCONNECT]");

            srv_wgtmgr_release_bearer();
            
            srv_wgtmgr_bearer_disconnect();
            break;
        }
        case SRV_CBM_BEARER_EVENT_SWITCH:
        {
            gadget_adp_log_prompt_trace("widget received [SRV_CBM_BEARER_EVENT_SWITCH]");

            srv_wgtmgr_bearer_switch(event->user_result, event->switch_type);
            break;
        }
    }
    return MMI_RET_OK;
}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_unload_and_disable_all_downloaded_wgt
 * DESCRIPTION
 *  unload and disable all downloaded widget installed in a particular drive 
 * PARAMETERS
 *  drive: [IN] the specified drive
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_unload_and_disable_all_downloaded_wgt(srv_wgtmgr_wgt_drive_enum drive)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    U8 *dwgt_status_p = cntx_p->dwgt_status;
    S32 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* if widget is installed in specified drive and active, unload and disable it */
    for (i = 0; i < SRV_WGTMGR_MAX_DOWNLOADED_WGT_NUM; i++)
    {
        if (cntx_p->dwgt_drive[i] == drive && dwgt_status_p[i] == SRV_WGTMGR_WGT_STATUS_ENABLED)
        {
            srv_wgtmgr_notify_evt_struct event;
            MMI_FRM_INIT_EVENT(&event, EVT_ID_SRV_WGTMGR_FILE_NOT_EXISTS_IND);
            event.id = i;
            MMI_FRM_CB_EMIT_POST_EVENT(&event);
        #ifdef __PLUTO_MMI_PACKAGE__
            dwgt_status_p[i] = SRV_WGTMGR_WGT_STATUS_DISABLED;
        #endif
        }
    }

#ifdef __PLUTO_MMI_PACKAGE__
    /* save widget status to nvram */
    srv_wgtmgr_save_wgt_status_to_nvram();
#endif
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_check_downloaded_wgt
 * DESCRIPTION
 *  this funciton is used to check a widget
 * PARAMETERS
 *  id: [IN] widget instance id
 * RETURNS
 *  error code
 *****************************************************************************/
srv_wgtmgr_result_enum srv_wgtmgr_check_downloaded_wgt(S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* if widget is installed in memory card which is not inserted now */
    if (srv_wgtmgr_check_downloaded_wgt_int(id) != SRV_WGTMGR_RET_OK)
    {
        if (cntx_p->dwgt_drive[id] == SRV_WGTMGR_DRIVE_MEMORY_CARD)
        {
            return SRV_WGTMGR_RET_MEMCARD_NOT_EXIST;
        }
        else
        {
            return SRV_WGTMGR_RET_FILE_NOT_EXIST;
        }
    }
    return SRV_WGTMGR_RET_OK;	
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_drive_letter
 * DESCRIPTION
 *  This is the function to get drive letter
 * PARAMETERS
 *  drive: [IN]
 * RETURNS
 *  drive letter
 *****************************************************************************/
char srv_wgtmgr_get_drive_letter(srv_wgtmgr_wgt_drive_enum drive)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;
    char letter;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (drive == SRV_WGTMGR_DRIVE_SYSTEM)
    {
        letter = cntx_p->system_drive;
    }
    else if (drive == SRV_WGTMGR_DRIVE_PUBLIC)
    {
        letter = cntx_p->public_drive;
    }
    else
    {
        letter = cntx_p->memcard_drive;
    }
    return letter;
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_exit_usb_mode_hdlr
 * DESCRIPTION
 *  This function is invoked when exiting USB mass storage mode
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_exit_usb_mode_hdlr(void)

{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    srv_wgtmgr_recover_gadget_folder();
    srv_wgtmgr_check_all_downloaded_wgt();
    /* set name and version data, because it might be wrongly produced when 
       phone is in USB mass storage mode */
    srv_wgtmgr_set_data_need_update(SRV_WGTMGR_UPDATE_NAME | SRV_WGTMGR_UPDATE_VERSION);
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_recover_gadget_folder
 * DESCRIPTION
 *  this funciton is to recover all gadget folders
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_recover_gadget_folder(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    WCHAR *buff;
    srv_wgtmgr_cntx_struct *cntx_p = g_srv_wgtmgr_cntx_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    buff = (WCHAR*)OslMalloc(sizeof(WCHAR) * 30);

    /* check @gadget */
    kal_wsprintf(buff, "%c:\\@gadget", cntx_p->public_drive);

    /* prevent the case that there is a file named @gadget */
    FS_Delete(buff);

    /* create if necessary */
    if (FS_GetAttributes((const WCHAR*)buff) < 0)
    {
        FS_CreateDir((const WCHAR*)buff);
    }
    FS_SetAttributes((const WCHAR*)buff, FS_ATTR_DIR | FS_ATTR_HIDDEN);

    /* check @gadget\\tmp */
    kal_wsprintf(buff, "%c:\\@gadget\\tmp", cntx_p->public_drive);    

    FS_Delete(buff);

    if(FS_GetAttributes((const WCHAR*)buff) < 0)
    {
        FS_CreateDir((const WCHAR*)buff);
    }
    FS_SetAttributes((const WCHAR*)buff, FS_ATTR_DIR | FS_ATTR_HIDDEN);

    kal_wsprintf(buff, "%c:\\@gadget", cntx_p->memcard_drive);

    /* prevent the case that there is a file named @gadget */
    FS_Delete(buff);

    if(FS_GetAttributes((const WCHAR*)buff) < 0)
    {
        FS_CreateDir((const WCHAR*)buff);
    }
    FS_SetAttributes((const WCHAR*)buff, FS_ATTR_DIR | FS_ATTR_HIDDEN);

    OslMfree(buff);
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_current_time_in_sec
 * DESCRIPTION
 *  this funciton is to get current time in sec
 * PARAMETERS
 *  void
 * RETURNS
 *  U32
 *****************************************************************************/
U32 srv_wgtmgr_get_current_time_in_sec(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    applib_time_struct time;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    applib_dt_get_secure_time(&time);
    return applib_dt_mytime_2_utc_sec(&time, KAL_FALSE);
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_downloaded_wgt_installed_drive
 * DESCRIPTION
 *  This function is used to get the drive where widget is installed
 * PARAMETERS
 *  id: [IN] the id of widget in query
 * RETURNS
 *  drive
 *****************************************************************************/
srv_wgtmgr_wgt_drive_enum srv_wgtmgr_get_downloaded_wgt_installed_drive(S32 id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return (srv_wgtmgr_wgt_drive_enum)g_srv_wgtmgr_cntx_p->dwgt_drive[id];
}


/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_is_preinstall_widget_finished
 * DESCRIPTION
 *  This function is used to check if widget preinstallation is finished
 * PARAMETERS
 *  void
 * RETURNS
 *  MMI_TRUE or MMI_FALSE
 *****************************************************************************/
MMI_BOOL srv_wgtmgr_is_preinstall_widget_finished()
{
#ifdef WIDGET_PREINSTALLATION_SUPPORT
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 done;
    S16 error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* pre-install widget */
    ReadValue(NVRAM_WGTMGR_PRE_INSTALL_DONE, &done, DS_BYTE, &error);
    if (done == 1)
    {
        return MMI_TRUE;
    }
    return MMI_FALSE;
#else
    return MMI_TRUE;
#endif
}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_get_engine_version
 * DESCRIPTION
 *  This function is used to get gadget engine version
 * PARAMETERS
 *  version: [Out] gadget engine version
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_get_engine_version(char *version)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    gadget_adp_mgr_get_engine_version(version);
}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_hold_bearer
 * DESCRIPTION
 *  This function is used to hold bearer connect
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_hold_bearer()
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    cbm_hold_bearer(g_srv_wgtmgr_cntx_p->da_app_id);
}

/*****************************************************************************
 * FUNCTION
 *  srv_wgtmgr_release_bearer
 * DESCRIPTION
 *  This function is used to release bearer connect
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void srv_wgtmgr_release_bearer()
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/

    cbm_release_bearer(g_srv_wgtmgr_cntx_p->da_app_id);
}



#endif /* __GADGET_SUPPORT__ */