mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-08-16 15:59:45 +00:00
Compare commits
646 Commits
v19.1
...
manager-v7
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7da97489cc | ||
![]() |
a9f11b28c8 | ||
![]() |
b31d986c8d | ||
![]() |
2dad751889 | ||
![]() |
c85b1c56af | ||
![]() |
6dd34aec47 | ||
![]() |
4cd154675f | ||
![]() |
d8d72f92b3 | ||
![]() |
a30f5b175f | ||
![]() |
8277896ca1 | ||
![]() |
493068c073 | ||
![]() |
f4299fbea8 | ||
![]() |
10ce11d671 | ||
![]() |
0f34457a10 | ||
![]() |
34c65e13bc | ||
![]() |
17a77e2577 | ||
![]() |
0f219e5ae6 | ||
![]() |
353c3c7d81 | ||
![]() |
0a89edf3b0 | ||
![]() |
e7155837d7 | ||
![]() |
31e003bda5 | ||
![]() |
490e4d3180 | ||
![]() |
dc9f69bab0 | ||
![]() |
fdf04f77f2 | ||
![]() |
5e87483f34 | ||
![]() |
f7aa451591 | ||
![]() |
321d11c2c6 | ||
![]() |
ee447bc4ce | ||
![]() |
31153e4366 | ||
![]() |
7693024c29 | ||
![]() |
9628700a2f | ||
![]() |
38576173cb | ||
![]() |
19a769c12e | ||
![]() |
3c1db7d2f7 | ||
![]() |
626507093a | ||
![]() |
588b3d14a3 | ||
![]() |
815efa7791 | ||
![]() |
97a691ce2f | ||
![]() |
9d948f2c2b | ||
![]() |
0b87108174 | ||
![]() |
7fc7809cfc | ||
![]() |
c30be20e49 | ||
![]() |
25c64db0a1 | ||
![]() |
676e9c6593 | ||
![]() |
d459859361 | ||
![]() |
2be0cef446 | ||
![]() |
294db93fde | ||
![]() |
7f971f7173 | ||
![]() |
5c7b59524d | ||
![]() |
5133e5910e | ||
![]() |
1512c350df | ||
![]() |
a5fc7891a6 | ||
![]() |
3eb9633231 | ||
![]() |
ac67b48247 | ||
![]() |
81b65ea646 | ||
![]() |
45c1f6bc27 | ||
![]() |
0d31e5c8b1 | ||
![]() |
6378abf454 | ||
![]() |
f8fcaadb5b | ||
![]() |
0b5fd3ee76 | ||
![]() |
d010cb7e42 | ||
![]() |
71136d7347 | ||
![]() |
a18c552ddf | ||
![]() |
9656878ef3 | ||
![]() |
7ded7de39a | ||
![]() |
0f74e89b44 | ||
![]() |
953c40b083 | ||
![]() |
271b0287d8 | ||
![]() |
96a8a2a8b8 | ||
![]() |
75306f658f | ||
![]() |
325d9a0b86 | ||
![]() |
a02493fbaa | ||
![]() |
9c27d691dd | ||
![]() |
935bd01f59 | ||
![]() |
eeb5d669f6 | ||
![]() |
78daa2eb62 | ||
![]() |
40eda05a30 | ||
![]() |
9f9de8c43b | ||
![]() |
a910c8ccd8 | ||
![]() |
43bda2d4a4 | ||
![]() |
c7033dd757 | ||
![]() |
5673a9bace | ||
![]() |
34ff764515 | ||
![]() |
1b3a009da7 | ||
![]() |
a49002bb2c | ||
![]() |
7342fc2307 | ||
![]() |
9867a3bd60 | ||
![]() |
5ffb9eaa5b | ||
![]() |
b05b688267 | ||
![]() |
f3d7f85063 | ||
![]() |
de969a9dab | ||
![]() |
59fd38bbf8 | ||
![]() |
06dc6df270 | ||
![]() |
ff8460b361 | ||
![]() |
674d272eaa | ||
![]() |
c3e00c279d | ||
![]() |
175d920c94 | ||
![]() |
04920883ea | ||
![]() |
5e44b0b9d5 | ||
![]() |
23c1a1dab8 | ||
![]() |
f5d054b93c | ||
![]() |
d25ae5e0a9 | ||
![]() |
c42a51dcbb | ||
![]() |
da3fd92b31 | ||
![]() |
4a45ba3c14 | ||
![]() |
dbc8bed234 | ||
![]() |
f8b4190a11 | ||
![]() |
479972e3ae | ||
![]() |
3ea28b0afb | ||
![]() |
2b3cc28966 | ||
![]() |
751642b39a | ||
![]() |
d6c2c821a4 | ||
![]() |
dfc65b95f7 | ||
![]() |
b45d922463 | ||
![]() |
f87ee3fcf9 | ||
![]() |
e0927cd763 | ||
![]() |
21099eabfa | ||
![]() |
abbd2e6b72 | ||
![]() |
5b7ddbbb01 | ||
![]() |
6352fbb3b2 | ||
![]() |
d3f49334e2 | ||
![]() |
c4356171b3 | ||
![]() |
5c5625911d | ||
![]() |
6a10cc9c55 | ||
![]() |
6b317f918e | ||
![]() |
08b528dc4f | ||
![]() |
fc886a5a47 | ||
![]() |
0cb90e2e55 | ||
![]() |
64113a69b4 | ||
![]() |
544bb7459c | ||
![]() |
578a50b464 | ||
![]() |
3d4081d0af | ||
![]() |
b763b81f56 | ||
![]() |
947dae4900 | ||
![]() |
debd1d7d54 | ||
![]() |
cba0d04000 | ||
![]() |
695e7e6da0 | ||
![]() |
4cd4bfa1d7 | ||
![]() |
16b400964b | ||
![]() |
cf2d02c0dd | ||
![]() |
0fcd0de0d1 | ||
![]() |
748a35774f | ||
![]() |
a52a3e38ed | ||
![]() |
ee0cef06a6 | ||
![]() |
0e5a113a0c | ||
![]() |
a1ccd44013 | ||
![]() |
4d91e50d6d | ||
![]() |
120668c7bc | ||
![]() |
d81ccde569 | ||
![]() |
e8581b4adb | ||
![]() |
19906575a3 | ||
![]() |
9329094a4e | ||
![]() |
b44f5122fd | ||
![]() |
17981730a4 | ||
![]() |
53de6da26c | ||
![]() |
3e30ccdeee | ||
![]() |
baaaf7d5de | ||
![]() |
45d8d139a9 | ||
![]() |
fe644e10d0 | ||
![]() |
f383d11d10 | ||
![]() |
ef1b928532 | ||
![]() |
6e46d394b1 | ||
![]() |
f109038d12 | ||
![]() |
e31e687602 | ||
![]() |
86bfb22d4c | ||
![]() |
3f057367e3 | ||
![]() |
3d7ed5820e | ||
![]() |
0118f2efa7 | ||
![]() |
15312e4709 | ||
![]() |
bf1568a73a | ||
![]() |
13a2520ea5 | ||
![]() |
f53238f206 | ||
![]() |
9375748d9b | ||
![]() |
201df54e79 | ||
![]() |
0b54fe477b | ||
![]() |
4119e6669e | ||
![]() |
d33e5226b3 | ||
![]() |
d73f39c706 | ||
![]() |
087b451e17 | ||
![]() |
86481c74ff | ||
![]() |
5b937fb1fa | ||
![]() |
ff828116bc | ||
![]() |
ee39616a8b | ||
![]() |
cdb53ca049 | ||
![]() |
8cf475f708 | ||
![]() |
0cb449e1d6 | ||
![]() |
e6adb7abca | ||
![]() |
cfad7dd317 | ||
![]() |
dd35224f92 | ||
![]() |
1283590eeb | ||
![]() |
dca3fe396f | ||
![]() |
8d87eae11b | ||
![]() |
fd7eaacae0 | ||
![]() |
fba33cbbe9 | ||
![]() |
950ffcd790 | ||
![]() |
c178299013 | ||
![]() |
5d17c1f588 | ||
![]() |
a75c00d94e | ||
![]() |
cd19517414 | ||
![]() |
155f39aab5 | ||
![]() |
4514d0b467 | ||
![]() |
6f4a938a31 | ||
![]() |
1303ea95dd | ||
![]() |
727fe1bd15 | ||
![]() |
64ebc977e9 | ||
![]() |
e89c50d934 | ||
![]() |
c859ddfb8f | ||
![]() |
a6126c5eda | ||
![]() |
85d9bd9106 | ||
![]() |
39e9622205 | ||
![]() |
021994c9f3 | ||
![]() |
2e7ce2a769 | ||
![]() |
84f0ff2fad | ||
![]() |
e6561e5f84 | ||
![]() |
5fa452aa74 | ||
![]() |
2225ccb146 | ||
![]() |
5aafc78847 | ||
![]() |
0d03833cff | ||
![]() |
a797d5d396 | ||
![]() |
f2494374f8 | ||
![]() |
48395ba860 | ||
![]() |
5ba5f5f94e | ||
![]() |
42ce6fd334 | ||
![]() |
f5c3ee3ae1 | ||
![]() |
3c7ece1605 | ||
![]() |
870efc49ea | ||
![]() |
085ede6d93 | ||
![]() |
4ef19d17da | ||
![]() |
223913c30a | ||
![]() |
010e4de4e1 | ||
![]() |
41134466ed | ||
![]() |
8f07747452 | ||
![]() |
eb5ce5be1e | ||
![]() |
71d855e836 | ||
![]() |
33b7ab593c | ||
![]() |
8706d834b4 | ||
![]() |
7cfab33ebb | ||
![]() |
1ababc8c7f | ||
![]() |
1f75e63c37 | ||
![]() |
cb3f9b9740 | ||
![]() |
9784353223 | ||
![]() |
7d93ca5c73 | ||
![]() |
ac20063e86 | ||
![]() |
debaec32af | ||
![]() |
0e9b71e7a9 | ||
![]() |
85f5ff3c14 | ||
![]() |
3d81f167ea | ||
![]() |
fb70a2e52d | ||
![]() |
460e85a1b5 | ||
![]() |
539b64bd57 | ||
![]() |
90e38a06a2 | ||
![]() |
09ab910630 | ||
![]() |
c15f80b33f | ||
![]() |
b2e6ba3c4a | ||
![]() |
b16f696b0e | ||
![]() |
9adfb382e8 | ||
![]() |
44368383f4 | ||
![]() |
d1ff7e0ffe | ||
![]() |
42e7db8d13 | ||
![]() |
0c17ea5755 | ||
![]() |
cdaff5b39c | ||
![]() |
2b1b970e78 | ||
![]() |
0aebc0a8e3 | ||
![]() |
c3a89f589e | ||
![]() |
971cd73fb3 | ||
![]() |
1947860d61 | ||
![]() |
55aaa421e8 | ||
![]() |
a8932706d8 | ||
![]() |
a97972aac0 | ||
![]() |
094c3d559a | ||
![]() |
6fb032b3c2 | ||
![]() |
8ca188f4d4 | ||
![]() |
746a1d8d59 | ||
![]() |
63c5e00d86 | ||
![]() |
9d2e5d6665 | ||
![]() |
f6045bf8b5 | ||
![]() |
e83f40d5c5 | ||
![]() |
e5118418b2 | ||
![]() |
7cd814d917 | ||
![]() |
78282c1a49 | ||
![]() |
fd4214ccf3 | ||
![]() |
0785945635 | ||
![]() |
967bdeae7b | ||
![]() |
452db51669 | ||
![]() |
5875ced367 | ||
![]() |
fbac6bcfd0 | ||
![]() |
0dcd3ece9d | ||
![]() |
224fff89e3 | ||
![]() |
22e73644f9 | ||
![]() |
6a0f6ab319 | ||
![]() |
88a394836f | ||
![]() |
f822c1c2e4 | ||
![]() |
1d16d980b3 | ||
![]() |
501b18f986 | ||
![]() |
21ed759e53 | ||
![]() |
8d50dfd93c | ||
![]() |
51e40dd98c | ||
![]() |
b2048379af | ||
![]() |
011539f6f1 | ||
![]() |
5457c3803f | ||
![]() |
b3d777bb6c | ||
![]() |
12e00c3054 | ||
![]() |
40b683111c | ||
![]() |
9542ca773f | ||
![]() |
8af832a496 | ||
![]() |
6836130fda | ||
![]() |
724893879f | ||
![]() |
736729f5ef | ||
![]() |
aa47966347 | ||
![]() |
d64d12afe8 | ||
![]() |
1f8df419c4 | ||
![]() |
7ba8202af5 | ||
![]() |
d7b691cf59 | ||
![]() |
7058d5e4cd | ||
![]() |
52fd508fea | ||
![]() |
41045b62dc | ||
![]() |
188ea2644a | ||
![]() |
4c8f357978 | ||
![]() |
4bb2fd6ba6 | ||
![]() |
33c9f74508 | ||
![]() |
f53fe67372 | ||
![]() |
51ff724691 | ||
![]() |
291bf93f9d | ||
![]() |
5fcd629f16 | ||
![]() |
ab90901793 | ||
![]() |
4f206fd918 | ||
![]() |
7233285437 | ||
![]() |
8e348a11c2 | ||
![]() |
085ea6d0a1 | ||
![]() |
aaf88b1895 | ||
![]() |
4f4a9412a3 | ||
![]() |
a92e039363 | ||
![]() |
33aa4ca4b7 | ||
![]() |
05658cafc7 | ||
![]() |
ff3710de66 | ||
![]() |
db8dd9f186 | ||
![]() |
e8b73ba6d1 | ||
![]() |
f1112fdf37 | ||
![]() |
a48c4f9e05 | ||
![]() |
19a521d2e9 | ||
![]() |
dd6e55ac31 | ||
![]() |
b1e63f0f14 | ||
![]() |
b0e49a4cc8 | ||
![]() |
1e94517a72 | ||
![]() |
98f60216ac | ||
![]() |
e29b712108 | ||
![]() |
a462435f2f | ||
![]() |
911b8273fe | ||
![]() |
09935e591a | ||
![]() |
4a212dba35 | ||
![]() |
aac9e85e04 | ||
![]() |
bb67a837d3 | ||
![]() |
6cde695194 | ||
![]() |
a1a1ac0bbb | ||
![]() |
9ec8bc2166 | ||
![]() |
28cd6a75e7 | ||
![]() |
4cc7aced15 | ||
![]() |
1058aeb04f | ||
![]() |
cfec0db947 | ||
![]() |
120bd6cd68 | ||
![]() |
9aef06d1b8 | ||
![]() |
e6e9dd751c | ||
![]() |
5dd677756f | ||
![]() |
b77c590910 | ||
![]() |
7e5f2822ae | ||
![]() |
12bbc7fd6b | ||
![]() |
bf9ac8252b | ||
![]() |
4a3f5dc619 | ||
![]() |
ca156befbd | ||
![]() |
4db41e2ac4 | ||
![]() |
982a43fce1 | ||
![]() |
dd76a74e1c | ||
![]() |
70cb52b2c7 | ||
![]() |
5c7f69acaa | ||
![]() |
f1d9015e5f | ||
![]() |
e8d900c58e | ||
![]() |
a6241ae912 | ||
![]() |
4a697ca2ec | ||
![]() |
58bec7f2c9 | ||
![]() |
213f84985c | ||
![]() |
074b1f8c61 | ||
![]() |
326eee8c83 | ||
![]() |
00bff4912e | ||
![]() |
0ce1720516 | ||
![]() |
ee407472cf | ||
![]() |
f341f3b2dd | ||
![]() |
8513946e09 | ||
![]() |
8ebd9c8927 | ||
![]() |
1d54c5144e | ||
![]() |
e40d4318fa | ||
![]() |
7756e10779 | ||
![]() |
3e58d502d0 | ||
![]() |
1c8846dc57 | ||
![]() |
2f320c7239 | ||
![]() |
e799918ab6 | ||
![]() |
86c4928e0f | ||
![]() |
0293eb5c51 | ||
![]() |
1ee75b6aa6 | ||
![]() |
4b30b224b5 | ||
![]() |
16b232d2a3 | ||
![]() |
3f3b1f5b1d | ||
![]() |
cec017b7bf | ||
![]() |
3123cc1059 | ||
![]() |
caa9df86bc | ||
![]() |
f417389a7a | ||
![]() |
662a5c8ea6 | ||
![]() |
7edfbfb764 | ||
![]() |
c1602d2554 | ||
![]() |
9f8d4e1022 | ||
![]() |
d1dfda405f | ||
![]() |
28efded624 | ||
![]() |
06c86ee267 | ||
![]() |
5892780871 | ||
![]() |
4fcdcd9a8a | ||
![]() |
80d834fb55 | ||
![]() |
4122ebe18f | ||
![]() |
7d87777bf8 | ||
![]() |
4a73d634e0 | ||
![]() |
373dc10a40 | ||
![]() |
ed43ec8ea2 | ||
![]() |
7918fc3528 | ||
![]() |
bf58205b0a | ||
![]() |
c0d1ce96d1 | ||
![]() |
b31d3802eb | ||
![]() |
be1228c3b4 | ||
![]() |
15c94c6b34 | ||
![]() |
202d23426a | ||
![]() |
fc26de48b2 | ||
![]() |
76c88913f9 | ||
![]() |
a3a1aed723 | ||
![]() |
81aa56f60f | ||
![]() |
73bb850209 | ||
![]() |
8dfec12330 | ||
![]() |
ae24397793 | ||
![]() |
3b0f888407 | ||
![]() |
845d1e02b0 | ||
![]() |
5d357bc41f | ||
![]() |
6a54672b13 | ||
![]() |
3d9a15df44 | ||
![]() |
449c7fda2f | ||
![]() |
8b7b05da68 | ||
![]() |
92400ebcab | ||
![]() |
23d3e56967 | ||
![]() |
6785dc4967 | ||
![]() |
dad20f6a2d | ||
![]() |
bb15671046 | ||
![]() |
21984fac8b | ||
![]() |
f392afe87f | ||
![]() |
6a243ec7bc | ||
![]() |
8cd3b603df | ||
![]() |
6e1aefe6d8 | ||
![]() |
1c90b6eca3 | ||
![]() |
c33cf9f878 | ||
![]() |
27cb40eec9 | ||
![]() |
c06081b75d | ||
![]() |
a7eec2f0a0 | ||
![]() |
4fd0fe3194 | ||
![]() |
cc74593ddd | ||
![]() |
fdb7c5dba1 | ||
![]() |
77470c7cfa | ||
![]() |
f0a734fdab | ||
![]() |
75405b2b25 | ||
![]() |
90ed4b3c49 | ||
![]() |
290a17a764 | ||
![]() |
aaabd836e4 | ||
![]() |
076e5cea3b | ||
![]() |
8515971ccf | ||
![]() |
d86fb033ea | ||
![]() |
99d7d8ddbc | ||
![]() |
df78fd2d41 | ||
![]() |
dabe6267b9 | ||
![]() |
0119ebddbe | ||
![]() |
3216ef9f47 | ||
![]() |
b79d1bcded | ||
![]() |
17e234f9d5 | ||
![]() |
ea1f75f80e | ||
![]() |
8c40db5730 | ||
![]() |
6fe03d2795 | ||
![]() |
c595a87ccf | ||
![]() |
fac07c3913 | ||
![]() |
c63fdbbc6b | ||
![]() |
2ff5d9606b | ||
![]() |
ed43452c1a | ||
![]() |
8f28d4028f | ||
![]() |
b54543b18c | ||
![]() |
966d6593ca | ||
![]() |
ad95b1c9d1 | ||
![]() |
3bfa38c60a | ||
![]() |
0bdbcad8be | ||
![]() |
80855e89ec | ||
![]() |
0850401dc4 | ||
![]() |
337fda2023 | ||
![]() |
64f238191e | ||
![]() |
eb169cb133 | ||
![]() |
80cd85b061 | ||
![]() |
89275270f3 | ||
![]() |
e7339ba619 | ||
![]() |
d9ad7d522c | ||
![]() |
92789c3113 | ||
![]() |
c1c677e161 | ||
![]() |
2fe917ff82 | ||
![]() |
0e6c205732 | ||
![]() |
125ae0a173 | ||
![]() |
0245e13591 | ||
![]() |
d546733287 | ||
![]() |
c275326d59 | ||
![]() |
d4561507b8 | ||
![]() |
ef0e22cc41 | ||
![]() |
62db65bf18 | ||
![]() |
d5371f752c | ||
![]() |
a5f5e94115 | ||
![]() |
2624706c69 | ||
![]() |
d39d885ec2 | ||
![]() |
d83c744725 | ||
![]() |
843995cdb9 | ||
![]() |
9491ba77e0 | ||
![]() |
58a449d437 | ||
![]() |
7f55e0f05b | ||
![]() |
67c3f40adb | ||
![]() |
ff7a0ba599 | ||
![]() |
b152c63102 | ||
![]() |
415ff23be5 | ||
![]() |
b0d6de783e | ||
![]() |
ac28e6e5ca | ||
![]() |
4f9e8d2e8a | ||
![]() |
21be2f46f3 | ||
![]() |
a6e7680212 | ||
![]() |
e79e744e08 | ||
![]() |
7abdac72a4 | ||
![]() |
90d85eaf7d | ||
![]() |
e65f9740fb | ||
![]() |
7538f89b56 | ||
![]() |
7c755a3991 | ||
![]() |
10e903c9fc | ||
![]() |
b018124226 | ||
![]() |
a9350f50c9 | ||
![]() |
ed7babcbf1 | ||
![]() |
61ebc335c4 | ||
![]() |
0167bd76f1 | ||
![]() |
79d704008b | ||
![]() |
0a703585b0 | ||
![]() |
5d632d0d90 | ||
![]() |
4eecaea601 | ||
![]() |
63055818ec | ||
![]() |
0beb08b687 | ||
![]() |
b27801a27c | ||
![]() |
a0cfce7cbc | ||
![]() |
8b7144c986 | ||
![]() |
d3f5f5ee59 | ||
![]() |
a2a3c7f438 | ||
![]() |
4496f82d5b | ||
![]() |
09d531557d | ||
![]() |
7fee82f731 | ||
![]() |
475054c48a | ||
![]() |
a743d05751 | ||
![]() |
d1ed502e03 | ||
![]() |
37744c7ab6 | ||
![]() |
bbc9e60a12 | ||
![]() |
6c975ecc4c | ||
![]() |
23e8a4ce4b | ||
![]() |
50134a2f9b | ||
![]() |
628b37c4fa | ||
![]() |
1b4ae70a43 | ||
![]() |
b25c49725f | ||
![]() |
b245782c7e | ||
![]() |
a9f32baae0 | ||
![]() |
e7ef71865d | ||
![]() |
88c4f72b37 | ||
![]() |
abbcdf91a5 | ||
![]() |
b876df6e21 | ||
![]() |
4bb81f35d7 | ||
![]() |
ff20267b3f | ||
![]() |
2c9586d811 | ||
![]() |
2813d2031a | ||
![]() |
065051a360 | ||
![]() |
db218407b0 | ||
![]() |
d52210dd90 | ||
![]() |
f3cd9a096a | ||
![]() |
e426090a18 | ||
![]() |
cbe64fd559 | ||
![]() |
63ea7a70bd | ||
![]() |
fb0998f7a2 | ||
![]() |
a9b00dd537 | ||
![]() |
52eb059515 | ||
![]() |
7640246255 | ||
![]() |
52c83b2916 | ||
![]() |
d9cded0fc9 | ||
![]() |
750c42caf1 | ||
![]() |
bbf650c6cf | ||
![]() |
a25dace7e0 | ||
![]() |
14ff22fbcd | ||
![]() |
07eb7dda2d | ||
![]() |
d4058175b4 | ||
![]() |
2de984ae24 | ||
![]() |
761a8bf2a9 | ||
![]() |
6df7006b36 | ||
![]() |
aceb3ee863 | ||
![]() |
11d716a3c8 | ||
![]() |
7cc8c014eb | ||
![]() |
f21241d944 | ||
![]() |
a181fa0652 | ||
![]() |
3f748b4d2a | ||
![]() |
683450f9c6 | ||
![]() |
adbd47a36c | ||
![]() |
ce693aa5e9 | ||
![]() |
ad80804461 | ||
![]() |
2d55632430 | ||
![]() |
e81f00ef1a | ||
![]() |
93fb0e3d74 | ||
![]() |
71ce0de606 | ||
![]() |
0407062c1d | ||
![]() |
cda14af208 | ||
![]() |
258f170cd7 | ||
![]() |
f76015d714 | ||
![]() |
7e5e14163c | ||
![]() |
bcd1064e94 | ||
![]() |
8a8441c875 | ||
![]() |
15aa813416 | ||
![]() |
605faccffd | ||
![]() |
79f2d08c81 | ||
![]() |
0568ae5391 | ||
![]() |
5330dda9f8 | ||
![]() |
ebab126579 | ||
![]() |
0e5417a13e | ||
![]() |
9a968e0584 | ||
![]() |
ffec64d209 | ||
![]() |
f332746188 | ||
![]() |
b2fa5b551e | ||
![]() |
36e83edddc | ||
![]() |
6b045eadef | ||
![]() |
147264822c | ||
![]() |
36e4ccd800 | ||
![]() |
796c16237d | ||
![]() |
861ad9881c | ||
![]() |
3101c538e9 | ||
![]() |
42adc7382f | ||
![]() |
9bb4dfad13 | ||
![]() |
bd00ae8ede | ||
![]() |
f309522268 | ||
![]() |
0efaddff23 | ||
![]() |
94ba7cb0c5 | ||
![]() |
2d58c725e0 | ||
![]() |
e035523eb8 | ||
![]() |
bea5308ab7 | ||
![]() |
f006a85fec | ||
![]() |
ea93013ebc |
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -11,7 +11,7 @@
|
|||||||
*.bat text eol=crlf
|
*.bat text eol=crlf
|
||||||
|
|
||||||
# Denote all files that are truly binary and should not be modified.
|
# Denote all files that are truly binary and should not be modified.
|
||||||
chromeos/** binary
|
tools/** binary
|
||||||
*.jar binary
|
*.jar binary
|
||||||
*.exe binary
|
*.exe binary
|
||||||
*.apk binary
|
*.apk binary
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,8 +2,8 @@ out
|
|||||||
*.zip
|
*.zip
|
||||||
*.jks
|
*.jks
|
||||||
*.apk
|
*.apk
|
||||||
config.prop
|
/config.prop
|
||||||
update.sh
|
/update.sh
|
||||||
|
|
||||||
# Built binaries
|
# Built binaries
|
||||||
native/out
|
native/out
|
||||||
|
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -19,3 +19,9 @@
|
|||||||
[submodule "nanopb"]
|
[submodule "nanopb"]
|
||||||
path = native/jni/external/nanopb
|
path = native/jni/external/nanopb
|
||||||
url = https://github.com/nanopb/nanopb.git
|
url = https://github.com/nanopb/nanopb.git
|
||||||
|
[submodule "mincrypt"]
|
||||||
|
path = native/jni/external/mincrypt
|
||||||
|
url = https://github.com/topjohnwu/mincrypt.git
|
||||||
|
[submodule "termux-elf-cleaner"]
|
||||||
|
path = tools/termux-elf-cleaner
|
||||||
|
url = https://github.com/termux/termux-elf-cleaner.git
|
||||||
|
@@ -10,7 +10,7 @@ Furthermore, Magisk provides a **Systemless Interface** to alter the system (or
|
|||||||
|
|
||||||
## Bug Reports
|
## Bug Reports
|
||||||
|
|
||||||
**Make sure to install the latest [Canary Build](https://forum.xda-developers.com/apps/magisk/dev-magisk-canary-channel-bleeding-edge-t3839337) before reporting any bugs!** **DO NOT** report bugs that is already fixed upstream. Follow the instructions in the [Canary Channel XDA Thread](https://forum.xda-developers.com/apps/magisk/dev-magisk-canary-channel-bleeding-edge-t3839337), and report a bug either by opening an issue on GitHub or directly in the thread.
|
**Make sure to install the latest [Canary Build](https://forum.xda-developers.com/apps/magisk/dev-magisk-canary-channel-bleeding-edge-t3839337) before reporting any bugs!** **DO NOT** report bugs that are already fixed upstream. Follow the instructions in the [Canary Channel XDA Thread](https://forum.xda-developers.com/apps/magisk/dev-magisk-canary-channel-bleeding-edge-t3839337), and report a bug either by [opening an issue on GitHub](https://github.com/topjohnwu/Magisk/issues) or directly in the thread.
|
||||||
|
|
||||||
## Building Environment Requirements
|
## Building Environment Requirements
|
||||||
|
|
||||||
@@ -30,13 +30,12 @@ Furthermore, Magisk provides a **Systemless Interface** to alter the system (or
|
|||||||
|
|
||||||
## Translations
|
## Translations
|
||||||
|
|
||||||
Default string resources for Magisk Manager are scattered throughout
|
Default string resources for Magisk Manager and its stub APK are located here:
|
||||||
|
|
||||||
- `app/src/main/res/values/strings.xml`
|
- `app/src/main/res/values/strings.xml`
|
||||||
- `stub/src/main/res/values/strings.xml`
|
- `stub/src/main/res/values/strings.xml`
|
||||||
- `shared/src/main/res/values/strings.xml`
|
|
||||||
|
|
||||||
Translate each and place them in the respective locations (`<module>/src/main/res/values-<lang>/strings.xml`).
|
Translate each and place them in the respective locations (`[module]/src/main/res/values-[lang]/strings.xml`).
|
||||||
|
|
||||||
## Signature Verification
|
## Signature Verification
|
||||||
|
|
||||||
|
132
app/build.gradle
132
app/build.gradle
@@ -1,6 +1,6 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'kotlin-android-extensions'
|
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
|
apply plugin: 'kotlin-android-extensions'
|
||||||
apply plugin: 'kotlin-kapt'
|
apply plugin: 'kotlin-kapt'
|
||||||
|
|
||||||
kapt {
|
kapt {
|
||||||
@@ -16,51 +16,119 @@ android {
|
|||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId 'com.topjohnwu.magisk'
|
applicationId 'com.topjohnwu.magisk'
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
versionName configProps['appVersion']
|
multiDexEnabled true
|
||||||
versionCode configProps['appVersionCode'] as Integer
|
versionName props['appVersion']
|
||||||
javaCompileOptions {
|
versionCode props['appVersionCode'] as Integer
|
||||||
annotationProcessorOptions {
|
|
||||||
argument('butterknife.debuggable', 'false')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
release {
|
release {
|
||||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
minifyEnabled true
|
||||||
|
shrinkResources true
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
|
||||||
|
'proguard-rules.pro', 'proguard-kotlin.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dataBinding {
|
||||||
|
enabled = true
|
||||||
|
}
|
||||||
|
|
||||||
|
packagingOptions {
|
||||||
|
exclude '/META-INF/*.version'
|
||||||
|
exclude '/META-INF/*.kotlin_module'
|
||||||
|
exclude '/META-INF/rxkotlin.properties'
|
||||||
|
exclude '/androidsupportmultidexversion.txt'
|
||||||
|
exclude '/org/bouncycastle/**'
|
||||||
|
exclude '/kotlin/**'
|
||||||
|
exclude '/kotlinx/**'
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinOptions {
|
||||||
|
jvmTarget = '1.8'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
androidExtensions {
|
||||||
|
experimental = true
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation project(':net')
|
|
||||||
implementation project(':shared')
|
implementation project(':shared')
|
||||||
implementation project(':signing')
|
implementation project(':signing')
|
||||||
|
|
||||||
implementation 'com.github.topjohnwu:jtar:1.0.0'
|
implementation 'com.github.topjohnwu:jtar:1.0.0'
|
||||||
implementation 'net.sourceforge.streamsupport:android-retrostreams:1.7.0'
|
implementation 'com.jakewharton.timber:timber:4.7.1'
|
||||||
implementation 'com.github.sevar83:indeterminate-checkbox:1.0.5'
|
implementation 'com.ncapdevi:frag-nav:3.2.0'
|
||||||
|
implementation 'com.github.pwittchen:reactivenetwork-rx2:3.0.6'
|
||||||
|
|
||||||
def markwonVersion = '3.0.0'
|
implementation 'io.reactivex.rxjava2:rxjava:2.2.13'
|
||||||
implementation "ru.noties.markwon:core:${markwonVersion}"
|
implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
|
||||||
implementation "ru.noties.markwon:html:${markwonVersion}"
|
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
||||||
implementation "ru.noties.markwon:image-svg:${markwonVersion}"
|
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:${vKotlin}"
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${vKotlin}"
|
||||||
|
|
||||||
|
def vBAdapt = '3.1.1'
|
||||||
|
def bindingAdapter = 'me.tatarka.bindingcollectionadapter2:bindingcollectionadapter'
|
||||||
|
implementation "${bindingAdapter}:${vBAdapt}"
|
||||||
|
implementation "${bindingAdapter}-recyclerview:${vBAdapt}"
|
||||||
|
|
||||||
|
def vMarkwon = '4.1.2'
|
||||||
|
implementation "io.noties.markwon:core:${vMarkwon}"
|
||||||
|
implementation "io.noties.markwon:html:${vMarkwon}"
|
||||||
|
implementation "io.noties.markwon:image:${vMarkwon}"
|
||||||
|
implementation 'com.caverock:androidsvg:1.4'
|
||||||
|
|
||||||
|
def vLibsu = '2.5.1'
|
||||||
|
implementation "com.github.topjohnwu.libsu:core:${vLibsu}"
|
||||||
|
implementation "com.github.topjohnwu.libsu:io:${vLibsu}"
|
||||||
|
|
||||||
|
def vKoin = "2.0.1"
|
||||||
|
implementation "org.koin:koin-core:${vKoin}"
|
||||||
|
implementation "org.koin:koin-android:${vKoin}"
|
||||||
|
implementation "org.koin:koin-androidx-viewmodel:${vKoin}"
|
||||||
|
|
||||||
|
def vRetrofit = '2.6.2'
|
||||||
|
implementation "com.squareup.retrofit2:retrofit:${vRetrofit}"
|
||||||
|
implementation "com.squareup.retrofit2:converter-moshi:${vRetrofit}"
|
||||||
|
implementation "com.squareup.retrofit2:converter-scalars:${vRetrofit}"
|
||||||
|
implementation "com.squareup.retrofit2:adapter-rxjava2:${vRetrofit}"
|
||||||
|
|
||||||
|
def vOkHttp = '3.12.6'
|
||||||
|
implementation "com.squareup.okhttp3:okhttp:${vOkHttp}"
|
||||||
|
implementation "com.squareup.okhttp3:logging-interceptor:${vOkHttp}"
|
||||||
|
|
||||||
|
def vMoshi = "1.8.0"
|
||||||
|
implementation "com.squareup.moshi:moshi:${vMoshi}"
|
||||||
|
|
||||||
|
def vKotshi = "2.0.1"
|
||||||
|
implementation "se.ansman.kotshi:api:${vKotshi}"
|
||||||
|
kapt "se.ansman.kotshi:compiler:${vKotshi}"
|
||||||
|
|
||||||
|
modules {
|
||||||
|
module('androidx.room:room-runtime') {
|
||||||
|
replacedBy('com.github.topjohnwu:room-runtime')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
def vRoom = "2.2.1"
|
||||||
|
implementation "com.github.topjohnwu:room-runtime:${vRoom}"
|
||||||
|
kapt "androidx.room:room-compiler:${vRoom}"
|
||||||
|
|
||||||
|
def vNav = "2.1.0"
|
||||||
|
implementation "androidx.navigation:navigation-fragment-ktx:$vNav"
|
||||||
|
implementation "androidx.navigation:navigation-ui-ktx:$vNav"
|
||||||
|
|
||||||
def androidXVersion = "1.0.0"
|
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03'
|
||||||
implementation "androidx.preference:preference:${androidXVersion}"
|
implementation 'androidx.preference:preference:1.1.0'
|
||||||
implementation "androidx.recyclerview:recyclerview:${androidXVersion}"
|
implementation 'androidx.recyclerview:recyclerview:1.1.0-rc01'
|
||||||
implementation "androidx.cardview:cardview:${androidXVersion}"
|
implementation 'androidx.fragment:fragment-ktx:1.2.0-rc01'
|
||||||
implementation "com.google.android.material:material:${androidXVersion}"
|
implementation 'androidx.cardview:cardview:1.0.0'
|
||||||
implementation 'androidx.work:work-runtime:2.0.1'
|
implementation 'androidx.work:work-runtime:2.2.0'
|
||||||
implementation 'androidx.transition:transition:1.1.0-beta01'
|
implementation 'androidx.transition:transition:1.3.0-rc01'
|
||||||
|
implementation 'androidx.multidex:multidex:2.0.1'
|
||||||
def libsuVersion = '2.5.0'
|
implementation 'androidx.core:core-ktx:1.1.0'
|
||||||
implementation "com.github.topjohnwu.libsu:core:${libsuVersion}"
|
implementation 'com.google.android.material:material:1.2.0-alpha01'
|
||||||
implementation "com.github.topjohnwu.libsu:io:${libsuVersion}"
|
|
||||||
|
|
||||||
def butterKnifeVersion = '10.1.0'
|
|
||||||
implementation "com.jakewharton:butterknife-runtime:${butterKnifeVersion}"
|
|
||||||
kapt "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
|
|
||||||
}
|
}
|
||||||
|
20
app/proguard-kotlin.pro
Normal file
20
app/proguard-kotlin.pro
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
## So every class is case insensitive to avoid some bizare problems
|
||||||
|
-dontusemixedcaseclassnames
|
||||||
|
|
||||||
|
## If reflection issues come up uncomment this, that should temporarily fix it
|
||||||
|
#-keep class kotlin.** { *; }
|
||||||
|
#-keep class kotlin.Metadata { *; }
|
||||||
|
#-keepclassmembers class kotlin.Metadata {
|
||||||
|
# public <methods>;
|
||||||
|
#}
|
||||||
|
|
||||||
|
## Never warn about Kotlin, it should work as-is
|
||||||
|
-dontwarn kotlin.**
|
||||||
|
|
||||||
|
## Removes runtime null checks - doesn't really matter if it crashes on kotlin or java NPE
|
||||||
|
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
|
||||||
|
static void checkParameterIsNotNull(java.lang.Object, java.lang.String);
|
||||||
|
}
|
||||||
|
|
||||||
|
## Useless option for dex
|
||||||
|
-dontpreverify
|
33
app/proguard-rules.pro
vendored
33
app/proguard-rules.pro
vendored
@@ -16,35 +16,30 @@
|
|||||||
# public *;
|
# public *;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
# BouncyCastle
|
|
||||||
-keep,allowoptimization class org.bouncycastle.jcajce.provider.asymmetric.rsa.**SHA1** { *; }
|
|
||||||
-keep,allowoptimization class org.bouncycastle.jcajce.provider.asymmetric.RSA** { *; }
|
|
||||||
-keep,allowoptimization class org.bouncycastle.jcajce.provider.digest.SHA1** { *; }
|
|
||||||
-dontwarn javax.naming.**
|
|
||||||
|
|
||||||
# Snet
|
# Snet
|
||||||
-keepclassmembers class com.topjohnwu.magisk.utils.ISafetyNetHelper { *; }
|
-keepclassmembers class com.topjohnwu.magisk.utils.SafetyNetHelper { *; }
|
||||||
-keep,allowobfuscation interface com.topjohnwu.magisk.utils.ISafetyNetHelper$Callback
|
-keep,allowobfuscation interface com.topjohnwu.magisk.utils.SafetyNetHelper$Callback
|
||||||
-keepclassmembers class * implements com.topjohnwu.magisk.utils.ISafetyNetHelper$Callback {
|
-keepclassmembers class * implements com.topjohnwu.magisk.utils.SafetyNetHelper$Callback {
|
||||||
void onResponse(int);
|
void onResponse(int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Keep all fragment constructors
|
||||||
|
-keepclassmembers class * extends androidx.fragment.app.Fragment {
|
||||||
|
public <init>(...);
|
||||||
|
}
|
||||||
|
|
||||||
# DelegateWorker
|
# DelegateWorker
|
||||||
-keep,allowobfuscation class * extends com.topjohnwu.magisk.model.worker.DelegateWorker
|
-keep,allowobfuscation class * extends com.topjohnwu.magisk.base.DelegateWorker
|
||||||
|
|
||||||
# BootSigner
|
# BootSigner
|
||||||
-keepclassmembers class com.topjohnwu.signing.BootSigner { *; }
|
-keep class a.a { *; }
|
||||||
|
|
||||||
# SVG
|
# Workaround R8 bug
|
||||||
-dontwarn com.caverock.androidsvg.SVGAndroidRenderer
|
-keep,allowobfuscation class com.topjohnwu.magisk.model.receiver.GeneralReceiver
|
||||||
|
-keepclassmembers class a.e { *; }
|
||||||
# RetroStreams
|
|
||||||
-dontwarn java9.**
|
|
||||||
|
|
||||||
# Strip logging
|
# Strip logging
|
||||||
-assumenosideeffects class com.topjohnwu.magisk.utils.Logger {
|
-assumenosideeffects class timber.log.Timber.Tree { *; }
|
||||||
public *** debug(...);
|
|
||||||
}
|
|
||||||
|
|
||||||
# Excessive obfuscation
|
# Excessive obfuscation
|
||||||
-repackageclasses 'a'
|
-repackageclasses 'a'
|
||||||
|
5
app/res-ids.txt
Normal file
5
app/res-ids.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
com.topjohnwu.magisk:color/xxxxxxxx = 0x7f010000
|
||||||
|
com.topjohnwu.magisk:drawable/xxxxxxxx = 0x7f020000
|
||||||
|
com.topjohnwu.magisk:string/xxxxxxxx = 0x7f030000
|
||||||
|
com.topjohnwu.magisk:style/xxxxxxxx = 0x7f040000
|
||||||
|
com.topjohnwu.magisk:xml/xxxxxxxx = 0x7f050000
|
@@ -1,50 +1,74 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
** Special Requirements **
|
||||||
|
|
||||||
|
This AndroidManifest.xml will be copied into the stub
|
||||||
|
APK to allow APK delegation. This is why these special
|
||||||
|
requirements exist.
|
||||||
|
|
||||||
|
* Class names *
|
||||||
|
Class names a.a, a.c, a.e should not be changed as they are used
|
||||||
|
externally. All other class names can be changed.
|
||||||
|
|
||||||
|
* Resource IDs *
|
||||||
|
All resource IDs referred in AndroidManifest.xml is required to be
|
||||||
|
included into the "shared" module to make the ID match with stub.
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.topjohnwu.magisk">
|
package="com.topjohnwu.magisk">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
|
||||||
android:name="a.e"
|
android:name="a.e"
|
||||||
android:theme="@style/AppTheme"
|
android:appComponentFactory="a.a"
|
||||||
|
android:allowBackup="true"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
tools:ignore="UnusedAttribute,GoogleAppIndexingWarning">
|
tools:ignore="UnusedAttribute,GoogleAppIndexingWarning"
|
||||||
|
tools:replace="android:appComponentFactory">
|
||||||
|
|
||||||
<!-- Activities -->
|
<!-- Splash -->
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name="a.b"
|
|
||||||
android:configChanges="orientation|screenSize"
|
|
||||||
android:exported="true" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="a.c"
|
android:name="a.c"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
android:exported="true"
|
|
||||||
android:theme="@style/SplashTheme">
|
android:theme="@style/SplashTheme">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<!-- Main -->
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="a.b"
|
||||||
|
android:configChanges="orientation|screenSize"
|
||||||
|
android:exported="true" />
|
||||||
|
|
||||||
|
<!-- Flashing -->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="a.f"
|
android:name="a.f"
|
||||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||||
android:screenOrientation="nosensor"
|
android:screenOrientation="nosensor" />
|
||||||
android:theme="@style/AppTheme.NoDrawer" />
|
|
||||||
|
|
||||||
<!-- Superuser -->
|
<!-- Superuser -->
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="a.m"
|
android:name="a.m"
|
||||||
android:exported="false"
|
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||||
android:directBootAware="true"
|
android:directBootAware="true"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:theme="@style/SuRequest" />
|
android:exported="false" />
|
||||||
|
|
||||||
<!-- Receiver -->
|
<!-- Receiver -->
|
||||||
|
|
||||||
@@ -52,6 +76,7 @@
|
|||||||
android:name="a.h"
|
android:name="a.h"
|
||||||
android:directBootAware="true">
|
android:directBootAware="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.REBOOT" />
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.LOCALE_CHANGED" />
|
<action android:name="android.intent.action.LOCALE_CHANGED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -63,15 +88,23 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
<!-- Service -->
|
<!-- DownloadService -->
|
||||||
|
|
||||||
<service android:name="a.j" />
|
<service
|
||||||
|
android:name="a.j"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<!-- Hardcode GMS version -->
|
<!-- Hardcode GMS version -->
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.gms.version"
|
android:name="com.google.android.gms.version"
|
||||||
android:value="12451000" />
|
android:value="12451000" />
|
||||||
|
|
||||||
|
<!-- Initialize WorkManager on-demand -->
|
||||||
|
<provider
|
||||||
|
android:name="androidx.work.impl.WorkManagerInitializer"
|
||||||
|
android:authorities="${applicationId}.workmanager-init"
|
||||||
|
tools:node="remove" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@@ -1,13 +1,22 @@
|
|||||||
package a;
|
package a;
|
||||||
|
|
||||||
|
import androidx.core.app.AppComponentFactory;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.utils.PatchAPK;
|
import com.topjohnwu.magisk.utils.PatchAPK;
|
||||||
import com.topjohnwu.signing.BootSigner;
|
import com.topjohnwu.signing.BootSigner;
|
||||||
|
|
||||||
import androidx.annotation.Keep;
|
public class a extends AppComponentFactory {
|
||||||
|
|
||||||
@Keep
|
@Deprecated
|
||||||
public class a extends BootSigner {
|
|
||||||
public static boolean patchAPK(String in, String out, String pkg) {
|
public static boolean patchAPK(String in, String out, String pkg) {
|
||||||
return PatchAPK.patch(in, out, pkg);
|
return PatchAPK.patch(in, out, pkg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean patchAPK(String in, String out, String pkg, String label) {
|
||||||
|
return PatchAPK.patch(in, out, pkg, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
BootSigner.main(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,5 +3,11 @@ package a;
|
|||||||
import com.topjohnwu.magisk.App;
|
import com.topjohnwu.magisk.App;
|
||||||
|
|
||||||
public class e extends App {
|
public class e extends App {
|
||||||
/* stub */
|
public e() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public e(Object o) {
|
||||||
|
super(o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package a;
|
package a;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.model.download.DownloadModuleService;
|
import com.topjohnwu.magisk.model.download.DownloadService;
|
||||||
|
|
||||||
public class j extends DownloadModuleService {
|
public class j extends DownloadService {
|
||||||
/* stub */
|
/* stub */
|
||||||
}
|
}
|
||||||
|
@@ -2,14 +2,14 @@ package a;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.model.worker.DelegateWorker;
|
|
||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.work.Worker;
|
import androidx.work.Worker;
|
||||||
import androidx.work.WorkerParameters;
|
import androidx.work.WorkerParameters;
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.base.DelegateWorker;
|
||||||
|
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
|
|
||||||
public abstract class w<T extends DelegateWorker> extends Worker {
|
public abstract class w<T extends DelegateWorker> extends Worker {
|
||||||
|
|
||||||
/* Wrapper class to workaround Proguard -keep class * extends Worker */
|
/* Wrapper class to workaround Proguard -keep class * extends Worker */
|
||||||
@@ -22,7 +22,7 @@ public abstract class w<T extends DelegateWorker> extends Worker {
|
|||||||
try {
|
try {
|
||||||
base = ((Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
|
base = ((Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
|
||||||
.getActualTypeArguments()[0]).newInstance();
|
.getActualTypeArguments()[0]).newInstance();
|
||||||
base.setActualWorker(this);
|
base.attachWorker(this);
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,101 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Application;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.data.database.MagiskDB;
|
|
||||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper;
|
|
||||||
import com.topjohnwu.magisk.ui.base.BaseActivity;
|
|
||||||
import com.topjohnwu.magisk.utils.LocaleManager;
|
|
||||||
import com.topjohnwu.magisk.utils.RootUtils;
|
|
||||||
import com.topjohnwu.net.Networking;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
|
||||||
|
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
|
|
||||||
public class App extends Application implements Application.ActivityLifecycleCallbacks {
|
|
||||||
|
|
||||||
public static App self;
|
|
||||||
public static Context deContext;
|
|
||||||
public static ThreadPoolExecutor THREAD_POOL;
|
|
||||||
|
|
||||||
// Global resources
|
|
||||||
public SharedPreferences prefs;
|
|
||||||
public MagiskDB mDB;
|
|
||||||
public RepoDatabaseHelper repoDB;
|
|
||||||
private volatile BaseActivity foreground;
|
|
||||||
|
|
||||||
static {
|
|
||||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
|
||||||
Shell.Config.setFlags(Shell.FLAG_MOUNT_MASTER | Shell.FLAG_USE_MAGISK_BUSYBOX);
|
|
||||||
Shell.Config.verboseLogging(BuildConfig.DEBUG);
|
|
||||||
Shell.Config.addInitializers(RootUtils.class);
|
|
||||||
Shell.Config.setTimeout(2);
|
|
||||||
THREAD_POOL = (ThreadPoolExecutor) AsyncTask.THREAD_POOL_EXECUTOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void attachBaseContext(Context base) {
|
|
||||||
super.attachBaseContext(base);
|
|
||||||
self = this;
|
|
||||||
deContext = base;
|
|
||||||
registerActivityLifecycleCallbacks(this);
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 24) {
|
|
||||||
deContext = base.createDeviceProtectedStorageContext();
|
|
||||||
deContext.moveSharedPreferencesFrom(base,
|
|
||||||
PreferenceManager.getDefaultSharedPreferencesName(base));
|
|
||||||
}
|
|
||||||
prefs = PreferenceManager.getDefaultSharedPreferences(deContext);
|
|
||||||
mDB = new MagiskDB(base);
|
|
||||||
|
|
||||||
Networking.init(base);
|
|
||||||
LocaleManager.setLocale(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
|
||||||
super.onConfigurationChanged(newConfig);
|
|
||||||
LocaleManager.setLocale(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BaseActivity foreground() {
|
|
||||||
return self.foreground;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityStarted(@NonNull Activity activity) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onActivityResumed(@NonNull Activity activity) {
|
|
||||||
foreground = (BaseActivity) activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onActivityPaused(@NonNull Activity activity) {
|
|
||||||
foreground = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityStopped(@NonNull Activity activity) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityDestroyed(@NonNull Activity activity) {}
|
|
||||||
}
|
|
85
app/src/main/java/com/topjohnwu/magisk/App.kt
Normal file
85
app/src/main/java/com/topjohnwu/magisk/App.kt
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package com.topjohnwu.magisk
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.multidex.MultiDex
|
||||||
|
import androidx.room.Room
|
||||||
|
import androidx.work.WorkManager
|
||||||
|
import androidx.work.impl.WorkDatabase
|
||||||
|
import androidx.work.impl.WorkDatabase_Impl
|
||||||
|
import com.topjohnwu.magisk.data.database.RepoDatabase
|
||||||
|
import com.topjohnwu.magisk.data.database.RepoDatabase_Impl
|
||||||
|
import com.topjohnwu.magisk.di.ActivityTracker
|
||||||
|
import com.topjohnwu.magisk.di.koinModules
|
||||||
|
import com.topjohnwu.magisk.extensions.get
|
||||||
|
import com.topjohnwu.magisk.extensions.unwrap
|
||||||
|
import com.topjohnwu.magisk.utils.RootInit
|
||||||
|
import com.topjohnwu.magisk.utils.updateConfig
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import org.koin.android.ext.koin.androidContext
|
||||||
|
import org.koin.core.context.startKoin
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
open class App() : Application() {
|
||||||
|
|
||||||
|
constructor(o: Any) : this() {
|
||||||
|
Info.stub = DynAPK.load(o)
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
|
||||||
|
Shell.Config.setFlags(Shell.FLAG_MOUNT_MASTER or Shell.FLAG_USE_MAGISK_BUSYBOX)
|
||||||
|
Shell.Config.verboseLogging(BuildConfig.DEBUG)
|
||||||
|
Shell.Config.addInitializers(RootInit::class.java)
|
||||||
|
Shell.Config.setTimeout(2)
|
||||||
|
Room.setFactory {
|
||||||
|
when (it) {
|
||||||
|
WorkDatabase::class.java -> WorkDatabase_Impl()
|
||||||
|
RepoDatabase::class.java -> RepoDatabase_Impl()
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun attachBaseContext(base: Context) {
|
||||||
|
// Basic setup
|
||||||
|
if (BuildConfig.DEBUG)
|
||||||
|
MultiDex.install(base)
|
||||||
|
Timber.plant(Timber.DebugTree())
|
||||||
|
|
||||||
|
// Some context magic
|
||||||
|
val app: Application
|
||||||
|
val impl: Context
|
||||||
|
if (base is Application) {
|
||||||
|
app = base
|
||||||
|
impl = base.baseContext
|
||||||
|
} else {
|
||||||
|
app = this
|
||||||
|
impl = base
|
||||||
|
}
|
||||||
|
val wrapped = impl.wrap()
|
||||||
|
super.attachBaseContext(wrapped)
|
||||||
|
|
||||||
|
// Normal startup
|
||||||
|
startKoin {
|
||||||
|
androidContext(wrapped)
|
||||||
|
modules(koinModules)
|
||||||
|
}
|
||||||
|
ResourceMgr.init(impl)
|
||||||
|
app.registerActivityLifecycleCallbacks(get<ActivityTracker>())
|
||||||
|
WorkManager.initialize(impl.wrapJob(), androidx.work.Configuration.Builder().build())
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is required as some platforms expect ContextImpl
|
||||||
|
override fun getBaseContext(): Context {
|
||||||
|
return super.getBaseContext().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
resources.updateConfig(newConfig)
|
||||||
|
if (!isRunningAsStub)
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
}
|
||||||
|
}
|
@@ -1,31 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.model.download.DownloadModuleService;
|
|
||||||
import com.topjohnwu.magisk.model.receiver.GeneralReceiver;
|
|
||||||
import com.topjohnwu.magisk.model.update.UpdateCheckService;
|
|
||||||
import com.topjohnwu.magisk.ui.MainActivity;
|
|
||||||
import com.topjohnwu.magisk.ui.SplashActivity;
|
|
||||||
import com.topjohnwu.magisk.ui.flash.FlashActivity;
|
|
||||||
import com.topjohnwu.magisk.ui.surequest.SuRequestActivity;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ClassMap {
|
|
||||||
private static Map<Class, Class> classMap = new HashMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
classMap.put(App.class, a.e.class);
|
|
||||||
classMap.put(MainActivity.class, a.b.class);
|
|
||||||
classMap.put(SplashActivity.class, a.c.class);
|
|
||||||
classMap.put(FlashActivity.class, a.f.class);
|
|
||||||
classMap.put(UpdateCheckService.class, a.g.class);
|
|
||||||
classMap.put(GeneralReceiver.class, a.h.class);
|
|
||||||
classMap.put(DownloadModuleService.class, a.j.class);
|
|
||||||
classMap.put(SuRequestActivity.class, a.m.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <T> Class<T> get(Class c) {
|
|
||||||
return classMap.get(c);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,396 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.util.Xml;
|
|
||||||
|
|
||||||
import androidx.collection.ArrayMap;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
|
||||||
import com.topjohnwu.superuser.ShellUtils;
|
|
||||||
import com.topjohnwu.superuser.io.SuFile;
|
|
||||||
import com.topjohnwu.superuser.io.SuFileInputStream;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class Config {
|
|
||||||
|
|
||||||
// Current status
|
|
||||||
public static String magiskVersionString;
|
|
||||||
public static int magiskVersionCode = -1;
|
|
||||||
private static boolean magiskHide;
|
|
||||||
|
|
||||||
// Update Info
|
|
||||||
public static String remoteMagiskVersionString;
|
|
||||||
public static int remoteMagiskVersionCode = -1;
|
|
||||||
public static String magiskLink;
|
|
||||||
public static String magiskNoteLink;
|
|
||||||
public static String magiskMD5;
|
|
||||||
public static String remoteManagerVersionString;
|
|
||||||
public static int remoteManagerVersionCode = -1;
|
|
||||||
public static String managerLink;
|
|
||||||
public static String managerNoteLink;
|
|
||||||
public static String uninstallerLink;
|
|
||||||
|
|
||||||
// Install flags
|
|
||||||
public static boolean keepVerity = false;
|
|
||||||
public static boolean keepEnc = false;
|
|
||||||
public static boolean recovery = false;
|
|
||||||
|
|
||||||
public static int suLogTimeout = 14;
|
|
||||||
|
|
||||||
public static class Key {
|
|
||||||
// su configs
|
|
||||||
public static final String ROOT_ACCESS = "root_access";
|
|
||||||
public static final String SU_MULTIUSER_MODE = "multiuser_mode";
|
|
||||||
public static final String SU_MNT_NS = "mnt_ns";
|
|
||||||
public static final String SU_MANAGER = "requester";
|
|
||||||
public static final String SU_REQUEST_TIMEOUT = "su_request_timeout";
|
|
||||||
public static final String SU_AUTO_RESPONSE = "su_auto_response";
|
|
||||||
public static final String SU_NOTIFICATION = "su_notification";
|
|
||||||
public static final String SU_REAUTH = "su_reauth";
|
|
||||||
public static final String SU_FINGERPRINT = "su_fingerprint";
|
|
||||||
|
|
||||||
// prefs
|
|
||||||
public static final String CHECK_UPDATES = "check_update";
|
|
||||||
public static final String UPDATE_CHANNEL = "update_channel";
|
|
||||||
public static final String CUSTOM_CHANNEL = "custom_channel";
|
|
||||||
public static final String LOCALE = "locale";
|
|
||||||
public static final String DARK_THEME = "dark_theme";
|
|
||||||
public static final String ETAG_KEY = "ETag";
|
|
||||||
public static final String REPO_ORDER = "repo_order";
|
|
||||||
public static final String SHOW_SYSTEM_APP = "show_system";
|
|
||||||
|
|
||||||
// system state
|
|
||||||
public static final String UPDATE_SERVICE_VER = "update_service_version";
|
|
||||||
public static final String MAGISKHIDE = "magiskhide";
|
|
||||||
public static final String COREONLY = "disable";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Value {
|
|
||||||
public static final int DEFAULT_CHANNEL = -1;
|
|
||||||
public static final int STABLE_CHANNEL = 0;
|
|
||||||
public static final int BETA_CHANNEL = 1;
|
|
||||||
public static final int CUSTOM_CHANNEL = 2;
|
|
||||||
public static final int CANARY_CHANNEL = 3;
|
|
||||||
public static final int CANARY_DEBUG_CHANNEL = 4;
|
|
||||||
public static final int ROOT_ACCESS_DISABLED = 0;
|
|
||||||
public static final int ROOT_ACCESS_APPS_ONLY = 1;
|
|
||||||
public static final int ROOT_ACCESS_ADB_ONLY = 2;
|
|
||||||
public static final int ROOT_ACCESS_APPS_AND_ADB = 3;
|
|
||||||
public static final int MULTIUSER_MODE_OWNER_ONLY = 0;
|
|
||||||
public static final int MULTIUSER_MODE_OWNER_MANAGED = 1;
|
|
||||||
public static final int MULTIUSER_MODE_USER = 2;
|
|
||||||
public static final int NAMESPACE_MODE_GLOBAL = 0;
|
|
||||||
public static final int NAMESPACE_MODE_REQUESTER = 1;
|
|
||||||
public static final int NAMESPACE_MODE_ISOLATE = 2;
|
|
||||||
public static final int NO_NOTIFICATION = 0;
|
|
||||||
public static final int NOTIFICATION_TOAST = 1;
|
|
||||||
public static final int SU_PROMPT = 0;
|
|
||||||
public static final int SU_AUTO_DENY = 1;
|
|
||||||
public static final int SU_AUTO_ALLOW = 2;
|
|
||||||
public static final int[] TIMEOUT_LIST = {0, -1, 10, 20, 30, 60};
|
|
||||||
public static final int ORDER_NAME = 0;
|
|
||||||
public static final int ORDER_DATE = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadMagiskInfo() {
|
|
||||||
try {
|
|
||||||
magiskVersionString = ShellUtils.fastCmd("magisk -v").split(":")[0];
|
|
||||||
magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V"));
|
|
||||||
magiskHide = Shell.su("magiskhide --status").exec().isSuccess();
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void export() {
|
|
||||||
// Flush prefs to disk
|
|
||||||
App app = App.self;
|
|
||||||
app.prefs.edit().commit();
|
|
||||||
File xml = new File(App.deContext.getFilesDir().getParent() + "/shared_prefs",
|
|
||||||
app.getPackageName() + "_preferences.xml");
|
|
||||||
Shell.su(Utils.fmt("cat %s > /data/adb/%s", xml, Const.MANAGER_CONFIGS)).exec();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initialize() {
|
|
||||||
SharedPreferences pref = App.self.prefs;
|
|
||||||
SharedPreferences.Editor editor = pref.edit();
|
|
||||||
File config = SuFile.open("/data/adb", Const.MANAGER_CONFIGS);
|
|
||||||
if (config.exists()) {
|
|
||||||
try {
|
|
||||||
SuFileInputStream is = new SuFileInputStream(config);
|
|
||||||
XmlPullParser parser = Xml.newPullParser();
|
|
||||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
|
|
||||||
parser.setInput(is, "UTF-8");
|
|
||||||
parser.nextTag();
|
|
||||||
parser.require(XmlPullParser.START_TAG, null, "map");
|
|
||||||
while (parser.next() != XmlPullParser.END_TAG) {
|
|
||||||
if (parser.getEventType() != XmlPullParser.START_TAG)
|
|
||||||
continue;
|
|
||||||
String key = parser.getAttributeValue(null, "name");
|
|
||||||
String value = parser.getAttributeValue(null, "value");
|
|
||||||
switch (parser.getName()) {
|
|
||||||
case "string":
|
|
||||||
parser.require(XmlPullParser.START_TAG, null, "string");
|
|
||||||
editor.putString(key, parser.nextText());
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, "string");
|
|
||||||
break;
|
|
||||||
case "boolean":
|
|
||||||
parser.require(XmlPullParser.START_TAG, null, "boolean");
|
|
||||||
editor.putBoolean(key, Boolean.parseBoolean(value));
|
|
||||||
parser.nextTag();
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, "boolean");
|
|
||||||
break;
|
|
||||||
case "int":
|
|
||||||
parser.require(XmlPullParser.START_TAG, null, "int");
|
|
||||||
editor.putInt(key, Integer.parseInt(value));
|
|
||||||
parser.nextTag();
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, "int");
|
|
||||||
break;
|
|
||||||
case "long":
|
|
||||||
parser.require(XmlPullParser.START_TAG, null, "long");
|
|
||||||
editor.putLong(key, Long.parseLong(value));
|
|
||||||
parser.nextTag();
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, "long");
|
|
||||||
break;
|
|
||||||
case "float":
|
|
||||||
parser.require(XmlPullParser.START_TAG, null, "int");
|
|
||||||
editor.putFloat(key, Float.parseFloat(value));
|
|
||||||
parser.nextTag();
|
|
||||||
parser.require(XmlPullParser.END_TAG, null, "int");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
parser.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException | XmlPullParserException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
editor.remove(Key.ETAG_KEY);
|
|
||||||
editor.apply();
|
|
||||||
editor = pref.edit();
|
|
||||||
config.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set defaults if not set
|
|
||||||
setDefs(pref, editor);
|
|
||||||
|
|
||||||
// These settings are from actual device state
|
|
||||||
editor.putBoolean(Key.MAGISKHIDE, magiskHide)
|
|
||||||
.putBoolean(Key.COREONLY, Const.MAGISK_DISABLE_FILE.exists())
|
|
||||||
.putInt(Key.UPDATE_SERVICE_VER, Const.UPDATE_SERVICE_VER)
|
|
||||||
.apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final int PREF_INT = 0;
|
|
||||||
private static final int PREF_STR_INT = 1;
|
|
||||||
private static final int PREF_BOOL = 2;
|
|
||||||
private static final int PREF_STR = 3;
|
|
||||||
private static final int DB_INT = 4;
|
|
||||||
private static final int DB_BOOL = 5;
|
|
||||||
private static final int DB_STR = 6;
|
|
||||||
|
|
||||||
private static int getConfigType(String key) {
|
|
||||||
switch (key) {
|
|
||||||
case Key.REPO_ORDER:
|
|
||||||
return PREF_INT;
|
|
||||||
|
|
||||||
case Key.SU_REQUEST_TIMEOUT:
|
|
||||||
case Key.SU_AUTO_RESPONSE:
|
|
||||||
case Key.SU_NOTIFICATION:
|
|
||||||
case Key.UPDATE_CHANNEL:
|
|
||||||
return PREF_STR_INT;
|
|
||||||
|
|
||||||
case Key.DARK_THEME:
|
|
||||||
case Key.SU_REAUTH:
|
|
||||||
case Key.CHECK_UPDATES:
|
|
||||||
case Key.MAGISKHIDE:
|
|
||||||
case Key.COREONLY:
|
|
||||||
case Key.SHOW_SYSTEM_APP:
|
|
||||||
return PREF_BOOL;
|
|
||||||
|
|
||||||
case Key.CUSTOM_CHANNEL:
|
|
||||||
case Key.LOCALE:
|
|
||||||
case Key.ETAG_KEY:
|
|
||||||
return PREF_STR;
|
|
||||||
|
|
||||||
case Key.ROOT_ACCESS:
|
|
||||||
case Key.SU_MNT_NS:
|
|
||||||
case Key.SU_MULTIUSER_MODE:
|
|
||||||
return DB_INT;
|
|
||||||
|
|
||||||
case Key.SU_FINGERPRINT:
|
|
||||||
return DB_BOOL;
|
|
||||||
|
|
||||||
case Key.SU_MANAGER:
|
|
||||||
return DB_STR;
|
|
||||||
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public static <T> T get(String key) {
|
|
||||||
App app = App.self;
|
|
||||||
switch (getConfigType(key)) {
|
|
||||||
case PREF_INT:
|
|
||||||
return (T) (Integer) app.prefs.getInt(key, getDef(key));
|
|
||||||
case PREF_STR_INT:
|
|
||||||
return (T) (Integer) Utils.getPrefsInt(app.prefs, key, getDef(key));
|
|
||||||
case PREF_BOOL:
|
|
||||||
return (T) (Boolean) app.prefs.getBoolean(key, getDef(key));
|
|
||||||
case PREF_STR:
|
|
||||||
return (T) app.prefs.getString(key, getDef(key));
|
|
||||||
case DB_INT:
|
|
||||||
return (T) (Integer) app.mDB.getSettings(key, getDef(key));
|
|
||||||
case DB_BOOL:
|
|
||||||
return (T) (Boolean) (app.mDB.getSettings(key, getDef(key) ? 1 : 0) != 0);
|
|
||||||
case DB_STR:
|
|
||||||
return (T) app.mDB.getStrings(key, getDef(key));
|
|
||||||
}
|
|
||||||
/* Will never get here (IllegalArgumentException in getConfigType) */
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void set(String key, Object val) {
|
|
||||||
App app = App.self;
|
|
||||||
switch (getConfigType(key)) {
|
|
||||||
case PREF_INT:
|
|
||||||
app.prefs.edit().putInt(key, (int) val).apply();
|
|
||||||
break;
|
|
||||||
case PREF_STR_INT:
|
|
||||||
app.prefs.edit().putString(key, String.valueOf(val)).apply();
|
|
||||||
break;
|
|
||||||
case PREF_BOOL:
|
|
||||||
app.prefs.edit().putBoolean(key, (boolean) val).apply();
|
|
||||||
break;
|
|
||||||
case PREF_STR:
|
|
||||||
app.prefs.edit().putString(key, (String) val).apply();
|
|
||||||
break;
|
|
||||||
case DB_INT:
|
|
||||||
app.mDB.setSettings(key, (int) val);
|
|
||||||
break;
|
|
||||||
case DB_BOOL:
|
|
||||||
app.mDB.setSettings(key, (boolean) val ? 1 : 0);
|
|
||||||
break;
|
|
||||||
case DB_STR:
|
|
||||||
app.mDB.setStrings(key, (String) val);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void remove(String key) {
|
|
||||||
App app = App.self;
|
|
||||||
switch (getConfigType(key)) {
|
|
||||||
case PREF_INT:
|
|
||||||
case PREF_STR_INT:
|
|
||||||
case PREF_BOOL:
|
|
||||||
case PREF_STR:
|
|
||||||
app.prefs.edit().remove(key).apply();
|
|
||||||
break;
|
|
||||||
case DB_BOOL:
|
|
||||||
case DB_INT:
|
|
||||||
app.mDB.rmSettings(key);
|
|
||||||
break;
|
|
||||||
case DB_STR:
|
|
||||||
app.mDB.setStrings(key, null);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ArrayMap<String, Object> defs = new ArrayMap<>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
/* Set default configurations */
|
|
||||||
|
|
||||||
// prefs int
|
|
||||||
defs.put(Key.REPO_ORDER, Value.ORDER_DATE);
|
|
||||||
|
|
||||||
// prefs string int
|
|
||||||
defs.put(Key.SU_REQUEST_TIMEOUT, 10);
|
|
||||||
defs.put(Key.SU_AUTO_RESPONSE, Value.SU_PROMPT);
|
|
||||||
defs.put(Key.SU_NOTIFICATION, Value.NOTIFICATION_TOAST);
|
|
||||||
defs.put(Key.UPDATE_CHANNEL, Utils.isCanary() ?
|
|
||||||
Value.CANARY_DEBUG_CHANNEL : Value.DEFAULT_CHANNEL);
|
|
||||||
|
|
||||||
// prefs bool
|
|
||||||
defs.put(Key.CHECK_UPDATES, true);
|
|
||||||
defs.put(Key.DARK_THEME, true);
|
|
||||||
//defs.put(Key.SU_REAUTH, false);
|
|
||||||
//defs.put(Key.SHOW_SYSTEM_APP, false);
|
|
||||||
|
|
||||||
// prefs string
|
|
||||||
defs.put(Key.CUSTOM_CHANNEL, "");
|
|
||||||
defs.put(Key.LOCALE, "");
|
|
||||||
//defs.put(Key.ETAG_KEY, null);
|
|
||||||
|
|
||||||
// db int
|
|
||||||
defs.put(Key.ROOT_ACCESS, Value.ROOT_ACCESS_APPS_AND_ADB);
|
|
||||||
defs.put(Key.SU_MNT_NS, Value.NAMESPACE_MODE_REQUESTER);
|
|
||||||
defs.put(Key.SU_MULTIUSER_MODE, Value.MULTIUSER_MODE_OWNER_ONLY);
|
|
||||||
|
|
||||||
// db bool
|
|
||||||
//defs.put(Key.SU_FINGERPRINT, false);
|
|
||||||
|
|
||||||
// db strings
|
|
||||||
//defs.put(Key.SU_MANAGER, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> T getDef(String key) {
|
|
||||||
Object val = defs.get(key);
|
|
||||||
switch (getConfigType(key)) {
|
|
||||||
case PREF_INT:
|
|
||||||
case DB_INT:
|
|
||||||
case PREF_STR_INT:
|
|
||||||
return val != null ? (T) val : (T) (Integer) 0;
|
|
||||||
case DB_BOOL:
|
|
||||||
case PREF_BOOL:
|
|
||||||
return val != null ? (T) val : (T) (Boolean) false;
|
|
||||||
case DB_STR:
|
|
||||||
case PREF_STR:
|
|
||||||
return (T) val;
|
|
||||||
}
|
|
||||||
/* Will never get here (IllegalArgumentException in getConfigType) */
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setDefs(SharedPreferences pref, SharedPreferences.Editor editor) {
|
|
||||||
App app = App.self;
|
|
||||||
for (String key : defs.keySet()) {
|
|
||||||
int type = getConfigType(key);
|
|
||||||
switch (type) {
|
|
||||||
case DB_INT:
|
|
||||||
editor.putString(key, String.valueOf(
|
|
||||||
app.mDB.getSettings(key, (Integer) defs.get(key))));
|
|
||||||
continue;
|
|
||||||
case DB_STR:
|
|
||||||
editor.putString(key, app.mDB.getStrings(key, (String) defs.get(key)));
|
|
||||||
continue;
|
|
||||||
case DB_BOOL:
|
|
||||||
int bs = app.mDB.getSettings(key, -1);
|
|
||||||
editor.putBoolean(key, bs < 0 ? (Boolean) defs.get(key) : bs != 0);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (pref.contains(key))
|
|
||||||
continue;
|
|
||||||
switch (type) {
|
|
||||||
case PREF_INT:
|
|
||||||
editor.putInt(key, (Integer) defs.get(key));
|
|
||||||
break;
|
|
||||||
case PREF_STR_INT:
|
|
||||||
editor.putString(key, String.valueOf(defs.get(key)));
|
|
||||||
break;
|
|
||||||
case PREF_STR:
|
|
||||||
editor.putString(key, (String) defs.get(key));
|
|
||||||
break;
|
|
||||||
case PREF_BOOL:
|
|
||||||
editor.putBoolean(key, (Boolean) defs.get(key));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
215
app/src/main/java/com/topjohnwu/magisk/Config.kt
Normal file
215
app/src/main/java/com/topjohnwu/magisk/Config.kt
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
package com.topjohnwu.magisk
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.os.Environment
|
||||||
|
import android.util.Xml
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import com.topjohnwu.magisk.data.database.SettingsDao
|
||||||
|
import com.topjohnwu.magisk.data.database.StringDao
|
||||||
|
import com.topjohnwu.magisk.data.repository.DBConfig
|
||||||
|
import com.topjohnwu.magisk.di.Protected
|
||||||
|
import com.topjohnwu.magisk.extensions.get
|
||||||
|
import com.topjohnwu.magisk.extensions.inject
|
||||||
|
import com.topjohnwu.magisk.extensions.packageName
|
||||||
|
import com.topjohnwu.magisk.model.preference.PreferenceModel
|
||||||
|
import com.topjohnwu.magisk.utils.FingerprintHelper
|
||||||
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import com.topjohnwu.superuser.io.SuFile
|
||||||
|
import com.topjohnwu.superuser.io.SuFileInputStream
|
||||||
|
import org.xmlpull.v1.XmlPullParser
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
object Config : PreferenceModel, DBConfig {
|
||||||
|
|
||||||
|
override val stringDao: StringDao by inject()
|
||||||
|
override val settingsDao: SettingsDao by inject()
|
||||||
|
override val context: Context by inject(Protected)
|
||||||
|
|
||||||
|
object Key {
|
||||||
|
// db configs
|
||||||
|
const val ROOT_ACCESS = "root_access"
|
||||||
|
const val SU_MULTIUSER_MODE = "multiuser_mode"
|
||||||
|
const val SU_MNT_NS = "mnt_ns"
|
||||||
|
const val SU_FINGERPRINT = "su_fingerprint"
|
||||||
|
const val SU_MANAGER = "requester"
|
||||||
|
const val KEYSTORE = "keystore"
|
||||||
|
|
||||||
|
// prefs
|
||||||
|
const val SU_REQUEST_TIMEOUT = "su_request_timeout"
|
||||||
|
const val SU_AUTO_RESPONSE = "su_auto_response"
|
||||||
|
const val SU_NOTIFICATION = "su_notification"
|
||||||
|
const val SU_REAUTH = "su_reauth"
|
||||||
|
const val CHECK_UPDATES = "check_update"
|
||||||
|
const val UPDATE_CHANNEL = "update_channel"
|
||||||
|
const val CUSTOM_CHANNEL = "custom_channel"
|
||||||
|
const val LOCALE = "locale"
|
||||||
|
const val DARK_THEME = "dark_theme"
|
||||||
|
const val REPO_ORDER = "repo_order"
|
||||||
|
const val SHOW_SYSTEM_APP = "show_system"
|
||||||
|
const val DOWNLOAD_PATH = "download_path"
|
||||||
|
|
||||||
|
// system state
|
||||||
|
const val MAGISKHIDE = "magiskhide"
|
||||||
|
const val COREONLY = "disable"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Value {
|
||||||
|
// Update channels
|
||||||
|
const val DEFAULT_CHANNEL = -1
|
||||||
|
const val STABLE_CHANNEL = 0
|
||||||
|
const val BETA_CHANNEL = 1
|
||||||
|
const val CUSTOM_CHANNEL = 2
|
||||||
|
const val CANARY_CHANNEL = 3
|
||||||
|
const val CANARY_DEBUG_CHANNEL = 4
|
||||||
|
|
||||||
|
// root access mode
|
||||||
|
const val ROOT_ACCESS_DISABLED = 0
|
||||||
|
const val ROOT_ACCESS_APPS_ONLY = 1
|
||||||
|
const val ROOT_ACCESS_ADB_ONLY = 2
|
||||||
|
const val ROOT_ACCESS_APPS_AND_ADB = 3
|
||||||
|
|
||||||
|
// su multiuser
|
||||||
|
const val MULTIUSER_MODE_OWNER_ONLY = 0
|
||||||
|
const val MULTIUSER_MODE_OWNER_MANAGED = 1
|
||||||
|
const val MULTIUSER_MODE_USER = 2
|
||||||
|
|
||||||
|
// su mnt ns
|
||||||
|
const val NAMESPACE_MODE_GLOBAL = 0
|
||||||
|
const val NAMESPACE_MODE_REQUESTER = 1
|
||||||
|
const val NAMESPACE_MODE_ISOLATE = 2
|
||||||
|
|
||||||
|
// su notification
|
||||||
|
const val NO_NOTIFICATION = 0
|
||||||
|
const val NOTIFICATION_TOAST = 1
|
||||||
|
|
||||||
|
// su auto response
|
||||||
|
const val SU_PROMPT = 0
|
||||||
|
const val SU_AUTO_DENY = 1
|
||||||
|
const val SU_AUTO_ALLOW = 2
|
||||||
|
|
||||||
|
// su timeout
|
||||||
|
val TIMEOUT_LIST = intArrayOf(0, -1, 10, 20, 30, 60)
|
||||||
|
|
||||||
|
// repo order
|
||||||
|
const val ORDER_NAME = 0
|
||||||
|
const val ORDER_DATE = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
private val defaultChannel =
|
||||||
|
if (Utils.isCanary) {
|
||||||
|
if (BuildConfig.DEBUG)
|
||||||
|
Value.CANARY_DEBUG_CHANNEL
|
||||||
|
else
|
||||||
|
Value.CANARY_CHANNEL
|
||||||
|
}
|
||||||
|
else Value.DEFAULT_CHANNEL
|
||||||
|
|
||||||
|
var downloadPath by preference(Key.DOWNLOAD_PATH, Environment.DIRECTORY_DOWNLOADS)
|
||||||
|
var repoOrder by preference(Key.REPO_ORDER, Value.ORDER_DATE)
|
||||||
|
|
||||||
|
var suDefaultTimeout by preferenceStrInt(Key.SU_REQUEST_TIMEOUT, 10)
|
||||||
|
var suAutoReponse by preferenceStrInt(Key.SU_AUTO_RESPONSE, Value.SU_PROMPT)
|
||||||
|
var suNotification by preferenceStrInt(Key.SU_NOTIFICATION, Value.NOTIFICATION_TOAST)
|
||||||
|
var updateChannel by preferenceStrInt(Key.UPDATE_CHANNEL, defaultChannel)
|
||||||
|
|
||||||
|
var darkTheme by preference(Key.DARK_THEME, true)
|
||||||
|
var suReAuth by preference(Key.SU_REAUTH, false)
|
||||||
|
var checkUpdate by preference(Key.CHECK_UPDATES, true)
|
||||||
|
var magiskHide by preference(Key.MAGISKHIDE, true)
|
||||||
|
var coreOnly by preference(Key.COREONLY, false)
|
||||||
|
var showSystemApp by preference(Key.SHOW_SYSTEM_APP, false)
|
||||||
|
|
||||||
|
var customChannelUrl by preference(Key.CUSTOM_CHANNEL, "")
|
||||||
|
var locale by preference(Key.LOCALE, "")
|
||||||
|
|
||||||
|
var rootMode by dbSettings(Key.ROOT_ACCESS, Value.ROOT_ACCESS_APPS_AND_ADB)
|
||||||
|
var suMntNamespaceMode by dbSettings(Key.SU_MNT_NS, Value.NAMESPACE_MODE_REQUESTER)
|
||||||
|
var suMultiuserMode by dbSettings(Key.SU_MULTIUSER_MODE, Value.MULTIUSER_MODE_OWNER_ONLY)
|
||||||
|
var suFingerprint by dbSettings(Key.SU_FINGERPRINT, false)
|
||||||
|
var suManager by dbStrings(Key.SU_MANAGER, "", true)
|
||||||
|
var keyStoreRaw by dbStrings(Key.KEYSTORE, "", true)
|
||||||
|
|
||||||
|
// Always return a path in external storage where we can write
|
||||||
|
val downloadDirectory get() =
|
||||||
|
Utils.ensureDownloadPath(downloadPath) ?: get<Context>().getExternalFilesDir(null)!!
|
||||||
|
|
||||||
|
fun initialize() = prefs.edit {
|
||||||
|
parsePrefs(this)
|
||||||
|
|
||||||
|
// Get actual state
|
||||||
|
putBoolean(Key.COREONLY, Const.MAGISK_DISABLE_FILE.exists())
|
||||||
|
|
||||||
|
// Write database configs
|
||||||
|
putString(Key.ROOT_ACCESS, rootMode.toString())
|
||||||
|
putString(Key.SU_MNT_NS, suMntNamespaceMode.toString())
|
||||||
|
putString(Key.SU_MULTIUSER_MODE, suMultiuserMode.toString())
|
||||||
|
putBoolean(Key.SU_FINGERPRINT, FingerprintHelper.useFingerprint())
|
||||||
|
}.also {
|
||||||
|
if (!prefs.contains(Key.UPDATE_CHANNEL))
|
||||||
|
prefs.edit().putString(Key.UPDATE_CHANNEL, defaultChannel.toString()).apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parsePrefs(editor: SharedPreferences.Editor) = editor.apply {
|
||||||
|
val config = SuFile.open("/data/adb", Const.MANAGER_CONFIGS)
|
||||||
|
if (config.exists()) runCatching {
|
||||||
|
val input = SuFileInputStream(config).buffered()
|
||||||
|
val parser = Xml.newPullParser()
|
||||||
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false)
|
||||||
|
parser.setInput(input, "UTF-8")
|
||||||
|
parser.nextTag()
|
||||||
|
parser.require(XmlPullParser.START_TAG, null, "map")
|
||||||
|
while (parser.next() != XmlPullParser.END_TAG) {
|
||||||
|
if (parser.eventType != XmlPullParser.START_TAG)
|
||||||
|
continue
|
||||||
|
val key: String = parser.getAttributeValue(null, "name")
|
||||||
|
fun value() = parser.getAttributeValue(null, "value")!!
|
||||||
|
when (parser.name) {
|
||||||
|
"string" -> {
|
||||||
|
parser.require(XmlPullParser.START_TAG, null, "string")
|
||||||
|
putString(key, parser.nextText())
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, "string")
|
||||||
|
}
|
||||||
|
"boolean" -> {
|
||||||
|
parser.require(XmlPullParser.START_TAG, null, "boolean")
|
||||||
|
putBoolean(key, value().toBoolean())
|
||||||
|
parser.nextTag()
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, "boolean")
|
||||||
|
}
|
||||||
|
"int" -> {
|
||||||
|
parser.require(XmlPullParser.START_TAG, null, "int")
|
||||||
|
putInt(key, value().toInt())
|
||||||
|
parser.nextTag()
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, "int")
|
||||||
|
}
|
||||||
|
"long" -> {
|
||||||
|
parser.require(XmlPullParser.START_TAG, null, "long")
|
||||||
|
putLong(key, value().toLong())
|
||||||
|
parser.nextTag()
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, "long")
|
||||||
|
}
|
||||||
|
"float" -> {
|
||||||
|
parser.require(XmlPullParser.START_TAG, null, "int")
|
||||||
|
putFloat(key, value().toFloat())
|
||||||
|
parser.nextTag()
|
||||||
|
parser.require(XmlPullParser.END_TAG, null, "int")
|
||||||
|
}
|
||||||
|
else -> parser.next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
config.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun export() {
|
||||||
|
// Flush prefs to disk
|
||||||
|
prefs.edit().commit()
|
||||||
|
val xml = File(
|
||||||
|
"${get<Context>(Protected).filesDir.parent}/shared_prefs",
|
||||||
|
"${packageName}_preferences.xml"
|
||||||
|
)
|
||||||
|
Shell.su("cat $xml > /data/adb/${Const.MANAGER_CONFIGS}").exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,99 +0,0 @@
|
|||||||
package com.topjohnwu.magisk;
|
|
||||||
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.Process;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class Const {
|
|
||||||
|
|
||||||
public static final String DEBUG_TAG = "MagiskManager";
|
|
||||||
|
|
||||||
// APK content
|
|
||||||
public static final String ANDROID_MANIFEST = "AndroidManifest.xml";
|
|
||||||
|
|
||||||
public static final String SU_KEYSTORE_KEY = "su_key";
|
|
||||||
|
|
||||||
// Paths
|
|
||||||
public static final String MAGISK_PATH = "/sbin/.magisk/img";
|
|
||||||
public static final File EXTERNAL_PATH;
|
|
||||||
public static File MAGISK_DISABLE_FILE;
|
|
||||||
|
|
||||||
static {
|
|
||||||
MAGISK_DISABLE_FILE = new File("xxx");
|
|
||||||
EXTERNAL_PATH = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
|
||||||
EXTERNAL_PATH.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final String TMP_FOLDER_PATH = "/dev/tmp";
|
|
||||||
public static final String MAGISK_LOG = "/cache/magisk.log";
|
|
||||||
public static final String MANAGER_CONFIGS = ".tmp.magisk.config";
|
|
||||||
|
|
||||||
// Versions
|
|
||||||
public static final int UPDATE_SERVICE_VER = 1;
|
|
||||||
public static final int SNET_EXT_VER = 12;
|
|
||||||
|
|
||||||
public static final int USER_ID = Process.myUid() / 100000;
|
|
||||||
|
|
||||||
public static final class MAGISK_VER {
|
|
||||||
public static final int MIN_SUPPORT = 18000;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ID {
|
|
||||||
public static final int FETCH_ZIP = 2;
|
|
||||||
public static final int SELECT_BOOT = 3;
|
|
||||||
|
|
||||||
// notifications
|
|
||||||
public static final int MAGISK_UPDATE_NOTIFICATION_ID = 4;
|
|
||||||
public static final int APK_UPDATE_NOTIFICATION_ID = 5;
|
|
||||||
public static final int DTBO_NOTIFICATION_ID = 7;
|
|
||||||
public static final int HIDE_MANAGER_NOTIFICATION_ID = 8;
|
|
||||||
public static final String UPDATE_NOTIFICATION_CHANNEL = "update";
|
|
||||||
public static final String PROGRESS_NOTIFICATION_CHANNEL = "progress";
|
|
||||||
public static final String CHECK_MAGISK_UPDATE_WORKER_ID = "magisk_update";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Url {
|
|
||||||
private static String getRaw(String where, String name) {
|
|
||||||
return String.format("https://raw.githubusercontent.com/topjohnwu/magisk_files/%s/%s", where, name);
|
|
||||||
}
|
|
||||||
public static final String STABLE_URL = getRaw("master", "stable.json");
|
|
||||||
public static final String BETA_URL = getRaw("master", "beta.json");
|
|
||||||
public static final String CANARY_URL = getRaw("master", "canary_builds/release.json");
|
|
||||||
public static final String CANARY_DEBUG_URL = getRaw("master", "canary_builds/canary.json");
|
|
||||||
public static final String REPO_URL = "https://api.github.com/users/Magisk-Modules-Repo/repos?per_page=100&sort=pushed&page=%d";
|
|
||||||
public static final String FILE_URL = "https://raw.githubusercontent.com/Magisk-Modules-Repo/%s/master/%s";
|
|
||||||
public static final String ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip";
|
|
||||||
public static final String MODULE_INSTALLER = "https://raw.githubusercontent.com/topjohnwu/Magisk/master/scripts/module_installer.sh";
|
|
||||||
public static final String PAYPAL_URL = "https://www.paypal.me/topjohnwu";
|
|
||||||
public static final String PATREON_URL = "https://www.patreon.com/topjohnwu";
|
|
||||||
public static final String TWITTER_URL = "https://twitter.com/topjohnwu";
|
|
||||||
public static final String XDA_THREAD = "http://forum.xda-developers.com/showthread.php?t=3432382";
|
|
||||||
public static final String SOURCE_CODE_URL = "https://github.com/topjohnwu/Magisk";
|
|
||||||
public static final String SNET_URL = getRaw("b66b1a914978e5f4c4bbfd74a59f4ad371bac107", "snet.apk");
|
|
||||||
public static final String BOOTCTL_URL = getRaw("9c5dfc1b8245c0b5b524901ef0ff0f8335757b77", "bootctl");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Key {
|
|
||||||
// others
|
|
||||||
public static final String LINK_KEY = "Link";
|
|
||||||
public static final String IF_NONE_MATCH = "If-None-Match";
|
|
||||||
// intents
|
|
||||||
public static final String OPEN_SECTION = "section";
|
|
||||||
public static final String INTENT_SET_NAME = "filename";
|
|
||||||
public static final String INTENT_SET_LINK = "link";
|
|
||||||
public static final String FLASH_ACTION = "action";
|
|
||||||
public static final String BROADCAST_MANAGER_UPDATE = "manager_update";
|
|
||||||
public static final String BROADCAST_REBOOT = "reboot";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class Value {
|
|
||||||
public static final String FLASH_ZIP = "flash";
|
|
||||||
public static final String PATCH_FILE = "patch";
|
|
||||||
public static final String FLASH_MAGISK = "magisk";
|
|
||||||
public static final String FLASH_INACTIVE_SLOT = "slot";
|
|
||||||
public static final String UNINSTALL = "uninstall";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
79
app/src/main/java/com/topjohnwu/magisk/Const.kt
Normal file
79
app/src/main/java/com/topjohnwu/magisk/Const.kt
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package com.topjohnwu.magisk
|
||||||
|
|
||||||
|
import android.os.Process
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
object Const {
|
||||||
|
|
||||||
|
// Paths
|
||||||
|
const val MAGISK_PATH = "/sbin/.magisk/img"
|
||||||
|
var MAGISK_DISABLE_FILE = File("xxx")
|
||||||
|
const val TMP_FOLDER_PATH = "/dev/tmp"
|
||||||
|
const val MAGISK_LOG = "/cache/magisk.log"
|
||||||
|
|
||||||
|
// Versions
|
||||||
|
const val SNET_EXT_VER = 13
|
||||||
|
const val SNET_REVISION = "a6c47f86f10b310358afa9dbe837037dd5d561df"
|
||||||
|
const val BOOTCTL_REVISION = "a6c47f86f10b310358afa9dbe837037dd5d561df"
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
const val ANDROID_MANIFEST = "AndroidManifest.xml"
|
||||||
|
const val MAGISK_INSTALL_LOG_FILENAME = "magisk_install_log_%s.log"
|
||||||
|
const val MANAGER_CONFIGS = ".tmp.magisk.config"
|
||||||
|
val USER_ID = Process.myUid() / 100000
|
||||||
|
|
||||||
|
object Version {
|
||||||
|
const val MIN_SUPPORT = 18000
|
||||||
|
const val CONNECT_MODE = 20002
|
||||||
|
}
|
||||||
|
|
||||||
|
object ID {
|
||||||
|
const val FETCH_ZIP = 2
|
||||||
|
const val SELECT_BOOT = 3
|
||||||
|
|
||||||
|
// notifications
|
||||||
|
const val MAGISK_UPDATE_NOTIFICATION_ID = 4
|
||||||
|
const val APK_UPDATE_NOTIFICATION_ID = 5
|
||||||
|
const val DTBO_NOTIFICATION_ID = 7
|
||||||
|
const val HIDE_MANAGER_NOTIFICATION_ID = 8
|
||||||
|
const val UPDATE_NOTIFICATION_CHANNEL = "update"
|
||||||
|
const val PROGRESS_NOTIFICATION_CHANNEL = "progress"
|
||||||
|
const val CHECK_MAGISK_UPDATE_WORKER_ID = "magisk_update"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Url {
|
||||||
|
const val ZIP_URL = "https://github.com/Magisk-Modules-Repo/%s/archive/master.zip"
|
||||||
|
const val PAYPAL_URL = "https://www.paypal.me/topjohnwu"
|
||||||
|
const val PATREON_URL = "https://www.patreon.com/topjohnwu"
|
||||||
|
const val TWITTER_URL = "https://twitter.com/topjohnwu"
|
||||||
|
const val XDA_THREAD = "http://forum.xda-developers.com/showthread.php?t=3432382"
|
||||||
|
const val SOURCE_CODE_URL = "https://github.com/topjohnwu/Magisk"
|
||||||
|
|
||||||
|
const val GITHUB_RAW_URL = "https://raw.githubusercontent.com/"
|
||||||
|
const val GITHUB_API_URL = "https://api.github.com/users/Magisk-Modules-Repo/"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Key {
|
||||||
|
// others
|
||||||
|
const val LINK_KEY = "Link"
|
||||||
|
const val IF_NONE_MATCH = "If-None-Match"
|
||||||
|
const val ETAG_KEY = "ETag"
|
||||||
|
// intents
|
||||||
|
const val OPEN_SECTION = "section"
|
||||||
|
const val INTENT_SET_APP = "app_json"
|
||||||
|
const val FLASH_ACTION = "action"
|
||||||
|
const val FLASH_DATA = "additional_data"
|
||||||
|
const val DISMISS_ID = "dismiss_id"
|
||||||
|
const val BROADCAST_MANAGER_UPDATE = "manager_update"
|
||||||
|
const val BROADCAST_REBOOT = "reboot"
|
||||||
|
}
|
||||||
|
|
||||||
|
object Value {
|
||||||
|
const val FLASH_ZIP = "flash"
|
||||||
|
const val PATCH_FILE = "patch"
|
||||||
|
const val FLASH_MAGISK = "magisk"
|
||||||
|
const val FLASH_INACTIVE_SLOT = "slot"
|
||||||
|
const val UNINSTALL = "uninstall"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
199
app/src/main/java/com/topjohnwu/magisk/Hacks.kt
Normal file
199
app/src/main/java/com/topjohnwu/magisk/Hacks.kt
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
@file:Suppress("DEPRECATION")
|
||||||
|
|
||||||
|
package com.topjohnwu.magisk
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.job.JobInfo
|
||||||
|
import android.app.job.JobScheduler
|
||||||
|
import android.app.job.JobWorkItem
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.res.AssetManager
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.content.res.Resources
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import com.topjohnwu.magisk.extensions.langTagToLocale
|
||||||
|
import com.topjohnwu.magisk.model.download.DownloadService
|
||||||
|
import com.topjohnwu.magisk.model.receiver.GeneralReceiver
|
||||||
|
import com.topjohnwu.magisk.model.update.UpdateCheckService
|
||||||
|
import com.topjohnwu.magisk.ui.MainActivity
|
||||||
|
import com.topjohnwu.magisk.ui.SplashActivity
|
||||||
|
import com.topjohnwu.magisk.ui.flash.FlashActivity
|
||||||
|
import com.topjohnwu.magisk.ui.surequest.SuRequestActivity
|
||||||
|
import com.topjohnwu.magisk.utils.currentLocale
|
||||||
|
import com.topjohnwu.magisk.utils.defaultLocale
|
||||||
|
import com.topjohnwu.magisk.utils.refreshLocale
|
||||||
|
import com.topjohnwu.magisk.utils.updateConfig
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun AssetManager.addAssetPath(path: String) {
|
||||||
|
DynAPK.addAssetPath(this, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.wrap(global: Boolean = true): Context
|
||||||
|
= if (global) GlobalResContext(this) else ResContext(this)
|
||||||
|
|
||||||
|
fun Context.wrapJob(): Context = object : GlobalResContext(this) {
|
||||||
|
|
||||||
|
override fun getApplicationContext(): Context {
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
override fun getSystemService(name: String): Any? {
|
||||||
|
return if (!isRunningAsStub) super.getSystemService(name) else
|
||||||
|
when (name) {
|
||||||
|
Context.JOB_SCHEDULER_SERVICE ->
|
||||||
|
JobSchedulerWrapper(super.getSystemService(name) as JobScheduler)
|
||||||
|
else -> super.getSystemService(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Class<*>.cmp(pkg: String = BuildConfig.APPLICATION_ID): ComponentName {
|
||||||
|
val name = ClassMap[this].name
|
||||||
|
return ComponentName(pkg, Info.stub?.componentMap?.get(name) ?: name)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.intent(c: Class<*>): Intent {
|
||||||
|
val cls = ClassMap[c]
|
||||||
|
return Info.stub?.let {
|
||||||
|
val className = it.componentMap.getOrElse(cls.name) { cls.name }
|
||||||
|
Intent().setComponent(ComponentName(this, className))
|
||||||
|
} ?: Intent(this, cls)
|
||||||
|
}
|
||||||
|
|
||||||
|
private open class GlobalResContext(base: Context) : ContextWrapper(base) {
|
||||||
|
open val mRes: Resources get() = ResourceMgr.resource
|
||||||
|
private val loader by lazy { javaClass.classLoader!! }
|
||||||
|
|
||||||
|
override fun getResources(): Resources {
|
||||||
|
return mRes
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getClassLoader(): ClassLoader {
|
||||||
|
return loader
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createConfigurationContext(config: Configuration): Context {
|
||||||
|
return ResContext(super.createConfigurationContext(config))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ResContext(base: Context) : GlobalResContext(base) {
|
||||||
|
override val mRes by lazy { base.resources.patch() }
|
||||||
|
|
||||||
|
private fun Resources.patch(): Resources {
|
||||||
|
updateConfig()
|
||||||
|
if (isRunningAsStub)
|
||||||
|
assets.addAssetPath(ResourceMgr.resApk)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object ResourceMgr {
|
||||||
|
|
||||||
|
lateinit var resource: Resources
|
||||||
|
lateinit var resApk: String
|
||||||
|
|
||||||
|
fun init(context: Context) {
|
||||||
|
resource = context.resources
|
||||||
|
refreshLocale()
|
||||||
|
if (isRunningAsStub) {
|
||||||
|
resApk = DynAPK.current(context).path
|
||||||
|
resource.assets.addAssetPath(resApk)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(api = 28)
|
||||||
|
private class JobSchedulerWrapper(private val base: JobScheduler) : JobScheduler() {
|
||||||
|
|
||||||
|
override fun schedule(job: JobInfo): Int {
|
||||||
|
return base.schedule(job.patch())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun enqueue(job: JobInfo, work: JobWorkItem): Int {
|
||||||
|
return base.enqueue(job.patch(), work)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun cancel(jobId: Int) {
|
||||||
|
base.cancel(jobId)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun cancelAll() {
|
||||||
|
base.cancelAll()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllPendingJobs(): List<JobInfo> {
|
||||||
|
return base.allPendingJobs
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getPendingJob(jobId: Int): JobInfo? {
|
||||||
|
return base.getPendingJob(jobId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun JobInfo.patch(): JobInfo {
|
||||||
|
// We need to patch the component of JobInfo to access WorkManager SystemJobService
|
||||||
|
|
||||||
|
val name = service.className
|
||||||
|
val component = ComponentName(
|
||||||
|
service.packageName,
|
||||||
|
Info.stub!!.componentMap[name] ?: name)
|
||||||
|
|
||||||
|
// Clone the JobInfo except component
|
||||||
|
val builder = JobInfo.Builder(id, component)
|
||||||
|
.setExtras(extras)
|
||||||
|
.setTransientExtras(transientExtras)
|
||||||
|
.setClipData(clipData, clipGrantFlags)
|
||||||
|
.setRequiredNetwork(requiredNetwork)
|
||||||
|
.setEstimatedNetworkBytes(estimatedNetworkDownloadBytes, estimatedNetworkUploadBytes)
|
||||||
|
.setRequiresCharging(isRequireCharging)
|
||||||
|
.setRequiresDeviceIdle(isRequireDeviceIdle)
|
||||||
|
.setRequiresBatteryNotLow(isRequireBatteryNotLow)
|
||||||
|
.setRequiresStorageNotLow(isRequireStorageNotLow)
|
||||||
|
.also {
|
||||||
|
triggerContentUris?.let { uris ->
|
||||||
|
for (uri in uris)
|
||||||
|
it.addTriggerContentUri(uri)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setTriggerContentUpdateDelay(triggerContentUpdateDelay)
|
||||||
|
.setTriggerContentMaxDelay(triggerContentMaxDelay)
|
||||||
|
.setImportantWhileForeground(isImportantWhileForeground)
|
||||||
|
.setPrefetch(isPrefetch)
|
||||||
|
.setPersisted(isPersisted)
|
||||||
|
|
||||||
|
if (isPeriodic) {
|
||||||
|
builder.setPeriodic(intervalMillis, flexMillis)
|
||||||
|
} else {
|
||||||
|
if (minLatencyMillis > 0)
|
||||||
|
builder.setMinimumLatency(minLatencyMillis)
|
||||||
|
if (maxExecutionDelayMillis > 0)
|
||||||
|
builder.setOverrideDeadline(maxExecutionDelayMillis)
|
||||||
|
}
|
||||||
|
if (!isRequireDeviceIdle)
|
||||||
|
builder.setBackoffCriteria(initialBackoffMillis, backoffPolicy)
|
||||||
|
|
||||||
|
return builder.build()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object ClassMap {
|
||||||
|
|
||||||
|
private val map = mapOf(
|
||||||
|
App::class.java to a.e::class.java,
|
||||||
|
MainActivity::class.java to a.b::class.java,
|
||||||
|
SplashActivity::class.java to a.c::class.java,
|
||||||
|
FlashActivity::class.java to a.f::class.java,
|
||||||
|
UpdateCheckService::class.java to a.g::class.java,
|
||||||
|
GeneralReceiver::class.java to a.h::class.java,
|
||||||
|
DownloadService::class.java to a.j::class.java,
|
||||||
|
SuRequestActivity::class.java to a.m::class.java
|
||||||
|
)
|
||||||
|
|
||||||
|
operator fun get(c: Class<*>) = map.getOrElse(c) { throw IllegalArgumentException() }
|
||||||
|
}
|
62
app/src/main/java/com/topjohnwu/magisk/Info.kt
Normal file
62
app/src/main/java/com/topjohnwu/magisk/Info.kt
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package com.topjohnwu.magisk
|
||||||
|
|
||||||
|
import com.github.pwittchen.reactivenetwork.library.rx2.ReactiveNetwork
|
||||||
|
import com.topjohnwu.magisk.extensions.get
|
||||||
|
import com.topjohnwu.magisk.extensions.subscribeK
|
||||||
|
import com.topjohnwu.magisk.model.entity.UpdateInfo
|
||||||
|
import com.topjohnwu.magisk.utils.CachedValue
|
||||||
|
import com.topjohnwu.magisk.utils.KObservableField
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import com.topjohnwu.superuser.ShellUtils
|
||||||
|
|
||||||
|
val isRunningAsStub get() = Info.stub != null
|
||||||
|
|
||||||
|
object Info {
|
||||||
|
|
||||||
|
val envRef = CachedValue { loadState() }
|
||||||
|
|
||||||
|
val env by envRef // Local
|
||||||
|
var remote = UpdateInfo() // Remote
|
||||||
|
var stub: DynAPK.Data? = null // Stub
|
||||||
|
|
||||||
|
var keepVerity = false
|
||||||
|
var keepEnc = false
|
||||||
|
var recovery = false
|
||||||
|
|
||||||
|
val isConnected by lazy {
|
||||||
|
KObservableField(false).also { field ->
|
||||||
|
ReactiveNetwork.observeNetworkConnectivity(get())
|
||||||
|
.subscribeK {
|
||||||
|
field.value = it.available()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadState() = runCatching {
|
||||||
|
val str = ShellUtils.fastCmd("magisk -v").split(":".toRegex())[0]
|
||||||
|
val code = ShellUtils.fastCmd("magisk -V").toInt()
|
||||||
|
val hide = Shell.su("magiskhide --status").exec().isSuccess
|
||||||
|
var mode = -1
|
||||||
|
if (code >= Const.Version.CONNECT_MODE) {
|
||||||
|
mode = Shell.su("magisk --connect-mode").exec().code
|
||||||
|
if (mode == 0) {
|
||||||
|
// Manually trigger broadcast test
|
||||||
|
Shell.su("magisk --broadcast-test").exec()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Env(code, str, hide, mode)
|
||||||
|
}.getOrElse { Env() }
|
||||||
|
|
||||||
|
class Env(
|
||||||
|
val magiskVersionCode: Int = -1,
|
||||||
|
val magiskVersionString: String = "",
|
||||||
|
hide: Boolean = false,
|
||||||
|
var connectionMode: Int = -1
|
||||||
|
) {
|
||||||
|
val magiskHide get() = Config.magiskHide
|
||||||
|
|
||||||
|
init {
|
||||||
|
Config.magiskHide = hide
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
124
app/src/main/java/com/topjohnwu/magisk/base/BaseActivity.kt
Normal file
124
app/src/main/java/com/topjohnwu/magisk/base/BaseActivity.kt
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
package com.topjohnwu.magisk.base
|
||||||
|
|
||||||
|
import android.Manifest
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.collection.SparseArrayCompat
|
||||||
|
import androidx.core.app.ActivityCompat
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import androidx.databinding.ViewDataBinding
|
||||||
|
import com.topjohnwu.magisk.BR
|
||||||
|
import com.topjohnwu.magisk.Config
|
||||||
|
import com.topjohnwu.magisk.R
|
||||||
|
import com.topjohnwu.magisk.base.viewmodel.BaseViewModel
|
||||||
|
import com.topjohnwu.magisk.extensions.set
|
||||||
|
import com.topjohnwu.magisk.model.events.EventHandler
|
||||||
|
import com.topjohnwu.magisk.model.permissions.PermissionRequestBuilder
|
||||||
|
import com.topjohnwu.magisk.utils.currentLocale
|
||||||
|
import com.topjohnwu.magisk.wrap
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
typealias RequestCallback = BaseActivity<*, *>.(Int, Intent?) -> Unit
|
||||||
|
|
||||||
|
abstract class BaseActivity<ViewModel : BaseViewModel, Binding : ViewDataBinding> :
|
||||||
|
AppCompatActivity(), EventHandler {
|
||||||
|
|
||||||
|
protected lateinit var binding: Binding
|
||||||
|
protected abstract val layoutRes: Int
|
||||||
|
protected abstract val viewModel: ViewModel
|
||||||
|
protected open val themeRes: Int = R.style.MagiskTheme
|
||||||
|
protected open val snackbarView get() = binding.root
|
||||||
|
|
||||||
|
private val resultCallbacks by lazy { SparseArrayCompat<RequestCallback>() }
|
||||||
|
|
||||||
|
init {
|
||||||
|
val theme = if (Config.darkTheme) {
|
||||||
|
AppCompatDelegate.MODE_NIGHT_YES
|
||||||
|
} else {
|
||||||
|
AppCompatDelegate.MODE_NIGHT_NO
|
||||||
|
}
|
||||||
|
AppCompatDelegate.setDefaultNightMode(theme)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyOverrideConfiguration(config: Configuration?) {
|
||||||
|
// Force applying our preferred local
|
||||||
|
config?.setLocale(currentLocale)
|
||||||
|
super.applyOverrideConfiguration(config)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun attachBaseContext(base: Context) {
|
||||||
|
super.attachBaseContext(base.wrap(false))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
setTheme(themeRes)
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
viewModel.viewEvents.observe(this, viewEventObserver)
|
||||||
|
|
||||||
|
binding = DataBindingUtil.setContentView<Binding>(this, layoutRes).apply {
|
||||||
|
setVariable(BR.viewModel, viewModel)
|
||||||
|
lifecycleOwner = this@BaseActivity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun withPermissions(vararg permissions: String, builder: PermissionRequestBuilder.() -> Unit) {
|
||||||
|
val request = PermissionRequestBuilder().apply(builder).build()
|
||||||
|
val ungranted = permissions.filter {
|
||||||
|
ContextCompat.checkSelfPermission(this, it) != PackageManager.PERMISSION_GRANTED
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ungranted.isEmpty()) {
|
||||||
|
request.onSuccess()
|
||||||
|
} else {
|
||||||
|
val requestCode = Random.nextInt(256, 512)
|
||||||
|
resultCallbacks[requestCode] = { result, _ ->
|
||||||
|
if (result > 0)
|
||||||
|
request.onSuccess()
|
||||||
|
else
|
||||||
|
request.onFailure()
|
||||||
|
}
|
||||||
|
ActivityCompat.requestPermissions(this, ungranted.toTypedArray(), requestCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun withExternalRW(builder: PermissionRequestBuilder.() -> Unit) {
|
||||||
|
withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE, builder = builder)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onRequestPermissionsResult(
|
||||||
|
requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||||
|
var success = true
|
||||||
|
for (res in grantResults) {
|
||||||
|
if (res != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
success = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resultCallbacks[requestCode]?.apply {
|
||||||
|
resultCallbacks.remove(requestCode)
|
||||||
|
invoke(this@BaseActivity, if (success) 1 else -1, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
resultCallbacks[requestCode]?.apply {
|
||||||
|
resultCallbacks.remove(requestCode)
|
||||||
|
invoke(this@BaseActivity, resultCode, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startActivityForResult(intent: Intent, requestCode: Int, listener: RequestCallback) {
|
||||||
|
resultCallbacks[requestCode] = listener
|
||||||
|
startActivityForResult(intent, requestCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
50
app/src/main/java/com/topjohnwu/magisk/base/BaseFragment.kt
Normal file
50
app/src/main/java/com/topjohnwu/magisk/base/BaseFragment.kt
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package com.topjohnwu.magisk.base
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.annotation.CallSuper
|
||||||
|
import androidx.databinding.DataBindingUtil
|
||||||
|
import androidx.databinding.ViewDataBinding
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.topjohnwu.magisk.BR
|
||||||
|
import com.topjohnwu.magisk.base.viewmodel.BaseViewModel
|
||||||
|
import com.topjohnwu.magisk.model.events.EventHandler
|
||||||
|
import com.topjohnwu.magisk.model.events.ViewEvent
|
||||||
|
|
||||||
|
abstract class BaseFragment<ViewModel : BaseViewModel, Binding : ViewDataBinding> :
|
||||||
|
Fragment(), EventHandler {
|
||||||
|
|
||||||
|
protected val activity get() = requireActivity() as BaseActivity<*, *>
|
||||||
|
protected lateinit var binding: Binding
|
||||||
|
protected abstract val layoutRes: Int
|
||||||
|
protected abstract val viewModel: ViewModel
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
viewModel.viewEvents.observe(this, viewEventObserver)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
binding = DataBindingUtil.inflate<Binding>(inflater, layoutRes, container, false).apply {
|
||||||
|
setVariable(BR.viewModel, viewModel)
|
||||||
|
lifecycleOwner = this@BaseFragment
|
||||||
|
}
|
||||||
|
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
override fun onEventDispatched(event: ViewEvent) {
|
||||||
|
super.onEventDispatched(event)
|
||||||
|
activity.onEventDispatched(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun onBackPressed(): Boolean = false
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
package com.topjohnwu.magisk.base
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.preference.*
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
|
||||||
|
abstract class BasePreferenceFragment : PreferenceFragmentCompat(),
|
||||||
|
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
|
protected val prefs: SharedPreferences by inject()
|
||||||
|
protected val activity get() = requireActivity() as BaseActivity<*, *>
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
val v = super.onCreateView(inflater, container, savedInstanceState)
|
||||||
|
prefs.registerOnSharedPreferenceChangeListener(this)
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDestroyView() {
|
||||||
|
prefs.unregisterOnSharedPreferenceChangeListener(this)
|
||||||
|
super.onDestroyView()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setAllPreferencesToAvoidHavingExtraSpace(preference: Preference) {
|
||||||
|
preference.isIconSpaceReserved = false
|
||||||
|
if (preference is PreferenceGroup)
|
||||||
|
for (i in 0 until preference.preferenceCount)
|
||||||
|
setAllPreferencesToAvoidHavingExtraSpace(preference.getPreference(i))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setPreferenceScreen(preferenceScreen: PreferenceScreen?) {
|
||||||
|
if (preferenceScreen != null)
|
||||||
|
setAllPreferencesToAvoidHavingExtraSpace(preferenceScreen)
|
||||||
|
super.setPreferenceScreen(preferenceScreen)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateAdapter(preferenceScreen: PreferenceScreen?): RecyclerView.Adapter<*> =
|
||||||
|
object : PreferenceGroupAdapter(preferenceScreen) {
|
||||||
|
@SuppressLint("RestrictedApi")
|
||||||
|
override fun onPreferenceHierarchyChange(preference: Preference?) {
|
||||||
|
if (preference != null)
|
||||||
|
setAllPreferencesToAvoidHavingExtraSpace(preference)
|
||||||
|
super.onPreferenceHierarchyChange(preference)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
app/src/main/java/com/topjohnwu/magisk/base/BaseReceiver.kt
Normal file
17
app/src/main/java/com/topjohnwu/magisk/base/BaseReceiver.kt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.topjohnwu.magisk.base
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
|
import android.content.Intent
|
||||||
|
import com.topjohnwu.magisk.wrap
|
||||||
|
import org.koin.core.KoinComponent
|
||||||
|
|
||||||
|
abstract class BaseReceiver : BroadcastReceiver(), KoinComponent {
|
||||||
|
|
||||||
|
final override fun onReceive(context: Context, intent: Intent?) {
|
||||||
|
onReceive(context.wrap() as ContextWrapper, intent)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract fun onReceive(context: ContextWrapper, intent: Intent?)
|
||||||
|
}
|
12
app/src/main/java/com/topjohnwu/magisk/base/BaseService.kt
Normal file
12
app/src/main/java/com/topjohnwu/magisk/base/BaseService.kt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package com.topjohnwu.magisk.base
|
||||||
|
|
||||||
|
import android.app.Service
|
||||||
|
import android.content.Context
|
||||||
|
import com.topjohnwu.magisk.wrap
|
||||||
|
import org.koin.core.KoinComponent
|
||||||
|
|
||||||
|
abstract class BaseService : Service(), KoinComponent {
|
||||||
|
override fun attachBaseContext(base: Context) {
|
||||||
|
super.attachBaseContext(base.wrap())
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,59 @@
|
|||||||
|
package com.topjohnwu.magisk.base
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.Network
|
||||||
|
import android.net.Uri
|
||||||
|
import androidx.annotation.MainThread
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import androidx.work.Data
|
||||||
|
import androidx.work.ListenableWorker
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
abstract class DelegateWorker {
|
||||||
|
|
||||||
|
private lateinit var worker: ListenableWorker
|
||||||
|
|
||||||
|
val applicationContext: Context
|
||||||
|
get() = worker.applicationContext
|
||||||
|
|
||||||
|
val id: UUID
|
||||||
|
get() = worker.id
|
||||||
|
|
||||||
|
val inputData: Data
|
||||||
|
get() = worker.inputData
|
||||||
|
|
||||||
|
val tags: Set<String>
|
||||||
|
get() = worker.tags
|
||||||
|
|
||||||
|
val triggeredContentUris: List<Uri>
|
||||||
|
@RequiresApi(24)
|
||||||
|
get() = worker.triggeredContentUris
|
||||||
|
|
||||||
|
val triggeredContentAuthorities: List<String>
|
||||||
|
@RequiresApi(24)
|
||||||
|
get() = worker.triggeredContentAuthorities
|
||||||
|
|
||||||
|
val network: Network?
|
||||||
|
@RequiresApi(28)
|
||||||
|
get() = worker.network
|
||||||
|
|
||||||
|
val runAttemptCount: Int
|
||||||
|
get() = worker.runAttemptCount
|
||||||
|
|
||||||
|
val isStopped: Boolean
|
||||||
|
get() = worker.isStopped
|
||||||
|
|
||||||
|
abstract fun doWork(): ListenableWorker.Result
|
||||||
|
|
||||||
|
fun onStopped() {}
|
||||||
|
|
||||||
|
fun attachWorker(w: ListenableWorker) {
|
||||||
|
worker = w
|
||||||
|
}
|
||||||
|
|
||||||
|
@MainThread
|
||||||
|
fun startWork(): ListenableFuture<ListenableWorker.Result> {
|
||||||
|
return worker.startWork()
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,35 @@
|
|||||||
|
package com.topjohnwu.magisk.base.viewmodel
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import com.topjohnwu.magisk.extensions.doOnSubscribeUi
|
||||||
|
import com.topjohnwu.magisk.model.events.BackPressEvent
|
||||||
|
import com.topjohnwu.magisk.model.events.PermissionEvent
|
||||||
|
import com.topjohnwu.magisk.model.events.ViewActionEvent
|
||||||
|
import com.topjohnwu.magisk.utils.KObservableField
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import io.reactivex.subjects.PublishSubject
|
||||||
|
import com.topjohnwu.magisk.Info.isConnected as gIsConnected
|
||||||
|
|
||||||
|
|
||||||
|
abstract class BaseViewModel(
|
||||||
|
initialState: State = State.LOADING
|
||||||
|
) : LoadingViewModel(initialState) {
|
||||||
|
|
||||||
|
val isConnected = object : KObservableField<Boolean>(gIsConnected.value, gIsConnected) {
|
||||||
|
override fun get(): Boolean {
|
||||||
|
return gIsConnected.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun withView(action: Activity.() -> Unit) {
|
||||||
|
ViewActionEvent(action).publish()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun withPermissions(vararg permissions: String): Observable<Boolean> {
|
||||||
|
val subject = PublishSubject.create<Boolean>()
|
||||||
|
return subject.doOnSubscribeUi { PermissionEvent(permissions.toList(), subject).publish() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun back() = BackPressEvent().publish()
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,78 @@
|
|||||||
|
package com.topjohnwu.magisk.base.viewmodel
|
||||||
|
|
||||||
|
import androidx.databinding.Bindable
|
||||||
|
import com.topjohnwu.magisk.BR
|
||||||
|
import io.reactivex.*
|
||||||
|
|
||||||
|
abstract class LoadingViewModel(defaultState: State = State.LOADING) :
|
||||||
|
StatefulViewModel<LoadingViewModel.State>(defaultState) {
|
||||||
|
|
||||||
|
val loading @Bindable get() = state == State.LOADING
|
||||||
|
val loaded @Bindable get() = state == State.LOADED
|
||||||
|
val loadingFailed @Bindable get() = state == State.LOADING_FAILED
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"Direct access is recommended since 0.2. This access method will be removed in 1.0",
|
||||||
|
ReplaceWith("state = State.LOADING", "com.topjohnwu.magisk.base.viewmodel.LoadingViewModel.State"),
|
||||||
|
DeprecationLevel.WARNING
|
||||||
|
)
|
||||||
|
fun setLoading() {
|
||||||
|
state = State.LOADING
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"Direct access is recommended since 0.2. This access method will be removed in 1.0",
|
||||||
|
ReplaceWith("state = State.LOADED", "com.topjohnwu.magisk.base.viewmodel.LoadingViewModel.State"),
|
||||||
|
DeprecationLevel.WARNING
|
||||||
|
)
|
||||||
|
fun setLoaded() {
|
||||||
|
state = State.LOADED
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated(
|
||||||
|
"Direct access is recommended since 0.2. This access method will be removed in 1.0",
|
||||||
|
ReplaceWith("state = State.LOADING_FAILED", "com.topjohnwu.magisk.base.viewmodel.LoadingViewModel.State"),
|
||||||
|
DeprecationLevel.WARNING
|
||||||
|
)
|
||||||
|
fun setLoadingFailed() {
|
||||||
|
state = State.LOADING_FAILED
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun notifyStateChanged() {
|
||||||
|
notifyPropertyChanged(BR.loading)
|
||||||
|
notifyPropertyChanged(BR.loaded)
|
||||||
|
notifyPropertyChanged(BR.loadingFailed)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class State {
|
||||||
|
LOADED, LOADING, LOADING_FAILED
|
||||||
|
}
|
||||||
|
|
||||||
|
//region Rx
|
||||||
|
protected fun <T> Observable<T>.applyViewModel(viewModel: LoadingViewModel, allowFinishing: Boolean = true) =
|
||||||
|
doOnSubscribe { viewModel.state = State.LOADING }
|
||||||
|
.doOnError { viewModel.state = State.LOADING_FAILED }
|
||||||
|
.doOnNext { if (allowFinishing) viewModel.state = State.LOADED }
|
||||||
|
|
||||||
|
protected fun <T> Single<T>.applyViewModel(viewModel: LoadingViewModel, allowFinishing: Boolean = true) =
|
||||||
|
doOnSubscribe { viewModel.state = State.LOADING }
|
||||||
|
.doOnError { viewModel.state = State.LOADING_FAILED }
|
||||||
|
.doOnSuccess { if (allowFinishing) viewModel.state = State.LOADED }
|
||||||
|
|
||||||
|
protected fun <T> Maybe<T>.applyViewModel(viewModel: LoadingViewModel, allowFinishing: Boolean = true) =
|
||||||
|
doOnSubscribe { viewModel.state = State.LOADING }
|
||||||
|
.doOnError { viewModel.state = State.LOADING_FAILED }
|
||||||
|
.doOnComplete { if (allowFinishing) viewModel.state = State.LOADED }
|
||||||
|
.doOnSuccess { if (allowFinishing) viewModel.state = State.LOADED }
|
||||||
|
|
||||||
|
protected fun <T> Flowable<T>.applyViewModel(viewModel: LoadingViewModel, allowFinishing: Boolean = true) =
|
||||||
|
doOnSubscribe { viewModel.state = State.LOADING }
|
||||||
|
.doOnError { viewModel.state = State.LOADING_FAILED }
|
||||||
|
.doOnNext { if (allowFinishing) viewModel.state = State.LOADED }
|
||||||
|
|
||||||
|
protected fun Completable.applyViewModel(viewModel: LoadingViewModel, allowFinishing: Boolean = true) =
|
||||||
|
doOnSubscribe { viewModel.state = State.LOADING }
|
||||||
|
.doOnError { viewModel.state = State.LOADING_FAILED }
|
||||||
|
.doOnComplete { if (allowFinishing) viewModel.state = State.LOADED }
|
||||||
|
//endregion
|
||||||
|
}
|
@@ -0,0 +1,46 @@
|
|||||||
|
package com.topjohnwu.magisk.base.viewmodel
|
||||||
|
|
||||||
|
import androidx.databinding.Observable
|
||||||
|
import androidx.databinding.PropertyChangeRegistry
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy of [android.databinding.BaseObservable] which extends [ViewModel]
|
||||||
|
*/
|
||||||
|
abstract class ObservableViewModel : TeanityViewModel(), Observable {
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private var callbacks: PropertyChangeRegistry? = null
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun addOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback) {
|
||||||
|
if (callbacks == null) {
|
||||||
|
callbacks = PropertyChangeRegistry()
|
||||||
|
}
|
||||||
|
callbacks?.add(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun removeOnPropertyChangedCallback(callback: Observable.OnPropertyChangedCallback) {
|
||||||
|
callbacks?.remove(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies listeners that all properties of this instance have changed.
|
||||||
|
*/
|
||||||
|
@Synchronized
|
||||||
|
fun notifyChange() {
|
||||||
|
callbacks?.notifyCallbacks(this, 0, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies listeners that a specific property has changed. The getter for the property
|
||||||
|
* that changes should be marked with [android.databinding.Bindable] to generate a field in
|
||||||
|
* `BR` to be used as `fieldId`.
|
||||||
|
*
|
||||||
|
* @param fieldId The generated BR id for the Bindable field.
|
||||||
|
*/
|
||||||
|
fun notifyPropertyChanged(fieldId: Int) {
|
||||||
|
callbacks?.notifyCallbacks(this, fieldId, null)
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,15 @@
|
|||||||
|
package com.topjohnwu.magisk.base.viewmodel
|
||||||
|
|
||||||
|
abstract class StatefulViewModel<State : Enum<*>>(
|
||||||
|
val defaultState: State
|
||||||
|
) : ObservableViewModel() {
|
||||||
|
|
||||||
|
var state: State = defaultState
|
||||||
|
set(value) {
|
||||||
|
field = value
|
||||||
|
notifyStateChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun notifyStateChanged() = Unit
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
package com.topjohnwu.magisk.base.viewmodel
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
import com.topjohnwu.magisk.model.events.SimpleViewEvent
|
||||||
|
import com.topjohnwu.magisk.model.events.ViewEvent
|
||||||
|
import io.reactivex.disposables.CompositeDisposable
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
|
||||||
|
abstract class TeanityViewModel : ViewModel() {
|
||||||
|
|
||||||
|
private val disposables = CompositeDisposable()
|
||||||
|
private val _viewEvents = MutableLiveData<ViewEvent>()
|
||||||
|
val viewEvents: LiveData<ViewEvent> get() = _viewEvents
|
||||||
|
|
||||||
|
override fun onCleared() {
|
||||||
|
super.onCleared()
|
||||||
|
disposables.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <Event : ViewEvent> Event.publish() {
|
||||||
|
_viewEvents.value = this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Int.publish() {
|
||||||
|
_viewEvents.value = SimpleViewEvent(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Disposable.add() {
|
||||||
|
disposables.add(this)
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,33 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.data.database.base.*
|
||||||
|
import com.topjohnwu.magisk.model.entity.MagiskLog
|
||||||
|
import com.topjohnwu.magisk.model.entity.toLog
|
||||||
|
import com.topjohnwu.magisk.model.entity.toMap
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
class LogDao : BaseDao() {
|
||||||
|
|
||||||
|
override val table = DatabaseDefinition.Table.LOG
|
||||||
|
|
||||||
|
fun deleteOutdated(
|
||||||
|
suTimeout: Long = TimeUnit.DAYS.toMillis(14)
|
||||||
|
) = query<Delete> {
|
||||||
|
condition {
|
||||||
|
lessThan("time", suTimeout.toString())
|
||||||
|
}
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun deleteAll() = query<Delete> {}.ignoreElement()
|
||||||
|
|
||||||
|
fun fetchAll() = query<Select> {
|
||||||
|
orderBy("time", Order.DESC)
|
||||||
|
}.flattenAsFlowable { it }
|
||||||
|
.map { it.toLog() }
|
||||||
|
.toList()
|
||||||
|
|
||||||
|
fun put(log: MagiskLog) = query<Insert> {
|
||||||
|
values(log.toMap())
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
}
|
@@ -1,190 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.data.database;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.Config;
|
|
||||||
import com.topjohnwu.magisk.Const;
|
|
||||||
import com.topjohnwu.magisk.model.entity.Policy;
|
|
||||||
import com.topjohnwu.magisk.model.entity.SuLogEntry;
|
|
||||||
import com.topjohnwu.magisk.utils.LocaleManager;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class MagiskDB {
|
|
||||||
|
|
||||||
private static final String POLICY_TABLE = "policies";
|
|
||||||
private static final String LOG_TABLE = "logs";
|
|
||||||
private static final String SETTINGS_TABLE = "settings";
|
|
||||||
private static final String STRINGS_TABLE = "strings";
|
|
||||||
|
|
||||||
private PackageManager pm;
|
|
||||||
|
|
||||||
public MagiskDB(Context context) {
|
|
||||||
pm = context.getPackageManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePolicy(Policy policy) {
|
|
||||||
deletePolicy(policy.uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> rawSQL(String fmt, Object... args) {
|
|
||||||
return Shell.su("magisk --sqlite '" + Utils.fmt(fmt, args) + "'").exec().getOut();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<ContentValues> SQL(String fmt, Object... args) {
|
|
||||||
List<ContentValues> list = new ArrayList<>();
|
|
||||||
for (String raw : rawSQL(fmt, args)) {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
String[] cols = raw.split("\\|");
|
|
||||||
for (String col : cols) {
|
|
||||||
String[] pair = col.split("=", 2);
|
|
||||||
if (pair.length != 2)
|
|
||||||
continue;
|
|
||||||
values.put(pair[0], pair[1]);
|
|
||||||
}
|
|
||||||
list.add(values);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String toSQL(ContentValues values) {
|
|
||||||
StringBuilder keys = new StringBuilder(), vals = new StringBuilder();
|
|
||||||
keys.append('(');
|
|
||||||
vals.append("VALUES(");
|
|
||||||
boolean first = true;
|
|
||||||
for (Map.Entry<String, Object> entry : values.valueSet()) {
|
|
||||||
if (!first) {
|
|
||||||
keys.append(',');
|
|
||||||
vals.append(',');
|
|
||||||
} else {
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
keys.append(entry.getKey());
|
|
||||||
vals.append('"');
|
|
||||||
vals.append(entry.getValue());
|
|
||||||
vals.append('"');
|
|
||||||
}
|
|
||||||
keys.append(')');
|
|
||||||
vals.append(')');
|
|
||||||
keys.append(vals);
|
|
||||||
return keys.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearOutdated() {
|
|
||||||
rawSQL(
|
|
||||||
"DELETE FROM %s WHERE until > 0 AND until < %d;" +
|
|
||||||
"DELETE FROM %s WHERE time < %d",
|
|
||||||
POLICY_TABLE, System.currentTimeMillis() / 1000,
|
|
||||||
LOG_TABLE, System.currentTimeMillis() - Config.suLogTimeout * 86400000
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePolicy(String pkg) {
|
|
||||||
rawSQL("DELETE FROM %s WHERE package_name=\"%s\"", POLICY_TABLE, pkg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deletePolicy(int uid) {
|
|
||||||
rawSQL("DELETE FROM %s WHERE uid=%d", POLICY_TABLE, uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Policy getPolicy(int uid) {
|
|
||||||
List<ContentValues> res =
|
|
||||||
SQL("SELECT * FROM %s WHERE uid=%d", POLICY_TABLE, uid);
|
|
||||||
if (!res.isEmpty()) {
|
|
||||||
try {
|
|
||||||
return new Policy(res.get(0), pm);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
deletePolicy(uid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updatePolicy(Policy policy) {
|
|
||||||
rawSQL("REPLACE INTO %s %s", POLICY_TABLE, toSQL(policy.getContentValues()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Policy> getPolicyList() {
|
|
||||||
List<Policy> list = new ArrayList<>();
|
|
||||||
for (ContentValues values : SQL("SELECT * FROM %s WHERE uid/100000=%d", POLICY_TABLE, Const.USER_ID)) {
|
|
||||||
try {
|
|
||||||
list.add(new Policy(values, pm));
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
deletePolicy(values.getAsInteger("uid"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(list);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<List<SuLogEntry>> getLogs() {
|
|
||||||
List<List<SuLogEntry>> ret = new ArrayList<>();
|
|
||||||
List<SuLogEntry> list = null;
|
|
||||||
String dateString = null, newString;
|
|
||||||
for (ContentValues values : SQL("SELECT * FROM %s ORDER BY time DESC", LOG_TABLE)) {
|
|
||||||
Date date = new Date(values.getAsLong("time"));
|
|
||||||
newString = DateFormat.getDateInstance(DateFormat.MEDIUM, LocaleManager.locale).format(date);
|
|
||||||
if (!TextUtils.equals(dateString, newString)) {
|
|
||||||
dateString = newString;
|
|
||||||
list = new ArrayList<>();
|
|
||||||
ret.add(list);
|
|
||||||
}
|
|
||||||
list.add(new SuLogEntry(values));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addLog(SuLogEntry log) {
|
|
||||||
rawSQL("INSERT INTO %s %s", LOG_TABLE, toSQL(log.getContentValues()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearLogs() {
|
|
||||||
rawSQL("DELETE FROM %s", LOG_TABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void rmSettings(String key) {
|
|
||||||
rawSQL("DELETE FROM %s WHERE key=\"%s\"", SETTINGS_TABLE, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSettings(String key, int value) {
|
|
||||||
ContentValues data = new ContentValues();
|
|
||||||
data.put("key", key);
|
|
||||||
data.put("value", value);
|
|
||||||
rawSQL("REPLACE INTO %s %s", SETTINGS_TABLE, toSQL(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSettings(String key, int defaultValue) {
|
|
||||||
List<ContentValues> res = SQL("SELECT value FROM %s WHERE key=\"%s\"", SETTINGS_TABLE, key);
|
|
||||||
if (res.isEmpty())
|
|
||||||
return defaultValue;
|
|
||||||
return res.get(0).getAsInteger("value");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStrings(String key, String value) {
|
|
||||||
if (value == null) {
|
|
||||||
rawSQL("DELETE FROM %s WHERE key=\"%s\"", STRINGS_TABLE, key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ContentValues data = new ContentValues();
|
|
||||||
data.put("key", key);
|
|
||||||
data.put("value", value);
|
|
||||||
rawSQL("REPLACE INTO %s %s", STRINGS_TABLE, toSQL(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStrings(String key, String defaultValue) {
|
|
||||||
List<ContentValues> res = SQL("SELECT value FROM %s WHERE key=\"%s\"", STRINGS_TABLE, key);
|
|
||||||
if (res.isEmpty())
|
|
||||||
return defaultValue;
|
|
||||||
return res.get(0).getAsString("value");
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,75 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import com.topjohnwu.magisk.Const
|
||||||
|
import com.topjohnwu.magisk.data.database.base.*
|
||||||
|
import com.topjohnwu.magisk.extensions.now
|
||||||
|
import com.topjohnwu.magisk.model.entity.MagiskPolicy
|
||||||
|
import com.topjohnwu.magisk.model.entity.toMap
|
||||||
|
import com.topjohnwu.magisk.model.entity.toPolicy
|
||||||
|
import timber.log.Timber
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
|
class PolicyDao(
|
||||||
|
private val context: Context
|
||||||
|
) : BaseDao() {
|
||||||
|
|
||||||
|
override val table: String = DatabaseDefinition.Table.POLICY
|
||||||
|
|
||||||
|
fun deleteOutdated(
|
||||||
|
nowSeconds: Long = TimeUnit.MILLISECONDS.toSeconds(now)
|
||||||
|
) = query<Delete> {
|
||||||
|
condition {
|
||||||
|
greaterThan("until", "0")
|
||||||
|
and {
|
||||||
|
lessThan("until", nowSeconds.toString())
|
||||||
|
}
|
||||||
|
or {
|
||||||
|
lessThan("until", "0")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun delete(packageName: String) = query<Delete> {
|
||||||
|
condition {
|
||||||
|
equals("package_name", packageName)
|
||||||
|
}
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun delete(uid: Int) = query<Delete> {
|
||||||
|
condition {
|
||||||
|
equals("uid", uid)
|
||||||
|
}
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun fetch(uid: Int) = query<Select> {
|
||||||
|
condition {
|
||||||
|
equals("uid", uid)
|
||||||
|
}
|
||||||
|
}.map { it.first().toPolicySafe() }
|
||||||
|
|
||||||
|
fun update(policy: MagiskPolicy) = query<Replace> {
|
||||||
|
values(policy.toMap())
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun fetchAll() = query<Select> {
|
||||||
|
condition {
|
||||||
|
equals("uid/100000", Const.USER_ID)
|
||||||
|
}
|
||||||
|
}.map { it.mapNotNull { it.toPolicySafe() } }
|
||||||
|
|
||||||
|
|
||||||
|
private fun Map<String, String>.toPolicySafe(): MagiskPolicy? {
|
||||||
|
return runCatching { toPolicy(context.packageManager) }.getOrElse {
|
||||||
|
Timber.e(it)
|
||||||
|
if (it is PackageManager.NameNotFoundException) {
|
||||||
|
val uid = getOrElse("uid") { null } ?: return null
|
||||||
|
delete(uid).subscribe()
|
||||||
|
}
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,72 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database
|
||||||
|
|
||||||
|
import androidx.room.*
|
||||||
|
import com.topjohnwu.magisk.Config
|
||||||
|
import com.topjohnwu.magisk.model.entity.module.Repo
|
||||||
|
|
||||||
|
@Dao
|
||||||
|
abstract class RepoDao {
|
||||||
|
|
||||||
|
val repoIDList get() = getRepoID().map { it.id }
|
||||||
|
|
||||||
|
val repos: List<Repo> get() = when (Config.repoOrder) {
|
||||||
|
Config.Value.ORDER_NAME -> getReposNameOrder()
|
||||||
|
else -> getReposDateOrder()
|
||||||
|
}
|
||||||
|
|
||||||
|
var etagKey: String
|
||||||
|
set(etag) = addEtagRaw(RepoEtag(0, etag))
|
||||||
|
get() = etagRaw()?.key.orEmpty()
|
||||||
|
|
||||||
|
fun clear() {
|
||||||
|
clearRepos()
|
||||||
|
clearEtag()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Query("SELECT * FROM repos ORDER BY last_update DESC")
|
||||||
|
protected abstract fun getReposDateOrder(): List<Repo>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM repos ORDER BY name COLLATE NOCASE")
|
||||||
|
protected abstract fun getReposNameOrder(): List<Repo>
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
abstract fun addRepo(repo: Repo)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM repos WHERE id = :id")
|
||||||
|
abstract fun getRepo(id: String): Repo?
|
||||||
|
|
||||||
|
@Query("SELECT id FROM repos")
|
||||||
|
protected abstract fun getRepoID(): List<RepoID>
|
||||||
|
|
||||||
|
@Delete
|
||||||
|
abstract fun removeRepo(repo: Repo)
|
||||||
|
|
||||||
|
@Query("DELETE FROM repos WHERE id = :id")
|
||||||
|
abstract fun removeRepo(id: String)
|
||||||
|
|
||||||
|
@Query("DELETE FROM repos WHERE id IN (:idList)")
|
||||||
|
abstract fun removeRepos(idList: Collection<String>)
|
||||||
|
|
||||||
|
@Query("SELECT * FROM etag")
|
||||||
|
protected abstract fun etagRaw(): RepoEtag?
|
||||||
|
|
||||||
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
protected abstract fun addEtagRaw(etag: RepoEtag)
|
||||||
|
|
||||||
|
@Query("DELETE FROM repos")
|
||||||
|
protected abstract fun clearRepos()
|
||||||
|
|
||||||
|
@Query("DELETE FROM etag")
|
||||||
|
protected abstract fun clearEtag()
|
||||||
|
}
|
||||||
|
|
||||||
|
data class RepoID(
|
||||||
|
@PrimaryKey val id: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@Entity(tableName = "etag")
|
||||||
|
data class RepoEtag(
|
||||||
|
@PrimaryKey val id: Int,
|
||||||
|
val key: String
|
||||||
|
)
|
||||||
|
|
@@ -0,0 +1,11 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database
|
||||||
|
|
||||||
|
import androidx.room.Database
|
||||||
|
import androidx.room.RoomDatabase
|
||||||
|
import com.topjohnwu.magisk.model.entity.module.Repo
|
||||||
|
|
||||||
|
@Database(version = 6, entities = [Repo::class, RepoEtag::class])
|
||||||
|
abstract class RepoDatabase : RoomDatabase() {
|
||||||
|
|
||||||
|
abstract fun repoDao() : RepoDao
|
||||||
|
}
|
@@ -1,107 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.data.database;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.Config;
|
|
||||||
import com.topjohnwu.magisk.model.entity.Repo;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
|
||||||
|
|
||||||
private static final int DATABASE_VER = 5;
|
|
||||||
private static final String TABLE_NAME = "repos";
|
|
||||||
|
|
||||||
private SQLiteDatabase mDb;
|
|
||||||
|
|
||||||
public RepoDatabaseHelper(Context context) {
|
|
||||||
super(context, "repo.db", null, DATABASE_VER);
|
|
||||||
mDb = getWritableDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(SQLiteDatabase db) {
|
|
||||||
onUpgrade(db, 0, DATABASE_VER);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
||||||
if (oldVersion != newVersion) {
|
|
||||||
// Nuke old DB and create new table
|
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
|
|
||||||
db.execSQL(
|
|
||||||
"CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " " +
|
|
||||||
"(id TEXT, name TEXT, version TEXT, versionCode INT, " +
|
|
||||||
"author TEXT, description TEXT, last_update INT, PRIMARY KEY(id))");
|
|
||||||
Config.remove(Config.Key.ETAG_KEY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
||||||
onUpgrade(db, 0, DATABASE_VER);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearRepo() {
|
|
||||||
mDb.delete(TABLE_NAME, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void removeRepo(String id) {
|
|
||||||
mDb.delete(TABLE_NAME, "id=?", new String[] { id });
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeRepo(Repo repo) {
|
|
||||||
removeRepo(repo.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeRepo(Iterable<String> list) {
|
|
||||||
for (String id : list) {
|
|
||||||
if (id == null) continue;
|
|
||||||
mDb.delete(TABLE_NAME, "id=?", new String[] { id });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addRepo(Repo repo) {
|
|
||||||
mDb.replace(TABLE_NAME, null, repo.getContentValues());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Repo getRepo(String id) {
|
|
||||||
try (Cursor c = mDb.query(TABLE_NAME, null, "id=?", new String[] { id }, null, null, null)) {
|
|
||||||
if (c.moveToNext()) {
|
|
||||||
return new Repo(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursor getRawCursor() {
|
|
||||||
return mDb.query(TABLE_NAME, null, null, null, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cursor getRepoCursor() {
|
|
||||||
String orderBy = null;
|
|
||||||
switch ((int) Config.get(Config.Key.REPO_ORDER)) {
|
|
||||||
case Config.Value.ORDER_NAME:
|
|
||||||
orderBy = "name COLLATE NOCASE";
|
|
||||||
break;
|
|
||||||
case Config.Value.ORDER_DATE:
|
|
||||||
orderBy = "last_update DESC";
|
|
||||||
}
|
|
||||||
return mDb.query(TABLE_NAME, null, null, null, null, null, orderBy);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getRepoIDSet() {
|
|
||||||
HashSet<String> set = new HashSet<>(300);
|
|
||||||
try (Cursor c = mDb.query(TABLE_NAME, null, null, null, null, null, null)) {
|
|
||||||
while (c.moveToNext()) {
|
|
||||||
set.add(c.getString(c.getColumnIndex("id")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return set;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,22 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.data.database.base.*
|
||||||
|
|
||||||
|
class SettingsDao : BaseDao() {
|
||||||
|
|
||||||
|
override val table = DatabaseDefinition.Table.SETTINGS
|
||||||
|
|
||||||
|
fun delete(key: String) = query<Delete> {
|
||||||
|
condition { equals("key", key) }
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun put(key: String, value: Int) = query<Replace> {
|
||||||
|
values("key" to key, "value" to value)
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun fetch(key: String, default: Int = -1) = query<Select> {
|
||||||
|
fields("value")
|
||||||
|
condition { equals("key", key) }
|
||||||
|
}.map { it.firstOrNull()?.values?.firstOrNull()?.toIntOrNull() ?: default }
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,22 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.data.database.base.*
|
||||||
|
|
||||||
|
class StringDao : BaseDao() {
|
||||||
|
|
||||||
|
override val table = DatabaseDefinition.Table.STRINGS
|
||||||
|
|
||||||
|
fun delete(key: String) = query<Delete> {
|
||||||
|
condition { equals("key", key) }
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun put(key: String, value: String) = query<Replace> {
|
||||||
|
values("key" to key, "value" to value)
|
||||||
|
}.ignoreElement()
|
||||||
|
|
||||||
|
fun fetch(key: String, default: String = "") = query<Select> {
|
||||||
|
fields("value")
|
||||||
|
condition { equals("key", key) }
|
||||||
|
}.map { it.firstOrNull()?.values?.firstOrNull() ?: default }
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,15 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database.base
|
||||||
|
|
||||||
|
abstract class BaseDao {
|
||||||
|
|
||||||
|
abstract val table: String
|
||||||
|
|
||||||
|
inline fun <reified Builder : MagiskQueryBuilder> query(builder: Builder.() -> Unit) =
|
||||||
|
Builder::class.java.newInstance()
|
||||||
|
.apply { table = this@BaseDao.table }
|
||||||
|
.apply(builder)
|
||||||
|
.toString()
|
||||||
|
.let { MagiskQuery(it) }
|
||||||
|
.query()
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,30 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database.base
|
||||||
|
|
||||||
|
import androidx.annotation.AnyThread
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import io.reactivex.Single
|
||||||
|
|
||||||
|
object DatabaseDefinition {
|
||||||
|
|
||||||
|
object Table {
|
||||||
|
const val POLICY = "policies"
|
||||||
|
const val LOG = "logs"
|
||||||
|
const val SETTINGS = "settings"
|
||||||
|
const val STRINGS = "strings"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@AnyThread
|
||||||
|
fun MagiskQuery.query() = query.su()
|
||||||
|
|
||||||
|
fun String.suRaw() = Single.fromCallable { Shell.su(this).exec().out }
|
||||||
|
fun String.su() = suRaw().map { it.toMap() }
|
||||||
|
|
||||||
|
fun List<String>.toMap() = map { it.split(Regex("\\|")) }
|
||||||
|
.map { it.toMapInternal() }
|
||||||
|
|
||||||
|
private fun List<String>.toMapInternal() = map { it.split("=", limit = 2) }
|
||||||
|
.filter { it.size == 2 }
|
||||||
|
.map { Pair(it[0], it[1]) }
|
||||||
|
.toMap()
|
@@ -0,0 +1,5 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database.base
|
||||||
|
|
||||||
|
inline class MagiskQuery(private val _query: String) {
|
||||||
|
val query get() = "magisk --sqlite '$_query'"
|
||||||
|
}
|
@@ -0,0 +1,155 @@
|
|||||||
|
package com.topjohnwu.magisk.data.database.base
|
||||||
|
|
||||||
|
import androidx.annotation.StringDef
|
||||||
|
import com.topjohnwu.magisk.data.database.base.Order.Companion.ASC
|
||||||
|
import com.topjohnwu.magisk.data.database.base.Order.Companion.DESC
|
||||||
|
|
||||||
|
interface MagiskQueryBuilder {
|
||||||
|
|
||||||
|
val requestType: String
|
||||||
|
var table: String
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
inline operator fun <reified Builder : MagiskQueryBuilder> invoke(builder: Builder.() -> Unit): MagiskQuery =
|
||||||
|
Builder::class.java.newInstance()
|
||||||
|
.apply(builder)
|
||||||
|
.toString()
|
||||||
|
.let {
|
||||||
|
MagiskQuery(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Delete : MagiskQueryBuilder {
|
||||||
|
override val requestType: String = "DELETE FROM"
|
||||||
|
override var table = ""
|
||||||
|
|
||||||
|
private var condition = ""
|
||||||
|
|
||||||
|
fun condition(builder: Condition.() -> Unit) {
|
||||||
|
condition = Condition().apply(builder).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return listOf(requestType, table, condition).joinToString(" ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Select : MagiskQueryBuilder {
|
||||||
|
override val requestType: String get() = "SELECT $fields FROM"
|
||||||
|
override lateinit var table: String
|
||||||
|
|
||||||
|
private var fields = "*"
|
||||||
|
private var condition = ""
|
||||||
|
private var orderField = ""
|
||||||
|
|
||||||
|
fun fields(vararg newFields: String) {
|
||||||
|
if (newFields.isEmpty()) {
|
||||||
|
fields = "*"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fields = newFields.joinToString(", ")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun condition(builder: Condition.() -> Unit) {
|
||||||
|
condition = Condition().apply(builder).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun orderBy(field: String, @OrderStrict order: String) {
|
||||||
|
orderField = "ORDER BY $field $order"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return listOf(requestType, table, condition, orderField).joinToString(" ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Replace : Insert() {
|
||||||
|
override val requestType: String = "REPLACE INTO"
|
||||||
|
}
|
||||||
|
|
||||||
|
open class Insert : MagiskQueryBuilder {
|
||||||
|
override val requestType: String = "INSERT INTO"
|
||||||
|
override lateinit var table: String
|
||||||
|
|
||||||
|
private val keys get() = _values.keys.joinToString(",")
|
||||||
|
private val values get() = _values.values.joinToString(",") {
|
||||||
|
when (it) {
|
||||||
|
is Boolean -> if (it) "1" else "0"
|
||||||
|
is Number -> it.toString()
|
||||||
|
else -> "\"$it\""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private var _values: Map<String, Any> = mapOf()
|
||||||
|
|
||||||
|
fun values(vararg pairs: Pair<String, Any>) {
|
||||||
|
_values = pairs.toMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun values(values: Map<String, Any>) {
|
||||||
|
_values = values
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return listOf(requestType, table, "($keys) VALUES($values)").joinToString(" ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Condition {
|
||||||
|
|
||||||
|
private val conditionWord = "WHERE %s"
|
||||||
|
private var condition: String = ""
|
||||||
|
|
||||||
|
fun equals(field: String, value: Any) {
|
||||||
|
condition = when (value) {
|
||||||
|
is String -> "$field=\"$value\""
|
||||||
|
else -> "$field=$value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun greaterThan(field: String, value: String) {
|
||||||
|
condition = "$field > $value"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun lessThan(field: String, value: String) {
|
||||||
|
condition = "$field < $value"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun greaterOrEqualTo(field: String, value: String) {
|
||||||
|
condition = "$field >= $value"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun lessOrEqualTo(field: String, value: String) {
|
||||||
|
condition = "$field <= $value"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun and(builder: Condition.() -> Unit) {
|
||||||
|
condition = "($condition AND ${Condition().apply(builder).condition})"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun or(builder: Condition.() -> Unit) {
|
||||||
|
condition = "($condition OR ${Condition().apply(builder).condition})"
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return conditionWord.format(condition)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Order {
|
||||||
|
|
||||||
|
@set:OrderStrict
|
||||||
|
var order = DESC
|
||||||
|
var field = ""
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val ASC = "ASC"
|
||||||
|
const val DESC = "DESC"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@StringDef(ASC, DESC)
|
||||||
|
@Retention(AnnotationRetention.SOURCE)
|
||||||
|
annotation class OrderStrict
|
@@ -0,0 +1,81 @@
|
|||||||
|
package com.topjohnwu.magisk.data.network
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.Const
|
||||||
|
import com.topjohnwu.magisk.model.entity.UpdateInfo
|
||||||
|
import com.topjohnwu.magisk.tasks.GithubRepoInfo
|
||||||
|
import io.reactivex.Flowable
|
||||||
|
import io.reactivex.Single
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import retrofit2.adapter.rxjava2.Result
|
||||||
|
import retrofit2.http.*
|
||||||
|
|
||||||
|
interface GithubRawServices {
|
||||||
|
|
||||||
|
//region topjohnwu/magisk_files
|
||||||
|
|
||||||
|
@GET("$MAGISK_FILES/master/stable.json")
|
||||||
|
fun fetchStableUpdate(): Single<UpdateInfo>
|
||||||
|
|
||||||
|
@GET("$MAGISK_FILES/master/beta.json")
|
||||||
|
fun fetchBetaUpdate(): Single<UpdateInfo>
|
||||||
|
|
||||||
|
@GET("$MAGISK_FILES/canary/release.json")
|
||||||
|
fun fetchCanaryUpdate(): Single<UpdateInfo>
|
||||||
|
|
||||||
|
@GET("$MAGISK_FILES/canary/debug.json")
|
||||||
|
fun fetchCanaryDebugUpdate(): Single<UpdateInfo>
|
||||||
|
|
||||||
|
@GET
|
||||||
|
fun fetchCustomUpdate(@Url url: String): Single<UpdateInfo>
|
||||||
|
|
||||||
|
@GET("$MAGISK_FILES/{$REVISION}/snet.jar")
|
||||||
|
@Streaming
|
||||||
|
fun fetchSafetynet(@Path(REVISION) revision: String = Const.SNET_REVISION): Single<ResponseBody>
|
||||||
|
|
||||||
|
@GET("$MAGISK_FILES/{$REVISION}/bootctl")
|
||||||
|
@Streaming
|
||||||
|
fun fetchBootctl(@Path(REVISION) revision: String = Const.BOOTCTL_REVISION): Single<ResponseBody>
|
||||||
|
|
||||||
|
@GET("$MAGISK_MASTER/scripts/module_installer.sh")
|
||||||
|
@Streaming
|
||||||
|
fun fetchInstaller(): Single<ResponseBody>
|
||||||
|
|
||||||
|
@GET("$MAGISK_MODULES/{$MODULE}/master/{$FILE}")
|
||||||
|
fun fetchModuleInfo(@Path(MODULE) id: String, @Path(FILE) file: String): Single<String>
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method shall be used exclusively for fetching files from urls from previous requests.
|
||||||
|
* Him, who uses it in a wrong way, shall die in an eternal flame.
|
||||||
|
* */
|
||||||
|
@GET
|
||||||
|
@Streaming
|
||||||
|
fun fetchFile(@Url url: String): Single<ResponseBody>
|
||||||
|
|
||||||
|
@GET
|
||||||
|
fun fetchString(@Url url: String): Single<String>
|
||||||
|
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val REVISION = "revision"
|
||||||
|
private const val MODULE = "module"
|
||||||
|
private const val FILE = "file"
|
||||||
|
|
||||||
|
|
||||||
|
private const val MAGISK_FILES = "topjohnwu/magisk_files"
|
||||||
|
private const val MAGISK_MASTER = "topjohnwu/Magisk/master"
|
||||||
|
private const val MAGISK_MODULES = "Magisk-Modules-Repo"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GithubApiServices {
|
||||||
|
|
||||||
|
@GET("repos")
|
||||||
|
fun fetchRepos(@Query("page") page: Int,
|
||||||
|
@Header(Const.Key.IF_NONE_MATCH) etag: String,
|
||||||
|
@Query("sort") sort: String = "pushed",
|
||||||
|
@Query("per_page") count: Int = 100): Flowable<Result<List<GithubRepoInfo>>>
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,106 @@
|
|||||||
|
package com.topjohnwu.magisk.data.repository
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.data.database.SettingsDao
|
||||||
|
import com.topjohnwu.magisk.data.database.StringDao
|
||||||
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
interface DBConfig {
|
||||||
|
val settingsDao: SettingsDao
|
||||||
|
val stringDao: StringDao
|
||||||
|
|
||||||
|
fun dbSettings(
|
||||||
|
name: String,
|
||||||
|
default: Int
|
||||||
|
) = DBSettingsValue(name, default)
|
||||||
|
|
||||||
|
fun dbSettings(
|
||||||
|
name: String,
|
||||||
|
default: Boolean
|
||||||
|
) = DBBoolSettings(name, default)
|
||||||
|
|
||||||
|
fun dbStrings(
|
||||||
|
name: String,
|
||||||
|
default: String,
|
||||||
|
sync: Boolean = false
|
||||||
|
) = DBStringsValue(name, default, sync)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DBSettingsValue(
|
||||||
|
private val name: String,
|
||||||
|
private val default: Int
|
||||||
|
) : ReadWriteProperty<DBConfig, Int> {
|
||||||
|
|
||||||
|
private var value: Int? = null
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun getValue(thisRef: DBConfig, property: KProperty<*>): Int {
|
||||||
|
if (value == null)
|
||||||
|
value = thisRef.settingsDao.fetch(name, default).blockingGet()
|
||||||
|
return value!!
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setValue(thisRef: DBConfig, property: KProperty<*>, value: Int) {
|
||||||
|
synchronized(this) {
|
||||||
|
this.value = value
|
||||||
|
}
|
||||||
|
thisRef.settingsDao.put(name, value)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.subscribe()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DBBoolSettings(
|
||||||
|
name: String,
|
||||||
|
default: Boolean
|
||||||
|
) : ReadWriteProperty<DBConfig, Boolean> {
|
||||||
|
|
||||||
|
val base = DBSettingsValue(name, if (default) 1 else 0)
|
||||||
|
|
||||||
|
override fun getValue(thisRef: DBConfig, property: KProperty<*>): Boolean
|
||||||
|
= base.getValue(thisRef, property) != 0
|
||||||
|
|
||||||
|
override fun setValue(thisRef: DBConfig, property: KProperty<*>, value: Boolean) =
|
||||||
|
base.setValue(thisRef, property, if (value) 1 else 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
class DBStringsValue(
|
||||||
|
private val name: String,
|
||||||
|
private val default: String,
|
||||||
|
private val sync: Boolean
|
||||||
|
) : ReadWriteProperty<DBConfig, String> {
|
||||||
|
|
||||||
|
private var value: String? = null
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun getValue(thisRef: DBConfig, property: KProperty<*>): String {
|
||||||
|
if (value == null)
|
||||||
|
value = thisRef.stringDao.fetch(name, default).blockingGet()
|
||||||
|
return value!!
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setValue(thisRef: DBConfig, property: KProperty<*>, value: String) {
|
||||||
|
synchronized(this) {
|
||||||
|
this.value = value
|
||||||
|
}
|
||||||
|
if (value.isEmpty()) {
|
||||||
|
if (sync) {
|
||||||
|
thisRef.stringDao.delete(name).blockingAwait()
|
||||||
|
} else {
|
||||||
|
thisRef.stringDao.delete(name)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.subscribe()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (sync) {
|
||||||
|
thisRef.stringDao.put(name, value).blockingAwait()
|
||||||
|
} else {
|
||||||
|
thisRef.stringDao.put(name, value)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.subscribe()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,40 @@
|
|||||||
|
package com.topjohnwu.magisk.data.repository
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.Const
|
||||||
|
import com.topjohnwu.magisk.data.database.LogDao
|
||||||
|
import com.topjohnwu.magisk.data.database.base.suRaw
|
||||||
|
import com.topjohnwu.magisk.extensions.toSingle
|
||||||
|
import com.topjohnwu.magisk.model.entity.MagiskLog
|
||||||
|
import com.topjohnwu.magisk.model.entity.WrappedMagiskLog
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
|
|
||||||
|
class LogRepository(
|
||||||
|
private val logDao: LogDao
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun fetchLogs() = logDao.fetchAll()
|
||||||
|
.map { it.sortByDescending { it.date.time }; it }
|
||||||
|
.map { it.wrap() }
|
||||||
|
|
||||||
|
fun fetchMagiskLogs() = "tail -n 5000 ${Const.MAGISK_LOG}".suRaw()
|
||||||
|
.filter { it.isNotEmpty() }
|
||||||
|
|
||||||
|
fun clearLogs() = logDao.deleteAll()
|
||||||
|
fun clearOutdated() = logDao.deleteOutdated()
|
||||||
|
|
||||||
|
fun clearMagiskLogs() = Shell.su("echo -n > " + Const.MAGISK_LOG)
|
||||||
|
.toSingle()
|
||||||
|
.map { it.exec() }
|
||||||
|
|
||||||
|
fun put(log: MagiskLog) = logDao.put(log)
|
||||||
|
|
||||||
|
private fun List<MagiskLog>.wrap(): List<WrappedMagiskLog> {
|
||||||
|
val day = TimeUnit.DAYS.toMillis(1)
|
||||||
|
return groupBy { it.date.time / day }
|
||||||
|
.map { WrappedMagiskLog(it.key * day, it.value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,77 @@
|
|||||||
|
package com.topjohnwu.magisk.data.repository
|
||||||
|
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import com.topjohnwu.magisk.Config
|
||||||
|
import com.topjohnwu.magisk.Info
|
||||||
|
import com.topjohnwu.magisk.data.database.base.su
|
||||||
|
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||||
|
import com.topjohnwu.magisk.extensions.getLabel
|
||||||
|
import com.topjohnwu.magisk.extensions.packageName
|
||||||
|
import com.topjohnwu.magisk.extensions.toSingle
|
||||||
|
import com.topjohnwu.magisk.model.entity.HideAppInfo
|
||||||
|
import com.topjohnwu.magisk.model.entity.HideTarget
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import io.reactivex.Single
|
||||||
|
|
||||||
|
class MagiskRepository(
|
||||||
|
private val apiRaw: GithubRawServices,
|
||||||
|
private val packageManager: PackageManager
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun fetchSafetynet() = apiRaw.fetchSafetynet()
|
||||||
|
|
||||||
|
fun fetchUpdate() = when (Config.updateChannel) {
|
||||||
|
Config.Value.DEFAULT_CHANNEL, Config.Value.STABLE_CHANNEL -> apiRaw.fetchStableUpdate()
|
||||||
|
Config.Value.BETA_CHANNEL -> apiRaw.fetchBetaUpdate()
|
||||||
|
Config.Value.CANARY_CHANNEL -> apiRaw.fetchCanaryUpdate()
|
||||||
|
Config.Value.CANARY_DEBUG_CHANNEL -> apiRaw.fetchCanaryDebugUpdate()
|
||||||
|
Config.Value.CUSTOM_CHANNEL -> apiRaw.fetchCustomUpdate(Config.customChannelUrl)
|
||||||
|
else -> throw IllegalArgumentException()
|
||||||
|
}.flatMap {
|
||||||
|
// If remote version is lower than current installed, try switching to beta
|
||||||
|
if (it.magisk.versionCode < Info.env.magiskVersionCode
|
||||||
|
&& Config.updateChannel == Config.Value.DEFAULT_CHANNEL) {
|
||||||
|
Config.updateChannel = Config.Value.BETA_CHANNEL
|
||||||
|
apiRaw.fetchBetaUpdate()
|
||||||
|
} else {
|
||||||
|
Single.just(it)
|
||||||
|
}
|
||||||
|
}.doOnSuccess { Info.remote = it }
|
||||||
|
|
||||||
|
fun fetchApps() =
|
||||||
|
Single.fromCallable { packageManager.getInstalledApplications(0) }
|
||||||
|
.flattenAsFlowable { it }
|
||||||
|
.filter { it.enabled && !blacklist.contains(it.packageName) }
|
||||||
|
.map {
|
||||||
|
val label = it.getLabel(packageManager)
|
||||||
|
val icon = it.loadIcon(packageManager)
|
||||||
|
HideAppInfo(it, label, icon)
|
||||||
|
}
|
||||||
|
.filter { it.processes.isNotEmpty() }
|
||||||
|
.toList()
|
||||||
|
|
||||||
|
fun fetchHideTargets() = Shell.su("magiskhide --ls").toSingle()
|
||||||
|
.map { it.exec().out }
|
||||||
|
.flattenAsFlowable { it }
|
||||||
|
.map { HideTarget(it) }
|
||||||
|
.toList()
|
||||||
|
|
||||||
|
fun toggleHide(isEnabled: Boolean, packageName: String, process: String) =
|
||||||
|
"magiskhide --%s %s %s".format(isEnabled.state, packageName, process).su().ignoreElement()
|
||||||
|
|
||||||
|
private val Boolean.state get() = if (this) "add" else "rm"
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val blacklist by lazy { listOf(
|
||||||
|
packageName,
|
||||||
|
"android",
|
||||||
|
"com.android.chrome",
|
||||||
|
"com.chrome.beta",
|
||||||
|
"com.chrome.dev",
|
||||||
|
"com.chrome.canary",
|
||||||
|
"com.android.webview",
|
||||||
|
"com.google.android.webview"
|
||||||
|
) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,15 @@
|
|||||||
|
package com.topjohnwu.magisk.data.repository
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||||
|
import com.topjohnwu.magisk.model.entity.module.Repo
|
||||||
|
|
||||||
|
class StringRepository(
|
||||||
|
private val api: GithubRawServices
|
||||||
|
) {
|
||||||
|
|
||||||
|
fun getString(url: String) = api.fetchString(url)
|
||||||
|
|
||||||
|
fun getMetadata(repo: Repo) = api.fetchModuleInfo(repo.id, "module.prop")
|
||||||
|
|
||||||
|
fun getReadme(repo: Repo) = api.fetchModuleInfo(repo.id, "README.md")
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
package com.topjohnwu.magisk.databinding
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.view.isGone
|
||||||
|
import androidx.core.view.isInvisible
|
||||||
|
import androidx.databinding.BindingAdapter
|
||||||
|
|
||||||
|
@BindingAdapter("gone")
|
||||||
|
fun setGone(view: View, gone: Boolean) {
|
||||||
|
view.isGone = gone
|
||||||
|
}
|
||||||
|
|
||||||
|
@BindingAdapter("invisible")
|
||||||
|
fun setInvisible(view: View, invisible: Boolean) {
|
||||||
|
view.isInvisible = invisible
|
||||||
|
}
|
||||||
|
|
||||||
|
@BindingAdapter("goneUnless")
|
||||||
|
fun setGoneUnless(view: View, goneUnless: Boolean) {
|
||||||
|
setGone(view, goneUnless.not())
|
||||||
|
}
|
||||||
|
|
||||||
|
@BindingAdapter("invisibleUnless")
|
||||||
|
fun setInvisibleUnless(view: View, invisibleUnless: Boolean) {
|
||||||
|
setInvisible(view, invisibleUnless.not())
|
||||||
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
package com.topjohnwu.magisk.databinding
|
||||||
|
|
||||||
|
import android.graphics.drawable.GradientDrawable
|
||||||
|
import android.graphics.drawable.InsetDrawable
|
||||||
|
import androidx.databinding.BindingAdapter
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.topjohnwu.magisk.extensions.startEndToLeftRight
|
||||||
|
import com.topjohnwu.magisk.extensions.toPx
|
||||||
|
import com.topjohnwu.magisk.utils.KItemDecoration
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
@BindingAdapter(
|
||||||
|
"dividerColor",
|
||||||
|
"dividerHorizontal",
|
||||||
|
"dividerSize",
|
||||||
|
"dividerAfterLast",
|
||||||
|
"dividerMarginStart",
|
||||||
|
"dividerMarginEnd",
|
||||||
|
"dividerMarginTop",
|
||||||
|
"dividerMarginBottom",
|
||||||
|
requireAll = false
|
||||||
|
)
|
||||||
|
fun setDivider(
|
||||||
|
view: RecyclerView,
|
||||||
|
color: Int,
|
||||||
|
horizontal: Boolean,
|
||||||
|
_size: Float,
|
||||||
|
_afterLast: Boolean?,
|
||||||
|
marginStartF: Float,
|
||||||
|
marginEndF: Float,
|
||||||
|
marginTopF: Float,
|
||||||
|
marginBottomF: Float
|
||||||
|
) {
|
||||||
|
val orientation = if (horizontal) RecyclerView.HORIZONTAL else RecyclerView.VERTICAL
|
||||||
|
val size = if (_size > 0) _size.roundToInt() else 1.toPx()
|
||||||
|
val (width, height) = if (horizontal) size to 1 else 1 to size
|
||||||
|
val afterLast = _afterLast ?: true
|
||||||
|
|
||||||
|
val marginStart = marginStartF.roundToInt()
|
||||||
|
val marginEnd = marginEndF.roundToInt()
|
||||||
|
val marginTop = marginTopF.roundToInt()
|
||||||
|
val marginBottom = marginBottomF.roundToInt()
|
||||||
|
val (marginLeft, marginRight) = view.context.startEndToLeftRight(marginStart, marginEnd)
|
||||||
|
|
||||||
|
val drawable = GradientDrawable().apply {
|
||||||
|
setSize(width, height)
|
||||||
|
shape = GradientDrawable.RECTANGLE
|
||||||
|
setColor(color)
|
||||||
|
}.let {
|
||||||
|
InsetDrawable(it, marginLeft, marginTop, marginRight, marginBottom)
|
||||||
|
}
|
||||||
|
|
||||||
|
val decoration = KItemDecoration(view.context, orientation)
|
||||||
|
.setDeco(drawable)
|
||||||
|
.apply { showAfterLast = afterLast }
|
||||||
|
view.addItemDecoration(decoration)
|
||||||
|
}
|
@@ -0,0 +1,13 @@
|
|||||||
|
package com.topjohnwu.magisk.databinding
|
||||||
|
|
||||||
|
import androidx.databinding.ViewDataBinding
|
||||||
|
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter
|
||||||
|
|
||||||
|
open class BindingBoundAdapter : BindingRecyclerViewAdapter<RvItem>() {
|
||||||
|
|
||||||
|
override fun onBindBinding(binding: ViewDataBinding, variableId: Int, layoutRes: Int, position: Int, item: RvItem) {
|
||||||
|
super.onBindBinding(binding, variableId, layoutRes, position, item)
|
||||||
|
|
||||||
|
item.onBindingBound(binding)
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,48 @@
|
|||||||
|
package com.topjohnwu.magisk.databinding
|
||||||
|
|
||||||
|
import androidx.annotation.CallSuper
|
||||||
|
import androidx.databinding.ViewDataBinding
|
||||||
|
import com.topjohnwu.magisk.BR
|
||||||
|
import com.topjohnwu.magisk.utils.DiffObservableList
|
||||||
|
import me.tatarka.bindingcollectionadapter2.ItemBinding
|
||||||
|
|
||||||
|
abstract class RvItem {
|
||||||
|
|
||||||
|
abstract val layoutRes: Int
|
||||||
|
|
||||||
|
@CallSuper
|
||||||
|
open fun bind(binding: ItemBinding<*>) {
|
||||||
|
binding.set(BR.item, layoutRes)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This callback is useful if you want to manipulate your views directly.
|
||||||
|
* If you want to use this callback, you must set [me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter]
|
||||||
|
* on your RecyclerView and call it from there. You can use [BindingBoundAdapter] for your convenience.
|
||||||
|
*/
|
||||||
|
open fun onBindingBound(binding: ViewDataBinding) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class ComparableRvItem<in T> : RvItem() {
|
||||||
|
|
||||||
|
abstract fun itemSameAs(other: T): Boolean
|
||||||
|
abstract fun contentSameAs(other: T): Boolean
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
open fun genericItemSameAs(other: Any): Boolean = other::class == this::class && itemSameAs(other as T)
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
open fun genericContentSameAs(other: Any): Boolean = other::class == this::class && contentSameAs(other as T)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val callback = object : DiffObservableList.Callback<ComparableRvItem<*>> {
|
||||||
|
override fun areItemsTheSame(
|
||||||
|
oldItem: ComparableRvItem<*>,
|
||||||
|
newItem: ComparableRvItem<*>
|
||||||
|
) = oldItem.genericItemSameAs(newItem)
|
||||||
|
|
||||||
|
override fun areContentsTheSame(
|
||||||
|
oldItem: ComparableRvItem<*>,
|
||||||
|
newItem: ComparableRvItem<*>
|
||||||
|
) = oldItem.genericContentSameAs(newItem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,61 @@
|
|||||||
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Activity
|
||||||
|
import android.app.Application
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.topjohnwu.magisk.utils.RxBus
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
val SUTimeout = named("su_timeout")
|
||||||
|
val Protected = named("protected")
|
||||||
|
|
||||||
|
val applicationModule = module {
|
||||||
|
single { RxBus() }
|
||||||
|
factory { get<Context>().resources }
|
||||||
|
factory { get<Context>().packageManager }
|
||||||
|
factory(Protected) { createDEContext(get()) }
|
||||||
|
single(SUTimeout) { get<Context>(Protected).getSharedPreferences("su_timeout", 0) }
|
||||||
|
single { PreferenceManager.getDefaultSharedPreferences(get<Context>(Protected)) }
|
||||||
|
single { ActivityTracker() }
|
||||||
|
factory { get<ActivityTracker>().foreground ?: NullActivity }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createDEContext(context: Context): Context {
|
||||||
|
return if (Build.VERSION.SDK_INT >= 24)
|
||||||
|
context.createDeviceProtectedStorageContext()
|
||||||
|
else context
|
||||||
|
}
|
||||||
|
|
||||||
|
class ActivityTracker : Application.ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
var foreground: Activity? = null
|
||||||
|
|
||||||
|
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {}
|
||||||
|
|
||||||
|
override fun onActivityStarted(activity: Activity) {}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onActivityResumed(activity: Activity) {
|
||||||
|
foreground = activity
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
override fun onActivityPaused(activity: Activity) {
|
||||||
|
foreground = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityStopped(activity: Activity) {}
|
||||||
|
|
||||||
|
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
|
||||||
|
|
||||||
|
override fun onActivityDestroyed(activity: Activity) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("Registered")
|
||||||
|
object NullActivity : Activity()
|
23
app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt
Normal file
23
app/src/main/java/com/topjohnwu/magisk/di/DatabaseModule.kt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.room.Room
|
||||||
|
import com.topjohnwu.magisk.data.database.*
|
||||||
|
import com.topjohnwu.magisk.tasks.RepoUpdater
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
|
||||||
|
val databaseModule = module {
|
||||||
|
single { LogDao() }
|
||||||
|
single { PolicyDao(get()) }
|
||||||
|
single { SettingsDao() }
|
||||||
|
single { StringDao() }
|
||||||
|
single { createRepoDatabase(get()) }
|
||||||
|
single { get<RepoDatabase>().repoDao() }
|
||||||
|
single { RepoUpdater(get(), get()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createRepoDatabase(context: Context) =
|
||||||
|
Room.databaseBuilder(context, RepoDatabase::class.java, "repo.db")
|
||||||
|
.fallbackToDestructiveMigration()
|
||||||
|
.build()
|
9
app/src/main/java/com/topjohnwu/magisk/di/Modules.kt
Normal file
9
app/src/main/java/com/topjohnwu/magisk/di/Modules.kt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
|
val koinModules = listOf(
|
||||||
|
applicationModule,
|
||||||
|
networkingModule,
|
||||||
|
databaseModule,
|
||||||
|
repositoryModule,
|
||||||
|
viewModelModules
|
||||||
|
)
|
@@ -0,0 +1,83 @@
|
|||||||
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.squareup.moshi.JsonAdapter
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.topjohnwu.magisk.BuildConfig
|
||||||
|
import com.topjohnwu.magisk.Const
|
||||||
|
import com.topjohnwu.magisk.data.network.GithubApiServices
|
||||||
|
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||||
|
import com.topjohnwu.magisk.net.Networking
|
||||||
|
import com.topjohnwu.magisk.net.NoSSLv3SocketFactory
|
||||||
|
import io.noties.markwon.Markwon
|
||||||
|
import io.noties.markwon.html.HtmlPlugin
|
||||||
|
import io.noties.markwon.image.ImagesPlugin
|
||||||
|
import io.noties.markwon.image.network.OkHttpNetworkSchemeHandler
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
import org.koin.dsl.module
|
||||||
|
import retrofit2.Retrofit
|
||||||
|
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
|
||||||
|
import retrofit2.converter.moshi.MoshiConverterFactory
|
||||||
|
import retrofit2.converter.scalars.ScalarsConverterFactory
|
||||||
|
import se.ansman.kotshi.KotshiJsonAdapterFactory
|
||||||
|
|
||||||
|
val networkingModule = module {
|
||||||
|
single { createOkHttpClient(get()) }
|
||||||
|
single { createRetrofit(get()) }
|
||||||
|
single { createApiService<GithubRawServices>(get(), Const.Url.GITHUB_RAW_URL) }
|
||||||
|
single { createApiService<GithubApiServices>(get(), Const.Url.GITHUB_API_URL) }
|
||||||
|
single { createMarkwon(get(), get()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
fun createOkHttpClient(context: Context): OkHttpClient {
|
||||||
|
val builder = OkHttpClient.Builder()
|
||||||
|
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
val httpLoggingInterceptor = HttpLoggingInterceptor().apply {
|
||||||
|
level = HttpLoggingInterceptor.Level.HEADERS
|
||||||
|
}
|
||||||
|
builder.addInterceptor(httpLoggingInterceptor)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Networking.init(context)) {
|
||||||
|
builder.sslSocketFactory(NoSSLv3SocketFactory())
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createMoshiConverterFactory(): MoshiConverterFactory {
|
||||||
|
val moshi = Moshi.Builder()
|
||||||
|
.add(KotshiJsonAdapterFactory)
|
||||||
|
.build()
|
||||||
|
return MoshiConverterFactory.create(moshi)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createRetrofit(okHttpClient: OkHttpClient): Retrofit.Builder {
|
||||||
|
return Retrofit.Builder()
|
||||||
|
.addConverterFactory(ScalarsConverterFactory.create())
|
||||||
|
.addConverterFactory(createMoshiConverterFactory())
|
||||||
|
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||||
|
.client(okHttpClient)
|
||||||
|
}
|
||||||
|
|
||||||
|
@KotshiJsonAdapterFactory
|
||||||
|
abstract class JsonAdapterFactory : JsonAdapter.Factory
|
||||||
|
|
||||||
|
inline fun <reified T> createApiService(retrofitBuilder: Retrofit.Builder, baseUrl: String): T {
|
||||||
|
return retrofitBuilder
|
||||||
|
.baseUrl(baseUrl)
|
||||||
|
.build()
|
||||||
|
.create(T::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createMarkwon(context: Context, okHttpClient: OkHttpClient): Markwon {
|
||||||
|
return Markwon.builder(context)
|
||||||
|
.usePlugin(HtmlPlugin.create())
|
||||||
|
.usePlugin(ImagesPlugin.create {
|
||||||
|
it.addSchemeHandler(OkHttpNetworkSchemeHandler.create(okHttpClient))
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
}
|
@@ -0,0 +1,13 @@
|
|||||||
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.data.repository.LogRepository
|
||||||
|
import com.topjohnwu.magisk.data.repository.MagiskRepository
|
||||||
|
import com.topjohnwu.magisk.data.repository.StringRepository
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
|
||||||
|
val repositoryModule = module {
|
||||||
|
single { MagiskRepository(get(), get()) }
|
||||||
|
single { LogRepository(get()) }
|
||||||
|
single { StringRepository(get()) }
|
||||||
|
}
|
@@ -0,0 +1,27 @@
|
|||||||
|
package com.topjohnwu.magisk.di
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import com.topjohnwu.magisk.ui.MainViewModel
|
||||||
|
import com.topjohnwu.magisk.ui.flash.FlashViewModel
|
||||||
|
import com.topjohnwu.magisk.ui.hide.HideViewModel
|
||||||
|
import com.topjohnwu.magisk.ui.home.HomeViewModel
|
||||||
|
import com.topjohnwu.magisk.ui.log.LogViewModel
|
||||||
|
import com.topjohnwu.magisk.ui.module.ModuleViewModel
|
||||||
|
import com.topjohnwu.magisk.ui.superuser.SuperuserViewModel
|
||||||
|
import com.topjohnwu.magisk.ui.surequest.SuRequestViewModel
|
||||||
|
import org.koin.androidx.viewmodel.dsl.viewModel
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
|
||||||
|
val viewModelModules = module {
|
||||||
|
viewModel { MainViewModel() }
|
||||||
|
viewModel { HomeViewModel(get()) }
|
||||||
|
viewModel { SuperuserViewModel(get(), get(), get(), get()) }
|
||||||
|
viewModel { HideViewModel(get(), get()) }
|
||||||
|
viewModel { ModuleViewModel(get(), get(), get()) }
|
||||||
|
viewModel { LogViewModel(get(), get()) }
|
||||||
|
viewModel { (action: String, file: Uri, additional: Uri) ->
|
||||||
|
FlashViewModel(action, file, additional, get())
|
||||||
|
}
|
||||||
|
viewModel { SuRequestViewModel(get(), get(), get(SUTimeout), get()) }
|
||||||
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import androidx.databinding.Observable
|
||||||
|
import androidx.databinding.ObservableBoolean
|
||||||
|
import androidx.databinding.ObservableField
|
||||||
|
import androidx.databinding.ObservableInt
|
||||||
|
|
||||||
|
fun <T> ObservableField<T>.addOnPropertyChangedCallback(
|
||||||
|
removeAfterChanged: Boolean = false,
|
||||||
|
callback: (T?) -> Unit
|
||||||
|
) {
|
||||||
|
addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
|
||||||
|
override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
|
||||||
|
callback(get())
|
||||||
|
if (removeAfterChanged) removeOnPropertyChangedCallback(this)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ObservableInt.addOnPropertyChangedCallback(
|
||||||
|
removeAfterChanged: Boolean = false,
|
||||||
|
callback: (Int) -> Unit
|
||||||
|
) {
|
||||||
|
addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
|
||||||
|
override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
|
||||||
|
callback(get())
|
||||||
|
if (removeAfterChanged) removeOnPropertyChangedCallback(this)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ObservableBoolean.addOnPropertyChangedCallback(
|
||||||
|
removeAfterChanged: Boolean = false,
|
||||||
|
callback: (Boolean) -> Unit
|
||||||
|
) {
|
||||||
|
addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
|
||||||
|
override fun onPropertyChanged(sender: Observable?, propertyId: Int) {
|
||||||
|
callback(get())
|
||||||
|
if (removeAfterChanged) removeOnPropertyChangedCallback(this)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> ObservableField<T>.update(block: (T?) -> Unit) {
|
||||||
|
set(get().apply(block))
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> ObservableField<T>.updateNonNull(block: (T) -> Unit) {
|
||||||
|
update {
|
||||||
|
it ?: return@update
|
||||||
|
block(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun ObservableInt.update(block: (Int) -> Unit) {
|
||||||
|
set(get().apply(block))
|
||||||
|
}
|
@@ -0,0 +1,9 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
fun Int.toDp(): Int = ceil(this / Resources.getSystem().displayMetrics.density).roundToInt()
|
||||||
|
|
||||||
|
fun Int.toPx(): Int = (this * Resources.getSystem().displayMetrics.density).roundToInt()
|
@@ -0,0 +1,6 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
|
||||||
|
fun ui(body: () -> Unit) = Handler(Looper.getMainLooper()).post(body)
|
201
app/src/main/java/com/topjohnwu/magisk/extensions/RxJava.kt
Normal file
201
app/src/main/java/com/topjohnwu/magisk/extensions/RxJava.kt
Normal file
@@ -0,0 +1,201 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import androidx.databinding.ObservableField
|
||||||
|
import com.topjohnwu.magisk.utils.KObservableField
|
||||||
|
import io.reactivex.*
|
||||||
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||||
|
import io.reactivex.disposables.Disposables
|
||||||
|
import io.reactivex.functions.BiFunction
|
||||||
|
import io.reactivex.schedulers.Schedulers
|
||||||
|
import androidx.databinding.Observable as BindingObservable
|
||||||
|
|
||||||
|
fun <T> Observable<T>.applySchedulers(
|
||||||
|
subscribeOn: Scheduler = Schedulers.io(),
|
||||||
|
observeOn: Scheduler = AndroidSchedulers.mainThread()
|
||||||
|
): Observable<T> = this.subscribeOn(subscribeOn).observeOn(observeOn)
|
||||||
|
|
||||||
|
fun <T> Flowable<T>.applySchedulers(
|
||||||
|
subscribeOn: Scheduler = Schedulers.io(),
|
||||||
|
observeOn: Scheduler = AndroidSchedulers.mainThread()
|
||||||
|
): Flowable<T> = this.subscribeOn(subscribeOn).observeOn(observeOn)
|
||||||
|
|
||||||
|
fun <T> Single<T>.applySchedulers(
|
||||||
|
subscribeOn: Scheduler = Schedulers.io(),
|
||||||
|
observeOn: Scheduler = AndroidSchedulers.mainThread()
|
||||||
|
): Single<T> = this.subscribeOn(subscribeOn).observeOn(observeOn)
|
||||||
|
|
||||||
|
fun <T> Maybe<T>.applySchedulers(
|
||||||
|
subscribeOn: Scheduler = Schedulers.io(),
|
||||||
|
observeOn: Scheduler = AndroidSchedulers.mainThread()
|
||||||
|
): Maybe<T> = this.subscribeOn(subscribeOn).observeOn(observeOn)
|
||||||
|
|
||||||
|
fun Completable.applySchedulers(
|
||||||
|
subscribeOn: Scheduler = Schedulers.io(),
|
||||||
|
observeOn: Scheduler = AndroidSchedulers.mainThread()
|
||||||
|
): Completable = this.subscribeOn(subscribeOn).observeOn(observeOn)
|
||||||
|
|
||||||
|
/*=== ALIASES FOR OBSERVABLES ===*/
|
||||||
|
|
||||||
|
typealias OnCompleteListener = () -> Unit
|
||||||
|
typealias OnSuccessListener<T> = (T) -> Unit
|
||||||
|
typealias OnErrorListener = (Throwable) -> Unit
|
||||||
|
|
||||||
|
/*=== ALIASES FOR OBSERVABLES ===*/
|
||||||
|
|
||||||
|
fun <T> Observable<T>.subscribeK(
|
||||||
|
onError: OnErrorListener = { it.printStackTrace() },
|
||||||
|
onComplete: OnCompleteListener = {},
|
||||||
|
onNext: OnSuccessListener<T> = {}
|
||||||
|
) = applySchedulers()
|
||||||
|
.subscribe(onNext, onError, onComplete)
|
||||||
|
|
||||||
|
fun <T> Single<T>.subscribeK(
|
||||||
|
onError: OnErrorListener = { it.printStackTrace() },
|
||||||
|
onNext: OnSuccessListener<T> = {}
|
||||||
|
) = applySchedulers()
|
||||||
|
.subscribe(onNext, onError)
|
||||||
|
|
||||||
|
fun <T> Maybe<T>.subscribeK(
|
||||||
|
onError: OnErrorListener = { it.printStackTrace() },
|
||||||
|
onComplete: OnCompleteListener = {},
|
||||||
|
onNext: OnSuccessListener<T> = {}
|
||||||
|
) = applySchedulers()
|
||||||
|
.subscribe(onNext, onError, onComplete)
|
||||||
|
|
||||||
|
fun <T> Flowable<T>.subscribeK(
|
||||||
|
onError: OnErrorListener = { it.printStackTrace() },
|
||||||
|
onComplete: OnCompleteListener = {},
|
||||||
|
onNext: OnSuccessListener<T> = {}
|
||||||
|
) = applySchedulers()
|
||||||
|
.subscribe(onNext, onError, onComplete)
|
||||||
|
|
||||||
|
fun Completable.subscribeK(
|
||||||
|
onError: OnErrorListener = { it.printStackTrace() },
|
||||||
|
onComplete: OnCompleteListener = {}
|
||||||
|
) = applySchedulers()
|
||||||
|
.subscribe(onComplete, onError)
|
||||||
|
|
||||||
|
|
||||||
|
fun <T> Observable<out T>.updateBy(
|
||||||
|
field: KObservableField<T?>
|
||||||
|
) = doOnNextUi { field.value = it }
|
||||||
|
.doOnErrorUi { field.value = null }
|
||||||
|
|
||||||
|
fun <T> Single<out T>.updateBy(
|
||||||
|
field: KObservableField<T?>
|
||||||
|
) = doOnSuccessUi { field.value = it }
|
||||||
|
.doOnErrorUi { field.value = null }
|
||||||
|
|
||||||
|
fun <T> Maybe<out T>.updateBy(
|
||||||
|
field: KObservableField<T?>
|
||||||
|
) = doOnSuccessUi { field.value = it }
|
||||||
|
.doOnErrorUi { field.value = null }
|
||||||
|
.doOnComplete { field.value = field.value }
|
||||||
|
|
||||||
|
fun <T> Flowable<out T>.updateBy(
|
||||||
|
field: KObservableField<T?>
|
||||||
|
) = doOnNextUi { field.value = it }
|
||||||
|
.doOnErrorUi { field.value = null }
|
||||||
|
|
||||||
|
fun Completable.updateBy(
|
||||||
|
field: KObservableField<Boolean>
|
||||||
|
) = doOnCompleteUi { field.value = true }
|
||||||
|
.doOnErrorUi { field.value = false }
|
||||||
|
|
||||||
|
|
||||||
|
fun <T> Observable<T>.doOnSubscribeUi(body: () -> Unit) =
|
||||||
|
doOnSubscribe { ui { body() } }
|
||||||
|
|
||||||
|
fun <T> Single<T>.doOnSubscribeUi(body: () -> Unit) =
|
||||||
|
doOnSubscribe { ui { body() } }
|
||||||
|
|
||||||
|
fun <T> Maybe<T>.doOnSubscribeUi(body: () -> Unit) =
|
||||||
|
doOnSubscribe { ui { body() } }
|
||||||
|
|
||||||
|
fun <T> Flowable<T>.doOnSubscribeUi(body: () -> Unit) =
|
||||||
|
doOnSubscribe { ui { body() } }
|
||||||
|
|
||||||
|
fun Completable.doOnSubscribeUi(body: () -> Unit) =
|
||||||
|
doOnSubscribe { ui { body() } }
|
||||||
|
|
||||||
|
|
||||||
|
fun <T> Observable<T>.doOnErrorUi(body: (Throwable) -> Unit) =
|
||||||
|
doOnError { ui { body(it) } }
|
||||||
|
|
||||||
|
fun <T> Single<T>.doOnErrorUi(body: (Throwable) -> Unit) =
|
||||||
|
doOnError { ui { body(it) } }
|
||||||
|
|
||||||
|
fun <T> Maybe<T>.doOnErrorUi(body: (Throwable) -> Unit) =
|
||||||
|
doOnError { ui { body(it) } }
|
||||||
|
|
||||||
|
fun <T> Flowable<T>.doOnErrorUi(body: (Throwable) -> Unit) =
|
||||||
|
doOnError { ui { body(it) } }
|
||||||
|
|
||||||
|
fun Completable.doOnErrorUi(body: (Throwable) -> Unit) =
|
||||||
|
doOnError { ui { body(it) } }
|
||||||
|
|
||||||
|
|
||||||
|
fun <T> Observable<T>.doOnNextUi(body: (T) -> Unit) =
|
||||||
|
doOnNext { ui { body(it) } }
|
||||||
|
|
||||||
|
fun <T> Flowable<T>.doOnNextUi(body: (T) -> Unit) =
|
||||||
|
doOnNext { ui { body(it) } }
|
||||||
|
|
||||||
|
fun <T> Single<T>.doOnSuccessUi(body: (T) -> Unit) =
|
||||||
|
doOnSuccess { ui { body(it) } }
|
||||||
|
|
||||||
|
fun <T> Maybe<T>.doOnSuccessUi(body: (T) -> Unit) =
|
||||||
|
doOnSuccess { ui { body(it) } }
|
||||||
|
|
||||||
|
fun <T> Maybe<T>.doOnCompleteUi(body: () -> Unit) =
|
||||||
|
doOnComplete { ui { body() } }
|
||||||
|
|
||||||
|
fun Completable.doOnCompleteUi(body: () -> Unit) =
|
||||||
|
doOnComplete { ui { body() } }
|
||||||
|
|
||||||
|
|
||||||
|
fun <T, R> Observable<List<T>>.mapList(
|
||||||
|
transformer: (T) -> R
|
||||||
|
) = flatMapIterable { it }
|
||||||
|
.map(transformer)
|
||||||
|
.toList()
|
||||||
|
|
||||||
|
fun <T, R> Single<List<T>>.mapList(
|
||||||
|
transformer: (T) -> R
|
||||||
|
) = flattenAsFlowable { it }
|
||||||
|
.map(transformer)
|
||||||
|
.toList()
|
||||||
|
|
||||||
|
fun <T, R> Maybe<List<T>>.mapList(
|
||||||
|
transformer: (T) -> R
|
||||||
|
) = flattenAsFlowable { it }
|
||||||
|
.map(transformer)
|
||||||
|
.toList()
|
||||||
|
|
||||||
|
fun <T, R> Flowable<List<T>>.mapList(
|
||||||
|
transformer: (T) -> R
|
||||||
|
) = flatMapIterable { it }
|
||||||
|
.map(transformer)
|
||||||
|
.toList()
|
||||||
|
|
||||||
|
fun <T> ObservableField<T>.toObservable(): Observable<T> {
|
||||||
|
val observableField = this
|
||||||
|
return Observable.create { emitter ->
|
||||||
|
observableField.get()?.let { emitter.onNext(it) }
|
||||||
|
|
||||||
|
val callback = object : BindingObservable.OnPropertyChangedCallback() {
|
||||||
|
override fun onPropertyChanged(sender: BindingObservable?, propertyId: Int) {
|
||||||
|
observableField.get()?.let { emitter.onNext(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
observableField.addOnPropertyChangedCallback(callback)
|
||||||
|
emitter.setDisposable(Disposables.fromAction {
|
||||||
|
observableField.removeOnPropertyChangedCallback(callback)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T : Any> T.toSingle() = Single.just(this)
|
||||||
|
|
||||||
|
fun <T1, T2, R> zip(t1: Single<T1>, t2: Single<T2>, zipper: (T1, T2) -> R) =
|
||||||
|
Single.zip(t1, t2, BiFunction<T1, T2, R> { rt1, rt2 -> zipper(rt1, rt2) })
|
126
app/src/main/java/com/topjohnwu/magisk/extensions/Snackbar.kt
Normal file
126
app/src/main/java/com/topjohnwu/magisk/extensions/Snackbar.kt
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.res.ColorStateList
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.annotation.ColorRes
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
|
||||||
|
fun AppCompatActivity.snackbar(
|
||||||
|
view: View,
|
||||||
|
@StringRes messageRes: Int,
|
||||||
|
length: Int = Snackbar.LENGTH_SHORT,
|
||||||
|
f: Snackbar.() -> Unit = {}
|
||||||
|
) {
|
||||||
|
snackbar(view, getString(messageRes), length, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun AppCompatActivity.snackbar(
|
||||||
|
view: View,
|
||||||
|
message: String,
|
||||||
|
length: Int = Snackbar.LENGTH_SHORT,
|
||||||
|
f: Snackbar.() -> Unit = {}
|
||||||
|
) = Snackbar.make(view, message, length)
|
||||||
|
.apply(f)
|
||||||
|
.show()
|
||||||
|
|
||||||
|
fun Fragment.snackbar(
|
||||||
|
view: View,
|
||||||
|
@StringRes messageRes: Int,
|
||||||
|
length: Int = Snackbar.LENGTH_SHORT,
|
||||||
|
f: Snackbar.() -> Unit = {}
|
||||||
|
) {
|
||||||
|
snackbar(view, getString(messageRes), length, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Fragment.snackbar(
|
||||||
|
view: View,
|
||||||
|
message: String,
|
||||||
|
length: Int = Snackbar.LENGTH_SHORT,
|
||||||
|
f: Snackbar.() -> Unit = {}
|
||||||
|
) = Snackbar.make(view, message, length)
|
||||||
|
.apply(f)
|
||||||
|
.show()
|
||||||
|
|
||||||
|
fun Snackbar.action(init: KSnackbar.() -> Unit) = apply {
|
||||||
|
val config = KSnackbar().apply(init)
|
||||||
|
|
||||||
|
setAction(config.title(context), config.onClickListener)
|
||||||
|
|
||||||
|
when {
|
||||||
|
config.hasValidColor -> setActionTextColor(config.color(context) ?: return@apply)
|
||||||
|
config.hasValidColorStateList -> setActionTextColor(config.colorStateList(context) ?: return@apply)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class KSnackbar {
|
||||||
|
var colorRes: Int = -1
|
||||||
|
var colorStateListRes: Int = -1
|
||||||
|
|
||||||
|
var title: CharSequence = ""
|
||||||
|
var titleRes: Int = -1
|
||||||
|
|
||||||
|
internal var onClickListener: (View) -> Unit = {}
|
||||||
|
internal val hasValidColor get() = colorRes != -1
|
||||||
|
internal val hasValidColorStateList get() = colorStateListRes != -1
|
||||||
|
|
||||||
|
fun onClicked(listener: (View) -> Unit) {
|
||||||
|
onClickListener = listener
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun title(context: Context) = if (title.isBlank()) context.getString(titleRes) else title
|
||||||
|
internal fun colorStateList(context: Context) = context.colorStateListCompat(colorStateListRes)
|
||||||
|
internal fun color(context: Context) = context.colorCompat(colorRes)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Kotlin DSL version is preferred", ReplaceWith("action {}"))
|
||||||
|
fun Snackbar.action(
|
||||||
|
@StringRes actionRes: Int,
|
||||||
|
@ColorRes colorRes: Int? = null,
|
||||||
|
listener: (View) -> Unit
|
||||||
|
) {
|
||||||
|
view.resources.getString(actionRes)
|
||||||
|
colorRes?.let { ContextCompat.getColor(view.context, colorRes) }
|
||||||
|
action {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated("Kotlin DSL version is preferred", ReplaceWith("action {}"))
|
||||||
|
fun Snackbar.action(action: String, @ColorInt color: Int? = null, listener: (View) -> Unit) {
|
||||||
|
setAction(action, listener)
|
||||||
|
color?.let { setActionTextColor(color) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Snackbar.textColorRes(@ColorRes colorRes: Int) {
|
||||||
|
textColor(context.colorCompat(colorRes) ?: return)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Snackbar.textColor(@ColorInt color: Int) {
|
||||||
|
val tv = view.findViewById<TextView>(com.google.android.material.R.id.snackbar_text)
|
||||||
|
tv.setTextColor(color)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Snackbar.backgroundColorRes(@ColorRes colorRes: Int) {
|
||||||
|
backgroundColor(context.colorCompat(colorRes) ?: return)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Snackbar.backgroundColor(@ColorInt color: Int) {
|
||||||
|
ViewCompat.setBackgroundTintList(
|
||||||
|
view,
|
||||||
|
ColorStateList.valueOf(color)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Snackbar.alert() {
|
||||||
|
textColor(0xF44336)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Snackbar.success() {
|
||||||
|
textColor(0x4CAF50)
|
||||||
|
}
|
308
app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt
Normal file
308
app/src/main/java/com/topjohnwu/magisk/extensions/XAndroid.kt
Normal file
@@ -0,0 +1,308 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import android.content.ComponentName
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
|
import android.content.Intent
|
||||||
|
import android.content.pm.ApplicationInfo
|
||||||
|
import android.content.pm.ComponentInfo
|
||||||
|
import android.content.pm.PackageInfo
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import android.content.pm.PackageManager.*
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.content.res.Resources
|
||||||
|
import android.database.Cursor
|
||||||
|
import android.graphics.Bitmap
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.drawable.AdaptiveIconDrawable
|
||||||
|
import android.graphics.drawable.BitmapDrawable
|
||||||
|
import android.graphics.drawable.LayerDrawable
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import android.os.Build.VERSION.SDK_INT
|
||||||
|
import android.provider.OpenableColumns
|
||||||
|
import android.view.View
|
||||||
|
import androidx.annotation.ColorRes
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.net.toUri
|
||||||
|
import com.topjohnwu.magisk.Const
|
||||||
|
import com.topjohnwu.magisk.FileProvider
|
||||||
|
import com.topjohnwu.magisk.utils.DynamicClassLoader
|
||||||
|
import com.topjohnwu.magisk.utils.Utils
|
||||||
|
import com.topjohnwu.magisk.utils.currentLocale
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileNotFoundException
|
||||||
|
import java.lang.reflect.Array as JArray
|
||||||
|
|
||||||
|
val packageName: String get() = get<Context>().packageName
|
||||||
|
|
||||||
|
val PackageInfo.processes
|
||||||
|
get() = activities?.processNames.orEmpty() +
|
||||||
|
services?.processNames.orEmpty() +
|
||||||
|
receivers?.processNames.orEmpty() +
|
||||||
|
providers?.processNames.orEmpty()
|
||||||
|
|
||||||
|
val Array<out ComponentInfo>.processNames get() = mapNotNull { it.processName }
|
||||||
|
|
||||||
|
val ApplicationInfo.packageInfo: PackageInfo?
|
||||||
|
get() {
|
||||||
|
val pm: PackageManager by inject()
|
||||||
|
|
||||||
|
return try {
|
||||||
|
val request = GET_ACTIVITIES or
|
||||||
|
GET_SERVICES or
|
||||||
|
GET_RECEIVERS or
|
||||||
|
GET_PROVIDERS
|
||||||
|
pm.getPackageInfo(packageName, request)
|
||||||
|
} catch (e1: Exception) {
|
||||||
|
try {
|
||||||
|
pm.activities(packageName).apply {
|
||||||
|
services = pm.services(packageName)
|
||||||
|
receivers = pm.receivers(packageName)
|
||||||
|
providers = pm.providers(packageName)
|
||||||
|
}
|
||||||
|
} catch (e2: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val Uri.fileName: String
|
||||||
|
get() {
|
||||||
|
var name: String? = null
|
||||||
|
get<Context>().contentResolver.query(this, null, null, null, null)?.use { c ->
|
||||||
|
val nameIndex = c.getColumnIndex(OpenableColumns.DISPLAY_NAME)
|
||||||
|
if (nameIndex != -1) {
|
||||||
|
c.moveToFirst()
|
||||||
|
name = c.getString(nameIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (name == null && path != null) {
|
||||||
|
val idx = path!!.lastIndexOf('/')
|
||||||
|
name = path!!.substring(idx + 1)
|
||||||
|
}
|
||||||
|
return name.orEmpty()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PackageManager.activities(packageName: String) =
|
||||||
|
getPackageInfo(packageName, GET_ACTIVITIES)
|
||||||
|
|
||||||
|
fun PackageManager.services(packageName: String) =
|
||||||
|
getPackageInfo(packageName, GET_SERVICES).services
|
||||||
|
|
||||||
|
fun PackageManager.receivers(packageName: String) =
|
||||||
|
getPackageInfo(packageName, GET_RECEIVERS).receivers
|
||||||
|
|
||||||
|
fun PackageManager.providers(packageName: String) =
|
||||||
|
getPackageInfo(packageName, GET_PROVIDERS).providers
|
||||||
|
|
||||||
|
fun Context.rawResource(id: Int) = resources.openRawResource(id)
|
||||||
|
|
||||||
|
fun Context.readUri(uri: Uri) =
|
||||||
|
contentResolver.openInputStream(uri) ?: throw FileNotFoundException()
|
||||||
|
|
||||||
|
fun Context.getBitmap(id: Int): Bitmap {
|
||||||
|
var drawable = AppCompatResources.getDrawable(this, id)!!
|
||||||
|
if (drawable is BitmapDrawable)
|
||||||
|
return drawable.bitmap
|
||||||
|
if (SDK_INT >= 26 && drawable is AdaptiveIconDrawable) {
|
||||||
|
drawable = LayerDrawable(arrayOf(drawable.background, drawable.foreground))
|
||||||
|
}
|
||||||
|
val bitmap = Bitmap.createBitmap(
|
||||||
|
drawable.intrinsicWidth, drawable.intrinsicHeight,
|
||||||
|
Bitmap.Config.ARGB_8888
|
||||||
|
)
|
||||||
|
val canvas = Canvas(bitmap)
|
||||||
|
drawable.setBounds(0, 0, canvas.width, canvas.height)
|
||||||
|
drawable.draw(canvas)
|
||||||
|
return bitmap
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Intent.startActivity(context: Context) = context.startActivity(this)
|
||||||
|
|
||||||
|
fun Intent.startActivityWithRoot() {
|
||||||
|
val args = mutableListOf("am", "start", "--user", Const.USER_ID.toString())
|
||||||
|
val cmd = toCommand(args).joinToString(" ")
|
||||||
|
Shell.su(cmd).submit()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Intent.toCommand(args: MutableList<String> = mutableListOf()): MutableList<String> {
|
||||||
|
action?.also {
|
||||||
|
args.add("-a")
|
||||||
|
args.add(it)
|
||||||
|
}
|
||||||
|
component?.also {
|
||||||
|
args.add("-n")
|
||||||
|
args.add(it.flattenToString())
|
||||||
|
}
|
||||||
|
data?.also {
|
||||||
|
args.add("-d")
|
||||||
|
args.add(it.toString())
|
||||||
|
}
|
||||||
|
categories?.also {
|
||||||
|
for (cat in it) {
|
||||||
|
args.add("-c")
|
||||||
|
args.add(cat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
type?.also {
|
||||||
|
args.add("-t")
|
||||||
|
args.add(it)
|
||||||
|
}
|
||||||
|
extras?.also {
|
||||||
|
loop@ for (key in it.keySet()) {
|
||||||
|
val v = it[key] ?: continue
|
||||||
|
var value: Any = v
|
||||||
|
val arg: String
|
||||||
|
when {
|
||||||
|
v is String -> arg = "--es"
|
||||||
|
v is Boolean -> arg = "--ez"
|
||||||
|
v is Int -> arg = "--ei"
|
||||||
|
v is Long -> arg = "--el"
|
||||||
|
v is Float -> arg = "--ef"
|
||||||
|
v is Uri -> arg = "--eu"
|
||||||
|
v is ComponentName -> {
|
||||||
|
arg = "--ecn"
|
||||||
|
value = v.flattenToString()
|
||||||
|
}
|
||||||
|
v is List<*> -> {
|
||||||
|
if (v.isEmpty())
|
||||||
|
continue@loop
|
||||||
|
|
||||||
|
arg = if (v[0] is Int)
|
||||||
|
"--eial"
|
||||||
|
else if (v[0] is Long)
|
||||||
|
"--elal"
|
||||||
|
else if (v[0] is Float)
|
||||||
|
"--efal"
|
||||||
|
else if (v[0] is String)
|
||||||
|
"--esal"
|
||||||
|
else
|
||||||
|
continue@loop /* Unsupported */
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
for (o in v) {
|
||||||
|
sb.append(o.toString().replace(",", "\\,"))
|
||||||
|
sb.append(',')
|
||||||
|
}
|
||||||
|
// Remove trailing comma
|
||||||
|
sb.deleteCharAt(sb.length - 1)
|
||||||
|
value = sb
|
||||||
|
}
|
||||||
|
v.javaClass.isArray -> {
|
||||||
|
arg = if (v is IntArray)
|
||||||
|
"--eia"
|
||||||
|
else if (v is LongArray)
|
||||||
|
"--ela"
|
||||||
|
else if (v is FloatArray)
|
||||||
|
"--efa"
|
||||||
|
else if (v is Array<*> && v.isArrayOf<String>())
|
||||||
|
"--esa"
|
||||||
|
else
|
||||||
|
continue@loop /* Unsupported */
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
val len = JArray.getLength(v)
|
||||||
|
for (i in 0 until len) {
|
||||||
|
sb.append(JArray.get(v, i)!!.toString().replace(",", "\\,"))
|
||||||
|
sb.append(',')
|
||||||
|
}
|
||||||
|
// Remove trailing comma
|
||||||
|
sb.deleteCharAt(sb.length - 1)
|
||||||
|
value = sb
|
||||||
|
}
|
||||||
|
else -> continue@loop
|
||||||
|
} /* Unsupported */
|
||||||
|
|
||||||
|
args.add(arg)
|
||||||
|
args.add(key)
|
||||||
|
args.add(value.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
args.add("-f")
|
||||||
|
args.add(flags.toString())
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
|
fun File.provide(context: Context = get()): Uri {
|
||||||
|
return FileProvider.getUriForFile(context, context.packageName + ".provider", this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun File.mv(destination: File) {
|
||||||
|
inputStream().writeTo(destination)
|
||||||
|
deleteRecursively()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.toFile() = File(this)
|
||||||
|
|
||||||
|
fun Intent.chooser(title: String = "Pick an app") = Intent.createChooser(this, title)
|
||||||
|
|
||||||
|
fun Context.cachedFile(name: String) = File(cacheDir, name)
|
||||||
|
|
||||||
|
fun <Result> Cursor.toList(transformer: (Cursor) -> Result): List<Result> {
|
||||||
|
val out = mutableListOf<Result>()
|
||||||
|
while (moveToNext()) out.add(transformer(this))
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ApplicationInfo.getLabel(pm: PackageManager): String {
|
||||||
|
runCatching {
|
||||||
|
if (labelRes > 0) {
|
||||||
|
val res = pm.getResourcesForApplication(this)
|
||||||
|
val config = Configuration()
|
||||||
|
config.setLocale(currentLocale)
|
||||||
|
res.updateConfiguration(config, res.displayMetrics)
|
||||||
|
return res.getString(labelRes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return loadLabel(pm).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Intent.exists(packageManager: PackageManager) = resolveActivity(packageManager) != null
|
||||||
|
|
||||||
|
fun Context.colorCompat(@ColorRes id: Int) = try {
|
||||||
|
ContextCompat.getColor(this, id)
|
||||||
|
} catch (e: Resources.NotFoundException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.colorStateListCompat(@ColorRes id: Int) = try {
|
||||||
|
ContextCompat.getColorStateList(this, id)
|
||||||
|
} catch (e: Resources.NotFoundException) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.drawableCompat(@DrawableRes id: Int) = ContextCompat.getDrawable(this, id)
|
||||||
|
/**
|
||||||
|
* Pass [start] and [end] dimensions, function will return left and right
|
||||||
|
* with respect to RTL layout direction
|
||||||
|
*/
|
||||||
|
fun Context.startEndToLeftRight(start: Int, end: Int): Pair<Int, Int> {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 &&
|
||||||
|
resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL
|
||||||
|
) {
|
||||||
|
return end to start
|
||||||
|
}
|
||||||
|
return start to end
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.openUrl(url: String) = Utils.openLink(this, url.toUri())
|
||||||
|
|
||||||
|
@Suppress("FunctionName")
|
||||||
|
inline fun <reified T> T.DynamicClassLoader(apk: File)
|
||||||
|
= DynamicClassLoader(apk, T::class.java.classLoader)
|
||||||
|
|
||||||
|
fun Context.unwrap() : Context {
|
||||||
|
var context = this
|
||||||
|
while (true) {
|
||||||
|
if (context is ContextWrapper)
|
||||||
|
context = context.baseContext
|
||||||
|
else
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return context
|
||||||
|
}
|
@@ -0,0 +1,8 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.utils.KObservableField
|
||||||
|
|
||||||
|
|
||||||
|
fun KObservableField<Boolean>.toggle() {
|
||||||
|
value = !value
|
||||||
|
}
|
103
app/src/main/java/com/topjohnwu/magisk/extensions/XJava.kt
Normal file
103
app/src/main/java/com/topjohnwu/magisk/extensions/XJava.kt
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.core.net.toFile
|
||||||
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
|
import java.util.*
|
||||||
|
import java.util.zip.ZipEntry
|
||||||
|
import java.util.zip.ZipInputStream
|
||||||
|
import kotlin.NoSuchElementException
|
||||||
|
|
||||||
|
fun ZipInputStream.forEach(callback: (ZipEntry) -> Unit) {
|
||||||
|
var entry: ZipEntry? = nextEntry
|
||||||
|
while (entry != null) {
|
||||||
|
callback(entry)
|
||||||
|
entry = nextEntry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Uri.writeTo(file: File) = toFile().copyTo(file)
|
||||||
|
|
||||||
|
fun InputStream.writeTo(file: File) =
|
||||||
|
withStreams(this, file.outputStream()) { reader, writer -> reader.copyTo(writer) }
|
||||||
|
|
||||||
|
inline fun <In : InputStream, Out : OutputStream> withStreams(
|
||||||
|
inStream: In,
|
||||||
|
outStream: Out,
|
||||||
|
withBoth: (In, Out) -> Unit
|
||||||
|
) {
|
||||||
|
inStream.use { reader ->
|
||||||
|
outStream.use { writer ->
|
||||||
|
withBoth(reader, writer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T, R> List<T>.firstMap(mapper: (T) -> R?): R {
|
||||||
|
for (item: T in this) {
|
||||||
|
return mapper(item) ?: continue
|
||||||
|
}
|
||||||
|
throw NoSuchElementException("Collection contains no element matching the predicate.")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.langTagToLocale(): Locale {
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
return Locale.forLanguageTag(this)
|
||||||
|
} else {
|
||||||
|
val tok = split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||||
|
if (tok.isEmpty()) {
|
||||||
|
return Locale("")
|
||||||
|
}
|
||||||
|
val language = when (tok[0]) {
|
||||||
|
"und" -> "" // Undefined
|
||||||
|
"fil" -> "tl" // Filipino
|
||||||
|
else -> tok[0]
|
||||||
|
}
|
||||||
|
if (language.length != 2 && language.length != 3)
|
||||||
|
return Locale("")
|
||||||
|
if (tok.size == 1)
|
||||||
|
return Locale(language)
|
||||||
|
val country = tok[1]
|
||||||
|
|
||||||
|
return if (country.length != 2 && country.length != 3) Locale(language)
|
||||||
|
else Locale(language, country)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Locale.toLangTag(): String {
|
||||||
|
if (Build.VERSION.SDK_INT >= 21) {
|
||||||
|
return toLanguageTag()
|
||||||
|
} else {
|
||||||
|
var language = language
|
||||||
|
var country = country
|
||||||
|
var variant = variant
|
||||||
|
when {
|
||||||
|
language.isEmpty() || !language.matches("\\p{Alpha}{2,8}".toRegex()) ->
|
||||||
|
language = "und" // Follow the Locale#toLanguageTag() implementation
|
||||||
|
language == "iw" -> language = "he" // correct deprecated "Hebrew"
|
||||||
|
language == "in" -> language = "id" // correct deprecated "Indonesian"
|
||||||
|
language == "ji" -> language = "yi" // correct deprecated "Yiddish"
|
||||||
|
}
|
||||||
|
// ensure valid country code, if not well formed, it's omitted
|
||||||
|
|
||||||
|
// variant subtags that begin with a letter must be at least 5 characters long
|
||||||
|
// ensure valid country code, if not well formed, it's omitted
|
||||||
|
if (!country.matches("\\p{Alpha}{2}|\\p{Digit}{3}".toRegex())) {
|
||||||
|
country = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// variant subtags that begin with a letter must be at least 5 characters long
|
||||||
|
if (!variant.matches("\\p{Alnum}{5,8}|\\p{Digit}\\p{Alnum}{3}".toRegex())) {
|
||||||
|
variant = ""
|
||||||
|
}
|
||||||
|
val tag = StringBuilder(language)
|
||||||
|
if (country.isNotEmpty())
|
||||||
|
tag.append('-').append(country)
|
||||||
|
if (variant.isNotEmpty())
|
||||||
|
tag.append('-').append(variant)
|
||||||
|
return tag.toString()
|
||||||
|
}
|
||||||
|
}
|
17
app/src/main/java/com/topjohnwu/magisk/extensions/XKoin.kt
Normal file
17
app/src/main/java/com/topjohnwu/magisk/extensions/XKoin.kt
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import org.koin.core.context.GlobalContext
|
||||||
|
import org.koin.core.parameter.ParametersDefinition
|
||||||
|
import org.koin.core.qualifier.Qualifier
|
||||||
|
|
||||||
|
fun getKoin() = GlobalContext.get().koin
|
||||||
|
|
||||||
|
inline fun <reified T> inject(
|
||||||
|
qualifier: Qualifier? = null,
|
||||||
|
noinline parameters: ParametersDefinition? = null
|
||||||
|
) = lazy { get<T>(qualifier, parameters) }
|
||||||
|
|
||||||
|
inline fun <reified T> get(
|
||||||
|
qualifier: Qualifier? = null,
|
||||||
|
noinline parameters: ParametersDefinition? = null
|
||||||
|
): T = getKoin().get(qualifier, parameters)
|
83
app/src/main/java/com/topjohnwu/magisk/extensions/XList.kt
Normal file
83
app/src/main/java/com/topjohnwu/magisk/extensions/XList.kt
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import androidx.collection.SparseArrayCompat
|
||||||
|
import androidx.databinding.ObservableList
|
||||||
|
import com.topjohnwu.magisk.utils.DiffObservableList
|
||||||
|
import io.reactivex.disposables.Disposable
|
||||||
|
|
||||||
|
fun <T> MutableList<T>.update(newList: List<T>) {
|
||||||
|
clear()
|
||||||
|
addAll(newList)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun List<String>.toShellCmd(): String {
|
||||||
|
val sb = StringBuilder()
|
||||||
|
for (s in this) {
|
||||||
|
if (s.contains(" ")) {
|
||||||
|
sb.append('"').append(s).append('"')
|
||||||
|
} else {
|
||||||
|
sb.append(s)
|
||||||
|
}
|
||||||
|
sb.append(' ')
|
||||||
|
}
|
||||||
|
sb.deleteCharAt(sb.length - 1)
|
||||||
|
return sb.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T1, T2> ObservableList<T1>.sendUpdatesTo(
|
||||||
|
target: DiffObservableList<T2>,
|
||||||
|
mapper: (List<T1>) -> List<T2>
|
||||||
|
) = addOnListChangedCallback(object :
|
||||||
|
ObservableList.OnListChangedCallback<ObservableList<T1>>() {
|
||||||
|
override fun onChanged(sender: ObservableList<T1>?) {
|
||||||
|
updateAsync(sender ?: return)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeRemoved(sender: ObservableList<T1>?, p0: Int, p1: Int) {
|
||||||
|
updateAsync(sender ?: return)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeMoved(sender: ObservableList<T1>?, p0: Int, p1: Int, p2: Int) {
|
||||||
|
updateAsync(sender ?: return)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeInserted(sender: ObservableList<T1>?, p0: Int, p1: Int) {
|
||||||
|
updateAsync(sender ?: return)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemRangeChanged(sender: ObservableList<T1>?, p0: Int, p1: Int) {
|
||||||
|
updateAsync(sender ?: return)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var updater: Disposable? = null
|
||||||
|
|
||||||
|
private fun updateAsync(sender: List<T1>) {
|
||||||
|
updater?.dispose()
|
||||||
|
updater = sender.toSingle()
|
||||||
|
.map { mapper(it) }
|
||||||
|
.map { it to target.calculateDiff(it) }
|
||||||
|
.subscribeK { target.update(it.first, it.second) }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
fun <T1> ObservableList<T1>.copyNewInputInto(
|
||||||
|
target: MutableList<T1>
|
||||||
|
) = addOnListChangedCallback(object : ObservableList.OnListChangedCallback<ObservableList<T1>>() {
|
||||||
|
override fun onChanged(p0: ObservableList<T1>?) = Unit
|
||||||
|
override fun onItemRangeRemoved(p0: ObservableList<T1>?, p1: Int, p2: Int) = Unit
|
||||||
|
override fun onItemRangeMoved(p0: ObservableList<T1>?, p1: Int, p2: Int, p3: Int) = Unit
|
||||||
|
override fun onItemRangeChanged(p0: ObservableList<T1>?, p1: Int, p2: Int) = Unit
|
||||||
|
override fun onItemRangeInserted(
|
||||||
|
sender: ObservableList<T1>?,
|
||||||
|
positionStart: Int,
|
||||||
|
itemCount: Int
|
||||||
|
) {
|
||||||
|
val positionEnd = positionStart + itemCount
|
||||||
|
val addedValues = sender?.slice(positionStart until positionEnd).orEmpty()
|
||||||
|
target.addAll(addedValues)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
operator fun <E> SparseArrayCompat<E>.set(key: Int, value: E) {
|
||||||
|
put(key, value)
|
||||||
|
}
|
14
app/src/main/java/com/topjohnwu/magisk/extensions/XSU.kt
Normal file
14
app/src/main/java/com/topjohnwu/magisk/extensions/XSU.kt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.Info
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import com.topjohnwu.superuser.io.SuFileInputStream
|
||||||
|
import com.topjohnwu.superuser.io.SuFileOutputStream
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
fun reboot(reason: String = if (Info.recovery) "recovery" else "") {
|
||||||
|
Shell.su("/system/bin/svc power reboot $reason || /system/bin/reboot $reason").submit()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun File.suOutputStream() = SuFileOutputStream(this)
|
||||||
|
fun File.suInputStream() = SuFileInputStream(this)
|
29
app/src/main/java/com/topjohnwu/magisk/extensions/XString.kt
Normal file
29
app/src/main/java/com/topjohnwu/magisk/extensions/XString.kt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import android.content.res.Resources
|
||||||
|
|
||||||
|
val specialChars = arrayOf('!', '@', '#', '$', '%', '&', '?')
|
||||||
|
|
||||||
|
fun String.replaceRandomWithSpecial(): String {
|
||||||
|
var random: Char
|
||||||
|
do {
|
||||||
|
random = random()
|
||||||
|
} while (random == '.')
|
||||||
|
return replace(random, specialChars.random())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun StringBuilder.appendIf(condition: Boolean, builder: StringBuilder.() -> Unit) =
|
||||||
|
if (condition) apply(builder) else this
|
||||||
|
|
||||||
|
fun Int.res(vararg args: Any): String {
|
||||||
|
val resources: Resources by inject()
|
||||||
|
return resources.getString(this, *args)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun String.trimEmptyToNull(): String? = if (isBlank()) null else this
|
||||||
|
|
||||||
|
fun String.legalFilename() = replace(" ", "_").replace("'", "").replace("\"", "")
|
||||||
|
.replace("$", "").replace("`", "").replace("*", "").replace("/", "_")
|
||||||
|
.replace("#", "").replace("@", "").replace("\\", "_")
|
||||||
|
|
||||||
|
fun String.isEmptyInternal() = isNullOrBlank()
|
20
app/src/main/java/com/topjohnwu/magisk/extensions/XTime.kt
Normal file
20
app/src/main/java/com/topjohnwu/magisk/extensions/XTime.kt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.utils.currentLocale
|
||||||
|
import java.text.DateFormat
|
||||||
|
import java.text.ParseException
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
|
||||||
|
val now get() = System.currentTimeMillis()
|
||||||
|
|
||||||
|
fun Long.toTime(format: DateFormat) = format.format(this).orEmpty()
|
||||||
|
fun String.toTime(format: DateFormat) = try {
|
||||||
|
format.parse(this)?.time ?: -1
|
||||||
|
} catch (e: ParseException) {
|
||||||
|
-1L
|
||||||
|
}
|
||||||
|
|
||||||
|
val timeFormatFull by lazy { SimpleDateFormat("yyyy/MM/dd_HH:mm:ss", currentLocale) }
|
||||||
|
val timeFormatStandard by lazy { SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", currentLocale) }
|
||||||
|
val timeFormatMedium by lazy { DateFormat.getDateInstance(DateFormat.MEDIUM, currentLocale) }
|
||||||
|
val timeFormatTime by lazy { SimpleDateFormat("h:mm a", currentLocale) }
|
14
app/src/main/java/com/topjohnwu/magisk/extensions/XView.kt
Normal file
14
app/src/main/java/com/topjohnwu/magisk/extensions/XView.kt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.topjohnwu.magisk.extensions
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewTreeObserver
|
||||||
|
|
||||||
|
fun View.setOnViewReadyListener(callback: () -> Unit) = addOnGlobalLayoutListener(true, callback)
|
||||||
|
|
||||||
|
fun View.addOnGlobalLayoutListener(oneShot: Boolean = false, callback: () -> Unit) =
|
||||||
|
viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
|
override fun onGlobalLayout() {
|
||||||
|
if (oneShot) viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
})
|
@@ -1,427 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.adapters;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.ComponentInfo;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.annotation.WorkerThread;
|
|
||||||
import androidx.collection.ArraySet;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.buildware.widget.indeterm.IndeterminateCheckBox;
|
|
||||||
import com.topjohnwu.magisk.App;
|
|
||||||
import com.topjohnwu.magisk.Config;
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.utils.Event;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
import com.topjohnwu.magisk.view.ArrowExpandable;
|
|
||||||
import com.topjohnwu.magisk.view.Expandable;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
|
||||||
import com.topjohnwu.superuser.internal.UiThreadHandler;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import java9.util.Comparators;
|
|
||||||
import java9.util.Lists;
|
|
||||||
import java9.util.Objects;
|
|
||||||
import java9.util.Sets;
|
|
||||||
import java9.util.stream.Collectors;
|
|
||||||
import java9.util.stream.Stream;
|
|
||||||
import java9.util.stream.StreamSupport;
|
|
||||||
|
|
||||||
public class ApplicationAdapter extends SectionedAdapter
|
|
||||||
<ApplicationAdapter.AppViewHolder, ApplicationAdapter.ProcessViewHolder> {
|
|
||||||
|
|
||||||
private static final String SAFETYNET_PROCESS = "com.google.android.gms.unstable";
|
|
||||||
private static final String GMS_PACKAGE = "com.google.android.gms";
|
|
||||||
private static boolean old_hide = false;
|
|
||||||
|
|
||||||
/* A list of apps that should not be shown as hide-able */
|
|
||||||
private static final List<String> HIDE_BLACKLIST = Lists.of(
|
|
||||||
App.self.getPackageName(),
|
|
||||||
"android",
|
|
||||||
"com.android.chrome",
|
|
||||||
"com.chrome.beta",
|
|
||||||
"com.chrome.dev",
|
|
||||||
"com.chrome.canary",
|
|
||||||
"com.android.webview",
|
|
||||||
"com.google.android.webview"
|
|
||||||
);
|
|
||||||
private static final List<String> DEFAULT_HIDELIST = Lists.of(
|
|
||||||
SAFETYNET_PROCESS
|
|
||||||
);
|
|
||||||
|
|
||||||
private static int BOTTOM_MARGIN = -1;
|
|
||||||
|
|
||||||
private List<HideAppInfo> fullList, showList;
|
|
||||||
private List<HideTarget> hideList;
|
|
||||||
private PackageManager pm;
|
|
||||||
private boolean showSystem;
|
|
||||||
|
|
||||||
public ApplicationAdapter(Context context) {
|
|
||||||
fullList = showList = Collections.emptyList();
|
|
||||||
hideList = Collections.emptyList();
|
|
||||||
pm = context.getPackageManager();
|
|
||||||
showSystem = Config.get(Config.Key.SHOW_SYSTEM_APP);
|
|
||||||
AsyncTask.SERIAL_EXECUTOR.execute(this::loadApps);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ViewGroup.MarginLayoutParams getMargins(RecyclerView.ViewHolder vh) {
|
|
||||||
return (ViewGroup.MarginLayoutParams) vh.itemView.getLayoutParams();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSectionCount() {
|
|
||||||
return showList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount(int section) {
|
|
||||||
HideAppInfo app = showList.get(section);
|
|
||||||
return app.expanded ? app.processList.size() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AppViewHolder onCreateSectionViewHolder(ViewGroup parent) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_hide_app, parent, false);
|
|
||||||
AppViewHolder vh = new AppViewHolder(v);
|
|
||||||
if (BOTTOM_MARGIN < 0)
|
|
||||||
BOTTOM_MARGIN = getMargins(vh).bottomMargin;
|
|
||||||
return vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ProcessViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_hide_process, parent, false);
|
|
||||||
return new ProcessViewHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindSectionViewHolder(AppViewHolder holder, int section) {
|
|
||||||
HideAppInfo app = showList.get(section);
|
|
||||||
holder.app_name.setText(app.name);
|
|
||||||
holder.app_icon.setImageDrawable(app.info.loadIcon(pm));
|
|
||||||
holder.package_name.setText(app.info.packageName);
|
|
||||||
holder.checkBox.setOnStateChangedListener(null);
|
|
||||||
holder.checkBox.setState(app.getState());
|
|
||||||
holder.ex.setExpanded(app.expanded);
|
|
||||||
|
|
||||||
int index = getItemPosition(section, 0);
|
|
||||||
holder.checkBox.setOnStateChangedListener((IndeterminateCheckBox box, @Nullable Boolean status) -> {
|
|
||||||
if (status != null) {
|
|
||||||
setHide(status, app);
|
|
||||||
if (app.expanded)
|
|
||||||
notifyItemRangeChanged(index, app.processList.size());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (app.processList.size() > 1) {
|
|
||||||
holder.arrow.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
holder.trigger.setOnClickListener((v) -> {
|
|
||||||
if (app.expanded) {
|
|
||||||
app.expanded = false;
|
|
||||||
notifyItemRangeRemoved(index, app.processList.size());
|
|
||||||
holder.ex.collapse();
|
|
||||||
} else {
|
|
||||||
app.expanded = true;
|
|
||||||
notifyItemRangeInserted(index, app.processList.size());
|
|
||||||
holder.ex.expand();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
holder.arrow.setVisibility(View.GONE);
|
|
||||||
holder.trigger.setOnClickListener(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindItemViewHolder(ProcessViewHolder holder, int section, int position) {
|
|
||||||
HideAppInfo app = showList.get(section);
|
|
||||||
HideProcessInfo target = app.processList.get(position);
|
|
||||||
holder.process.setText(target.name);
|
|
||||||
holder.checkbox.setOnCheckedChangeListener(null);
|
|
||||||
holder.checkbox.setChecked(target.hidden);
|
|
||||||
holder.checkbox.setOnCheckedChangeListener((v, checked) -> {
|
|
||||||
setHide(checked, app, target);
|
|
||||||
notifyItemChanged(getSectionPosition(section));
|
|
||||||
});
|
|
||||||
getMargins(holder).bottomMargin =
|
|
||||||
position == app.processList.size() - 1 ? BOTTOM_MARGIN : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void filter(String constraint) {
|
|
||||||
AsyncTask.SERIAL_EXECUTOR.execute(() -> {
|
|
||||||
Stream<HideAppInfo> s = StreamSupport.stream(fullList)
|
|
||||||
.filter(this::systemFilter)
|
|
||||||
.filter(t -> nameFilter(t, constraint));
|
|
||||||
UiThreadHandler.run(() -> {
|
|
||||||
showList = s.collect(Collectors.toList());
|
|
||||||
notifyDataSetChanged();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setShowSystem(boolean b) {
|
|
||||||
showSystem = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refresh() {
|
|
||||||
AsyncTask.SERIAL_EXECUTOR.execute(this::loadApps);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setHide(boolean add, HideAppInfo app) {
|
|
||||||
if (add) {
|
|
||||||
StreamSupport.stream(app.processList).forEach(p -> setHide(true, app, p));
|
|
||||||
} else {
|
|
||||||
if (StreamSupport.stream(app.processList)
|
|
||||||
.anyMatch(p -> p.name.equals(SAFETYNET_PROCESS))) {
|
|
||||||
StreamSupport.stream(app.processList).forEach(p -> setHide(false, app, p));
|
|
||||||
} else {
|
|
||||||
// Quick removal
|
|
||||||
Shell.su("magiskhide --rm " + app.info.packageName).submit();
|
|
||||||
StreamSupport.stream(app.processList).forEach(p -> p.hidden = false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setHide(boolean add, HideAppInfo app, HideProcessInfo process) {
|
|
||||||
// Don't remove SafetyNet
|
|
||||||
if (!add && DEFAULT_HIDELIST.contains(process.name))
|
|
||||||
return;
|
|
||||||
Shell.su(Utils.fmt("magiskhide --%s %s %s", add ? "add" : "rm",
|
|
||||||
app.info.packageName, process.name)).submit();
|
|
||||||
process.hidden = add;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addProcesses(Set<String> set, ComponentInfo[] infos) {
|
|
||||||
if (infos != null)
|
|
||||||
for (ComponentInfo info : infos)
|
|
||||||
set.add(info.processName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private PackageInfo getPackageInfo(String pkg) {
|
|
||||||
// Try super hard to get as much info as possible
|
|
||||||
try {
|
|
||||||
return pm.getPackageInfo(pkg,
|
|
||||||
PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES |
|
|
||||||
PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS);
|
|
||||||
} catch (Exception e1) {
|
|
||||||
try {
|
|
||||||
PackageInfo info = pm.getPackageInfo(pkg, PackageManager.GET_ACTIVITIES);
|
|
||||||
info.services = pm.getPackageInfo(pkg, PackageManager.GET_SERVICES).services;
|
|
||||||
info.receivers = pm.getPackageInfo(pkg, PackageManager.GET_RECEIVERS).receivers;
|
|
||||||
info.providers = pm.getPackageInfo(pkg, PackageManager.GET_PROVIDERS).providers;
|
|
||||||
return info;
|
|
||||||
} catch (Exception e2) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@WorkerThread
|
|
||||||
private void loadApps() {
|
|
||||||
hideList = StreamSupport.stream(Shell.su("magiskhide --ls").exec().getOut())
|
|
||||||
.map(HideTarget::new)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
fullList = StreamSupport.stream(pm.getInstalledApplications(0))
|
|
||||||
.filter(info -> !HIDE_BLACKLIST.contains(info.packageName) && info.enabled)
|
|
||||||
.map(info -> {
|
|
||||||
if (old_hide) {
|
|
||||||
return new HideAppInfo(info, Sets.of(info.packageName));
|
|
||||||
} else {
|
|
||||||
Set<String> set = new ArraySet<>();
|
|
||||||
PackageInfo pkg = getPackageInfo(info.packageName);
|
|
||||||
if (pkg != null) {
|
|
||||||
addProcesses(set, pkg.activities);
|
|
||||||
addProcesses(set, pkg.services);
|
|
||||||
addProcesses(set, pkg.receivers);
|
|
||||||
addProcesses(set, pkg.providers);
|
|
||||||
}
|
|
||||||
if (set.isEmpty())
|
|
||||||
return null;
|
|
||||||
return new HideAppInfo(info, set);
|
|
||||||
}
|
|
||||||
}).filter(Objects::nonNull).sorted()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
Event.trigger(false, Event.MAGISK_HIDE_DONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// True if not system app or user already hidden it
|
|
||||||
private boolean systemFilter(HideAppInfo target) {
|
|
||||||
return showSystem || target.haveHidden() ||
|
|
||||||
(target.info.flags & ApplicationInfo.FLAG_SYSTEM) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean contains(String s, String filter) {
|
|
||||||
return s.toLowerCase().contains(filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean nameFilter(HideAppInfo target, String filter) {
|
|
||||||
if (filter == null || filter.isEmpty())
|
|
||||||
return true;
|
|
||||||
filter = filter.toLowerCase();
|
|
||||||
if (contains(target.name, filter))
|
|
||||||
return true;
|
|
||||||
for (HideProcessInfo p : target.processList) {
|
|
||||||
if (contains(p.name, filter))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return contains(target.info.packageName, filter);
|
|
||||||
}
|
|
||||||
|
|
||||||
class HideAppInfo implements Comparable<HideAppInfo> {
|
|
||||||
String name;
|
|
||||||
ApplicationInfo info;
|
|
||||||
List<HideProcessInfo> processList;
|
|
||||||
boolean expanded;
|
|
||||||
IndeterminateCheckBox.OnStateChangedListener listener;
|
|
||||||
|
|
||||||
HideAppInfo(ApplicationInfo appInfo, Set<String> set) {
|
|
||||||
info = appInfo;
|
|
||||||
name = Utils.getAppLabel(info, pm);
|
|
||||||
expanded = false;
|
|
||||||
processList = StreamSupport.stream(set)
|
|
||||||
.map(process -> new HideProcessInfo(info.packageName, process))
|
|
||||||
.sorted().collect(Collectors.toList());
|
|
||||||
listener = (IndeterminateCheckBox box, @Nullable Boolean status) -> {
|
|
||||||
if (status != null) {
|
|
||||||
for (HideProcessInfo p : processList) {
|
|
||||||
String cmd = Utils.fmt("magiskhide --%s %s %s",
|
|
||||||
status ? "add" : "rm", info.packageName, p.name);
|
|
||||||
Shell.su(cmd).submit();
|
|
||||||
p.hidden = status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(HideAppInfo o) {
|
|
||||||
Comparator<HideAppInfo> c;
|
|
||||||
c = Comparators.comparing(HideAppInfo::haveHidden);
|
|
||||||
c = Comparators.reversed(c);
|
|
||||||
c = Comparators.thenComparing(c, t -> t.name, String::compareToIgnoreCase);
|
|
||||||
c = Comparators.thenComparing(c, t -> t.info.packageName);
|
|
||||||
return c.compare(this, o);
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean getState() {
|
|
||||||
boolean all = true;
|
|
||||||
boolean hidden = false;
|
|
||||||
for (HideProcessInfo p : processList) {
|
|
||||||
if (!p.hidden)
|
|
||||||
all = false;
|
|
||||||
else
|
|
||||||
hidden = true;
|
|
||||||
}
|
|
||||||
if (all)
|
|
||||||
return true;
|
|
||||||
return hidden ? null : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean haveHidden() {
|
|
||||||
Boolean c = getState();
|
|
||||||
return c == null ? true : c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HideProcessInfo implements Comparable<HideProcessInfo> {
|
|
||||||
String name;
|
|
||||||
boolean hidden;
|
|
||||||
|
|
||||||
HideProcessInfo(String pkg, String process) {
|
|
||||||
this.name = process;
|
|
||||||
for (HideTarget t : hideList) {
|
|
||||||
if (t.pkg.equals(pkg) && t.process.equals(process)) {
|
|
||||||
hidden = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(HideProcessInfo o) {
|
|
||||||
Comparator<HideProcessInfo> c;
|
|
||||||
c = Comparators.comparing((HideProcessInfo t) -> t.hidden);
|
|
||||||
c = Comparators.reversed(c);
|
|
||||||
c = Comparators.thenComparing(c, t -> t.name);
|
|
||||||
return c.compare(this, o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class HideTarget {
|
|
||||||
String pkg;
|
|
||||||
String process;
|
|
||||||
|
|
||||||
HideTarget(String line) {
|
|
||||||
String[] split = line.split("\\|", 2);
|
|
||||||
pkg = split[0];
|
|
||||||
if (split.length == 2) {
|
|
||||||
process = split[1];
|
|
||||||
} else {
|
|
||||||
// Backwards compatibility
|
|
||||||
old_hide = true;
|
|
||||||
process = pkg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class AppViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.app_icon) ImageView app_icon;
|
|
||||||
@BindView(R.id.app_name) TextView app_name;
|
|
||||||
@BindView(R.id.package_name) TextView package_name;
|
|
||||||
@BindView(R.id.checkbox) IndeterminateCheckBox checkBox;
|
|
||||||
@BindView(R.id.trigger) View trigger;
|
|
||||||
@BindView(R.id.arrow) ImageView arrow;
|
|
||||||
|
|
||||||
Expandable ex;
|
|
||||||
|
|
||||||
AppViewHolder(@NonNull View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
new ApplicationAdapter$AppViewHolder_ViewBinding(this, itemView);
|
|
||||||
ex = new ArrowExpandable(new Expandable() {
|
|
||||||
@Override
|
|
||||||
protected void onExpand() {
|
|
||||||
getMargins(AppViewHolder.this).bottomMargin = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCollapse() {
|
|
||||||
getMargins(AppViewHolder.this).bottomMargin = BOTTOM_MARGIN;
|
|
||||||
}
|
|
||||||
}, arrow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ProcessViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.process) TextView process;
|
|
||||||
@BindView(R.id.checkbox) CheckBox checkbox;
|
|
||||||
|
|
||||||
ProcessViewHolder(@NonNull View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
new ApplicationAdapter$ProcessViewHolder_ViewBinding(this, itemView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,127 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.adapters;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.model.entity.Module;
|
|
||||||
import com.topjohnwu.magisk.view.SnackbarMaker;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
|
|
||||||
public class ModulesAdapter extends RecyclerView.Adapter<ModulesAdapter.ViewHolder> {
|
|
||||||
|
|
||||||
private final List<Module> mList;
|
|
||||||
|
|
||||||
public ModulesAdapter(List<Module> list) {
|
|
||||||
mList = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
||||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_module, parent, false);
|
|
||||||
return new ViewHolder(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
|
||||||
Context context = holder.itemView.getContext();
|
|
||||||
final Module module = mList.get(position);
|
|
||||||
|
|
||||||
String version = module.getVersion();
|
|
||||||
String author = module.getAuthor();
|
|
||||||
String description = module.getDescription();
|
|
||||||
String noInfo = context.getString(R.string.no_info_provided);
|
|
||||||
|
|
||||||
holder.title.setText(module.getName());
|
|
||||||
holder.versionName.setText(TextUtils.isEmpty(version) ? noInfo : version);
|
|
||||||
holder.author.setText(TextUtils.isEmpty(author) ? noInfo : context.getString(R.string.author, author));
|
|
||||||
holder.description.setText(TextUtils.isEmpty(description) ? noInfo : description);
|
|
||||||
|
|
||||||
holder.checkBox.setOnCheckedChangeListener(null);
|
|
||||||
holder.checkBox.setChecked(module.isEnabled());
|
|
||||||
holder.checkBox.setOnCheckedChangeListener((v, isChecked) -> {
|
|
||||||
int snack;
|
|
||||||
if (isChecked) {
|
|
||||||
module.removeDisableFile();
|
|
||||||
snack = R.string.disable_file_removed;
|
|
||||||
} else {
|
|
||||||
module.createDisableFile();
|
|
||||||
snack = R.string.disable_file_created;
|
|
||||||
}
|
|
||||||
SnackbarMaker.make(holder.itemView, snack, Snackbar.LENGTH_SHORT).show();
|
|
||||||
});
|
|
||||||
|
|
||||||
holder.delete.setOnClickListener(v -> {
|
|
||||||
boolean removed = module.willBeRemoved();
|
|
||||||
int snack;
|
|
||||||
if (removed) {
|
|
||||||
module.deleteRemoveFile();
|
|
||||||
snack = R.string.remove_file_deleted;
|
|
||||||
} else {
|
|
||||||
module.createRemoveFile();
|
|
||||||
snack = R.string.remove_file_created;
|
|
||||||
}
|
|
||||||
SnackbarMaker.make(holder.itemView, snack, Snackbar.LENGTH_SHORT).show();
|
|
||||||
updateDeleteButton(holder, module);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (module.isUpdated()) {
|
|
||||||
holder.notice.setVisibility(View.VISIBLE);
|
|
||||||
holder.notice.setText(R.string.update_file_created);
|
|
||||||
holder.delete.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
updateDeleteButton(holder, module);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateDeleteButton(ViewHolder holder, Module module) {
|
|
||||||
holder.notice.setVisibility(module.willBeRemoved() ? View.VISIBLE : View.GONE);
|
|
||||||
|
|
||||||
if (module.willBeRemoved()) {
|
|
||||||
holder.delete.setImageResource(R.drawable.ic_undelete);
|
|
||||||
} else {
|
|
||||||
holder.delete.setImageResource(R.drawable.ic_delete);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return mList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.title) TextView title;
|
|
||||||
@BindView(R.id.version_name) TextView versionName;
|
|
||||||
@BindView(R.id.description) TextView description;
|
|
||||||
@BindView(R.id.notice) TextView notice;
|
|
||||||
@BindView(R.id.checkbox) CheckBox checkBox;
|
|
||||||
@BindView(R.id.author) TextView author;
|
|
||||||
@BindView(R.id.delete) ImageView delete;
|
|
||||||
|
|
||||||
ViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
new ModulesAdapter$ViewHolder_ViewBinding(this, itemView);
|
|
||||||
|
|
||||||
if (!Shell.rootAccess()) {
|
|
||||||
checkBox.setEnabled(false);
|
|
||||||
delete.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,172 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.adapters;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.widget.SwitchCompat;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.data.database.MagiskDB;
|
|
||||||
import com.topjohnwu.magisk.model.entity.Policy;
|
|
||||||
import com.topjohnwu.magisk.utils.FingerprintHelper;
|
|
||||||
import com.topjohnwu.magisk.view.ArrowExpandable;
|
|
||||||
import com.topjohnwu.magisk.view.Expandable;
|
|
||||||
import com.topjohnwu.magisk.view.ExpandableViewHolder;
|
|
||||||
import com.topjohnwu.magisk.view.SnackbarMaker;
|
|
||||||
import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog;
|
|
||||||
import com.topjohnwu.magisk.view.dialogs.FingerprintAuthDialog;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
|
|
||||||
public class PolicyAdapter extends RecyclerView.Adapter<PolicyAdapter.ViewHolder> {
|
|
||||||
|
|
||||||
private List<Policy> policyList;
|
|
||||||
private MagiskDB dbHelper;
|
|
||||||
private PackageManager pm;
|
|
||||||
private boolean[] expandList;
|
|
||||||
|
|
||||||
public PolicyAdapter(List<Policy> list, MagiskDB db, PackageManager pm) {
|
|
||||||
policyList = list;
|
|
||||||
expandList = new boolean[policyList.size()];
|
|
||||||
dbHelper = db;
|
|
||||||
this.pm = pm;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_policy, parent, false);
|
|
||||||
return new ViewHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
|
||||||
Policy policy = policyList.get(position);
|
|
||||||
|
|
||||||
holder.settings.setExpanded(expandList[position]);
|
|
||||||
holder.trigger.setOnClickListener(view -> {
|
|
||||||
if (holder.settings.isExpanded()) {
|
|
||||||
holder.settings.collapse();
|
|
||||||
expandList[position] = false;
|
|
||||||
} else {
|
|
||||||
holder.settings.expand();
|
|
||||||
expandList[position] = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
holder.appName.setText(policy.appName);
|
|
||||||
holder.packageName.setText(policy.packageName);
|
|
||||||
holder.appIcon.setImageDrawable(policy.info.loadIcon(pm));
|
|
||||||
|
|
||||||
holder.notificationSwitch.setOnCheckedChangeListener(null);
|
|
||||||
holder.loggingSwitch.setOnCheckedChangeListener(null);
|
|
||||||
|
|
||||||
holder.masterSwitch.setChecked(policy.policy == Policy.ALLOW);
|
|
||||||
holder.notificationSwitch.setChecked(policy.notification);
|
|
||||||
holder.loggingSwitch.setChecked(policy.logging);
|
|
||||||
|
|
||||||
holder.masterSwitch.setOnClickListener(v -> {
|
|
||||||
boolean isChecked = holder.masterSwitch.isChecked();
|
|
||||||
Runnable r = () -> {
|
|
||||||
if ((isChecked && policy.policy == Policy.DENY) ||
|
|
||||||
(!isChecked && policy.policy == Policy.ALLOW)) {
|
|
||||||
policy.policy = isChecked ? Policy.ALLOW : Policy.DENY;
|
|
||||||
String message = v.getContext().getString(
|
|
||||||
isChecked ? R.string.su_snack_grant : R.string.su_snack_deny, policy.appName);
|
|
||||||
SnackbarMaker.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show();
|
|
||||||
dbHelper.updatePolicy(policy);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (FingerprintHelper.useFingerprint()) {
|
|
||||||
holder.masterSwitch.setChecked(!isChecked);
|
|
||||||
new FingerprintAuthDialog((Activity) v.getContext(), () -> {
|
|
||||||
holder.masterSwitch.setChecked(isChecked);
|
|
||||||
r.run();
|
|
||||||
}).show();
|
|
||||||
} else {
|
|
||||||
r.run();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
holder.notificationSwitch.setOnCheckedChangeListener((v, isChecked) -> {
|
|
||||||
if ((isChecked && !policy.notification) ||
|
|
||||||
(!isChecked && policy.notification)) {
|
|
||||||
policy.notification = isChecked;
|
|
||||||
String message = v.getContext().getString(
|
|
||||||
isChecked ? R.string.su_snack_notif_on : R.string.su_snack_notif_off, policy.appName);
|
|
||||||
SnackbarMaker.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show();
|
|
||||||
dbHelper.updatePolicy(policy);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
holder.loggingSwitch.setOnCheckedChangeListener((v, isChecked) -> {
|
|
||||||
if ((isChecked && !policy.logging) ||
|
|
||||||
(!isChecked && policy.logging)) {
|
|
||||||
policy.logging = isChecked;
|
|
||||||
String message = v.getContext().getString(
|
|
||||||
isChecked ? R.string.su_snack_log_on : R.string.su_snack_log_off, policy.appName);
|
|
||||||
SnackbarMaker.make(holder.itemView, message, Snackbar.LENGTH_SHORT).show();
|
|
||||||
dbHelper.updatePolicy(policy);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
holder.delete.setOnClickListener(v -> {
|
|
||||||
DialogInterface.OnClickListener l = (dialog, which) -> {
|
|
||||||
policyList.remove(position);
|
|
||||||
notifyItemRemoved(position);
|
|
||||||
notifyItemRangeChanged(position, policyList.size());
|
|
||||||
SnackbarMaker.make(holder.itemView, v.getContext().getString(R.string.su_snack_revoke, policy.appName),
|
|
||||||
Snackbar.LENGTH_SHORT).show();
|
|
||||||
dbHelper.deletePolicy(policy);
|
|
||||||
};
|
|
||||||
if (FingerprintHelper.useFingerprint()) {
|
|
||||||
new FingerprintAuthDialog((Activity) v.getContext(),
|
|
||||||
() -> l.onClick(null, 0)).show();
|
|
||||||
} else {
|
|
||||||
new CustomAlertDialog((Activity) v.getContext())
|
|
||||||
.setTitle(R.string.su_revoke_title)
|
|
||||||
.setMessage(v.getContext().getString(R.string.su_revoke_msg, policy.appName))
|
|
||||||
.setPositiveButton(R.string.yes, l)
|
|
||||||
.setNegativeButton(R.string.no_thanks, null)
|
|
||||||
.setCancelable(true)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
return policyList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.app_name) TextView appName;
|
|
||||||
@BindView(R.id.package_name) TextView packageName;
|
|
||||||
@BindView(R.id.app_icon) ImageView appIcon;
|
|
||||||
@BindView(R.id.master_switch) SwitchCompat masterSwitch;
|
|
||||||
@BindView(R.id.notification_switch) SwitchCompat notificationSwitch;
|
|
||||||
@BindView(R.id.logging_switch) SwitchCompat loggingSwitch;
|
|
||||||
@BindView(R.id.expand_layout) ViewGroup expandLayout;
|
|
||||||
@BindView(R.id.arrow) ImageView arrow;
|
|
||||||
@BindView(R.id.trigger) View trigger;
|
|
||||||
@BindView(R.id.delete) ImageView delete;
|
|
||||||
@BindView(R.id.more_info) ImageView moreInfo;
|
|
||||||
|
|
||||||
Expandable settings;
|
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
new PolicyAdapter$ViewHolder_ViewBinding(this, itemView);
|
|
||||||
settings = new ArrowExpandable(new ExpandableViewHolder(expandLayout), arrow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,246 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.adapters;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Pair;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.SearchView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.App;
|
|
||||||
import com.topjohnwu.magisk.ClassMap;
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.data.database.RepoDatabaseHelper;
|
|
||||||
import com.topjohnwu.magisk.model.download.DownloadModuleService;
|
|
||||||
import com.topjohnwu.magisk.model.entity.Module;
|
|
||||||
import com.topjohnwu.magisk.model.entity.Repo;
|
|
||||||
import com.topjohnwu.magisk.ui.base.BaseActivity;
|
|
||||||
import com.topjohnwu.magisk.utils.Event;
|
|
||||||
import com.topjohnwu.magisk.view.MarkDownWindow;
|
|
||||||
import com.topjohnwu.magisk.view.dialogs.CustomAlertDialog;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
import java9.util.stream.StreamSupport;
|
|
||||||
|
|
||||||
public class ReposAdapter
|
|
||||||
extends SectionedAdapter<ReposAdapter.SectionHolder, ReposAdapter.RepoHolder>
|
|
||||||
implements Event.AutoListener, SearchView.OnQueryTextListener {
|
|
||||||
|
|
||||||
private static final int UPDATES = 0;
|
|
||||||
private static final int INSTALLED = 1;
|
|
||||||
private static final int OTHERS = 2;
|
|
||||||
|
|
||||||
private Map<String, Module> moduleMap;
|
|
||||||
private RepoDatabaseHelper repoDB;
|
|
||||||
private List<Pair<Integer, List<Repo>>> repoPairs;
|
|
||||||
private List<Repo> fullList;
|
|
||||||
private SearchView mSearch;
|
|
||||||
|
|
||||||
public ReposAdapter() {
|
|
||||||
repoDB = App.self.repoDB;
|
|
||||||
moduleMap = Collections.emptyMap();
|
|
||||||
fullList = Collections.emptyList();
|
|
||||||
repoPairs = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSectionCount() {
|
|
||||||
return repoPairs.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount(int section) {
|
|
||||||
return repoPairs.get(section).second.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SectionHolder onCreateSectionViewHolder(ViewGroup parent) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.section, parent, false);
|
|
||||||
return new SectionHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RepoHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_repo, parent, false);
|
|
||||||
return new RepoHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindSectionViewHolder(SectionHolder holder, int section) {
|
|
||||||
switch (repoPairs.get(section).first) {
|
|
||||||
case UPDATES:
|
|
||||||
holder.sectionText.setText(R.string.update_available);
|
|
||||||
break;
|
|
||||||
case INSTALLED:
|
|
||||||
holder.sectionText.setText(R.string.installed);
|
|
||||||
break;
|
|
||||||
case OTHERS:
|
|
||||||
holder.sectionText.setText(R.string.not_installed);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindItemViewHolder(RepoHolder holder, int section, int position) {
|
|
||||||
Repo repo = repoPairs.get(section).second.get(position);
|
|
||||||
Context context = holder.itemView.getContext();
|
|
||||||
|
|
||||||
String name = repo.getName();
|
|
||||||
String version = repo.getVersion();
|
|
||||||
String author = repo.getAuthor();
|
|
||||||
String description = repo.getDescription();
|
|
||||||
String noInfo = context.getString(R.string.no_info_provided);
|
|
||||||
|
|
||||||
holder.title.setText(TextUtils.isEmpty(name) ? noInfo : name);
|
|
||||||
holder.versionName.setText(TextUtils.isEmpty(version) ? noInfo : version);
|
|
||||||
holder.author.setText(TextUtils.isEmpty(author) ? noInfo : context.getString(R.string.author, author));
|
|
||||||
holder.description.setText(TextUtils.isEmpty(description) ? noInfo : description);
|
|
||||||
holder.updateTime.setText(context.getString(R.string.updated_on, repo.getLastUpdateString()));
|
|
||||||
|
|
||||||
holder.infoLayout.setOnClickListener(v ->
|
|
||||||
MarkDownWindow.show((BaseActivity) context, null, repo.getDetailUrl()));
|
|
||||||
|
|
||||||
holder.downloadImage.setOnClickListener(v -> {
|
|
||||||
new CustomAlertDialog((BaseActivity) context)
|
|
||||||
.setTitle(context.getString(R.string.repo_install_title, repo.getName()))
|
|
||||||
.setMessage(context.getString(R.string.repo_install_msg, repo.getDownloadFilename()))
|
|
||||||
.setCancelable(true)
|
|
||||||
.setPositiveButton(R.string.install, (d, i) ->
|
|
||||||
startDownload((BaseActivity) context, repo, true))
|
|
||||||
.setNeutralButton(R.string.download, (d, i) ->
|
|
||||||
startDownload((BaseActivity) context, repo, false))
|
|
||||||
.setNegativeButton(R.string.no_thanks, null)
|
|
||||||
.show();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startDownload(BaseActivity activity, Repo repo, Boolean install) {
|
|
||||||
activity.runWithExternalRW(() -> {
|
|
||||||
Intent intent = new Intent(activity, ClassMap.get(DownloadModuleService.class))
|
|
||||||
.putExtra("repo", repo).putExtra("install", install);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
activity.startForegroundService(intent);
|
|
||||||
} else {
|
|
||||||
activity.startService(intent);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateLists() {
|
|
||||||
if (mSearch != null)
|
|
||||||
onQueryTextChange(mSearch.getQuery().toString());
|
|
||||||
else
|
|
||||||
onQueryTextChange("");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean noCaseContain(String a, String b) {
|
|
||||||
return a.toLowerCase().contains(b.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSearchView(SearchView view) {
|
|
||||||
mSearch = view;
|
|
||||||
mSearch.setOnQueryTextListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notifyDBChanged(boolean refresh) {
|
|
||||||
try (Cursor c = repoDB.getRepoCursor()) {
|
|
||||||
fullList = new ArrayList<>(c.getCount());
|
|
||||||
while (c.moveToNext())
|
|
||||||
fullList.add(new Repo(c));
|
|
||||||
}
|
|
||||||
if (refresh)
|
|
||||||
updateLists();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEvent(int event) {
|
|
||||||
moduleMap = Event.getResult(event);
|
|
||||||
updateLists();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int[] getListeningEvents() {
|
|
||||||
return new int[] {Event.MODULE_LOAD_DONE};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextChange(String s) {
|
|
||||||
List<Repo> updates = new ArrayList<>();
|
|
||||||
List<Repo> installed = new ArrayList<>();
|
|
||||||
List<Repo> others = new ArrayList<>();
|
|
||||||
|
|
||||||
StreamSupport.stream(fullList)
|
|
||||||
.filter(repo -> noCaseContain(repo.getName(), s)
|
|
||||||
|| noCaseContain(repo.getAuthor(), s)
|
|
||||||
|| noCaseContain(repo.getDescription(), s))
|
|
||||||
.forEach(repo -> {
|
|
||||||
Module module = moduleMap.get(repo.getId());
|
|
||||||
if (module != null) {
|
|
||||||
if (repo.getVersionCode() > module.getVersionCode()) {
|
|
||||||
// Updates
|
|
||||||
updates.add(repo);
|
|
||||||
} else {
|
|
||||||
installed.add(repo);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
others.add(repo);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
repoPairs.clear();
|
|
||||||
if (!updates.isEmpty())
|
|
||||||
repoPairs.add(new Pair<>(UPDATES, updates));
|
|
||||||
if (!installed.isEmpty())
|
|
||||||
repoPairs.add(new Pair<>(INSTALLED, installed));
|
|
||||||
if (!others.isEmpty())
|
|
||||||
repoPairs.add(new Pair<>(OTHERS, others));
|
|
||||||
|
|
||||||
notifyDataSetChanged();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static class SectionHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.section_text) TextView sectionText;
|
|
||||||
|
|
||||||
SectionHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
new ReposAdapter$SectionHolder_ViewBinding(this, itemView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class RepoHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.title) TextView title;
|
|
||||||
@BindView(R.id.version_name) TextView versionName;
|
|
||||||
@BindView(R.id.description) TextView description;
|
|
||||||
@BindView(R.id.author) TextView author;
|
|
||||||
@BindView(R.id.info_layout) View infoLayout;
|
|
||||||
@BindView(R.id.download) ImageView downloadImage;
|
|
||||||
@BindView(R.id.update_time) TextView updateTime;
|
|
||||||
|
|
||||||
RepoHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
new ReposAdapter$RepoHolder_ViewBinding(this, itemView);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,96 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.adapters;
|
|
||||||
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
public abstract class SectionedAdapter<S extends RecyclerView.ViewHolder, C extends RecyclerView.ViewHolder>
|
|
||||||
extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|
||||||
|
|
||||||
private static final int SECTION_TYPE = Integer.MIN_VALUE;
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
final public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
if (viewType == SECTION_TYPE)
|
|
||||||
return onCreateSectionViewHolder(parent);
|
|
||||||
return onCreateItemViewHolder(parent, viewType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
|
||||||
PositionInfo info = getPositionInfo(position);
|
|
||||||
if (info.position == -1)
|
|
||||||
onBindSectionViewHolder((S) holder, info.section);
|
|
||||||
else
|
|
||||||
onBindItemViewHolder((C) holder, info.section, info.position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
final public int getItemCount() {
|
|
||||||
int size, sec;
|
|
||||||
size = sec = getSectionCount();
|
|
||||||
for (int i = 0; i < sec; ++i){
|
|
||||||
size += getItemCount(i);
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
final public int getItemViewType(int position) {
|
|
||||||
PositionInfo info = getPositionInfo(position);
|
|
||||||
if (info.position == -1)
|
|
||||||
return SECTION_TYPE;
|
|
||||||
else
|
|
||||||
return getItemViewType(info.section, info.position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getItemViewType(int section, int position) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getSectionPosition(int section) {
|
|
||||||
return getItemPosition(section, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getItemPosition(int section, int position) {
|
|
||||||
int realPosition = 0;
|
|
||||||
// Previous sections
|
|
||||||
for (int i = 0; i < section; ++i) {
|
|
||||||
realPosition += getItemCount(i) + 1;
|
|
||||||
}
|
|
||||||
// Current section
|
|
||||||
realPosition += position + 1;
|
|
||||||
return realPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
private PositionInfo getPositionInfo(int position) {
|
|
||||||
int section = 0;
|
|
||||||
while (true) {
|
|
||||||
if (position == 0)
|
|
||||||
return new PositionInfo(section, -1);
|
|
||||||
position -= 1;
|
|
||||||
if (position < getItemCount(section))
|
|
||||||
return new PositionInfo(section, position);
|
|
||||||
position -= getItemCount(section++);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class PositionInfo {
|
|
||||||
int section;
|
|
||||||
int position;
|
|
||||||
PositionInfo(int section, int position) {
|
|
||||||
this.section = section;
|
|
||||||
this.position = position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract int getSectionCount();
|
|
||||||
public abstract int getItemCount(int section);
|
|
||||||
public abstract S onCreateSectionViewHolder(ViewGroup parent);
|
|
||||||
public abstract C onCreateItemViewHolder(ViewGroup parent, int viewType);
|
|
||||||
public abstract void onBindSectionViewHolder(S holder, int section);
|
|
||||||
public abstract void onBindItemViewHolder(C holder, int section, int position);
|
|
||||||
}
|
|
@@ -1,103 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.adapters;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.IdRes;
|
|
||||||
import androidx.annotation.LayoutRes;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class StringListAdapter<VH extends StringListAdapter.ViewHolder>
|
|
||||||
extends RecyclerView.Adapter<VH> {
|
|
||||||
|
|
||||||
private RecyclerView rv;
|
|
||||||
private boolean dynamic;
|
|
||||||
private int screenWidth;
|
|
||||||
private int txtWidth = -1;
|
|
||||||
private int padding;
|
|
||||||
|
|
||||||
protected List<String> mList;
|
|
||||||
|
|
||||||
public StringListAdapter(List<String> list) {
|
|
||||||
this(list, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public StringListAdapter(List<String> list, boolean isDynamic) {
|
|
||||||
mList = list;
|
|
||||||
dynamic = isDynamic;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public final VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(itemLayoutRes(), parent, false);
|
|
||||||
VH vh = createViewHolder(v);
|
|
||||||
if (txtWidth < 0)
|
|
||||||
onUpdateTextWidth(vh);
|
|
||||||
return vh;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(@NonNull VH holder, int position) {
|
|
||||||
holder.txt.setText(mList.get(position));
|
|
||||||
holder.txt.getLayoutParams().width = txtWidth;
|
|
||||||
if (dynamic)
|
|
||||||
onUpdateTextWidth(holder);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onUpdateTextWidth(VH vh) {
|
|
||||||
if (txtWidth < 0) {
|
|
||||||
txtWidth = screenWidth - padding;
|
|
||||||
} else {
|
|
||||||
vh.txt.measure(0, 0);
|
|
||||||
int width = vh.txt.getMeasuredWidth();
|
|
||||||
if (width > txtWidth) {
|
|
||||||
txtWidth = width;
|
|
||||||
vh.txt.getLayoutParams().width = txtWidth;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rv.getWidth() != txtWidth + padding)
|
|
||||||
rv.requestLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttachedToRecyclerView(@NonNull RecyclerView rv) {
|
|
||||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
||||||
((Activity) rv.getContext()).getWindowManager()
|
|
||||||
.getDefaultDisplay().getMetrics(displayMetrics);
|
|
||||||
screenWidth = displayMetrics.widthPixels;
|
|
||||||
padding = rv.getPaddingStart() + rv.getPaddingEnd();
|
|
||||||
this.rv = rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final int getItemCount() {
|
|
||||||
return mList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@LayoutRes
|
|
||||||
protected abstract int itemLayoutRes();
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public abstract VH createViewHolder(@NonNull View v);
|
|
||||||
|
|
||||||
public static abstract class ViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
public TextView txt;
|
|
||||||
|
|
||||||
public ViewHolder(@NonNull View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
txt = itemView.findViewById(textViewResId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@IdRes
|
|
||||||
protected abstract int textViewResId();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,144 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.adapters;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.view.animation.Animation;
|
|
||||||
import android.view.animation.RotateAnimation;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.R;
|
|
||||||
import com.topjohnwu.magisk.data.database.MagiskDB;
|
|
||||||
import com.topjohnwu.magisk.model.entity.SuLogEntry;
|
|
||||||
import com.topjohnwu.magisk.view.ExpandableViewHolder;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import butterknife.BindView;
|
|
||||||
|
|
||||||
public class SuLogAdapter extends SectionedAdapter<SuLogAdapter.SectionHolder, SuLogAdapter.LogViewHolder> {
|
|
||||||
|
|
||||||
private List<List<SuLogEntry>> logEntries;
|
|
||||||
private Set<Integer> itemExpanded, sectionExpanded;
|
|
||||||
private MagiskDB suDB;
|
|
||||||
|
|
||||||
public SuLogAdapter(MagiskDB db) {
|
|
||||||
suDB = db;
|
|
||||||
logEntries = Collections.emptyList();
|
|
||||||
sectionExpanded = new HashSet<>();
|
|
||||||
itemExpanded = new HashSet<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSectionCount() {
|
|
||||||
return logEntries.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount(int section) {
|
|
||||||
return sectionExpanded.contains(section) ? logEntries.get(section).size() : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SectionHolder onCreateSectionViewHolder(ViewGroup parent) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_sulog_group, parent, false);
|
|
||||||
return new SectionHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LogViewHolder onCreateItemViewHolder(ViewGroup parent, int viewType) {
|
|
||||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_sulog, parent, false);
|
|
||||||
return new LogViewHolder(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindSectionViewHolder(SectionHolder holder, int section) {
|
|
||||||
SuLogEntry entry = logEntries.get(section).get(0);
|
|
||||||
holder.arrow.setRotation(sectionExpanded.contains(section) ? 180 : 0);
|
|
||||||
holder.itemView.setOnClickListener(v -> {
|
|
||||||
RotateAnimation rotate;
|
|
||||||
if (sectionExpanded.contains(section)) {
|
|
||||||
holder.arrow.setRotation(0);
|
|
||||||
rotate = new RotateAnimation(180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
|
|
||||||
sectionExpanded.remove(section);
|
|
||||||
notifyItemRangeRemoved(getItemPosition(section, 0), logEntries.get(section).size());
|
|
||||||
} else {
|
|
||||||
rotate = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
|
|
||||||
sectionExpanded.add(section);
|
|
||||||
notifyItemRangeInserted(getItemPosition(section, 0), logEntries.get(section).size());
|
|
||||||
}
|
|
||||||
rotate.setDuration(300);
|
|
||||||
rotate.setFillAfter(true);
|
|
||||||
holder.arrow.setAnimation(rotate);
|
|
||||||
});
|
|
||||||
holder.date.setText(entry.getDateString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindItemViewHolder(LogViewHolder holder, int section, int position) {
|
|
||||||
SuLogEntry entry = logEntries.get(section).get(position);
|
|
||||||
int realIdx = getItemPosition(section, position);
|
|
||||||
holder.expandable.setExpanded(itemExpanded.contains(realIdx));
|
|
||||||
holder.itemView.setOnClickListener(view -> {
|
|
||||||
if (holder.expandable.isExpanded()) {
|
|
||||||
holder.expandable.collapse();
|
|
||||||
itemExpanded.remove(realIdx);
|
|
||||||
} else {
|
|
||||||
holder.expandable.expand();
|
|
||||||
itemExpanded.add(realIdx);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Context context = holder.itemView.getContext();
|
|
||||||
holder.appName.setText(entry.appName);
|
|
||||||
holder.action.setText(entry.action ? R.string.grant : R.string.deny);
|
|
||||||
holder.pid.setText(context.getString(R.string.pid, entry.fromPid));
|
|
||||||
holder.uid.setText(context.getString(R.string.target_uid, entry.toUid));
|
|
||||||
holder.command.setText(context.getString(R.string.command, entry.command));
|
|
||||||
holder.time.setText(entry.getTimeString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notifyDBChanged() {
|
|
||||||
logEntries = suDB.getLogs();
|
|
||||||
itemExpanded.clear();
|
|
||||||
sectionExpanded.clear();
|
|
||||||
sectionExpanded.add(0);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
static class SectionHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.date) TextView date;
|
|
||||||
@BindView(R.id.arrow) ImageView arrow;
|
|
||||||
|
|
||||||
SectionHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
new SuLogAdapter$SectionHolder_ViewBinding(this, itemView);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class LogViewHolder extends RecyclerView.ViewHolder {
|
|
||||||
|
|
||||||
@BindView(R.id.app_name) TextView appName;
|
|
||||||
@BindView(R.id.action) TextView action;
|
|
||||||
@BindView(R.id.time) TextView time;
|
|
||||||
@BindView(R.id.pid) TextView pid;
|
|
||||||
@BindView(R.id.uid) TextView uid;
|
|
||||||
@BindView(R.id.cmd) TextView command;
|
|
||||||
@BindView(R.id.expand_layout) ViewGroup expandLayout;
|
|
||||||
|
|
||||||
ExpandableViewHolder expandable;
|
|
||||||
|
|
||||||
LogViewHolder(View itemView) {
|
|
||||||
super(itemView);
|
|
||||||
new SuLogAdapter$LogViewHolder_ViewBinding(this, itemView);
|
|
||||||
expandable = new ExpandableViewHolder(expandLayout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.adapters;
|
|
||||||
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
import androidx.fragment.app.FragmentPagerAdapter;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TabFragmentAdapter extends FragmentPagerAdapter {
|
|
||||||
|
|
||||||
private List<Fragment> fragmentList;
|
|
||||||
private List<String> titleList;
|
|
||||||
|
|
||||||
public TabFragmentAdapter(FragmentManager fm) {
|
|
||||||
super(fm);
|
|
||||||
fragmentList = new ArrayList<>();
|
|
||||||
titleList = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fragment getItem(int position) {
|
|
||||||
return fragmentList.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return fragmentList.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CharSequence getPageTitle(int position) {
|
|
||||||
return titleList.get(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addTab(Fragment fragment, String title) {
|
|
||||||
fragmentList.add(fragment);
|
|
||||||
titleList.add(title);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,37 @@
|
|||||||
|
package com.topjohnwu.magisk.model.binding
|
||||||
|
|
||||||
|
import androidx.databinding.ViewDataBinding
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.topjohnwu.magisk.databinding.ComparableRvItem
|
||||||
|
import com.topjohnwu.magisk.model.entity.recycler.LenientRvItem
|
||||||
|
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter
|
||||||
|
|
||||||
|
class BindingAdapter : BindingRecyclerViewAdapter<ComparableRvItem<*>>() {
|
||||||
|
|
||||||
|
private var recyclerView: RecyclerView? = null
|
||||||
|
|
||||||
|
override fun onBindBinding(
|
||||||
|
binding: ViewDataBinding,
|
||||||
|
variableId: Int,
|
||||||
|
layoutRes: Int,
|
||||||
|
position: Int,
|
||||||
|
item: ComparableRvItem<*>
|
||||||
|
) {
|
||||||
|
super.onBindBinding(binding, variableId, layoutRes, position, item)
|
||||||
|
|
||||||
|
when (item) {
|
||||||
|
is LenientRvItem -> {
|
||||||
|
val recycler = recyclerView ?: return
|
||||||
|
item.onBindingBound(binding)
|
||||||
|
item.onBindingBound(binding, recycler)
|
||||||
|
}
|
||||||
|
else -> item.onBindingBound(binding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
|
||||||
|
super.onAttachedToRecyclerView(recyclerView)
|
||||||
|
this.recyclerView = recyclerView
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,156 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.download;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.app.Service;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.IBinder;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.App;
|
|
||||||
import com.topjohnwu.magisk.ClassMap;
|
|
||||||
import com.topjohnwu.magisk.Const;
|
|
||||||
import com.topjohnwu.magisk.model.entity.Repo;
|
|
||||||
import com.topjohnwu.magisk.ui.flash.FlashActivity;
|
|
||||||
import com.topjohnwu.magisk.view.Notifications;
|
|
||||||
import com.topjohnwu.magisk.view.ProgressNotification;
|
|
||||||
import com.topjohnwu.net.Networking;
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
|
||||||
import com.topjohnwu.superuser.ShellUtils;
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipInputStream;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
|
||||||
|
|
||||||
public class DownloadModuleService extends Service {
|
|
||||||
|
|
||||||
private List<ProgressNotification> notifications;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
notifications = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
||||||
Shell.EXECUTOR.execute(() -> {
|
|
||||||
Repo repo = intent.getParcelableExtra("repo");
|
|
||||||
boolean install = intent.getBooleanExtra("install", false);
|
|
||||||
dlProcessInstall(repo, install);
|
|
||||||
});
|
|
||||||
return START_REDELIVER_INTENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized void onTaskRemoved(Intent rootIntent) {
|
|
||||||
for (ProgressNotification n : notifications) {
|
|
||||||
Notifications.mgr.cancel(n.hashCode());
|
|
||||||
}
|
|
||||||
notifications.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void addNotification(ProgressNotification n) {
|
|
||||||
if (notifications.isEmpty()) {
|
|
||||||
// Start foreground
|
|
||||||
startForeground(n.hashCode(), n.getNotification());
|
|
||||||
}
|
|
||||||
notifications.add(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
private synchronized void removeNotification(ProgressNotification n) {
|
|
||||||
notifications.remove(n);
|
|
||||||
if (notifications.isEmpty()) {
|
|
||||||
// No more tasks, stop service
|
|
||||||
stopForeground(true);
|
|
||||||
stopSelf();
|
|
||||||
} else {
|
|
||||||
// Pick another notification as our foreground notification
|
|
||||||
n = notifications.get(0);
|
|
||||||
startForeground(n.hashCode(), n.getNotification());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dlProcessInstall(Repo repo, boolean install) {
|
|
||||||
File output = new File(Const.EXTERNAL_PATH, repo.getDownloadFilename());
|
|
||||||
ProgressNotification progress = new ProgressNotification(output.getName());
|
|
||||||
addNotification(progress);
|
|
||||||
try {
|
|
||||||
InputStream in = Networking.get(repo.getZipUrl())
|
|
||||||
.setDownloadProgressListener(progress)
|
|
||||||
.execForInputStream().getResult();
|
|
||||||
OutputStream out = new BufferedOutputStream(new FileOutputStream(output));
|
|
||||||
processZip(in, out);
|
|
||||||
Intent intent = new Intent(this, ClassMap.get(FlashActivity.class));
|
|
||||||
intent.setData(Uri.fromFile(output))
|
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_ZIP);
|
|
||||||
synchronized (getApplication()) {
|
|
||||||
if (install && App.foreground() != null &&
|
|
||||||
!(App.foreground() instanceof FlashActivity)) {
|
|
||||||
/* Only start flashing if there is a foreground activity and the
|
|
||||||
* user is not also flashing another module at the same time */
|
|
||||||
App.foreground().startActivity(intent);
|
|
||||||
} else {
|
|
||||||
/* Or else we preset a notification notifying that we are done */
|
|
||||||
PendingIntent pi = PendingIntent.getActivity(this, progress.hashCode(), intent,
|
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
progress.dlDone(pi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
progress.dlFail();
|
|
||||||
}
|
|
||||||
removeNotification(progress);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processZip(InputStream in, OutputStream out)
|
|
||||||
throws IOException {
|
|
||||||
try (ZipInputStream zin = new ZipInputStream(in);
|
|
||||||
ZipOutputStream zout = new ZipOutputStream(out)) {
|
|
||||||
|
|
||||||
// Inject latest module-installer.sh as update-binary
|
|
||||||
zout.putNextEntry(new ZipEntry("META-INF/"));
|
|
||||||
zout.putNextEntry(new ZipEntry("META-INF/com/"));
|
|
||||||
zout.putNextEntry(new ZipEntry("META-INF/com/google/"));
|
|
||||||
zout.putNextEntry(new ZipEntry("META-INF/com/google/android/"));
|
|
||||||
zout.putNextEntry(new ZipEntry("META-INF/com/google/android/update-binary"));
|
|
||||||
try (InputStream update_bin = Networking.get(Const.Url.MODULE_INSTALLER)
|
|
||||||
.execForInputStream().getResult()) {
|
|
||||||
ShellUtils.pump(update_bin, zout);
|
|
||||||
}
|
|
||||||
zout.putNextEntry(new ZipEntry("META-INF/com/google/android/updater-script"));
|
|
||||||
zout.write("#MAGISK\n".getBytes("UTF-8"));
|
|
||||||
|
|
||||||
int off = -1;
|
|
||||||
ZipEntry entry;
|
|
||||||
while ((entry = zin.getNextEntry()) != null) {
|
|
||||||
if (off < 0)
|
|
||||||
off = entry.getName().indexOf('/') + 1;
|
|
||||||
String path = entry.getName().substring(off);
|
|
||||||
if (path.isEmpty())
|
|
||||||
continue;
|
|
||||||
if (path.startsWith("META-INF"))
|
|
||||||
continue;
|
|
||||||
zout.putNextEntry(new ZipEntry(path));
|
|
||||||
if (!entry.isDirectory())
|
|
||||||
ShellUtils.pump(zin, zout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,154 @@
|
|||||||
|
package com.topjohnwu.magisk.model.download
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.Notification
|
||||||
|
import android.app.PendingIntent
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Build
|
||||||
|
import android.webkit.MimeTypeMap
|
||||||
|
import com.topjohnwu.magisk.R
|
||||||
|
import com.topjohnwu.magisk.extensions.chooser
|
||||||
|
import com.topjohnwu.magisk.extensions.exists
|
||||||
|
import com.topjohnwu.magisk.extensions.provide
|
||||||
|
import com.topjohnwu.magisk.intent
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.Configuration.*
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.Configuration.Flash.Secondary
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.*
|
||||||
|
import com.topjohnwu.magisk.ui.flash.FlashActivity
|
||||||
|
import com.topjohnwu.magisk.utils.APKInstall
|
||||||
|
import org.koin.core.get
|
||||||
|
import java.io.File
|
||||||
|
import kotlin.random.Random.Default.nextInt
|
||||||
|
|
||||||
|
/* More of a facade for [RemoteFileService], but whatever... */
|
||||||
|
@SuppressLint("Registered")
|
||||||
|
open class DownloadService : RemoteFileService() {
|
||||||
|
|
||||||
|
private val context get() = this
|
||||||
|
private val File.type
|
||||||
|
get() = MimeTypeMap.getSingleton()
|
||||||
|
.getMimeTypeFromExtension(extension)
|
||||||
|
?: "resource/folder"
|
||||||
|
|
||||||
|
override fun onFinished(subject: DownloadSubject, id: Int) = when (subject) {
|
||||||
|
is Magisk -> onFinishedInternal(subject, id)
|
||||||
|
is Module -> onFinishedInternal(subject, id)
|
||||||
|
is Manager -> onFinishedInternal(subject, id)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onFinishedInternal(
|
||||||
|
subject: Magisk,
|
||||||
|
id: Int
|
||||||
|
) = when (val conf = subject.configuration) {
|
||||||
|
Uninstall -> FlashActivity.uninstall(this, subject.file, id)
|
||||||
|
is Patch -> FlashActivity.patch(this, subject.file, conf.fileUri, id)
|
||||||
|
is Flash -> FlashActivity.flash(this, subject.file, conf is Secondary, id)
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onFinishedInternal(
|
||||||
|
subject: Module,
|
||||||
|
id: Int
|
||||||
|
) = when (subject.configuration) {
|
||||||
|
is Flash -> FlashActivity.install(this, subject.file, id)
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onFinishedInternal(
|
||||||
|
subject: Manager,
|
||||||
|
id: Int
|
||||||
|
) {
|
||||||
|
remove(id)
|
||||||
|
when (subject.configuration) {
|
||||||
|
is APK.Upgrade -> APKInstall.install(this, subject.file)
|
||||||
|
is APK.Restore -> Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---
|
||||||
|
|
||||||
|
override fun Notification.Builder.addActions(subject: DownloadSubject)
|
||||||
|
= when (subject) {
|
||||||
|
is Magisk -> addActionsInternal(subject)
|
||||||
|
is Module -> addActionsInternal(subject)
|
||||||
|
is Manager -> addActionsInternal(subject)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Notification.Builder.addActionsInternal(subject: Magisk)
|
||||||
|
= when (val conf = subject.configuration) {
|
||||||
|
Download -> this.apply {
|
||||||
|
fileIntent(subject.file.parentFile!!)
|
||||||
|
.takeIf { it.exists(get()) }
|
||||||
|
?.let { addAction(0, R.string.download_open_parent, it.chooser()) }
|
||||||
|
fileIntent(subject.file)
|
||||||
|
.takeIf { it.exists(get()) }
|
||||||
|
?.let { addAction(0, R.string.download_open_self, it.chooser()) }
|
||||||
|
}
|
||||||
|
Uninstall -> setContentIntent(FlashActivity.uninstallIntent(context, subject.file))
|
||||||
|
is Flash -> setContentIntent(FlashActivity.flashIntent(context, subject.file, conf is Secondary))
|
||||||
|
is Patch -> setContentIntent(FlashActivity.patchIntent(context, subject.file, conf.fileUri))
|
||||||
|
else -> this
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Notification.Builder.addActionsInternal(subject: Module)
|
||||||
|
= when (subject.configuration) {
|
||||||
|
Download -> this.apply {
|
||||||
|
fileIntent(subject.file.parentFile!!)
|
||||||
|
.takeIf { it.exists(get()) }
|
||||||
|
?.let { addAction(0, R.string.download_open_parent, it.chooser()) }
|
||||||
|
fileIntent(subject.file)
|
||||||
|
.takeIf { it.exists(get()) }
|
||||||
|
?.let { addAction(0, R.string.download_open_self, it.chooser()) }
|
||||||
|
}
|
||||||
|
is Flash -> setContentIntent(FlashActivity.installIntent(context, subject.file))
|
||||||
|
else -> this
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Notification.Builder.addActionsInternal(subject: Manager)
|
||||||
|
= when (subject.configuration) {
|
||||||
|
APK.Upgrade -> setContentIntent(APKInstall.installIntent(context, subject.file))
|
||||||
|
else -> this
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("ReplaceSingleLineLet")
|
||||||
|
private fun Notification.Builder.setContentIntent(intent: Intent) =
|
||||||
|
PendingIntent.getActivity(context, nextInt(), intent, PendingIntent.FLAG_ONE_SHOT)
|
||||||
|
.let { setContentIntent(it) }
|
||||||
|
|
||||||
|
@Suppress("ReplaceSingleLineLet")
|
||||||
|
private fun Notification.Builder.addAction(icon: Int, title: Int, intent: Intent) =
|
||||||
|
PendingIntent.getActivity(context, nextInt(), intent, PendingIntent.FLAG_ONE_SHOT)
|
||||||
|
.let { addAction(icon, getString(title), it) }
|
||||||
|
|
||||||
|
// ---
|
||||||
|
|
||||||
|
private fun fileIntent(file: File): Intent {
|
||||||
|
return Intent(Intent.ACTION_VIEW)
|
||||||
|
.setDataAndType(file.provide(this), file.type)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
}
|
||||||
|
|
||||||
|
class Builder {
|
||||||
|
lateinit var subject: DownloadSubject
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
inline operator fun invoke(context: Context, argBuilder: Builder.() -> Unit) {
|
||||||
|
val app = context.applicationContext
|
||||||
|
val builder = Builder().apply(argBuilder)
|
||||||
|
val intent = app.intent(DownloadService::class.java).putExtra(ARG_URL, builder.subject)
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
app.startForegroundService(intent)
|
||||||
|
} else {
|
||||||
|
app.startService(intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,65 @@
|
|||||||
|
package com.topjohnwu.magisk.model.download
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.*
|
||||||
|
import com.topjohnwu.magisk.extensions.writeTo
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Restore
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.Configuration.APK.Upgrade
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
||||||
|
import com.topjohnwu.magisk.utils.PatchAPK
|
||||||
|
import com.topjohnwu.superuser.Shell
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
private fun RemoteFileService.patch(apk: File, id: Int) {
|
||||||
|
if (packageName == BuildConfig.APPLICATION_ID)
|
||||||
|
return
|
||||||
|
|
||||||
|
update(id) { notification ->
|
||||||
|
notification.setProgress(0, 0, true)
|
||||||
|
.setProgress(0, 0, true)
|
||||||
|
.setContentTitle(getString(R.string.hide_manager_title))
|
||||||
|
.setContentText("")
|
||||||
|
}
|
||||||
|
val patched = File(apk.parent, "patched.apk")
|
||||||
|
PatchAPK.patch(apk, patched, packageName, applicationInfo.nonLocalizedLabel.toString())
|
||||||
|
apk.delete()
|
||||||
|
patched.renameTo(apk)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun RemoteFileService.upgrade(apk: File, id: Int) {
|
||||||
|
if (isRunningAsStub) {
|
||||||
|
// Move to upgrade location
|
||||||
|
apk.copyTo(DynAPK.update(this), overwrite = true)
|
||||||
|
apk.delete()
|
||||||
|
if (Info.stub!!.version < Info.remote.stub.versionCode) {
|
||||||
|
// We also want to upgrade stub
|
||||||
|
service.fetchFile(Info.remote.stub.link).blockingGet().byteStream().use {
|
||||||
|
it.writeTo(apk)
|
||||||
|
}
|
||||||
|
patch(apk, id)
|
||||||
|
} else {
|
||||||
|
// Simply relaunch the app
|
||||||
|
ProcessPhoenix.triggerRebirth(this)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
patch(apk, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun RemoteFileService.restore(apk: File, id: Int) {
|
||||||
|
update(id) { notification ->
|
||||||
|
notification.setProgress(0, 0, true)
|
||||||
|
.setProgress(0, 0, true)
|
||||||
|
.setContentTitle(getString(R.string.restore_img_msg))
|
||||||
|
.setContentText("")
|
||||||
|
}
|
||||||
|
Config.export()
|
||||||
|
// Make it world readable
|
||||||
|
apk.setReadable(true, false)
|
||||||
|
Shell.su("pm install $apk && pm uninstall $packageName").exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun RemoteFileService.handleAPK(subject: DownloadSubject.Manager)
|
||||||
|
= when (subject.configuration) {
|
||||||
|
is Upgrade -> upgrade(subject.file, subject.hashCode())
|
||||||
|
is Restore -> restore(subject.file, subject.hashCode())
|
||||||
|
}
|
@@ -0,0 +1,44 @@
|
|||||||
|
package com.topjohnwu.magisk.model.download
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.extensions.withStreams
|
||||||
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.util.zip.ZipEntry
|
||||||
|
import java.util.zip.ZipInputStream
|
||||||
|
import java.util.zip.ZipOutputStream
|
||||||
|
|
||||||
|
fun InputStream.toModule(file: File, installer: InputStream) {
|
||||||
|
|
||||||
|
val input = ZipInputStream(buffered())
|
||||||
|
val output = ZipOutputStream(file.outputStream().buffered())
|
||||||
|
|
||||||
|
withStreams(input, output) { zin, zout ->
|
||||||
|
zout.putNextEntry(ZipEntry("META-INF/"))
|
||||||
|
zout.putNextEntry(ZipEntry("META-INF/com/"))
|
||||||
|
zout.putNextEntry(ZipEntry("META-INF/com/google/"))
|
||||||
|
zout.putNextEntry(ZipEntry("META-INF/com/google/android/"))
|
||||||
|
zout.putNextEntry(ZipEntry("META-INF/com/google/android/update-binary"))
|
||||||
|
installer.copyTo(zout)
|
||||||
|
|
||||||
|
zout.putNextEntry(ZipEntry("META-INF/com/google/android/updater-script"))
|
||||||
|
zout.write("#MAGISK\n".toByteArray(charset("UTF-8")))
|
||||||
|
|
||||||
|
var off = -1
|
||||||
|
var entry: ZipEntry? = zin.nextEntry
|
||||||
|
while (entry != null) {
|
||||||
|
if (off < 0) {
|
||||||
|
off = entry.name.indexOf('/') + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
val path = entry.name.substring(off)
|
||||||
|
if (path.isNotEmpty() && !path.startsWith("META-INF")) {
|
||||||
|
zout.putNextEntry(ZipEntry(path))
|
||||||
|
if (!entry.isDirectory) {
|
||||||
|
zin.copyTo(zout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
entry = zin.nextEntry
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,85 @@
|
|||||||
|
package com.topjohnwu.magisk.model.download
|
||||||
|
|
||||||
|
import android.app.Notification
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.IBinder
|
||||||
|
import com.topjohnwu.magisk.base.BaseService
|
||||||
|
import com.topjohnwu.magisk.view.Notifications
|
||||||
|
import org.koin.core.KoinComponent
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.random.Random.Default.nextInt
|
||||||
|
|
||||||
|
abstract class NotificationService : BaseService(), KoinComponent {
|
||||||
|
|
||||||
|
abstract val defaultNotification: Notification.Builder
|
||||||
|
|
||||||
|
private val hasNotifications get() = notifications.isNotEmpty()
|
||||||
|
|
||||||
|
private val notifications =
|
||||||
|
Collections.synchronizedMap(mutableMapOf<Int, Notification.Builder>())
|
||||||
|
|
||||||
|
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||||
|
super.onTaskRemoved(rootIntent)
|
||||||
|
notifications.forEach { cancel(it.key) }
|
||||||
|
notifications.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
// --
|
||||||
|
|
||||||
|
fun update(
|
||||||
|
id: Int,
|
||||||
|
body: (Notification.Builder) -> Unit = {}
|
||||||
|
) {
|
||||||
|
val notification = notifications.getOrPut(id) { defaultNotification }
|
||||||
|
|
||||||
|
notify(id, notification.also(body).build())
|
||||||
|
|
||||||
|
if (notifications.size == 1) {
|
||||||
|
updateForeground()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun finishNotify(
|
||||||
|
id: Int,
|
||||||
|
editBody: (Notification.Builder) -> Notification.Builder? = { null }
|
||||||
|
) : Int {
|
||||||
|
val currentNotification = remove(id)?.run(editBody)
|
||||||
|
|
||||||
|
var newId = -1
|
||||||
|
currentNotification?.let {
|
||||||
|
newId = nextInt(Int.MAX_VALUE)
|
||||||
|
notify(newId, it.build())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasNotifications) {
|
||||||
|
stopSelf()
|
||||||
|
}
|
||||||
|
return newId
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---
|
||||||
|
|
||||||
|
private fun notify(id: Int, notification: Notification) {
|
||||||
|
Notifications.mgr.notify(id, notification)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun cancel(id: Int) {
|
||||||
|
Notifications.mgr.cancel(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun remove(id: Int) = notifications.remove(id).also {
|
||||||
|
cancel(id)
|
||||||
|
updateForeground()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateForeground() {
|
||||||
|
if (hasNotifications)
|
||||||
|
startForeground(notifications.keys.first(), notifications.values.first().build())
|
||||||
|
else
|
||||||
|
stopForeground(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// --
|
||||||
|
|
||||||
|
override fun onBind(p0: Intent?): IBinder? = null
|
||||||
|
}
|
@@ -0,0 +1,118 @@
|
|||||||
|
package com.topjohnwu.magisk.model.download
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.app.Notification
|
||||||
|
import android.content.Intent
|
||||||
|
import com.topjohnwu.magisk.R
|
||||||
|
import com.topjohnwu.magisk.data.network.GithubRawServices
|
||||||
|
import com.topjohnwu.magisk.di.NullActivity
|
||||||
|
import com.topjohnwu.magisk.extensions.get
|
||||||
|
import com.topjohnwu.magisk.extensions.subscribeK
|
||||||
|
import com.topjohnwu.magisk.extensions.writeTo
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject
|
||||||
|
import com.topjohnwu.magisk.model.entity.internal.DownloadSubject.*
|
||||||
|
import com.topjohnwu.magisk.utils.ProgressInputStream
|
||||||
|
import com.topjohnwu.magisk.view.Notifications
|
||||||
|
import com.topjohnwu.superuser.ShellUtils
|
||||||
|
import io.reactivex.Completable
|
||||||
|
import okhttp3.ResponseBody
|
||||||
|
import org.koin.android.ext.android.inject
|
||||||
|
import timber.log.Timber
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
abstract class RemoteFileService : NotificationService() {
|
||||||
|
|
||||||
|
val service: GithubRawServices by inject()
|
||||||
|
|
||||||
|
override val defaultNotification
|
||||||
|
get() = Notifications.progress(this, "")
|
||||||
|
|
||||||
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
|
intent?.getParcelableExtra<DownloadSubject>(ARG_URL)?.let { start(it) }
|
||||||
|
return START_REDELIVER_INTENT
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---
|
||||||
|
|
||||||
|
private fun start(subject: DownloadSubject) = checkExisting(subject)
|
||||||
|
.onErrorResumeNext { download(subject) }
|
||||||
|
.doOnSubscribe { update(subject.hashCode()) { it.setContentTitle(subject.title) } }
|
||||||
|
.subscribeK(onError = {
|
||||||
|
Timber.e(it)
|
||||||
|
finishNotify(subject.hashCode()) { notification ->
|
||||||
|
notification.setContentText(getString(R.string.download_file_error))
|
||||||
|
.setSmallIcon(android.R.drawable.stat_notify_error)
|
||||||
|
.setOngoing(false)
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
val newId = finishNotify(subject)
|
||||||
|
if (get<Activity>() !is NullActivity) {
|
||||||
|
onFinished(subject, newId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun checkExisting(subject: DownloadSubject) = Completable.fromAction {
|
||||||
|
check(subject is Magisk) { "Download cache is disabled" }
|
||||||
|
|
||||||
|
subject.file.also {
|
||||||
|
check(it.exists() && ShellUtils.checkSum("MD5", it, subject.magisk.md5)) {
|
||||||
|
"The given file does not match checksum"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun download(subject: DownloadSubject) = service.fetchFile(subject.url)
|
||||||
|
.map { it.toStream(subject.hashCode()) }
|
||||||
|
.flatMapCompletable { stream ->
|
||||||
|
when (subject) {
|
||||||
|
is Module -> service.fetchInstaller()
|
||||||
|
.doOnSuccess { stream.toModule(subject.file, it.byteStream()) }
|
||||||
|
.ignoreElement()
|
||||||
|
else -> Completable.fromAction { stream.writeTo(subject.file) }
|
||||||
|
}
|
||||||
|
}.doOnComplete {
|
||||||
|
if (subject is Manager)
|
||||||
|
handleAPK(subject)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ResponseBody.toStream(id: Int): InputStream {
|
||||||
|
val maxRaw = contentLength()
|
||||||
|
val max = maxRaw / 1_000_000f
|
||||||
|
|
||||||
|
return ProgressInputStream(byteStream()) {
|
||||||
|
val progress = it / 1_000_000f
|
||||||
|
update(id) { notification ->
|
||||||
|
if (maxRaw > 0) {
|
||||||
|
notification
|
||||||
|
.setProgress(maxRaw.toInt(), it.toInt(), false)
|
||||||
|
.setContentText("%.2f / %.2f MB".format(progress, max))
|
||||||
|
} else {
|
||||||
|
notification.setContentText("%.2f MB / ??".format(progress))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun finishNotify(subject: DownloadSubject) = finishNotify(subject.hashCode()) {
|
||||||
|
it.addActions(subject)
|
||||||
|
.setContentText(getString(R.string.download_complete))
|
||||||
|
.setSmallIcon(android.R.drawable.stat_sys_download_done)
|
||||||
|
.setProgress(0, 0, false)
|
||||||
|
.setOngoing(false)
|
||||||
|
.setAutoCancel(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---
|
||||||
|
|
||||||
|
|
||||||
|
@Throws(Throwable::class)
|
||||||
|
protected abstract fun onFinished(subject: DownloadSubject, id: Int)
|
||||||
|
|
||||||
|
protected abstract fun Notification.Builder.addActions(subject: DownloadSubject)
|
||||||
|
: Notification.Builder
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val ARG_URL = "arg_url"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,144 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.entity;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class BaseModule implements Comparable<BaseModule>, Parcelable {
|
|
||||||
|
|
||||||
private String mId, mName, mVersion, mAuthor, mDescription;
|
|
||||||
private int mVersionCode = -1;
|
|
||||||
|
|
||||||
protected BaseModule() {
|
|
||||||
mId = mName = mVersion = mAuthor = mDescription = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected BaseModule(Cursor c) {
|
|
||||||
mId = nonNull(c.getString(c.getColumnIndex("id")));
|
|
||||||
mName = nonNull(c.getString(c.getColumnIndex("name")));
|
|
||||||
mVersion = nonNull(c.getString(c.getColumnIndex("version")));
|
|
||||||
mVersionCode = c.getInt(c.getColumnIndex("versionCode"));
|
|
||||||
mAuthor = nonNull(c.getString(c.getColumnIndex("author")));
|
|
||||||
mDescription = nonNull(c.getString(c.getColumnIndex("description")));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected BaseModule(Parcel p) {
|
|
||||||
mId = p.readString();
|
|
||||||
mName = p.readString();
|
|
||||||
mVersion = p.readString();
|
|
||||||
mAuthor = p.readString();
|
|
||||||
mDescription = p.readString();
|
|
||||||
mVersionCode = p.readInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(@NonNull BaseModule module) {
|
|
||||||
return this.getName().toLowerCase().compareTo(module.getName().toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int describeContents() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
dest.writeString(mId);
|
|
||||||
dest.writeString(mName);
|
|
||||||
dest.writeString(mVersion);
|
|
||||||
dest.writeString(mAuthor);
|
|
||||||
dest.writeString(mDescription);
|
|
||||||
dest.writeInt(mVersionCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String nonNull(String s) {
|
|
||||||
return s == null ? "" : s;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentValues getContentValues() {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put("id", mId);
|
|
||||||
values.put("name", mName);
|
|
||||||
values.put("version", mVersion);
|
|
||||||
values.put("versionCode", mVersionCode);
|
|
||||||
values.put("author", mAuthor);
|
|
||||||
values.put("description", mDescription);
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void parseProps(List<String> props) { parseProps(props.toArray(new String[0])); }
|
|
||||||
|
|
||||||
protected void parseProps(String[] props) throws NumberFormatException {
|
|
||||||
for (String line : props) {
|
|
||||||
String[] prop = line.split("=", 2);
|
|
||||||
if (prop.length != 2)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
String key = prop[0].trim();
|
|
||||||
String value = prop[1].trim();
|
|
||||||
if (key.isEmpty() || key.charAt(0) == '#')
|
|
||||||
continue;
|
|
||||||
|
|
||||||
switch (key) {
|
|
||||||
case "id":
|
|
||||||
mId = value;
|
|
||||||
break;
|
|
||||||
case "name":
|
|
||||||
mName = value;
|
|
||||||
break;
|
|
||||||
case "version":
|
|
||||||
mVersion = value;
|
|
||||||
break;
|
|
||||||
case "versionCode":
|
|
||||||
mVersionCode = Integer.parseInt(value);
|
|
||||||
break;
|
|
||||||
case "author":
|
|
||||||
mAuthor = value;
|
|
||||||
break;
|
|
||||||
case "description":
|
|
||||||
mDescription = value;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return mName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
mName = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return mVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthor() {
|
|
||||||
return mAuthor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return mId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(String id) {
|
|
||||||
mId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return mDescription;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getVersionCode() {
|
|
||||||
return mVersionCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -0,0 +1,16 @@
|
|||||||
|
package com.topjohnwu.magisk.model.entity
|
||||||
|
|
||||||
|
import android.content.pm.ApplicationInfo
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
|
import com.topjohnwu.magisk.extensions.packageInfo
|
||||||
|
import com.topjohnwu.magisk.extensions.processes
|
||||||
|
|
||||||
|
class HideAppInfo(
|
||||||
|
val info: ApplicationInfo,
|
||||||
|
val name: String,
|
||||||
|
val icon: Drawable
|
||||||
|
) {
|
||||||
|
|
||||||
|
val processes = info.packageInfo?.processes?.distinct() ?: listOf(info.packageName)
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,10 @@
|
|||||||
|
package com.topjohnwu.magisk.model.entity
|
||||||
|
|
||||||
|
class HideTarget(line: String) {
|
||||||
|
|
||||||
|
private val split = line.split(Regex("\\|"), 2)
|
||||||
|
|
||||||
|
val packageName = split[0]
|
||||||
|
val process = split.getOrElse(1) { packageName }
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,57 @@
|
|||||||
|
package com.topjohnwu.magisk.model.entity
|
||||||
|
|
||||||
|
import com.topjohnwu.magisk.extensions.timeFormatTime
|
||||||
|
import com.topjohnwu.magisk.extensions.toTime
|
||||||
|
import com.topjohnwu.magisk.model.entity.MagiskPolicy.Companion.ALLOW
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
data class MagiskLog(
|
||||||
|
val fromUid: Int,
|
||||||
|
val toUid: Int,
|
||||||
|
val fromPid: Int,
|
||||||
|
val packageName: String,
|
||||||
|
val appName: String,
|
||||||
|
val command: String,
|
||||||
|
val action: Boolean,
|
||||||
|
val date: Date
|
||||||
|
) {
|
||||||
|
val timeString = date.time.toTime(timeFormatTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class WrappedMagiskLog(
|
||||||
|
val time: Long,
|
||||||
|
val items: List<MagiskLog>
|
||||||
|
)
|
||||||
|
|
||||||
|
fun Map<String, String>.toLog(): MagiskLog {
|
||||||
|
return MagiskLog(
|
||||||
|
fromUid = get("from_uid")?.toIntOrNull() ?: -1,
|
||||||
|
toUid = get("to_uid")?.toIntOrNull() ?: -1,
|
||||||
|
fromPid = get("from_pid")?.toIntOrNull() ?: -1,
|
||||||
|
packageName = get("package_name").orEmpty(),
|
||||||
|
appName = get("app_name").orEmpty(),
|
||||||
|
command = get("command").orEmpty(),
|
||||||
|
action = get("action")?.toIntOrNull() != 0,
|
||||||
|
date = get("time")?.toLongOrNull()?.toDate() ?: Date()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Long.toDate() = Date(this)
|
||||||
|
|
||||||
|
fun MagiskLog.toMap() = mapOf(
|
||||||
|
"from_uid" to fromUid,
|
||||||
|
"to_uid" to toUid,
|
||||||
|
"from_pid" to fromPid,
|
||||||
|
"package_name" to packageName,
|
||||||
|
"app_name" to appName,
|
||||||
|
"command" to command,
|
||||||
|
"action" to action,
|
||||||
|
"time" to date.time
|
||||||
|
)
|
||||||
|
|
||||||
|
fun MagiskPolicy.toLog(
|
||||||
|
toUid: Int,
|
||||||
|
fromPid: Int,
|
||||||
|
command: String,
|
||||||
|
date: Date
|
||||||
|
) = MagiskLog(uid, toUid, fromPid, packageName, appName, command, policy == ALLOW, date)
|
@@ -0,0 +1,69 @@
|
|||||||
|
package com.topjohnwu.magisk.model.entity
|
||||||
|
|
||||||
|
import android.content.pm.ApplicationInfo
|
||||||
|
import android.content.pm.PackageManager
|
||||||
|
import com.topjohnwu.magisk.extensions.getLabel
|
||||||
|
import com.topjohnwu.magisk.model.entity.MagiskPolicy.Companion.INTERACTIVE
|
||||||
|
|
||||||
|
|
||||||
|
data class MagiskPolicy(
|
||||||
|
val uid: Int,
|
||||||
|
val packageName: String,
|
||||||
|
val appName: String,
|
||||||
|
val policy: Int = INTERACTIVE,
|
||||||
|
val until: Long = -1L,
|
||||||
|
val logging: Boolean = true,
|
||||||
|
val notification: Boolean = true,
|
||||||
|
val applicationInfo: ApplicationInfo
|
||||||
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val INTERACTIVE = 0
|
||||||
|
const val DENY = 1
|
||||||
|
const val ALLOW = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun MagiskPolicy.toMap() = mapOf(
|
||||||
|
"uid" to uid,
|
||||||
|
"package_name" to packageName,
|
||||||
|
"policy" to policy,
|
||||||
|
"until" to until,
|
||||||
|
"logging" to logging,
|
||||||
|
"notification" to notification
|
||||||
|
)
|
||||||
|
|
||||||
|
@Throws(PackageManager.NameNotFoundException::class)
|
||||||
|
fun Map<String, String>.toPolicy(pm: PackageManager): MagiskPolicy {
|
||||||
|
val uid = get("uid")?.toIntOrNull() ?: -1
|
||||||
|
val packageName = get("package_name").orEmpty()
|
||||||
|
val info = pm.getApplicationInfo(packageName, 0)
|
||||||
|
|
||||||
|
if (info.uid != uid)
|
||||||
|
throw PackageManager.NameNotFoundException()
|
||||||
|
|
||||||
|
return MagiskPolicy(
|
||||||
|
uid = uid,
|
||||||
|
packageName = packageName,
|
||||||
|
policy = get("policy")?.toIntOrNull() ?: INTERACTIVE,
|
||||||
|
until = get("until")?.toLongOrNull() ?: -1L,
|
||||||
|
logging = get("logging")?.toIntOrNull() != 0,
|
||||||
|
notification = get("notification")?.toIntOrNull() != 0,
|
||||||
|
applicationInfo = info,
|
||||||
|
appName = info.getLabel(pm)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(PackageManager.NameNotFoundException::class)
|
||||||
|
fun Int.toPolicy(pm: PackageManager): MagiskPolicy {
|
||||||
|
val pkg = pm.getPackagesForUid(this)?.firstOrNull()
|
||||||
|
?: throw PackageManager.NameNotFoundException()
|
||||||
|
val info = pm.getApplicationInfo(pkg, 0)
|
||||||
|
return MagiskPolicy(
|
||||||
|
uid = this,
|
||||||
|
packageName = pkg,
|
||||||
|
applicationInfo = info,
|
||||||
|
appName = info.loadLabel(pm).toString()
|
||||||
|
)
|
||||||
|
}
|
@@ -1,79 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.entity;
|
|
||||||
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
|
|
||||||
import com.topjohnwu.superuser.Shell;
|
|
||||||
import com.topjohnwu.superuser.io.SuFile;
|
|
||||||
|
|
||||||
public class Module extends BaseModule {
|
|
||||||
|
|
||||||
private SuFile mRemoveFile, mDisableFile, mUpdateFile;
|
|
||||||
private boolean mEnable, mRemove, mUpdated;
|
|
||||||
|
|
||||||
public Module(String path) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
parseProps(Shell.su("dos2unix < " + path + "/module.prop").exec().getOut());
|
|
||||||
} catch (NumberFormatException ignored) {}
|
|
||||||
|
|
||||||
mRemoveFile = new SuFile(path, "remove");
|
|
||||||
mDisableFile = new SuFile(path, "disable");
|
|
||||||
mUpdateFile = new SuFile(path, "update");
|
|
||||||
|
|
||||||
if (getId().isEmpty()) {
|
|
||||||
int sep = path.lastIndexOf('/');
|
|
||||||
setId(path.substring(sep + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getName().isEmpty()) {
|
|
||||||
setName(getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
mEnable = !mDisableFile.exists();
|
|
||||||
mRemove = mRemoveFile.exists();
|
|
||||||
mUpdated = mUpdateFile.exists();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Parcelable.Creator<Module> CREATOR = new Creator<Module>() {
|
|
||||||
/* It won't be used at any place */
|
|
||||||
@Override
|
|
||||||
public Module createFromParcel(Parcel source) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Module[] newArray(int size) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public void createDisableFile() {
|
|
||||||
mEnable = !mDisableFile.createNewFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeDisableFile() {
|
|
||||||
mEnable = mDisableFile.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return mEnable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createRemoveFile() {
|
|
||||||
mRemove = mRemoveFile.createNewFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteRemoveFile() {
|
|
||||||
mRemove = !mRemoveFile.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean willBeRemoved() {
|
|
||||||
return mRemove;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isUpdated() {
|
|
||||||
return mUpdated;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,61 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.entity;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
|
|
||||||
public class Policy implements Comparable<Policy>{
|
|
||||||
public static final int INTERACTIVE = 0;
|
|
||||||
public static final int DENY = 1;
|
|
||||||
public static final int ALLOW = 2;
|
|
||||||
|
|
||||||
public int uid, policy = INTERACTIVE;
|
|
||||||
public long until;
|
|
||||||
public boolean logging = true, notification = true;
|
|
||||||
public String packageName, appName;
|
|
||||||
public ApplicationInfo info;
|
|
||||||
|
|
||||||
public Policy(int uid, PackageManager pm) throws PackageManager.NameNotFoundException {
|
|
||||||
String[] pkgs = pm.getPackagesForUid(uid);
|
|
||||||
if (pkgs == null || pkgs.length == 0)
|
|
||||||
throw new PackageManager.NameNotFoundException();
|
|
||||||
this.uid = uid;
|
|
||||||
packageName = pkgs[0];
|
|
||||||
info = pm.getApplicationInfo(packageName, 0);
|
|
||||||
appName = Utils.getAppLabel(info, pm);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Policy(ContentValues values, PackageManager pm) throws PackageManager.NameNotFoundException {
|
|
||||||
uid = values.getAsInteger("uid");
|
|
||||||
packageName = values.getAsString("package_name");
|
|
||||||
policy = values.getAsInteger("policy");
|
|
||||||
until = values.getAsInteger("until");
|
|
||||||
logging = values.getAsInteger("logging") != 0;
|
|
||||||
notification = values.getAsInteger("notification") != 0;
|
|
||||||
info = pm.getApplicationInfo(packageName, 0);
|
|
||||||
if (info.uid != uid)
|
|
||||||
throw new PackageManager.NameNotFoundException();
|
|
||||||
appName = info.loadLabel(pm).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentValues getContentValues() {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put("uid", uid);
|
|
||||||
values.put("package_name", packageName);
|
|
||||||
values.put("policy", policy);
|
|
||||||
values.put("until", until);
|
|
||||||
values.put("logging", logging ? 1 : 0);
|
|
||||||
values.put("notification", notification ? 1 : 0);
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(@NonNull Policy policy) {
|
|
||||||
return appName.toLowerCase().compareTo(policy.appName.toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,109 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.entity;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.os.Parcel;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.Const;
|
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class Repo extends BaseModule {
|
|
||||||
|
|
||||||
private Date mLastUpdate;
|
|
||||||
|
|
||||||
public Repo(String id) {
|
|
||||||
setId(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Repo(Cursor c) {
|
|
||||||
super(c);
|
|
||||||
mLastUpdate = new Date(c.getLong(c.getColumnIndex("last_update")));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Repo(Parcel p) {
|
|
||||||
super(p);
|
|
||||||
mLastUpdate = new Date(p.readLong());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Parcelable.Creator<Repo> CREATOR = new Parcelable.Creator<Repo>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Repo createFromParcel(Parcel source) {
|
|
||||||
return new Repo(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Repo[] newArray(int size) {
|
|
||||||
return new Repo[size];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
|
||||||
super.writeToParcel(dest, flags);
|
|
||||||
dest.writeLong(mLastUpdate.getTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() throws IllegalRepoException {
|
|
||||||
String props[] = Utils.dlString(getPropUrl()).split("\\n");
|
|
||||||
try {
|
|
||||||
parseProps(props);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new IllegalRepoException("Repo [" + getId() + "] parse error: " + e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getVersionCode() < 0) {
|
|
||||||
throw new IllegalRepoException("Repo [" + getId() + "] does not contain versionCode");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update(Date lastUpdate) throws IllegalRepoException {
|
|
||||||
mLastUpdate = lastUpdate;
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentValues getContentValues() {
|
|
||||||
ContentValues values = super.getContentValues();
|
|
||||||
values.put("last_update", mLastUpdate.getTime());
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getZipUrl() {
|
|
||||||
return String.format(Const.Url.ZIP_URL, getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPropUrl() {
|
|
||||||
return getFileUrl("module.prop");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDetailUrl() {
|
|
||||||
return getFileUrl("README.md");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFileUrl(String file) {
|
|
||||||
return String.format(Const.Url.FILE_URL, getId(), file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastUpdateString() {
|
|
||||||
return DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(mLastUpdate);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLastUpdate() {
|
|
||||||
return mLastUpdate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDownloadFilename() {
|
|
||||||
return Utils.getLegalFilename(getName() + "-" + getVersion() + ".zip");
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IllegalRepoException extends Exception {
|
|
||||||
IllegalRepoException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,56 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.model.entity;
|
|
||||||
|
|
||||||
import android.content.ContentValues;
|
|
||||||
|
|
||||||
import com.topjohnwu.magisk.utils.LocaleManager;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class SuLogEntry {
|
|
||||||
|
|
||||||
public int fromUid, toUid, fromPid;
|
|
||||||
public String packageName, appName, command;
|
|
||||||
public boolean action;
|
|
||||||
public Date date;
|
|
||||||
|
|
||||||
public SuLogEntry(Policy policy) {
|
|
||||||
fromUid = policy.uid;
|
|
||||||
packageName = policy.packageName;
|
|
||||||
appName = policy.appName;
|
|
||||||
action = policy.policy == Policy.ALLOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SuLogEntry(ContentValues values) {
|
|
||||||
fromUid = values.getAsInteger("from_uid");
|
|
||||||
packageName = values.getAsString("package_name");
|
|
||||||
appName = values.getAsString("app_name");
|
|
||||||
fromPid = values.getAsInteger("from_pid");
|
|
||||||
command = values.getAsString("command");
|
|
||||||
toUid = values.getAsInteger("to_uid");
|
|
||||||
action = values.getAsInteger("action") != 0;
|
|
||||||
date = new Date(values.getAsLong("time"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ContentValues getContentValues() {
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put("from_uid", fromUid);
|
|
||||||
values.put("package_name", packageName);
|
|
||||||
values.put("app_name", appName);
|
|
||||||
values.put("from_pid", fromPid);
|
|
||||||
values.put("command", command);
|
|
||||||
values.put("to_uid", toUid);
|
|
||||||
values.put("action", action ? 1 : 0);
|
|
||||||
values.put("time", date.getTime());
|
|
||||||
return values;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDateString() {
|
|
||||||
return DateFormat.getDateInstance(DateFormat.MEDIUM, LocaleManager.locale).format(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTimeString() {
|
|
||||||
return new SimpleDateFormat("h:mm a", LocaleManager.locale).format(date);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,42 @@
|
|||||||
|
package com.topjohnwu.magisk.model.entity
|
||||||
|
|
||||||
|
import android.os.Parcelable
|
||||||
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
import se.ansman.kotshi.JsonSerializable
|
||||||
|
|
||||||
|
@JsonSerializable
|
||||||
|
data class UpdateInfo(
|
||||||
|
val app: ManagerJson = ManagerJson(),
|
||||||
|
val uninstaller: UninstallerJson = UninstallerJson(),
|
||||||
|
val magisk: MagiskJson = MagiskJson(),
|
||||||
|
val stub: StubJson = StubJson()
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonSerializable
|
||||||
|
data class UninstallerJson(
|
||||||
|
val link: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
@JsonSerializable
|
||||||
|
data class MagiskJson(
|
||||||
|
val version: String = "",
|
||||||
|
val versionCode: Int = -1,
|
||||||
|
val link: String = "",
|
||||||
|
val note: String = "",
|
||||||
|
val md5: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
@JsonSerializable
|
||||||
|
data class ManagerJson(
|
||||||
|
val version: String = "",
|
||||||
|
val versionCode: Int = -1,
|
||||||
|
val link: String = "",
|
||||||
|
val note: String = ""
|
||||||
|
) : Parcelable
|
||||||
|
|
||||||
|
@JsonSerializable
|
||||||
|
data class StubJson(
|
||||||
|
val versionCode: Int = -1,
|
||||||
|
val link: String = ""
|
||||||
|
)
|
@@ -0,0 +1,37 @@
|
|||||||
|
package com.topjohnwu.magisk.model.entity.internal
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import android.os.Parcelable
|
||||||
|
import kotlinx.android.parcel.Parcelize
|
||||||
|
|
||||||
|
sealed class Configuration : Parcelable {
|
||||||
|
|
||||||
|
sealed class Flash : Configuration() {
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
object Primary : Flash()
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
object Secondary : Flash()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class APK : Configuration() {
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
object Upgrade : APK()
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
object Restore : APK()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
object Download : Configuration()
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
object Uninstall : Configuration()
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class Patch(val fileUri: Uri) : Configuration()
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user