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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
|
/*
* 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.XmlRes;
import android.content.ComponentName;
import android.content.ContentResolver;
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.ComponentInfo;
import android.content.pm.ContainerEncryptionParams;
import android.content.pm.FeatureInfo;
import android.content.pm.IPackageDataObserver;
import android.content.pm.IPackageDeleteObserver;
import android.content.pm.IPackageInstallObserver;
import android.content.pm.IPackageManager;
import android.content.pm.IPackageMoveObserver;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.InstrumentationInfo;
import android.content.pm.IntentFilterVerificationInfo;
import android.content.pm.KeySet;
import android.content.pm.ManifestDigest;
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.UserInfo;
import android.content.pm.VerificationParams;
import android.content.pm.VerifierDeviceIdentity;
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.net.Uri;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.ArrayMap;
import android.util.Log;
import android.view.Display;
import dalvik.system.VMRuntime;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.android.internal.util.UserIcons;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
/*package*/
final class ApplicationPackageManager extends PackageManager {
private static final String TAG = "ApplicationPackageManager";
private final static boolean DEBUG_ICONS = false;
// Default flags to use with PackageManager when no flags are given.
private final static int sDefaultFlags = PackageManager.GET_SHARED_LIBRARY_FILES;
private final Object mLock = new Object();
@GuardedBy("mLock")
private UserManager mUserManager;
@GuardedBy("mLock")
private PackageInstaller mInstaller;
UserManager getUserManager() {
synchronized (mLock) {
if (mUserManager == null) {
mUserManager = UserManager.get(mContext);
}
return mUserManager;
}
}
@Override
public PackageInfo getPackageInfo(String packageName, int flags)
throws NameNotFoundException {
try {
PackageInfo pi = mPM.getPackageInfo(packageName, flags, mContext.getUserId());
if (pi != null) {
return pi;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(packageName);
}
@Override
public String[] currentToCanonicalPackageNames(String[] names) {
try {
return mPM.currentToCanonicalPackageNames(names);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public String[] canonicalToCurrentPackageNames(String[] names) {
try {
return mPM.canonicalToCurrentPackageNames(names);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@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) {
// Try to find a main leanback_launcher activity.
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);
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 {
try {
int[] gids = mPM.getPackageGids(packageName, mContext.getUserId());
if (gids != null) {
return gids;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(packageName);
}
@Override
public int getPackageUid(String packageName, int userHandle)
throws NameNotFoundException {
try {
int uid = mPM.getPackageUid(packageName, userHandle);
if (uid >= 0) {
return uid;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(packageName);
}
@Override
public PermissionInfo getPermissionInfo(String name, int flags)
throws NameNotFoundException {
try {
PermissionInfo pi = mPM.getPermissionInfo(name, flags);
if (pi != null) {
return pi;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(name);
}
@Override
public List<PermissionInfo> queryPermissionsByGroup(String group, int flags)
throws NameNotFoundException {
try {
List<PermissionInfo> pi = mPM.queryPermissionsByGroup(group, flags);
if (pi != null) {
return pi;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(group);
}
@Override
public PermissionGroupInfo getPermissionGroupInfo(String name,
int flags) throws NameNotFoundException {
try {
PermissionGroupInfo pgi = mPM.getPermissionGroupInfo(name, flags);
if (pgi != null) {
return pgi;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(name);
}
@Override
public List<PermissionGroupInfo> getAllPermissionGroups(int flags) {
try {
return mPM.getAllPermissionGroups(flags);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public ApplicationInfo getApplicationInfo(String packageName, int flags)
throws NameNotFoundException {
try {
ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, mContext.getUserId());
if (ai != null) {
// This is a temporary hack. Callers must use
// createPackageContext(packageName).getApplicationInfo() to
// get the right paths.
maybeAdjustApplicationInfo(ai);
return ai;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(packageName);
}
private static void 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)) {
info.nativeLibraryDir = info.secondaryNativeLibraryDir;
}
}
}
@Override
public ActivityInfo getActivityInfo(ComponentName className, int flags)
throws NameNotFoundException {
try {
ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
if (ai != null) {
return ai;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(className.toString());
}
@Override
public ActivityInfo getReceiverInfo(ComponentName className, int flags)
throws NameNotFoundException {
try {
ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
if (ai != null) {
return ai;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(className.toString());
}
@Override
public ServiceInfo getServiceInfo(ComponentName className, int flags)
throws NameNotFoundException {
try {
ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
if (si != null) {
return si;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(className.toString());
}
@Override
public ProviderInfo getProviderInfo(ComponentName className, int flags)
throws NameNotFoundException {
try {
ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
if (pi != null) {
return pi;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(className.toString());
}
@Override
public String[] getSystemSharedLibraryNames() {
try {
return mPM.getSystemSharedLibraryNames();
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public FeatureInfo[] getSystemAvailableFeatures() {
try {
return mPM.getSystemAvailableFeatures();
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public boolean hasSystemFeature(String name) {
try {
return mPM.hasSystemFeature(name);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public int checkPermission(String permName, String pkgName) {
try {
return mPM.checkPermission(permName, pkgName, mContext.getUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public boolean addPermission(PermissionInfo info) {
try {
return mPM.addPermission(info);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public boolean addPermissionAsync(PermissionInfo info) {
try {
return mPM.addPermissionAsync(info);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public void removePermission(String name) {
try {
mPM.removePermission(name);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public void grantPermission(String packageName, String permissionName, UserHandle user) {
try {
mPM.grantPermission(packageName, permissionName, user.getIdentifier());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public void revokePermission(String packageName, String permissionName, UserHandle user) {
try {
mPM.revokePermission(packageName, permissionName, user.getIdentifier());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public int checkSignatures(String pkg1, String pkg2) {
try {
return mPM.checkSignatures(pkg1, pkg2);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public int checkSignatures(int uid1, int uid2) {
try {
return mPM.checkUidSignatures(uid1, uid2);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public String[] getPackagesForUid(int uid) {
try {
return mPM.getPackagesForUid(uid);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public String getNameForUid(int uid) {
try {
return mPM.getNameForUid(uid);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public int getUidForSharedUser(String sharedUserName)
throws NameNotFoundException {
try {
int uid = mPM.getUidForSharedUser(sharedUserName);
if(uid != -1) {
return uid;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException("No shared userid for user:"+sharedUserName);
}
@SuppressWarnings("unchecked")
@Override
public List<PackageInfo> getInstalledPackages(int flags) {
return getInstalledPackages(flags, mContext.getUserId());
}
/** @hide */
@Override
public List<PackageInfo> getInstalledPackages(int flags, int userId) {
try {
ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId);
return slice.getList();
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@SuppressWarnings("unchecked")
@Override
public List<PackageInfo> getPackagesHoldingPermissions(
String[] permissions, int flags) {
final int userId = mContext.getUserId();
try {
ParceledListSlice<PackageInfo> slice = mPM.getPackagesHoldingPermissions(
permissions, flags, userId);
return slice.getList();
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@SuppressWarnings("unchecked")
@Override
public List<ApplicationInfo> getInstalledApplications(int flags) {
final int userId = mContext.getUserId();
try {
ParceledListSlice<ApplicationInfo> slice = mPM.getInstalledApplications(flags, userId);
return slice.getList();
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public ResolveInfo resolveActivity(Intent intent, int flags) {
return resolveActivityAsUser(intent, flags, mContext.getUserId());
}
@Override
public ResolveInfo resolveActivityAsUser(Intent intent, int flags, int userId) {
try {
return mPM.resolveIntent(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
flags,
userId);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public List<ResolveInfo> queryIntentActivities(Intent intent,
int flags) {
return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
}
/** @hide Same as above but for a specific user */
@Override
public List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
int flags, int userId) {
try {
return mPM.queryIntentActivities(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
flags,
userId);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public List<ResolveInfo> queryIntentActivityOptions(
ComponentName caller, Intent[] specifics, Intent intent,
int flags) {
final ContentResolver resolver = mContext.getContentResolver();
String[] specificTypes = null;
if (specifics != null) {
final int N = specifics.length;
for (int i=0; i<N; i++) {
Intent sp = specifics[i];
if (sp != null) {
String t = sp.resolveTypeIfNeeded(resolver);
if (t != null) {
if (specificTypes == null) {
specificTypes = new String[N];
}
specificTypes[i] = t;
}
}
}
}
try {
return mPM.queryIntentActivityOptions(caller, specifics,
specificTypes, intent, intent.resolveTypeIfNeeded(resolver),
flags, mContext.getUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
/**
* @hide
*/
@Override
public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags, int userId) {
try {
return mPM.queryIntentReceivers(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
flags,
userId);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
return queryBroadcastReceivers(intent, flags, mContext.getUserId());
}
@Override
public ResolveInfo resolveService(Intent intent, int flags) {
try {
return mPM.resolveService(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
flags,
mContext.getUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public List<ResolveInfo> queryIntentServicesAsUser(Intent intent, int flags, int userId) {
try {
return mPM.queryIntentServices(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
flags,
userId);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
}
@Override
public List<ResolveInfo> queryIntentContentProvidersAsUser(
Intent intent, int flags, int userId) {
try {
return mPM.queryIntentContentProviders(intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()), flags, userId);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public List<ResolveInfo> queryIntentContentProviders(Intent intent, int flags) {
return queryIntentContentProvidersAsUser(intent, flags, mContext.getUserId());
}
@Override
public ProviderInfo resolveContentProvider(String name, int flags) {
return resolveContentProviderAsUser(name, flags, mContext.getUserId());
}
/** @hide **/
@Override
public ProviderInfo resolveContentProviderAsUser(String name, int flags, int userId) {
try {
return mPM.resolveContentProvider(name, flags, userId);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public List<ProviderInfo> queryContentProviders(String processName,
int uid, int flags) {
try {
return mPM.queryContentProviders(processName, uid, flags);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Override
public InstrumentationInfo getInstrumentationInfo(
ComponentName className, int flags)
throws NameNotFoundException {
try {
InstrumentationInfo ii = mPM.getInstrumentationInfo(
className, flags);
if (ii != null) {
return ii;
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException(className.toString());
}
@Override
public List<InstrumentationInfo> queryInstrumentation(
String targetPackage, int flags) {
try {
return mPM.queryInstrumentation(targetPackage, flags);
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
@Nullable
@Override
public Drawable getDrawable(String packageName, @DrawableRes int resId,
@Nullable ApplicationInfo appInfo) {
final ResourceName name = new ResourceName(packageName, resId);
final Drawable cachedIcon = getCachedIcon(name);
if (cachedIcon != null) {
return cachedIcon;
}
if (appInfo == null) {
try {
appInfo = getApplicationInfo(packageName, sDefaultFlags);
} catch (NameNotFoundException e) {
return null;
}
}
if (resId != 0) {
try {
final Resources r = getResourcesForApplication(appInfo);
final Drawable dr = r.getDrawable(resId, null);
if (dr != null) {
putCachedIcon(name, dr);
}
if (false) {
RuntimeException e = new RuntimeException("here");
e.fillInStackTrace();
Log.w(TAG, "Getting drawable 0x" + Integer.toHexString(resId)
+ " from package " + packageName
+ ": app scale=" + r.getCompatibilityInfo().applicationScale
+ ", caller scale=" + mContext.getResources()
.getCompatibilityInfo().applicationScale,
e);
}
if (DEBUG_ICONS) {
Log.v(TAG, "Getting drawable 0x"
+ Integer.toHexString(resId) + " from " + r
+ ": " + dr);
}
return dr;
} catch (NameNotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for "
+ appInfo.packageName);
} catch (Resources.NotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for "
+ appInfo.packageName + ": " + e.getMessage());
} catch (Exception e) {
// If an exception was thrown, fall through to return
// default icon.
Log.w("PackageManager", "Failure retrieving icon 0x"
+ Integer.toHexString(resId) + " in package "
+ packageName, e);
}
}
return null;
}
@Override public Drawable getActivityIcon(ComponentName activityName)
throws NameNotFoundException {
return getActivityInfo(activityName, sDefaultFlags).loadIcon(this);
}
@Override public Drawable getActivityIcon(Intent intent)
throws NameNotFoundException {
if (intent.getComponent() != null) {
return getActivityIcon(intent.getComponent());
}
ResolveInfo info = resolveActivity(
intent, PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) {
return info.activityInfo.loadIcon(this);
}
throw new NameNotFoundException(intent.toUri(0));
}
@Override public Drawable getDefaultActivityIcon() {
return Resources.getSystem().getDrawable(
com.android.internal.R.drawable.sym_def_app_icon);
}
@Override public Drawable getApplicationIcon(ApplicationInfo info) {
return info.loadIcon(this);
}
@Override public Drawable getApplicationIcon(String packageName)
throws NameNotFoundException {
return getApplicationIcon(getApplicationInfo(packageName, sDefaultFlags));
}
@Override
public Drawable getActivityBanner(ComponentName activityName)
throws NameNotFoundException {
return getActivityInfo(activityName, sDefaultFlags).loadBanner(this);
}
@Override
public Drawable getActivityBanner(Intent intent)
throws NameNotFoundException {
if (intent.getComponent() != null) {
return getActivityBanner(intent.getComponent());
}
ResolveInfo info = resolveActivity(
intent, PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) {
return info.activityInfo.loadBanner(this);
}
throw new NameNotFoundException(intent.toUri(0));
}
@Override
public Drawable getApplicationBanner(ApplicationInfo info) {
return info.loadBanner(this);
}
@Override
public Drawable getApplicationBanner(String packageName)
throws NameNotFoundException {
return getApplicationBanner(getApplicationInfo(packageName, sDefaultFlags));
}
@Override
public Drawable getActivityLogo(ComponentName activityName)
throws NameNotFoundException {
return getActivityInfo(activityName, sDefaultFlags).loadLogo(this);
}
@Override
public Drawable getActivityLogo(Intent intent)
throws NameNotFoundException {
if (intent.getComponent() != null) {
return getActivityLogo(intent.getComponent());
}
ResolveInfo info = resolveActivity(
intent, PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) {
return info.activityInfo.loadLogo(this);
}
throw new NameNotFoundException(intent.toUri(0));
}
@Override
public Drawable getApplicationLogo(ApplicationInfo info) {
return info.loadLogo(this);
}
@Override
public Drawable getApplicationLogo(String packageName)
throws NameNotFoundException {
return getApplicationLogo(getApplicationInfo(packageName, sDefaultFlags));
}
@Override
public Drawable getUserBadgedIcon(Drawable icon, UserHandle user) {
final int badgeResId = getBadgeResIdForUser(user.getIdentifier());
if (badgeResId == 0) {
return icon;
}
Drawable badgeIcon = getDrawable("system", badgeResId, null);
return getBadgedDrawable(icon, badgeIcon, null, true);
}
@Override
public Drawable getUserBadgedDrawableForDensity(Drawable drawable, UserHandle user,
Rect badgeLocation, int badgeDensity) {
Drawable badgeDrawable = getUserBadgeForDensity(user, badgeDensity);
if (badgeDrawable == null) {
return drawable;
}
return getBadgedDrawable(drawable, badgeDrawable, badgeLocation, true);
}
@Override
public Drawable getUserBadgeForDensity(UserHandle user, int density) {
UserInfo userInfo = getUserIfProfile(user.getIdentifier());
if (userInfo != null && userInfo.isManagedProfile()) {
if (density <= 0) {
density = mContext.getResources().getDisplayMetrics().densityDpi;
}
return Resources.getSystem().getDrawableForDensity(
com.android.internal.R.drawable.ic_corp_badge, density);
}
return null;
}
@Override
public CharSequence getUserBadgedLabel(CharSequence label, UserHandle user) {
UserInfo userInfo = getUserIfProfile(user.getIdentifier());
if (userInfo != null && userInfo.isManagedProfile()) {
return Resources.getSystem().getString(
com.android.internal.R.string.managed_profile_label_badge, label);
}
return label;
}
@Override
public Resources getResourcesForActivity(ComponentName activityName)
throws NameNotFoundException {
return getResourcesForApplication(
getActivityInfo(activityName, sDefaultFlags).applicationInfo);
}
@Override
public Resources getResourcesForApplication(@NonNull ApplicationInfo app)
throws NameNotFoundException {
if (app.packageName.equals("system")) {
return mContext.mMainThread.getSystemContext().getResources();
}
final boolean sameUid = (app.uid == Process.myUid());
final Resources r = mContext.mMainThread.getTopLevelResources(
sameUid ? app.sourceDir : app.publicSourceDir,
sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
null, mContext.mPackageInfo);
if (r != null) {
return r;
}
throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
}
@Override
public Resources getResourcesForApplication(String appPackageName)
throws NameNotFoundException {
return getResourcesForApplication(
getApplicationInfo(appPackageName, sDefaultFlags));
}
/** @hide */
@Override
public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
throws NameNotFoundException {
if (userId < 0) {
throw new IllegalArgumentException(
"Call does not support special user #" + userId);
}
if ("system".equals(appPackageName)) {
return mContext.mMainThread.getSystemContext().getResources();
}
try {
ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, sDefaultFlags, userId);
if (ai != null) {
return getResourcesForApplication(ai);
}
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
}
int mCachedSafeMode = -1;
@Override public boolean isSafeMode() {
try {
if (mCachedSafeMode < 0) {
mCachedSafeMode = mPM.isSafeMode() ? 1 : 0;
}
return mCachedSafeMode != 0;
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
static void configurationChanged() {
synchronized (sSync) {
sIconCache.clear();
sStringCache.clear();
}
}
ApplicationPackageManager(ContextImpl context,
IPackageManager pm) {
mContext = context;
mPM = pm;
}
@Nullable
private Drawable getCachedIcon(@NonNull ResourceName name) {
synchronized (sSync) {
final WeakReference<Drawable.ConstantState> wr = sIconCache.get(name);
if (DEBUG_ICONS) Log.v(TAG, "Get cached weak drawable ref for "
+ name + ": " + wr);
if (wr != null) { // we have the activity
final Drawable.ConstantState state = wr.get();
if (state != null) {
if (DEBUG_ICONS) {
Log.v(TAG, "Get cached drawable state for " + name + ": " + state);
}
// Note: It's okay here to not use the newDrawable(Resources) variant
// of the API. The ConstantState comes from a drawable that was
// originally created by passing the proper app Resources instance
// which means the state should already contain the proper
// resources specific information (like density.) See
// BitmapDrawable.BitmapState for instance.
return state.newDrawable();
}
// our entry has been purged
sIconCache.remove(name);
}
}
return null;
}
private void putCachedIcon(@NonNull ResourceName name, @NonNull Drawable dr) {
synchronized (sSync) {
sIconCache.put(name, new WeakReference<>(dr.getConstantState()));
if (DEBUG_ICONS) Log.v(TAG, "Added cached drawable state for " + name + ": " + dr);
}
}
static void handlePackageBroadcast(int cmd, String[] pkgList, boolean hasPkgInfo) {
boolean immediateGc = false;
if (cmd == IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE) {
immediateGc = true;
}
if (pkgList != null && (pkgList.length > 0)) {
boolean needCleanup = false;
for (String ssp : pkgList) {
synchronized (sSync) {
for (int i=sIconCache.size()-1; i>=0; i--) {
ResourceName nm = sIconCache.keyAt(i);
if (nm.packageName.equals(ssp)) {
//Log.i(TAG, "Removing cached drawable for " + nm);
sIconCache.removeAt(i);
needCleanup = true;
}
}
for (int i=sStringCache.size()-1; i>=0; i--) {
ResourceName nm = sStringCache.keyAt(i);
if (nm.packageName.equals(ssp)) {
//Log.i(TAG, "Removing cached string for " + nm);
sStringCache.removeAt(i);
needCleanup = true;
}
}
}
}
if (needCleanup || hasPkgInfo) {
if (immediateGc) {
// Schedule an immediate gc.
Runtime.getRuntime().gc();
} else {
ActivityThread.currentActivityThread().scheduleGcIdler();
}
}
}
}
private static final class ResourceName {
final String packageName;
final int iconId;
ResourceName(String _packageName, int _iconId) {
packageName = _packageName;
iconId = _iconId;
}
ResourceName(ApplicationInfo aInfo, int _iconId) {
this(aInfo.packageName, _iconId);
}
ResourceName(ComponentInfo cInfo, int _iconId) {
this(cInfo.applicationInfo.packageName, _iconId);
}
ResourceName(ResolveInfo rInfo, int _iconId) {
this(rInfo.activityInfo.applicationInfo.packageName, _iconId);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResourceName that = (ResourceName) o;
if (iconId != that.iconId) return false;
return !(packageName != null ?
!packageName.equals(that.packageName) : that.packageName != null);
}
@Override
public int hashCode() {
int result;
result = packageName.hashCode();
result = 31 * result + iconId;
return result;
}
@Override
public String toString() {
return "{ResourceName " + packageName + " / " + iconId + "}";
}
}
private CharSequence getCachedString(ResourceName name) {
synchronized (sSync) {
WeakReference<CharSequence> wr = sStringCache.get(name);
if (wr != null) { // we have the activity
CharSequence cs = wr.get();
if (cs != null) {
return cs;
}
// our entry has been purged
sStringCache.remove(name);
}
}
return null;
}
private void putCachedString(ResourceName name, CharSequence cs) {
synchronized (sSync) {
sStringCache.put(name, new WeakReference<CharSequence>(cs));
}
}
@Override
public CharSequence getText(String packageName, @StringRes int resid,
ApplicationInfo appInfo) {
ResourceName name = new ResourceName(packageName, resid);
CharSequence text = getCachedString(name);
if (text != null) {
return text;
}
if (appInfo == null) {
try {
appInfo = getApplicationInfo(packageName, sDefaultFlags);
} catch (NameNotFoundException e) {
return null;
}
}
try {
Resources r = getResourcesForApplication(appInfo);
text = r.getText(resid);
putCachedString(name, text);
return text;
} catch (NameNotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for "
+ appInfo.packageName);
} catch (RuntimeException e) {
// If an exception was thrown, fall through to return
// default icon.
Log.w("PackageManager", "Failure retrieving text 0x"
+ Integer.toHexString(resid) + " in package "
+ packageName, e);
}
return null;
}
@Override
public XmlResourceParser getXml(String packageName, @XmlRes int resid,
ApplicationInfo appInfo) {
if (appInfo == null) {
try {
appInfo = getApplicationInfo(packageName, sDefaultFlags);
} catch (NameNotFoundException e) {
return null;
}
}
try {
Resources r = getResourcesForApplication(appInfo);
return r.getXml(resid);
} catch (RuntimeException e) {
// If an exception was thrown, fall through to return
// default icon.
Log.w("PackageManager", "Failure retrieving xml 0x"
+ Integer.toHexString(resid) + " in package "
+ packageName, e);
} catch (NameNotFoundException e) {
Log.w("PackageManager", "Failure retrieving resources for "
+ appInfo.packageName);
}
return null;
}
@Override
public CharSequence getApplicationLabel(ApplicationInfo info) {
return info.loadLabel(this);
}
@Override
public void installPackage(Uri packageURI, IPackageInstallObserver observer, int flags,
String installerPackageName) {
final VerificationParams verificationParams = new VerificationParams(null, null,
null, VerificationParams.NO_UID, null);
installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
installerPackageName, verificationParams, null);
}
@Override
public void installPackageWithVerification(Uri packageURI, IPackageInstallObserver observer,
int flags, String installerPackageName, Uri verificationURI,
ManifestDigest manifestDigest, ContainerEncryptionParams encryptionParams) {
final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
null, VerificationParams.NO_UID, manifestDigest);
installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
installerPackageName, verificationParams, encryptionParams);
}
@Override
public void installPackageWithVerificationAndEncryption(Uri packageURI,
IPackageInstallObserver observer, int flags, String installerPackageName,
VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
installCommon(packageURI, new LegacyPackageInstallObserver(observer), flags,
installerPackageName, verificationParams, encryptionParams);
}
@Override
public void installPackage(Uri packageURI, PackageInstallObserver observer,
int flags, String installerPackageName) {
final VerificationParams verificationParams = new VerificationParams(null, null,
null, VerificationParams.NO_UID, null);
installCommon(packageURI, observer, flags, installerPackageName, verificationParams, null);
}
@Override
public void installPackageWithVerification(Uri packageURI,
PackageInstallObserver observer, int flags, String installerPackageName,
Uri verificationURI, ManifestDigest manifestDigest,
ContainerEncryptionParams encryptionParams) {
final VerificationParams verificationParams = new VerificationParams(verificationURI, null,
null, VerificationParams.NO_UID, manifestDigest);
installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
encryptionParams);
}
@Override
public void installPackageWithVerificationAndEncryption(Uri packageURI,
PackageInstallObserver observer, int flags, String installerPackageName,
VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
installCommon(packageURI, observer, flags, installerPackageName, verificationParams,
encryptionParams);
}
private void installCommon(Uri packageURI,
PackageInstallObserver observer, int flags, String installerPackageName,
VerificationParams verificationParams, ContainerEncryptionParams encryptionParams) {
if (!"file".equals(packageURI.getScheme())) {
throw new UnsupportedOperationException("Only file:// URIs are supported");
}
if (encryptionParams != null) {
throw new UnsupportedOperationException("ContainerEncryptionParams not supported");
}
final String originPath = packageURI.getPath();
try {
mPM.installPackage(originPath, observer.getBinder(), flags, installerPackageName,
verificationParams, null);
} catch (RemoteException ignored) {
}
}
@Override
public int installExistingPackage(String packageName)
throws NameNotFoundException {
try {
int res = mPM.installExistingPackageAsUser(packageName, UserHandle.myUserId());
if (res == INSTALL_FAILED_INVALID_URI) {
throw new NameNotFoundException("Package " + packageName + " doesn't exist");
}
return res;
} catch (RemoteException e) {
// Should never happen!
throw new NameNotFoundException("Package " + packageName + " doesn't exist");
}
}
@Override
public void verifyPendingInstall(int id, int response) {
try {
mPM.verifyPendingInstall(id, response);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void extendVerificationTimeout(int id, int verificationCodeAtTimeout,
long millisecondsToDelay) {
try {
mPM.extendVerificationTimeout(id, verificationCodeAtTimeout, millisecondsToDelay);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void verifyIntentFilter(int id, int verificationCode, List<String> outFailedDomains) {
try {
mPM.verifyIntentFilter(id, verificationCode, outFailedDomains);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public int getIntentVerificationStatus(String packageName, int userId) {
try {
return mPM.getIntentVerificationStatus(packageName, userId);
} catch (RemoteException e) {
// Should never happen!
return PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED;
}
}
@Override
public boolean updateIntentVerificationStatus(String packageName, int status, int userId) {
try {
return mPM.updateIntentVerificationStatus(packageName, status, userId);
} catch (RemoteException e) {
// Should never happen!
return false;
}
}
@Override
public List<IntentFilterVerificationInfo> getIntentFilterVerifications(String packageName) {
try {
return mPM.getIntentFilterVerifications(packageName);
} catch (RemoteException e) {
// Should never happen!
return null;
}
}
@Override
public List<IntentFilter> getAllIntentFilters(String packageName) {
try {
return mPM.getAllIntentFilters(packageName);
} catch (RemoteException e) {
// Should never happen!
return null;
}
}
@Override
public String getDefaultBrowserPackageName(int userId) {
try {
return mPM.getDefaultBrowserPackageName(userId);
} catch (RemoteException e) {
// Should never happen!
return null;
}
}
@Override
public boolean setDefaultBrowserPackageName(String packageName, int userId) {
try {
return mPM.setDefaultBrowserPackageName(packageName, userId);
} catch (RemoteException e) {
// Should never happen!
return false;
}
}
@Override
public void setInstallerPackageName(String targetPackage,
String installerPackageName) {
try {
mPM.setInstallerPackageName(targetPackage, installerPackageName);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void movePackage(String packageName, IPackageMoveObserver observer, int flags) {
try {
mPM.movePackage(packageName, observer, flags);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
@Override
public void movePackageAndData(String packageName, String volumeUuid,
IPackageMoveObserver observer) {
try {
mPM.movePackageAndData(packageName, volumeUuid, observer);
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
@Override
public String getInstallerPackageName(String packageName) {
try {
return mPM.getInstallerPackageName(packageName);
} catch (RemoteException e) {
// Should never happen!
}
return null;
}
@Override
public void deletePackage(String packageName, IPackageDeleteObserver observer, int flags) {
try {
mPM.deletePackageAsUser(packageName, observer, UserHandle.myUserId(), flags);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void clearApplicationUserData(String packageName,
IPackageDataObserver observer) {
try {
mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void deleteApplicationCacheFiles(String packageName,
IPackageDataObserver observer) {
try {
mPM.deleteApplicationCacheFiles(packageName, observer);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void freeStorageAndNotify(long idealStorageSize, IPackageDataObserver observer) {
try {
mPM.freeStorageAndNotify(idealStorageSize, observer);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void freeStorage(long freeStorageSize, IntentSender pi) {
try {
mPM.freeStorage(freeStorageSize, pi);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void getPackageSizeInfo(String packageName, int userHandle,
IPackageStatsObserver observer) {
try {
mPM.getPackageSizeInfo(packageName, userHandle, observer);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void addPackageToPreferred(String packageName) {
try {
mPM.addPackageToPreferred(packageName);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void removePackageFromPreferred(String packageName) {
try {
mPM.removePackageFromPreferred(packageName);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public List<PackageInfo> getPreferredPackages(int flags) {
try {
return mPM.getPreferredPackages(flags);
} catch (RemoteException e) {
// Should never happen!
}
return new ArrayList<PackageInfo>();
}
@Override
public void addPreferredActivity(IntentFilter filter,
int match, ComponentName[] set, ComponentName activity) {
try {
mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void addPreferredActivity(IntentFilter filter, int match,
ComponentName[] set, ComponentName activity, int userId) {
try {
mPM.addPreferredActivity(filter, match, set, activity, userId);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void replacePreferredActivity(IntentFilter filter,
int match, ComponentName[] set, ComponentName activity) {
try {
mPM.replacePreferredActivity(filter, match, set, activity, UserHandle.myUserId());
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void replacePreferredActivityAsUser(IntentFilter filter,
int match, ComponentName[] set, ComponentName activity,
int userId) {
try {
mPM.replacePreferredActivity(filter, match, set, activity, userId);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public void clearPackagePreferredActivities(String packageName) {
try {
mPM.clearPackagePreferredActivities(packageName);
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public int getPreferredActivities(List<IntentFilter> outFilters,
List<ComponentName> outActivities, String packageName) {
try {
return mPM.getPreferredActivities(outFilters, outActivities, packageName);
} catch (RemoteException e) {
// Should never happen!
}
return 0;
}
@Override
public ComponentName getHomeActivities(List<ResolveInfo> outActivities) {
try {
return mPM.getHomeActivities(outActivities);
} catch (RemoteException e) {
// Should never happen!
}
return null;
}
@Override
public void setComponentEnabledSetting(ComponentName componentName,
int newState, int flags) {
try {
mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public int getComponentEnabledSetting(ComponentName componentName) {
try {
return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
} catch (RemoteException e) {
// Should never happen!
}
return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
}
@Override
public void setApplicationEnabledSetting(String packageName,
int newState, int flags) {
try {
mPM.setApplicationEnabledSetting(packageName, newState, flags,
mContext.getUserId(), mContext.getOpPackageName());
} catch (RemoteException e) {
// Should never happen!
}
}
@Override
public int getApplicationEnabledSetting(String packageName) {
try {
return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
} catch (RemoteException e) {
// Should never happen!
}
return PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
}
@Override
public boolean setApplicationHiddenSettingAsUser(String packageName, boolean hidden,
UserHandle user) {
try {
return mPM.setApplicationHiddenSettingAsUser(packageName, hidden,
user.getIdentifier());
} catch (RemoteException re) {
// Should never happen!
}
return false;
}
@Override
public boolean getApplicationHiddenSettingAsUser(String packageName, UserHandle user) {
try {
return mPM.getApplicationHiddenSettingAsUser(packageName, user.getIdentifier());
} catch (RemoteException re) {
// Should never happen!
}
return false;
}
/** @hide */
@Override
public KeySet getKeySetByAlias(String packageName, String alias) {
Preconditions.checkNotNull(packageName);
Preconditions.checkNotNull(alias);
KeySet ks;
try {
ks = mPM.getKeySetByAlias(packageName, alias);
} catch (RemoteException e) {
return null;
}
return ks;
}
/** @hide */
@Override
public KeySet getSigningKeySet(String packageName) {
Preconditions.checkNotNull(packageName);
KeySet ks;
try {
ks = mPM.getSigningKeySet(packageName);
} catch (RemoteException e) {
return null;
}
return ks;
}
/** @hide */
@Override
public boolean isSignedBy(String packageName, KeySet ks) {
Preconditions.checkNotNull(packageName);
Preconditions.checkNotNull(ks);
try {
return mPM.isPackageSignedByKeySet(packageName, ks);
} catch (RemoteException e) {
return false;
}
}
/** @hide */
@Override
public boolean isSignedByExactly(String packageName, KeySet ks) {
Preconditions.checkNotNull(packageName);
Preconditions.checkNotNull(ks);
try {
return mPM.isPackageSignedByKeySetExactly(packageName, ks);
} catch (RemoteException e) {
return false;
}
}
/**
* @hide
*/
@Override
public VerifierDeviceIdentity getVerifierDeviceIdentity() {
try {
return mPM.getVerifierDeviceIdentity();
} catch (RemoteException e) {
// Should never happen!
}
return null;
}
/**
* @hide
*/
@Override
public boolean isUpgrade() {
try {
return mPM.isUpgrade();
} catch (RemoteException e) {
return false;
}
}
@Override
public PackageInstaller getPackageInstaller() {
synchronized (mLock) {
if (mInstaller == null) {
try {
mInstaller = new PackageInstaller(mContext, this, mPM.getPackageInstaller(),
mContext.getPackageName(), mContext.getUserId());
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
return mInstaller;
}
}
@Override
public boolean isPackageAvailable(String packageName) {
try {
return mPM.isPackageAvailable(packageName, mContext.getUserId());
} catch (RemoteException e) {
throw e.rethrowAsRuntimeException();
}
}
/**
* @hide
*/
@Override
public void addCrossProfileIntentFilter(IntentFilter filter, int sourceUserId, int targetUserId,
int flags) {
try {
mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(),
sourceUserId, targetUserId, flags);
} catch (RemoteException e) {
// Should never happen!
}
}
/**
* @hide
*/
@Override
public void clearCrossProfileIntentFilters(int sourceUserId) {
try {
mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName());
} catch (RemoteException e) {
// Should never happen!
}
}
/**
* @hide
*/
public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
Drawable dr = loadUnbadgedItemIcon(itemInfo, appInfo);
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
return dr;
}
return getUserBadgedIcon(dr, new UserHandle(mContext.getUserId()));
}
/**
* @hide
*/
public Drawable loadUnbadgedItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) {
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
if (bitmap == null) {
return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
}
return new BitmapDrawable(bitmap);
}
Drawable dr = null;
if (itemInfo.packageName != null) {
dr = getDrawable(itemInfo.packageName, itemInfo.icon, appInfo);
}
if (dr == null) {
dr = itemInfo.loadDefaultIcon(this);
}
return dr;
}
private Drawable getBadgedDrawable(Drawable drawable, Drawable badgeDrawable,
Rect badgeLocation, boolean tryBadgeInPlace) {
final int badgedWidth = drawable.getIntrinsicWidth();
final int badgedHeight = drawable.getIntrinsicHeight();
final boolean canBadgeInPlace = tryBadgeInPlace
&& (drawable instanceof BitmapDrawable)
&& ((BitmapDrawable) drawable).getBitmap().isMutable();
final Bitmap bitmap;
if (canBadgeInPlace) {
bitmap = ((BitmapDrawable) drawable).getBitmap();
} else {
bitmap = Bitmap.createBitmap(badgedWidth, badgedHeight, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(bitmap);
if (!canBadgeInPlace) {
drawable.setBounds(0, 0, badgedWidth, badgedHeight);
drawable.draw(canvas);
}
if (badgeLocation != null) {
if (badgeLocation.left < 0 || badgeLocation.top < 0
|| badgeLocation.width() > badgedWidth || badgeLocation.height() > badgedHeight) {
throw new IllegalArgumentException("Badge location " + badgeLocation
+ " not in badged drawable bounds "
+ new Rect(0, 0, badgedWidth, badgedHeight));
}
badgeDrawable.setBounds(0, 0, badgeLocation.width(), badgeLocation.height());
canvas.save();
canvas.translate(badgeLocation.left, badgeLocation.top);
badgeDrawable.draw(canvas);
canvas.restore();
} else {
badgeDrawable.setBounds(0, 0, badgedWidth, badgedHeight);
badgeDrawable.draw(canvas);
}
if (!canBadgeInPlace) {
BitmapDrawable mergedDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
mergedDrawable.setTargetDensity(bitmapDrawable.getBitmap().getDensity());
}
return mergedDrawable;
}
return drawable;
}
private int getBadgeResIdForUser(int userHandle) {
// Return the framework-provided badge.
UserInfo userInfo = getUserIfProfile(userHandle);
if (userInfo != null && userInfo.isManagedProfile()) {
return com.android.internal.R.drawable.ic_corp_icon_badge;
}
return 0;
}
private UserInfo getUserIfProfile(int userHandle) {
List<UserInfo> userProfiles = getUserManager().getProfiles(UserHandle.myUserId());
for (UserInfo user : userProfiles) {
if (user.id == userHandle) {
return user;
}
}
return null;
}
private final ContextImpl mContext;
private final IPackageManager mPM;
private static final Object sSync = new Object();
private static ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>> sIconCache
= new ArrayMap<ResourceName, WeakReference<Drawable.ConstantState>>();
private static ArrayMap<ResourceName, WeakReference<CharSequence>> sStringCache
= new ArrayMap<ResourceName, WeakReference<CharSequence>>();
}
|