-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathApplicationPackageManager.java
More file actions
3400 lines (3047 loc) · 117 KB
/
ApplicationPackageManager.java
File metadata and controls
3400 lines (3047 loc) · 117 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.app;
import android.annotation.DrawableRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringRes;
import android.annotation.UserIdInt;
import android.annotation.XmlRes;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ChangedPackages;
import android.content.pm.ComponentInfo;
import android.content.pm.FeatureInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageDeleteObserver;
import android.content.pm.IPackageManager;
import android.content.pm.IPackageMoveObserver;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.InstallSourceInfo;
import android.content.pm.InstantAppInfo;
import android.content.pm.InstrumentationInfo;
import android.content.pm.IntentFilterVerificationInfo;
import android.content.pm.KeySet;
import android.content.pm.ModuleInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.SharedLibraryInfo;
import android.content.pm.SuspendDialogInfo;
import android.content.pm.VerifierDeviceIdentity;
import android.content.pm.VersionedPackage;
import android.content.pm.dex.ArtManager;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.Process;
import android.os.RemoteException;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.permission.IOnPermissionsChangeListener;
import android.permission.IPermissionManager;
import android.permission.PermissionManager;
import android.provider.Settings;
import android.system.ErrnoException;
import android.system.Os;
import android.system.OsConstants;
import android.system.StructStat;
import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.DebugUtils;
import android.util.LauncherIcons;
import android.util.Log;
import android.view.Display;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.Immutable;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.gmscompat.AttestationHooks;
import com.android.internal.os.SomeArgs;
import com.android.internal.util.UserIcons;
import dalvik.system.VMRuntime;
import libcore.util.EmptyArray;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/** @hide */
public class ApplicationPackageManager extends PackageManager {
private static final String TAG = "ApplicationPackageManager";
private static final boolean DEBUG_ICONS = false;
/**
* Note: Changing this won't do anything on it's own - you should also change the filtering in
* {@link #shouldTraceGrant}
*
* @hide
*/
public static final boolean DEBUG_TRACE_GRANTS = false;
public static final boolean DEBUG_TRACE_PERMISSION_UPDATES = false;
private static final int DEFAULT_EPHEMERAL_COOKIE_MAX_SIZE_BYTES = 16384; // 16KB
// Default flags to use with PackageManager when no flags are given.
private static final int sDefaultFlags = GET_SHARED_LIBRARY_FILES;
// Name of the resource which provides background permission button string
public static final String APP_PERMISSION_BUTTON_ALLOW_ALWAYS =
"app_permission_button_allow_always";
// Name of the package which the permission controller's resources are in.
public static final String PERMISSION_CONTROLLER_RESOURCE_PACKAGE =
"com.android.permissioncontroller";
private final Object mLock = new Object();
@GuardedBy("mLock")
private UserManager mUserManager;
@GuardedBy("mLock")
private PackageInstaller mInstaller;
@GuardedBy("mLock")
private ArtManager mArtManager;
@GuardedBy("mDelegates")
private final ArrayList<MoveCallbackDelegate> mDelegates = new ArrayList<>();
@GuardedBy("mLock")
private String mPermissionsControllerPackageName;
UserManager getUserManager() {
synchronized (mLock) {
if (mUserManager == null) {
mUserManager = UserManager.get(mContext);
}
return mUserManager;
}
}
@Override
public int getUserId() {
return mContext.getUserId();
}
@Override
public PackageInfo getPackageInfo(String packageName, int flags)
throws NameNotFoundException {
return getPackageInfoAsUser(packageName, flags, getUserId());
}
@Override
public PackageInfo getPackageInfo(VersionedPackage versionedPackage, int flags)
throws NameNotFoundException {
final int userId = getUserId();
try {
PackageInfo pi = mPM.getPackageInfoVersioned(versionedPackage,
updateFlagsForPackage(flags, userId), userId);
if (pi != null) {
return pi;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(versionedPackage.toString());
}
@Override
public PackageInfo getPackageInfoAsUser(String packageName, int flags, int userId)
throws NameNotFoundException {
PackageInfo pi =
getPackageInfoAsUserCached(
packageName,
updateFlagsForPackage(flags, userId),
userId);
if (pi == null) {
throw new NameNotFoundException(packageName);
}
return pi;
}
@Override
public String[] currentToCanonicalPackageNames(String[] names) {
try {
return mPM.currentToCanonicalPackageNames(names);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public String[] canonicalToCurrentPackageNames(String[] names) {
try {
return mPM.canonicalToCurrentPackageNames(names);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public Intent getLaunchIntentForPackage(String packageName) {
// First see if the package has an INFO activity; the existence of
// such an activity is implied to be the desired front-door for the
// overall package (such as if it has multiple launcher entries).
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_INFO);
intentToResolve.setPackage(packageName);
List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
// Otherwise, try to find a main launcher activity.
if (ris == null || ris.size() <= 0) {
// reuse the intent instance
intentToResolve.removeCategory(Intent.CATEGORY_INFO);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage(packageName);
ris = queryIntentActivities(intentToResolve, 0);
}
if (ris == null || ris.size() <= 0) {
return null;
}
Intent intent = new Intent(intentToResolve);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(ris.get(0).activityInfo.packageName,
ris.get(0).activityInfo.name);
return intent;
}
@Override
public Intent getLeanbackLaunchIntentForPackage(String packageName) {
return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_LEANBACK_LAUNCHER);
}
@Override
public Intent getCarLaunchIntentForPackage(String packageName) {
return getLaunchIntentForPackageAndCategory(packageName, Intent.CATEGORY_CAR_LAUNCHER);
}
private Intent getLaunchIntentForPackageAndCategory(String packageName, String category) {
// Try to find a main launcher activity for the given categories.
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(category);
intentToResolve.setPackage(packageName);
List<ResolveInfo> ris = queryIntentActivities(intentToResolve, 0);
if (ris == null || ris.size() <= 0) {
return null;
}
Intent intent = new Intent(intentToResolve);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(ris.get(0).activityInfo.packageName,
ris.get(0).activityInfo.name);
return intent;
}
@Override
public int[] getPackageGids(String packageName) throws NameNotFoundException {
return getPackageGids(packageName, 0);
}
@Override
public int[] getPackageGids(String packageName, int flags)
throws NameNotFoundException {
final int userId = getUserId();
try {
int[] gids = mPM.getPackageGids(packageName,
updateFlagsForPackage(flags, userId), userId);
if (gids != null) {
return gids;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(packageName);
}
@Override
public int getPackageUid(String packageName, int flags) throws NameNotFoundException {
return getPackageUidAsUser(packageName, flags, getUserId());
}
@Override
public int getPackageUidAsUser(String packageName, int userId) throws NameNotFoundException {
return getPackageUidAsUser(packageName, 0, userId);
}
@Override
public int getPackageUidAsUser(String packageName, int flags, int userId)
throws NameNotFoundException {
try {
int uid = mPM.getPackageUid(packageName,
updateFlagsForPackage(flags, userId), userId);
if (uid >= 0) {
return uid;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(packageName);
}
@Override
@SuppressWarnings("unchecked")
public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
try {
final ParceledListSlice<PermissionGroupInfo> parceledList =
mPermissionManager.getAllPermissionGroups(flags);
if (parceledList == null) {
return Collections.emptyList();
}
return parceledList.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public PermissionGroupInfo getPermissionGroupInfo(String groupName, int flags)
throws NameNotFoundException {
try {
final PermissionGroupInfo pgi =
mPermissionManager.getPermissionGroupInfo(groupName, flags);
if (pgi != null) {
return pgi;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(groupName);
}
@Override
public PermissionInfo getPermissionInfo(String permName, int flags)
throws NameNotFoundException {
try {
final String packageName = mContext.getOpPackageName();
final PermissionInfo pi =
mPermissionManager.getPermissionInfo(permName, packageName, flags);
if (pi != null) {
return pi;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(permName);
}
@Override
@SuppressWarnings("unchecked")
public List<PermissionInfo> queryPermissionsByGroup(String groupName, int flags)
throws NameNotFoundException {
try {
final ParceledListSlice<PermissionInfo> parceledList =
mPermissionManager.queryPermissionsByGroup(groupName, flags);
if (parceledList != null) {
final List<PermissionInfo> pi = parceledList.getList();
if (pi != null) {
return pi;
}
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(groupName);
}
@Override
public boolean arePermissionsIndividuallyControlled() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_permissionsIndividuallyControlled);
}
@Override
public boolean isWirelessConsentModeEnabled() {
return mContext.getResources().getBoolean(
com.android.internal.R.bool.config_wirelessConsentRequired);
}
@Override
public ApplicationInfo getApplicationInfo(String packageName, int flags)
throws NameNotFoundException {
return getApplicationInfoAsUser(packageName, flags, getUserId());
}
@Override
public ApplicationInfo getApplicationInfoAsUser(String packageName, int flags, int userId)
throws NameNotFoundException {
ApplicationInfo ai = getApplicationInfoAsUserCached(
packageName,
updateFlagsForApplication(flags, userId),
userId);
if (ai == null) {
throw new NameNotFoundException(packageName);
}
return maybeAdjustApplicationInfo(ai);
}
private static ApplicationInfo maybeAdjustApplicationInfo(ApplicationInfo info) {
// If we're dealing with a multi-arch application that has both
// 32 and 64 bit shared libraries, we might need to choose the secondary
// depending on what the current runtime's instruction set is.
if (info.primaryCpuAbi != null && info.secondaryCpuAbi != null) {
final String runtimeIsa = VMRuntime.getRuntime().vmInstructionSet();
// Get the instruction set that the libraries of secondary Abi is supported.
// In presence of a native bridge this might be different than the one secondary Abi used.
String secondaryIsa = VMRuntime.getInstructionSet(info.secondaryCpuAbi);
final String secondaryDexCodeIsa = SystemProperties.get("ro.dalvik.vm.isa." + secondaryIsa);
secondaryIsa = secondaryDexCodeIsa.isEmpty() ? secondaryIsa : secondaryDexCodeIsa;
// If the runtimeIsa is the same as the primary isa, then we do nothing.
// Everything will be set up correctly because info.nativeLibraryDir will
// correspond to the right ISA.
if (runtimeIsa.equals(secondaryIsa)) {
ApplicationInfo modified = new ApplicationInfo(info);
modified.nativeLibraryDir = info.secondaryNativeLibraryDir;
return modified;
}
}
return info;
}
@Override
public ActivityInfo getActivityInfo(ComponentName className, int flags)
throws NameNotFoundException {
final int userId = getUserId();
try {
ActivityInfo ai = mPM.getActivityInfo(className,
updateFlagsForComponent(flags, userId, null), userId);
if (ai != null) {
return ai;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public ActivityInfo getReceiverInfo(ComponentName className, int flags)
throws NameNotFoundException {
final int userId = getUserId();
try {
ActivityInfo ai = mPM.getReceiverInfo(className,
updateFlagsForComponent(flags, userId, null), userId);
if (ai != null) {
return ai;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public ServiceInfo getServiceInfo(ComponentName className, int flags)
throws NameNotFoundException {
final int userId = getUserId();
try {
ServiceInfo si = mPM.getServiceInfo(className,
updateFlagsForComponent(flags, userId, null), userId);
if (si != null) {
return si;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public ProviderInfo getProviderInfo(ComponentName className, int flags)
throws NameNotFoundException {
final int userId = getUserId();
try {
ProviderInfo pi = mPM.getProviderInfo(className,
updateFlagsForComponent(flags, userId, null), userId);
if (pi != null) {
return pi;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException(className.toString());
}
@Override
public String[] getSystemSharedLibraryNames() {
try {
return mPM.getSystemSharedLibraryNames();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
@Override
public @NonNull List<SharedLibraryInfo> getSharedLibraries(int flags) {
return getSharedLibrariesAsUser(flags, getUserId());
}
/** @hide */
@Override
@SuppressWarnings("unchecked")
public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
try {
ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
mContext.getOpPackageName(), flags, userId);
if (sharedLibs == null) {
return Collections.emptyList();
}
return sharedLibs.getList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@NonNull
@Override
public List<SharedLibraryInfo> getDeclaredSharedLibraries(@NonNull String packageName,
@InstallFlags int flags) {
try {
ParceledListSlice<SharedLibraryInfo> sharedLibraries = mPM.getDeclaredSharedLibraries(
packageName, flags, mContext.getUserId());
return sharedLibraries != null ? sharedLibraries.getList() : Collections.emptyList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
@Override
public @NonNull String getServicesSystemSharedLibraryPackageName() {
try {
return mPM.getServicesSystemSharedLibraryPackageName();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* @hide
*/
public @NonNull String getSharedSystemSharedLibraryPackageName() {
try {
return mPM.getSharedSystemSharedLibraryPackageName();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public ChangedPackages getChangedPackages(int sequenceNumber) {
try {
return mPM.getChangedPackages(sequenceNumber, getUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
@SuppressWarnings("unchecked")
public FeatureInfo[] getSystemAvailableFeatures() {
try {
ParceledListSlice<FeatureInfo> parceledList =
mPM.getSystemAvailableFeatures();
if (parceledList == null) {
return new FeatureInfo[0];
}
final List<FeatureInfo> list = parceledList.getList();
final FeatureInfo[] res = new FeatureInfo[list.size()];
for (int i = 0; i < res.length; i++) {
res[i] = list.get(i);
}
return res;
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public boolean hasSystemFeature(String name) {
return hasSystemFeature(name, 0);
}
/**
* Identifies a single hasSystemFeature query.
*/
@Immutable
private static final class HasSystemFeatureQuery {
public final String name;
public final int version;
public HasSystemFeatureQuery(String n, int v) {
name = n;
version = v;
}
@Override
public String toString() {
return String.format("HasSystemFeatureQuery(name=\"%s\", version=%d)",
name, version);
}
@Override
public boolean equals(Object o) {
if (o instanceof HasSystemFeatureQuery) {
HasSystemFeatureQuery r = (HasSystemFeatureQuery) o;
return Objects.equals(name, r.name) && version == r.version;
} else {
return false;
}
}
@Override
public int hashCode() {
return Objects.hashCode(name) * 13 + version;
}
}
// Make this cache relatively large. There are many system features and
// none are ever invalidated. MPTS tests suggests that the cache should
// hold at least 150 entries.
private final static PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>
mHasSystemFeatureCache =
new PropertyInvalidatedCache<HasSystemFeatureQuery, Boolean>(
256, "cache_key.has_system_feature") {
@Override
protected Boolean recompute(HasSystemFeatureQuery query) {
try {
return ActivityThread.currentActivityThread().getPackageManager().
hasSystemFeature(query.name, query.version);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
};
@Override
public boolean hasSystemFeature(String name, int version) {
return AttestationHooks.hasSystemFeature(name,
mHasSystemFeatureCache.query(new HasSystemFeatureQuery(name, version)));
}
/** @hide */
public void disableHasSystemFeatureCache() {
mHasSystemFeatureCache.disableLocal();
}
/** @hide */
public static void invalidateHasSystemFeatureCache() {
mHasSystemFeatureCache.invalidateCache();
}
@Override
public int checkPermission(String permName, String pkgName) {
return PermissionManager
.checkPackageNamePermission(permName, pkgName, getUserId());
}
@Override
public boolean isPermissionRevokedByPolicy(String permName, String pkgName) {
try {
return mPermissionManager.isPermissionRevokedByPolicy(permName, pkgName, getUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/**
* @hide
*/
@Override
public String getPermissionControllerPackageName() {
synchronized (mLock) {
if (mPermissionsControllerPackageName == null) {
try {
mPermissionsControllerPackageName = mPM.getPermissionControllerPackageName();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
return mPermissionsControllerPackageName;
}
}
@Override
public boolean addPermission(PermissionInfo info) {
try {
return mPermissionManager.addPermission(info, false);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public boolean addPermissionAsync(PermissionInfo info) {
try {
return mPermissionManager.addPermission(info, true);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public void removePermission(String name) {
try {
mPermissionManager.removePermission(name);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public void grantRuntimePermission(String packageName, String permissionName,
UserHandle user) {
if (DEBUG_TRACE_GRANTS
&& shouldTraceGrant(packageName, permissionName, user.getIdentifier())) {
Log.i(TAG, "App " + mContext.getPackageName() + " is granting " + packageName + " "
+ permissionName + " for user " + user.getIdentifier(), new RuntimeException());
}
try {
mPM.grantRuntimePermission(packageName, permissionName, user.getIdentifier());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** @hide */
public static boolean shouldTraceGrant(String packageName, String permissionName, int userId) {
// To be modified when debugging
return false;
}
@Override
public void revokeRuntimePermission(String packageName, String permName, UserHandle user) {
revokeRuntimePermission(packageName, permName, user, null);
}
@Override
public void revokeRuntimePermission(String packageName, String permName, UserHandle user,
String reason) {
if (DEBUG_TRACE_PERMISSION_UPDATES
&& shouldTraceGrant(packageName, permName, user.getIdentifier())) {
Log.i(TAG, "App " + mContext.getPackageName() + " is revoking " + packageName + " "
+ permName + " for user " + user.getIdentifier() + " with reason " + reason,
new RuntimeException());
}
try {
mPermissionManager
.revokeRuntimePermission(packageName, permName, user.getIdentifier(), reason);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public int getPermissionFlags(String permName, String packageName, UserHandle user) {
try {
return mPermissionManager
.getPermissionFlags(permName, packageName, user.getIdentifier());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public void updatePermissionFlags(String permName, String packageName,
int flagMask, int flagValues, UserHandle user) {
if (DEBUG_TRACE_PERMISSION_UPDATES
&& shouldTraceGrant(packageName, permName, user.getIdentifier())) {
Log.i(TAG, "App " + mContext.getPackageName() + " is updating flags for "
+ packageName + " "
+ permName + " for user " + user.getIdentifier() + ": "
+ DebugUtils.flagsToString(PackageManager.class, "FLAG_PERMISSION_", flagMask)
+ " := " + DebugUtils.flagsToString(
PackageManager.class, "FLAG_PERMISSION_", flagValues),
new RuntimeException());
}
try {
final boolean checkAdjustPolicyFlagPermission =
mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q;
mPermissionManager.updatePermissionFlags(permName, packageName, flagMask,
flagValues, checkAdjustPolicyFlagPermission, user.getIdentifier());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public @NonNull Set<String> getWhitelistedRestrictedPermissions(
@NonNull String packageName, @PermissionWhitelistFlags int flags) {
try {
final int userId = getUserId();
final List<String> whitelist = mPermissionManager
.getWhitelistedRestrictedPermissions(packageName, flags, userId);
if (whitelist != null) {
return new ArraySet<>(whitelist);
}
return Collections.emptySet();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public boolean addWhitelistedRestrictedPermission(@NonNull String packageName,
@NonNull String permName, @PermissionWhitelistFlags int flags) {
try {
final int userId = getUserId();
return mPermissionManager
.addWhitelistedRestrictedPermission(packageName, permName, flags, userId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public boolean setAutoRevokeWhitelisted(
@NonNull String packageName, boolean whitelisted) {
try {
final int userId = getUserId();
return mPermissionManager.setAutoRevokeWhitelisted(packageName, whitelisted, userId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public boolean isAutoRevokeWhitelisted(@NonNull String packageName) {
try {
final int userId = getUserId();
return mPermissionManager.isAutoRevokeWhitelisted(packageName, userId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public boolean removeWhitelistedRestrictedPermission(@NonNull String packageName,
@NonNull String permName, @PermissionWhitelistFlags int flags) {
try {
final int userId = getUserId();
return mPermissionManager
.removeWhitelistedRestrictedPermission(packageName, permName, flags, userId);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
@UnsupportedAppUsage
public boolean shouldShowRequestPermissionRationale(String permName) {
try {
final String packageName = mContext.getPackageName();
return mPermissionManager
.shouldShowRequestPermissionRationale(permName, packageName, getUserId());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public CharSequence getBackgroundPermissionOptionLabel() {
try {
String permissionController = getPermissionControllerPackageName();
Context context =
mContext.createPackageContext(permissionController, 0);
int textId = context.getResources().getIdentifier(APP_PERMISSION_BUTTON_ALLOW_ALWAYS,
"string", PERMISSION_CONTROLLER_RESOURCE_PACKAGE);
if (textId != 0) {
return context.getText(textId);
}
} catch (NameNotFoundException e) {
Log.e(TAG, "Permission controller not found.", e);
}
return "";
}
@Override
public int checkSignatures(String pkg1, String pkg2) {
try {
return mPM.checkSignatures(pkg1, pkg2);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public int checkSignatures(int uid1, int uid2) {
try {
return mPM.checkUidSignatures(uid1, uid2);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public boolean hasSigningCertificate(
String packageName, byte[] certificate, @CertificateInputType int type) {
try {
return mPM.hasSigningCertificate(packageName, certificate, type);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public boolean hasSigningCertificate(
int uid, byte[] certificate, @CertificateInputType int type) {
try {
return mPM.hasUidSigningCertificate(uid, certificate, type);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public String[] getPackagesForUid(int uid) {
try {
return mPM.getPackagesForUid(uid);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public String getNameForUid(int uid) {
try {
return mPM.getNameForUid(uid);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public String[] getNamesForUids(int[] uids) {
try {
return mPM.getNamesForUids(uids);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
@Override
public int getUidForSharedUser(String sharedUserName)
throws NameNotFoundException {
try {
int uid = mPM.getUidForSharedUser(sharedUserName);
if(uid != -1) {
return uid;
}
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
}
@Override
public List<ModuleInfo> getInstalledModules(int flags) {
try {
return mPM.getInstalledModules(flags);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}