Skip to content

Commit bdb2936

Browse files
committed
Fix checking for keystore entries in Android 12 onwards
Signed-off-by: Muntashir Al-Islam <muntashirakon@riseup.net>
1 parent ed9f1c7 commit bdb2936

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

app/src/main/java/io/github/muntashirakon/AppManager/utils/KeyStoreUtils.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
package io.github.muntashirakon.AppManager.utils;
44

5+
import android.os.Build;
56
import android.os.UserHandleHidden;
67

78
import androidx.annotation.NonNull;
9+
import androidx.annotation.RequiresApi;
810

911
import java.io.FileNotFoundException;
1012
import java.util.ArrayList;
1113
import java.util.List;
1214

15+
import io.github.muntashirakon.AppManager.runner.Runner;
1316
import io.github.muntashirakon.io.Path;
1417
import io.github.muntashirakon.io.Paths;
1518

1619
public final class KeyStoreUtils {
1720
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);
2323
}
24-
return false;
24+
return hasKeyStoreV1(uid);
2525
}
2626

2727
public static boolean hasMasterKey(int uid) {
@@ -57,4 +57,20 @@ public static List<String> getKeyStoreFiles(int uid, int userHandle) {
5757
public static Path getMasterKey(int userHandle) throws FileNotFoundException {
5858
return getKeyStorePath(userHandle).findFile(".masterkey");
5959
}
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+
}
6076
}

0 commit comments

Comments
 (0)