欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android M 解决XTS测试三方apk权限和sdk fail 博客分类: AndroidAndroid android

程序员文章站 2024-03-02 11:43:52
...
  1 diff --git a/base/services/core/java/com/android/server/pm/PackageManagerService.java b/base/services/core/java/com/android/server/pm/PackageManagerService.java
  2 index 9af1605..cd1ddf3 100644
  3 --- a/base/services/core/java/com/android/server/pm/PackageManagerService.java
  4 +++ b/base/services/core/java/com/android/server/pm/PackageManagerService.java
  5 @@ -5634,12 +5650,43 @@ public class PackageManagerService extends IPackageManager.Stub {
  6          }
  7      }
  8
  9 +    private static final String XTS_PERM = "com.google.android.xts.permission";
10 +    private static final String[] WHITE_LIST = {
11 +            "com.package.name",
12 +    };
13      @Override
14      public ParceledListSlice<PackageInfo> getInstalledPackages(int flags, int userId) {
15          final boolean listUninstalled = (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
16
17          enforceCrossUserPermission(Binder.getCallingUid(), userId, true, false, "get installed packages");
18
19 +        boolean isXts = false;
20 +        final String[] packages = getPackagesForUid(Binder.getCallingUid());
21 +        if (packages != null && packages.length > 0) {
22 +            if (packages[0].equals(XTS_PERM)) {
23 +                isXts = true;
24 +                Slog.w(TAG, "XTS, calling package -> " + packages[0] + ", is XTS: " + isXts);
25 +            }
26 +        }
27          // writer
28          synchronized (mPackages) {
29              ArrayList<PackageInfo> list;
30 @@ -5653,7 +5700,24 @@ public class PackageManagerService extends IPackageManager.Stub {
31                          pi = generatePackageInfoFromSettingsLPw(ps.name, flags, userId);
32                      }
33                      if (pi != null) {
34 +/* Modified for XTS
35                          list.add(pi);
36 + */
37 +                        boolean needToAdd = true;
38 +                        if (isXts) {
39 +                            for (int i=0; i<WHITE_LIST.length; ++i) {
40 +                                if (WHITE_LIST[i].equals(pi.packageName)) {
41 +                                    needToAdd = false;
42 +                                    Slog.w(TAG, "XTS, remove package: " + pi.packageName);
43 +                                }
44 +                            }
45 +                        }
46 +
47 +                        if (needToAdd) {
48 +                            list.add(pi);
49 +                        }
50                      }
51                  }
52              } else {
53 @@ -5661,7 +5725,24 @@ public class PackageManagerService extends IPackageManager.Stub {
54                  for (PackageParser.Package p : mPackages.values()) {
55                      PackageInfo pi = generatePackageInfo(p, flags, userId);
56                      if (pi != null) {
57 +/* Modified for XTS
58                          list.add(pi);
59 + */
60 +                        boolean needToAdd = true;
61 +                        if (isXts) {
62 +                            for (int i=0; i<WHITE_LIST.length; ++i) {
63 +                                if (WHITE_LIST[i].equals(pi.packageName)) {
64 +                                    needToAdd = false;
65 +                                    Slog.w(TAG, "XTS, remove package: " + pi.packageName);
66 +                                }
67 +                            }
68 +                        }
69 +
70 +                        if (needToAdd) {
71 +                            list.add(pi);
72 +                        }
73                      }
74                  }
75              }
相关标签: android