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 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381
|
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app;
import static java.lang.Long.max;
import android.Manifest;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.app.usage.UsageStatsManager;
import android.compat.Compatibility;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledAfter;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.database.DatabaseUtils;
import android.media.AudioAttributes.AttributeUsage;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerExecutor;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Looper;
import android.os.PackageTagsList;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Process;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserManager;
import android.provider.DeviceConfig;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.LongSparseArray;
import android.util.LongSparseLongArray;
import android.util.Pools;
import android.util.SparseArray;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.Immutable;
import com.android.internal.app.IAppOpsActiveCallback;
import com.android.internal.app.IAppOpsAsyncNotedCallback;
import com.android.internal.app.IAppOpsCallback;
import com.android.internal.app.IAppOpsNotedCallback;
import com.android.internal.app.IAppOpsService;
import com.android.internal.app.IAppOpsStartedCallback;
import com.android.internal.app.MessageSamplingConfig;
import com.android.internal.os.RuntimeInit;
import com.android.internal.os.ZygoteInit;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.DataClass;
import com.android.internal.util.FrameworkStatsLog;
import com.android.internal.util.Parcelling;
import com.android.internal.util.Preconditions;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* App-ops are used for two purposes: Access control and tracking.
*
* <p>App-ops cover a wide variety of functionality from helping with runtime permissions access
* control and tracking to battery consumption tracking.
*
* <h2>Access control</h2>
*
* <p>App-ops can either be controlled for each uid or for each package. Which one is used depends
* on the API provider maintaining this app-op. For any security or privacy related app-op the
* provider needs to control the app-op for per uid as all security and privacy is based on uid in
* Android.
*
* <p>To control access the app-op can be set to a mode to:
* <dl>
* <dt>{@link #MODE_DEFAULT}
* <dd>Default behavior, might differ from app-op or app-op
* <dt>{@link #MODE_ALLOWED}
* <dd>Allow the access
* <dt>{@link #MODE_IGNORED}
* <dd>Don't allow the access, i.e. don't perform the requested action or return no or
* placeholder data
* <dt>{@link #MODE_ERRORED}
* <dd>Throw a {@link SecurityException} on access. This can be suppressed by using a
* {@code ...noThrow} method to check the mode
* </dl>
*
* <p>API providers need to check the mode returned by {@link #noteOp} if they are are allowing
* access to operations gated by the app-op. {@link #unsafeCheckOp} should be used to check the
* mode if no access is granted. E.g. this can be used for displaying app-op state in the UI or
* when checking the state before later calling {@link #noteOp} anyway.
*
* <p>If an operation refers to a time span (e.g. a audio-recording session) the API provider
* should use {@link #startOp} and {@link #finishOp} instead of {@link #noteOp}.
*
* <h3>Runtime permissions and app-ops</h3>
*
* <p>Each platform defined runtime permission (beside background modifiers) has an associated app
* op which is used for tracking but also to allow for silent failures. I.e. if the runtime
* permission is denied the caller gets a {@link SecurityException}, but if the permission is
* granted and the app-op is {@link #MODE_IGNORED} then the callers gets placeholder behavior, e.g.
* location callbacks would not happen.
*
* <h3>App-op permissions</h3>
*
* <p>App-ops permissions are platform defined permissions that can be overridden. The security
* check for app-op permissions should by {@link #MODE_DEFAULT default} check the permission grant
* state. If the app-op state is set to {@link #MODE_ALLOWED} or {@link #MODE_IGNORED} the app-op
* state should be checked instead of the permission grant state.
*
* <p>This functionality allows to grant access by default to apps fulfilling the requirements for
* a certain permission level. Still the behavior can be overridden when needed.
*
* <h2>Tracking</h2>
*
* <p>App-ops track many important events, including all accesses to runtime permission protected
* APIs. This is done by tracking when an app-op was {@link #noteOp noted} or
* {@link #startOp started}. The tracked data can only be read by system components.
*
* <p><b>Only {@link #noteOp}/{@link #startOp} are tracked; {@link #unsafeCheckOp} is not tracked.
* Hence it is important to eventually call {@link #noteOp} or {@link #startOp} when providing
* access to protected operations or data.</b>
*
* <p>Some apps are forwarding access to other apps. E.g. an app might get the location from the
* system's location provider and then send the location further to a 3rd app. In this case the
* app passing on the data needs to call {@link #noteProxyOp} to signal the access proxying. This
* might also make sense inside of a single app if the access is forwarded between two parts of
* the tagged with different attribution tags.
*
* <p>An app can register an {@link OnOpNotedCallback} to get informed about what accesses the
* system is tracking for it. As each runtime permission has an associated app-op this API is
* particularly useful for an app that want to find unexpected private data accesses.
*/
@SystemService(Context.APP_OPS_SERVICE)
public class AppOpsManager {
/**
* This is a subtle behavior change to {@link #startWatchingMode}.
*
* Before this change the system called back for the switched op. After the change the system
* will call back for the actually requested op or all switched ops if no op is specified.
*
* @hide
*/
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.Q)
public static final long CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE = 148180766L;
/**
* Enforce that all attributionTags send to {@link #noteOp}, {@link #noteProxyOp},
* and {@link #startOp} are defined in the manifest of the package that is specified as
* parameter to the methods.
*
* <p>To enable this change both the package calling {@link #noteOp} as well as the package
* specified as parameter to the method need to have this change enable.
*
* @hide
*/
@TestApi
@ChangeId
@EnabledAfter(targetSdkVersion = Build.VERSION_CODES.R)
public static final long SECURITY_EXCEPTION_ON_INVALID_ATTRIBUTION_TAG_CHANGE = 151105954L;
private static final String FULL_LOG = "privacy_attribution_tag_full_log_enabled";
private static final int MAX_UNFORWARDED_OPS = 10;
private static Boolean sFullLog = null;
final Context mContext;
@UnsupportedAppUsage
final IAppOpsService mService;
/**
* Service for the application context, to be used by static methods via
* {@link #getService()}
*/
@GuardedBy("sLock")
static IAppOpsService sService;
@GuardedBy("mModeWatchers")
private final ArrayMap<OnOpChangedListener, IAppOpsCallback> mModeWatchers =
new ArrayMap<>();
@GuardedBy("mActiveWatchers")
private final ArrayMap<OnOpActiveChangedListener, IAppOpsActiveCallback> mActiveWatchers =
new ArrayMap<>();
@GuardedBy("mStartedWatchers")
private final ArrayMap<OnOpStartedListener, IAppOpsStartedCallback> mStartedWatchers =
new ArrayMap<>();
@GuardedBy("mNotedWatchers")
private final ArrayMap<OnOpNotedListener, IAppOpsNotedCallback> mNotedWatchers =
new ArrayMap<>();
private static final Object sLock = new Object();
/** Current {@link OnOpNotedCallback}. Change via {@link #setOnOpNotedCallback} */
@GuardedBy("sLock")
private static @Nullable OnOpNotedCallback sOnOpNotedCallback;
/**
* Sync note-ops collected from {@link #readAndLogNotedAppops(Parcel)} that have not been
* delivered to a callback yet.
*
* Similar to {@link com.android.server.appop.AppOpsService#mUnforwardedAsyncNotedOps} for
* {@link COLLECT_ASYNC}. Used in situation when AppOpsManager asks to collect stacktrace with
* {@link #sMessageCollector}, which forces {@link COLLECT_SYNC} mode.
*/
@GuardedBy("sLock")
private static ArrayList<AsyncNotedAppOp> sUnforwardedOps = new ArrayList<>();
/**
* Additional collector that collect accesses and forwards a few of them them via
* {@link IAppOpsService#reportRuntimeAppOpAccessMessageAndGetConfig}.
*/
private static OnOpNotedCallback sMessageCollector =
new OnOpNotedCallback() {
@Override
public void onNoted(@NonNull SyncNotedAppOp op) {
reportStackTraceIfNeeded(op);
}
@Override
public void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp) {
// collected directly in AppOpsService
}
@Override
public void onSelfNoted(@NonNull SyncNotedAppOp op) {
reportStackTraceIfNeeded(op);
}
private void reportStackTraceIfNeeded(@NonNull SyncNotedAppOp op) {
if (!isCollectingStackTraces()) {
return;
}
MessageSamplingConfig config = sConfig;
if (leftCircularDistance(strOpToOp(op.getOp()), config.getSampledOpCode(),
_NUM_OP) <= config.getAcceptableLeftDistance()
|| config.getExpirationTimeSinceBootMillis()
< SystemClock.elapsedRealtime()) {
String stackTrace = getFormattedStackTrace();
try {
String packageName = ActivityThread.currentOpPackageName();
sConfig = getService().reportRuntimeAppOpAccessMessageAndGetConfig(
packageName == null ? "" : packageName, op, stackTrace);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
}
}
};
static IBinder sClientId;
/**
* How many seconds we want for a drop in uid state from top to settle before applying it.
*
* <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS}
*
* @hide
*/
@TestApi
public static final String KEY_TOP_STATE_SETTLE_TIME = "top_state_settle_time";
/**
* How many second we want for a drop in uid state from foreground to settle before applying it.
*
* <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS}
*
* @hide
*/
@TestApi
public static final String KEY_FG_SERVICE_STATE_SETTLE_TIME =
"fg_service_state_settle_time";
/**
* How many seconds we want for a drop in uid state from background to settle before applying
* it.
*
* <>Set a parameter to {@link android.provider.Settings.Global#APP_OPS_CONSTANTS}
*
* @hide
*/
@TestApi
public static final String KEY_BG_STATE_SETTLE_TIME = "bg_state_settle_time";
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "HISTORICAL_MODE_" }, value = {
HISTORICAL_MODE_DISABLED,
HISTORICAL_MODE_ENABLED_ACTIVE,
HISTORICAL_MODE_ENABLED_PASSIVE
})
public @interface HistoricalMode {}
/**
* Mode in which app op history is completely disabled.
* @hide
*/
@TestApi
public static final int HISTORICAL_MODE_DISABLED = 0;
/**
* Mode in which app op history is enabled and app ops performed by apps would
* be tracked. This is the mode in which the feature is completely enabled.
* @hide
*/
@TestApi
public static final int HISTORICAL_MODE_ENABLED_ACTIVE = 1;
/**
* Mode in which app op history is enabled but app ops performed by apps would
* not be tracked and the only way to add ops to the history is via explicit calls
* to dedicated APIs. This mode is useful for testing to allow full control of
* the historical content.
* @hide
*/
@TestApi
public static final int HISTORICAL_MODE_ENABLED_PASSIVE = 2;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "MODE_" }, value = {
MODE_ALLOWED,
MODE_IGNORED,
MODE_ERRORED,
MODE_DEFAULT,
MODE_FOREGROUND
})
public @interface Mode {}
/**
* Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is
* allowed to perform the given operation.
*/
public static final int MODE_ALLOWED = 0;
/**
* Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller is
* not allowed to perform the given operation, and this attempt should
* <em>silently fail</em> (it should not cause the app to crash).
*/
public static final int MODE_IGNORED = 1;
/**
* Result from {@link #checkOpNoThrow}, {@link #noteOpNoThrow}, {@link #startOpNoThrow}: the
* given caller is not allowed to perform the given operation, and this attempt should
* cause it to have a fatal error, typically a {@link SecurityException}.
*/
public static final int MODE_ERRORED = 2;
/**
* Result from {@link #checkOp}, {@link #noteOp}, {@link #startOp}: the given caller should
* use its default security check. This mode is not normally used; it should only be used
* with appop permissions, and callers must explicitly check for it and deal with it.
*/
public static final int MODE_DEFAULT = 3;
/**
* Special mode that means "allow only when app is in foreground." This is <b>not</b>
* returned from {@link #unsafeCheckOp}, {@link #noteOp}, {@link #startOp}. Rather,
* {@link #unsafeCheckOp} will always return {@link #MODE_ALLOWED} (because it is always
* possible for it to be ultimately allowed, depending on the app's background state),
* and {@link #noteOp} and {@link #startOp} will return {@link #MODE_ALLOWED} when the app
* being checked is currently in the foreground, otherwise {@link #MODE_IGNORED}.
*
* <p>The only place you will this normally see this value is through
* {@link #unsafeCheckOpRaw}, which returns the actual raw mode of the op. Note that because
* you can't know the current state of the app being checked (and it can change at any
* point), you can only treat the result here as an indication that it will vary between
* {@link #MODE_ALLOWED} and {@link #MODE_IGNORED} depending on changes in the background
* state of the app. You thus must always use {@link #noteOp} or {@link #startOp} to do
* the actual check for access to the op.</p>
*/
public static final int MODE_FOREGROUND = 4;
/**
* Flag for {@link #startWatchingMode(String, String, int, OnOpChangedListener)}:
* Also get reports if the foreground state of an op's uid changes. This only works
* when watching a particular op, not when watching a package.
*/
public static final int WATCH_FOREGROUND_CHANGES = 1 << 0;
/**
* Flag for {@link #startWatchingMode} that causes the callback to happen on the switch-op
* instead the op the callback was registered. (This simulates pre-R behavior).
*
* @hide
*/
public static final int CALL_BACK_ON_SWITCHED_OP = 1 << 1;
/**
* Flag to determine whether we should log noteOp/startOp calls to make sure they
* are correctly used
*
* @hide
*/
public static final boolean NOTE_OP_COLLECTION_ENABLED = false;
/**
* @hide
*/
public static final String[] MODE_NAMES = new String[] {
"allow", // MODE_ALLOWED
"ignore", // MODE_IGNORED
"deny", // MODE_ERRORED
"default", // MODE_DEFAULT
"foreground", // MODE_FOREGROUND
};
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = { "UID_STATE_" }, value = {
UID_STATE_PERSISTENT,
UID_STATE_TOP,
UID_STATE_FOREGROUND_SERVICE_LOCATION,
UID_STATE_FOREGROUND_SERVICE,
UID_STATE_FOREGROUND,
UID_STATE_BACKGROUND,
UID_STATE_CACHED
})
public @interface UidState {}
/**
* Uid state: The UID is a foreground persistent app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_PERSISTENT = 100;
/**
* Uid state: The UID is top foreground app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_TOP = 200;
/**
* Uid state: The UID is running a foreground service of location type.
* The lower the UID state the more important the UID is for the user.
* This uid state is a counterpart to PROCESS_STATE_FOREGROUND_SERVICE_LOCATION which has been
* deprecated.
* @hide
* @deprecated
*/
@SystemApi
@Deprecated
public static final int UID_STATE_FOREGROUND_SERVICE_LOCATION = 300;
/**
* Uid state: The UID is running a foreground service. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_FOREGROUND_SERVICE = 400;
/**
* Uid state: The UID is a foreground app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_FOREGROUND = 500;
/**
* The max, which is min priority, UID state for which any app op
* would be considered as performed in the foreground.
* @hide
*/
public static final int UID_STATE_MAX_LAST_NON_RESTRICTED = UID_STATE_FOREGROUND;
/**
* Uid state: The UID is a background app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_BACKGROUND = 600;
/**
* Uid state: The UID is a cached app. The lower the UID
* state the more important the UID is for the user.
* @hide
*/
@SystemApi
public static final int UID_STATE_CACHED = 700;
/**
* Uid state: The UID state with the highest priority.
* @hide
*/
public static final int MAX_PRIORITY_UID_STATE = UID_STATE_PERSISTENT;
/**
* Uid state: The UID state with the lowest priority.
* @hide
*/
public static final int MIN_PRIORITY_UID_STATE = UID_STATE_CACHED;
/**
* Resolves the first unrestricted state given an app op.
* @param op The op to resolve.
* @return The last restricted UID state.
*
* @hide
*/
public static int resolveFirstUnrestrictedUidState(int op) {
return UID_STATE_FOREGROUND;
}
/**
* Resolves the last restricted state given an app op.
* @param op The op to resolve.
* @return The last restricted UID state.
*
* @hide
*/
public static int resolveLastRestrictedUidState(int op) {
return UID_STATE_BACKGROUND;
}
/** @hide Note: Keep these sorted */
public static final int[] UID_STATES = {
UID_STATE_PERSISTENT,
UID_STATE_TOP,
UID_STATE_FOREGROUND_SERVICE_LOCATION,
UID_STATE_FOREGROUND_SERVICE,
UID_STATE_FOREGROUND,
UID_STATE_BACKGROUND,
UID_STATE_CACHED
};
/** @hide */
public static String getUidStateName(@UidState int uidState) {
switch (uidState) {
case UID_STATE_PERSISTENT:
return "pers";
case UID_STATE_TOP:
return "top";
case UID_STATE_FOREGROUND_SERVICE_LOCATION:
return "fgsvcl";
case UID_STATE_FOREGROUND_SERVICE:
return "fgsvc";
case UID_STATE_FOREGROUND:
return "fg";
case UID_STATE_BACKGROUND:
return "bg";
case UID_STATE_CACHED:
return "cch";
default:
return "unknown";
}
}
/**
* Flag: non proxy operations. These are operations
* performed on behalf of the app itself and not on behalf of
* another one.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_SELF = 0x1;
/**
* Flag: trusted proxy operations. These are operations
* performed on behalf of another app by a trusted app.
* Which is work a trusted app blames on another app.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_TRUSTED_PROXY = 0x2;
/**
* Flag: untrusted proxy operations. These are operations
* performed on behalf of another app by an untrusted app.
* Which is work an untrusted app blames on another app.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_UNTRUSTED_PROXY = 0x4;
/**
* Flag: trusted proxied operations. These are operations
* performed by a trusted other app on behalf of an app.
* Which is work an app was blamed for by a trusted app.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_TRUSTED_PROXIED = 0x8;
/**
* Flag: untrusted proxied operations. These are operations
* performed by an untrusted other app on behalf of an app.
* Which is work an app was blamed for by an untrusted app.
*
* @hide
*/
@SystemApi
public static final int OP_FLAG_UNTRUSTED_PROXIED = 0x10;
/**
* Flags: all operations. These include operations matched
* by {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}.
*
* @hide
*/
@SystemApi
public static final int OP_FLAGS_ALL =
OP_FLAG_SELF
| OP_FLAG_TRUSTED_PROXY
| OP_FLAG_UNTRUSTED_PROXY
| OP_FLAG_TRUSTED_PROXIED
| OP_FLAG_UNTRUSTED_PROXIED;
/**
* Flags: all trusted operations which is ones either the app did {@link #OP_FLAG_SELF},
* or it was blamed for by a trusted app {@link #OP_FLAG_TRUSTED_PROXIED}, or ones the
* app if untrusted blamed on other apps {@link #OP_FLAG_UNTRUSTED_PROXY}.
*
* @hide
*/
@SystemApi
public static final int OP_FLAGS_ALL_TRUSTED = AppOpsManager.OP_FLAG_SELF
| AppOpsManager.OP_FLAG_UNTRUSTED_PROXY
| AppOpsManager.OP_FLAG_TRUSTED_PROXIED;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "FLAG_" }, value = {
OP_FLAG_SELF,
OP_FLAG_TRUSTED_PROXY,
OP_FLAG_UNTRUSTED_PROXY,
OP_FLAG_TRUSTED_PROXIED,
OP_FLAG_UNTRUSTED_PROXIED
})
public @interface OpFlags {}
/** @hide */
public static final String getFlagName(@OpFlags int flag) {
switch (flag) {
case OP_FLAG_SELF:
return "s";
case OP_FLAG_TRUSTED_PROXY:
return "tp";
case OP_FLAG_UNTRUSTED_PROXY:
return "up";
case OP_FLAG_TRUSTED_PROXIED:
return "tpd";
case OP_FLAG_UNTRUSTED_PROXIED:
return "upd";
default:
return "unknown";
}
}
/**
* Attribution chain flag: specifies that this is the accessor. When
* an app A accesses the data that is then passed to app B that is then
* passed to C, we call app A accessor, app B intermediary, and app C
* receiver. If A accesses the data for itself, then it is the accessor
* and the receiver.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_FLAG_ACCESSOR = 0x1;
/**
* Attribution chain flag: specifies that this is the intermediary. When
* an app A accesses the data that is then passed to app B that is then
* passed to C, we call app A accessor, app B intermediary, and app C
* receiver. If A accesses the data for itself, then it is the accessor
* and the receiver.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_FLAG_INTERMEDIARY = 0x2;
/**
* Attribution chain flag: specifies that this is the receiver. When
* an app A accesses the data that is then passed to app B that is then
* passed to C, we call app A accessor, app B intermediary, and app C
* receiver. If A accesses the data for itself, then it is the accessor
* and the receiver.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_FLAG_RECEIVER = 0x4;
/**
* Attribution chain flag: Specifies that all attribution sources in the chain were trusted.
* Must only be set by system server.
* @hide
*/
public static final int ATTRIBUTION_FLAG_TRUSTED = 0x8;
/**
* No attribution flags.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_FLAGS_NONE = 0x0;
/**
* No attribution chain id.
* @hide
*/
@TestApi
public static final int ATTRIBUTION_CHAIN_ID_NONE = -1;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "FLAG_" }, value = {
ATTRIBUTION_FLAG_ACCESSOR,
ATTRIBUTION_FLAG_INTERMEDIARY,
ATTRIBUTION_FLAG_RECEIVER,
ATTRIBUTION_FLAG_TRUSTED
})
public @interface AttributionFlags {}
// These constants are redefined here to work around a metalava limitation/bug where
// @IntDef is not able to see @hide symbols when they are hidden via package hiding:
// frameworks/base/core/java/com/android/internal/package.html
/** @hide */
public static final int SAMPLING_STRATEGY_DEFAULT =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__DEFAULT;
/** @hide */
public static final int SAMPLING_STRATEGY_UNIFORM =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__UNIFORM;
/** @hide */
public static final int SAMPLING_STRATEGY_RARELY_USED =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__RARELY_USED;
/** @hide */
public static final int SAMPLING_STRATEGY_BOOT_TIME_SAMPLING =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__BOOT_TIME_SAMPLING;
/** @hide */
public static final int SAMPLING_STRATEGY_UNIFORM_OPS =
FrameworkStatsLog.RUNTIME_APP_OP_ACCESS__SAMPLING_STRATEGY__UNIFORM_OPS;
/**
* Strategies used for message sampling
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"SAMPLING_STRATEGY_"}, value = {
SAMPLING_STRATEGY_DEFAULT,
SAMPLING_STRATEGY_UNIFORM,
SAMPLING_STRATEGY_RARELY_USED,
SAMPLING_STRATEGY_BOOT_TIME_SAMPLING,
SAMPLING_STRATEGY_UNIFORM_OPS
})
public @interface SamplingStrategy {}
private static final int UID_STATE_OFFSET = 31;
private static final int FLAGS_MASK = 0xFFFFFFFF;
/**
* Key for a data bucket storing app op state. The bucket
* is composed of the uid state and state flags. This way
* we can query data for given uid state and a set of flags where
* the flags control which type of data to get. For example,
* one can get the ops an app did on behalf of other apps
* while in the background.
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD})
public @interface DataBucketKey {
}
/** @hide */
public static String keyToString(@DataBucketKey long key) {
final int uidState = extractUidStateFromKey(key);
final int flags = extractFlagsFromKey(key);
return "[" + getUidStateName(uidState) + "-" + flagsToString(flags) + "]";
}
/** @hide */
public static @DataBucketKey long makeKey(@UidState int uidState, @OpFlags int flags) {
return ((long) uidState << UID_STATE_OFFSET) | flags;
}
/** @hide */
public static int extractUidStateFromKey(@DataBucketKey long key) {
return (int) (key >> UID_STATE_OFFSET);
}
/** @hide */
public static int extractFlagsFromKey(@DataBucketKey long key) {
return (int) (key & FLAGS_MASK);
}
/** @hide */
public static String flagsToString(@OpFlags int flags) {
final StringBuilder flagsBuilder = new StringBuilder();
while (flags != 0) {
final int flag = 1 << Integer.numberOfTrailingZeros(flags);
flags &= ~flag;
if (flagsBuilder.length() > 0) {
flagsBuilder.append('|');
}
flagsBuilder.append(getFlagName(flag));
}
return flagsBuilder.toString();
}
// when adding one of these:
// - increment _NUM_OP
// - define an OPSTR_* constant (marked as @SystemApi)
// - add rows to sOpToSwitch, sOpToString, sOpNames, sOpPerms, sOpDefaultMode, sOpDisableReset,
// sOpRestrictions, sOpAllowSystemRestrictionBypass
// - add descriptive strings to Settings/res/values/arrays.xml
// - add the op to the appropriate template in AppOpsState.OpsTemplate (settings app)
/** @hide No operation specified. */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int OP_NONE = AppProtoEnums.APP_OP_NONE;
/** @hide Access to coarse location information. */
@UnsupportedAppUsage
@TestApi
public static final int OP_COARSE_LOCATION = AppProtoEnums.APP_OP_COARSE_LOCATION;
/** @hide Access to fine location information. */
@UnsupportedAppUsage
public static final int OP_FINE_LOCATION = AppProtoEnums.APP_OP_FINE_LOCATION;
/** @hide Causing GPS to run. */
@UnsupportedAppUsage
public static final int OP_GPS = AppProtoEnums.APP_OP_GPS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_VIBRATE = AppProtoEnums.APP_OP_VIBRATE;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_CONTACTS = AppProtoEnums.APP_OP_READ_CONTACTS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_CONTACTS = AppProtoEnums.APP_OP_WRITE_CONTACTS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_CALL_LOG = AppProtoEnums.APP_OP_READ_CALL_LOG;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_CALL_LOG = AppProtoEnums.APP_OP_WRITE_CALL_LOG;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_CALENDAR = AppProtoEnums.APP_OP_READ_CALENDAR;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_CALENDAR = AppProtoEnums.APP_OP_WRITE_CALENDAR;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WIFI_SCAN = AppProtoEnums.APP_OP_WIFI_SCAN;
/** @hide */
@UnsupportedAppUsage
public static final int OP_POST_NOTIFICATION = AppProtoEnums.APP_OP_POST_NOTIFICATION;
/** @hide */
@UnsupportedAppUsage
public static final int OP_NEIGHBORING_CELLS = AppProtoEnums.APP_OP_NEIGHBORING_CELLS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_CALL_PHONE = AppProtoEnums.APP_OP_CALL_PHONE;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_SMS = AppProtoEnums.APP_OP_READ_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_SMS = AppProtoEnums.APP_OP_WRITE_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_RECEIVE_SMS = AppProtoEnums.APP_OP_RECEIVE_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_RECEIVE_EMERGECY_SMS =
AppProtoEnums.APP_OP_RECEIVE_EMERGENCY_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_RECEIVE_MMS = AppProtoEnums.APP_OP_RECEIVE_MMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_RECEIVE_WAP_PUSH = AppProtoEnums.APP_OP_RECEIVE_WAP_PUSH;
/** @hide */
@UnsupportedAppUsage
public static final int OP_SEND_SMS = AppProtoEnums.APP_OP_SEND_SMS;
/** @hide */
public static final int OP_MANAGE_ONGOING_CALLS = AppProtoEnums.APP_OP_MANAGE_ONGOING_CALLS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_ICC_SMS = AppProtoEnums.APP_OP_READ_ICC_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_ICC_SMS = AppProtoEnums.APP_OP_WRITE_ICC_SMS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_SETTINGS = AppProtoEnums.APP_OP_WRITE_SETTINGS;
/** @hide Required to draw on top of other apps. */
@UnsupportedAppUsage
@TestApi
public static final int OP_SYSTEM_ALERT_WINDOW = AppProtoEnums.APP_OP_SYSTEM_ALERT_WINDOW;
/** @hide */
@UnsupportedAppUsage
public static final int OP_ACCESS_NOTIFICATIONS =
AppProtoEnums.APP_OP_ACCESS_NOTIFICATIONS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_CAMERA = AppProtoEnums.APP_OP_CAMERA;
/** @hide */
@UnsupportedAppUsage
@TestApi
public static final int OP_RECORD_AUDIO = AppProtoEnums.APP_OP_RECORD_AUDIO;
/** @hide */
@UnsupportedAppUsage
public static final int OP_PLAY_AUDIO = AppProtoEnums.APP_OP_PLAY_AUDIO;
/** @hide */
@UnsupportedAppUsage
public static final int OP_READ_CLIPBOARD = AppProtoEnums.APP_OP_READ_CLIPBOARD;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WRITE_CLIPBOARD = AppProtoEnums.APP_OP_WRITE_CLIPBOARD;
/** @hide */
@UnsupportedAppUsage
public static final int OP_TAKE_MEDIA_BUTTONS = AppProtoEnums.APP_OP_TAKE_MEDIA_BUTTONS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_TAKE_AUDIO_FOCUS = AppProtoEnums.APP_OP_TAKE_AUDIO_FOCUS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_MASTER_VOLUME = AppProtoEnums.APP_OP_AUDIO_MASTER_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_VOICE_VOLUME = AppProtoEnums.APP_OP_AUDIO_VOICE_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_RING_VOLUME = AppProtoEnums.APP_OP_AUDIO_RING_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_MEDIA_VOLUME = AppProtoEnums.APP_OP_AUDIO_MEDIA_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_ALARM_VOLUME = AppProtoEnums.APP_OP_AUDIO_ALARM_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_NOTIFICATION_VOLUME =
AppProtoEnums.APP_OP_AUDIO_NOTIFICATION_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_BLUETOOTH_VOLUME =
AppProtoEnums.APP_OP_AUDIO_BLUETOOTH_VOLUME;
/** @hide */
@UnsupportedAppUsage
public static final int OP_WAKE_LOCK = AppProtoEnums.APP_OP_WAKE_LOCK;
/** @hide Continually monitoring location data. */
@UnsupportedAppUsage
public static final int OP_MONITOR_LOCATION =
AppProtoEnums.APP_OP_MONITOR_LOCATION;
/** @hide Continually monitoring location data with a relatively high power request. */
@UnsupportedAppUsage
public static final int OP_MONITOR_HIGH_POWER_LOCATION =
AppProtoEnums.APP_OP_MONITOR_HIGH_POWER_LOCATION;
/** @hide Retrieve current usage stats via {@link UsageStatsManager}. */
@UnsupportedAppUsage
public static final int OP_GET_USAGE_STATS = AppProtoEnums.APP_OP_GET_USAGE_STATS;
/** @hide */
@UnsupportedAppUsage
public static final int OP_MUTE_MICROPHONE = AppProtoEnums.APP_OP_MUTE_MICROPHONE;
/** @hide */
@UnsupportedAppUsage
public static final int OP_TOAST_WINDOW = AppProtoEnums.APP_OP_TOAST_WINDOW;
/** @hide Capture the device's display contents and/or audio */
@UnsupportedAppUsage
public static final int OP_PROJECT_MEDIA = AppProtoEnums.APP_OP_PROJECT_MEDIA;
/**
* Start (without additional user intervention) a VPN connection, as used by {@link
* android.net.VpnService} along with as Platform VPN connections, as used by {@link
* android.net.VpnManager}
*
* <p>This appop is granted to apps that have already been given user consent to start
* VpnService based VPN connections. As this is a superset of OP_ACTIVATE_PLATFORM_VPN, this
* appop also allows the starting of Platform VPNs.
*
* @hide
*/
@UnsupportedAppUsage
public static final int OP_ACTIVATE_VPN = AppProtoEnums.APP_OP_ACTIVATE_VPN;
/** @hide Access the WallpaperManagerAPI to write wallpapers. */
@UnsupportedAppUsage
public static final int OP_WRITE_WALLPAPER = AppProtoEnums.APP_OP_WRITE_WALLPAPER;
/** @hide Received the assist structure from an app. */
@UnsupportedAppUsage
public static final int OP_ASSIST_STRUCTURE = AppProtoEnums.APP_OP_ASSIST_STRUCTURE;
/** @hide Received a screenshot from assist. */
@UnsupportedAppUsage
public static final int OP_ASSIST_SCREENSHOT = AppProtoEnums.APP_OP_ASSIST_SCREENSHOT;
/** @hide Read the phone state. */
@UnsupportedAppUsage
public static final int OP_READ_PHONE_STATE = AppProtoEnums.APP_OP_READ_PHONE_STATE;
/** @hide Add voicemail messages to the voicemail content provider. */
@UnsupportedAppUsage
public static final int OP_ADD_VOICEMAIL = AppProtoEnums.APP_OP_ADD_VOICEMAIL;
/** @hide Access APIs for SIP calling over VOIP or WiFi. */
@UnsupportedAppUsage
public static final int OP_USE_SIP = AppProtoEnums.APP_OP_USE_SIP;
/** @hide Intercept outgoing calls. */
@UnsupportedAppUsage
public static final int OP_PROCESS_OUTGOING_CALLS =
AppProtoEnums.APP_OP_PROCESS_OUTGOING_CALLS;
/** @hide User the fingerprint API. */
@UnsupportedAppUsage
public static final int OP_USE_FINGERPRINT = AppProtoEnums.APP_OP_USE_FINGERPRINT;
/** @hide Access to body sensors such as heart rate, etc. */
@UnsupportedAppUsage
public static final int OP_BODY_SENSORS = AppProtoEnums.APP_OP_BODY_SENSORS;
/** @hide Read previously received cell broadcast messages. */
@UnsupportedAppUsage
public static final int OP_READ_CELL_BROADCASTS = AppProtoEnums.APP_OP_READ_CELL_BROADCASTS;
/** @hide Inject mock location into the system. */
@UnsupportedAppUsage
public static final int OP_MOCK_LOCATION = AppProtoEnums.APP_OP_MOCK_LOCATION;
/** @hide Read external storage. */
@UnsupportedAppUsage
public static final int OP_READ_EXTERNAL_STORAGE = AppProtoEnums.APP_OP_READ_EXTERNAL_STORAGE;
/** @hide Write external storage. */
@UnsupportedAppUsage
public static final int OP_WRITE_EXTERNAL_STORAGE =
AppProtoEnums.APP_OP_WRITE_EXTERNAL_STORAGE;
/** @hide Turned on the screen. */
@UnsupportedAppUsage
public static final int OP_TURN_SCREEN_ON = AppProtoEnums.APP_OP_TURN_SCREEN_ON;
/** @hide Get device accounts. */
@UnsupportedAppUsage
public static final int OP_GET_ACCOUNTS = AppProtoEnums.APP_OP_GET_ACCOUNTS;
/** @hide Control whether an application is allowed to run in the background. */
@UnsupportedAppUsage
public static final int OP_RUN_IN_BACKGROUND =
AppProtoEnums.APP_OP_RUN_IN_BACKGROUND;
/** @hide */
@UnsupportedAppUsage
public static final int OP_AUDIO_ACCESSIBILITY_VOLUME =
AppProtoEnums.APP_OP_AUDIO_ACCESSIBILITY_VOLUME;
/** @hide Read the phone number. */
@UnsupportedAppUsage
public static final int OP_READ_PHONE_NUMBERS = AppProtoEnums.APP_OP_READ_PHONE_NUMBERS;
/** @hide Request package installs through package installer */
@UnsupportedAppUsage
public static final int OP_REQUEST_INSTALL_PACKAGES =
AppProtoEnums.APP_OP_REQUEST_INSTALL_PACKAGES;
/** @hide Enter picture-in-picture. */
@UnsupportedAppUsage
public static final int OP_PICTURE_IN_PICTURE = AppProtoEnums.APP_OP_PICTURE_IN_PICTURE;
/** @hide Instant app start foreground service. */
@UnsupportedAppUsage
public static final int OP_INSTANT_APP_START_FOREGROUND =
AppProtoEnums.APP_OP_INSTANT_APP_START_FOREGROUND;
/** @hide Answer incoming phone calls */
@UnsupportedAppUsage
public static final int OP_ANSWER_PHONE_CALLS = AppProtoEnums.APP_OP_ANSWER_PHONE_CALLS;
/** @hide Run jobs when in background */
@UnsupportedAppUsage
public static final int OP_RUN_ANY_IN_BACKGROUND = AppProtoEnums.APP_OP_RUN_ANY_IN_BACKGROUND;
/** @hide Change Wi-Fi connectivity state */
@UnsupportedAppUsage
public static final int OP_CHANGE_WIFI_STATE = AppProtoEnums.APP_OP_CHANGE_WIFI_STATE;
/** @hide Request package deletion through package installer */
@UnsupportedAppUsage
public static final int OP_REQUEST_DELETE_PACKAGES =
AppProtoEnums.APP_OP_REQUEST_DELETE_PACKAGES;
/** @hide Bind an accessibility service. */
@UnsupportedAppUsage
public static final int OP_BIND_ACCESSIBILITY_SERVICE =
AppProtoEnums.APP_OP_BIND_ACCESSIBILITY_SERVICE;
/** @hide Continue handover of a call from another app */
@UnsupportedAppUsage
public static final int OP_ACCEPT_HANDOVER = AppProtoEnums.APP_OP_ACCEPT_HANDOVER;
/** @hide Create and Manage IPsec Tunnels */
@UnsupportedAppUsage
public static final int OP_MANAGE_IPSEC_TUNNELS = AppProtoEnums.APP_OP_MANAGE_IPSEC_TUNNELS;
/** @hide Any app start foreground service. */
@UnsupportedAppUsage
@TestApi
public static final int OP_START_FOREGROUND = AppProtoEnums.APP_OP_START_FOREGROUND;
/** @hide */
@UnsupportedAppUsage
public static final int OP_BLUETOOTH_SCAN = AppProtoEnums.APP_OP_BLUETOOTH_SCAN;
/** @hide */
public static final int OP_BLUETOOTH_CONNECT = AppProtoEnums.APP_OP_BLUETOOTH_CONNECT;
/** @hide */
public static final int OP_BLUETOOTH_ADVERTISE = AppProtoEnums.APP_OP_BLUETOOTH_ADVERTISE;
/** @hide Use the BiometricPrompt/BiometricManager APIs. */
public static final int OP_USE_BIOMETRIC = AppProtoEnums.APP_OP_USE_BIOMETRIC;
/** @hide Physical activity recognition. */
public static final int OP_ACTIVITY_RECOGNITION = AppProtoEnums.APP_OP_ACTIVITY_RECOGNITION;
/** @hide Financial app sms read. */
public static final int OP_SMS_FINANCIAL_TRANSACTIONS =
AppProtoEnums.APP_OP_SMS_FINANCIAL_TRANSACTIONS;
/** @hide Read media of audio type. */
public static final int OP_READ_MEDIA_AUDIO = AppProtoEnums.APP_OP_READ_MEDIA_AUDIO;
/** @hide Write media of audio type. */
public static final int OP_WRITE_MEDIA_AUDIO = AppProtoEnums.APP_OP_WRITE_MEDIA_AUDIO;
/** @hide Read media of video type. */
public static final int OP_READ_MEDIA_VIDEO = AppProtoEnums.APP_OP_READ_MEDIA_VIDEO;
/** @hide Write media of video type. */
public static final int OP_WRITE_MEDIA_VIDEO = AppProtoEnums.APP_OP_WRITE_MEDIA_VIDEO;
/** @hide Read media of image type. */
public static final int OP_READ_MEDIA_IMAGES = AppProtoEnums.APP_OP_READ_MEDIA_IMAGES;
/** @hide Write media of image type. */
public static final int OP_WRITE_MEDIA_IMAGES = AppProtoEnums.APP_OP_WRITE_MEDIA_IMAGES;
/** @hide Has a legacy (non-isolated) view of storage. */
public static final int OP_LEGACY_STORAGE = AppProtoEnums.APP_OP_LEGACY_STORAGE;
/** @hide Accessing accessibility features */
public static final int OP_ACCESS_ACCESSIBILITY = AppProtoEnums.APP_OP_ACCESS_ACCESSIBILITY;
/** @hide Read the device identifiers (IMEI / MEID, IMSI, SIM / Build serial) */
public static final int OP_READ_DEVICE_IDENTIFIERS =
AppProtoEnums.APP_OP_READ_DEVICE_IDENTIFIERS;
/** @hide Read location metadata from media */
public static final int OP_ACCESS_MEDIA_LOCATION = AppProtoEnums.APP_OP_ACCESS_MEDIA_LOCATION;
/** @hide Query all apps on device, regardless of declarations in the calling app manifest */
public static final int OP_QUERY_ALL_PACKAGES = AppProtoEnums.APP_OP_QUERY_ALL_PACKAGES;
/** @hide Access all external storage */
public static final int OP_MANAGE_EXTERNAL_STORAGE =
AppProtoEnums.APP_OP_MANAGE_EXTERNAL_STORAGE;
/** @hide Communicate cross-profile within the same profile group. */
public static final int OP_INTERACT_ACROSS_PROFILES =
AppProtoEnums.APP_OP_INTERACT_ACROSS_PROFILES;
/**
* Start (without additional user intervention) a Platform VPN connection, as used by {@link
* android.net.VpnManager}
*
* <p>This appop is granted to apps that have already been given user consent to start Platform
* VPN connections. This appop is insufficient to start VpnService based VPNs; OP_ACTIVATE_VPN
* is needed for that.
*
* @hide
*/
public static final int OP_ACTIVATE_PLATFORM_VPN = AppProtoEnums.APP_OP_ACTIVATE_PLATFORM_VPN;
/** @hide Controls whether or not read logs are available for incremental installations. */
public static final int OP_LOADER_USAGE_STATS = AppProtoEnums.APP_OP_LOADER_USAGE_STATS;
// App op deprecated/removed.
private static final int OP_DEPRECATED_1 = AppProtoEnums.APP_OP_DEPRECATED_1;
/** @hide Auto-revoke app permissions if app is unused for an extended period */
public static final int OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED =
AppProtoEnums.APP_OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED;
/**
* Whether {@link #OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED} is allowed to be changed by
* the installer
*
* @hide
*/
public static final int OP_AUTO_REVOKE_MANAGED_BY_INSTALLER =
AppProtoEnums.APP_OP_AUTO_REVOKE_MANAGED_BY_INSTALLER;
/** @hide */
public static final int OP_NO_ISOLATED_STORAGE = AppProtoEnums.APP_OP_NO_ISOLATED_STORAGE;
/**
* Phone call is using microphone
*
* @hide
*/
public static final int OP_PHONE_CALL_MICROPHONE = AppProtoEnums.APP_OP_PHONE_CALL_MICROPHONE;
/**
* Phone call is using camera
*
* @hide
*/
public static final int OP_PHONE_CALL_CAMERA = AppProtoEnums.APP_OP_PHONE_CALL_CAMERA;
/**
* Audio is being recorded for hotword detection.
*
* @hide
*/
public static final int OP_RECORD_AUDIO_HOTWORD = AppProtoEnums.APP_OP_RECORD_AUDIO_HOTWORD;
/**
* Manage credentials in the system KeyChain.
*
* @hide
*/
public static final int OP_MANAGE_CREDENTIALS = AppProtoEnums.APP_OP_MANAGE_CREDENTIALS;
/** @hide */
public static final int OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER =
AppProtoEnums.APP_OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER;
/**
* App output audio is being recorded
*
* @hide
*/
public static final int OP_RECORD_AUDIO_OUTPUT = AppProtoEnums.APP_OP_RECORD_AUDIO_OUTPUT;
/**
* App can schedule exact alarm to perform timing based background work
*
* @hide
*/
public static final int OP_SCHEDULE_EXACT_ALARM = AppProtoEnums.APP_OP_SCHEDULE_EXACT_ALARM;
/**
* Fine location being accessed by a location source, which is
* a component that already has location data since it is the one
* that produces location, which is it is a data source for
* location data.
*
* @hide
*/
public static final int OP_FINE_LOCATION_SOURCE = AppProtoEnums.APP_OP_FINE_LOCATION_SOURCE;
/**
* Coarse location being accessed by a location source, which is
* a component that already has location data since it is the one
* that produces location, which is it is a data source for
* location data.
*
* @hide
*/
public static final int OP_COARSE_LOCATION_SOURCE = AppProtoEnums.APP_OP_COARSE_LOCATION_SOURCE;
/**
* Allow apps to create the requests to manage the media files without user confirmation.
*
* @see android.Manifest.permission#MANAGE_MEDIA
* @see android.provider.MediaStore#createDeleteRequest(ContentResolver, Collection)
* @see android.provider.MediaStore#createTrashRequest(ContentResolver, Collection, boolean)
* @see android.provider.MediaStore#createWriteRequest(ContentResolver, Collection)
*
* @hide
*/
public static final int OP_MANAGE_MEDIA = AppProtoEnums.APP_OP_MANAGE_MEDIA;
/** @hide */
public static final int OP_UWB_RANGING = AppProtoEnums.APP_OP_UWB_RANGING;
/** @hide */
public static final int OP_NEARBY_WIFI_DEVICES = AppProtoEnums.APP_OP_NEARBY_WIFI_DEVICES;
/**
* Activity recognition being accessed by an activity recognition source, which
* is a component that already has access since it is the one that detects
* activity recognition.
*
* @hide
*/
public static final int OP_ACTIVITY_RECOGNITION_SOURCE =
AppProtoEnums.APP_OP_ACTIVITY_RECOGNITION_SOURCE;
/**
* Incoming phone audio is being recorded
*
* @hide
*/
public static final int OP_RECORD_INCOMING_PHONE_AUDIO =
AppProtoEnums.APP_OP_RECORD_INCOMING_PHONE_AUDIO;
/**
* VPN app establishes a connection through the VpnService API.
*
* @hide
*/
public static final int OP_ESTABLISH_VPN_SERVICE = AppProtoEnums.APP_OP_ESTABLISH_VPN_SERVICE;
/**
* VPN app establishes a connection through the VpnManager API.
*
* @hide
*/
public static final int OP_ESTABLISH_VPN_MANAGER = AppProtoEnums.APP_OP_ESTABLISH_VPN_MANAGER;
/**
* Access restricted settings.
*
* @hide
*/
public static final int OP_ACCESS_RESTRICTED_SETTINGS =
AppProtoEnums.APP_OP_ACCESS_RESTRICTED_SETTINGS;
/**
* Receive microphone audio from an ambient sound detection event
*
* @hide
*/
public static final int OP_RECEIVE_AMBIENT_TRIGGER_AUDIO =
AppProtoEnums.APP_OP_RECEIVE_AMBIENT_TRIGGER_AUDIO;
/** @hide */
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static final int _NUM_OP = 121;
/** Access to coarse location information. */
public static final String OPSTR_COARSE_LOCATION = "android:coarse_location";
/** Access to fine location information. */
public static final String OPSTR_FINE_LOCATION =
"android:fine_location";
/** Continually monitoring location data. */
public static final String OPSTR_MONITOR_LOCATION
= "android:monitor_location";
/** Continually monitoring location data with a relatively high power request. */
public static final String OPSTR_MONITOR_HIGH_POWER_LOCATION
= "android:monitor_location_high_power";
/** Access to {@link android.app.usage.UsageStatsManager}. */
public static final String OPSTR_GET_USAGE_STATS
= "android:get_usage_stats";
/** Activate a VPN connection without user intervention. @hide */
@SystemApi
public static final String OPSTR_ACTIVATE_VPN
= "android:activate_vpn";
/** Allows an application to read the user's contacts data. */
public static final String OPSTR_READ_CONTACTS
= "android:read_contacts";
/** Allows an application to write to the user's contacts data. */
public static final String OPSTR_WRITE_CONTACTS
= "android:write_contacts";
/** Allows an application to read the user's call log. */
public static final String OPSTR_READ_CALL_LOG
= "android:read_call_log";
/** Allows an application to write to the user's call log. */
public static final String OPSTR_WRITE_CALL_LOG
= "android:write_call_log";
/** Allows an application to read the user's calendar data. */
public static final String OPSTR_READ_CALENDAR
= "android:read_calendar";
/** Allows an application to write to the user's calendar data. */
public static final String OPSTR_WRITE_CALENDAR
= "android:write_calendar";
/** Allows an application to initiate a phone call. */
public static final String OPSTR_CALL_PHONE
= "android:call_phone";
/** Allows an application to read SMS messages. */
public static final String OPSTR_READ_SMS
= "android:read_sms";
/** Allows an application to receive SMS messages. */
public static final String OPSTR_RECEIVE_SMS
= "android:receive_sms";
/** Allows an application to receive MMS messages. */
public static final String OPSTR_RECEIVE_MMS
= "android:receive_mms";
/** Allows an application to receive WAP push messages. */
public static final String OPSTR_RECEIVE_WAP_PUSH
= "android:receive_wap_push";
/** Allows an application to send SMS messages. */
public static final String OPSTR_SEND_SMS
= "android:send_sms";
/** Required to be able to access the camera device. */
public static final String OPSTR_CAMERA
= "android:camera";
/** Required to be able to access the microphone device. */
public static final String OPSTR_RECORD_AUDIO
= "android:record_audio";
/** Required to access phone state related information. */
public static final String OPSTR_READ_PHONE_STATE
= "android:read_phone_state";
/** Required to access phone state related information. */
public static final String OPSTR_ADD_VOICEMAIL
= "android:add_voicemail";
/** Access APIs for SIP calling over VOIP or WiFi */
public static final String OPSTR_USE_SIP
= "android:use_sip";
/** Access APIs for diverting outgoing calls */
public static final String OPSTR_PROCESS_OUTGOING_CALLS
= "android:process_outgoing_calls";
/** Use the fingerprint API. */
public static final String OPSTR_USE_FINGERPRINT
= "android:use_fingerprint";
/** Access to body sensors such as heart rate, etc. */
public static final String OPSTR_BODY_SENSORS
= "android:body_sensors";
/** Read previously received cell broadcast messages. */
public static final String OPSTR_READ_CELL_BROADCASTS
= "android:read_cell_broadcasts";
/** Inject mock location into the system. */
public static final String OPSTR_MOCK_LOCATION
= "android:mock_location";
/** Read external storage. */
public static final String OPSTR_READ_EXTERNAL_STORAGE
= "android:read_external_storage";
/** Write external storage. */
public static final String OPSTR_WRITE_EXTERNAL_STORAGE
= "android:write_external_storage";
/** Required to draw on top of other apps. */
public static final String OPSTR_SYSTEM_ALERT_WINDOW
= "android:system_alert_window";
/** Required to write/modify/update system settings. */
public static final String OPSTR_WRITE_SETTINGS
= "android:write_settings";
/** @hide Get device accounts. */
@SystemApi
public static final String OPSTR_GET_ACCOUNTS
= "android:get_accounts";
public static final String OPSTR_READ_PHONE_NUMBERS
= "android:read_phone_numbers";
/** Access to picture-in-picture. */
public static final String OPSTR_PICTURE_IN_PICTURE
= "android:picture_in_picture";
/** @hide */
@SystemApi
public static final String OPSTR_INSTANT_APP_START_FOREGROUND
= "android:instant_app_start_foreground";
/** Answer incoming phone calls */
public static final String OPSTR_ANSWER_PHONE_CALLS
= "android:answer_phone_calls";
/**
* Accept call handover
* @hide
*/
@SystemApi
public static final String OPSTR_ACCEPT_HANDOVER
= "android:accept_handover";
/** @hide */
@SystemApi
public static final String OPSTR_GPS = "android:gps";
/** @hide */
@SystemApi
public static final String OPSTR_VIBRATE = "android:vibrate";
/** @hide */
@SystemApi
public static final String OPSTR_WIFI_SCAN = "android:wifi_scan";
/** @hide */
@SystemApi
public static final String OPSTR_POST_NOTIFICATION = "android:post_notification";
/** @hide */
@SystemApi
public static final String OPSTR_NEIGHBORING_CELLS = "android:neighboring_cells";
/** @hide */
@SystemApi
public static final String OPSTR_WRITE_SMS = "android:write_sms";
/** @hide */
@SystemApi
public static final String OPSTR_RECEIVE_EMERGENCY_BROADCAST =
"android:receive_emergency_broadcast";
/** @hide */
@SystemApi
public static final String OPSTR_READ_ICC_SMS = "android:read_icc_sms";
/** @hide */
@SystemApi
public static final String OPSTR_WRITE_ICC_SMS = "android:write_icc_sms";
/** @hide */
@SystemApi
public static final String OPSTR_ACCESS_NOTIFICATIONS = "android:access_notifications";
/** @hide */
@SystemApi
public static final String OPSTR_PLAY_AUDIO = "android:play_audio";
/** @hide */
@SystemApi
public static final String OPSTR_READ_CLIPBOARD = "android:read_clipboard";
/** @hide */
@SystemApi
public static final String OPSTR_WRITE_CLIPBOARD = "android:write_clipboard";
/** @hide */
@SystemApi
public static final String OPSTR_TAKE_MEDIA_BUTTONS = "android:take_media_buttons";
/** @hide */
@SystemApi
public static final String OPSTR_TAKE_AUDIO_FOCUS = "android:take_audio_focus";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_MASTER_VOLUME = "android:audio_master_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_VOICE_VOLUME = "android:audio_voice_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_RING_VOLUME = "android:audio_ring_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_MEDIA_VOLUME = "android:audio_media_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_ALARM_VOLUME = "android:audio_alarm_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_NOTIFICATION_VOLUME =
"android:audio_notification_volume";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_BLUETOOTH_VOLUME = "android:audio_bluetooth_volume";
/** @hide */
@SystemApi
public static final String OPSTR_WAKE_LOCK = "android:wake_lock";
/** @hide */
@SystemApi
public static final String OPSTR_MUTE_MICROPHONE = "android:mute_microphone";
/** @hide */
@SystemApi
public static final String OPSTR_TOAST_WINDOW = "android:toast_window";
/** @hide */
@SystemApi
public static final String OPSTR_PROJECT_MEDIA = "android:project_media";
/** @hide */
@SystemApi
public static final String OPSTR_WRITE_WALLPAPER = "android:write_wallpaper";
/** @hide */
@SystemApi
public static final String OPSTR_ASSIST_STRUCTURE = "android:assist_structure";
/** @hide */
@SystemApi
public static final String OPSTR_ASSIST_SCREENSHOT = "android:assist_screenshot";
/** @hide */
@SystemApi
public static final String OPSTR_TURN_SCREEN_ON = "android:turn_screen_on";
/** @hide */
@SystemApi
public static final String OPSTR_RUN_IN_BACKGROUND = "android:run_in_background";
/** @hide */
@SystemApi
public static final String OPSTR_AUDIO_ACCESSIBILITY_VOLUME =
"android:audio_accessibility_volume";
/** @hide */
@SystemApi
public static final String OPSTR_REQUEST_INSTALL_PACKAGES = "android:request_install_packages";
/** @hide */
@SystemApi
public static final String OPSTR_RUN_ANY_IN_BACKGROUND = "android:run_any_in_background";
/** @hide */
@SystemApi
public static final String OPSTR_CHANGE_WIFI_STATE = "android:change_wifi_state";
/** @hide */
@SystemApi
public static final String OPSTR_REQUEST_DELETE_PACKAGES = "android:request_delete_packages";
/** @hide */
@SystemApi
public static final String OPSTR_BIND_ACCESSIBILITY_SERVICE =
"android:bind_accessibility_service";
/** @hide */
@SystemApi
public static final String OPSTR_MANAGE_IPSEC_TUNNELS = "android:manage_ipsec_tunnels";
/** @hide */
@SystemApi
public static final String OPSTR_START_FOREGROUND = "android:start_foreground";
/** @hide */
public static final String OPSTR_BLUETOOTH_SCAN = "android:bluetooth_scan";
/** @hide */
public static final String OPSTR_BLUETOOTH_CONNECT = "android:bluetooth_connect";
/** @hide */
public static final String OPSTR_BLUETOOTH_ADVERTISE = "android:bluetooth_advertise";
/** @hide Use the BiometricPrompt/BiometricManager APIs. */
public static final String OPSTR_USE_BIOMETRIC = "android:use_biometric";
/** @hide Recognize physical activity. */
@TestApi
public static final String OPSTR_ACTIVITY_RECOGNITION = "android:activity_recognition";
/** @hide Financial app read sms. */
public static final String OPSTR_SMS_FINANCIAL_TRANSACTIONS =
"android:sms_financial_transactions";
/** @hide Read media of audio type. */
@SystemApi
public static final String OPSTR_READ_MEDIA_AUDIO = "android:read_media_audio";
/** @hide Write media of audio type. */
@SystemApi
public static final String OPSTR_WRITE_MEDIA_AUDIO = "android:write_media_audio";
/** @hide Read media of video type. */
@SystemApi
public static final String OPSTR_READ_MEDIA_VIDEO = "android:read_media_video";
/** @hide Write media of video type. */
@SystemApi
public static final String OPSTR_WRITE_MEDIA_VIDEO = "android:write_media_video";
/** @hide Read media of image type. */
@SystemApi
public static final String OPSTR_READ_MEDIA_IMAGES = "android:read_media_images";
/** @hide Write media of image type. */
@SystemApi
public static final String OPSTR_WRITE_MEDIA_IMAGES = "android:write_media_images";
/** @hide Has a legacy (non-isolated) view of storage. */
@SystemApi
public static final String OPSTR_LEGACY_STORAGE = "android:legacy_storage";
/** @hide Read location metadata from media */
public static final String OPSTR_ACCESS_MEDIA_LOCATION = "android:access_media_location";
/** @hide Interact with accessibility. */
@SystemApi
public static final String OPSTR_ACCESS_ACCESSIBILITY = "android:access_accessibility";
/** @hide Read device identifiers */
public static final String OPSTR_READ_DEVICE_IDENTIFIERS = "android:read_device_identifiers";
/** @hide Query all packages on device */
public static final String OPSTR_QUERY_ALL_PACKAGES = "android:query_all_packages";
/** @hide Access all external storage */
@SystemApi
public static final String OPSTR_MANAGE_EXTERNAL_STORAGE =
"android:manage_external_storage";
/** @hide Auto-revoke app permissions if app is unused for an extended period */
@SystemApi
public static final String OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED =
"android:auto_revoke_permissions_if_unused";
/** @hide Auto-revoke app permissions if app is unused for an extended period */
@SystemApi
public static final String OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER =
"android:auto_revoke_managed_by_installer";
/** @hide Communicate cross-profile within the same profile group. */
@SystemApi
public static final String OPSTR_INTERACT_ACROSS_PROFILES = "android:interact_across_profiles";
/** @hide Start Platform VPN without user intervention */
@SystemApi
public static final String OPSTR_ACTIVATE_PLATFORM_VPN = "android:activate_platform_vpn";
/** @hide */
@SystemApi
public static final String OPSTR_LOADER_USAGE_STATS = "android:loader_usage_stats";
/**
* Grants an app access to the {@link android.telecom.InCallService} API to see
* information about ongoing calls and to enable control of calls.
* @hide
*/
@SystemApi
@TestApi
public static final String OPSTR_MANAGE_ONGOING_CALLS = "android:manage_ongoing_calls";
/**
* AppOp granted to apps that we are started via {@code am instrument -e --no-isolated-storage}
*
* <p>MediaProvider is the only component (outside of system server) that should care about this
* app op, hence {@code SystemApi.Client.MODULE_LIBRARIES}.
*
* @hide
*/
@SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
public static final String OPSTR_NO_ISOLATED_STORAGE = "android:no_isolated_storage";
/**
* Phone call is using microphone
*
* @hide
*/
@SystemApi
public static final String OPSTR_PHONE_CALL_MICROPHONE = "android:phone_call_microphone";
/**
* Phone call is using camera
*
* @hide
*/
@SystemApi
public static final String OPSTR_PHONE_CALL_CAMERA = "android:phone_call_camera";
/**
* Audio is being recorded for hotword detection.
*
* @hide
*/
@TestApi
public static final String OPSTR_RECORD_AUDIO_HOTWORD = "android:record_audio_hotword";
/**
* Manage credentials in the system KeyChain.
*
* @hide
*/
public static final String OPSTR_MANAGE_CREDENTIALS = "android:manage_credentials";
/**
* Allows to read device identifiers and use ICC based authentication like EAP-AKA.
*
* @hide
*/
@TestApi
public static final String OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER =
"android:use_icc_auth_with_device_identifier";
/**
* App output audio is being recorded
*
* @hide
*/
public static final String OPSTR_RECORD_AUDIO_OUTPUT = "android:record_audio_output";
/**
* App can schedule exact alarm to perform timing based background work.
*
* @hide
*/
public static final String OPSTR_SCHEDULE_EXACT_ALARM = "android:schedule_exact_alarm";
/**
* Fine location being accessed by a location source, which is
* a component that already has location since it is the one that
* produces location.
*
* @hide
*/
public static final String OPSTR_FINE_LOCATION_SOURCE = "android:fine_location_source";
/**
* Coarse location being accessed by a location source, which is
* a component that already has location since it is the one that
* produces location.
*
* @hide
*/
public static final String OPSTR_COARSE_LOCATION_SOURCE = "android:coarse_location_source";
/**
* Allow apps to create the requests to manage the media files without user confirmation.
*
* @see android.Manifest.permission#MANAGE_MEDIA
* @see android.provider.MediaStore#createDeleteRequest(ContentResolver, Collection)
* @see android.provider.MediaStore#createTrashRequest(ContentResolver, Collection, boolean)
* @see android.provider.MediaStore#createWriteRequest(ContentResolver, Collection)
*
* @hide
*/
public static final String OPSTR_MANAGE_MEDIA = "android:manage_media";
/** @hide */
public static final String OPSTR_UWB_RANGING = "android:uwb_ranging";
/** @hide */
public static final String OPSTR_NEARBY_WIFI_DEVICES = "android:nearby_wifi_devices";
/**
* Activity recognition being accessed by an activity recognition source, which
* is a component that already has access since it is the one that detects
* activity recognition.
*
* @hide
*/
@TestApi
public static final String OPSTR_ACTIVITY_RECOGNITION_SOURCE =
"android:activity_recognition_source";
/**
* @hide
*/
public static final String OPSTR_RECORD_INCOMING_PHONE_AUDIO =
"android:record_incoming_phone_audio";
/**
* VPN app establishes a connection through the VpnService API.
*
* @hide
*/
@SystemApi
public static final String OPSTR_ESTABLISH_VPN_SERVICE = "android:establish_vpn_service";
/**
* VPN app establishes a connection through the VpnManager API.
*
* @hide
*/
@SystemApi
public static final String OPSTR_ESTABLISH_VPN_MANAGER = "android:establish_vpn_manager";
/**
* Limit user accessing restricted settings.
*
* @hide
*/
public static final String OPSTR_ACCESS_RESTRICTED_SETTINGS =
"android:access_restricted_settings";
/**
* Receive microphone audio from an ambient sound detection event
*
* @hide
*/
public static final String OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO =
"android:receive_ambient_trigger_audio";
/** {@link #sAppOpsToNote} not initialized yet for this op */
private static final byte SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED = 0;
/** Should not collect noting of this app-op in {@link #sAppOpsToNote} */
private static final byte SHOULD_NOT_COLLECT_NOTE_OP = 1;
/** Should collect noting of this app-op in {@link #sAppOpsToNote} */
private static final byte SHOULD_COLLECT_NOTE_OP = 2;
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "SHOULD_" }, value = {
SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED,
SHOULD_NOT_COLLECT_NOTE_OP,
SHOULD_COLLECT_NOTE_OP
})
private @interface ShouldCollectNoteOp {}
private static final int[] RUNTIME_AND_APPOP_PERMISSIONS_OPS = {
// RUNTIME PERMISSIONS
// Contacts
OP_READ_CONTACTS,
OP_WRITE_CONTACTS,
OP_GET_ACCOUNTS,
// Calendar
OP_READ_CALENDAR,
OP_WRITE_CALENDAR,
// SMS
OP_SEND_SMS,
OP_RECEIVE_SMS,
OP_READ_SMS,
OP_RECEIVE_WAP_PUSH,
OP_RECEIVE_MMS,
OP_READ_CELL_BROADCASTS,
// Storage
OP_READ_EXTERNAL_STORAGE,
OP_WRITE_EXTERNAL_STORAGE,
OP_ACCESS_MEDIA_LOCATION,
// Location
OP_COARSE_LOCATION,
OP_FINE_LOCATION,
// Phone
OP_READ_PHONE_STATE,
OP_READ_PHONE_NUMBERS,
OP_CALL_PHONE,
OP_READ_CALL_LOG,
OP_WRITE_CALL_LOG,
OP_ADD_VOICEMAIL,
OP_USE_SIP,
OP_PROCESS_OUTGOING_CALLS,
OP_ANSWER_PHONE_CALLS,
OP_ACCEPT_HANDOVER,
// Microphone
OP_RECORD_AUDIO,
// Camera
OP_CAMERA,
// Body sensors
OP_BODY_SENSORS,
// Activity recognition
OP_ACTIVITY_RECOGNITION,
// Aural
OP_READ_MEDIA_AUDIO,
OP_WRITE_MEDIA_AUDIO,
// Visual
OP_READ_MEDIA_VIDEO,
OP_WRITE_MEDIA_VIDEO,
OP_READ_MEDIA_IMAGES,
OP_WRITE_MEDIA_IMAGES,
// Nearby devices
OP_BLUETOOTH_SCAN,
OP_BLUETOOTH_CONNECT,
OP_BLUETOOTH_ADVERTISE,
OP_UWB_RANGING,
OP_NEARBY_WIFI_DEVICES,
// Notifications
OP_POST_NOTIFICATION,
// APPOP PERMISSIONS
OP_ACCESS_NOTIFICATIONS,
OP_SYSTEM_ALERT_WINDOW,
OP_WRITE_SETTINGS,
OP_REQUEST_INSTALL_PACKAGES,
OP_START_FOREGROUND,
OP_SMS_FINANCIAL_TRANSACTIONS,
OP_MANAGE_IPSEC_TUNNELS,
OP_INSTANT_APP_START_FOREGROUND,
OP_MANAGE_EXTERNAL_STORAGE,
OP_INTERACT_ACROSS_PROFILES,
OP_LOADER_USAGE_STATS,
OP_MANAGE_ONGOING_CALLS,
OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER,
OP_SCHEDULE_EXACT_ALARM,
OP_MANAGE_MEDIA,
};
/**
* This maps each operation to the operation that serves as the
* switch to determine whether it is allowed. Generally this is
* a 1:1 mapping, but for some things (like location) that have
* multiple low-level operations being tracked that should be
* presented to the user as one switch then this can be used to
* make them all controlled by the same single operation.
*/
private static int[] sOpToSwitch = new int[] {
OP_COARSE_LOCATION, // COARSE_LOCATION
OP_FINE_LOCATION, // FINE_LOCATION
OP_COARSE_LOCATION, // GPS
OP_VIBRATE, // VIBRATE
OP_READ_CONTACTS, // READ_CONTACTS
OP_WRITE_CONTACTS, // WRITE_CONTACTS
OP_READ_CALL_LOG, // READ_CALL_LOG
OP_WRITE_CALL_LOG, // WRITE_CALL_LOG
OP_READ_CALENDAR, // READ_CALENDAR
OP_WRITE_CALENDAR, // WRITE_CALENDAR
OP_COARSE_LOCATION, // WIFI_SCAN
OP_POST_NOTIFICATION, // POST_NOTIFICATION
OP_COARSE_LOCATION, // NEIGHBORING_CELLS
OP_CALL_PHONE, // CALL_PHONE
OP_READ_SMS, // READ_SMS
OP_WRITE_SMS, // WRITE_SMS
OP_RECEIVE_SMS, // RECEIVE_SMS
OP_RECEIVE_SMS, // RECEIVE_EMERGECY_SMS
OP_RECEIVE_MMS, // RECEIVE_MMS
OP_RECEIVE_WAP_PUSH, // RECEIVE_WAP_PUSH
OP_SEND_SMS, // SEND_SMS
OP_READ_SMS, // READ_ICC_SMS
OP_WRITE_SMS, // WRITE_ICC_SMS
OP_WRITE_SETTINGS, // WRITE_SETTINGS
OP_SYSTEM_ALERT_WINDOW, // SYSTEM_ALERT_WINDOW
OP_ACCESS_NOTIFICATIONS, // ACCESS_NOTIFICATIONS
OP_CAMERA, // CAMERA
OP_RECORD_AUDIO, // RECORD_AUDIO
OP_PLAY_AUDIO, // PLAY_AUDIO
OP_READ_CLIPBOARD, // READ_CLIPBOARD
OP_WRITE_CLIPBOARD, // WRITE_CLIPBOARD
OP_TAKE_MEDIA_BUTTONS, // TAKE_MEDIA_BUTTONS
OP_TAKE_AUDIO_FOCUS, // TAKE_AUDIO_FOCUS
OP_AUDIO_MASTER_VOLUME, // AUDIO_MASTER_VOLUME
OP_AUDIO_VOICE_VOLUME, // AUDIO_VOICE_VOLUME
OP_AUDIO_RING_VOLUME, // AUDIO_RING_VOLUME
OP_AUDIO_MEDIA_VOLUME, // AUDIO_MEDIA_VOLUME
OP_AUDIO_ALARM_VOLUME, // AUDIO_ALARM_VOLUME
OP_AUDIO_NOTIFICATION_VOLUME, // AUDIO_NOTIFICATION_VOLUME
OP_AUDIO_BLUETOOTH_VOLUME, // AUDIO_BLUETOOTH_VOLUME
OP_WAKE_LOCK, // WAKE_LOCK
OP_COARSE_LOCATION, // MONITOR_LOCATION
OP_COARSE_LOCATION, // MONITOR_HIGH_POWER_LOCATION
OP_GET_USAGE_STATS, // GET_USAGE_STATS
OP_MUTE_MICROPHONE, // MUTE_MICROPHONE
OP_TOAST_WINDOW, // TOAST_WINDOW
OP_PROJECT_MEDIA, // PROJECT_MEDIA
OP_ACTIVATE_VPN, // ACTIVATE_VPN
OP_WRITE_WALLPAPER, // WRITE_WALLPAPER
OP_ASSIST_STRUCTURE, // ASSIST_STRUCTURE
OP_ASSIST_SCREENSHOT, // ASSIST_SCREENSHOT
OP_READ_PHONE_STATE, // READ_PHONE_STATE
OP_ADD_VOICEMAIL, // ADD_VOICEMAIL
OP_USE_SIP, // USE_SIP
OP_PROCESS_OUTGOING_CALLS, // PROCESS_OUTGOING_CALLS
OP_USE_FINGERPRINT, // USE_FINGERPRINT
OP_BODY_SENSORS, // BODY_SENSORS
OP_READ_CELL_BROADCASTS, // READ_CELL_BROADCASTS
OP_MOCK_LOCATION, // MOCK_LOCATION
OP_READ_EXTERNAL_STORAGE, // READ_EXTERNAL_STORAGE
OP_WRITE_EXTERNAL_STORAGE, // WRITE_EXTERNAL_STORAGE
OP_TURN_SCREEN_ON, // TURN_SCREEN_ON
OP_GET_ACCOUNTS, // GET_ACCOUNTS
OP_RUN_IN_BACKGROUND, // RUN_IN_BACKGROUND
OP_AUDIO_ACCESSIBILITY_VOLUME, // AUDIO_ACCESSIBILITY_VOLUME
OP_READ_PHONE_NUMBERS, // READ_PHONE_NUMBERS
OP_REQUEST_INSTALL_PACKAGES, // REQUEST_INSTALL_PACKAGES
OP_PICTURE_IN_PICTURE, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
OP_INSTANT_APP_START_FOREGROUND, // INSTANT_APP_START_FOREGROUND
OP_ANSWER_PHONE_CALLS, // ANSWER_PHONE_CALLS
OP_RUN_ANY_IN_BACKGROUND, // OP_RUN_ANY_IN_BACKGROUND
OP_CHANGE_WIFI_STATE, // OP_CHANGE_WIFI_STATE
OP_REQUEST_DELETE_PACKAGES, // OP_REQUEST_DELETE_PACKAGES
OP_BIND_ACCESSIBILITY_SERVICE, // OP_BIND_ACCESSIBILITY_SERVICE
OP_ACCEPT_HANDOVER, // ACCEPT_HANDOVER
OP_MANAGE_IPSEC_TUNNELS, // MANAGE_IPSEC_HANDOVERS
OP_START_FOREGROUND, // START_FOREGROUND
OP_BLUETOOTH_SCAN, // BLUETOOTH_SCAN
OP_USE_BIOMETRIC, // BIOMETRIC
OP_ACTIVITY_RECOGNITION, // ACTIVITY_RECOGNITION
OP_SMS_FINANCIAL_TRANSACTIONS, // SMS_FINANCIAL_TRANSACTIONS
OP_READ_MEDIA_AUDIO, // READ_MEDIA_AUDIO
OP_WRITE_MEDIA_AUDIO, // WRITE_MEDIA_AUDIO
OP_READ_MEDIA_VIDEO, // READ_MEDIA_VIDEO
OP_WRITE_MEDIA_VIDEO, // WRITE_MEDIA_VIDEO
OP_READ_MEDIA_IMAGES, // READ_MEDIA_IMAGES
OP_WRITE_MEDIA_IMAGES, // WRITE_MEDIA_IMAGES
OP_LEGACY_STORAGE, // LEGACY_STORAGE
OP_ACCESS_ACCESSIBILITY, // ACCESS_ACCESSIBILITY
OP_READ_DEVICE_IDENTIFIERS, // READ_DEVICE_IDENTIFIERS
OP_ACCESS_MEDIA_LOCATION, // ACCESS_MEDIA_LOCATION
OP_QUERY_ALL_PACKAGES, // QUERY_ALL_PACKAGES
OP_MANAGE_EXTERNAL_STORAGE, // MANAGE_EXTERNAL_STORAGE
OP_INTERACT_ACROSS_PROFILES, //INTERACT_ACROSS_PROFILES
OP_ACTIVATE_PLATFORM_VPN, // ACTIVATE_PLATFORM_VPN
OP_LOADER_USAGE_STATS, // LOADER_USAGE_STATS
OP_DEPRECATED_1, // deprecated
OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED, //AUTO_REVOKE_PERMISSIONS_IF_UNUSED
OP_AUTO_REVOKE_MANAGED_BY_INSTALLER, //OP_AUTO_REVOKE_MANAGED_BY_INSTALLER
OP_NO_ISOLATED_STORAGE, // NO_ISOLATED_STORAGE
OP_PHONE_CALL_MICROPHONE, // OP_PHONE_CALL_MICROPHONE
OP_PHONE_CALL_CAMERA, // OP_PHONE_CALL_CAMERA
OP_RECORD_AUDIO_HOTWORD, // RECORD_AUDIO_HOTWORD
OP_MANAGE_ONGOING_CALLS, // MANAGE_ONGOING_CALLS
OP_MANAGE_CREDENTIALS, // MANAGE_CREDENTIALS
OP_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER, // USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER
OP_RECORD_AUDIO_OUTPUT, // RECORD_AUDIO_OUTPUT
OP_SCHEDULE_EXACT_ALARM, // SCHEDULE_EXACT_ALARM
OP_FINE_LOCATION, // OP_FINE_LOCATION_SOURCE
OP_COARSE_LOCATION, // OP_COARSE_LOCATION_SOURCE
OP_MANAGE_MEDIA, // MANAGE_MEDIA
OP_BLUETOOTH_CONNECT, // OP_BLUETOOTH_CONNECT
OP_UWB_RANGING, // OP_UWB_RANGING
OP_ACTIVITY_RECOGNITION, // OP_ACTIVITY_RECOGNITION_SOURCE
OP_BLUETOOTH_ADVERTISE, // OP_BLUETOOTH_ADVERTISE
OP_RECORD_INCOMING_PHONE_AUDIO, // OP_RECORD_INCOMING_PHONE_AUDIO
OP_NEARBY_WIFI_DEVICES, // OP_NEARBY_WIFI_DEVICES
OP_ESTABLISH_VPN_SERVICE, // OP_ESTABLISH_VPN_SERVICE
OP_ESTABLISH_VPN_MANAGER, // OP_ESTABLISH_VPN_MANAGER
OP_ACCESS_RESTRICTED_SETTINGS, // OP_ACCESS_RESTRICTED_SETTINGS
OP_RECEIVE_AMBIENT_TRIGGER_AUDIO, // RECEIVE_SOUNDTRIGGER_AUDIO
};
/**
* This maps each operation to the public string constant for it.
*/
private static String[] sOpToString = new String[]{
OPSTR_COARSE_LOCATION,
OPSTR_FINE_LOCATION,
OPSTR_GPS,
OPSTR_VIBRATE,
OPSTR_READ_CONTACTS,
OPSTR_WRITE_CONTACTS,
OPSTR_READ_CALL_LOG,
OPSTR_WRITE_CALL_LOG,
OPSTR_READ_CALENDAR,
OPSTR_WRITE_CALENDAR,
OPSTR_WIFI_SCAN,
OPSTR_POST_NOTIFICATION,
OPSTR_NEIGHBORING_CELLS,
OPSTR_CALL_PHONE,
OPSTR_READ_SMS,
OPSTR_WRITE_SMS,
OPSTR_RECEIVE_SMS,
OPSTR_RECEIVE_EMERGENCY_BROADCAST,
OPSTR_RECEIVE_MMS,
OPSTR_RECEIVE_WAP_PUSH,
OPSTR_SEND_SMS,
OPSTR_READ_ICC_SMS,
OPSTR_WRITE_ICC_SMS,
OPSTR_WRITE_SETTINGS,
OPSTR_SYSTEM_ALERT_WINDOW,
OPSTR_ACCESS_NOTIFICATIONS,
OPSTR_CAMERA,
OPSTR_RECORD_AUDIO,
OPSTR_PLAY_AUDIO,
OPSTR_READ_CLIPBOARD,
OPSTR_WRITE_CLIPBOARD,
OPSTR_TAKE_MEDIA_BUTTONS,
OPSTR_TAKE_AUDIO_FOCUS,
OPSTR_AUDIO_MASTER_VOLUME,
OPSTR_AUDIO_VOICE_VOLUME,
OPSTR_AUDIO_RING_VOLUME,
OPSTR_AUDIO_MEDIA_VOLUME,
OPSTR_AUDIO_ALARM_VOLUME,
OPSTR_AUDIO_NOTIFICATION_VOLUME,
OPSTR_AUDIO_BLUETOOTH_VOLUME,
OPSTR_WAKE_LOCK,
OPSTR_MONITOR_LOCATION,
OPSTR_MONITOR_HIGH_POWER_LOCATION,
OPSTR_GET_USAGE_STATS,
OPSTR_MUTE_MICROPHONE,
OPSTR_TOAST_WINDOW,
OPSTR_PROJECT_MEDIA,
OPSTR_ACTIVATE_VPN,
OPSTR_WRITE_WALLPAPER,
OPSTR_ASSIST_STRUCTURE,
OPSTR_ASSIST_SCREENSHOT,
OPSTR_READ_PHONE_STATE,
OPSTR_ADD_VOICEMAIL,
OPSTR_USE_SIP,
OPSTR_PROCESS_OUTGOING_CALLS,
OPSTR_USE_FINGERPRINT,
OPSTR_BODY_SENSORS,
OPSTR_READ_CELL_BROADCASTS,
OPSTR_MOCK_LOCATION,
OPSTR_READ_EXTERNAL_STORAGE,
OPSTR_WRITE_EXTERNAL_STORAGE,
OPSTR_TURN_SCREEN_ON,
OPSTR_GET_ACCOUNTS,
OPSTR_RUN_IN_BACKGROUND,
OPSTR_AUDIO_ACCESSIBILITY_VOLUME,
OPSTR_READ_PHONE_NUMBERS,
OPSTR_REQUEST_INSTALL_PACKAGES,
OPSTR_PICTURE_IN_PICTURE,
OPSTR_INSTANT_APP_START_FOREGROUND,
OPSTR_ANSWER_PHONE_CALLS,
OPSTR_RUN_ANY_IN_BACKGROUND,
OPSTR_CHANGE_WIFI_STATE,
OPSTR_REQUEST_DELETE_PACKAGES,
OPSTR_BIND_ACCESSIBILITY_SERVICE,
OPSTR_ACCEPT_HANDOVER,
OPSTR_MANAGE_IPSEC_TUNNELS,
OPSTR_START_FOREGROUND,
OPSTR_BLUETOOTH_SCAN,
OPSTR_USE_BIOMETRIC,
OPSTR_ACTIVITY_RECOGNITION,
OPSTR_SMS_FINANCIAL_TRANSACTIONS,
OPSTR_READ_MEDIA_AUDIO,
OPSTR_WRITE_MEDIA_AUDIO,
OPSTR_READ_MEDIA_VIDEO,
OPSTR_WRITE_MEDIA_VIDEO,
OPSTR_READ_MEDIA_IMAGES,
OPSTR_WRITE_MEDIA_IMAGES,
OPSTR_LEGACY_STORAGE,
OPSTR_ACCESS_ACCESSIBILITY,
OPSTR_READ_DEVICE_IDENTIFIERS,
OPSTR_ACCESS_MEDIA_LOCATION,
OPSTR_QUERY_ALL_PACKAGES,
OPSTR_MANAGE_EXTERNAL_STORAGE,
OPSTR_INTERACT_ACROSS_PROFILES,
OPSTR_ACTIVATE_PLATFORM_VPN,
OPSTR_LOADER_USAGE_STATS,
"", // deprecated
OPSTR_AUTO_REVOKE_PERMISSIONS_IF_UNUSED,
OPSTR_AUTO_REVOKE_MANAGED_BY_INSTALLER,
OPSTR_NO_ISOLATED_STORAGE,
OPSTR_PHONE_CALL_MICROPHONE,
OPSTR_PHONE_CALL_CAMERA,
OPSTR_RECORD_AUDIO_HOTWORD,
OPSTR_MANAGE_ONGOING_CALLS,
OPSTR_MANAGE_CREDENTIALS,
OPSTR_USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER,
OPSTR_RECORD_AUDIO_OUTPUT,
OPSTR_SCHEDULE_EXACT_ALARM,
OPSTR_FINE_LOCATION_SOURCE,
OPSTR_COARSE_LOCATION_SOURCE,
OPSTR_MANAGE_MEDIA,
OPSTR_BLUETOOTH_CONNECT,
OPSTR_UWB_RANGING,
OPSTR_ACTIVITY_RECOGNITION_SOURCE,
OPSTR_BLUETOOTH_ADVERTISE,
OPSTR_RECORD_INCOMING_PHONE_AUDIO,
OPSTR_NEARBY_WIFI_DEVICES,
OPSTR_ESTABLISH_VPN_SERVICE,
OPSTR_ESTABLISH_VPN_MANAGER,
OPSTR_ACCESS_RESTRICTED_SETTINGS,
OPSTR_RECEIVE_AMBIENT_TRIGGER_AUDIO,
};
/**
* This provides a simple name for each operation to be used
* in debug output.
*/
private static String[] sOpNames = new String[] {
"COARSE_LOCATION",
"FINE_LOCATION",
"GPS",
"VIBRATE",
"READ_CONTACTS",
"WRITE_CONTACTS",
"READ_CALL_LOG",
"WRITE_CALL_LOG",
"READ_CALENDAR",
"WRITE_CALENDAR",
"WIFI_SCAN",
"POST_NOTIFICATION",
"NEIGHBORING_CELLS",
"CALL_PHONE",
"READ_SMS",
"WRITE_SMS",
"RECEIVE_SMS",
"RECEIVE_EMERGECY_SMS",
"RECEIVE_MMS",
"RECEIVE_WAP_PUSH",
"SEND_SMS",
"READ_ICC_SMS",
"WRITE_ICC_SMS",
"WRITE_SETTINGS",
"SYSTEM_ALERT_WINDOW",
"ACCESS_NOTIFICATIONS",
"CAMERA",
"RECORD_AUDIO",
"PLAY_AUDIO",
"READ_CLIPBOARD",
"WRITE_CLIPBOARD",
"TAKE_MEDIA_BUTTONS",
"TAKE_AUDIO_FOCUS",
"AUDIO_MASTER_VOLUME",
"AUDIO_VOICE_VOLUME",
"AUDIO_RING_VOLUME",
"AUDIO_MEDIA_VOLUME",
"AUDIO_ALARM_VOLUME",
"AUDIO_NOTIFICATION_VOLUME",
"AUDIO_BLUETOOTH_VOLUME",
"WAKE_LOCK",
"MONITOR_LOCATION",
"MONITOR_HIGH_POWER_LOCATION",
"GET_USAGE_STATS",
"MUTE_MICROPHONE",
"TOAST_WINDOW",
"PROJECT_MEDIA",
"ACTIVATE_VPN",
"WRITE_WALLPAPER",
"ASSIST_STRUCTURE",
"ASSIST_SCREENSHOT",
"READ_PHONE_STATE",
"ADD_VOICEMAIL",
"USE_SIP",
"PROCESS_OUTGOING_CALLS",
"USE_FINGERPRINT",
"BODY_SENSORS",
"READ_CELL_BROADCASTS",
"MOCK_LOCATION",
"READ_EXTERNAL_STORAGE",
"WRITE_EXTERNAL_STORAGE",
"TURN_ON_SCREEN",
"GET_ACCOUNTS",
"RUN_IN_BACKGROUND",
"AUDIO_ACCESSIBILITY_VOLUME",
"READ_PHONE_NUMBERS",
"REQUEST_INSTALL_PACKAGES",
"PICTURE_IN_PICTURE",
"INSTANT_APP_START_FOREGROUND",
"ANSWER_PHONE_CALLS",
"RUN_ANY_IN_BACKGROUND",
"CHANGE_WIFI_STATE",
"REQUEST_DELETE_PACKAGES",
"BIND_ACCESSIBILITY_SERVICE",
"ACCEPT_HANDOVER",
"MANAGE_IPSEC_TUNNELS",
"START_FOREGROUND",
"BLUETOOTH_SCAN",
"USE_BIOMETRIC",
"ACTIVITY_RECOGNITION",
"SMS_FINANCIAL_TRANSACTIONS",
"READ_MEDIA_AUDIO",
"WRITE_MEDIA_AUDIO",
"READ_MEDIA_VIDEO",
"WRITE_MEDIA_VIDEO",
"READ_MEDIA_IMAGES",
"WRITE_MEDIA_IMAGES",
"LEGACY_STORAGE",
"ACCESS_ACCESSIBILITY",
"READ_DEVICE_IDENTIFIERS",
"ACCESS_MEDIA_LOCATION",
"QUERY_ALL_PACKAGES",
"MANAGE_EXTERNAL_STORAGE",
"INTERACT_ACROSS_PROFILES",
"ACTIVATE_PLATFORM_VPN",
"LOADER_USAGE_STATS",
"deprecated",
"AUTO_REVOKE_PERMISSIONS_IF_UNUSED",
"AUTO_REVOKE_MANAGED_BY_INSTALLER",
"NO_ISOLATED_STORAGE",
"PHONE_CALL_MICROPHONE",
"PHONE_CALL_CAMERA",
"RECORD_AUDIO_HOTWORD",
"MANAGE_ONGOING_CALLS",
"MANAGE_CREDENTIALS",
"USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER",
"RECORD_AUDIO_OUTPUT",
"SCHEDULE_EXACT_ALARM",
"FINE_LOCATION_SOURCE",
"COARSE_LOCATION_SOURCE",
"MANAGE_MEDIA",
"BLUETOOTH_CONNECT",
"UWB_RANGING",
"ACTIVITY_RECOGNITION_SOURCE",
"BLUETOOTH_ADVERTISE",
"RECORD_INCOMING_PHONE_AUDIO",
"NEARBY_WIFI_DEVICES",
"ESTABLISH_VPN_SERVICE",
"ESTABLISH_VPN_MANAGER",
"ACCESS_RESTRICTED_SETTINGS",
"RECEIVE_SOUNDTRIGGER_AUDIO",
};
/**
* This optionally maps a permission to an operation. If there
* is no permission associated with an operation, it is null.
*/
@UnsupportedAppUsage
private static String[] sOpPerms = new String[] {
android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.ACCESS_FINE_LOCATION,
null,
android.Manifest.permission.VIBRATE,
android.Manifest.permission.READ_CONTACTS,
android.Manifest.permission.WRITE_CONTACTS,
android.Manifest.permission.READ_CALL_LOG,
android.Manifest.permission.WRITE_CALL_LOG,
android.Manifest.permission.READ_CALENDAR,
android.Manifest.permission.WRITE_CALENDAR,
android.Manifest.permission.ACCESS_WIFI_STATE,
android.Manifest.permission.POST_NOTIFICATIONS,
null, // neighboring cells shares the coarse location perm
android.Manifest.permission.CALL_PHONE,
android.Manifest.permission.READ_SMS,
null, // no permission required for writing sms
android.Manifest.permission.RECEIVE_SMS,
android.Manifest.permission.RECEIVE_EMERGENCY_BROADCAST,
android.Manifest.permission.RECEIVE_MMS,
android.Manifest.permission.RECEIVE_WAP_PUSH,
android.Manifest.permission.SEND_SMS,
android.Manifest.permission.READ_SMS,
null, // no permission required for writing icc sms
android.Manifest.permission.WRITE_SETTINGS,
android.Manifest.permission.SYSTEM_ALERT_WINDOW,
android.Manifest.permission.ACCESS_NOTIFICATIONS,
android.Manifest.permission.CAMERA,
android.Manifest.permission.RECORD_AUDIO,
null, // no permission for playing audio
null, // no permission for reading clipboard
null, // no permission for writing clipboard
null, // no permission for taking media buttons
null, // no permission for taking audio focus
null, // no permission for changing global volume
null, // no permission for changing voice volume
null, // no permission for changing ring volume
null, // no permission for changing media volume
null, // no permission for changing alarm volume
null, // no permission for changing notification volume
null, // no permission for changing bluetooth volume
android.Manifest.permission.WAKE_LOCK,
null, // no permission for generic location monitoring
null, // no permission for high power location monitoring
android.Manifest.permission.PACKAGE_USAGE_STATS,
null, // no permission for muting/unmuting microphone
null, // no permission for displaying toasts
null, // no permission for projecting media
null, // no permission for activating vpn
null, // no permission for supporting wallpaper
null, // no permission for receiving assist structure
null, // no permission for receiving assist screenshot
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.ADD_VOICEMAIL,
Manifest.permission.USE_SIP,
Manifest.permission.PROCESS_OUTGOING_CALLS,
Manifest.permission.USE_FINGERPRINT,
Manifest.permission.BODY_SENSORS,
Manifest.permission.READ_CELL_BROADCASTS,
null,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
null, // no permission for turning the screen on
Manifest.permission.GET_ACCOUNTS,
null, // no permission for running in background
null, // no permission for changing accessibility volume
Manifest.permission.READ_PHONE_NUMBERS,
Manifest.permission.REQUEST_INSTALL_PACKAGES,
null, // no permission for entering picture-in-picture on hide
Manifest.permission.INSTANT_APP_FOREGROUND_SERVICE,
Manifest.permission.ANSWER_PHONE_CALLS,
null, // no permission for OP_RUN_ANY_IN_BACKGROUND
Manifest.permission.CHANGE_WIFI_STATE,
Manifest.permission.REQUEST_DELETE_PACKAGES,
Manifest.permission.BIND_ACCESSIBILITY_SERVICE,
Manifest.permission.ACCEPT_HANDOVER,
Manifest.permission.MANAGE_IPSEC_TUNNELS,
Manifest.permission.FOREGROUND_SERVICE,
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.USE_BIOMETRIC,
Manifest.permission.ACTIVITY_RECOGNITION,
Manifest.permission.SMS_FINANCIAL_TRANSACTIONS,
Manifest.permission.READ_MEDIA_AUDIO,
null, // no permission for OP_WRITE_MEDIA_AUDIO
Manifest.permission.READ_MEDIA_VIDEO,
null, // no permission for OP_WRITE_MEDIA_VIDEO
Manifest.permission.READ_MEDIA_IMAGES,
null, // no permission for OP_WRITE_MEDIA_IMAGES
null, // no permission for OP_LEGACY_STORAGE
null, // no permission for OP_ACCESS_ACCESSIBILITY
null, // no direct permission for OP_READ_DEVICE_IDENTIFIERS
Manifest.permission.ACCESS_MEDIA_LOCATION,
null, // no permission for OP_QUERY_ALL_PACKAGES
Manifest.permission.MANAGE_EXTERNAL_STORAGE,
android.Manifest.permission.INTERACT_ACROSS_PROFILES,
null, // no permission for OP_ACTIVATE_PLATFORM_VPN
android.Manifest.permission.LOADER_USAGE_STATS,
null, // deprecated operation
null, // no permission for OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED
null, // no permission for OP_AUTO_REVOKE_MANAGED_BY_INSTALLER
null, // no permission for OP_NO_ISOLATED_STORAGE
null, // no permission for OP_PHONE_CALL_MICROPHONE
null, // no permission for OP_PHONE_CALL_CAMERA
null, // no permission for OP_RECORD_AUDIO_HOTWORD
Manifest.permission.MANAGE_ONGOING_CALLS,
null, // no permission for OP_MANAGE_CREDENTIALS
Manifest.permission.USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER,
null, // no permission for OP_RECORD_AUDIO_OUTPUT
Manifest.permission.SCHEDULE_EXACT_ALARM,
null, // no permission for OP_ACCESS_FINE_LOCATION_SOURCE,
null, // no permission for OP_ACCESS_COARSE_LOCATION_SOURCE,
Manifest.permission.MANAGE_MEDIA,
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.UWB_RANGING,
null, // no permission for OP_ACTIVITY_RECOGNITION_SOURCE,
Manifest.permission.BLUETOOTH_ADVERTISE,
null, // no permission for OP_RECORD_INCOMING_PHONE_AUDIO,
Manifest.permission.NEARBY_WIFI_DEVICES,
null, // no permission for OP_ESTABLISH_VPN_SERVICE
null, // no permission for OP_ESTABLISH_VPN_MANAGER
null, // no permission for OP_ACCESS_RESTRICTED_SETTINGS,
null, // no permission for OP_RECEIVE_SOUNDTRIGGER_AUDIO
};
/**
* Specifies whether an Op should be restricted by a user restriction.
* Each Op should be filled with a restriction string from UserManager or
* null to specify it is not affected by any user restriction.
*/
private static String[] sOpRestrictions = new String[] {
UserManager.DISALLOW_SHARE_LOCATION, //COARSE_LOCATION
UserManager.DISALLOW_SHARE_LOCATION, //FINE_LOCATION
UserManager.DISALLOW_SHARE_LOCATION, //GPS
null, //VIBRATE
null, //READ_CONTACTS
null, //WRITE_CONTACTS
UserManager.DISALLOW_OUTGOING_CALLS, //READ_CALL_LOG
UserManager.DISALLOW_OUTGOING_CALLS, //WRITE_CALL_LOG
null, //READ_CALENDAR
null, //WRITE_CALENDAR
UserManager.DISALLOW_SHARE_LOCATION, //WIFI_SCAN
null, //POST_NOTIFICATION
null, //NEIGHBORING_CELLS
null, //CALL_PHONE
UserManager.DISALLOW_SMS, //READ_SMS
UserManager.DISALLOW_SMS, //WRITE_SMS
UserManager.DISALLOW_SMS, //RECEIVE_SMS
null, //RECEIVE_EMERGENCY_SMS
UserManager.DISALLOW_SMS, //RECEIVE_MMS
null, //RECEIVE_WAP_PUSH
UserManager.DISALLOW_SMS, //SEND_SMS
UserManager.DISALLOW_SMS, //READ_ICC_SMS
UserManager.DISALLOW_SMS, //WRITE_ICC_SMS
null, //WRITE_SETTINGS
UserManager.DISALLOW_CREATE_WINDOWS, //SYSTEM_ALERT_WINDOW
null, //ACCESS_NOTIFICATIONS
UserManager.DISALLOW_CAMERA, //CAMERA
UserManager.DISALLOW_RECORD_AUDIO, //RECORD_AUDIO
null, //PLAY_AUDIO
null, //READ_CLIPBOARD
null, //WRITE_CLIPBOARD
null, //TAKE_MEDIA_BUTTONS
null, //TAKE_AUDIO_FOCUS
UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MASTER_VOLUME
UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_VOICE_VOLUME
UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_RING_VOLUME
UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_MEDIA_VOLUME
UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ALARM_VOLUME
UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_NOTIFICATION_VOLUME
UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_BLUETOOTH_VOLUME
null, //WAKE_LOCK
UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_LOCATION
UserManager.DISALLOW_SHARE_LOCATION, //MONITOR_HIGH_POWER_LOCATION
null, //GET_USAGE_STATS
UserManager.DISALLOW_UNMUTE_MICROPHONE, // MUTE_MICROPHONE
UserManager.DISALLOW_CREATE_WINDOWS, // TOAST_WINDOW
null, //PROJECT_MEDIA
null, // ACTIVATE_VPN
UserManager.DISALLOW_WALLPAPER, // WRITE_WALLPAPER
null, // ASSIST_STRUCTURE
null, // ASSIST_SCREENSHOT
null, // READ_PHONE_STATE
null, // ADD_VOICEMAIL
null, // USE_SIP
null, // PROCESS_OUTGOING_CALLS
null, // USE_FINGERPRINT
null, // BODY_SENSORS
null, // READ_CELL_BROADCASTS
null, // MOCK_LOCATION
null, // READ_EXTERNAL_STORAGE
null, // WRITE_EXTERNAL_STORAGE
null, // TURN_ON_SCREEN
null, // GET_ACCOUNTS
null, // RUN_IN_BACKGROUND
UserManager.DISALLOW_ADJUST_VOLUME, //AUDIO_ACCESSIBILITY_VOLUME
null, // READ_PHONE_NUMBERS
null, // REQUEST_INSTALL_PACKAGES
null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
null, // INSTANT_APP_START_FOREGROUND
null, // ANSWER_PHONE_CALLS
null, // OP_RUN_ANY_IN_BACKGROUND
null, // OP_CHANGE_WIFI_STATE
null, // REQUEST_DELETE_PACKAGES
null, // OP_BIND_ACCESSIBILITY_SERVICE
null, // ACCEPT_HANDOVER
null, // MANAGE_IPSEC_TUNNELS
null, // START_FOREGROUND
null, // maybe should be UserManager.DISALLOW_SHARE_LOCATION, //BLUETOOTH_SCAN
null, // USE_BIOMETRIC
null, // ACTIVITY_RECOGNITION
UserManager.DISALLOW_SMS, // SMS_FINANCIAL_TRANSACTIONS
null, // READ_MEDIA_AUDIO
null, // WRITE_MEDIA_AUDIO
null, // READ_MEDIA_VIDEO
null, // WRITE_MEDIA_VIDEO
null, // READ_MEDIA_IMAGES
null, // WRITE_MEDIA_IMAGES
null, // LEGACY_STORAGE
null, // ACCESS_ACCESSIBILITY
null, // READ_DEVICE_IDENTIFIERS
null, // ACCESS_MEDIA_LOCATION
null, // QUERY_ALL_PACKAGES
null, // MANAGE_EXTERNAL_STORAGE
null, // INTERACT_ACROSS_PROFILES
null, // ACTIVATE_PLATFORM_VPN
null, // LOADER_USAGE_STATS
null, // deprecated operation
null, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED
null, // AUTO_REVOKE_MANAGED_BY_INSTALLER
null, // NO_ISOLATED_STORAGE
null, // PHONE_CALL_MICROPHONE
null, // PHONE_CALL_MICROPHONE
null, // RECORD_AUDIO_HOTWORD
null, // MANAGE_ONGOING_CALLS
null, // MANAGE_CREDENTIALS
null, // USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER
null, // RECORD_AUDIO_OUTPUT
null, // SCHEDULE_EXACT_ALARM
null, // ACCESS_FINE_LOCATION_SOURCE
null, // ACCESS_COARSE_LOCATION_SOURCE
null, // MANAGE_MEDIA
null, // BLUETOOTH_CONNECT
null, // UWB_RANGING
null, // ACTIVITY_RECOGNITION_SOURCE
null, // BLUETOOTH_ADVERTISE
null, // RECORD_INCOMING_PHONE_AUDIO
null, // NEARBY_WIFI_DEVICES
null, // ESTABLISH_VPN_SERVICE
null, // ESTABLISH_VPN_MANAGER
null, // ACCESS_RESTRICTED_SETTINGS
null, // RECEIVE_SOUNDTRIGGER_AUDIO
};
/**
* In which cases should an app be allowed to bypass the {@link #setUserRestriction user
* restriction} for a certain app-op.
*/
private static RestrictionBypass[] sOpAllowSystemRestrictionBypass = new RestrictionBypass[] {
new RestrictionBypass(true, false, false), //COARSE_LOCATION
new RestrictionBypass(true, false, false), //FINE_LOCATION
null, //GPS
null, //VIBRATE
null, //READ_CONTACTS
null, //WRITE_CONTACTS
null, //READ_CALL_LOG
null, //WRITE_CALL_LOG
null, //READ_CALENDAR
null, //WRITE_CALENDAR
new RestrictionBypass(false, true, false), //WIFI_SCAN
null, //POST_NOTIFICATION
null, //NEIGHBORING_CELLS
null, //CALL_PHONE
null, //READ_SMS
null, //WRITE_SMS
null, //RECEIVE_SMS
null, //RECEIVE_EMERGECY_SMS
null, //RECEIVE_MMS
null, //RECEIVE_WAP_PUSH
null, //SEND_SMS
null, //READ_ICC_SMS
null, //WRITE_ICC_SMS
null, //WRITE_SETTINGS
new RestrictionBypass(false, true, false), //SYSTEM_ALERT_WINDOW
null, //ACCESS_NOTIFICATIONS
null, //CAMERA
new RestrictionBypass(false, false, true), //RECORD_AUDIO
null, //PLAY_AUDIO
null, //READ_CLIPBOARD
null, //WRITE_CLIPBOARD
null, //TAKE_MEDIA_BUTTONS
null, //TAKE_AUDIO_FOCUS
null, //AUDIO_MASTER_VOLUME
null, //AUDIO_VOICE_VOLUME
null, //AUDIO_RING_VOLUME
null, //AUDIO_MEDIA_VOLUME
null, //AUDIO_ALARM_VOLUME
null, //AUDIO_NOTIFICATION_VOLUME
null, //AUDIO_BLUETOOTH_VOLUME
null, //WAKE_LOCK
null, //MONITOR_LOCATION
null, //MONITOR_HIGH_POWER_LOCATION
null, //GET_USAGE_STATS
null, //MUTE_MICROPHONE
new RestrictionBypass(false, true, false), //TOAST_WINDOW
null, //PROJECT_MEDIA
null, //ACTIVATE_VPN
null, //WALLPAPER
null, //ASSIST_STRUCTURE
null, //ASSIST_SCREENSHOT
null, //READ_PHONE_STATE
null, //ADD_VOICEMAIL
null, // USE_SIP
null, // PROCESS_OUTGOING_CALLS
null, // USE_FINGERPRINT
null, // BODY_SENSORS
null, // READ_CELL_BROADCASTS
null, // MOCK_LOCATION
null, // READ_EXTERNAL_STORAGE
null, // WRITE_EXTERNAL_STORAGE
null, // TURN_ON_SCREEN
null, // GET_ACCOUNTS
null, // RUN_IN_BACKGROUND
null, // AUDIO_ACCESSIBILITY_VOLUME
null, // READ_PHONE_NUMBERS
null, // REQUEST_INSTALL_PACKAGES
null, // ENTER_PICTURE_IN_PICTURE_ON_HIDE
null, // INSTANT_APP_START_FOREGROUND
null, // ANSWER_PHONE_CALLS
null, // OP_RUN_ANY_IN_BACKGROUND
null, // OP_CHANGE_WIFI_STATE
null, // OP_REQUEST_DELETE_PACKAGES
null, // OP_BIND_ACCESSIBILITY_SERVICE
null, // ACCEPT_HANDOVER
null, // MANAGE_IPSEC_HANDOVERS
null, // START_FOREGROUND
new RestrictionBypass(false, true, false), // BLUETOOTH_SCAN
null, // USE_BIOMETRIC
null, // ACTIVITY_RECOGNITION
null, // SMS_FINANCIAL_TRANSACTIONS
null, // READ_MEDIA_AUDIO
null, // WRITE_MEDIA_AUDIO
null, // READ_MEDIA_VIDEO
null, // WRITE_MEDIA_VIDEO
null, // READ_MEDIA_IMAGES
null, // WRITE_MEDIA_IMAGES
null, // LEGACY_STORAGE
null, // ACCESS_ACCESSIBILITY
null, // READ_DEVICE_IDENTIFIERS
null, // ACCESS_MEDIA_LOCATION
null, // QUERY_ALL_PACKAGES
null, // MANAGE_EXTERNAL_STORAGE
null, // INTERACT_ACROSS_PROFILES
null, // ACTIVATE_PLATFORM_VPN
null, // LOADER_USAGE_STATS
null, // deprecated operation
null, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED
null, // AUTO_REVOKE_MANAGED_BY_INSTALLER
null, // NO_ISOLATED_STORAGE
null, // PHONE_CALL_MICROPHONE
null, // PHONE_CALL_CAMERA
null, // RECORD_AUDIO_HOTWORD
null, // MANAGE_ONGOING_CALLS
null, // MANAGE_CREDENTIALS
null, // USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER
null, // RECORD_AUDIO_OUTPUT
null, // SCHEDULE_EXACT_ALARM
null, // ACCESS_FINE_LOCATION_SOURCE
null, // ACCESS_COARSE_LOCATION_SOURCE
null, // MANAGE_MEDIA
null, // BLUETOOTH_CONNECT
null, // UWB_RANGING
null, // ACTIVITY_RECOGNITION_SOURCE
null, // BLUETOOTH_ADVERTISE
null, // RECORD_INCOMING_PHONE_AUDIO
null, // NEARBY_WIFI_DEVICES
null, // ESTABLISH_VPN_SERVICE
null, // ESTABLISH_VPN_MANAGER
null, // ACCESS_RESTRICTED_SETTINGS
null, // RECEIVE_SOUNDTRIGGER_AUDIO
};
/**
* This specifies the default mode for each operation.
*/
private static int[] sOpDefaultMode = new int[] {
AppOpsManager.MODE_ALLOWED, // COARSE_LOCATION
AppOpsManager.MODE_ALLOWED, // FINE_LOCATION
AppOpsManager.MODE_ALLOWED, // GPS
AppOpsManager.MODE_ALLOWED, // VIBRATE
AppOpsManager.MODE_ALLOWED, // READ_CONTACTS
AppOpsManager.MODE_ALLOWED, // WRITE_CONTACTS
AppOpsManager.MODE_ALLOWED, // READ_CALL_LOG
AppOpsManager.MODE_ALLOWED, // WRITE_CALL_LOG
AppOpsManager.MODE_ALLOWED, // READ_CALENDAR
AppOpsManager.MODE_ALLOWED, // WRITE_CALENDAR
AppOpsManager.MODE_ALLOWED, // WIFI_SCAN
AppOpsManager.MODE_ALLOWED, // POST_NOTIFICATION
AppOpsManager.MODE_ALLOWED, // NEIGHBORING_CELLS
AppOpsManager.MODE_ALLOWED, // CALL_PHONE
AppOpsManager.MODE_ALLOWED, // READ_SMS
AppOpsManager.MODE_IGNORED, // WRITE_SMS
AppOpsManager.MODE_ALLOWED, // RECEIVE_SMS
AppOpsManager.MODE_ALLOWED, // RECEIVE_EMERGENCY_BROADCAST
AppOpsManager.MODE_ALLOWED, // RECEIVE_MMS
AppOpsManager.MODE_ALLOWED, // RECEIVE_WAP_PUSH
AppOpsManager.MODE_ALLOWED, // SEND_SMS
AppOpsManager.MODE_ALLOWED, // READ_ICC_SMS
AppOpsManager.MODE_ALLOWED, // WRITE_ICC_SMS
AppOpsManager.MODE_DEFAULT, // WRITE_SETTINGS
getSystemAlertWindowDefault(), // SYSTEM_ALERT_WINDOW
AppOpsManager.MODE_ALLOWED, // ACCESS_NOTIFICATIONS
AppOpsManager.MODE_ALLOWED, // CAMERA
AppOpsManager.MODE_ALLOWED, // RECORD_AUDIO
AppOpsManager.MODE_ALLOWED, // PLAY_AUDIO
AppOpsManager.MODE_ALLOWED, // READ_CLIPBOARD
AppOpsManager.MODE_ALLOWED, // WRITE_CLIPBOARD
AppOpsManager.MODE_ALLOWED, // TAKE_MEDIA_BUTTONS
AppOpsManager.MODE_ALLOWED, // TAKE_AUDIO_FOCUS
AppOpsManager.MODE_ALLOWED, // AUDIO_MASTER_VOLUME
AppOpsManager.MODE_ALLOWED, // AUDIO_VOICE_VOLUME
AppOpsManager.MODE_ALLOWED, // AUDIO_RING_VOLUME
AppOpsManager.MODE_ALLOWED, // AUDIO_MEDIA_VOLUME
AppOpsManager.MODE_ALLOWED, // AUDIO_ALARM_VOLUME
AppOpsManager.MODE_ALLOWED, // AUDIO_NOTIFICATION_VOLUME
AppOpsManager.MODE_ALLOWED, // AUDIO_BLUETOOTH_VOLUME
AppOpsManager.MODE_ALLOWED, // WAKE_LOCK
AppOpsManager.MODE_ALLOWED, // MONITOR_LOCATION
AppOpsManager.MODE_ALLOWED, // MONITOR_HIGH_POWER_LOCATION
AppOpsManager.MODE_DEFAULT, // GET_USAGE_STATS
AppOpsManager.MODE_ALLOWED, // MUTE_MICROPHONE
AppOpsManager.MODE_ALLOWED, // TOAST_WINDOW
AppOpsManager.MODE_IGNORED, // PROJECT_MEDIA
AppOpsManager.MODE_IGNORED, // ACTIVATE_VPN
AppOpsManager.MODE_ALLOWED, // WRITE_WALLPAPER
AppOpsManager.MODE_ALLOWED, // ASSIST_STRUCTURE
AppOpsManager.MODE_ALLOWED, // ASSIST_SCREENSHOT
AppOpsManager.MODE_ALLOWED, // READ_PHONE_STATE
AppOpsManager.MODE_ALLOWED, // ADD_VOICEMAIL
AppOpsManager.MODE_ALLOWED, // USE_SIP
AppOpsManager.MODE_ALLOWED, // PROCESS_OUTGOING_CALLS
AppOpsManager.MODE_ALLOWED, // USE_FINGERPRINT
AppOpsManager.MODE_ALLOWED, // BODY_SENSORS
AppOpsManager.MODE_ALLOWED, // READ_CELL_BROADCASTS
AppOpsManager.MODE_ERRORED, // MOCK_LOCATION
AppOpsManager.MODE_ALLOWED, // READ_EXTERNAL_STORAGE
AppOpsManager.MODE_ALLOWED, // WRITE_EXTERNAL_STORAGE
AppOpsManager.MODE_ALLOWED, // TURN_SCREEN_ON
AppOpsManager.MODE_ALLOWED, // GET_ACCOUNTS
AppOpsManager.MODE_ALLOWED, // RUN_IN_BACKGROUND
AppOpsManager.MODE_ALLOWED, // AUDIO_ACCESSIBILITY_VOLUME
AppOpsManager.MODE_ALLOWED, // READ_PHONE_NUMBERS
AppOpsManager.MODE_DEFAULT, // REQUEST_INSTALL_PACKAGES
AppOpsManager.MODE_ALLOWED, // PICTURE_IN_PICTURE
AppOpsManager.MODE_DEFAULT, // INSTANT_APP_START_FOREGROUND
AppOpsManager.MODE_ALLOWED, // ANSWER_PHONE_CALLS
AppOpsManager.MODE_ALLOWED, // RUN_ANY_IN_BACKGROUND
AppOpsManager.MODE_ALLOWED, // CHANGE_WIFI_STATE
AppOpsManager.MODE_ALLOWED, // REQUEST_DELETE_PACKAGES
AppOpsManager.MODE_ALLOWED, // BIND_ACCESSIBILITY_SERVICE
AppOpsManager.MODE_ALLOWED, // ACCEPT_HANDOVER
AppOpsManager.MODE_ERRORED, // MANAGE_IPSEC_TUNNELS
AppOpsManager.MODE_ALLOWED, // START_FOREGROUND
AppOpsManager.MODE_ALLOWED, // BLUETOOTH_SCAN
AppOpsManager.MODE_ALLOWED, // USE_BIOMETRIC
AppOpsManager.MODE_ALLOWED, // ACTIVITY_RECOGNITION
AppOpsManager.MODE_DEFAULT, // SMS_FINANCIAL_TRANSACTIONS
AppOpsManager.MODE_ALLOWED, // READ_MEDIA_AUDIO
AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_AUDIO
AppOpsManager.MODE_ALLOWED, // READ_MEDIA_VIDEO
AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_VIDEO
AppOpsManager.MODE_ALLOWED, // READ_MEDIA_IMAGES
AppOpsManager.MODE_ERRORED, // WRITE_MEDIA_IMAGES
AppOpsManager.MODE_DEFAULT, // LEGACY_STORAGE
AppOpsManager.MODE_ALLOWED, // ACCESS_ACCESSIBILITY
AppOpsManager.MODE_ERRORED, // READ_DEVICE_IDENTIFIERS
AppOpsManager.MODE_ALLOWED, // ALLOW_MEDIA_LOCATION
AppOpsManager.MODE_DEFAULT, // QUERY_ALL_PACKAGES
AppOpsManager.MODE_DEFAULT, // MANAGE_EXTERNAL_STORAGE
AppOpsManager.MODE_DEFAULT, // INTERACT_ACROSS_PROFILES
AppOpsManager.MODE_IGNORED, // ACTIVATE_PLATFORM_VPN
AppOpsManager.MODE_DEFAULT, // LOADER_USAGE_STATS
AppOpsManager.MODE_IGNORED, // deprecated operation
AppOpsManager.MODE_DEFAULT, // OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED
AppOpsManager.MODE_ALLOWED, // OP_AUTO_REVOKE_MANAGED_BY_INSTALLER
AppOpsManager.MODE_ERRORED, // OP_NO_ISOLATED_STORAGE
AppOpsManager.MODE_ALLOWED, // PHONE_CALL_MICROPHONE
AppOpsManager.MODE_ALLOWED, // PHONE_CALL_CAMERA
AppOpsManager.MODE_ALLOWED, // RECORD_AUDIO_HOTWORD
AppOpsManager.MODE_DEFAULT, // MANAGE_ONGOING_CALLS
AppOpsManager.MODE_DEFAULT, // MANAGE_CREDENTIALS
AppOpsManager.MODE_DEFAULT, // USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER
AppOpsManager.MODE_ALLOWED, // RECORD_AUDIO_OUTPUT
AppOpsManager.MODE_DEFAULT, // SCHEDULE_EXACT_ALARM
AppOpsManager.MODE_ALLOWED, // ACCESS_FINE_LOCATION_SOURCE
AppOpsManager.MODE_ALLOWED, // ACCESS_COARSE_LOCATION_SOURCE
AppOpsManager.MODE_DEFAULT, // MANAGE_MEDIA
AppOpsManager.MODE_ALLOWED, // BLUETOOTH_CONNECT
AppOpsManager.MODE_ALLOWED, // UWB_RANGING
AppOpsManager.MODE_ALLOWED, // ACTIVITY_RECOGNITION_SOURCE
AppOpsManager.MODE_ALLOWED, // BLUETOOTH_ADVERTISE
AppOpsManager.MODE_ALLOWED, // RECORD_INCOMING_PHONE_AUDIO
AppOpsManager.MODE_ALLOWED, // NEARBY_WIFI_DEVICES
AppOpsManager.MODE_ALLOWED, // ESTABLISH_VPN_SERVICE
AppOpsManager.MODE_ALLOWED, // ESTABLISH_VPN_MANAGER
AppOpsManager.MODE_ALLOWED, // ACCESS_RESTRICTED_SETTINGS,
AppOpsManager.MODE_ALLOWED, // RECEIVE_SOUNDTRIGGER_AUDIO
};
/**
* This specifies whether each option is allowed to be reset
* when resetting all app preferences. Disable reset for
* app ops that are under strong control of some part of the
* system (such as OP_WRITE_SMS, which should be allowed only
* for whichever app is selected as the current SMS app).
*/
private static boolean[] sOpDisableReset = new boolean[] {
false, // COARSE_LOCATION
false, // FINE_LOCATION
false, // GPS
false, // VIBRATE
false, // READ_CONTACTS
false, // WRITE_CONTACTS
false, // READ_CALL_LOG
false, // WRITE_CALL_LOG
false, // READ_CALENDAR
false, // WRITE_CALENDAR
false, // WIFI_SCAN
false, // POST_NOTIFICATION
false, // NEIGHBORING_CELLS
false, // CALL_PHONE
true, // READ_SMS
true, // WRITE_SMS
true, // RECEIVE_SMS
false, // RECEIVE_EMERGENCY_BROADCAST
false, // RECEIVE_MMS
true, // RECEIVE_WAP_PUSH
true, // SEND_SMS
false, // READ_ICC_SMS
false, // WRITE_ICC_SMS
false, // WRITE_SETTINGS
false, // SYSTEM_ALERT_WINDOW
false, // ACCESS_NOTIFICATIONS
false, // CAMERA
false, // RECORD_AUDIO
false, // PLAY_AUDIO
false, // READ_CLIPBOARD
false, // WRITE_CLIPBOARD
false, // TAKE_MEDIA_BUTTONS
false, // TAKE_AUDIO_FOCUS
false, // AUDIO_MASTER_VOLUME
false, // AUDIO_VOICE_VOLUME
false, // AUDIO_RING_VOLUME
false, // AUDIO_MEDIA_VOLUME
false, // AUDIO_ALARM_VOLUME
false, // AUDIO_NOTIFICATION_VOLUME
false, // AUDIO_BLUETOOTH_VOLUME
false, // WAKE_LOCK
false, // MONITOR_LOCATION
false, // MONITOR_HIGH_POWER_LOCATION
false, // GET_USAGE_STATS
false, // MUTE_MICROPHONE
false, // TOAST_WINDOW
false, // PROJECT_MEDIA
false, // ACTIVATE_VPN
false, // WRITE_WALLPAPER
false, // ASSIST_STRUCTURE
false, // ASSIST_SCREENSHOT
false, // READ_PHONE_STATE
false, // ADD_VOICEMAIL
false, // USE_SIP
false, // PROCESS_OUTGOING_CALLS
false, // USE_FINGERPRINT
false, // BODY_SENSORS
true, // READ_CELL_BROADCASTS
false, // MOCK_LOCATION
false, // READ_EXTERNAL_STORAGE
false, // WRITE_EXTERNAL_STORAGE
false, // TURN_SCREEN_ON
false, // GET_ACCOUNTS
false, // RUN_IN_BACKGROUND
false, // AUDIO_ACCESSIBILITY_VOLUME
false, // READ_PHONE_NUMBERS
false, // REQUEST_INSTALL_PACKAGES
false, // PICTURE_IN_PICTURE
false, // INSTANT_APP_START_FOREGROUND
false, // ANSWER_PHONE_CALLS
false, // RUN_ANY_IN_BACKGROUND
false, // CHANGE_WIFI_STATE
false, // REQUEST_DELETE_PACKAGES
false, // BIND_ACCESSIBILITY_SERVICE
false, // ACCEPT_HANDOVER
false, // MANAGE_IPSEC_TUNNELS
false, // START_FOREGROUND
false, // BLUETOOTH_SCAN
false, // USE_BIOMETRIC
false, // ACTIVITY_RECOGNITION
false, // SMS_FINANCIAL_TRANSACTIONS
false, // READ_MEDIA_AUDIO
false, // WRITE_MEDIA_AUDIO
false, // READ_MEDIA_VIDEO
true, // WRITE_MEDIA_VIDEO
false, // READ_MEDIA_IMAGES
true, // WRITE_MEDIA_IMAGES
true, // LEGACY_STORAGE
false, // ACCESS_ACCESSIBILITY
false, // READ_DEVICE_IDENTIFIERS
false, // ACCESS_MEDIA_LOCATION
false, // QUERY_ALL_PACKAGES
false, // MANAGE_EXTERNAL_STORAGE
false, // INTERACT_ACROSS_PROFILES
false, // ACTIVATE_PLATFORM_VPN
false, // LOADER_USAGE_STATS
false, // deprecated operation
false, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED
false, // AUTO_REVOKE_MANAGED_BY_INSTALLER
true, // NO_ISOLATED_STORAGE
false, // PHONE_CALL_MICROPHONE
false, // PHONE_CALL_CAMERA
false, // RECORD_AUDIO_HOTWORD
true, // MANAGE_ONGOING_CALLS
false, // MANAGE_CREDENTIALS
true, // USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER
false, // RECORD_AUDIO_OUTPUT
false, // SCHEDULE_EXACT_ALARM
false, // ACCESS_FINE_LOCATION_SOURCE
false, // ACCESS_COARSE_LOCATION_SOURCE
false, // MANAGE_MEDIA
false, // BLUETOOTH_CONNECT
false, // UWB_RANGING
false, // ACTIVITY_RECOGNITION_SOURCE
false, // BLUETOOTH_ADVERTISE
false, // RECORD_INCOMING_PHONE_AUDIO
false, // NEARBY_WIFI_DEVICES
false, // OP_ESTABLISH_VPN_SERVICE
false, // OP_ESTABLISH_VPN_MANAGER
true, // ACCESS_RESTRICTED_SETTINGS
false, // RECEIVE_SOUNDTRIGGER_AUDIO
};
/**
* This specifies whether each option is only allowed to be read
* by apps with manage appops permission.
*/
private static boolean[] sOpRestrictRead = new boolean[] {
false, // COARSE_LOCATION
false, // FINE_LOCATION
false, // GPS
false, // VIBRATE
false, // READ_CONTACTS
false, // WRITE_CONTACTS
false, // READ_CALL_LOG
false, // WRITE_CALL_LOG
false, // READ_CALENDAR
false, // WRITE_CALENDAR
false, // WIFI_SCAN
false, // POST_NOTIFICATION
false, // NEIGHBORING_CELLS
false, // CALL_PHONE
false, // READ_SMS
false, // WRITE_SMS
false, // RECEIVE_SMS
false, // RECEIVE_EMERGENCY_BROADCAST
false, // RECEIVE_MMS
false, // RECEIVE_WAP_PUSH
false, // SEND_SMS
false, // READ_ICC_SMS
false, // WRITE_ICC_SMS
false, // WRITE_SETTINGS
false, // SYSTEM_ALERT_WINDOW
false, // ACCESS_NOTIFICATIONS
false, // CAMERA
false, // RECORD_AUDIO
false, // PLAY_AUDIO
false, // READ_CLIPBOARD
false, // WRITE_CLIPBOARD
false, // TAKE_MEDIA_BUTTONS
false, // TAKE_AUDIO_FOCUS
false, // AUDIO_MASTER_VOLUME
false, // AUDIO_VOICE_VOLUME
false, // AUDIO_RING_VOLUME
false, // AUDIO_MEDIA_VOLUME
false, // AUDIO_ALARM_VOLUME
false, // AUDIO_NOTIFICATION_VOLUME
false, // AUDIO_BLUETOOTH_VOLUME
false, // WAKE_LOCK
false, // MONITOR_LOCATION
false, // MONITOR_HIGH_POWER_LOCATION
false, // GET_USAGE_STATS
false, // MUTE_MICROPHONE
false, // TOAST_WINDOW
false, // PROJECT_MEDIA
false, // ACTIVATE_VPN
false, // WRITE_WALLPAPER
false, // ASSIST_STRUCTURE
false, // ASSIST_SCREENSHOT
false, // READ_PHONE_STATE
false, // ADD_VOICEMAIL
false, // USE_SIP
false, // PROCESS_OUTGOING_CALLS
false, // USE_FINGERPRINT
false, // BODY_SENSORS
false, // READ_CELL_BROADCASTS
false, // MOCK_LOCATION
false, // READ_EXTERNAL_STORAGE
false, // WRITE_EXTERNAL_STORAGE
false, // TURN_SCREEN_ON
false, // GET_ACCOUNTS
false, // RUN_IN_BACKGROUND
false, // AUDIO_ACCESSIBILITY_VOLUME
false, // READ_PHONE_NUMBERS
false, // REQUEST_INSTALL_PACKAGES
false, // PICTURE_IN_PICTURE
false, // INSTANT_APP_START_FOREGROUND
false, // ANSWER_PHONE_CALLS
false, // RUN_ANY_IN_BACKGROUND
false, // CHANGE_WIFI_STATE
false, // REQUEST_DELETE_PACKAGES
false, // BIND_ACCESSIBILITY_SERVICE
false, // ACCEPT_HANDOVER
false, // MANAGE_IPSEC_TUNNELS
false, // START_FOREGROUND
false, // BLUETOOTH_SCAN
false, // USE_BIOMETRIC
false, // ACTIVITY_RECOGNITION
false, // SMS_FINANCIAL_TRANSACTIONS
false, // READ_MEDIA_AUDIO
false, // WRITE_MEDIA_AUDIO
false, // READ_MEDIA_VIDEO
false, // WRITE_MEDIA_VIDEO
false, // READ_MEDIA_IMAGES
false, // WRITE_MEDIA_IMAGES
false, // LEGACY_STORAGE
false, // ACCESS_ACCESSIBILITY
false, // READ_DEVICE_IDENTIFIERS
false, // ACCESS_MEDIA_LOCATION
false, // QUERY_ALL_PACKAGES
false, // MANAGE_EXTERNAL_STORAGE
false, // INTERACT_ACROSS_PROFILES
false, // ACTIVATE_PLATFORM_VPN
false, // LOADER_USAGE_STATS
false, // deprecated operation
false, // AUTO_REVOKE_PERMISSIONS_IF_UNUSED
false, // AUTO_REVOKE_MANAGED_BY_INSTALLER
false, // NO_ISOLATED_STORAGE
false, // PHONE_CALL_MICROPHONE
false, // PHONE_CALL_CAMERA
false, // RECORD_AUDIO_HOTWORD
false, // MANAGE_ONGOING_CALLS
false, // MANAGE_CREDENTIALS
false, // USE_ICC_AUTH_WITH_DEVICE_IDENTIFIER
false, // RECORD_AUDIO_OUTPUT
false, // SCHEDULE_EXACT_ALARM
false, // ACCESS_FINE_LOCATION_SOURCE
false, // ACCESS_COARSE_LOCATION_SOURCE
false, // MANAGE_MEDIA
false, // BLUETOOTH_CONNECT
false, // UWB_RANGING
false, // ACTIVITY_RECOGNITION_SOURCE
false, // BLUETOOTH_ADVERTISE
false, // RECORD_INCOMING_PHONE_AUDIO
false, // NEARBY_WIFI_DEVICES
false, // OP_ESTABLISH_VPN_SERVICE
false, // OP_ESTABLISH_VPN_MANAGER
true, // ACCESS_RESTRICTED_SETTINGS
false, // RECEIVE_SOUNDTRIGGER_AUDIO
};
/**
* Mapping from an app op name to the app op code.
*/
private static HashMap<String, Integer> sOpStrToOp = new HashMap<>();
/**
* Mapping from a permission to the corresponding app op.
*/
private static HashMap<String, Integer> sPermToOp = new HashMap<>();
/**
* Set to the uid of the caller if this thread is currently executing a two-way binder
* transaction. Not set if this thread is currently not executing a two way binder transaction.
*
* @see #startNotedAppOpsCollection
* @see #getNotedOpCollectionMode
*/
private static final ThreadLocal<Integer> sBinderThreadCallingUid = new ThreadLocal<>();
/**
* If a thread is currently executing a two-way binder transaction, this stores the op-codes of
* the app-ops that were noted during this transaction.
*
* @see #getNotedOpCollectionMode
* @see #collectNotedOpSync
*/
private static final ThreadLocal<ArrayMap<String, long[]>> sAppOpsNotedInThisBinderTransaction =
new ThreadLocal<>();
/** Whether noting for an appop should be collected */
private static final @ShouldCollectNoteOp byte[] sAppOpsToNote = new byte[_NUM_OP];
static {
if (sOpToSwitch.length != _NUM_OP) {
throw new IllegalStateException("sOpToSwitch length " + sOpToSwitch.length
+ " should be " + _NUM_OP);
}
if (sOpToString.length != _NUM_OP) {
throw new IllegalStateException("sOpToString length " + sOpToString.length
+ " should be " + _NUM_OP);
}
if (sOpNames.length != _NUM_OP) {
throw new IllegalStateException("sOpNames length " + sOpNames.length
+ " should be " + _NUM_OP);
}
if (sOpPerms.length != _NUM_OP) {
throw new IllegalStateException("sOpPerms length " + sOpPerms.length
+ " should be " + _NUM_OP);
}
if (sOpDefaultMode.length != _NUM_OP) {
throw new IllegalStateException("sOpDefaultMode length " + sOpDefaultMode.length
+ " should be " + _NUM_OP);
}
if (sOpDisableReset.length != _NUM_OP) {
throw new IllegalStateException("sOpDisableReset length " + sOpDisableReset.length
+ " should be " + _NUM_OP);
}
if (sOpRestrictions.length != _NUM_OP) {
throw new IllegalStateException("sOpRestrictions length " + sOpRestrictions.length
+ " should be " + _NUM_OP);
}
if (sOpAllowSystemRestrictionBypass.length != _NUM_OP) {
throw new IllegalStateException("sOpAllowSYstemRestrictionsBypass length "
+ sOpRestrictions.length + " should be " + _NUM_OP);
}
for (int i=0; i<_NUM_OP; i++) {
if (sOpToString[i] != null) {
sOpStrToOp.put(sOpToString[i], i);
}
}
for (int op : RUNTIME_AND_APPOP_PERMISSIONS_OPS) {
if (sOpPerms[op] != null) {
sPermToOp.put(sOpPerms[op], op);
}
}
if ((_NUM_OP + Long.SIZE - 1) / Long.SIZE != 2) {
// The code currently assumes that the length of sAppOpsNotedInThisBinderTransaction is
// two longs
throw new IllegalStateException("notedAppOps collection code assumes < 128 appops");
}
}
/** Config used to control app ops access messages sampling */
private static MessageSamplingConfig sConfig =
new MessageSamplingConfig(OP_NONE, 0, 0);
/** @hide */
public static final String KEY_HISTORICAL_OPS = "historical_ops";
/** System properties for debug logging of noteOp call sites */
private static final String DEBUG_LOGGING_ENABLE_PROP = "appops.logging_enabled";
private static final String DEBUG_LOGGING_PACKAGES_PROP = "appops.logging_packages";
private static final String DEBUG_LOGGING_OPS_PROP = "appops.logging_ops";
private static final String DEBUG_LOGGING_TAG = "AppOpsManager";
/**
* Retrieve the op switch that controls the given operation.
* @hide
*/
@UnsupportedAppUsage
public static int opToSwitch(int op) {
return sOpToSwitch[op];
}
/**
* Retrieve a non-localized name for the operation, for debugging output.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public static String opToName(int op) {
if (op == OP_NONE) return "NONE";
return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")");
}
/**
* Retrieve a non-localized public name for the operation.
*
* @hide
*/
public static @NonNull String opToPublicName(int op) {
return sOpToString[op];
}
/**
* @hide
*/
public static int strDebugOpToOp(String op) {
for (int i=0; i<sOpNames.length; i++) {
if (sOpNames[i].equals(op)) {
return i;
}
}
throw new IllegalArgumentException("Unknown operation string: " + op);
}
/**
* Retrieve the permission associated with an operation, or null if there is not one.
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@TestApi
public static String opToPermission(int op) {
return sOpPerms[op];
}
/**
* Retrieve the permission associated with an operation, or null if there is not one.
*
* @param op The operation name.
*
* @hide
*/
@Nullable
@SystemApi
public static String opToPermission(@NonNull String op) {
return opToPermission(strOpToOp(op));
}
/**
* Retrieve the user restriction associated with an operation, or null if there is not one.
* @hide
*/
public static String opToRestriction(int op) {
return sOpRestrictions[op];
}
/**
* Retrieve the app op code for a permission, or null if there is not one.
* This API is intended to be used for mapping runtime or appop permissions
* to the corresponding app op.
* @hide
*/
@UnsupportedAppUsage
@TestApi
public static int permissionToOpCode(String permission) {
Integer boxedOpCode = sPermToOp.get(permission);
return boxedOpCode != null ? boxedOpCode : OP_NONE;
}
/**
* Retrieve whether the op allows to bypass the user restriction.
*
* @hide
*/
public static RestrictionBypass opAllowSystemBypassRestriction(int op) {
return sOpAllowSystemRestrictionBypass[op];
}
/**
* Retrieve the default mode for the operation.
* @hide
*/
public static @Mode int opToDefaultMode(int op) {
return sOpDefaultMode[op];
}
/**
* Retrieve the default mode for the app op.
*
* @param appOp The app op name
*
* @return the default mode for the app op
*
* @hide
*/
@SystemApi
public static int opToDefaultMode(@NonNull String appOp) {
return opToDefaultMode(strOpToOp(appOp));
}
/**
* Retrieve the human readable mode.
* @hide
*/
public static String modeToName(@Mode int mode) {
if (mode >= 0 && mode < MODE_NAMES.length) {
return MODE_NAMES[mode];
}
return "mode=" + mode;
}
/**
* Retrieve whether the op can be read by apps with manage appops permission.
* @hide
*/
public static boolean opRestrictsRead(int op) {
return sOpRestrictRead[op];
}
/**
* Retrieve whether the op allows itself to be reset.
* @hide
*/
public static boolean opAllowsReset(int op) {
return !sOpDisableReset[op];
}
/**
* Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}.
*
* This is intended for use client side, when the receiver id must be created before the
* associated call is made to the system server. If using {@link PendingIntent} as the receiver,
* avoid using this method as it will include a pointless additional x-process call. Instead
* prefer passing the PendingIntent to the system server, and then invoking
* {@link #toReceiverId(PendingIntent)}.
*
* @param obj the receiver in use
* @return a string representation of the receiver suitable for app ops use
* @hide
*/
// TODO: this should probably be @SystemApi as well
public static @NonNull String toReceiverId(@Nullable Object obj) {
if (obj == null) {
return "null";
} else if (obj instanceof PendingIntent) {
return toReceiverId((PendingIntent) obj);
} else {
return obj.getClass().getName() + "@" + System.identityHashCode(obj);
}
}
/**
* Returns a listenerId suitable for use with {@link #noteOp(int, int, String, String, String)}.
*
* This is intended for use server side, where ActivityManagerService can be referenced without
* an additional x-process call.
*
* @param pendingIntent the pendingIntent in use
* @return a string representation of the pending intent suitable for app ops use
* @see #toReceiverId(Object)
* @hide
*/
// TODO: this should probably be @SystemApi as well
public static @NonNull String toReceiverId(@NonNull PendingIntent pendingIntent) {
return pendingIntent.getTag("");
}
/**
* When to not enforce {@link #setUserRestriction restrictions}.
*
* @hide
*/
public static class RestrictionBypass {
/** Does the app need to be system uid to bypass the restriction */
public boolean isSystemUid;
/** Does the app need to be privileged to bypass the restriction */
public boolean isPrivileged;
/**
* Does the app need to have the EXEMPT_FROM_AUDIO_RESTRICTIONS permission to bypass the
* restriction
*/
public boolean isRecordAudioRestrictionExcept;
public RestrictionBypass(boolean isSystemUid, boolean isPrivileged,
boolean isRecordAudioRestrictionExcept) {
this.isSystemUid = isSystemUid;
this.isPrivileged = isPrivileged;
this.isRecordAudioRestrictionExcept = isRecordAudioRestrictionExcept;
}
public static RestrictionBypass UNRESTRICTED = new RestrictionBypass(false, true, true);
}
/**
* Class holding all of the operation information associated with an app.
* @hide
*/
@SystemApi
public static final class PackageOps implements Parcelable {
private final String mPackageName;
private final int mUid;
private final List<OpEntry> mEntries;
/**
* @hide
*/
@UnsupportedAppUsage
public PackageOps(String packageName, int uid, List<OpEntry> entries) {
mPackageName = packageName;
mUid = uid;
mEntries = entries;
}
/**
* @return The name of the package.
*/
public @NonNull String getPackageName() {
return mPackageName;
}
/**
* @return The uid of the package.
*/
public int getUid() {
return mUid;
}
/**
* @return The ops of the package.
*/
public @NonNull List<OpEntry> getOps() {
return mEntries;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(mPackageName);
dest.writeInt(mUid);
dest.writeInt(mEntries.size());
for (int i=0; i<mEntries.size(); i++) {
mEntries.get(i).writeToParcel(dest, flags);
}
}
PackageOps(Parcel source) {
mPackageName = source.readString();
mUid = source.readInt();
mEntries = new ArrayList<OpEntry>();
final int N = source.readInt();
for (int i=0; i<N; i++) {
mEntries.add(OpEntry.CREATOR.createFromParcel(source));
}
}
public static final @android.annotation.NonNull Creator<PackageOps> CREATOR = new Creator<PackageOps>() {
@Override public PackageOps createFromParcel(Parcel source) {
return new PackageOps(source);
}
@Override public PackageOps[] newArray(int size) {
return new PackageOps[size];
}
};
}
/**
* Proxy information for a {@link #noteOp} event
*
* @hide
*/
@SystemApi
// @DataClass(genHiddenConstructor = true, genHiddenCopyConstructor = true)
// genHiddenCopyConstructor does not work for @hide @SystemApi classes
public static final class OpEventProxyInfo implements Parcelable {
/** UID of the proxy app that noted the op */
private @IntRange(from = 0) int mUid;
/** Package of the proxy that noted the op */
private @Nullable String mPackageName;
/** Attribution tag of the proxy that noted the op */
private @Nullable String mAttributionTag;
/**
* Reinit existing object with new state.
*
* @param uid UID of the proxy app that noted the op
* @param packageName Package of the proxy that noted the op
* @param attributionTag attribution tag of the proxy that noted the op
*
* @hide
*/
public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName,
@Nullable String attributionTag) {
mUid = Preconditions.checkArgumentNonnegative(uid);
mPackageName = packageName;
mAttributionTag = attributionTag;
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new OpEventProxyInfo.
*
* @param uid
* UID of the proxy app that noted the op
* @param packageName
* Package of the proxy that noted the op
* @param attributionTag
* Attribution tag of the proxy that noted the op
* @hide
*/
@DataClass.Generated.Member
public OpEventProxyInfo(
@IntRange(from = 0) int uid,
@Nullable String packageName,
@Nullable String attributionTag) {
this.mUid = uid;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mUid,
"from", 0);
this.mPackageName = packageName;
this.mAttributionTag = attributionTag;
// onConstructed(); // You can define this method to get a callback
}
/**
* Copy constructor
*
* @hide
*/
@DataClass.Generated.Member
public OpEventProxyInfo(@NonNull OpEventProxyInfo orig) {
mUid = orig.mUid;
mPackageName = orig.mPackageName;
mAttributionTag = orig.mAttributionTag;
}
/**
* UID of the proxy app that noted the op
*/
@DataClass.Generated.Member
public @IntRange(from = 0) int getUid() {
return mUid;
}
/**
* Package of the proxy that noted the op
*/
@DataClass.Generated.Member
public @Nullable String getPackageName() {
return mPackageName;
}
/**
* Attribution tag of the proxy that noted the op
*/
@DataClass.Generated.Member
public @Nullable String getAttributionTag() {
return mAttributionTag;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mPackageName != null) flg |= 0x2;
if (mAttributionTag != null) flg |= 0x4;
dest.writeByte(flg);
dest.writeInt(mUid);
if (mPackageName != null) dest.writeString(mPackageName);
if (mAttributionTag != null) dest.writeString(mAttributionTag);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ OpEventProxyInfo(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
int uid = in.readInt();
String packageName = (flg & 0x2) == 0 ? null : in.readString();
String attributionTag = (flg & 0x4) == 0 ? null : in.readString();
this.mUid = uid;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mUid,
"from", 0);
this.mPackageName = packageName;
this.mAttributionTag = attributionTag;
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator<OpEventProxyInfo> CREATOR
= new Parcelable.Creator<OpEventProxyInfo>() {
@Override
public OpEventProxyInfo[] newArray(int size) {
return new OpEventProxyInfo[size];
}
@Override
public OpEventProxyInfo createFromParcel(@NonNull Parcel in) {
return new OpEventProxyInfo(in);
}
};
/*
@DataClass.Generated(
time = 1576814974615L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private @android.annotation.IntRange(from=0L) int mUid\nprivate @android.annotation.Nullable java.lang.String mPackageName\nprivate @android.annotation.Nullable java.lang.String mAttributionTag\npublic void reinit(int,java.lang.String,java.lang.String)\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genHiddenCopyConstructor=true)")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/**
* Description of a {@link #noteOp} or {@link #startOp} event
*
* @hide
*/
//@DataClass codegen verifier is broken
public static final class NoteOpEvent implements Parcelable {
/** Time of noteOp event */
private @IntRange(from = 0) long mNoteTime;
/** The duration of this event (in case this is a startOp event, -1 otherwise). */
private @IntRange(from = -1) long mDuration;
/** Proxy information of the noteOp event */
private @Nullable OpEventProxyInfo mProxy;
/**
* Reinit existing object with new state.
*
* @param noteTime Time of noteOp event
* @param duration The duration of this event (in case this is a startOp event,
* -1 otherwise).
* @param proxy Proxy information of the noteOp event
* @param proxyPool The pool to release previous {@link OpEventProxyInfo} to
*/
public void reinit(@IntRange(from = 0) long noteTime,
@IntRange(from = -1) long duration,
@Nullable OpEventProxyInfo proxy,
@NonNull Pools.Pool<OpEventProxyInfo> proxyPool) {
mNoteTime = Preconditions.checkArgumentNonnegative(noteTime);
mDuration = Preconditions.checkArgumentInRange(duration, -1L, Long.MAX_VALUE,
"duration");
if (mProxy != null) {
proxyPool.release(mProxy);
}
mProxy = proxy;
}
/**
* Copy constructor
*
* @hide
*/
public NoteOpEvent(@NonNull NoteOpEvent original) {
this(original.mNoteTime, original.mDuration,
original.mProxy != null ? new OpEventProxyInfo(original.mProxy) : null);
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new NoteOpEvent.
*
* @param noteTime
* Time of noteOp event
* @param duration
* The duration of this event (in case this is a startOp event, -1 otherwise).
* @param proxy
* Proxy information of the noteOp event
*/
@DataClass.Generated.Member
public NoteOpEvent(
@IntRange(from = 0) long noteTime,
@IntRange(from = -1) long duration,
@Nullable OpEventProxyInfo proxy) {
this.mNoteTime = noteTime;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mNoteTime,
"from", 0);
this.mDuration = duration;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mDuration,
"from", -1);
this.mProxy = proxy;
// onConstructed(); // You can define this method to get a callback
}
/**
* Time of noteOp event
*/
@DataClass.Generated.Member
public @IntRange(from = 0) long getNoteTime() {
return mNoteTime;
}
/**
* The duration of this event (in case this is a startOp event, -1 otherwise).
*/
@DataClass.Generated.Member
public @IntRange(from = -1) long getDuration() {
return mDuration;
}
/**
* Proxy information of the noteOp event
*/
@DataClass.Generated.Member
public @Nullable OpEventProxyInfo getProxy() {
return mProxy;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mProxy != null) flg |= 0x4;
dest.writeByte(flg);
dest.writeLong(mNoteTime);
dest.writeLong(mDuration);
if (mProxy != null) dest.writeTypedObject(mProxy, flags);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ NoteOpEvent(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
long noteTime = in.readLong();
long duration = in.readLong();
OpEventProxyInfo proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject(OpEventProxyInfo.CREATOR);
this.mNoteTime = noteTime;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mNoteTime,
"from", 0);
this.mDuration = duration;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mDuration,
"from", -1);
this.mProxy = proxy;
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator<NoteOpEvent> CREATOR
= new Parcelable.Creator<NoteOpEvent>() {
@Override
public NoteOpEvent[] newArray(int size) {
return new NoteOpEvent[size];
}
@Override
public NoteOpEvent createFromParcel(@NonNull Parcel in) {
return new NoteOpEvent(in);
}
};
/*
@DataClass.Generated(
time = 1576811792274L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private @android.annotation.IntRange(from=0L) long mNoteTime\nprivate @android.annotation.IntRange(from=-1) long mDuration\nprivate @android.annotation.Nullable android.app.OpEventProxyInfo mProxy\npublic void reinit(long,long,android.app.OpEventProxyInfo,android.util.Pools.Pool<android.app.OpEventProxyInfo>)\npublic @java.lang.Override java.lang.Object clone()\nclass NoteOpEvent extends java.lang.Object implements [android.os.Parcelable, java.lang.Cloneable]\n@com.android.internal.util.DataClass")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/**
* Last {@link #noteOp} and {@link #startOp} events performed for a single op and a specific
* {@link Context#createAttributionContext(String) attribution} for all uidModes and opFlags.
*
* @hide
*/
@SystemApi
@Immutable
// @DataClass(genHiddenConstructor = true) codegen verifier is broken
@DataClass.Suppress({"getAccessEvents", "getRejectEvents", "getOp"})
public static final class AttributedOpEntry implements Parcelable {
/** The code of the op */
private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp;
/** Whether the op is running */
private final boolean mRunning;
/** The access events */
@DataClass.ParcelWith(LongSparseArrayParceling.class)
private final @Nullable LongSparseArray<NoteOpEvent> mAccessEvents;
/** The rejection events */
@DataClass.ParcelWith(LongSparseArrayParceling.class)
private final @Nullable LongSparseArray<NoteOpEvent> mRejectEvents;
private AttributedOpEntry(@NonNull AttributedOpEntry other) {
mOp = other.mOp;
mRunning = other.mRunning;
mAccessEvents = other.mAccessEvents == null ? null : other.mAccessEvents.clone();
mRejectEvents = other.mRejectEvents == null ? null : other.mRejectEvents.clone();
}
/**
* Returns all keys for which we have events.
*
* @hide
*/
public @NonNull ArraySet<Long> collectKeys() {
ArraySet<Long> keys = new ArraySet<>();
if (mAccessEvents != null) {
int numEvents = mAccessEvents.size();
for (int i = 0; i < numEvents; i++) {
keys.add(mAccessEvents.keyAt(i));
}
}
if (mRejectEvents != null) {
int numEvents = mRejectEvents.size();
for (int i = 0; i < numEvents; i++) {
keys.add(mRejectEvents.keyAt(i));
}
}
return keys;
}
/**
* Return the last access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access
*
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see OpEntry#getLastAccessTime(int)
*/
public long getLastAccessTime(@OpFlags int flags) {
return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the last foreground access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see OpEntry#getLastAccessForegroundTime(int)
*/
public long getLastAccessForegroundTime(@OpFlags int flags) {
return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the last background access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see OpEntry#getLastAccessBackgroundTime(int)
*/
public long getLastAccessBackgroundTime(@OpFlags int flags) {
return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the last access event.
*
* @param flags The op flags
*
* @return the last access event of {@code null} if there was no access
*/
private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
return getLastEvent(mAccessEvents, fromUidState, toUidState, flags);
}
/**
* Return the last access time.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see OpEntry#getLastAccessTime(int, int, int)
*/
public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return -1;
}
return lastEvent.getNoteTime();
}
/**
* Return the last rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection
*
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see OpEntry#getLastRejectTime(int)
*/
public long getLastRejectTime(@OpFlags int flags) {
return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the last foreground rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see OpEntry#getLastRejectForegroundTime(int)
*/
public long getLastRejectForegroundTime(@OpFlags int flags) {
return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the last background rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see OpEntry#getLastRejectBackgroundTime(int)
*/
public long getLastRejectBackgroundTime(@OpFlags int flags) {
return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the last background rejection event.
*
* @param flags The op flags
*
* @return the last rejection event of {@code null} if there was no rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see OpEntry#getLastRejectTime(int, int, int)
*/
private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
return getLastEvent(mRejectEvents, fromUidState, toUidState, flags);
}
/**
* Return the last rejection time.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch) or {@code -1} if there was no
* rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see OpEntry#getLastRejectTime(int, int, int)
*/
public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return -1;
}
return lastEvent.getNoteTime();
}
/**
* Return the duration in milliseconds of the last the access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no rejection
*
* @see #getLastForegroundDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see OpEntry#getLastDuration(int)
*/
public long getLastDuration(@OpFlags int flags) {
return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the duration in milliseconds of the last foreground access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no foreground rejection
*
* @see #getLastDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see OpEntry#getLastForegroundDuration(int)
*/
public long getLastForegroundDuration(@OpFlags int flags) {
return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the duration in milliseconds of the last background access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no background rejection
*
* @see #getLastDuration(int)
* @see #getLastForegroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see OpEntry#getLastBackgroundDuration(int)
*/
public long getLastBackgroundDuration(@OpFlags int flags) {
return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the duration in milliseconds of the last access.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no rejection
*
* @see #getLastDuration(int)
* @see #getLastForegroundDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see OpEntry#getLastDuration(int, int, int)
*/
public long getLastDuration(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);;
if (lastEvent == null) {
return -1;
}
return lastEvent.getDuration();
}
/**
* Gets the proxy info of the app that performed the last access on behalf of this
* attribution and as a result blamed the op on this attribution.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy access
*
* @see #getLastForegroundProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see OpEntry#getLastProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the proxy info of the app that performed the last foreground access on behalf of
* this attribution and as a result blamed the op on this attribution.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy access
*
* @see #getLastProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see OpEntry#getLastForegroundProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Gets the proxy info of the app that performed the last background access on behalf of
* this attribution and as a result blamed the op on this attribution.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy background access
*
* @see #getLastProxyInfo(int)
* @see #getLastForegroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see OpEntry#getLastBackgroundProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Gets the proxy info of the app that performed the last access on behalf of this
* attribution and as a result blamed the op on this attribution.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy foreground access
*
* @see #getLastProxyInfo(int)
* @see #getLastForegroundProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see OpEntry#getLastProxyInfo(int, int, int)
*/
public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return null;
}
return lastEvent.getProxy();
}
@NonNull
String getOpName() {
return AppOpsManager.opToPublicName(mOp);
}
int getOp() {
return mOp;
}
private static class LongSparseArrayParceling implements
Parcelling<LongSparseArray<NoteOpEvent>> {
@Override
public void parcel(@Nullable LongSparseArray<NoteOpEvent> array, @NonNull Parcel dest,
int parcelFlags) {
if (array == null) {
dest.writeInt(-1);
return;
}
int numEntries = array.size();
dest.writeInt(numEntries);
for (int i = 0; i < numEntries; i++) {
dest.writeLong(array.keyAt(i));
dest.writeParcelable(array.valueAt(i), parcelFlags);
}
}
@Override
public @Nullable LongSparseArray<NoteOpEvent> unparcel(@NonNull Parcel source) {
int numEntries = source.readInt();
if (numEntries == -1) {
return null;
}
LongSparseArray<NoteOpEvent> array = new LongSparseArray<>(numEntries);
for (int i = 0; i < numEntries; i++) {
array.put(source.readLong(), source.readParcelable(null, android.app.AppOpsManager.NoteOpEvent.class));
}
return array;
}
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new OpAttributionEntry.
*
* @param op
* The code of the op
* @param running
* Whether the op is running
* @param accessEvents
* The access events
* @param rejectEvents
* The rejection events
* @hide
*/
@DataClass.Generated.Member
public AttributedOpEntry(
@IntRange(from = 0, to = _NUM_OP - 1) int op,
boolean running,
@Nullable LongSparseArray<NoteOpEvent> accessEvents,
@Nullable LongSparseArray<NoteOpEvent> rejectEvents) {
this.mOp = op;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOp,
"from", 0,
"to", _NUM_OP - 1);
this.mRunning = running;
this.mAccessEvents = accessEvents;
this.mRejectEvents = rejectEvents;
// onConstructed(); // You can define this method to get a callback
}
/**
* Whether the op is running
*/
@DataClass.Generated.Member
public boolean isRunning() {
return mRunning;
}
@DataClass.Generated.Member
static Parcelling<LongSparseArray<NoteOpEvent>> sParcellingForAccessEvents =
Parcelling.Cache.get(
LongSparseArrayParceling.class);
static {
if (sParcellingForAccessEvents == null) {
sParcellingForAccessEvents = Parcelling.Cache.put(
new LongSparseArrayParceling());
}
}
@DataClass.Generated.Member
static Parcelling<LongSparseArray<NoteOpEvent>> sParcellingForRejectEvents =
Parcelling.Cache.get(
LongSparseArrayParceling.class);
static {
if (sParcellingForRejectEvents == null) {
sParcellingForRejectEvents = Parcelling.Cache.put(
new LongSparseArrayParceling());
}
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mRunning) flg |= 0x2;
if (mAccessEvents != null) flg |= 0x4;
if (mRejectEvents != null) flg |= 0x8;
dest.writeByte(flg);
dest.writeInt(mOp);
sParcellingForAccessEvents.parcel(mAccessEvents, dest, flags);
sParcellingForRejectEvents.parcel(mRejectEvents, dest, flags);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ AttributedOpEntry(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
boolean running = (flg & 0x2) != 0;
int op = in.readInt();
LongSparseArray<NoteOpEvent> accessEvents = sParcellingForAccessEvents.unparcel(in);
LongSparseArray<NoteOpEvent> rejectEvents = sParcellingForRejectEvents.unparcel(in);
this.mOp = op;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOp,
"from", 0,
"to", _NUM_OP - 1);
this.mRunning = running;
this.mAccessEvents = accessEvents;
this.mRejectEvents = rejectEvents;
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator<AttributedOpEntry> CREATOR
= new Parcelable.Creator<AttributedOpEntry>() {
@Override
public AttributedOpEntry[] newArray(int size) {
return new AttributedOpEntry[size];
}
@Override
public AttributedOpEntry createFromParcel(@NonNull Parcel in) {
return new AttributedOpEntry(in);
}
};
/*
@DataClass.Generated(
time = 1574809856239L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final boolean mRunning\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpAttributionEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray<android.app.NoteOpEvent> mAccessEvents\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpAttributionEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray<android.app.NoteOpEvent> mRejectEvents\npublic @android.annotation.NonNull android.util.ArraySet<java.lang.Long> collectKeys()\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic long getAccessTime(int,int)\npublic long getRejectTime(int,int)\npublic long getDuration(int,int)\npublic int getProxyUid(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyAttributionTag(int,int)\nclass OpAttributionEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/**
* Last {@link #noteOp} and {@link #startOp} events performed for a single op for all uidModes
* and opFlags.
*
* @hide
*/
@Immutable
@SystemApi
// @DataClass(genHiddenConstructor = true) codegen verifier is broken
public static final class OpEntry implements Parcelable {
/** The code of the op */
private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp;
/** The mode of the op */
private final @Mode int mMode;
/** The attributed entries by attribution tag */
private final @NonNull Map<String, AttributedOpEntry> mAttributedOpEntries;
/**
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code "
+ "#getOpStr()}")
public int getOp() {
return mOp;
}
/**
* @return This entry's op string name, such as {@link #OPSTR_COARSE_LOCATION}.
*/
public @NonNull String getOpStr() {
return sOpToString[mOp];
}
/**
* @hide
*
* @deprecated Use {@link #getLastAccessTime(int)} instead
*/
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code "
+ "#getLastAccessTime(int)}")
public long getTime() {
return getLastAccessTime(OP_FLAGS_ALL);
}
/**
* Return the last access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access
*
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see AttributedOpEntry#getLastAccessTime(int)
*/
public long getLastAccessTime(@OpFlags int flags) {
return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the last foreground access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see AttributedOpEntry#getLastAccessForegroundTime(int)
*/
public long getLastAccessForegroundTime(@OpFlags int flags) {
return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the last background access time.
*
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessTime(int, int, int)
* @see AttributedOpEntry#getLastAccessBackgroundTime(int)
*/
public long getLastAccessBackgroundTime(@OpFlags int flags) {
return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the last access event.
*
* @param flags The op flags
*
* @return the last access event of {@code null} if there was no access
*/
private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
NoteOpEvent lastAccessEvent = null;
for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) {
NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastAccessEvent(
fromUidState, toUidState, flags);
if (lastAccessEvent == null || (lastAttributionAccessEvent != null
&& lastAttributionAccessEvent.getNoteTime()
> lastAccessEvent.getNoteTime())) {
lastAccessEvent = lastAttributionAccessEvent;
}
}
return lastAccessEvent;
}
/**
* Return the last access time.
*
* @param fromUidState the lowest uid state to query
* @param toUidState the highest uid state to query (inclusive)
* @param flags The op flags
*
* @return the last access time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no access
*
* @see #getLastAccessTime(int)
* @see #getLastAccessForegroundTime(int)
* @see #getLastAccessBackgroundTime(int)
* @see AttributedOpEntry#getLastAccessTime(int, int, int)
*/
public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);;
if (lastEvent == null) {
return -1;
}
return lastEvent.getNoteTime();
}
/**
* @hide
*
* @deprecated Use {@link #getLastRejectTime(int)} instead
*/
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, publicAlternatives = "{@code "
+ "#getLastRejectTime(int)}")
public long getRejectTime() {
return getLastRejectTime(OP_FLAGS_ALL);
}
/**
* Return the last rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection
*
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see AttributedOpEntry#getLastRejectTime(int)
*/
public long getLastRejectTime(@OpFlags int flags) {
return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the last foreground rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no foreground rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see AttributedOpEntry#getLastRejectForegroundTime(int)
*/
public long getLastRejectForegroundTime(@OpFlags int flags) {
return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the last background rejection time.
*
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no background rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see AttributedOpEntry#getLastRejectBackgroundTime(int)
*/
public long getLastRejectBackgroundTime(@OpFlags int flags) {
return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the last rejection event.
*
* @param flags The op flags
*
* @return the last reject event of {@code null} if there was no rejection
*/
private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
NoteOpEvent lastAccessEvent = null;
for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) {
NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastRejectEvent(
fromUidState, toUidState, flags);
if (lastAccessEvent == null || (lastAttributionAccessEvent != null
&& lastAttributionAccessEvent.getNoteTime()
> lastAccessEvent.getNoteTime())) {
lastAccessEvent = lastAttributionAccessEvent;
}
}
return lastAccessEvent;
}
/**
* Return the last rejection time.
*
* @param fromUidState the lowest uid state to query
* @param toUidState the highest uid state to query (inclusive)
* @param flags The op flags
*
* @return the last rejection time (in milliseconds since epoch start (January 1, 1970
* 00:00:00.000 GMT - Gregorian)) or {@code -1} if there was no rejection
*
* @see #getLastRejectTime(int)
* @see #getLastRejectForegroundTime(int)
* @see #getLastRejectBackgroundTime(int)
* @see #getLastRejectTime(int, int, int)
* @see AttributedOpEntry#getLastRejectTime(int, int, int)
*/
public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastRejectEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return -1;
}
return lastEvent.getNoteTime();
}
/**
* @return Whether the operation is running.
*/
public boolean isRunning() {
for (AttributedOpEntry opAttributionEntry : mAttributedOpEntries.values()) {
if (opAttributionEntry.isRunning()) {
return true;
}
}
return false;
}
/**
* @deprecated Use {@link #getLastDuration(int)} instead
*/
@Deprecated
public long getDuration() {
return getLastDuration(OP_FLAGS_ALL);
}
/**
* Return the duration in milliseconds of the last the access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no access
*
* @see #getLastForegroundDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see AttributedOpEntry#getLastDuration(int)
*/
public long getLastDuration(@OpFlags int flags) {
return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Return the duration in milliseconds of the last foreground access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no foreground access
*
* @see #getLastDuration(int)
* @see #getLastBackgroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see AttributedOpEntry#getLastForegroundDuration(int)
*/
public long getLastForegroundDuration(@OpFlags int flags) {
return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Return the duration in milliseconds of the last background access.
*
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no background access
*
* @see #getLastDuration(int)
* @see #getLastForegroundDuration(int)
* @see #getLastDuration(int, int, int)
* @see AttributedOpEntry#getLastBackgroundDuration(int)
*/
public long getLastBackgroundDuration(@OpFlags int flags) {
return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Return the duration in milliseconds of the last access.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return the duration in milliseconds or {@code -1} if there was no access
*
* @see #getLastDuration(int)
* @see #getLastForegroundDuration(int)
* @see #getLastBackgroundDuration(int)
* @see AttributedOpEntry#getLastDuration(int, int, int)
*/
public long getLastDuration(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return -1;
}
return lastEvent.getDuration();
}
/**
* @deprecated Use {@link #getLastProxyInfo(int)} instead
*/
@Deprecated
public int getProxyUid() {
OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL);
if (proxy == null) {
return Process.INVALID_UID;
}
return proxy.getUid();
}
/**
* @deprecated Use {@link #getLastProxyInfo(int)} instead
*/
@Deprecated
public int getProxyUid(@UidState int uidState, @OpFlags int flags) {
OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags);
if (proxy == null) {
return Process.INVALID_UID;
}
return proxy.getUid();
}
/**
* @deprecated Use {@link #getLastProxyInfo(int)} instead
*/
@Deprecated
public @Nullable String getProxyPackageName() {
OpEventProxyInfo proxy = getLastProxyInfo(OP_FLAGS_ALL);
if (proxy == null) {
return null;
}
return proxy.getPackageName();
}
/**
* @deprecated Use {@link #getLastProxyInfo(int)} instead
*/
@Deprecated
public @Nullable String getProxyPackageName(@UidState int uidState, @OpFlags int flags) {
OpEventProxyInfo proxy = getLastProxyInfo(uidState, uidState, flags);
if (proxy == null) {
return null;
}
return proxy.getPackageName();
}
/**
* Gets the proxy info of the app that performed the last access on behalf of this app and
* as a result blamed the op on this app.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy access
*
* @see #getLastForegroundProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see AttributedOpEntry#getLastProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the proxy info of the app that performed the last foreground access on behalf of
* this app and as a result blamed the op on this app.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no foreground proxy access
*
* @see #getLastProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see AttributedOpEntry#getLastForegroundProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
flags);
}
/**
* Gets the proxy info of the app that performed the last background access on behalf of
* this app and as a result blamed the op on this app.
*
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no background proxy access
*
* @see #getLastProxyInfo(int)
* @see #getLastForegroundProxyInfo(int)
* @see #getLastProxyInfo(int, int, int)
* @see AttributedOpEntry#getLastBackgroundProxyInfo(int)
*/
public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) {
return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
flags);
}
/**
* Gets the proxy info of the app that performed the last access on behalf of this app and
* as a result blamed the op on this app.
*
* @param fromUidState The lowest UID state for which to query
* @param toUidState The highest UID state for which to query (inclusive)
* @param flags The op flags
*
* @return The proxy info or {@code null} if there was no proxy access
*
* @see #getLastProxyInfo(int)
* @see #getLastForegroundProxyInfo(int)
* @see #getLastBackgroundProxyInfo(int)
* @see AttributedOpEntry#getLastProxyInfo(int, int, int)
*/
public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
NoteOpEvent lastEvent = getLastAccessEvent(fromUidState, toUidState, flags);
if (lastEvent == null) {
return null;
}
return lastEvent.getProxy();
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new OpEntry.
*
* @param op
* The code of the op
* @param mode
* The mode of the op
* @param attributedOpEntries
* The attributions that have been used when noting the op
* @hide
*/
@DataClass.Generated.Member
public OpEntry(
@IntRange(from = 0, to = _NUM_OP - 1) int op,
@Mode int mode,
@NonNull Map<String, AttributedOpEntry> attributedOpEntries) {
this.mOp = op;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOp,
"from", 0,
"to", _NUM_OP - 1);
this.mMode = mode;
com.android.internal.util.AnnotationValidations.validate(
Mode.class, null, mMode);
this.mAttributedOpEntries = attributedOpEntries;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mAttributedOpEntries);
// onConstructed(); // You can define this method to get a callback
}
/**
* The mode of the op
*/
@DataClass.Generated.Member
public @Mode int getMode() {
return mMode;
}
/**
* The attributed entries keyed by attribution tag.
*
* @see Context#createAttributionContext(String)
* @see #noteOp(String, int, String, String, String)
*/
@DataClass.Generated.Member
public @NonNull Map<String, AttributedOpEntry> getAttributedOpEntries() {
return mAttributedOpEntries;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
dest.writeInt(mOp);
dest.writeInt(mMode);
dest.writeMap(mAttributedOpEntries);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ OpEntry(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
int op = in.readInt();
int mode = in.readInt();
Map<String, AttributedOpEntry> attributions = new java.util.LinkedHashMap<>();
in.readMap(attributions, AttributedOpEntry.class.getClassLoader());
this.mOp = op;
com.android.internal.util.AnnotationValidations.validate(
IntRange.class, null, mOp,
"from", 0,
"to", _NUM_OP - 1);
this.mMode = mode;
com.android.internal.util.AnnotationValidations.validate(
Mode.class, null, mMode);
this.mAttributedOpEntries = attributions;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mAttributedOpEntries);
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator<OpEntry> CREATOR
= new Parcelable.Creator<OpEntry>() {
@Override
public OpEntry[] newArray(int size) {
return new OpEntry[size];
}
@Override
public OpEntry createFromParcel(@NonNull Parcel in) {
return new OpEntry(in);
}
};
/*
@DataClass.Generated(
time = 1574809856259L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final @android.app.Mode int mMode\nprivate final @android.annotation.NonNull java.util.Map<java.lang.String,android.app.OpAttributionEntry> mAttributions\npublic @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getOpStr()}\") int getOp()\npublic @android.annotation.NonNull java.lang.String getOpStr()\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getAccessTime(int, int)}\") long getTime()\npublic @java.lang.Deprecated long getLastAccessTime(int)\npublic @java.lang.Deprecated long getLastAccessForegroundTime(int)\npublic @java.lang.Deprecated long getLastAccessBackgroundTime(int)\npublic @java.lang.Deprecated long getLastAccessTime(int,int,int)\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getLastRejectTime(int, int, int)}\") long getRejectTime()\npublic @java.lang.Deprecated long getLastRejectTime(int)\npublic @java.lang.Deprecated long getLastRejectForegroundTime(int)\npublic @java.lang.Deprecated long getLastRejectBackgroundTime(int)\npublic @java.lang.Deprecated long getLastRejectTime(int,int,int)\npublic long getAccessTime(int,int)\npublic long getRejectTime(int,int)\npublic boolean isRunning()\nprivate android.app.NoteOpEvent getLastAccessEvent(int,int,int)\npublic @java.lang.Deprecated long getDuration()\npublic @java.lang.Deprecated long getLastForegroundDuration(int)\npublic @java.lang.Deprecated long getLastBackgroundDuration(int)\npublic @java.lang.Deprecated long getLastDuration(int,int,int)\npublic @java.lang.Deprecated int getProxyUid()\npublic @java.lang.Deprecated @android.annotation.Nullable java.lang.String getProxyPackageName()\nprivate @android.app.UidState int getLastAccessUidStateForFlagsInStatesOfAllAttributions(int,int,int)\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\nprivate @android.app.UidState int getLastRejectUidStateForFlagsInStatesOfAllAttributions(int,int,int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic long getDuration(int,int)\npublic int getProxyUid(int,int)\nprivate int getProxyUid(int,int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\nprivate @android.annotation.Nullable java.lang.String getProxyPackageName(int,int,int)\nclass OpEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/** @hide */
public interface HistoricalOpsVisitor {
void visitHistoricalOps(@NonNull HistoricalOps ops);
void visitHistoricalUidOps(@NonNull HistoricalUidOps ops);
void visitHistoricalPackageOps(@NonNull HistoricalPackageOps ops);
void visitHistoricalAttributionOps(@NonNull AttributedHistoricalOps ops);
void visitHistoricalOp(@NonNull HistoricalOp ops);
}
/**
* Flag for querying app op history: get only aggregate information (counts of events) and no
* discret accesses information - specific accesses with timestamp.
*
* @see #getHistoricalOps(HistoricalOpsRequest, Executor, Consumer)
*
* @hide
*/
@TestApi
@SystemApi
public static final int HISTORY_FLAG_AGGREGATE = 1 << 0;
/**
* Flag for querying app op history: get only discrete access information (only specific
* accesses with timestamps) and no aggregate information (counts over time).
*
* @see #getHistoricalOps(HistoricalOpsRequest, Executor, Consumer)
*
* @hide
*/
@TestApi
@SystemApi
public static final int HISTORY_FLAG_DISCRETE = 1 << 1;
/**
* Flag for querying app op history: assemble attribution chains, and attach the last visible
* node in the chain to the start as a proxy info. This only applies to discrete accesses.
*
* TODO 191512294: Add to @SystemApi
*
* @hide
*/
public static final int HISTORY_FLAG_GET_ATTRIBUTION_CHAINS = 1 << 2;
/**
* Flag for querying app op history: get all types of historical access information.
*
* @see #getHistoricalOps(HistoricalOpsRequest, Executor, Consumer)
*
* @hide
*/
@TestApi
@SystemApi
public static final int HISTORY_FLAGS_ALL = HISTORY_FLAG_AGGREGATE
| HISTORY_FLAG_DISCRETE;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "HISTORY_FLAG_" }, value = {
HISTORY_FLAG_AGGREGATE,
HISTORY_FLAG_DISCRETE,
HISTORY_FLAG_GET_ATTRIBUTION_CHAINS
})
public @interface OpHistoryFlags {}
/**
* Specifies what parameters to filter historical appop requests for
*
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "FILTER_BY_" }, value = {
FILTER_BY_UID,
FILTER_BY_PACKAGE_NAME,
FILTER_BY_ATTRIBUTION_TAG,
FILTER_BY_OP_NAMES
})
public @interface HistoricalOpsRequestFilter {}
/**
* Filter historical appop request by uid.
*
* @hide
*/
public static final int FILTER_BY_UID = 1<<0;
/**
* Filter historical appop request by package name.
*
* @hide
*/
public static final int FILTER_BY_PACKAGE_NAME = 1<<1;
/**
* Filter historical appop request by attribution tag.
*
* @hide
*/
public static final int FILTER_BY_ATTRIBUTION_TAG = 1<<2;
/**
* Filter historical appop request by op names.
*
* @hide
*/
public static final int FILTER_BY_OP_NAMES = 1<<3;
/**
* Request for getting historical app op usage. The request acts
* as a filtering criteria when querying historical op usage.
*
* @hide
*/
@Immutable
@SystemApi
public static final class HistoricalOpsRequest {
private final int mUid;
private final @Nullable String mPackageName;
private final @Nullable String mAttributionTag;
private final @Nullable List<String> mOpNames;
private final @OpHistoryFlags int mHistoryFlags;
private final @HistoricalOpsRequestFilter int mFilter;
private final long mBeginTimeMillis;
private final long mEndTimeMillis;
private final @OpFlags int mFlags;
private HistoricalOpsRequest(int uid, @Nullable String packageName,
@Nullable String attributionTag, @Nullable List<String> opNames,
@OpHistoryFlags int historyFlags, @HistoricalOpsRequestFilter int filter,
long beginTimeMillis, long endTimeMillis, @OpFlags int flags) {
mUid = uid;
mPackageName = packageName;
mAttributionTag = attributionTag;
mOpNames = opNames;
mHistoryFlags = historyFlags;
mFilter = filter;
mBeginTimeMillis = beginTimeMillis;
mEndTimeMillis = endTimeMillis;
mFlags = flags;
}
/**
* Builder for creating a {@link HistoricalOpsRequest}.
*
* @hide
*/
@SystemApi
public static final class Builder {
private int mUid = Process.INVALID_UID;
private @Nullable String mPackageName;
private @Nullable String mAttributionTag;
private @Nullable List<String> mOpNames;
private @OpHistoryFlags int mHistoryFlags;
private @HistoricalOpsRequestFilter int mFilter;
private final long mBeginTimeMillis;
private final long mEndTimeMillis;
private @OpFlags int mFlags = OP_FLAGS_ALL;
/**
* Creates a new builder.
*
* @param beginTimeMillis The beginning of the interval in milliseconds since
* epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be non
* negative.
* @param endTimeMillis The end of the interval in milliseconds since
* epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian). Must be after
* {@code beginTimeMillis}. Pass {@link Long#MAX_VALUE} to get the most recent
* history including ops that happen while this call is in flight.
*/
public Builder(long beginTimeMillis, long endTimeMillis) {
Preconditions.checkArgument(beginTimeMillis >= 0 && beginTimeMillis < endTimeMillis,
"beginTimeMillis must be non negative and lesser than endTimeMillis");
mBeginTimeMillis = beginTimeMillis;
mEndTimeMillis = endTimeMillis;
mHistoryFlags = HISTORY_FLAG_AGGREGATE;
}
/**
* Sets the UID to query for.
*
* @param uid The uid. Pass {@link android.os.Process#INVALID_UID} for any uid.
* @return This builder.
*/
public @NonNull Builder setUid(int uid) {
Preconditions.checkArgument(uid == Process.INVALID_UID || uid >= 0,
"uid must be " + Process.INVALID_UID + " or non negative");
mUid = uid;
if (uid == Process.INVALID_UID) {
mFilter &= ~FILTER_BY_UID;
} else {
mFilter |= FILTER_BY_UID;
}
return this;
}
/**
* Sets the package to query for.
*
* @param packageName The package name. <code>Null</code> for any package.
* @return This builder.
*/
public @NonNull Builder setPackageName(@Nullable String packageName) {
mPackageName = packageName;
if (packageName == null) {
mFilter &= ~FILTER_BY_PACKAGE_NAME;
} else {
mFilter |= FILTER_BY_PACKAGE_NAME;
}
return this;
}
/**
* Sets the attribution tag to query for.
*
* @param attributionTag attribution tag
* @return This builder.
*/
public @NonNull Builder setAttributionTag(@Nullable String attributionTag) {
mAttributionTag = attributionTag;
mFilter |= FILTER_BY_ATTRIBUTION_TAG;
return this;
}
/**
* Sets the op names to query for.
*
* @param opNames The op names. <code>Null</code> for any op.
* @return This builder.
*/
public @NonNull Builder setOpNames(@Nullable List<String> opNames) {
if (opNames != null) {
final int opCount = opNames.size();
for (int i = 0; i < opCount; i++) {
Preconditions.checkArgument(AppOpsManager.strOpToOp(
opNames.get(i)) != AppOpsManager.OP_NONE);
}
}
mOpNames = opNames;
if (mOpNames == null) {
mFilter &= ~FILTER_BY_OP_NAMES;
} else {
mFilter |= FILTER_BY_OP_NAMES;
}
return this;
}
/**
* Sets the op flags to query for. The flags specify the type of
* op data being queried.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return This builder.
*/
public @NonNull Builder setFlags(@OpFlags int flags) {
Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL);
mFlags = flags;
return this;
}
/**
* Specifies what type of historical information to query.
*
* @param flags Flags for the historical types to fetch which are any
* combination of {@link #HISTORY_FLAG_AGGREGATE}, {@link #HISTORY_FLAG_DISCRETE},
* {@link #HISTORY_FLAGS_ALL}. The default is {@link #HISTORY_FLAG_AGGREGATE}.
* @return This builder.
*/
public @NonNull Builder setHistoryFlags(@OpHistoryFlags int flags) {
Preconditions.checkFlagsArgument(flags,
HISTORY_FLAGS_ALL | HISTORY_FLAG_GET_ATTRIBUTION_CHAINS);
mHistoryFlags = flags;
return this;
}
/**
* @return a new {@link HistoricalOpsRequest}.
*/
public @NonNull HistoricalOpsRequest build() {
return new HistoricalOpsRequest(mUid, mPackageName, mAttributionTag, mOpNames,
mHistoryFlags, mFilter, mBeginTimeMillis, mEndTimeMillis, mFlags);
}
}
}
/**
* This class represents historical app op state of all UIDs for a given time interval.
*
* @hide
*/
@SystemApi
public static final class HistoricalOps implements Parcelable {
private long mBeginTimeMillis;
private long mEndTimeMillis;
private @Nullable SparseArray<HistoricalUidOps> mHistoricalUidOps;
/** @hide */
@TestApi
public HistoricalOps(long beginTimeMillis, long endTimeMillis) {
Preconditions.checkState(beginTimeMillis <= endTimeMillis);
mBeginTimeMillis = beginTimeMillis;
mEndTimeMillis = endTimeMillis;
}
/** @hide */
public HistoricalOps(@NonNull HistoricalOps other) {
mBeginTimeMillis = other.mBeginTimeMillis;
mEndTimeMillis = other.mEndTimeMillis;
Preconditions.checkState(mBeginTimeMillis <= mEndTimeMillis);
if (other.mHistoricalUidOps != null) {
final int opCount = other.getUidCount();
for (int i = 0; i < opCount; i++) {
final HistoricalUidOps origOps = other.getUidOpsAt(i);
final HistoricalUidOps clonedOps = new HistoricalUidOps(origOps);
if (mHistoricalUidOps == null) {
mHistoricalUidOps = new SparseArray<>(opCount);
}
mHistoricalUidOps.put(clonedOps.getUid(), clonedOps);
}
}
}
private HistoricalOps(Parcel parcel) {
mBeginTimeMillis = parcel.readLong();
mEndTimeMillis = parcel.readLong();
final int[] uids = parcel.createIntArray();
if (!ArrayUtils.isEmpty(uids)) {
final ParceledListSlice<HistoricalUidOps> listSlice = parcel.readParcelable(
HistoricalOps.class.getClassLoader(), android.content.pm.ParceledListSlice.class);
final List<HistoricalUidOps> uidOps = (listSlice != null)
? listSlice.getList() : null;
if (uidOps == null) {
return;
}
for (int i = 0; i < uids.length; i++) {
if (mHistoricalUidOps == null) {
mHistoricalUidOps = new SparseArray<>();
}
mHistoricalUidOps.put(uids[i], uidOps.get(i));
}
}
}
/**
* Splice a piece from the beginning of these ops.
*
* @param splicePoint The fraction of the data to be spliced off.
*
* @hide
*/
public @NonNull HistoricalOps spliceFromBeginning(double splicePoint) {
return splice(splicePoint, true);
}
/**
* Splice a piece from the end of these ops.
*
* @param fractionToRemove The fraction of the data to be spliced off.
*
* @hide
*/
public @NonNull HistoricalOps spliceFromEnd(double fractionToRemove) {
return splice(fractionToRemove, false);
}
/**
* Splice a piece from the beginning or end of these ops.
*
* @param fractionToRemove The fraction of the data to be spliced off.
* @param beginning Whether to splice off the beginning or the end.
*
* @return The spliced off part.
*
* @hide
*/
private @Nullable HistoricalOps splice(double fractionToRemove, boolean beginning) {
final long spliceBeginTimeMills;
final long spliceEndTimeMills;
if (beginning) {
spliceBeginTimeMills = mBeginTimeMillis;
spliceEndTimeMills = (long) (mBeginTimeMillis
+ getDurationMillis() * fractionToRemove);
mBeginTimeMillis = spliceEndTimeMills;
} else {
spliceBeginTimeMills = (long) (mEndTimeMillis
- getDurationMillis() * fractionToRemove);
spliceEndTimeMills = mEndTimeMillis;
mEndTimeMillis = spliceBeginTimeMills;
}
HistoricalOps splice = null;
final int uidCount = getUidCount();
for (int i = 0; i < uidCount; i++) {
final HistoricalUidOps origOps = getUidOpsAt(i);
final HistoricalUidOps spliceOps = origOps.splice(fractionToRemove);
if (spliceOps != null) {
if (splice == null) {
splice = new HistoricalOps(spliceBeginTimeMills, spliceEndTimeMills);
}
if (splice.mHistoricalUidOps == null) {
splice.mHistoricalUidOps = new SparseArray<>();
}
splice.mHistoricalUidOps.put(spliceOps.getUid(), spliceOps);
}
}
return splice;
}
/**
* Merge the passed ops into the current ones. The time interval is a
* union of the current and passed in one and the passed in data is
* folded into the data of this instance.
*
* @hide
*/
public void merge(@NonNull HistoricalOps other) {
mBeginTimeMillis = Math.min(mBeginTimeMillis, other.mBeginTimeMillis);
mEndTimeMillis = Math.max(mEndTimeMillis, other.mEndTimeMillis);
final int uidCount = other.getUidCount();
for (int i = 0; i < uidCount; i++) {
final HistoricalUidOps otherUidOps = other.getUidOpsAt(i);
final HistoricalUidOps thisUidOps = getUidOps(otherUidOps.getUid());
if (thisUidOps != null) {
thisUidOps.merge(otherUidOps);
} else {
if (mHistoricalUidOps == null) {
mHistoricalUidOps = new SparseArray<>();
}
mHistoricalUidOps.put(otherUidOps.getUid(), otherUidOps);
}
}
}
/**
* AppPermissionUsage the ops to leave only the data we filter for.
*
* @param uid Uid to filter for.
* @param packageName Package to filter for.
* @param attributionTag attribution tag to filter for
* @param opNames Ops to filter for.
* @param filter Which parameters to filter on.
* @param beginTimeMillis The begin time to filter for or {@link Long#MIN_VALUE} for all.
* @param endTimeMillis The end time to filter for or {@link Long#MAX_VALUE} for all.
*
* @hide
*/
public void filter(int uid, @Nullable String packageName, @Nullable String attributionTag,
@Nullable String[] opNames, @OpHistoryFlags int historyFilter,
@HistoricalOpsRequestFilter int filter,
long beginTimeMillis, long endTimeMillis) {
final long durationMillis = getDurationMillis();
mBeginTimeMillis = Math.max(mBeginTimeMillis, beginTimeMillis);
mEndTimeMillis = Math.min(mEndTimeMillis, endTimeMillis);
final double scaleFactor = Math.min((double) (endTimeMillis - beginTimeMillis)
/ (double) durationMillis, 1);
final int uidCount = getUidCount();
for (int i = uidCount - 1; i >= 0; i--) {
final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i);
if ((filter & FILTER_BY_UID) != 0 && uid != uidOp.getUid()) {
mHistoricalUidOps.removeAt(i);
} else {
uidOp.filter(packageName, attributionTag, opNames, filter, historyFilter,
scaleFactor, mBeginTimeMillis, mEndTimeMillis);
if (uidOp.getPackageCount() == 0) {
mHistoricalUidOps.removeAt(i);
}
}
}
}
/** @hide */
public boolean isEmpty() {
if (getBeginTimeMillis() >= getEndTimeMillis()) {
return true;
}
final int uidCount = getUidCount();
for (int i = uidCount - 1; i >= 0; i--) {
final HistoricalUidOps uidOp = mHistoricalUidOps.valueAt(i);
if (!uidOp.isEmpty()) {
return false;
}
}
return true;
}
/** @hide */
public long getDurationMillis() {
return mEndTimeMillis - mBeginTimeMillis;
}
/** @hide */
@TestApi
public void increaseAccessCount(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalUidOps(uid).increaseAccessCount(opCode,
packageName, attributionTag, uidState, flags, increment);
}
/** @hide */
@TestApi
public void increaseRejectCount(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalUidOps(uid).increaseRejectCount(opCode,
packageName, attributionTag, uidState, flags, increment);
}
/** @hide */
@TestApi
public void increaseAccessDuration(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalUidOps(uid).increaseAccessDuration(opCode,
packageName, attributionTag, uidState, flags, increment);
}
/** @hide */
@TestApi
public void addDiscreteAccess(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int opFlag,
long discreteAccessTime, long discreteAccessDuration) {
getOrCreateHistoricalUidOps(uid).addDiscreteAccess(opCode, packageName, attributionTag,
uidState, opFlag, discreteAccessTime, discreteAccessDuration, null);
}
/** @hide */
public void addDiscreteAccess(int opCode, int uid, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int opFlag,
long discreteAccessTime, long discreteAccessDuration,
@Nullable OpEventProxyInfo proxy) {
getOrCreateHistoricalUidOps(uid).addDiscreteAccess(opCode, packageName, attributionTag,
uidState, opFlag, discreteAccessTime, discreteAccessDuration, proxy);
}
/** @hide */
@TestApi
public void offsetBeginAndEndTime(long offsetMillis) {
mBeginTimeMillis += offsetMillis;
mEndTimeMillis += offsetMillis;
}
/** @hide */
public void setBeginAndEndTime(long beginTimeMillis, long endTimeMillis) {
mBeginTimeMillis = beginTimeMillis;
mEndTimeMillis = endTimeMillis;
}
/** @hide */
public void setBeginTime(long beginTimeMillis) {
mBeginTimeMillis = beginTimeMillis;
}
/** @hide */
public void setEndTime(long endTimeMillis) {
mEndTimeMillis = endTimeMillis;
}
/**
* @return The beginning of the interval in milliseconds since
* epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian).
*/
public long getBeginTimeMillis() {
return mBeginTimeMillis;
}
/**
* @return The end of the interval in milliseconds since
* epoch start (January 1, 1970 00:00:00.000 GMT - Gregorian).
*/
public long getEndTimeMillis() {
return mEndTimeMillis;
}
/**
* Gets number of UIDs with historical ops.
*
* @return The number of UIDs with historical ops.
*
* @see #getUidOpsAt(int)
*/
public @IntRange(from = 0) int getUidCount() {
if (mHistoricalUidOps == null) {
return 0;
}
return mHistoricalUidOps.size();
}
/**
* Gets the historical UID ops at a given index.
*
* @param index The index.
*
* @return The historical UID ops at the given index.
*
* @see #getUidCount()
*/
public @NonNull HistoricalUidOps getUidOpsAt(@IntRange(from = 0) int index) {
if (mHistoricalUidOps == null) {
throw new IndexOutOfBoundsException();
}
return mHistoricalUidOps.valueAt(index);
}
/**
* Gets the historical UID ops for a given UID.
*
* @param uid The UID.
*
* @return The historical ops for the UID.
*/
public @Nullable HistoricalUidOps getUidOps(int uid) {
if (mHistoricalUidOps == null) {
return null;
}
return mHistoricalUidOps.get(uid);
}
/** @hide */
public void clearHistory(int uid, @NonNull String packageName) {
HistoricalUidOps historicalUidOps = getOrCreateHistoricalUidOps(uid);
historicalUidOps.clearHistory(packageName);
if (historicalUidOps.isEmpty()) {
mHistoricalUidOps.remove(uid);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeLong(mBeginTimeMillis);
parcel.writeLong(mEndTimeMillis);
if (mHistoricalUidOps != null) {
final int uidCount = mHistoricalUidOps.size();
parcel.writeInt(uidCount);
for (int i = 0; i < uidCount; i++) {
parcel.writeInt(mHistoricalUidOps.keyAt(i));
}
final List<HistoricalUidOps> opsList = new ArrayList<>(uidCount);
for (int i = 0; i < uidCount; i++) {
opsList.add(mHistoricalUidOps.valueAt(i));
}
parcel.writeParcelable(new ParceledListSlice<>(opsList), flags);
} else {
parcel.writeInt(-1);
}
}
/**
* Accepts a visitor to traverse the ops tree.
*
* @param visitor The visitor.
*
* @hide
*/
public void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalOps(this);
final int uidCount = getUidCount();
for (int i = 0; i < uidCount; i++) {
getUidOpsAt(i).accept(visitor);
}
}
private @NonNull HistoricalUidOps getOrCreateHistoricalUidOps(int uid) {
if (mHistoricalUidOps == null) {
mHistoricalUidOps = new SparseArray<>();
}
HistoricalUidOps historicalUidOp = mHistoricalUidOps.get(uid);
if (historicalUidOp == null) {
historicalUidOp = new HistoricalUidOps(uid);
mHistoricalUidOps.put(uid, historicalUidOp);
}
return historicalUidOp;
}
/**
* @return Rounded value up at the 0.5 boundary.
*
* @hide
*/
public static double round(double value) {
return Math.floor(value + 0.5);
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final HistoricalOps other = (HistoricalOps) obj;
if (mBeginTimeMillis != other.mBeginTimeMillis) {
return false;
}
if (mEndTimeMillis != other.mEndTimeMillis) {
return false;
}
if (mHistoricalUidOps == null) {
if (other.mHistoricalUidOps != null) {
return false;
}
} else if (!mHistoricalUidOps.equals(other.mHistoricalUidOps)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = (int) (mBeginTimeMillis ^ (mBeginTimeMillis >>> 32));
result = 31 * result + mHistoricalUidOps.hashCode();
return result;
}
@NonNull
@Override
public String toString() {
return getClass().getSimpleName() + "[from:"
+ mBeginTimeMillis + " to:" + mEndTimeMillis + "]";
}
public static final @android.annotation.NonNull Creator<HistoricalOps> CREATOR = new Creator<HistoricalOps>() {
@Override
public @NonNull HistoricalOps createFromParcel(@NonNull Parcel parcel) {
return new HistoricalOps(parcel);
}
@Override
public @NonNull HistoricalOps[] newArray(int size) {
return new HistoricalOps[size];
}
};
}
/**
* This class represents historical app op state for a UID.
*
* @hide
*/
@SystemApi
public static final class HistoricalUidOps implements Parcelable {
private final int mUid;
private @Nullable ArrayMap<String, HistoricalPackageOps> mHistoricalPackageOps;
/** @hide */
public HistoricalUidOps(int uid) {
mUid = uid;
}
private HistoricalUidOps(@NonNull HistoricalUidOps other) {
mUid = other.mUid;
final int opCount = other.getPackageCount();
for (int i = 0; i < opCount; i++) {
final HistoricalPackageOps origOps = other.getPackageOpsAt(i);
final HistoricalPackageOps cloneOps = new HistoricalPackageOps(origOps);
if (mHistoricalPackageOps == null) {
mHistoricalPackageOps = new ArrayMap<>(opCount);
}
mHistoricalPackageOps.put(cloneOps.getPackageName(), cloneOps);
}
}
private HistoricalUidOps(@NonNull Parcel parcel) {
// No arg check since we always read from a trusted source.
mUid = parcel.readInt();
mHistoricalPackageOps = parcel.createTypedArrayMap(HistoricalPackageOps.CREATOR);
}
private @Nullable HistoricalUidOps splice(double fractionToRemove) {
HistoricalUidOps splice = null;
final int packageCount = getPackageCount();
for (int i = 0; i < packageCount; i++) {
final HistoricalPackageOps origOps = getPackageOpsAt(i);
final HistoricalPackageOps spliceOps = origOps.splice(fractionToRemove);
if (spliceOps != null) {
if (splice == null) {
splice = new HistoricalUidOps(mUid);
}
if (splice.mHistoricalPackageOps == null) {
splice.mHistoricalPackageOps = new ArrayMap<>();
}
splice.mHistoricalPackageOps.put(spliceOps.getPackageName(), spliceOps);
}
}
return splice;
}
private void merge(@NonNull HistoricalUidOps other) {
final int packageCount = other.getPackageCount();
for (int i = 0; i < packageCount; i++) {
final HistoricalPackageOps otherPackageOps = other.getPackageOpsAt(i);
final HistoricalPackageOps thisPackageOps = getPackageOps(
otherPackageOps.getPackageName());
if (thisPackageOps != null) {
thisPackageOps.merge(otherPackageOps);
} else {
if (mHistoricalPackageOps == null) {
mHistoricalPackageOps = new ArrayMap<>();
}
mHistoricalPackageOps.put(otherPackageOps.getPackageName(), otherPackageOps);
}
}
}
private void filter(@Nullable String packageName, @Nullable String attributionTag,
@Nullable String[] opNames, @HistoricalOpsRequestFilter int filter,
@OpHistoryFlags int historyFilter, double fractionToRemove, long beginTimeMillis,
long endTimeMillis) {
final int packageCount = getPackageCount();
for (int i = packageCount - 1; i >= 0; i--) {
final HistoricalPackageOps packageOps = getPackageOpsAt(i);
if ((filter & FILTER_BY_PACKAGE_NAME) != 0 && !packageName.equals(
packageOps.getPackageName())) {
mHistoricalPackageOps.removeAt(i);
} else {
packageOps.filter(attributionTag, opNames, filter, historyFilter,
fractionToRemove, beginTimeMillis, endTimeMillis);
if (packageOps.getAttributedOpsCount() == 0) {
mHistoricalPackageOps.removeAt(i);
}
}
}
}
private boolean isEmpty() {
final int packageCount = getPackageCount();
for (int i = packageCount - 1; i >= 0; i--) {
final HistoricalPackageOps packageOps = mHistoricalPackageOps.valueAt(i);
if (!packageOps.isEmpty()) {
return false;
}
}
return true;
}
private void increaseAccessCount(int opCode, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalPackageOps(packageName).increaseAccessCount(
opCode, attributionTag, uidState, flags, increment);
}
private void increaseRejectCount(int opCode, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalPackageOps(packageName).increaseRejectCount(
opCode, attributionTag, uidState, flags, increment);
}
private void increaseAccessDuration(int opCode, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
long increment) {
getOrCreateHistoricalPackageOps(packageName).increaseAccessDuration(
opCode, attributionTag, uidState, flags, increment);
}
private void addDiscreteAccess(int opCode, @NonNull String packageName,
@Nullable String attributionTag, @UidState int uidState,
@OpFlags int flag, long discreteAccessTime, long discreteAccessDuration,
@Nullable OpEventProxyInfo proxy) {
getOrCreateHistoricalPackageOps(packageName).addDiscreteAccess(opCode, attributionTag,
uidState, flag, discreteAccessTime, discreteAccessDuration, proxy);
};
/**
* @return The UID for which the data is related.
*/
public int getUid() {
return mUid;
}
/**
* Gets number of packages with historical ops.
*
* @return The number of packages with historical ops.
*
* @see #getPackageOpsAt(int)
*/
public @IntRange(from = 0) int getPackageCount() {
if (mHistoricalPackageOps == null) {
return 0;
}
return mHistoricalPackageOps.size();
}
/**
* Gets the historical package ops at a given index.
*
* @param index The index.
*
* @return The historical package ops at the given index.
*
* @see #getPackageCount()
*/
public @NonNull HistoricalPackageOps getPackageOpsAt(@IntRange(from = 0) int index) {
if (mHistoricalPackageOps == null) {
throw new IndexOutOfBoundsException();
}
return mHistoricalPackageOps.valueAt(index);
}
/**
* Gets the historical package ops for a given package.
*
* @param packageName The package.
*
* @return The historical ops for the package.
*/
public @Nullable HistoricalPackageOps getPackageOps(@NonNull String packageName) {
if (mHistoricalPackageOps == null) {
return null;
}
return mHistoricalPackageOps.get(packageName);
}
private void clearHistory(@NonNull String packageName) {
if (mHistoricalPackageOps != null) {
mHistoricalPackageOps.remove(packageName);
}
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeInt(mUid);
parcel.writeTypedArrayMap(mHistoricalPackageOps, flags);
}
private void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalUidOps(this);
final int packageCount = getPackageCount();
for (int i = 0; i < packageCount; i++) {
getPackageOpsAt(i).accept(visitor);
}
}
private @NonNull HistoricalPackageOps getOrCreateHistoricalPackageOps(
@NonNull String packageName) {
if (mHistoricalPackageOps == null) {
mHistoricalPackageOps = new ArrayMap<>();
}
HistoricalPackageOps historicalPackageOp = mHistoricalPackageOps.get(packageName);
if (historicalPackageOp == null) {
historicalPackageOp = new HistoricalPackageOps(packageName);
mHistoricalPackageOps.put(packageName, historicalPackageOp);
}
return historicalPackageOp;
}
public static final @android.annotation.NonNull Creator<HistoricalUidOps> CREATOR = new Creator<HistoricalUidOps>() {
@Override
public @NonNull HistoricalUidOps createFromParcel(@NonNull Parcel parcel) {
return new HistoricalUidOps(parcel);
}
@Override
public @NonNull HistoricalUidOps[] newArray(int size) {
return new HistoricalUidOps[size];
}
};
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final HistoricalUidOps other = (HistoricalUidOps) obj;
if (mUid != other.mUid) {
return false;
}
if (mHistoricalPackageOps == null) {
if (other.mHistoricalPackageOps != null) {
return false;
}
} else if (!mHistoricalPackageOps.equals(other.mHistoricalPackageOps)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = mUid;
result = 31 * result + (mHistoricalPackageOps != null
? mHistoricalPackageOps.hashCode() : 0);
return result;
}
}
/**
* This class represents historical app op information about a package.
*
* @hide
*/
@SystemApi
public static final class HistoricalPackageOps implements Parcelable {
private final @NonNull String mPackageName;
private @Nullable ArrayMap<String, AttributedHistoricalOps> mAttributedHistoricalOps;
/** @hide */
public HistoricalPackageOps(@NonNull String packageName) {
mPackageName = packageName;
}
private HistoricalPackageOps(@NonNull HistoricalPackageOps other) {
mPackageName = other.mPackageName;
final int opCount = other.getAttributedOpsCount();
for (int i = 0; i < opCount; i++) {
final AttributedHistoricalOps origOps = other.getAttributedOpsAt(i);
final AttributedHistoricalOps cloneOps = new AttributedHistoricalOps(origOps);
if (mAttributedHistoricalOps == null) {
mAttributedHistoricalOps = new ArrayMap<>(opCount);
}
mAttributedHistoricalOps.put(cloneOps.getTag(), cloneOps);
}
}
private HistoricalPackageOps(@NonNull Parcel parcel) {
mPackageName = parcel.readString();
mAttributedHistoricalOps = parcel.createTypedArrayMap(AttributedHistoricalOps.CREATOR);
}
private @Nullable HistoricalPackageOps splice(double fractionToRemove) {
HistoricalPackageOps splice = null;
final int attributionCount = getAttributedOpsCount();
for (int i = 0; i < attributionCount; i++) {
final AttributedHistoricalOps origOps = getAttributedOpsAt(i);
final AttributedHistoricalOps spliceOps = origOps.splice(fractionToRemove);
if (spliceOps != null) {
if (splice == null) {
splice = new HistoricalPackageOps(mPackageName);
}
if (splice.mAttributedHistoricalOps == null) {
splice.mAttributedHistoricalOps = new ArrayMap<>();
}
splice.mAttributedHistoricalOps.put(spliceOps.getTag(), spliceOps);
}
}
return splice;
}
private void merge(@NonNull HistoricalPackageOps other) {
final int attributionCount = other.getAttributedOpsCount();
for (int i = 0; i < attributionCount; i++) {
final AttributedHistoricalOps otherAttributionOps = other.getAttributedOpsAt(i);
final AttributedHistoricalOps thisAttributionOps = getAttributedOps(
otherAttributionOps.getTag());
if (thisAttributionOps != null) {
thisAttributionOps.merge(otherAttributionOps);
} else {
if (mAttributedHistoricalOps == null) {
mAttributedHistoricalOps = new ArrayMap<>();
}
mAttributedHistoricalOps.put(otherAttributionOps.getTag(),
otherAttributionOps);
}
}
}
private void filter(@Nullable String attributionTag, @Nullable String[] opNames,
@HistoricalOpsRequestFilter int filter, @OpHistoryFlags int historyFilter,
double fractionToRemove, long beginTimeMillis, long endTimeMillis) {
final int attributionCount = getAttributedOpsCount();
for (int i = attributionCount - 1; i >= 0; i--) {
final AttributedHistoricalOps attributionOps = getAttributedOpsAt(i);
if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(attributionTag,
attributionOps.getTag())) {
mAttributedHistoricalOps.removeAt(i);
} else {
attributionOps.filter(opNames, filter, historyFilter, fractionToRemove,
beginTimeMillis, endTimeMillis);
if (attributionOps.getOpCount() == 0) {
mAttributedHistoricalOps.removeAt(i);
}
}
}
}
private void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalPackageOps(this);
final int attributionCount = getAttributedOpsCount();
for (int i = 0; i < attributionCount; i++) {
getAttributedOpsAt(i).accept(visitor);
}
}
private boolean isEmpty() {
final int attributionCount = getAttributedOpsCount();
for (int i = attributionCount - 1; i >= 0; i--) {
final AttributedHistoricalOps attributionOps = mAttributedHistoricalOps.valueAt(i);
if (!attributionOps.isEmpty()) {
return false;
}
}
return true;
}
private void increaseAccessCount(int opCode, @Nullable String attributionTag,
@UidState int uidState, @OpFlags int flags, long increment) {
getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessCount(
opCode, uidState, flags, increment);
}
private void increaseRejectCount(int opCode, @Nullable String attributionTag,
@UidState int uidState, @OpFlags int flags, long increment) {
getOrCreateAttributedHistoricalOps(attributionTag).increaseRejectCount(
opCode, uidState, flags, increment);
}
private void increaseAccessDuration(int opCode, @Nullable String attributionTag,
@UidState int uidState, @OpFlags int flags, long increment) {
getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessDuration(
opCode, uidState, flags, increment);
}
private void addDiscreteAccess(int opCode, @Nullable String attributionTag,
@UidState int uidState, @OpFlags int flag, long discreteAccessTime,
long discreteAccessDuration, @Nullable OpEventProxyInfo proxy) {
getOrCreateAttributedHistoricalOps(attributionTag).addDiscreteAccess(opCode, uidState,
flag, discreteAccessTime, discreteAccessDuration, proxy);
}
/**
* Gets the package name which the data represents.
*
* @return The package name which the data represents.
*/
public @NonNull String getPackageName() {
return mPackageName;
}
private @NonNull AttributedHistoricalOps getOrCreateAttributedHistoricalOps(
@Nullable String attributionTag) {
if (mAttributedHistoricalOps == null) {
mAttributedHistoricalOps = new ArrayMap<>();
}
AttributedHistoricalOps historicalAttributionOp = mAttributedHistoricalOps.get(
attributionTag);
if (historicalAttributionOp == null) {
historicalAttributionOp = new AttributedHistoricalOps(attributionTag);
mAttributedHistoricalOps.put(attributionTag, historicalAttributionOp);
}
return historicalAttributionOp;
}
/**
* Gets number historical app ops.
*
* @return The number historical app ops.
* @see #getOpAt(int)
*/
public @IntRange(from = 0) int getOpCount() {
int numOps = 0;
int numAttributions = getAttributedOpsCount();
for (int code = 0; code < _NUM_OP; code++) {
String opName = opToPublicName(code);
for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) {
if (getAttributedOpsAt(attributionNum).getOp(opName) != null) {
numOps++;
break;
}
}
}
return numOps;
}
/**
* Gets the historical op at a given index.
*
* <p>This combines the counts from all attributions.
*
* @param index The index to lookup.
* @return The op at the given index.
* @see #getOpCount()
*/
public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) {
int numOpsFound = 0;
int numAttributions = getAttributedOpsCount();
for (int code = 0; code < _NUM_OP; code++) {
String opName = opToPublicName(code);
for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) {
if (getAttributedOpsAt(attributionNum).getOp(opName) != null) {
if (numOpsFound == index) {
return getOp(opName);
} else {
numOpsFound++;
break;
}
}
}
}
throw new IndexOutOfBoundsException();
}
/**
* Gets the historical entry for a given op name.
*
* <p>This combines the counts from all attributions.
*
* @param opName The op name.
* @return The historical entry for that op name.
*/
public @Nullable HistoricalOp getOp(@NonNull String opName) {
if (mAttributedHistoricalOps == null) {
return null;
}
HistoricalOp combinedOp = null;
int numAttributions = getAttributedOpsCount();
for (int i = 0; i < numAttributions; i++) {
HistoricalOp attributionOp = getAttributedOpsAt(i).getOp(opName);
if (attributionOp != null) {
if (combinedOp == null) {
combinedOp = new HistoricalOp(attributionOp);
} else {
combinedOp.merge(attributionOp);
}
}
}
return combinedOp;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(@NonNull Parcel parcel, int flags) {
parcel.writeString(mPackageName);
parcel.writeTypedArrayMap(mAttributedHistoricalOps, flags);
}
public static final @android.annotation.NonNull Creator<HistoricalPackageOps> CREATOR =
new Creator<HistoricalPackageOps>() {
@Override
public @NonNull HistoricalPackageOps createFromParcel(@NonNull Parcel parcel) {
return new HistoricalPackageOps(parcel);
}
@Override
public @NonNull HistoricalPackageOps[] newArray(int size) {
return new HistoricalPackageOps[size];
}
};
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final HistoricalPackageOps other = (HistoricalPackageOps) obj;
if (!mPackageName.equals(other.mPackageName)) {
return false;
}
if (mAttributedHistoricalOps == null) {
if (other.mAttributedHistoricalOps != null) {
return false;
}
} else if (!mAttributedHistoricalOps.equals(other.mAttributedHistoricalOps)) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = mPackageName != null ? mPackageName.hashCode() : 0;
result = 31 * result + (mAttributedHistoricalOps != null
? mAttributedHistoricalOps.hashCode() : 0);
return result;
}
/**
* Gets number of attributed historical ops.
*
* @return The number of attribution with historical ops.
*
* @see #getAttributedOpsAt(int)
*/
public @IntRange(from = 0) int getAttributedOpsCount() {
if (mAttributedHistoricalOps == null) {
return 0;
}
return mAttributedHistoricalOps.size();
}
/**
* Gets the attributed historical ops at a given index.
*
* @param index The index.
*
* @return The historical attribution ops at the given index.
*
* @see #getAttributedOpsCount()
*/
public @NonNull AttributedHistoricalOps getAttributedOpsAt(@IntRange(from = 0) int index) {
if (mAttributedHistoricalOps == null) {
throw new IndexOutOfBoundsException();
}
return mAttributedHistoricalOps.valueAt(index);
}
/**
* Gets the attributed historical ops for a given attribution tag.
*
* @param attributionTag The attribution tag.
*
* @return The historical ops for the attribution.
*/
public @Nullable AttributedHistoricalOps getAttributedOps(@Nullable String attributionTag) {
if (mAttributedHistoricalOps == null) {
return null;
}
return mAttributedHistoricalOps.get(attributionTag);
}
}
/**
* This class represents historical app op information about a attribution in a package.
*
* @hide
*/
@SystemApi
/* codegen verifier cannot deal with nested class parameters
@DataClass(genHiddenConstructor = true,
genEqualsHashCode = true, genHiddenCopyConstructor = true) */
@DataClass.Suppress("getHistoricalOps")
public static final class AttributedHistoricalOps implements Parcelable {
/** {@link Context#createAttributionContext attribution} tag */
private final @Nullable String mTag;
/** Ops for this attribution */
private @Nullable ArrayMap<String, HistoricalOp> mHistoricalOps;
/** @hide */
public AttributedHistoricalOps(@NonNull String tag) {
mTag = tag;
}
private AttributedHistoricalOps(@NonNull AttributedHistoricalOps other) {
mTag = other.mTag;
final int opCount = other.getOpCount();
for (int i = 0; i < opCount; i++) {
final HistoricalOp origOp = other.getOpAt(i);
final HistoricalOp cloneOp = new HistoricalOp(origOp);
if (mHistoricalOps == null) {
mHistoricalOps = new ArrayMap<>(opCount);
}
mHistoricalOps.put(cloneOp.getOpName(), cloneOp);
}
}
private @Nullable AttributedHistoricalOps splice(double fractionToRemove) {
AttributedHistoricalOps splice = null;
final int opCount = getOpCount();
for (int i = 0; i < opCount; i++) {
final HistoricalOp origOps = getOpAt(i);
final HistoricalOp spliceOps = origOps.splice(fractionToRemove);
if (spliceOps != null) {
if (splice == null) {
splice = new AttributedHistoricalOps(mTag, null);
}
if (splice.mHistoricalOps == null) {
splice.mHistoricalOps = new ArrayMap<>();
}
splice.mHistoricalOps.put(spliceOps.getOpName(), spliceOps);
}
}
return splice;
}
private void merge(@NonNull AttributedHistoricalOps other) {
final int opCount = other.getOpCount();
for (int i = 0; i < opCount; i++) {
final HistoricalOp otherOp = other.getOpAt(i);
final HistoricalOp thisOp = getOp(otherOp.getOpName());
if (thisOp != null) {
thisOp.merge(otherOp);
} else {
if (mHistoricalOps == null) {
mHistoricalOps = new ArrayMap<>();
}
mHistoricalOps.put(otherOp.getOpName(), otherOp);
}
}
}
private void filter(@Nullable String[] opNames, @HistoricalOpsRequestFilter int filter,
@OpHistoryFlags int historyFilter, double scaleFactor, long beginTimeMillis,
long endTimeMillis) {
final int opCount = getOpCount();
for (int i = opCount - 1; i >= 0; i--) {
final HistoricalOp op = mHistoricalOps.valueAt(i);
if ((filter & FILTER_BY_OP_NAMES) != 0 && !ArrayUtils.contains(opNames,
op.getOpName())) {
mHistoricalOps.removeAt(i);
} else {
op.filter(historyFilter, scaleFactor, beginTimeMillis, endTimeMillis);
}
}
}
private boolean isEmpty() {
final int opCount = getOpCount();
for (int i = opCount - 1; i >= 0; i--) {
final HistoricalOp op = mHistoricalOps.valueAt(i);
if (!op.isEmpty()) {
return false;
}
}
return true;
}
private void increaseAccessCount(int opCode, @UidState int uidState,
@OpFlags int flags, long increment) {
getOrCreateHistoricalOp(opCode).increaseAccessCount(uidState, flags, increment);
}
private void increaseRejectCount(int opCode, @UidState int uidState,
@OpFlags int flags, long increment) {
getOrCreateHistoricalOp(opCode).increaseRejectCount(uidState, flags, increment);
}
private void increaseAccessDuration(int opCode, @UidState int uidState,
@OpFlags int flags, long increment) {
getOrCreateHistoricalOp(opCode).increaseAccessDuration(uidState, flags, increment);
}
private void addDiscreteAccess(int opCode, @UidState int uidState, @OpFlags int flag,
long discreteAccessTime, long discreteAccessDuration,
@Nullable OpEventProxyInfo proxy) {
getOrCreateHistoricalOp(opCode).addDiscreteAccess(uidState,flag, discreteAccessTime,
discreteAccessDuration, proxy);
}
/**
* Gets number historical app ops.
*
* @return The number historical app ops.
* @see #getOpAt(int)
*/
public @IntRange(from = 0) int getOpCount() {
if (mHistoricalOps == null) {
return 0;
}
return mHistoricalOps.size();
}
/**
* Gets the historical op at a given index.
*
* @param index The index to lookup.
* @return The op at the given index.
* @see #getOpCount()
*/
public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) {
if (mHistoricalOps == null) {
throw new IndexOutOfBoundsException();
}
return mHistoricalOps.valueAt(index);
}
/**
* Gets the historical entry for a given op name.
*
* @param opName The op name.
* @return The historical entry for that op name.
*/
public @Nullable HistoricalOp getOp(@NonNull String opName) {
if (mHistoricalOps == null) {
return null;
}
return mHistoricalOps.get(opName);
}
private void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalAttributionOps(this);
final int opCount = getOpCount();
for (int i = 0; i < opCount; i++) {
getOpAt(i).accept(visitor);
}
}
private @NonNull HistoricalOp getOrCreateHistoricalOp(int opCode) {
if (mHistoricalOps == null) {
mHistoricalOps = new ArrayMap<>();
}
final String opStr = sOpToString[opCode];
HistoricalOp op = mHistoricalOps.get(opStr);
if (op == null) {
op = new HistoricalOp(opCode);
mHistoricalOps.put(opStr, op);
}
return op;
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/app/AppOpsManager.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/**
* Creates a new HistoricalAttributionOps.
*
* @param tag
* {@link Context#createAttributionContext attribution} tag
* @param historicalOps
* Ops for this attribution
* @hide
*/
@DataClass.Generated.Member
public AttributedHistoricalOps(
@Nullable String tag,
@Nullable ArrayMap<String,HistoricalOp> historicalOps) {
this.mTag = tag;
this.mHistoricalOps = historicalOps;
// onConstructed(); // You can define this method to get a callback
}
/**
* {@link Context#createAttributionContext attribution} tag
*/
@DataClass.Generated.Member
public @Nullable String getTag() {
return mTag;
}
@Override
@DataClass.Generated.Member
public boolean equals(@Nullable Object o) {
// You can override field equality logic by defining either of the methods like:
// boolean fieldNameEquals(HistoricalAttributionOps other) { ... }
// boolean fieldNameEquals(FieldType otherValue) { ... }
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@SuppressWarnings("unchecked")
AttributedHistoricalOps that = (AttributedHistoricalOps) o;
//noinspection PointlessBooleanExpression
return true
&& Objects.equals(mTag, that.mTag)
&& Objects.equals(mHistoricalOps, that.mHistoricalOps);
}
@Override
@DataClass.Generated.Member
public int hashCode() {
// You can override field hashCode logic by defining methods like:
// int fieldNameHashCode() { ... }
int _hash = 1;
_hash = 31 * _hash + Objects.hashCode(mTag);
_hash = 31 * _hash + Objects.hashCode(mHistoricalOps);
return _hash;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mTag != null) flg |= 0x1;
if (mHistoricalOps != null) flg |= 0x2;
dest.writeByte(flg);
if (mTag != null) dest.writeString(mTag);
if (mHistoricalOps != null) dest.writeMap(mHistoricalOps);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ AttributedHistoricalOps(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
String attributionTag = (flg & 0x1) == 0 ? null : in.readString();
ArrayMap<String,HistoricalOp> historicalOps = null;
if ((flg & 0x2) != 0) {
historicalOps = new ArrayMap();
in.readMap(historicalOps, HistoricalOp.class.getClassLoader());
}
this.mTag = attributionTag;
this.mHistoricalOps = historicalOps;
// onConstructed(); // You can define this method to get a callback
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator<AttributedHistoricalOps> CREATOR
= new Parcelable.Creator<AttributedHistoricalOps>() {
@Override
public AttributedHistoricalOps[] newArray(int size) {
return new AttributedHistoricalOps[size];
}
@Override
public AttributedHistoricalOps createFromParcel(@NonNull Parcel in) {
return new AttributedHistoricalOps(in);
}
};
/*
@DataClass.Generated(
time = 1578113234821L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
inputSignatures = "private final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate @android.annotation.Nullable android.util.ArrayMap<java.lang.String,android.app.HistoricalOp> mHistoricalOps\nprivate @android.annotation.Nullable android.app.HistoricalAttributionOps splice(double)\nprivate void merge(android.app.HistoricalAttributionOps)\nprivate void filter(java.lang.String[],int,double)\nprivate boolean isEmpty()\nprivate void increaseAccessCount(int,int,int,long)\nprivate void increaseRejectCount(int,int,int,long)\nprivate void increaseAccessDuration(int,int,int,long)\npublic @android.annotation.IntRange(from=0L) int getOpCount()\npublic @android.annotation.NonNull android.app.HistoricalOp getOpAt(int)\npublic @android.annotation.Nullable android.app.HistoricalOp getOp(java.lang.String)\nprivate void accept(android.app.HistoricalOpsVisitor)\nprivate @android.annotation.NonNull android.app.HistoricalOp getOrCreateHistoricalOp(int)\nclass HistoricalAttributionOps extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genEqualsHashCode=true, genHiddenCopyConstructor=true)")
@Deprecated
private void __metadata() {}
*/
//@formatter:on
// End of generated code
}
/**
* This class represents historical information about an app op.
*
* @hide
*/
@SystemApi
public static final class HistoricalOp implements Parcelable {
private final int mOp;
private @Nullable LongSparseLongArray mAccessCount;
private @Nullable LongSparseLongArray mRejectCount;
private @Nullable LongSparseLongArray mAccessDuration;
/** Discrete Ops for this Op */
private @Nullable List<AttributedOpEntry> mDiscreteAccesses;
/** @hide */
public HistoricalOp(int op) {
mOp = op;
}
private HistoricalOp(@NonNull HistoricalOp other) {
mOp = other.mOp;
if (other.mAccessCount != null) {
mAccessCount = other.mAccessCount.clone();
}
if (other.mRejectCount != null) {
mRejectCount = other.mRejectCount.clone();
}
if (other.mAccessDuration != null) {
mAccessDuration = other.mAccessDuration.clone();
}
final int historicalOpCount = other.getDiscreteAccessCount();
for (int i = 0; i < historicalOpCount; i++) {
final AttributedOpEntry origOp = other.getDiscreteAccessAt(i);
final AttributedOpEntry cloneOp = new AttributedOpEntry(origOp);
getOrCreateDiscreteAccesses().add(cloneOp);
}
}
private HistoricalOp(@NonNull Parcel parcel) {
mOp = parcel.readInt();
mAccessCount = readLongSparseLongArrayFromParcel(parcel);
mRejectCount = readLongSparseLongArrayFromParcel(parcel);
mAccessDuration = readLongSparseLongArrayFromParcel(parcel);
mDiscreteAccesses = readDiscreteAccessArrayFromParcel(parcel);
}
private void filter(@OpHistoryFlags int historyFlag, double scaleFactor,
long beginTimeMillis, long endTimeMillis) {
if ((historyFlag & HISTORY_FLAG_AGGREGATE) == 0) {
mAccessCount = null;
mRejectCount = null;
mAccessDuration = null;
} else {
scale(mAccessCount, scaleFactor);
scale(mRejectCount, scaleFactor);
scale(mAccessDuration, scaleFactor);
}
if ((historyFlag & HISTORY_FLAG_DISCRETE) == 0) {
mDiscreteAccesses = null;
return;
}
final int discreteOpCount = getDiscreteAccessCount();
for (int i = discreteOpCount - 1; i >= 0; i--) {
final AttributedOpEntry op = mDiscreteAccesses.get(i);
long opBeginTime = op.getLastAccessTime(OP_FLAGS_ALL);
long opEndTime = opBeginTime + op.getLastDuration(OP_FLAGS_ALL);
opEndTime = max(opBeginTime, opEndTime);
if (opEndTime < beginTimeMillis || opBeginTime > endTimeMillis) {
mDiscreteAccesses.remove(i);
}
}
}
private boolean isEmpty() {
return !hasData(mAccessCount)
&& !hasData(mRejectCount)
&& !hasData(mAccessDuration)
&& (mDiscreteAccesses == null);
}
private boolean hasData(@NonNull LongSparseLongArray array) {
return array != null && array.size() > 0;
}
private @Nullable HistoricalOp splice(double fractionToRemove) {
final HistoricalOp splice = new HistoricalOp(mOp);
splice(mAccessCount, splice::getOrCreateAccessCount, fractionToRemove);
splice(mRejectCount, splice::getOrCreateRejectCount, fractionToRemove);
splice(mAccessDuration, splice::getOrCreateAccessDuration, fractionToRemove);
return splice;
}
private static void splice(@Nullable LongSparseLongArray sourceContainer,
@NonNull Supplier<LongSparseLongArray> destContainerProvider,
double fractionToRemove) {
if (sourceContainer != null) {
final int size = sourceContainer.size();
for (int i = 0; i < size; i++) {
final long key = sourceContainer.keyAt(i);
final long value = sourceContainer.valueAt(i);
final long removedFraction = Math.round(value * fractionToRemove);
if (removedFraction > 0) {
destContainerProvider.get().put(key, removedFraction);
sourceContainer.put(key, value - removedFraction);
}
}
}
}
private void merge(@NonNull HistoricalOp other) {
merge(this::getOrCreateAccessCount, other.mAccessCount);
merge(this::getOrCreateRejectCount, other.mRejectCount);
merge(this::getOrCreateAccessDuration, other.mAccessDuration);
if (other.mDiscreteAccesses == null) {
return;
}
if (mDiscreteAccesses == null) {
mDiscreteAccesses = new ArrayList(other.mDiscreteAccesses);
return;
}
List<AttributedOpEntry> historicalDiscreteAccesses = new ArrayList<>();
final int otherHistoricalOpCount = other.getDiscreteAccessCount();
final int historicalOpCount = getDiscreteAccessCount();
int i = 0;
int j = 0;
while (i < otherHistoricalOpCount || j < historicalOpCount) {
if (i == otherHistoricalOpCount) {
historicalDiscreteAccesses.add(mDiscreteAccesses.get(j++));
} else if (j == historicalOpCount) {
historicalDiscreteAccesses.add(other.mDiscreteAccesses.get(i++));
} else if (mDiscreteAccesses.get(j).getLastAccessTime(OP_FLAGS_ALL)
< other.mDiscreteAccesses.get(i).getLastAccessTime(OP_FLAGS_ALL)) {
historicalDiscreteAccesses.add(mDiscreteAccesses.get(j++));
} else {
historicalDiscreteAccesses.add(other.mDiscreteAccesses.get(i++));
}
}
mDiscreteAccesses = deduplicateDiscreteEvents(historicalDiscreteAccesses);
}
private void increaseAccessCount(@UidState int uidState, @OpFlags int flags,
long increment) {
increaseCount(getOrCreateAccessCount(), uidState, flags, increment);
}
private void increaseRejectCount(@UidState int uidState, @OpFlags int flags,
long increment) {
increaseCount(getOrCreateRejectCount(), uidState, flags, increment);
}
private void increaseAccessDuration(@UidState int uidState, @OpFlags int flags,
long increment) {
increaseCount(getOrCreateAccessDuration(), uidState, flags, increment);
}
private void increaseCount(@NonNull LongSparseLongArray counts,
@UidState int uidState, @OpFlags int flags, long increment) {
while (flags != 0) {
final int flag = 1 << Integer.numberOfTrailingZeros(flags);
flags &= ~flag;
final long key = makeKey(uidState, flag);
counts.put(key, counts.get(key) + increment);
}
}
private void addDiscreteAccess(@UidState int uidState, @OpFlags int flag,
long discreteAccessTime, long discreteAccessDuration,
@Nullable OpEventProxyInfo proxy) {
List<AttributedOpEntry> discreteAccesses = getOrCreateDiscreteAccesses();
LongSparseArray<NoteOpEvent> accessEvents = new LongSparseArray<>();
long key = makeKey(uidState, flag);
NoteOpEvent note = new NoteOpEvent(discreteAccessTime, discreteAccessDuration, proxy);
accessEvents.append(key, note);
AttributedOpEntry access = new AttributedOpEntry(mOp, false, accessEvents, null);
int insertionPoint = discreteAccesses.size() - 1;
for (; insertionPoint >= 0; insertionPoint--) {
if (discreteAccesses.get(insertionPoint).getLastAccessTime(OP_FLAGS_ALL)
< discreteAccessTime) {
break;
}
}
insertionPoint++;
if (insertionPoint < discreteAccesses.size() && discreteAccesses.get(
insertionPoint).getLastAccessTime(OP_FLAGS_ALL) == discreteAccessTime) {
discreteAccesses.set(insertionPoint, mergeAttributedOpEntries(
Arrays.asList(discreteAccesses.get(insertionPoint), access)));
} else {
discreteAccesses.add(insertionPoint, access);
}
}
/**
* Gets the op name.
*
* @return The op name.
*/
public @NonNull String getOpName() {
return sOpToString[mOp];
}
/** @hide */
public int getOpCode() {
return mOp;
}
/**
* Gets number of discrete historical app ops.
*
* @return The number historical app ops.
* @see #getDiscreteAccessAt(int)
*/
public @IntRange(from = 0) int getDiscreteAccessCount() {
if (mDiscreteAccesses == null) {
return 0;
}
return mDiscreteAccesses.size();
}
/**
* Gets the historical op at a given index.
*
* @param index The index to lookup.
* @return The op at the given index.
* @see #getDiscreteAccessCount()
*/
public @NonNull AttributedOpEntry getDiscreteAccessAt(@IntRange(from = 0) int index) {
if (mDiscreteAccesses == null) {
throw new IndexOutOfBoundsException();
}
return mDiscreteAccesses.get(index);
}
/**
* Gets the number times the op was accessed (performed) in the foreground.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The times the op was accessed in the foreground.
*
* @see #getBackgroundAccessCount(int)
* @see #getAccessCount(int, int, int)
*/
public long getForegroundAccessCount(@OpFlags int flags) {
return sumForFlagsInStates(mAccessCount, MAX_PRIORITY_UID_STATE,
resolveFirstUnrestrictedUidState(mOp), flags);
}
/**
* Gets the discrete events the op was accessed (performed) in the foreground.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The list of discrete ops accessed in the foreground.
*
* @see #getBackgroundDiscreteAccesses(int)
* @see #getDiscreteAccesses(int, int, int)
*/
@NonNull
public List<AttributedOpEntry> getForegroundDiscreteAccesses(@OpFlags int flags) {
return listForFlagsInStates(mDiscreteAccesses, MAX_PRIORITY_UID_STATE,
resolveFirstUnrestrictedUidState(mOp), flags);
}
/**
* Gets the number times the op was accessed (performed) in the background.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The times the op was accessed in the background.
*
* @see #getForegroundAccessCount(int)
* @see #getAccessCount(int, int, int)
*/
public long getBackgroundAccessCount(@OpFlags int flags) {
return sumForFlagsInStates(mAccessCount, resolveLastRestrictedUidState(mOp),
MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the discrete events the op was accessed (performed) in the background.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The list of discrete ops accessed in the background.
*
* @see #getForegroundDiscreteAccesses(int)
* @see #getDiscreteAccesses(int, int, int)
*/
@NonNull
public List<AttributedOpEntry> getBackgroundDiscreteAccesses(@OpFlags int flags) {
return listForFlagsInStates(mDiscreteAccesses, resolveLastRestrictedUidState(mOp),
MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the number times the op was accessed (performed) for a
* range of uid states.
*
* @param fromUidState The UID state from which to query. Could be one of
* {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP},
* {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND},
* {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}.
* @param toUidState The UID state to which to query.
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
*
* @return The times the op was accessed for the given UID state.
*
* @see #getForegroundAccessCount(int)
* @see #getBackgroundAccessCount(int)
*/
public long getAccessCount(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
return sumForFlagsInStates(mAccessCount, fromUidState, toUidState, flags);
}
/**
* Gets the discrete events the op was accessed (performed) for a
* range of uid states.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The discrete the op was accessed in the background.
*
* @see #getBackgroundDiscreteAccesses(int)
* @see #getForegroundDiscreteAccesses(int)
*/
@NonNull
public List<AttributedOpEntry> getDiscreteAccesses(@UidState int fromUidState,
@UidState int toUidState, @OpFlags int flags) {
return listForFlagsInStates(mDiscreteAccesses, fromUidState, toUidState, flags);
}
/**
* Gets the number times the op was rejected in the foreground.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The times the op was rejected in the foreground.
*
* @see #getBackgroundRejectCount(int)
* @see #getRejectCount(int, int, int)
*/
public long getForegroundRejectCount(@OpFlags int flags) {
return sumForFlagsInStates(mRejectCount, MAX_PRIORITY_UID_STATE,
resolveFirstUnrestrictedUidState(mOp), flags);
}
/**
* Gets the number times the op was rejected in the background.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The times the op was rejected in the background.
*
* @see #getForegroundRejectCount(int)
* @see #getRejectCount(int, int, int)
*/
public long getBackgroundRejectCount(@OpFlags int flags) {
return sumForFlagsInStates(mRejectCount, resolveLastRestrictedUidState(mOp),
MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the number times the op was rejected for a given range of UID states.
*
* @param fromUidState The UID state from which to query. Could be one of
* {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP},
* {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND},
* {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}.
* @param toUidState The UID state to which to query.
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
*
* @return The times the op was rejected for the given UID state.
*
* @see #getForegroundRejectCount(int)
* @see #getBackgroundRejectCount(int)
*/
public long getRejectCount(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
return sumForFlagsInStates(mRejectCount, fromUidState, toUidState, flags);
}
/**
* Gets the total duration the app op was accessed (performed) in the foreground.
* The duration is in wall time.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The total duration the app op was accessed in the foreground.
*
* @see #getBackgroundAccessDuration(int)
* @see #getAccessDuration(int, int, int)
*/
public long getForegroundAccessDuration(@OpFlags int flags) {
return sumForFlagsInStates(mAccessDuration, MAX_PRIORITY_UID_STATE,
resolveFirstUnrestrictedUidState(mOp), flags);
}
/**
* Gets the total duration the app op was accessed (performed) in the background.
* The duration is in wall time.
*
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
* @return The total duration the app op was accessed in the background.
*
* @see #getForegroundAccessDuration(int)
* @see #getAccessDuration(int, int, int)
*/
public long getBackgroundAccessDuration(@OpFlags int flags) {
return sumForFlagsInStates(mAccessDuration, resolveLastRestrictedUidState(mOp),
MIN_PRIORITY_UID_STATE, flags);
}
/**
* Gets the total duration the app op was accessed (performed) for a given
* range of UID states. The duration is in wall time.
*
* @param fromUidState The UID state from which to query. Could be one of
* {@link #UID_STATE_PERSISTENT}, {@link #UID_STATE_TOP},
* {@link #UID_STATE_FOREGROUND_SERVICE}, {@link #UID_STATE_FOREGROUND},
* {@link #UID_STATE_BACKGROUND}, {@link #UID_STATE_CACHED}.
* @param toUidState The UID state from which to query.
* @param flags The flags which are any combination of
* {@link #OP_FLAG_SELF}, {@link #OP_FLAG_TRUSTED_PROXY},
* {@link #OP_FLAG_UNTRUSTED_PROXY}, {@link #OP_FLAG_TRUSTED_PROXIED},
* {@link #OP_FLAG_UNTRUSTED_PROXIED}. You can use {@link #OP_FLAGS_ALL}
* for any flag.
*
* @return The total duration the app op was accessed for the given UID state.
*
* @see #getForegroundAccessDuration(int)
* @see #getBackgroundAccessDuration(int)
*/
public long getAccessDuration(@UidState int fromUidState, @UidState int toUidState,
@OpFlags int flags) {
return sumForFlagsInStates(mAccessDuration, fromUidState, toUidState, flags);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int flags) {
parcel.writeInt(mOp);
writeLongSparseLongArrayToParcel(mAccessCount, parcel);
writeLongSparseLongArrayToParcel(mRejectCount, parcel);
writeLongSparseLongArrayToParcel(mAccessDuration, parcel);
writeDiscreteAccessArrayToParcel(mDiscreteAccesses, parcel, flags);
}
@Override
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
final HistoricalOp other = (HistoricalOp) obj;
if (mOp != other.mOp) {
return false;
}
if (!equalsLongSparseLongArray(mAccessCount, other.mAccessCount)) {
return false;
}
if (!equalsLongSparseLongArray(mRejectCount, other.mRejectCount)) {
return false;
}
if (!equalsLongSparseLongArray(mAccessDuration, other.mAccessDuration)) {
return false;
}
return mDiscreteAccesses == null ? (other.mDiscreteAccesses == null ? true
: false) : mDiscreteAccesses.equals(other.mDiscreteAccesses);
}
@Override
public int hashCode() {
int result = mOp;
result = 31 * result + Objects.hashCode(mAccessCount);
result = 31 * result + Objects.hashCode(mRejectCount);
result = 31 * result + Objects.hashCode(mAccessDuration);
result = 31 * result + Objects.hashCode(mDiscreteAccesses);
return result;
}
private void accept(@NonNull HistoricalOpsVisitor visitor) {
visitor.visitHistoricalOp(this);
}
private @NonNull LongSparseLongArray getOrCreateAccessCount() {
if (mAccessCount == null) {
mAccessCount = new LongSparseLongArray();
}
return mAccessCount;
}
private @NonNull LongSparseLongArray getOrCreateRejectCount() {
if (mRejectCount == null) {
mRejectCount = new LongSparseLongArray();
}
return mRejectCount;
}
private @NonNull LongSparseLongArray getOrCreateAccessDuration() {
if (mAccessDuration == null) {
mAccessDuration = new LongSparseLongArray();
}
return mAccessDuration;
}
private @NonNull List<AttributedOpEntry> getOrCreateDiscreteAccesses() {
if (mDiscreteAccesses == null) {
mDiscreteAccesses = new ArrayList<>();
}
return mDiscreteAccesses;
}
/**
* Multiplies the entries in the array with the passed in scale factor and
* rounds the result at up 0.5 boundary.
*
* @param data The data to scale.
* @param scaleFactor The scale factor.
*/
private static void scale(@NonNull LongSparseLongArray data, double scaleFactor) {
if (data != null) {
final int size = data.size();
for (int i = 0; i < size; i++) {
data.put(data.keyAt(i), (long) HistoricalOps.round(
(double) data.valueAt(i) * scaleFactor));
}
}
}
/**
* Merges two arrays while lazily acquiring the destination.
*
* @param thisSupplier The destination supplier.
* @param other The array to merge in.
*/
private static void merge(@NonNull Supplier<LongSparseLongArray> thisSupplier,
@Nullable LongSparseLongArray other) {
if (other != null) {
final int otherSize = other.size();
for (int i = 0; i < otherSize; i++) {
final LongSparseLongArray that = thisSupplier.get();
final long otherKey = other.keyAt(i);
final long otherValue = other.valueAt(i);
that.put(otherKey, that.get(otherKey) + otherValue);
}
}
}
/** @hide */
public @Nullable LongSparseArray<Object> collectKeys() {
LongSparseArray<Object> result = AppOpsManager.collectKeys(mAccessCount,
null /*result*/);
result = AppOpsManager.collectKeys(mRejectCount, result);
result = AppOpsManager.collectKeys(mAccessDuration, result);
return result;
}
public static final @android.annotation.NonNull Creator<HistoricalOp> CREATOR =
new Creator<HistoricalOp>() {
@Override
public @NonNull HistoricalOp createFromParcel(@NonNull Parcel source) {
return new HistoricalOp(source);
}
@Override
public @NonNull HistoricalOp[] newArray(int size) {
return new HistoricalOp[size];
}
};
}
/**
* Computes the sum of the counts for the given flags in between the begin and
* end UID states.
*
* @param counts The data array.
* @param beginUidState The beginning UID state (inclusive).
* @param endUidState The end UID state (inclusive).
* @param flags The UID flags.
* @return The sum.
*/
private static long sumForFlagsInStates(@Nullable LongSparseLongArray counts,
@UidState int beginUidState, @UidState int endUidState, @OpFlags int flags) {
if (counts == null) {
return 0;
}
long sum = 0;
while (flags != 0) {
final int flag = 1 << Integer.numberOfTrailingZeros(flags);
flags &= ~flag;
for (int uidState : UID_STATES) {
if (uidState < beginUidState || uidState > endUidState) {
continue;
}
final long key = makeKey(uidState, flag);
sum += counts.get(key);
}
}
return sum;
}
/**
* Returns list of events filtered by UidState and UID flags.
*
* @param accesses The events list.
* @param beginUidState The beginning UID state (inclusive).
* @param endUidState The end UID state (inclusive).
* @param flags The UID flags.
* @return filtered list of events.
*/
private static List<AttributedOpEntry> listForFlagsInStates(List<AttributedOpEntry> accesses,
@UidState int beginUidState, @UidState int endUidState, @OpFlags int flags) {
List<AttributedOpEntry> result = new ArrayList<>();
if (accesses == null) {
return result;
}
int nAccesses = accesses.size();
for (int i = 0; i < nAccesses; i++) {
AttributedOpEntry entry = accesses.get(i);
if (entry.getLastAccessTime(beginUidState, endUidState, flags) == -1) {
continue;
}
result.add(entry);
}
return deduplicateDiscreteEvents(result);
}
/**
* Callback for notification of changes to operation state.
*/
public interface OnOpChangedListener {
public void onOpChanged(String op, String packageName);
}
/**
* Callback for notification of changes to operation active state.
*/
public interface OnOpActiveChangedListener {
/**
* Called when the active state of an app-op changes.
*
* @param op The operation that changed.
* @param packageName The package performing the operation.
* @param active Whether the operation became active or inactive.
*/
void onOpActiveChanged(@NonNull String op, int uid, @NonNull String packageName,
boolean active);
/**
* Called when the active state of an app-op changes.
*
* @param op The operation that changed.
* @param uid The UID performing the operation.
* @param packageName The package performing the operation.
* @param attributionTag The operation's attribution tag.
* @param active Whether the operation became active or inactive.
* @param attributionFlags the attribution flags for this operation.
* @param attributionChainId the unique id of the attribution chain this op is a part of.
* @hide
*/
@TestApi
default void onOpActiveChanged(@NonNull String op, int uid, @NonNull String packageName,
@Nullable String attributionTag, boolean active, @AttributionFlags
int attributionFlags, int attributionChainId) {
onOpActiveChanged(op, uid, packageName, active);
}
}
/**
* Callback for notification of an op being noted.
*
* @hide
*/
public interface OnOpNotedListener {
/**
* Called when an op was noted.
* @param code The op code.
* @param uid The UID performing the operation.
* @param packageName The package performing the operation.
* @param attributionTag The attribution tag performing the operation.
* @param flags The flags of this op
* @param result The result of the note.
*/
void onOpNoted(int code, int uid, String packageName, String attributionTag,
@OpFlags int flags, @Mode int result);
}
/**
* Callback for notification of changes to operation state.
* This allows you to see the raw op codes instead of strings.
* @hide
*/
public static class OnOpChangedInternalListener implements OnOpChangedListener {
public void onOpChanged(String op, String packageName) { }
public void onOpChanged(int op, String packageName) { }
}
/**
* Callback for notification of changes to operation state.
* This allows you to see the raw op codes instead of strings.
* @hide
*/
public interface OnOpActiveChangedInternalListener extends OnOpActiveChangedListener {
default void onOpActiveChanged(String op, int uid, String packageName, boolean active) { }
default void onOpActiveChanged(int op, int uid, String packageName, boolean active) { }
}
/**
* Callback for notification of an op being started.
*
* @hide
*/
public interface OnOpStartedListener {
/**
* Represents a start operation that was unsuccessful
* @hide
*/
public int START_TYPE_FAILED = 0;
/**
* Represents a successful start operation
* @hide
*/
public int START_TYPE_STARTED = 1;
/**
* Represents an operation where a restricted operation became unrestricted, and resumed.
* @hide
*/
public int START_TYPE_RESUMED = 2;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(flag = true, prefix = { "TYPE_" }, value = {
START_TYPE_FAILED,
START_TYPE_STARTED,
START_TYPE_RESUMED
})
public @interface StartedType {}
/**
* Called when an op was started.
*
* Note: This is only for op starts. It is not called when an op is noted or stopped.
* @param op The op code.
* @param uid The UID performing the operation.
* @param packageName The package performing the operation.
* @param attributionTag The attribution tag performing the operation.
* @param flags The flags of this op.
* @param result The result of the start.
*/
void onOpStarted(int op, int uid, String packageName, String attributionTag,
@OpFlags int flags, @Mode int result);
/**
* Called when an op was started.
*
* Note: This is only for op starts. It is not called when an op is noted or stopped.
* By default, unless this method is overridden, no code will be executed for resume
* events.
* @param op The op code.
* @param uid The UID performing the operation.
* @param packageName The package performing the operation.
* @param attributionTag The attribution tag performing the operation.
* @param flags The flags of this op.
* @param result The result of the start.
* @param startType The start type of this start event. Either failed, resumed, or started.
* @param attributionFlags The location of this started op in an attribution chain.
* @param attributionChainId The ID of the attribution chain of this op, if it is in one.
*/
default void onOpStarted(int op, int uid, String packageName, String attributionTag,
@OpFlags int flags, @Mode int result, @StartedType int startType,
@AttributionFlags int attributionFlags, int attributionChainId) {
if (startType != START_TYPE_RESUMED) {
onOpStarted(op, uid, packageName, attributionTag, flags, result);
}
}
}
AppOpsManager(Context context, IAppOpsService service) {
mContext = context;
mService = service;
if (mContext != null) {
final PackageManager pm = mContext.getPackageManager();
try {
if (pm != null && pm.checkPermission(Manifest.permission.READ_DEVICE_CONFIG,
mContext.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_PRIVACY,
mContext.getMainExecutor(), properties -> {
if (properties.getKeyset().contains(FULL_LOG)) {
sFullLog = properties.getBoolean(FULL_LOG, false);
}
});
return;
}
} catch (Exception e) {
// This manager was made before DeviceConfig is ready, so it's a low-level
// system app. We likely don't care about its logs.
}
}
sFullLog = false;
}
/**
* Retrieve current operation state for all applications.
*
* The mode of the ops returned are set for the package but may not reflect their effective
* state due to UID policy or because it's controlled by a different global op.
*
* Use {@link #unsafeCheckOp(String, int, String)}} or
* {@link #noteOp(String, int, String, String, String)} if the effective mode is needed.
*
* @param ops The set of operations you are interested in, or null if you want all of them.
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS)
public @NonNull List<AppOpsManager.PackageOps> getPackagesForOps(@Nullable String[] ops) {
final int opCount = ops.length;
final int[] opCodes = new int[opCount];
for (int i = 0; i < opCount; i++) {
opCodes[i] = sOpStrToOp.get(ops[i]);
}
final List<AppOpsManager.PackageOps> result = getPackagesForOps(opCodes);
return (result != null) ? result : Collections.emptyList();
}
/**
* Retrieve current operation state for all applications.
*
* The mode of the ops returned are set for the package but may not reflect their effective
* state due to UID policy or because it's controlled by a different global op.
*
* Use {@link #unsafeCheckOp(String, int, String)}} or
* {@link #noteOp(String, int, String, String, String)} if the effective mode is needed.
*
* @param ops The set of operations you are interested in, or null if you want all of them.
* @hide
*/
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS)
@UnsupportedAppUsage
public List<AppOpsManager.PackageOps> getPackagesForOps(int[] ops) {
try {
return mService.getPackagesForOps(ops);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Retrieve current operation state for one application.
*
* The mode of the ops returned are set for the package but may not reflect their effective
* state due to UID policy or because it's controlled by a different global op.
*
* Use {@link #unsafeCheckOp(String, int, String)}} or
* {@link #noteOp(String, int, String, String, String)} if the effective mode is needed.
*
* @param uid The uid of the application of interest.
* @param packageName The name of the application of interest.
* @param ops The set of operations you are interested in, or null if you want all of them.
*
* @deprecated The int op codes are not stable and you should use the string based op
* names which are stable and namespaced. Use
* {@link #getOpsForPackage(int, String, String...)})}.
*
* @hide
* @removed
*/
@Deprecated
@SystemApi
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS)
public @NonNull List<PackageOps> getOpsForPackage(int uid, @NonNull String packageName,
@Nullable int[] ops) {
try {
return mService.getOpsForPackage(uid, packageName, ops);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Retrieve current operation state for one application. The UID and the
* package must match.
*
* The mode of the ops returned are set for the package but may not reflect their effective
* state due to UID policy or because it's controlled by a different global op.
*
* Use {@link #unsafeCheckOp(String, int, String)}} or
* {@link #noteOp(String, int, String, String, String)} if the effective mode is needed.
*
* @param uid The uid of the application of interest.
* @param packageName The name of the application of interest.
* @param ops The set of operations you are interested in, or null if you want all of them.
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS)
public @NonNull List<AppOpsManager.PackageOps> getOpsForPackage(int uid,
@NonNull String packageName, @Nullable String... ops) {
int[] opCodes = null;
if (ops != null) {
opCodes = new int[ops.length];
for (int i = 0; i < ops.length; i++) {
opCodes[i] = strOpToOp(ops[i]);
}
}
try {
final List<PackageOps> result = mService.getOpsForPackage(uid, packageName, opCodes);
if (result == null) {
return Collections.emptyList();
}
return result;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Retrieve historical app op stats for a period.
*
* @param request A request object describing the data being queried for.
* @param executor Executor on which to run the callback. If <code>null</code>
* the callback is executed on the default executor running on the main thread.
* @param callback Callback on which to deliver the result.
*
* @throws IllegalArgumentException If any of the argument contracts is violated.
*
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS)
public void getHistoricalOps(@NonNull HistoricalOpsRequest request,
@NonNull Executor executor, @NonNull Consumer<HistoricalOps> callback) {
Objects.requireNonNull(executor, "executor cannot be null");
Objects.requireNonNull(callback, "callback cannot be null");
try {
mService.getHistoricalOps(request.mUid, request.mPackageName, request.mAttributionTag,
request.mOpNames, request.mHistoryFlags, request.mFilter,
request.mBeginTimeMillis, request.mEndTimeMillis, request.mFlags,
new RemoteCallback((result) -> {
final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS);
final long identity = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.accept(ops));
} finally {
Binder.restoreCallingIdentity(identity);
}
}));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Retrieve historical app op stats for a period.
* <p>
* This method queries only the on disk state and the returned ops are raw,
* which is their times are relative to the history start as opposed to the
* epoch start.
*
* @param request A request object describing the data being queried for.
* @param executor Executor on which to run the callback. If <code>null</code>
* the callback is executed on the default executor running on the main thread.
* @param callback Callback on which to deliver the result.
*
* @throws IllegalArgumentException If any of the argument contracts is violated.
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void getHistoricalOpsFromDiskRaw(@NonNull HistoricalOpsRequest request,
@Nullable Executor executor, @NonNull Consumer<HistoricalOps> callback) {
Objects.requireNonNull(executor, "executor cannot be null");
Objects.requireNonNull(callback, "callback cannot be null");
try {
mService.getHistoricalOpsFromDiskRaw(request.mUid, request.mPackageName,
request.mAttributionTag, request.mOpNames, request.mHistoryFlags,
request.mFilter, request.mBeginTimeMillis, request.mEndTimeMillis,
request.mFlags, new RemoteCallback((result) -> {
final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS);
final long identity = Binder.clearCallingIdentity();
try {
executor.execute(() -> callback.accept(ops));
} finally {
Binder.restoreCallingIdentity(identity);
}
}));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Reloads the non historical state to allow testing the read/write path.
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void reloadNonHistoricalState() {
try {
mService.reloadNonHistoricalState();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Sets given app op in the specified mode for app ops in the UID.
* This applies to all apps currently in the UID or installed in
* this UID in the future.
*
* @param code The app op.
* @param uid The UID for which to set the app.
* @param mode The app op mode to set.
* @hide
*/
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
public void setUidMode(int code, int uid, @Mode int mode) {
try {
mService.setUidMode(code, uid, mode);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Sets given app op in the specified mode for app ops in the UID.
* This applies to all apps currently in the UID or installed in
* this UID in the future.
*
* @param appOp The app op.
* @param uid The UID for which to set the app.
* @param mode The app op mode to set.
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
public void setUidMode(@NonNull String appOp, int uid, @Mode int mode) {
try {
mService.setUidMode(AppOpsManager.strOpToOp(appOp), uid, mode);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
public void setUserRestriction(int code, boolean restricted, IBinder token) {
setUserRestriction(code, restricted, token, null);
}
/**
* An empty array of attribution tags means exclude all tags under that package.
* @hide
*/
public void setUserRestriction(int code, boolean restricted, IBinder token,
@Nullable PackageTagsList excludedPackageTags) {
setUserRestrictionForUser(code, restricted, token, excludedPackageTags,
mContext.getUserId());
}
/**
* An empty array of attribution tags means exclude all tags under that package.
* @hide
*/
public void setUserRestrictionForUser(int code, boolean restricted, IBinder token,
@Nullable PackageTagsList excludedPackageTags, int userId) {
try {
mService.setUserRestriction(code, restricted, token, userId, excludedPackageTags);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
@UnsupportedAppUsage
@TestApi
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
public void setMode(int code, int uid, String packageName, @Mode int mode) {
try {
mService.setMode(code, uid, packageName, mode);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Change the operating mode for the given op in the given app package. You must pass
* in both the uid and name of the application whose mode is being modified; if these
* do not match, the modification will not be applied.
*
* @param op The operation to modify. One of the OPSTR_* constants.
* @param uid The user id of the application whose mode will be changed.
* @param packageName The name of the application package name whose mode will
* be changed.
* @hide
*/
@SystemApi
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
public void setMode(@NonNull String op, int uid, @Nullable String packageName,
@Mode int mode) {
try {
mService.setMode(strOpToOp(op), uid, packageName, mode);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Set a non-persisted restriction on an audio operation at a stream-level.
* Restrictions are temporary additional constraints imposed on top of the persisted rules
* defined by {@link #setMode}.
*
* @param code The operation to restrict.
* @param usage The {@link android.media.AudioAttributes} usage value.
* @param mode The restriction mode (MODE_IGNORED,MODE_ERRORED) or MODE_ALLOWED to unrestrict.
* @param exceptionPackages Optional list of packages to exclude from the restriction.
* @hide
*/
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
@UnsupportedAppUsage
public void setRestriction(int code, @AttributeUsage int usage, @Mode int mode,
String[] exceptionPackages) {
try {
final int uid = Binder.getCallingUid();
mService.setAudioRestriction(code, usage, uid, mode, exceptionPackages);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
@RequiresPermission(android.Manifest.permission.MANAGE_APP_OPS_MODES)
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
public void resetAllModes() {
try {
mService.resetAllModes(mContext.getUserId(), null);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Gets the app-op name associated with a given permission.
*
* <p>The app-op name is one of the public constants defined
* in this class such as {@link #OPSTR_COARSE_LOCATION}.
* This API is intended to be used for mapping runtime
* permissions to the corresponding app-op.
*
* @param permission The permission.
* @return The app-op associated with the permission or {@code null}.
*/
public static @Nullable String permissionToOp(@NonNull String permission) {
final Integer opCode = sPermToOp.get(permission);
if (opCode == null) {
return null;
}
return sOpToString[opCode];
}
/**
* Resolves special UID's pakcages such as root, shell, media, etc.
*
* @param uid The uid to resolve.
* @param packageName Optional package. If caller system and null returns "android"
* @return The resolved package name.
*
* @hide
*/
public static @Nullable String resolvePackageName(int uid, @Nullable String packageName) {
if (uid == Process.ROOT_UID) {
return "root";
} else if (uid == Process.SHELL_UID) {
return "com.android.shell";
} else if (uid == Process.MEDIA_UID) {
return "media";
} else if (uid == Process.AUDIOSERVER_UID) {
return "audioserver";
} else if (uid == Process.CAMERASERVER_UID) {
return "cameraserver";
} else if (uid == Process.SYSTEM_UID && packageName == null) {
return "android";
}
return packageName;
}
/**
* Monitor for changes to the operating mode for the given op in the given app package.
* You can watch op changes only for your UID.
*
* @param op The operation to monitor, one of OPSTR_*.
* @param packageName The name of the application to monitor.
* @param callback Where to report changes.
*/
public void startWatchingMode(@NonNull String op, @Nullable String packageName,
@NonNull final OnOpChangedListener callback) {
startWatchingMode(strOpToOp(op), packageName, callback);
}
/**
* Monitor for changes to the operating mode for the given op in the given app package.
* You can watch op changes only for your UID.
*
* @param op The operation to monitor, one of OPSTR_*.
* @param packageName The name of the application to monitor.
* @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0.
* @param callback Where to report changes.
*/
public void startWatchingMode(@NonNull String op, @Nullable String packageName, int flags,
@NonNull final OnOpChangedListener callback) {
startWatchingMode(strOpToOp(op), packageName, flags, callback);
}
/**
* Monitor for changes to the operating mode for the given op in the given app package.
*
* <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
* you can watch changes only for your UID.
*
* @param op The operation to monitor, one of OP_*.
* @param packageName The name of the application to monitor.
* @param callback Where to report changes.
* @hide
*/
@RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true)
public void startWatchingMode(int op, String packageName, final OnOpChangedListener callback) {
startWatchingMode(op, packageName, 0, callback);
}
/**
* Monitor for changes to the operating mode for the given op in the given app package.
*
* <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
* you can watch changes only for your UID.
*
* @param op The operation to monitor, one of OP_*.
* @param packageName The name of the application to monitor.
* @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0.
* @param callback Where to report changes.
* @hide
*/
@RequiresPermission(value=android.Manifest.permission.WATCH_APPOPS, conditional=true)
public void startWatchingMode(int op, String packageName, int flags,
final OnOpChangedListener callback) {
synchronized (mModeWatchers) {
IAppOpsCallback cb = mModeWatchers.get(callback);
if (cb == null) {
cb = new IAppOpsCallback.Stub() {
public void opChanged(int op, int uid, String packageName) {
if (callback instanceof OnOpChangedInternalListener) {
((OnOpChangedInternalListener)callback).onOpChanged(op, packageName);
}
if (sOpToString[op] != null) {
callback.onOpChanged(sOpToString[op], packageName);
}
}
};
mModeWatchers.put(callback, cb);
}
// See CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE
if (!Compatibility.isChangeEnabled(
CALL_BACK_ON_CHANGED_LISTENER_WITH_SWITCHED_OP_CHANGE)) {
flags |= CALL_BACK_ON_SWITCHED_OP;
}
try {
mService.startWatchingModeWithFlags(op, packageName, flags, cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
/**
* Stop monitoring that was previously started with {@link #startWatchingMode}. All
* monitoring associated with this callback will be removed.
*/
public void stopWatchingMode(@NonNull OnOpChangedListener callback) {
synchronized (mModeWatchers) {
IAppOpsCallback cb = mModeWatchers.remove(callback);
if (cb != null) {
try {
mService.stopWatchingMode(cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
}
/** {@hide} */
@Deprecated
public void startWatchingActive(@NonNull int[] ops,
@NonNull OnOpActiveChangedListener callback) {
final String[] strOps = new String[ops.length];
for (int i = 0; i < ops.length; i++) {
strOps[i] = opToPublicName(ops[i]);
}
startWatchingActive(strOps, mContext.getMainExecutor(), callback);
}
/**
* Start watching for changes to the active state of app-ops. An app-op may be
* long running and it has a clear start and stop delimiters. If an op is being
* started or stopped by any package you will get a callback. To change the
* watched ops for a registered callback you need to unregister and register it
* again.
*
* <p> If you don't hold the {@code android.Manifest.permission#WATCH_APPOPS} permission
* you can watch changes only for your UID.
*
* @param ops The operations to watch.
* @param callback Where to report changes.
*
* @see #stopWatchingActive
*/
// TODO: Uncomment below annotation once b/73559440 is fixed
// @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
public void startWatchingActive(@NonNull String[] ops,
@CallbackExecutor @NonNull Executor executor,
@NonNull OnOpActiveChangedListener callback) {
Objects.requireNonNull(ops);
Objects.requireNonNull(executor);
Objects.requireNonNull(callback);
IAppOpsActiveCallback cb;
synchronized (mActiveWatchers) {
cb = mActiveWatchers.get(callback);
if (cb != null) {
return;
}
cb = new IAppOpsActiveCallback.Stub() {
@Override
public void opActiveChanged(int op, int uid, String packageName,
String attributionTag, boolean active, @AttributionFlags
int attributionFlags, int attributionChainId) {
executor.execute(() -> {
if (callback instanceof OnOpActiveChangedInternalListener) {
((OnOpActiveChangedInternalListener) callback).onOpActiveChanged(op,
uid, packageName, active);
}
if (sOpToString[op] != null) {
callback.onOpActiveChanged(sOpToString[op], uid, packageName,
attributionTag, active, attributionFlags, attributionChainId);
}
});
}
};
mActiveWatchers.put(callback, cb);
}
final int[] rawOps = new int[ops.length];
for (int i = 0; i < ops.length; i++) {
rawOps[i] = strOpToOp(ops[i]);
}
try {
mService.startWatchingActive(rawOps, cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Stop watching for changes to the active state of an app-op. An app-op may be
* long running and it has a clear start and stop delimiters. Unregistering a
* non-registered callback has no effect.
*
* @see #startWatchingActive
*/
public void stopWatchingActive(@NonNull OnOpActiveChangedListener callback) {
synchronized (mActiveWatchers) {
final IAppOpsActiveCallback cb = mActiveWatchers.remove(callback);
if (cb != null) {
try {
mService.stopWatchingActive(cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
}
/**
* Start watching for started app-ops.
* An app-op may be long running and it has a clear start delimiter.
* If an op start is attempted by any package, you will get a callback.
* To change the watched ops for a registered callback you need to unregister and register it
* again.
*
* <p> If you don't hold the {@code android.Manifest.permission#WATCH_APPOPS} permission
* you can watch changes only for your UID.
*
* @param ops The operations to watch.
* @param callback Where to report changes.
*
* @see #stopWatchingStarted(OnOpStartedListener)
* @see #startWatchingActive(int[], OnOpActiveChangedListener)
* @see #startWatchingNoted(int[], OnOpNotedListener)
* @see #startOp(int, int, String, boolean, String, String)
* @see #finishOp(int, int, String, String)
*
* @hide
*/
@RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
public void startWatchingStarted(@NonNull int[] ops, @NonNull OnOpStartedListener callback) {
IAppOpsStartedCallback cb;
synchronized (mStartedWatchers) {
if (mStartedWatchers.containsKey(callback)) {
return;
}
cb = new IAppOpsStartedCallback.Stub() {
@Override
public void opStarted(int op, int uid, String packageName, String attributionTag,
int flags, int mode, int startType, int attributionFlags,
int attributionChainId) {
callback.onOpStarted(op, uid, packageName, attributionTag, flags, mode,
startType, attributionFlags, attributionChainId);
}
};
mStartedWatchers.put(callback, cb);
}
try {
mService.startWatchingStarted(ops, cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Stop watching for started app-ops.
* An app-op may be long running and it has a clear start delimiter.
* Henceforth, if an op start is attempted by any package, you will not get a callback.
* Unregistering a non-registered callback has no effect.
*
* @see #startWatchingStarted(int[], OnOpStartedListener)
* @see #startOp(int, int, String, boolean, String, String)
*
* @hide
*/
public void stopWatchingStarted(@NonNull OnOpStartedListener callback) {
synchronized (mStartedWatchers) {
final IAppOpsStartedCallback cb = mStartedWatchers.remove(callback);
if (cb != null) {
try {
mService.stopWatchingStarted(cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
}
/**
* Start watching for noted app ops. An app op may be immediate or long running.
* Immediate ops are noted while long running ones are started and stopped. This
* method allows registering a listener to be notified when an app op is noted. If
* an op is being noted by any package you will get a callback. To change the
* watched ops for a registered callback you need to unregister and register it again.
*
* <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
* you can watch changes only for your UID.
*
* @param ops The ops to watch.
* @param callback Where to report changes.
*
* @see #startWatchingActive(int[], OnOpActiveChangedListener)
* @see #startWatchingStarted(int[], OnOpStartedListener)
* @see #stopWatchingNoted(OnOpNotedListener)
* @see #noteOp(String, int, String, String, String)
*
* @hide
*/
@RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
public void startWatchingNoted(@NonNull int[] ops, @NonNull OnOpNotedListener callback) {
IAppOpsNotedCallback cb;
synchronized (mNotedWatchers) {
cb = mNotedWatchers.get(callback);
if (cb != null) {
return;
}
cb = new IAppOpsNotedCallback.Stub() {
@Override
public void opNoted(int op, int uid, String packageName, String attributionTag,
int flags, int mode) {
callback.onOpNoted(op, uid, packageName, attributionTag, flags, mode);
}
};
mNotedWatchers.put(callback, cb);
}
try {
mService.startWatchingNoted(ops, cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Stop watching for noted app ops. An app op may be immediate or long running.
* Unregistering a non-registered callback has no effect.
*
* @see #startWatchingNoted(int[], OnOpNotedListener)
* @see #noteOp(String, int, String, String, String)
*
* @hide
*/
public void stopWatchingNoted(@NonNull OnOpNotedListener callback) {
synchronized (mNotedWatchers) {
final IAppOpsNotedCallback cb = mNotedWatchers.remove(callback);
if (cb != null) {
try {
mService.stopWatchingNoted(cb);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
}
}
private String buildSecurityExceptionMsg(int op, int uid, String packageName) {
return packageName + " from uid " + uid + " not allowed to perform " + sOpNames[op];
}
/**
* {@hide}
*/
@UnsupportedAppUsage
@TestApi
public static int strOpToOp(@NonNull String op) {
Integer val = sOpStrToOp.get(op);
if (val == null) {
throw new IllegalArgumentException("Unknown operation string: " + op);
}
return val;
}
/**
* Do a quick check for whether an application might be able to perform an operation.
* This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String,
* String, String)} or {@link #startOp(String, int, String, String, String)} for your actual
* security checks, which also ensure that the given uid and package name are consistent. This
* function can just be used for a quick check to see if an operation has been disabled for the
* application, as an early reject of some work. This does not modify the time stamp or other
* data about the operation.
*
* <p>Important things this will not do (which you need to ultimate use
* {@link #noteOp(String, int, String, String, String)} or
* {@link #startOp(String, int, String, String, String)} to cover):</p>
* <ul>
* <li>Verifying the uid and package are consistent, so callers can't spoof
* their identity.</li>
* <li>Taking into account the current foreground/background state of the
* app; apps whose mode varies by this state will always be reported
* as {@link #MODE_ALLOWED}.</li>
* </ul>
*
* @param op The operation to check. One of the OPSTR_* constants.
* @param uid The user id of the application attempting to perform the operation.
* @param packageName The name of the application attempting to perform the operation.
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
* {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
* causing the app to crash).
* @throws SecurityException If the app has been configured to crash on this op.
*/
public int unsafeCheckOp(@NonNull String op, int uid, @NonNull String packageName) {
return checkOp(strOpToOp(op), uid, packageName);
}
/**
* @deprecated Renamed to {@link #unsafeCheckOp(String, int, String)}.
*/
@Deprecated
public int checkOp(@NonNull String op, int uid, @NonNull String packageName) {
return checkOp(strOpToOp(op), uid, packageName);
}
/**
* Like {@link #checkOp} but instead of throwing a {@link SecurityException} it
* returns {@link #MODE_ERRORED}.
*/
public int unsafeCheckOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
return checkOpNoThrow(strOpToOp(op), uid, packageName);
}
/**
* @deprecated Renamed to {@link #unsafeCheckOpNoThrow(String, int, String)}.
*/
@Deprecated
public int checkOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
return checkOpNoThrow(strOpToOp(op), uid, packageName);
}
/**
* Like {@link #checkOp} but returns the <em>raw</em> mode associated with the op.
* Does not throw a security exception, does not translate {@link #MODE_FOREGROUND}.
*/
public int unsafeCheckOpRaw(@NonNull String op, int uid, @NonNull String packageName) {
return unsafeCheckOpRawNoThrow(op, uid, packageName);
}
/**
* Like {@link #unsafeCheckOpNoThrow(String, int, String)} but returns the <em>raw</em>
* mode associated with the op. Does not throw a security exception, does not translate
* {@link #MODE_FOREGROUND}.
*/
public int unsafeCheckOpRawNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
return unsafeCheckOpRawNoThrow(strOpToOp(op), uid, packageName);
}
/**
* Returns the <em>raw</em> mode associated with the op.
* Does not throw a security exception, does not translate {@link #MODE_FOREGROUND}.
* @hide
*/
public int unsafeCheckOpRawNoThrow(int op, int uid, @NonNull String packageName) {
try {
return mService.checkOperationRaw(op, uid, packageName, null);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* @deprecated Use {@link #noteOp(String, int, String, String, String)} instead
*/
@Deprecated
public int noteOp(@NonNull String op, int uid, @NonNull String packageName) {
return noteOp(op, uid, packageName, null, null);
}
/**
* @deprecated Use {@link #noteOp(String, int, String, String, String)} instead
*
* @hide
*/
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link "
+ "#noteOp(java.lang.String, int, java.lang.String, java.lang.String, "
+ "java.lang.String)} instead")
@Deprecated
public int noteOp(int op) {
return noteOp(op, Process.myUid(), mContext.getOpPackageName(), null, null);
}
/**
* @deprecated Use {@link #noteOp(String, int, String, String, String)} instead
*
* @hide
*/
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link "
+ "#noteOp(java.lang.String, int, java.lang.String, java.lang.String, "
+ "java.lang.String)} instead")
public int noteOp(int op, int uid, @Nullable String packageName) {
return noteOp(op, uid, packageName, null, null);
}
/**
* Make note of an application performing an operation and check if the application is allowed
* to perform it.
*
* <p>If this is a check that is not preceding the protected operation, use
* {@link #unsafeCheckOp} instead.
*
* <p>The identity of the package the app-op is noted for is specified by the
* {@code uid} and {@code packageName} parameters. If this is noted for a regular app both
* should be set and the package needs to be part of the uid. In the very rare case that an
* app-op is noted for an entity that does not have a package name, the package can be
* {@code null}. As it is possible that a single process contains more than one package the
* {@code packageName} should be {@link Context#getPackageName() read} from the context of the
* caller of the API (in the app process) that eventually triggers this check. If this op is
* not noted for a running process the {@code packageName} cannot be read from the context, but
* it should be clear which package the note is for.
*
* <p>If the {@code uid} and {@code packageName} do not match this return
* {@link #MODE_IGNORED}.
*
* <p>Beside the access check this method also records the access. While the access check is
* based on {@code uid} and/or {@code packageName} the access recording is done based on the
* {@code packageName} and {@code attributionTag}. The {@code attributionTag} should be
* {@link Context#getAttributionTag() read} from the same context the package name is read from.
* In the case the check is not related to an API call, the {@code attributionTag} should be
* {@code null}. Please note that e.g. registering a callback for later is still an API call and
* the code should store the attribution tag along the package name for being used in this
* method later.
*
* <p>The {@code message} parameter only needs to be set when this method is <ul>not</ul>
* called in a two-way binder call from the client. In this case the message is a free form text
* that is meant help the app developer determine what part of the app's code triggered the
* note. This message is passed back to the app in the
* {@link OnOpNotedCallback#onAsyncNoted(AsyncNotedAppOp)} callback. A good example of a useful
* message is including the {@link System#identityHashCode(Object)} of the listener that will
* receive data or the name of the manifest-receiver.
*
* @param op The operation to note. One of the OPSTR_* constants.
* @param uid The uid of the application attempting to perform the operation.
* @param packageName The name of the application attempting to perform the operation.
* @param attributionTag The {@link Context#createAttributionContext attribution tag} of the
* calling context or {@code null} for default attribution
* @param message A message describing why the op was noted
*
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
* {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
* causing the app to crash).
*
* @throws SecurityException If the app has been configured to crash on this op.
*/
// For platform callers of this method, please read the package name parameter from
// Context#getOpPackageName.
// When noting a callback, the message can be computed using the #toReceiverId method.
public int noteOp(@NonNull String op, int uid, @Nullable String packageName,
@Nullable String attributionTag, @Nullable String message) {
return noteOp(strOpToOp(op), uid, packageName, attributionTag, message);
}
/**
* @see #noteOp(String, int, String, String, String
*
* @hide
*/
public int noteOp(int op, int uid, @Nullable String packageName,
@Nullable String attributionTag, @Nullable String message) {
final int mode = noteOpNoThrow(op, uid, packageName, attributionTag, message);
if (mode == MODE_ERRORED) {
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
}
return mode;
}
/**
* @deprecated Use {@link #noteOpNoThrow(String, int, String, String, String)} instead
*/
@Deprecated
public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
return noteOpNoThrow(op, uid, packageName, null, null);
}
/**
* @deprecated Use {@link #noteOpNoThrow(int, int, String, String, String)} instead
*
* @hide
*/
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link "
+ "#noteOpNoThrow(java.lang.String, int, java.lang.String, java.lang.String, "
+ "java.lang.String)} instead")
public int noteOpNoThrow(int op, int uid, String packageName) {
return noteOpNoThrow(op, uid, packageName, null, null);
}
/**
* Like {@link #noteOp(String, int, String, String, String)} but instead of throwing a
* {@link SecurityException} it returns {@link #MODE_ERRORED}.
*
* @see #noteOp(String, int, String, String, String)
*/
public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName,
@Nullable String attributionTag, @Nullable String message) {
return noteOpNoThrow(strOpToOp(op), uid, packageName, attributionTag, message);
}
/**
* @see #noteOpNoThrow(String, int, String, String, String)
*
* @hide
*/
public int noteOpNoThrow(int op, int uid, @Nullable String packageName,
@Nullable String attributionTag, @Nullable String message) {
try {
collectNoteOpCallsForValidation(op);
int collectionMode = getNotedOpCollectionMode(uid, packageName, op);
boolean shouldCollectMessage = Process.myUid() == Process.SYSTEM_UID;
if (collectionMode == COLLECT_ASYNC) {
if (message == null) {
// Set stack trace as default message
message = getFormattedStackTrace();
shouldCollectMessage = true;
}
}
SyncNotedAppOp syncOp = mService.noteOperation(op, uid, packageName, attributionTag,
collectionMode == COLLECT_ASYNC, message, shouldCollectMessage);
if (syncOp.getOpMode() == MODE_ALLOWED) {
if (collectionMode == COLLECT_SELF) {
collectNotedOpForSelf(syncOp);
} else if (collectionMode == COLLECT_SYNC) {
collectNotedOpSync(syncOp);
}
}
return syncOp.getOpMode();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* @deprecated Use {@link #noteProxyOp(String, String, int, String, String)} instead
*/
@Deprecated
public int noteProxyOp(@NonNull String op, @NonNull String proxiedPackageName) {
return noteProxyOp(op, proxiedPackageName, Binder.getCallingUid(), null, null);
}
/**
* @deprecated Use {@link #noteProxyOp(String, String, int, String, String)} instead
*
* @hide
*/
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link "
+ "#noteProxyOp(java.lang.String, java.lang.String, int, java.lang.String, "
+ "java.lang.String)} instead")
public int noteProxyOp(int op, @Nullable String proxiedPackageName) {
return noteProxyOp(op, proxiedPackageName, Binder.getCallingUid(), null, null);
}
/**
* @see #noteProxyOp(String, String, int, String, String)
*
* @hide
*/
public int noteProxyOp(int op, @Nullable String proxiedPackageName, int proxiedUid,
@Nullable String proxiedAttributionTag, @Nullable String message) {
return noteProxyOp(op, new AttributionSource(mContext.getAttributionSource(),
new AttributionSource(proxiedUid, proxiedPackageName, proxiedAttributionTag,
mContext.getAttributionSource().getToken())), message,
/*skipProxyOperation*/ false);
}
/**
* Make note of an application performing an operation on behalf of another application when
* handling an IPC. This function will verify that the calling uid and proxied package name
* match, and if not, return {@link #MODE_IGNORED}. If this call succeeds, the last execution
* time of the operation for the proxied app and your app will be updated to the current time.
*
* @param op The operation to note. One of the OPSTR_* constants.
* @param proxiedPackageName The name of the application calling into the proxy application.
* @param proxiedUid The uid of the proxied application
* @param proxiedAttributionTag The proxied {@link Context#createAttributionContext
* attribution tag} or {@code null} for default attribution
* @param message A message describing the reason the op was noted
*
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED}
* if it is not allowed and should be silently ignored (without causing the app to crash).
*
* @throws SecurityException If the proxy or proxied app has been configured to crash on this
* op.
*/
public int noteProxyOp(@NonNull String op, @Nullable String proxiedPackageName, int proxiedUid,
@Nullable String proxiedAttributionTag, @Nullable String message) {
return noteProxyOp(strOpToOp(op), proxiedPackageName, proxiedUid, proxiedAttributionTag,
message);
}
/**
* Make note of an application performing an operation on behalf of another application(s).
*
* @param op The operation to note. One of the OPSTR_* constants.
* @param attributionSource The permission identity for which to note.
* @param message A message describing the reason the op was noted
* @param skipProxyOperation Whether to skip the proxy note.
*
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED}
* if it is not allowed and should be silently ignored (without causing the app to crash).
*
* @throws SecurityException If the any proxying operations in the permission identityf
* chain fails.
*
* @hide
*/
public int noteProxyOp(@NonNull int op, @NonNull AttributionSource attributionSource,
@Nullable String message, boolean skipProxyOperation) {
final int mode = noteProxyOpNoThrow(op, attributionSource, message, skipProxyOperation);
if (mode == MODE_ERRORED) {
throw new SecurityException("Proxy package "
+ attributionSource.getPackageName() + " from uid "
+ attributionSource.getUid() + " or calling package "
+ attributionSource.getNextPackageName() + " from uid "
+ attributionSource.getNextUid() + " not allowed to perform "
+ sOpNames[op]);
}
return mode;
}
/**
* @deprecated Use {@link #noteProxyOpNoThrow(String, String, int, String, String)} instead
*/
@Deprecated
public int noteProxyOpNoThrow(@NonNull String op, @NonNull String proxiedPackageName) {
return noteProxyOpNoThrow(op, proxiedPackageName, Binder.getCallingUid(), null, null);
}
/**
* @deprecated Use {@link #noteProxyOpNoThrow(String, String, int, String, String)} instead
*/
@Deprecated
public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName,
int proxiedUid) {
return noteProxyOpNoThrow(op, proxiedPackageName, proxiedUid, null, null);
}
/**
* Like {@link #noteProxyOp(String, String, int, String, String)} but instead
* of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}.
*
* @see #noteOpNoThrow(String, int, String, String, String)
*/
public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName,
int proxiedUid, @Nullable String proxiedAttributionTag, @Nullable String message) {
return noteProxyOpNoThrow(strOpToOp(op), new AttributionSource(
mContext.getAttributionSource(), new AttributionSource(proxiedUid,
proxiedPackageName, proxiedAttributionTag, mContext.getAttributionSource()
.getToken())), message,/*skipProxyOperation*/ false);
}
/**
* Make note of an application performing an operation on behalf of another application(s).
*
* @param op The operation to note. One of the OPSTR_* constants.
* @param attributionSource The permission identity for which to note.
* @param message A message describing the reason the op was noted
* @param skipProxyOperation Whether to note op for the proxy
*
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED}
* if it is not allowed and should be silently ignored (without causing the app to crash).
*
* @hide
*/
@SuppressWarnings("AndroidFrameworkClientSidePermissionCheck")
public int noteProxyOpNoThrow(int op, @NonNull AttributionSource attributionSource,
@Nullable String message, boolean skipProxyOperation) {
int myUid = Process.myUid();
try {
collectNoteOpCallsForValidation(op);
int collectionMode = getNotedOpCollectionMode(
attributionSource.getNextUid(),
attributionSource.getNextAttributionTag(), op);
boolean shouldCollectMessage = (myUid == Process.SYSTEM_UID);
if (collectionMode == COLLECT_ASYNC) {
if (message == null) {
// Set stack trace as default message
message = getFormattedStackTrace();
shouldCollectMessage = true;
}
}
SyncNotedAppOp syncOp = mService.noteProxyOperation(op, attributionSource,
collectionMode == COLLECT_ASYNC, message,
shouldCollectMessage, skipProxyOperation);
if (syncOp.getOpMode() == MODE_ALLOWED) {
if (collectionMode == COLLECT_SELF) {
collectNotedOpForSelf(syncOp);
} else if (collectionMode == COLLECT_SYNC
// Only collect app-ops when the proxy is trusted
&& (mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1,
myUid) == PackageManager.PERMISSION_GRANTED ||
Binder.getCallingUid() == attributionSource.getNextUid())) {
collectNotedOpSync(syncOp);
}
}
return syncOp.getOpMode();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
private static String getComponentPackageNameFromString(String from) {
ComponentName componentName = from != null ? ComponentName.unflattenFromString(from) : null;
return componentName != null ? componentName.getPackageName() : "";
}
private static boolean isPackagePreInstalled(Context context, String packageName, int userId) {
try {
final PackageManager pm = context.getPackageManager();
final ApplicationInfo info =
pm.getApplicationInfoAsUser(packageName, 0, userId);
return ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
/**
* Do a quick check for whether an application might be able to perform an operation.
* This is <em>not</em> a security check; you must use {@link #noteOp(String, int, String,
* String, String)} or {@link #startOp(int, int, String, boolean, String, String)} for your
* actual security checks, which also ensure that the given uid and package name are consistent.
* This function can just be used for a quick check to see if an operation has been disabled for
* the application, as an early reject of some work. This does not modify the time stamp or
* other data about the operation.
*
* <p>Important things this will not do (which you need to ultimate use
* {@link #noteOp(String, int, String, String, String)} or
* {@link #startOp(int, int, String, boolean, String, String)} to cover):</p>
* <ul>
* <li>Verifying the uid and package are consistent, so callers can't spoof
* their identity.</li>
* <li>Taking into account the current foreground/background state of the
* app; apps whose mode varies by this state will always be reported
* as {@link #MODE_ALLOWED}.</li>
* </ul>
*
* @param op The operation to check. One of the OP_* constants.
* @param uid The user id of the application attempting to perform the operation.
* @param packageName The name of the application attempting to perform the operation.
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
* {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
* causing the app to crash).
* @throws SecurityException If the app has been configured to crash on this op.
* @hide
*/
@UnsupportedAppUsage
public int checkOp(int op, int uid, String packageName) {
try {
int mode = mService.checkOperation(op, uid, packageName);
if (mode == MODE_ERRORED) {
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
}
return mode;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Like {@link #checkOp} but instead of throwing a {@link SecurityException} it
* returns {@link #MODE_ERRORED}.
*
* @see #checkOp(int, int, String)
*
* @hide
*/
@UnsupportedAppUsage
public int checkOpNoThrow(int op, int uid, String packageName) {
try {
int mode = mService.checkOperation(op, uid, packageName);
return mode == AppOpsManager.MODE_FOREGROUND ? AppOpsManager.MODE_ALLOWED : mode;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* @deprecated Use {@link PackageManager#getPackageUid} instead
*/
@Deprecated
public void checkPackage(int uid, @NonNull String packageName) {
try {
if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) {
throw new SecurityException(
"Package " + packageName + " does not belong to " + uid);
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Like {@link #checkOp} but at a stream-level for audio operations.
* @hide
*/
public int checkAudioOp(int op, int stream, int uid, String packageName) {
try {
final int mode = mService.checkAudioOperation(op, stream, uid, packageName);
if (mode == MODE_ERRORED) {
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
}
return mode;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Like {@link #checkAudioOp} but instead of throwing a {@link SecurityException} it
* returns {@link #MODE_ERRORED}.
* @hide
*/
public int checkAudioOpNoThrow(int op, int stream, int uid, String packageName) {
try {
return mService.checkAudioOperation(op, stream, uid, packageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* @deprecated Use own local {@link android.os.Binder#Binder()}
*
* @hide
*/
@Deprecated
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Create own "
+ "local {@link android.os.Binder}")
public static IBinder getToken(IAppOpsService service) {
return getClientId();
}
/** @hide */
public static IBinder getClientId() {
synchronized (AppOpsManager.class) {
if (sClientId == null) {
sClientId = new Binder();
}
return sClientId;
}
}
/** @hide */
private static IAppOpsService getService() {
synchronized (sLock) {
if (sService == null) {
sService = IAppOpsService.Stub.asInterface(
ServiceManager.getService(Context.APP_OPS_SERVICE));
}
return sService;
}
}
/**
* @deprecated use {@link #startOp(String, int, String, String, String)} instead
*/
@Deprecated
public int startOp(@NonNull String op, int uid, @NonNull String packageName) {
return startOp(op, uid, packageName, null, null);
}
/**
* @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead
*
* @hide
*/
@Deprecated
public int startOp(int op) {
return startOp(op, Process.myUid(), mContext.getOpPackageName(), false, null, null);
}
/**
* @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead
*
* @hide
*/
@Deprecated
public int startOp(int op, int uid, String packageName) {
return startOp(op, uid, packageName, false, null, null);
}
/**
* @deprecated Use {@link #startOp(int, int, String, boolean, String, String)} instead
*
* @hide
*/
@Deprecated
public int startOp(int op, int uid, String packageName, boolean startIfModeDefault) {
return startOp(op, uid, packageName, startIfModeDefault, null, null);
}
/**
* Report that an application has started executing a long-running operation.
*
* <p>For more details how to determine the {@code callingPackageName},
* {@code callingAttributionTag}, and {@code message}, please check the description in
* {@link #noteOp(String, int, String, String, String)}
*
* @param op The operation to start. One of the OPSTR_* constants.
* @param uid The user id of the application attempting to perform the operation.
* @param packageName The name of the application attempting to perform the operation.
* @param attributionTag The {@link Context#createAttributionContext attribution tag} or
* {@code null} for default attribution
* @param message Description why op was started
*
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
* {@link #MODE_IGNORED} if it is not allowed and should be silently ignored (without
* causing the app to crash).
*
* @throws SecurityException If the app has been configured to crash on this op or
* the package is not in the passed in UID.
*/
public int startOp(@NonNull String op, int uid, @Nullable String packageName,
@Nullable String attributionTag, @Nullable String message) {
return startOp(strOpToOp(op), uid, packageName, false, attributionTag, message);
}
/**
* @see #startOp(String, int, String, String, String)
*
* @hide
*/
public int startOp(int op, int uid, @Nullable String packageName, boolean startIfModeDefault,
@Nullable String attributionTag, @Nullable String message) {
final int mode = startOpNoThrow(op, uid, packageName, startIfModeDefault, attributionTag,
message);
if (mode == MODE_ERRORED) {
throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
}
return mode;
}
/**
* @deprecated use {@link #startOpNoThrow(String, int, String, String, String)} instead
*/
@Deprecated
public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
return startOpNoThrow(op, uid, packageName, null, null);
}
/**
* @deprecated Use {@link #startOpNoThrow(int, int, String, boolean, String, String} instead
*
* @hide
*/
@Deprecated
public int startOpNoThrow(int op, int uid, String packageName) {
return startOpNoThrow(op, uid, packageName, false, null, null);
}
/**
* @deprecated Use {@link #startOpNoThrow(int, int, String, boolean, String, String} instead
*
* @hide
*/
@Deprecated
public int startOpNoThrow(int op, int uid, String packageName, boolean startIfModeDefault) {
return startOpNoThrow(op, uid, packageName, startIfModeDefault, null, null);
}
/**
* Like {@link #startOp(String, int, String, String, String)} but instead of throwing a
* {@link SecurityException} it returns {@link #MODE_ERRORED}.
*
* @see #startOp(String, int, String, String, String)
*/
public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName,
@NonNull String attributionTag, @Nullable String message) {
return startOpNoThrow(strOpToOp(op), uid, packageName, false, attributionTag, message);
}
/**
* @see #startOpNoThrow(String, int, String, String, String)
*
* @hide
*/
public int startOpNoThrow(int op, int uid, @NonNull String packageName,
boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message) {
return startOpNoThrow(mContext.getAttributionSource().getToken(), op, uid, packageName,
startIfModeDefault, attributionTag, message);
}
/**
* @see #startOpNoThrow(String, int, String, String, String)
*
* @hide
*/
public int startOpNoThrow(@NonNull IBinder token, int op, int uid, @NonNull String packageName,
boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message) {
return startOpNoThrow(token, op, uid, packageName, startIfModeDefault, attributionTag,
message, ATTRIBUTION_FLAGS_NONE, ATTRIBUTION_CHAIN_ID_NONE);
}
/**
* @see #startOpNoThrow(String, int, String, String, String)
*
* @hide
*/
public int startOpNoThrow(@NonNull IBinder token, int op, int uid, @NonNull String packageName,
boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message,
@AttributionFlags int attributionFlags, int attributionChainId) {
try {
collectNoteOpCallsForValidation(op);
int collectionMode = getNotedOpCollectionMode(uid, packageName, op);
boolean shouldCollectMessage = Process.myUid() == Process.SYSTEM_UID;
if (collectionMode == COLLECT_ASYNC) {
if (message == null) {
// Set stack trace as default message
message = getFormattedStackTrace();
shouldCollectMessage = true;
}
}
SyncNotedAppOp syncOp = mService.startOperation(token, op, uid, packageName,
attributionTag, startIfModeDefault, collectionMode == COLLECT_ASYNC, message,
shouldCollectMessage, attributionFlags, attributionChainId);
if (syncOp.getOpMode() == MODE_ALLOWED) {
if (collectionMode == COLLECT_SELF) {
collectNotedOpForSelf(syncOp);
} else if (collectionMode == COLLECT_SYNC) {
collectNotedOpSync(syncOp);
}
}
return syncOp.getOpMode();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Report that an application has started executing a long-running operation on behalf of
* another application when handling an IPC. This function will verify that the calling uid and
* proxied package name match, and if not, return {@link #MODE_IGNORED}.
*
* @param op The op to note
* @param proxiedUid The uid to note the op for {@code null}
* @param proxiedPackageName The package name the uid belongs to
* @param proxiedAttributionTag The proxied {@link Context#createAttributionContext
* attribution tag} or {@code null} for default attribution
* @param message A message describing the reason the op was noted
*
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED}
* if it is not allowed and should be silently ignored (without causing the app to crash).
*
* @throws SecurityException If the proxy or proxied app has been configured to crash on this
* op.
*/
public int startProxyOp(@NonNull String op, int proxiedUid, @NonNull String proxiedPackageName,
@Nullable String proxiedAttributionTag, @Nullable String message) {
return startProxyOp(op, new AttributionSource(mContext.getAttributionSource(),
new AttributionSource(proxiedUid, proxiedPackageName, proxiedAttributionTag,
mContext.getAttributionSource().getToken())), message,
/*skipProxyOperation*/ false);
}
/**
* Report that an application has started executing a long-running operation on behalf of
* another application for the attribution chain specified by the {@link AttributionSource}}.
*
* @param op The op to note
* @param attributionSource The permission identity for which to check
* @param message A message describing the reason the op was noted
* @param skipProxyOperation Whether to skip the proxy start.
*
* @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED}
* if it is not allowed and should be silently ignored (without causing the app to crash).
*
* @throws SecurityException If the any proxying operations in the permission identity
* chain fails.
*
* @hide
*/
public int startProxyOp(@NonNull String op, @NonNull AttributionSource attributionSource,
@Nullable String message, boolean skipProxyOperation) {
final int mode = startProxyOpNoThrow(AppOpsManager.strOpToOp(op), attributionSource,
message, skipProxyOperation);
if (mode == MODE_ERRORED) {
throw new SecurityException("Proxy package "
+ attributionSource.getPackageName() + " from uid "
+ attributionSource.getUid() + " or calling package "
+ attributionSource.getNextPackageName() + " from uid "
+ attributionSource.getNextUid() + " not allowed to perform "
+ op);
}
return mode;
}
/**
* Like {@link #startProxyOp(String, int, String, String, String)} but instead
* of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED}.
*
* @see #startProxyOp(String, int, String, String, String)
*/
public int startProxyOpNoThrow(@NonNull String op, int proxiedUid,
@NonNull String proxiedPackageName, @Nullable String proxiedAttributionTag,
@Nullable String message) {
return startProxyOpNoThrow(AppOpsManager.strOpToOp(op), new AttributionSource(
mContext.getAttributionSource(), new AttributionSource(proxiedUid,
proxiedPackageName, proxiedAttributionTag,
mContext.getAttributionSource().getToken())), message,
/*skipProxyOperation*/ false);
}
/**
* Like {@link #startProxyOp(String, AttributionSource, String)} but instead
* of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED} and
* the checks is for the attribution chain specified by the {@link AttributionSource}.
*
* @see #startProxyOp(String, AttributionSource, String)
*
* @hide
*/
public int startProxyOpNoThrow(int op, @NonNull AttributionSource attributionSource,
@Nullable String message, boolean skipProxyOperation) {
return startProxyOpNoThrow(attributionSource.getToken(), op, attributionSource, message,
skipProxyOperation, ATTRIBUTION_FLAGS_NONE, ATTRIBUTION_FLAGS_NONE,
ATTRIBUTION_CHAIN_ID_NONE);
}
/**
* Like {@link #startProxyOp(String, AttributionSource, String)} but instead
* of throwing a {@link SecurityException} it returns {@link #MODE_ERRORED} and
* the checks is for the attribution chain specified by the {@link AttributionSource}.
*
* @see #startProxyOp(String, AttributionSource, String)
*
* @hide
*/
public int startProxyOpNoThrow(@NonNull IBinder clientId, int op,
@NonNull AttributionSource attributionSource,
@Nullable String message, boolean skipProxyOperation, @AttributionFlags
int proxyAttributionFlags, @AttributionFlags int proxiedAttributionFlags,
int attributionChainId) {
try {
collectNoteOpCallsForValidation(op);
int collectionMode = getNotedOpCollectionMode(
attributionSource.getNextUid(),
attributionSource.getNextPackageName(), op);
boolean shouldCollectMessage = Process.myUid() == Process.SYSTEM_UID;
if (collectionMode == COLLECT_ASYNC) {
if (message == null) {
// Set stack trace as default message
message = getFormattedStackTrace();
shouldCollectMessage = true;
}
}
SyncNotedAppOp syncOp = mService.startProxyOperation(clientId, op,
attributionSource, false, collectionMode == COLLECT_ASYNC, message,
shouldCollectMessage, skipProxyOperation, proxyAttributionFlags,
proxiedAttributionFlags, attributionChainId);
if (syncOp.getOpMode() == MODE_ALLOWED) {
if (collectionMode == COLLECT_SELF) {
collectNotedOpForSelf(syncOp);
} else if (collectionMode == COLLECT_SYNC
// Only collect app-ops when the proxy is trusted
&& (mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1,
Process.myUid()) == PackageManager.PERMISSION_GRANTED
|| Binder.getCallingUid() == attributionSource.getNextUid())) {
collectNotedOpSync(syncOp);
}
}
return syncOp.getOpMode();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* @deprecated Use {@link #finishOp(String, int, String, String)} instead
*
* @hide
*/
@Deprecated
public void finishOp(int op) {
finishOp(op, Process.myUid(), mContext.getOpPackageName(), null);
}
/**
* @deprecated Use {@link #finishOp(String, int, String, String)} instead
*/
public void finishOp(@NonNull String op, int uid, @NonNull String packageName) {
finishOp(strOpToOp(op), uid, packageName, null);
}
/**
* Report that an application is no longer performing an operation that had previously
* been started with {@link #startOp(String, int, String, String, String)}. There is no
* validation of input or result; the parameters supplied here must be the exact same ones
* previously passed in when starting the operation.
*/
public void finishOp(@NonNull String op, int uid, @NonNull String packageName,
@Nullable String attributionTag) {
finishOp(strOpToOp(op), uid, packageName, attributionTag);
}
/**
* @deprecated Use {@link #finishOp(int, int, String, String)} instead
*
* @hide
*/
public void finishOp(int op, int uid, @NonNull String packageName) {
finishOp(op, uid, packageName, null);
}
/**
* @see #finishOp(String, int, String, String)
*
* @hide
*/
public void finishOp(int op, int uid, @NonNull String packageName,
@Nullable String attributionTag) {
finishOp(mContext.getAttributionSource().getToken(), op, uid, packageName, attributionTag);
}
/**
* @see #finishOp(String, int, String, String)
*
* @hide
*/
public void finishOp(IBinder token, int op, int uid, @NonNull String packageName,
@Nullable String attributionTag) {
try {
mService.finishOperation(token, op, uid, packageName, attributionTag);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Report that an application is no longer performing an operation that had previously
* been started with {@link #startProxyOp(String, int, String, String, String)}. There is no
* validation of input or result; the parameters supplied here must be the exact same ones
* previously passed in when starting the operation.
*
* @param op The operation which was started
* @param proxiedUid The proxied appp's UID
* @param proxiedPackageName The proxied appp's package name
* @param proxiedAttributionTag The proxied appp's attribution tag or
* {@code null} for default attribution
*/
public void finishProxyOp(@NonNull String op, int proxiedUid,
@NonNull String proxiedPackageName, @Nullable String proxiedAttributionTag) {
IBinder token = mContext.getAttributionSource().getToken();
finishProxyOp(token, op, new AttributionSource(mContext.getAttributionSource(),
new AttributionSource(proxiedUid, proxiedPackageName, proxiedAttributionTag,
token)), /*skipProxyOperation*/ false);
}
/**
* Report that an application is no longer performing an operation that had previously
* been started with {@link #startProxyOp(String, AttributionSource, String, boolean)}. There
* is no validation of input or result; the parameters supplied here must be the exact same
* ones previously passed in when starting the operation.
*
* @param op The operation which was started
* @param attributionSource The permission identity for which to finish
* @param skipProxyOperation Whether to skip the proxy finish.
*
* @hide
*/
public void finishProxyOp(@NonNull IBinder clientId, @NonNull String op,
@NonNull AttributionSource attributionSource, boolean skipProxyOperation) {
try {
mService.finishProxyOperation(clientId, strOpToOp(op), attributionSource,
skipProxyOperation);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Checks whether the given op for a package is active, i.e. did someone call {@link #startOp}
* without {@link #finishOp} yet.
* <p>
* If you don't hold the {@code android.Manifest.permission#WATCH_APPOPS}
* permission you can query only for your UID.
*
* @see #finishOp(String, int, String, String)
* @see #startOp(String, int, String, String, String)
*/
public boolean isOpActive(@NonNull String op, int uid, @NonNull String packageName) {
return isOperationActive(strOpToOp(op), uid, packageName);
}
/**
* Get whether you are currently proxying to another package. That applies only
* for long running operations like {@link #OP_RECORD_AUDIO}.
*
* @param op The op.
* @param proxyAttributionTag Your attribution tag to query for.
* @param proxiedUid The proxied UID to query for.
* @param proxiedPackageName The proxied package to query for.
* @return Whether you are currently proxying to this target.
*
* @hide
*/
public boolean isProxying(int op, @NonNull String proxyAttributionTag, int proxiedUid,
@NonNull String proxiedPackageName) {
try {
return mService.isProxying(op, mContext.getOpPackageName(),
mContext.getAttributionTag(), proxiedUid, proxiedPackageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Clears the op state (last accesses + op modes) for a package but not
* the historical state.
*
* @param packageName The package to reset.
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void resetPackageOpsNoHistory(@NonNull String packageName) {
try {
mService.resetPackageOpsNoHistory(packageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Start collection of noted appops on this thread.
*
* <p>Called at the beginning of a two way binder transaction.
*
* @see #finishNotedAppOpsCollection()
*
* @hide
*/
public static void startNotedAppOpsCollection(int callingUid) {
sBinderThreadCallingUid.set(callingUid);
}
/**
* State of a temporarily paused noted app-ops collection.
*
* @see #pauseNotedAppOpsCollection()
*
* @hide
*/
public static class PausedNotedAppOpsCollection {
final int mUid;
final @Nullable ArrayMap<String, long[]> mCollectedNotedAppOps;
PausedNotedAppOpsCollection(int uid, @Nullable ArrayMap<String,
long[]> collectedNotedAppOps) {
mUid = uid;
mCollectedNotedAppOps = collectedNotedAppOps;
}
}
/**
* Temporarily suspend collection of noted app-ops when binder-thread calls into the other
* process. During such a call there might be call-backs coming back on the same thread which
* should not be accounted to the current collection.
*
* @return a state needed to resume the collection
*
* @hide
*/
public static @Nullable PausedNotedAppOpsCollection pauseNotedAppOpsCollection() {
Integer previousUid = sBinderThreadCallingUid.get();
if (previousUid != null) {
ArrayMap<String, long[]> previousCollectedNotedAppOps =
sAppOpsNotedInThisBinderTransaction.get();
sBinderThreadCallingUid.remove();
sAppOpsNotedInThisBinderTransaction.remove();
return new PausedNotedAppOpsCollection(previousUid, previousCollectedNotedAppOps);
}
return null;
}
/**
* Resume a collection paused via {@link #pauseNotedAppOpsCollection}.
*
* @param prevCollection The state of the previous collection
*
* @hide
*/
public static void resumeNotedAppOpsCollection(
@Nullable PausedNotedAppOpsCollection prevCollection) {
if (prevCollection != null) {
sBinderThreadCallingUid.set(prevCollection.mUid);
if (prevCollection.mCollectedNotedAppOps != null) {
sAppOpsNotedInThisBinderTransaction.set(prevCollection.mCollectedNotedAppOps);
}
}
}
/**
* Finish collection of noted appops on this thread.
*
* <p>Called at the end of a two way binder transaction.
*
* @see #startNotedAppOpsCollection(int)
*
* @hide
*/
public static void finishNotedAppOpsCollection() {
sBinderThreadCallingUid.remove();
sAppOpsNotedInThisBinderTransaction.remove();
}
/**
* Collect a noted op for the current process.
*
* @param op The noted op
* @param attributionTag The attribution tag the op is noted for
*/
private void collectNotedOpForSelf(SyncNotedAppOp syncOp) {
synchronized (sLock) {
if (sOnOpNotedCallback != null) {
sOnOpNotedCallback.onSelfNoted(syncOp);
}
}
sMessageCollector.onSelfNoted(syncOp);
}
/**
* Collect a noted op when inside of a two-way binder call.
*
* <p> Delivered to caller via {@link #prefixParcelWithAppOpsIfNeeded}
*
* @param syncOp the op and attribution tag to note for
*
* @hide
*/
@TestApi
public static void collectNotedOpSync(@NonNull SyncNotedAppOp syncOp) {
// If this is inside of a two-way binder call:
// We are inside of a two-way binder call. Delivered to caller via
// {@link #prefixParcelWithAppOpsIfNeeded}
int op = sOpStrToOp.get(syncOp.getOp());
ArrayMap<String, long[]> appOpsNoted = sAppOpsNotedInThisBinderTransaction.get();
if (appOpsNoted == null) {
appOpsNoted = new ArrayMap<>(1);
sAppOpsNotedInThisBinderTransaction.set(appOpsNoted);
}
long[] appOpsNotedForAttribution = appOpsNoted.get(syncOp.getAttributionTag());
if (appOpsNotedForAttribution == null) {
appOpsNotedForAttribution = new long[2];
appOpsNoted.put(syncOp.getAttributionTag(), appOpsNotedForAttribution);
}
if (op < 64) {
appOpsNotedForAttribution[0] |= 1L << op;
} else {
appOpsNotedForAttribution[1] |= 1L << (op - 64);
}
}
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(value = {
DONT_COLLECT,
COLLECT_SELF,
COLLECT_SYNC,
COLLECT_ASYNC
})
private @interface NotedOpCollectionMode {}
private static final int DONT_COLLECT = 0;
private static final int COLLECT_SELF = 1;
private static final int COLLECT_SYNC = 2;
private static final int COLLECT_ASYNC = 3;
/**
* Mark an app-op as noted.
*/
private @NotedOpCollectionMode int getNotedOpCollectionMode(int uid,
@Nullable String packageName, int op) {
if (packageName == null) {
packageName = "android";
}
// check if the appops needs to be collected and cache result
if (sAppOpsToNote[op] == SHOULD_COLLECT_NOTE_OP_NOT_INITIALIZED) {
boolean shouldCollectNotes;
try {
shouldCollectNotes = mService.shouldCollectNotes(op);
} catch (RemoteException e) {
return DONT_COLLECT;
}
if (shouldCollectNotes) {
sAppOpsToNote[op] = SHOULD_COLLECT_NOTE_OP;
} else {
sAppOpsToNote[op] = SHOULD_NOT_COLLECT_NOTE_OP;
}
}
if (sAppOpsToNote[op] != SHOULD_COLLECT_NOTE_OP) {
return DONT_COLLECT;
}
synchronized (sLock) {
if (uid == Process.myUid()
&& packageName.equals(ActivityThread.currentOpPackageName())) {
return COLLECT_SELF;
}
}
Integer binderUid = sBinderThreadCallingUid.get();
if (binderUid != null && binderUid == uid) {
return COLLECT_SYNC;
} else {
return COLLECT_ASYNC;
}
}
/**
* Append app-ops noted in the current two-way binder transaction to parcel.
*
* <p>This is called on the callee side of a two way binder transaction just before the
* transaction returns.
*
* @param p the parcel to append the noted app-ops to
*
* @hide
*/
// TODO (b/186872903) Refactor how sync noted ops are propagated.
public static void prefixParcelWithAppOpsIfNeeded(@NonNull Parcel p) {
ArrayMap<String, long[]> notedAppOps = sAppOpsNotedInThisBinderTransaction.get();
if (notedAppOps == null) {
return;
}
p.writeInt(Parcel.EX_HAS_NOTED_APPOPS_REPLY_HEADER);
int numAttributionWithNotesAppOps = notedAppOps.size();
p.writeInt(numAttributionWithNotesAppOps);
for (int i = 0; i < numAttributionWithNotesAppOps; i++) {
p.writeString(notedAppOps.keyAt(i));
p.writeLong(notedAppOps.valueAt(i)[0]);
p.writeLong(notedAppOps.valueAt(i)[1]);
}
}
/**
* Read app-ops noted during a two-way binder transaction from parcel.
*
* <p>This is called on the calling side of a two way binder transaction just after the
* transaction returns.
*
* @param p The parcel to read from
*
* @hide
*/
public static void readAndLogNotedAppops(@NonNull Parcel p) {
int numAttributionsWithNotedAppOps = p.readInt();
for (int i = 0; i < numAttributionsWithNotedAppOps; i++) {
String attributionTag = p.readString();
long[] rawNotedAppOps = new long[2];
rawNotedAppOps[0] = p.readLong();
rawNotedAppOps[1] = p.readLong();
if (rawNotedAppOps[0] != 0 || rawNotedAppOps[1] != 0) {
BitSet notedAppOps = BitSet.valueOf(rawNotedAppOps);
synchronized (sLock) {
for (int code = notedAppOps.nextSetBit(0); code != -1;
code = notedAppOps.nextSetBit(code + 1)) {
if (sOnOpNotedCallback != null) {
sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, attributionTag));
} else {
String message = getFormattedStackTrace();
sUnforwardedOps.add(
new AsyncNotedAppOp(code, Process.myUid(), attributionTag,
message, System.currentTimeMillis()));
if (sUnforwardedOps.size() > MAX_UNFORWARDED_OPS) {
sUnforwardedOps.remove(0);
}
}
}
}
for (int code = notedAppOps.nextSetBit(0); code != -1;
code = notedAppOps.nextSetBit(code + 1)) {
sMessageCollector.onNoted(new SyncNotedAppOp(code, attributionTag));
}
}
}
}
/**
* Set a new {@link OnOpNotedCallback}.
*
* <p>There can only ever be one collector per process. If there currently is another callback
* set, this will fail.
*
* @param asyncExecutor executor to execute {@link OnOpNotedCallback#onAsyncNoted} on, {@code
* null} to unset
* @param callback listener to set, {@code null} to unset
*
* @throws IllegalStateException If another callback is already registered
*/
public void setOnOpNotedCallback(@Nullable @CallbackExecutor Executor asyncExecutor,
@Nullable OnOpNotedCallback callback) {
Preconditions.checkState((callback == null) == (asyncExecutor == null));
synchronized (sLock) {
if (callback == null) {
Preconditions.checkState(sOnOpNotedCallback != null,
"No callback is currently registered");
try {
mService.stopWatchingAsyncNoted(mContext.getPackageName(),
sOnOpNotedCallback.mAsyncCb);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
sOnOpNotedCallback = null;
} else {
Preconditions.checkState(sOnOpNotedCallback == null,
"Another callback is already registered");
callback.mAsyncExecutor = asyncExecutor;
sOnOpNotedCallback = callback;
List<AsyncNotedAppOp> missedAsyncOps = null;
try {
mService.startWatchingAsyncNoted(mContext.getPackageName(),
sOnOpNotedCallback.mAsyncCb);
missedAsyncOps = mService.extractAsyncOps(mContext.getPackageName());
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
// Copy pointer so callback can be dispatched out of lock
OnOpNotedCallback onOpNotedCallback = sOnOpNotedCallback;
if (onOpNotedCallback != null && missedAsyncOps != null) {
int numMissedAsyncOps = missedAsyncOps.size();
for (int i = 0; i < numMissedAsyncOps; i++) {
final AsyncNotedAppOp asyncNotedAppOp = missedAsyncOps.get(i);
onOpNotedCallback.getAsyncNotedExecutor().execute(
() -> onOpNotedCallback.onAsyncNoted(asyncNotedAppOp));
}
}
synchronized (this) {
int numMissedSyncOps = sUnforwardedOps.size();
if (onOpNotedCallback != null) {
for (int i = 0; i < numMissedSyncOps; i++) {
final AsyncNotedAppOp syncNotedAppOp = sUnforwardedOps.get(i);
onOpNotedCallback.getAsyncNotedExecutor().execute(
() -> onOpNotedCallback.onAsyncNoted(syncNotedAppOp));
}
}
sUnforwardedOps.clear();
}
}
}
}
// TODO moltmann: Remove
/**
* Will be removed before R ships, leave it just to not break apps immediately.
*
* @removed
*
* @hide
*/
@SystemApi
@Deprecated
public void setNotedAppOpsCollector(@Nullable AppOpsCollector collector) {
synchronized (sLock) {
if (collector != null) {
if (isListeningForOpNoted()) {
setOnOpNotedCallback(null, null);
}
setOnOpNotedCallback(new HandlerExecutor(Handler.getMain()), collector);
} else if (sOnOpNotedCallback != null) {
setOnOpNotedCallback(null, null);
}
}
}
/**
* @return {@code true} iff the process currently is currently collecting noted appops.
*
* @see #setOnOpNotedCallback
*
* @hide
*/
public static boolean isListeningForOpNoted() {
return sOnOpNotedCallback != null || isCollectingStackTraces();
}
/**
* @return {@code true} iff the process is currently sampled for stacktrace collection.
*
* @see #setOnOpNotedCallback
*
* @hide
*/
private static boolean isCollectingStackTraces() {
if (sConfig.getSampledOpCode() == OP_NONE && sConfig.getAcceptableLeftDistance() == 0 &&
sConfig.getExpirationTimeSinceBootMillis() >= SystemClock.elapsedRealtime()) {
return false;
}
return true;
}
/**
* Callback an app can {@link #setOnOpNotedCallback set} to monitor the app-ops the
* system has tracked for it. I.e. each time any app calls {@link #noteOp} or {@link #startOp}
* one of a method of this object is called.
*
* <p><b>There will be a call for all app-ops related to runtime permissions, but not
* necessarily for all other app-ops.
*
* <pre>
* setOnOpNotedCallback(getMainExecutor(), new OnOpNotedCallback() {
* ArraySet<Pair<String, String>> opsNotedForThisProcess = new ArraySet<>();
*
* private synchronized void addAccess(String op, String accessLocation) {
* // Ops are often noted when runtime permission protected APIs were called.
* // In this case permissionToOp() allows to resolve the permission<->op
* opsNotedForThisProcess.add(new Pair(accessType, accessLocation));
* }
*
* public void onNoted(SyncNotedAppOp op) {
* // Accesses is currently happening, hence stack trace describes location of access
* addAccess(op.getOp(), Arrays.toString(Thread.currentThread().getStackTrace()));
* }
*
* public void onSelfNoted(SyncNotedAppOp op) {
* onNoted(op);
* }
*
* public void onAsyncNoted(AsyncNotedAppOp asyncOp) {
* // Stack trace is not useful for async ops as accessed happened on different thread
* addAccess(asyncOp.getOp(), asyncOp.getMessage());
* }
* });
* </pre>
*
* @see #setOnOpNotedCallback
*/
public abstract static class OnOpNotedCallback {
private @NonNull Executor mAsyncExecutor;
/** Callback registered with the system. This will receive the async notes ops */
private final IAppOpsAsyncNotedCallback mAsyncCb = new IAppOpsAsyncNotedCallback.Stub() {
@Override
public void opNoted(AsyncNotedAppOp op) {
Objects.requireNonNull(op);
final long token = Binder.clearCallingIdentity();
try {
getAsyncNotedExecutor().execute(() -> onAsyncNoted(op));
} finally {
Binder.restoreCallingIdentity(token);
}
}
};
// TODO moltmann: Remove
/**
* Will be removed before R ships.
*
* @return The executor for the system to use when calling {@link #onAsyncNoted}.
*
* @hide
*/
protected @NonNull Executor getAsyncNotedExecutor() {
return mAsyncExecutor;
}
/**
* Called when an app-op was {@link #noteOp noted} for this package inside of a synchronous
* API call, i.e. a API call that returned data or waited until the action was performed.
*
* <p>Called on the calling thread before the API returns. This allows the app to e.g.
* collect stack traces to figure out where the access came from.
*
* @param op op noted
*/
public abstract void onNoted(@NonNull SyncNotedAppOp op);
/**
* Called when this app noted an app-op for its own package,
*
* <p>This is very similar to {@link #onNoted} only that the tracking was not caused by the
* API provider in a separate process, but by one in the app's own process.
*
* @param op op noted
*/
public abstract void onSelfNoted(@NonNull SyncNotedAppOp op);
/**
* Called when an app-op was noted for this package which cannot be delivered via the other
* two mechanisms.
*
* <p>Called as soon as possible after the app-op was noted, but the delivery delay is not
* guaranteed. Due to how async calls work in Android this might even be delivered slightly
* before the private data is delivered to the app.
*
* <p>If the app is not running or no {@link OnOpNotedCallback} is registered a small amount
* of noted app-ops are buffered and then delivered as soon as a listener is registered.
*
* @param asyncOp op noted
*/
public abstract void onAsyncNoted(@NonNull AsyncNotedAppOp asyncOp);
}
// TODO moltmann: Remove
/**
* Will be removed before R ships, leave it just to not break apps immediately.
*
* @removed
*
* @hide
*/
@SystemApi
@Deprecated
public abstract static class AppOpsCollector extends OnOpNotedCallback {
public @NonNull Executor getAsyncNotedExecutor() {
return new HandlerExecutor(Handler.getMain());
}
};
/**
* Generate a stack trace used for noted app-ops logging.
*
* <p>This strips away the first few and last few stack trace elements as they are not
* interesting to apps.
*/
private static String getFormattedStackTrace() {
StackTraceElement[] trace = new Exception().getStackTrace();
int firstInteresting = 0;
for (int i = 0; i < trace.length; i++) {
if (trace[i].getClassName().startsWith(AppOpsManager.class.getName())
|| trace[i].getClassName().startsWith(Parcel.class.getName())
|| trace[i].getClassName().contains("$Stub$Proxy")
|| trace[i].getClassName().startsWith(DatabaseUtils.class.getName())
|| trace[i].getClassName().startsWith("android.content.ContentProviderProxy")
|| trace[i].getClassName().startsWith(ContentResolver.class.getName())) {
firstInteresting = i;
} else {
break;
}
}
int lastInteresting = trace.length - 1;
for (int i = trace.length - 1; i >= 0; i--) {
if (trace[i].getClassName().startsWith(HandlerThread.class.getName())
|| trace[i].getClassName().startsWith(Handler.class.getName())
|| trace[i].getClassName().startsWith(Looper.class.getName())
|| trace[i].getClassName().startsWith(Binder.class.getName())
|| trace[i].getClassName().startsWith(RuntimeInit.class.getName())
|| trace[i].getClassName().startsWith(ZygoteInit.class.getName())
|| trace[i].getClassName().startsWith(ActivityThread.class.getName())
|| trace[i].getClassName().startsWith(Method.class.getName())
|| trace[i].getClassName().startsWith("com.android.server.SystemServer")) {
lastInteresting = i;
} else {
break;
}
}
StringBuilder sb = new StringBuilder();
for (int i = firstInteresting; i <= lastInteresting; i++) {
if (sFullLog == null) {
try {
sFullLog = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_PRIVACY,
FULL_LOG, false);
} catch (Exception e) {
// This should not happen, but it may, in rare cases
sFullLog = false;
}
}
if (i != firstInteresting) {
sb.append('\n');
}
if (!sFullLog && sb.length() + trace[i].toString().length() > 600) {
break;
}
sb.append(trace[i]);
}
return sb.toString();
}
/**
* Checks whether the given op for a UID and package is active.
*
* <p> If you don't hold the {@link android.Manifest.permission#WATCH_APPOPS} permission
* you can query only for your UID.
*
* @see #startWatchingActive(int[], OnOpActiveChangedListener)
* @see #stopWatchingMode(OnOpChangedListener)
* @see #finishOp(int, int, String, String)
* @see #startOp(int, int, String, boolean, String, String)
*
* @hide */
@TestApi
// TODO: Uncomment below annotation once b/73559440 is fixed
// @RequiresPermission(value=Manifest.permission.WATCH_APPOPS, conditional=true)
public boolean isOperationActive(int code, int uid, String packageName) {
try {
return mService.isOperationActive(code, uid, packageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Configures the app ops persistence for testing.
*
* @param mode The mode in which the historical registry operates.
* @param baseSnapshotInterval The base interval on which we would be persisting a snapshot of
* the historical data. The history is recursive where every subsequent step encompasses
* {@code compressionStep} longer interval with {@code compressionStep} distance between
* snapshots.
* @param compressionStep The compression step in every iteration.
*
* @see #HISTORICAL_MODE_DISABLED
* @see #HISTORICAL_MODE_ENABLED_ACTIVE
* @see #HISTORICAL_MODE_ENABLED_PASSIVE
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void setHistoryParameters(@HistoricalMode int mode, long baseSnapshotInterval,
int compressionStep) {
try {
mService.setHistoryParameters(mode, baseSnapshotInterval, compressionStep);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Offsets the history by the given duration.
*
* @param offsetMillis The offset duration.
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void offsetHistory(long offsetMillis) {
try {
mService.offsetHistory(offsetMillis);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Adds ops to the history directly. This could be useful for testing especially
* when the historical registry operates in {@link #HISTORICAL_MODE_ENABLED_PASSIVE}
* mode.
*
* @param ops The ops to add to the history.
*
* @see #setHistoryParameters(int, long, int)
* @see #HISTORICAL_MODE_ENABLED_PASSIVE
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void addHistoricalOps(@NonNull HistoricalOps ops) {
try {
mService.addHistoricalOps(ops);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Resets the app ops persistence for testing.
*
* @see #setHistoryParameters(int, long, int)
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void resetHistoryParameters() {
try {
mService.resetHistoryParameters();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Clears all app ops history.
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void clearHistory() {
try {
mService.clearHistory();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Reboots the ops history.
*
* @param offlineDurationMillis The duration to wait between
* tearing down and initializing the history. Must be greater
* than or equal to zero.
*
* @hide
*/
@TestApi
@RequiresPermission(Manifest.permission.MANAGE_APPOPS)
public void rebootHistory(long offlineDurationMillis) {
try {
mService.rebootHistory(offlineDurationMillis);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Pulls current AppOps access report and picks package and op to watch for next access report
* Returns null if no reports were collected since last call. There is no guarantee of report
* collection, hence this method should be called periodically even if no report was collected
* to pick different package and op to watch.
* @hide
*/
@SystemApi
@RequiresPermission(Manifest.permission.GET_APP_OPS_STATS)
public @Nullable RuntimeAppOpAccessMessage collectRuntimeAppOpAccessMessage() {
try {
return mService.collectRuntimeAppOpAccessMessage();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* Returns all supported operation names.
* @hide
*/
@SystemApi
public static String[] getOpStrs() {
return Arrays.copyOf(sOpToString, sOpToString.length);
}
/**
* @return number of App ops
* @hide
*/
@TestApi
public static int getNumOps() {
return _NUM_OP;
}
/**
* Gets the last of the event.
*
* @param events The events
* @param flags The UID flags
* @param beginUidState The maximum UID state (inclusive)
* @param endUidState The minimum UID state (inclusive)
*
* @return The last event of {@code null}
*/
private static @Nullable NoteOpEvent getLastEvent(
@Nullable LongSparseArray<NoteOpEvent> events, @UidState int beginUidState,
@UidState int endUidState, @OpFlags int flags) {
if (events == null) {
return null;
}
NoteOpEvent lastEvent = null;
while (flags != 0) {
final int flag = 1 << Integer.numberOfTrailingZeros(flags);
flags &= ~flag;
for (int uidState : UID_STATES) {
if (uidState < beginUidState || uidState > endUidState) {
continue;
}
final long key = makeKey(uidState, flag);
NoteOpEvent event = events.get(key);
if (lastEvent == null
|| event != null && event.getNoteTime() > lastEvent.getNoteTime()) {
lastEvent = event;
}
}
}
return lastEvent;
}
private static boolean equalsLongSparseLongArray(@Nullable LongSparseLongArray a,
@Nullable LongSparseLongArray b) {
if (a == b) {
return true;
}
if (a == null || b == null) {
return false;
}
if (a.size() != b.size()) {
return false;
}
int numEntries = a.size();
for (int i = 0; i < numEntries; i++) {
if (a.keyAt(i) != b.keyAt(i) || a.valueAt(i) != b.valueAt(i)) {
return false;
}
}
return true;
}
private static void writeLongSparseLongArrayToParcel(
@Nullable LongSparseLongArray array, @NonNull Parcel parcel) {
if (array != null) {
final int size = array.size();
parcel.writeInt(size);
for (int i = 0; i < size; i++) {
parcel.writeLong(array.keyAt(i));
parcel.writeLong(array.valueAt(i));
}
} else {
parcel.writeInt(-1);
}
}
private static @Nullable LongSparseLongArray readLongSparseLongArrayFromParcel(
@NonNull Parcel parcel) {
final int size = parcel.readInt();
if (size < 0) {
return null;
}
final LongSparseLongArray array = new LongSparseLongArray(size);
for (int i = 0; i < size; i++) {
array.append(parcel.readLong(), parcel.readLong());
}
return array;
}
private static void writeDiscreteAccessArrayToParcel(
@Nullable List<AttributedOpEntry> array, @NonNull Parcel parcel, int flags) {
ParceledListSlice<AttributedOpEntry> listSlice =
array == null ? null : new ParceledListSlice<>(array);
parcel.writeParcelable(listSlice, flags);
}
private static @Nullable List<AttributedOpEntry> readDiscreteAccessArrayFromParcel(
@NonNull Parcel parcel) {
final ParceledListSlice<AttributedOpEntry> listSlice = parcel.readParcelable(null, android.content.pm.ParceledListSlice.class);
return listSlice == null ? null : listSlice.getList();
}
/**
* Collects the keys from an array to the result creating the result if needed.
*
* @param array The array whose keys to collect.
* @param result The optional result store collected keys.
* @return The result collected keys array.
*/
private static LongSparseArray<Object> collectKeys(@Nullable LongSparseLongArray array,
@Nullable LongSparseArray<Object> result) {
if (array != null) {
if (result == null) {
result = new LongSparseArray<>();
}
final int accessSize = array.size();
for (int i = 0; i < accessSize; i++) {
result.put(array.keyAt(i), null);
}
}
return result;
}
/** @hide */
public static String uidStateToString(@UidState int uidState) {
switch (uidState) {
case UID_STATE_PERSISTENT: {
return "UID_STATE_PERSISTENT";
}
case UID_STATE_TOP: {
return "UID_STATE_TOP";
}
case UID_STATE_FOREGROUND_SERVICE_LOCATION: {
return "UID_STATE_FOREGROUND_SERVICE_LOCATION";
}
case UID_STATE_FOREGROUND_SERVICE: {
return "UID_STATE_FOREGROUND_SERVICE";
}
case UID_STATE_FOREGROUND: {
return "UID_STATE_FOREGROUND";
}
case UID_STATE_BACKGROUND: {
return "UID_STATE_BACKGROUND";
}
case UID_STATE_CACHED: {
return "UID_STATE_CACHED";
}
default: {
return "UNKNOWN";
}
}
}
/** @hide */
public static int parseHistoricalMode(@NonNull String mode) {
switch (mode) {
case "HISTORICAL_MODE_ENABLED_ACTIVE": {
return HISTORICAL_MODE_ENABLED_ACTIVE;
}
case "HISTORICAL_MODE_ENABLED_PASSIVE": {
return HISTORICAL_MODE_ENABLED_PASSIVE;
}
default: {
return HISTORICAL_MODE_DISABLED;
}
}
}
/** @hide */
public static String historicalModeToString(@HistoricalMode int mode) {
switch (mode) {
case HISTORICAL_MODE_DISABLED: {
return "HISTORICAL_MODE_DISABLED";
}
case HISTORICAL_MODE_ENABLED_ACTIVE: {
return "HISTORICAL_MODE_ENABLED_ACTIVE";
}
case HISTORICAL_MODE_ENABLED_PASSIVE: {
return "HISTORICAL_MODE_ENABLED_PASSIVE";
}
default: {
return "UNKNOWN";
}
}
}
private static int getSystemAlertWindowDefault() {
final Context context = ActivityThread.currentApplication();
if (context == null) {
return AppOpsManager.MODE_DEFAULT;
}
// system alert window is disable on low ram phones starting from Q
final PackageManager pm = context.getPackageManager();
// TVs are constantly plugged in and has less concern for memory/power
if (ActivityManager.isLowRamDeviceStatic()
&& !pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK, 0)) {
return AppOpsManager.MODE_IGNORED;
}
return AppOpsManager.MODE_DEFAULT;
}
/**
* Calculate left circular distance for two numbers modulo size.
* @hide
*/
public static int leftCircularDistance(int from, int to, int size) {
return (to + size - from) % size;
}
/**
* Helper method for noteOp, startOp and noteProxyOp to call AppOpsService to collect/log
* stack traces
*
* <p> For each call, the stacktrace op code, package name and long version code will be
* passed along where it will be logged/collected
*
* @param op The operation to note
*/
private void collectNoteOpCallsForValidation(int op) {
if (NOTE_OP_COLLECTION_ENABLED) {
try {
mService.collectNoteOpCallsForValidation(getFormattedStackTrace(),
op, mContext.getOpPackageName(), mContext.getApplicationInfo().longVersionCode);
} catch (RemoteException e) {
// Swallow error, only meant for logging ops, should not affect flow of the code
}
}
}
private static List<AttributedOpEntry> deduplicateDiscreteEvents(List<AttributedOpEntry> list) {
int n = list.size();
int i = 0;
for (int j = 0, k = 0; j < n; i++, j = k) {
long currentAccessTime = list.get(j).getLastAccessTime(OP_FLAGS_ALL);
k = j + 1;
while(k < n && list.get(k).getLastAccessTime(OP_FLAGS_ALL) == currentAccessTime) {
k++;
}
list.set(i, mergeAttributedOpEntries(list.subList(j, k)));
}
for (; i < n; i++) {
list.remove(list.size() - 1);
}
return list;
}
private static AttributedOpEntry mergeAttributedOpEntries(List<AttributedOpEntry> opEntries) {
if (opEntries.size() == 1) {
return opEntries.get(0);
}
LongSparseArray<AppOpsManager.NoteOpEvent> accessEvents = new LongSparseArray<>();
LongSparseArray<AppOpsManager.NoteOpEvent> rejectEvents = new LongSparseArray<>();
int opCount = opEntries.size();
for (int i = 0; i < opCount; i++) {
AttributedOpEntry a = opEntries.get(i);
ArraySet<Long> keys = a.collectKeys();
final int keyCount = keys.size();
for (int k = 0; k < keyCount; k++) {
final long key = keys.valueAt(k);
final int uidState = extractUidStateFromKey(key);
final int flags = extractFlagsFromKey(key);
NoteOpEvent access = a.getLastAccessEvent(uidState, uidState, flags);
NoteOpEvent reject = a.getLastRejectEvent(uidState, uidState, flags);
if (access != null) {
NoteOpEvent existingAccess = accessEvents.get(key);
if (existingAccess == null || existingAccess.getDuration() == -1) {
accessEvents.append(key, access);
} else if (existingAccess.mProxy == null && access.mProxy != null ) {
existingAccess.mProxy = access.mProxy;
}
}
if (reject != null) {
rejectEvents.append(key, reject);
}
}
}
return new AttributedOpEntry(opEntries.get(0).mOp, false, accessEvents, rejectEvents);
}
}
|