|
2 | 2 |
|
3 | 3 | package io.github.muntashirakon.AppManager.utils; |
4 | 4 |
|
| 5 | +import android.os.Build; |
5 | 6 | import android.os.UserHandleHidden; |
6 | 7 |
|
7 | 8 | import androidx.annotation.NonNull; |
| 9 | +import androidx.annotation.RequiresApi; |
8 | 10 |
|
9 | 11 | import java.io.FileNotFoundException; |
10 | 12 | import java.util.ArrayList; |
11 | 13 | import java.util.List; |
12 | 14 |
|
| 15 | +import io.github.muntashirakon.AppManager.runner.Runner; |
13 | 16 | import io.github.muntashirakon.io.Path; |
14 | 17 | import io.github.muntashirakon.io.Paths; |
15 | 18 |
|
16 | 19 | public final class KeyStoreUtils { |
17 | 20 | public static boolean hasKeyStore(int uid) { |
18 | | - Path keyStorePath = getKeyStorePath(UserHandleHidden.getUserId(uid)); |
19 | | - String[] fileNames = keyStorePath.listFileNames(); |
20 | | - String uidStr = uid + "_"; |
21 | | - for (String fileName : fileNames) { |
22 | | - if (fileName.startsWith(uidStr)) return true; |
| 21 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { |
| 22 | + return hasKeyStoreV2(uid); |
23 | 23 | } |
24 | | - return false; |
| 24 | + return hasKeyStoreV1(uid); |
25 | 25 | } |
26 | 26 |
|
27 | 27 | public static boolean hasMasterKey(int uid) { |
@@ -57,4 +57,20 @@ public static List<String> getKeyStoreFiles(int uid, int userHandle) { |
57 | 57 | public static Path getMasterKey(int userHandle) throws FileNotFoundException { |
58 | 58 | return getKeyStorePath(userHandle).findFile(".masterkey"); |
59 | 59 | } |
| 60 | + |
| 61 | + @RequiresApi(Build.VERSION_CODES.S) |
| 62 | + public static boolean hasKeyStoreV2(int uid) { |
| 63 | + return Runner.runCommand(new String[]{"su", "" + uid, "-c", "keystore_cli_v2", "list"}) |
| 64 | + .getOutputAsList().size() > 1; |
| 65 | + } |
| 66 | + |
| 67 | + public static boolean hasKeyStoreV1(int uid) { |
| 68 | + Path keyStorePath = getKeyStorePath(UserHandleHidden.getUserId(uid)); |
| 69 | + String[] fileNames = keyStorePath.listFileNames(); |
| 70 | + String uidStr = uid + "_"; |
| 71 | + for (String fileName : fileNames) { |
| 72 | + if (fileName.startsWith(uidStr)) return true; |
| 73 | + } |
| 74 | + return false; |
| 75 | + } |
60 | 76 | } |
0 commit comments