Migrate to new ParsedComponents and ParseResult
Removes the massive old ComponentParseUtils in favor of
the new split classes.
Cleans up the parsing code to be uniform, removing the
String[] outError pattern in favor of ParseInput.
Bug: 135203078
Test: atest com.android.server.pm
Change-Id: I584ed37d4715300453dbe760d45d1eb4759b3dd3
diff --git a/services/core/java/android/content/pm/PackageManagerInternal.java b/services/core/java/android/content/pm/PackageManagerInternal.java
index 4ea6370..39a9efb 100644
--- a/services/core/java/android/content/pm/PackageManagerInternal.java
+++ b/services/core/java/android/content/pm/PackageManagerInternal.java
@@ -29,10 +29,7 @@
import android.content.pm.PackageManager.ComponentInfoFlags;
import android.content.pm.PackageManager.PackageInfoFlags;
import android.content.pm.PackageManager.ResolveInfoFlags;
-import com.android.server.pm.parsing.pkg.AndroidPackage;
-
-import android.content.pm.parsing.ComponentParseUtils;
-import android.content.pm.parsing.ComponentParseUtils.ParsedMainComponent;
+import android.content.pm.parsing.component.ParsedMainComponent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.ArrayMap;
@@ -40,6 +37,7 @@
import android.util.SparseArray;
import com.android.server.pm.PackageList;
+import com.android.server.pm.parsing.pkg.AndroidPackage;
import java.io.IOException;
import java.lang.annotation.Retention;
diff --git a/services/core/java/com/android/server/IntentResolver.java b/services/core/java/com/android/server/IntentResolver.java
index 05820d2..7ec2a34 100644
--- a/services/core/java/com/android/server/IntentResolver.java
+++ b/services/core/java/com/android/server/IntentResolver.java
@@ -16,6 +16,7 @@
package com.android.server;
+import android.annotation.NonNull;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
@@ -44,29 +45,30 @@
/**
* {@hide}
*/
-public abstract class IntentResolver<F extends IntentFilter, R extends Object> {
+public abstract class IntentResolver<F, R extends Object> {
final private static String TAG = "IntentResolver";
final private static boolean DEBUG = false;
final private static boolean localLOGV = DEBUG || false;
final private static boolean localVerificationLOGV = DEBUG || false;
public void addFilter(F f) {
+ IntentFilter intentFilter = getIntentFilter(f);
if (localLOGV) {
Slog.v(TAG, "Adding filter: " + f);
- f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
+ intentFilter.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
Slog.v(TAG, " Building Lookup Maps:");
}
mFilters.add(f);
- int numS = register_intent_filter(f, f.schemesIterator(),
+ int numS = register_intent_filter(f, intentFilter.schemesIterator(),
mSchemeToFilter, " Scheme: ");
int numT = register_mime_types(f, " Type: ");
if (numS == 0 && numT == 0) {
- register_intent_filter(f, f.actionsIterator(),
+ register_intent_filter(f, intentFilter.actionsIterator(),
mActionToFilter, " Action: ");
}
if (numT != 0) {
- register_intent_filter(f, f.actionsIterator(),
+ register_intent_filter(f, intentFilter.actionsIterator(),
mTypedActionToFilter, " TypedAction: ");
}
}
@@ -153,7 +155,7 @@
if (cur == null) {
break;
}
- if (filterEquals(cur, matching)) {
+ if (filterEquals(getIntentFilter(cur), matching)) {
if (res == null) {
res = new ArrayList<>();
}
@@ -178,7 +180,7 @@
} else {
ArrayList<F> res = null;
for (F cur : mFilters) {
- if (filterEquals(cur, matching)) {
+ if (filterEquals(getIntentFilter(cur), matching)) {
if (res == null) {
res = new ArrayList<>();
}
@@ -195,21 +197,22 @@
}
protected void removeFilterInternal(F f) {
+ IntentFilter intentFilter = getIntentFilter(f);
if (localLOGV) {
Slog.v(TAG, "Removing filter: " + f);
- f.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
+ intentFilter.dump(new LogPrinter(Log.VERBOSE, TAG, Log.LOG_ID_SYSTEM), " ");
Slog.v(TAG, " Cleaning Lookup Maps:");
}
- int numS = unregister_intent_filter(f, f.schemesIterator(),
+ int numS = unregister_intent_filter(f, intentFilter.schemesIterator(),
mSchemeToFilter, " Scheme: ");
int numT = unregister_mime_types(f, " Type: ");
if (numS == 0 && numT == 0) {
- unregister_intent_filter(f, f.actionsIterator(),
+ unregister_intent_filter(f, intentFilter.actionsIterator(),
mActionToFilter, " Action: ");
}
if (numT != 0) {
- unregister_intent_filter(f, f.actionsIterator(),
+ unregister_intent_filter(f, intentFilter.actionsIterator(),
mTypedActionToFilter, " TypedAction: ");
}
}
@@ -272,7 +275,7 @@
if (printer == null) {
printer = new PrintWriterPrinter(out);
}
- filter.dump(printer, fprefix + " ");
+ getIntentFilter(filter).dump(printer, fprefix + " ");
}
}
}
@@ -527,7 +530,7 @@
* @see android.content.IntentFilter#getAutoVerify()
*/
protected boolean isFilterVerified(F filter) {
- return filter.isVerified();
+ return getIntentFilter(filter).isVerified();
}
/**
@@ -591,7 +594,7 @@
}
private final int register_mime_types(F filter, String prefix) {
- final Iterator<String> i = filter.typesIterator();
+ final Iterator<String> i = getIntentFilter(filter).typesIterator();
if (i == null) {
return 0;
}
@@ -622,7 +625,7 @@
}
private final int unregister_mime_types(F filter, String prefix) {
- final Iterator<String> i = filter.typesIterator();
+ final Iterator<String> i = getIntentFilter(filter).typesIterator();
if (i == null) {
return 0;
}
@@ -762,12 +765,14 @@
}
// Are we verified ?
- if (filter.getAutoVerify()) {
+ IntentFilter intentFilter = getIntentFilter(filter);
+ if (intentFilter.getAutoVerify()) {
if (localVerificationLOGV || debug) {
Slog.v(TAG, " Filter verified: " + isFilterVerified(filter));
- int authorities = filter.countDataAuthorities();
+ int authorities = intentFilter.countDataAuthorities();
for (int z = 0; z < authorities; z++) {
- Slog.v(TAG, " " + filter.getDataAuthority(z).getHost());
+ Slog.v(TAG, " " + intentFilter.getDataAuthority(z)
+ .getHost());
}
}
}
@@ -780,12 +785,12 @@
continue;
}
- match = filter.match(action, resolvedType, scheme, data, categories, TAG);
+ match = intentFilter.match(action, resolvedType, scheme, data, categories, TAG);
if (match >= 0) {
if (debug) Slog.v(TAG, " Filter matched! match=0x" +
Integer.toHexString(match) + " hasDefault="
- + filter.hasCategory(Intent.CATEGORY_DEFAULT));
- if (!defaultOnly || filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
+ + intentFilter.hasCategory(Intent.CATEGORY_DEFAULT));
+ if (!defaultOnly || intentFilter.hasCategory(Intent.CATEGORY_DEFAULT)) {
final R oneResult = newResult(filter, match, userId);
if (debug) Slog.v(TAG, " Created result: " + oneResult);
if (oneResult != null) {
@@ -793,7 +798,7 @@
if (debug) {
dumpFilter(logPrintWriter, " ", filter);
logPrintWriter.flush();
- filter.dump(logPrinter, " ");
+ intentFilter.dump(logPrinter, " ");
}
}
} else {
@@ -875,4 +880,11 @@
* All of the actions that have been registered and specified a MIME type.
*/
private final ArrayMap<String, F[]> mTypedActionToFilter = new ArrayMap<String, F[]>();
+
+ /**
+ * Rather than refactoring the entire class, this allows the input {@link F} to be a type
+ * other than {@link IntentFilter}, transforming it whenever necessary. It is valid to use
+ * {@link IntentFilter} directly as {@link F} and just return {@param input}.
+ */
+ protected abstract IntentFilter getIntentFilter(@NonNull F input);
}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 9082807..6bf5aa3 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1045,6 +1045,11 @@
}
@Override
+ protected IntentFilter getIntentFilter(@NonNull BroadcastFilter input) {
+ return input;
+ }
+
+ @Override
protected BroadcastFilter[] newArray(int size) {
return new BroadcastFilter[size];
}
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index a163fb5..7462f7f 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -98,8 +98,7 @@
import android.content.pm.PackageManagerInternal;
import android.content.pm.PermissionInfo;
import android.content.pm.UserInfo;
-import com.android.server.pm.parsing.pkg.AndroidPackage;
-import android.content.pm.parsing.ComponentParseUtils.ParsedFeature;
+import android.content.pm.parsing.component.ParsedFeature;
import android.database.ContentObserver;
import android.hardware.camera2.CameraDevice.CAMERA_AUDIO_RESTRICTION;
import android.net.Uri;
@@ -156,6 +155,7 @@
import com.android.server.LockGuard;
import com.android.server.SystemServerInitThreadPool;
import com.android.server.pm.PackageList;
+import com.android.server.pm.parsing.pkg.AndroidPackage;
import libcore.util.EmptyArray;
diff --git a/services/core/java/com/android/server/firewall/IntentFirewall.java b/services/core/java/com/android/server/firewall/IntentFirewall.java
index c2af29c..1139d28 100644
--- a/services/core/java/com/android/server/firewall/IntentFirewall.java
+++ b/services/core/java/com/android/server/firewall/IntentFirewall.java
@@ -16,6 +16,7 @@
package com.android.server.firewall;
+import android.annotation.NonNull;
import android.app.AppGlobals;
import android.content.ComponentName;
import android.content.Intent;
@@ -521,6 +522,11 @@
return;
}
+ @Override
+ protected IntentFilter getIntentFilter(@NonNull FirewallIntentFilter input) {
+ return input;
+ }
+
public void queryByComponent(ComponentName componentName, List<Rule> candidateRules) {
Rule[] rules = mRulesByComponent.get(componentName);
if (rules != null) {
diff --git a/services/core/java/com/android/server/pm/AppsFilter.java b/services/core/java/com/android/server/pm/AppsFilter.java
index 57ad35b..1205a33 100644
--- a/services/core/java/com/android/server/pm/AppsFilter.java
+++ b/services/core/java/com/android/server/pm/AppsFilter.java
@@ -26,12 +26,12 @@
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
-import android.content.pm.parsing.ComponentParseUtils;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedComponent;
-import android.content.pm.parsing.ComponentParseUtils.ParsedIntentInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
-import android.content.pm.parsing.ComponentParseUtils.ParsedService;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedComponent;
+import android.content.pm.parsing.component.ParsedInstrumentation;
+import android.content.pm.parsing.component.ParsedIntentInfo;
+import android.content.pm.parsing.component.ParsedProvider;
+import android.content.pm.parsing.component.ParsedService;
import android.os.Binder;
import android.os.Process;
import android.os.Trace;
@@ -261,7 +261,7 @@
private static boolean matchesIntentFilters(Intent intent, AndroidPackage potentialTarget) {
for (int s = ArrayUtils.size(potentialTarget.getServices()) - 1; s >= 0; s--) {
ParsedService service = potentialTarget.getServices().get(s);
- if (!service.exported) {
+ if (!service.isExported()) {
continue;
}
if (matchesAnyFilter(intent, service)) {
@@ -270,7 +270,7 @@
}
for (int a = ArrayUtils.size(potentialTarget.getActivities()) - 1; a >= 0; a--) {
ParsedActivity activity = potentialTarget.getActivities().get(a);
- if (!activity.exported) {
+ if (!activity.isExported()) {
continue;
}
if (matchesAnyFilter(intent, activity)) {
@@ -279,7 +279,7 @@
}
for (int r = ArrayUtils.size(potentialTarget.getReceivers()) - 1; r >= 0; r--) {
ParsedActivity receiver = potentialTarget.getReceivers().get(r);
- if (!receiver.exported) {
+ if (!receiver.isExported()) {
continue;
}
if (matchesAnyFilter(intent, receiver)) {
@@ -289,9 +289,8 @@
return false;
}
- private static boolean matchesAnyFilter(
- Intent intent, ParsedComponent<? extends ParsedIntentInfo> component) {
- List<? extends ParsedIntentInfo> intents = component.intents;
+ private static boolean matchesAnyFilter(Intent intent, ParsedComponent component) {
+ List<ParsedIntentInfo> intents = component.getIntents();
for (int i = ArrayUtils.size(intents) - 1; i >= 0; i--) {
IntentFilter intentFilter = intents.get(i);
if (intentFilter.match(intent.getAction(), intent.getType(), intent.getScheme(),
@@ -673,8 +672,7 @@
String targetName) {
try {
Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "callingPkgInstruments");
- final List<ComponentParseUtils.ParsedInstrumentation> inst =
- callingPkgSetting.pkg.getInstrumentations();
+ final List<ParsedInstrumentation> inst = callingPkgSetting.pkg.getInstrumentations();
for (int i = ArrayUtils.size(inst) - 1; i >= 0; i--) {
if (Objects.equals(inst.get(i).getTargetPackage(), targetName)) {
if (DEBUG_LOGGING) {
diff --git a/services/core/java/com/android/server/pm/ComponentResolver.java b/services/core/java/com/android/server/pm/ComponentResolver.java
index 5e4892c..1f112be 100644
--- a/services/core/java/com/android/server/pm/ComponentResolver.java
+++ b/services/core/java/com/android/server/pm/ComponentResolver.java
@@ -22,12 +22,12 @@
import static com.android.server.pm.PackageManagerService.DEBUG_PACKAGE_SCANNING;
import static com.android.server.pm.PackageManagerService.DEBUG_REMOVE;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
-import android.content.pm.ApplicationInfo;
import android.content.pm.AuxiliaryResolveInfo;
import android.content.pm.InstantAppResolveInfo;
import android.content.pm.PackageManager;
@@ -37,13 +37,12 @@
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedIntentInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProviderIntentInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedService;
-import android.content.pm.parsing.ComponentParseUtils.ParsedServiceIntentInfo;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedComponent;
+import android.content.pm.parsing.component.ParsedIntentInfo;
+import android.content.pm.parsing.component.ParsedMainComponent;
+import android.content.pm.parsing.component.ParsedProvider;
+import android.content.pm.parsing.component.ParsedService;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -191,8 +190,11 @@
* of these during boot as we need to inspect at all of the intent filters on the
* /system partition in order to know which component is the setup wizard. This can
* only ever be non-empty if {@link #mDeferProtectedFilters} is {@code true}.
+ *
+ * This is a pair of component package name to actual filter, because we don't store the
+ * name inside the filter. It's technically independent of the component it's contained in.
*/
- private List<ParsedActivityIntentInfo> mProtectedFilters;
+ private List<Pair<ParsedMainComponent, ParsedIntentInfo>> mProtectedFilters;
ComponentResolver(UserManagerService userManager,
PackageManagerInternal packageManagerInternal,
@@ -354,7 +356,7 @@
continue;
}
- if (safeMode && (pkg.getFlags() & ApplicationInfo.FLAG_SYSTEM) == 0) {
+ if (safeMode && !pkg.isSystem()) {
continue;
}
final ProviderInfo info =
@@ -415,7 +417,7 @@
/** Add all components defined in the given package to the internal structures. */
void addAllComponents(AndroidPackage pkg, boolean chatty) {
- final ArrayList<ParsedActivityIntentInfo> newIntents = new ArrayList<>();
+ final ArrayList<Pair<ParsedActivity, ParsedIntentInfo>> newIntents = new ArrayList<>();
synchronized (mLock) {
addActivitiesLocked(pkg, newIntents, chatty);
addReceiversLocked(pkg, chatty);
@@ -428,14 +430,14 @@
PACKAGE_SETUP_WIZARD, UserHandle.USER_SYSTEM));
for (int i = newIntents.size() - 1; i >= 0; --i) {
- final ParsedActivityIntentInfo intentInfo = newIntents.get(i);
+ final Pair<ParsedActivity, ParsedIntentInfo> pair = newIntents.get(i);
final PackageSetting disabledPkgSetting = (PackageSetting) sPackageManagerInternal
- .getDisabledSystemPackage(intentInfo.getPackageName());
+ .getDisabledSystemPackage(pair.first.getPackageName());
final AndroidPackage disabledPkg =
disabledPkgSetting == null ? null : disabledPkgSetting.pkg;
final List<ParsedActivity> systemActivities =
disabledPkg != null ? disabledPkg.getActivities() : null;
- adjustPriority(systemActivities, intentInfo, setupWizardPackage);
+ adjustPriority(systemActivities, pair.first, pair.second, setupWizardPackage);
}
}
@@ -459,7 +461,8 @@
if (mProtectedFilters == null || mProtectedFilters.size() == 0) {
return;
}
- final List<ParsedActivityIntentInfo> protectedFilters = mProtectedFilters;
+ final List<Pair<ParsedMainComponent, ParsedIntentInfo>> protectedFilters =
+ mProtectedFilters;
mProtectedFilters = null;
// expect single setupwizard package
@@ -472,13 +475,17 @@
+ " All protected intents capped to priority 0");
}
for (int i = protectedFilters.size() - 1; i >= 0; --i) {
- final ParsedActivityIntentInfo filter = protectedFilters.get(i);
- if (filter.getPackageName().equals(setupWizardPackage)) {
+ final Pair<ParsedMainComponent, ParsedIntentInfo> pair = protectedFilters.get(i);
+ ParsedMainComponent component = pair.first;
+ ParsedIntentInfo filter = pair.second;
+ String packageName = component.getPackageName();
+ String className = component.getClassName();
+ if (packageName.equals(setupWizardPackage)) {
if (DEBUG_FILTERS) {
Slog.i(TAG, "Found setup wizard;"
+ " allow priority " + filter.getPriority() + ";"
- + " package: " + filter.getPackageName()
- + " activity: " + filter.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " priority: " + filter.getPriority());
}
// skip setup wizard; allow it to keep the high priority filter
@@ -486,8 +493,8 @@
}
if (DEBUG_FILTERS) {
Slog.i(TAG, "Protected action; cap priority to 0;"
- + " package: " + filter.getPackageName()
- + " activity: " + filter.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + filter.getPriority());
}
filter.setPriority(0);
@@ -540,7 +547,7 @@
printedSomething = true;
}
pw.print(" ");
- ComponentName.printShortString(pw, p.getPackageName(), p.className);
+ ComponentName.printShortString(pw, p.getPackageName(), p.getName());
pw.println(":");
pw.print(" ");
pw.println(p.toString());
@@ -575,24 +582,11 @@
if (dumpState.onTitlePrinted()) pw.println();
pw.println("Service permissions:");
- final Iterator<ParsedServiceIntentInfo> filterIterator = mServices.filterIterator();
+ final Iterator<Pair<ParsedService, ParsedIntentInfo>> filterIterator =
+ mServices.filterIterator();
while (filterIterator.hasNext()) {
- final ParsedServiceIntentInfo info = filterIterator.next();
-
- ParsedService service = null;
-
- AndroidPackage pkg = sPackageManagerInternal.getPackage(info.getPackageName());
- if (pkg != null && pkg.getServices() != null) {
- for (ParsedService parsedService : pkg.getServices()) {
- if (Objects.equals(parsedService.className, info.getClassName())) {
- service = parsedService;
- }
- }
- }
-
- if (service == null) {
- continue;
- }
+ final Pair<ParsedService, ParsedIntentInfo> pair = filterIterator.next();
+ ParsedService service = pair.first;
final String permission = service.getPermission();
if (permission != null) {
@@ -606,7 +600,7 @@
@GuardedBy("mLock")
private void addActivitiesLocked(AndroidPackage pkg,
- List<ParsedActivityIntentInfo> newIntents, boolean chatty) {
+ List<Pair<ParsedActivity, ParsedIntentInfo>> newIntents, boolean chatty) {
final int activitiesSize = ArrayUtils.size(pkg.getActivities());
StringBuilder r = null;
for (int i = 0; i < activitiesSize; i++) {
@@ -736,8 +730,8 @@
* <em>WARNING</em> for performance reasons, the passed in intentList WILL BE
* MODIFIED. Do not pass in a list that should not be changed.
*/
- private static <T> void getIntentListSubset(List<ParsedActivityIntentInfo> intentList,
- Function<ParsedActivityIntentInfo, Iterator<T>> generator, Iterator<T> searchIterator) {
+ private static <T> void getIntentListSubset(List<ParsedIntentInfo> intentList,
+ Function<ParsedIntentInfo, Iterator<T>> generator, Iterator<T> searchIterator) {
// loop through the set of actions; every one must be found in the intent filter
while (searchIterator.hasNext()) {
// we must have at least one filter in the list to consider a match
@@ -748,9 +742,9 @@
final T searchAction = searchIterator.next();
// loop through the set of intent filters
- final Iterator<ParsedActivityIntentInfo> intentIter = intentList.iterator();
+ final Iterator<ParsedIntentInfo> intentIter = intentList.iterator();
while (intentIter.hasNext()) {
- final ParsedActivityIntentInfo intentInfo = intentIter.next();
+ final ParsedIntentInfo intentInfo = intentIter.next();
boolean selectionFound = false;
// loop through the intent filter's selection criteria; at least one
@@ -773,7 +767,7 @@
}
}
- private static boolean isProtectedAction(ParsedActivityIntentInfo filter) {
+ private static boolean isProtectedAction(ParsedIntentInfo filter) {
final Iterator<String> actionsIter = filter.actionsIterator();
while (actionsIter != null && actionsIter.hasNext()) {
final String filterAction = actionsIter.next();
@@ -793,14 +787,14 @@
if (sysActivity.getName().equals(activityInfo.getName())) {
return sysActivity;
}
- if (sysActivity.getName().equals(activityInfo.targetActivity)) {
+ if (sysActivity.getName().equals(activityInfo.getTargetActivity())) {
return sysActivity;
}
- if (sysActivity.targetActivity != null) {
- if (sysActivity.targetActivity.equals(activityInfo.getName())) {
+ if (sysActivity.getTargetActivity() != null) {
+ if (sysActivity.getTargetActivity().equals(activityInfo.getName())) {
return sysActivity;
}
- if (sysActivity.targetActivity.equals(activityInfo.targetActivity)) {
+ if (sysActivity.getTargetActivity().equals(activityInfo.getTargetActivity())) {
return sysActivity;
}
}
@@ -821,23 +815,24 @@
* <em>NOTE:</em> There is one exception. For security reasons, the setup wizard is
* allowed to obtain any priority on any action.
*/
- private void adjustPriority(List<ParsedActivity> systemActivities,
- ParsedActivityIntentInfo intent, String setupWizardPackage) {
+ private void adjustPriority(List<ParsedActivity> systemActivities, ParsedActivity activity,
+ ParsedIntentInfo intent, String setupWizardPackage) {
// nothing to do; priority is fine as-is
if (intent.getPriority() <= 0) {
return;
}
- AndroidPackage pkg = sPackageManagerInternal.getPackage(intent.getPackageName());
+ String packageName = activity.getPackageName();
+ AndroidPackage pkg = sPackageManagerInternal.getPackage(packageName);
- final boolean privilegedApp =
- ((pkg.getPrivateFlags() & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0);
+ final boolean privilegedApp = pkg.isPrivileged();
+ String className = activity.getClassName();
if (!privilegedApp) {
// non-privileged applications can never define a priority >0
if (DEBUG_FILTERS) {
Slog.i(TAG, "Non-privileged app; cap priority to 0;"
- + " package: " + pkg.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
intent.setPriority(0);
@@ -858,11 +853,11 @@
if (mProtectedFilters == null) {
mProtectedFilters = new ArrayList<>();
}
- mProtectedFilters.add(intent);
+ mProtectedFilters.add(Pair.create(activity, intent));
if (DEBUG_FILTERS) {
Slog.i(TAG, "Protected action; save for later;"
- + " package: " + pkg.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
return;
@@ -871,12 +866,12 @@
Slog.i(TAG, "No setup wizard;"
+ " All protected intents capped to priority 0");
}
- if (intent.getPackageName().equals(setupWizardPackage)) {
+ if (packageName.equals(setupWizardPackage)) {
if (DEBUG_FILTERS) {
Slog.i(TAG, "Found setup wizard;"
+ " allow priority " + intent.getPriority() + ";"
- + " package: " + intent.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " priority: " + intent.getPriority());
}
// setup wizard gets whatever it wants
@@ -884,8 +879,8 @@
}
if (DEBUG_FILTERS) {
Slog.i(TAG, "Protected action; cap priority to 0;"
- + " package: " + intent.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
intent.setPriority(0);
@@ -898,27 +893,13 @@
// privileged app unbundled update ... try to find the same activity
- ParsedActivity foundActivity = null;
- ParsedActivity activity = null;
-
- if (pkg.getActivities() != null) {
- for (ParsedActivity parsedProvider : pkg.getActivities()) {
- if (Objects.equals(parsedProvider.className, intent.getClassName())) {
- activity = parsedProvider;
- }
- }
- }
-
- if (activity != null) {
- foundActivity = findMatchingActivity(systemActivities, activity);
- }
-
+ ParsedActivity foundActivity = findMatchingActivity(systemActivities, activity);
if (foundActivity == null) {
// this is a new activity; it cannot obtain >0 priority
if (DEBUG_FILTERS) {
Slog.i(TAG, "New activity; cap priority to 0;"
- + " package: " + pkg.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
intent.setPriority(0);
@@ -928,8 +909,8 @@
// found activity, now check for filter equivalence
// a shallow copy is enough; we modify the list, not its contents
- final List<ParsedActivityIntentInfo> intentListCopy =
- new ArrayList<>(foundActivity.intents);
+ final List<ParsedIntentInfo> intentListCopy =
+ new ArrayList<>(foundActivity.getIntents());
// find matching action subsets
final Iterator<String> actionsIterator = intent.actionsIterator();
@@ -939,8 +920,8 @@
// no more intents to match; we're not equivalent
if (DEBUG_FILTERS) {
Slog.i(TAG, "Mismatched action; cap priority to 0;"
- + " package: " + pkg.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
intent.setPriority(0);
@@ -957,8 +938,8 @@
// no more intents to match; we're not equivalent
if (DEBUG_FILTERS) {
Slog.i(TAG, "Mismatched category; cap priority to 0;"
- + " package: " + pkg.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
intent.setPriority(0);
@@ -974,8 +955,8 @@
// no more intents to match; we're not equivalent
if (DEBUG_FILTERS) {
Slog.i(TAG, "Mismatched scheme; cap priority to 0;"
- + " package: " + pkg.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
intent.setPriority(0);
@@ -993,8 +974,8 @@
// no more intents to match; we're not equivalent
if (DEBUG_FILTERS) {
Slog.i(TAG, "Mismatched authority; cap priority to 0;"
- + " package: " + pkg.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
intent.setPriority(0);
@@ -1011,8 +992,8 @@
if (DEBUG_FILTERS) {
Slog.i(TAG, "Found matching filter(s);"
+ " cap priority to " + cappedPriority + ";"
- + " package: " + pkg.getPackageName()
- + " activity: " + intent.getClassName()
+ + " package: " + packageName
+ + " activity: " + className
+ " origPrio: " + intent.getPriority());
}
intent.setPriority(cappedPriority);
@@ -1146,31 +1127,34 @@
}
}
- private abstract static class MimeGroupsAwareIntentResolver<F extends ParsedIntentInfo, R>
+ private abstract static class MimeGroupsAwareIntentResolver<F extends Pair<?
+ extends ParsedComponent, ParsedIntentInfo>, R>
extends IntentResolver<F, R> {
private ArrayMap<String, F[]> mMimeGroupToFilter = new ArrayMap<>();
private boolean mIsUpdatingMimeGroup = false;
@Override
public void addFilter(F f) {
+ IntentFilter intentFilter = getIntentFilter(f);
applyMimeGroups(f);
super.addFilter(f);
if (!mIsUpdatingMimeGroup) {
- register_intent_filter(f, f.mimeGroupsIterator(), mMimeGroupToFilter,
+ register_intent_filter(f, intentFilter.mimeGroupsIterator(), mMimeGroupToFilter,
" MimeGroup: ");
}
}
@Override
protected void removeFilterInternal(F f) {
+ IntentFilter intentFilter = getIntentFilter(f);
if (!mIsUpdatingMimeGroup) {
- unregister_intent_filter(f, f.mimeGroupsIterator(), mMimeGroupToFilter,
+ unregister_intent_filter(f, intentFilter.mimeGroupsIterator(), mMimeGroupToFilter,
" MimeGroup: ");
}
super.removeFilterInternal(f);
- f.clearDynamicDataTypes();
+ intentFilter.clearDynamicDataTypes();
}
/**
@@ -1197,10 +1181,11 @@
return hasChanges;
}
- private boolean updateFilter(F filter) {
+ private boolean updateFilter(F f) {
+ IntentFilter filter = getIntentFilter(f);
List<String> oldTypes = filter.dataTypes();
- removeFilter(filter);
- addFilter(filter);
+ removeFilter(f);
+ addFilter(f);
List<String> newTypes = filter.dataTypes();
return !equalLists(oldTypes, newTypes);
}
@@ -1221,12 +1206,12 @@
return first.equals(second);
}
- private void applyMimeGroups(F filter) {
- String packageName = filter.getPackageName();
+ private void applyMimeGroups(F f) {
+ IntentFilter filter = getIntentFilter(f);
for (int i = filter.countMimeGroups() - 1; i >= 0; i--) {
- List<String> mimeTypes = sPackageManagerInternal.getMimeGroup(packageName,
- filter.getMimeGroup(i));
+ List<String> mimeTypes = sPackageManagerInternal.getMimeGroup(
+ f.first.getPackageName(), filter.getMimeGroup(i));
for (int typeIndex = mimeTypes.size() - 1; typeIndex >= 0; typeIndex--) {
String mimeType = mimeTypes.get(typeIndex);
@@ -1244,7 +1229,7 @@
}
private static class ActivityIntentResolver
- extends MimeGroupsAwareIntentResolver<ParsedActivityIntentInfo, ResolveInfo> {
+ extends MimeGroupsAwareIntentResolver<Pair<ParsedActivity, ParsedIntentInfo>, ResolveInfo> {
@Override
public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
@@ -1277,15 +1262,18 @@
mFlags = flags;
final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
final int activitiesSize = packageActivities.size();
- ArrayList<ParsedActivityIntentInfo[]> listCut = new ArrayList<>(activitiesSize);
+ ArrayList<Pair<ParsedActivity, ParsedIntentInfo>[]> listCut =
+ new ArrayList<>(activitiesSize);
- List<ParsedActivityIntentInfo> intentFilters;
+ List<ParsedIntentInfo> intentFilters;
for (int i = 0; i < activitiesSize; ++i) {
- intentFilters = packageActivities.get(i).intents;
- if (intentFilters != null && intentFilters.size() > 0) {
- ParsedActivityIntentInfo[] array =
- new ParsedActivityIntentInfo[intentFilters.size()];
- intentFilters.toArray(array);
+ ParsedActivity activity = packageActivities.get(i);
+ intentFilters = activity.getIntents();
+ if (!intentFilters.isEmpty()) {
+ Pair<ParsedActivity, ParsedIntentInfo>[] array = newArray(intentFilters.size());
+ for (int arrayIndex = 0; arrayIndex < intentFilters.size(); arrayIndex++) {
+ array[arrayIndex] = Pair.create(activity, intentFilters.get(arrayIndex));
+ }
listCut.add(array);
}
}
@@ -1293,22 +1281,17 @@
}
private void addActivity(ParsedActivity a, String type,
- List<ParsedActivityIntentInfo> newIntents) {
+ List<Pair<ParsedActivity, ParsedIntentInfo>> newIntents) {
mActivities.put(a.getComponentName(), a);
if (DEBUG_SHOW_INFO) {
- final CharSequence label = a.nonLocalizedLabel != null
- ? a.nonLocalizedLabel
- : a.getName();
- Log.v(TAG, " " + type + " " + label + ":");
- }
- if (DEBUG_SHOW_INFO) {
+ Log.v(TAG, " " + type + ":");
Log.v(TAG, " Class=" + a.getName());
}
- final int intentsSize = a.intents.size();
+ final int intentsSize = a.getIntents().size();
for (int j = 0; j < intentsSize; j++) {
- ParsedActivityIntentInfo intent = a.intents.get(j);
+ ParsedIntentInfo intent = a.getIntents().get(j);
if (newIntents != null && "activity".equals(type)) {
- newIntents.add(intent);
+ newIntents.add(Pair.create(a, intent));
}
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
@@ -1317,36 +1300,34 @@
if (!intent.debugCheck()) {
Log.w(TAG, "==> For Activity " + a.getName());
}
- addFilter(intent);
+ addFilter(Pair.create(a, intent));
}
}
private void removeActivity(ParsedActivity a, String type) {
mActivities.remove(a.getComponentName());
if (DEBUG_SHOW_INFO) {
- Log.v(TAG, " " + type + " "
- + (a.nonLocalizedLabel != null ? a.nonLocalizedLabel
- : a.getName()) + ":");
+ Log.v(TAG, " " + type + ":");
Log.v(TAG, " Class=" + a.getName());
}
- final int intentsSize = a.intents.size();
+ final int intentsSize = a.getIntents().size();
for (int j = 0; j < intentsSize; j++) {
- ParsedActivityIntentInfo intent = a.intents.get(j);
+ ParsedIntentInfo intent = a.getIntents().get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
- removeFilter(intent);
+ removeFilter(Pair.create(a, intent));
}
}
@Override
- protected boolean allowFilterResult(
- ParsedActivityIntentInfo filter, List<ResolveInfo> dest) {
+ protected boolean allowFilterResult(Pair<ParsedActivity, ParsedIntentInfo> filter,
+ List<ResolveInfo> dest) {
for (int i = dest.size() - 1; i >= 0; --i) {
ActivityInfo destAi = dest.get(i).activityInfo;
- if (Objects.equals(destAi.name, filter.getClassName())
- && Objects.equals(destAi.packageName, filter.getPackageName())) {
+ if (Objects.equals(destAi.name, filter.first.getName())
+ && Objects.equals(destAi.packageName, filter.first.getPackageName())) {
return false;
}
}
@@ -1354,39 +1335,23 @@
}
@Override
- protected ParsedActivityIntentInfo[] newArray(int size) {
- return new ParsedActivityIntentInfo[size];
+ protected Pair<ParsedActivity, ParsedIntentInfo>[] newArray(int size) {
+ //noinspection unchecked
+ return (Pair<ParsedActivity, ParsedIntentInfo>[]) new Pair<?, ?>[size];
}
@Override
- protected boolean isFilterStopped(ParsedActivityIntentInfo filter, int userId) {
- if (!sUserManager.exists(userId)) return true;
-
- AndroidPackage pkg = sPackageManagerInternal.getPackage(filter.getPackageName());
- if (pkg == null) {
- return false;
- }
-
- PackageSetting ps = (PackageSetting) sPackageManagerInternal.getPackageSetting(
- filter.getPackageName());
- if (ps == null) {
- return false;
- }
-
- // System apps are never considered stopped for purposes of
- // filtering, because there may be no way for the user to
- // actually re-launch them.
- return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0
- && ps.getStopped(userId);
+ protected boolean isFilterStopped(Pair<ParsedActivity, ParsedIntentInfo> filter, int userId) {
+ return ComponentResolver.isFilterStopped(filter, userId);
}
@Override
protected boolean isPackageForFilter(String packageName,
- ParsedActivityIntentInfo info) {
- return packageName.equals(info.getPackageName());
+ Pair<ParsedActivity, ParsedIntentInfo> info) {
+ return packageName.equals(info.first.getPackageName());
}
- private void log(String reason, ParsedActivityIntentInfo info, int match,
+ private void log(String reason, ParsedIntentInfo info, int match,
int userId) {
Slog.w(TAG, reason
+ "; match: "
@@ -1396,8 +1361,11 @@
}
@Override
- protected ResolveInfo newResult(ParsedActivityIntentInfo info,
+ protected ResolveInfo newResult(Pair<ParsedActivity, ParsedIntentInfo> pair,
int match, int userId) {
+ ParsedActivity activity = pair.first;
+ ParsedIntentInfo info = pair.second;
+
if (!sUserManager.exists(userId)) {
if (DEBUG) {
log("User doesn't exist", info, match, userId);
@@ -1405,27 +1373,11 @@
return null;
}
- ParsedActivity activity = null;
-
- AndroidPackage pkg = sPackageManagerInternal.getPackage(info.getPackageName());
+ AndroidPackage pkg = sPackageManagerInternal.getPackage(activity.getPackageName());
if (pkg == null) {
return null;
}
- // TODO(b/135203078): Consider more efficient ways of doing this.
- List<ParsedActivity> activities = getResolveList(pkg);
- if (activities != null) {
- for (ParsedActivity parsedActivity : activities) {
- if (Objects.equals(parsedActivity.className, info.getClassName())) {
- activity = parsedActivity;
- }
- }
- }
-
- if (activity == null) {
- return null;
- }
-
if (!sPackageManagerInternal.isEnabledAndMatches(activity, mFlags, userId)) {
if (DEBUG) {
log("!PackageManagerInternal.isEnabledAndMatches; mFlags="
@@ -1435,7 +1387,7 @@
return null;
}
PackageSetting ps = (PackageSetting) sPackageManagerInternal.getPackageSetting(
- info.getPackageName());
+ activity.getPackageName());
if (ps == null) {
if (DEBUG) {
log("info.activity.owner.mExtras == null", info, match, userId);
@@ -1443,8 +1395,8 @@
return null;
}
final PackageUserState userState = ps.readUserState(userId);
- ActivityInfo ai =
- PackageInfoUtils.generateActivityInfo(pkg, activity, mFlags, userState, userId);
+ ActivityInfo ai = PackageInfoUtils.generateActivityInfo(pkg, activity, mFlags,
+ userState, userId);
if (ai == null) {
if (DEBUG) {
log("Failed to create ActivityInfo based on " + activity, info, match,
@@ -1507,15 +1459,15 @@
//System.out.println("Result: " + res.activityInfo.className +
// " = " + res.priority);
res.match = match;
- res.isDefault = info.hasDefault;
- res.labelRes = info.labelRes;
- res.nonLocalizedLabel = info.nonLocalizedLabel;
+ res.isDefault = info.isHasDefault();
+ res.labelRes = info.getLabelRes();
+ res.nonLocalizedLabel = info.getNonLocalizedLabel();
if (sPackageManagerInternal.userNeedsBadging(userId)) {
res.noResourceId = true;
} else {
- res.icon = info.icon;
+ res.icon = info.getIcon();
}
- res.iconResourceId = info.icon;
+ res.iconResourceId = info.getIcon();
res.system = res.activityInfo.applicationInfo.isSystemApp();
res.isInstantAppAvailable = userState.instantApp;
return res;
@@ -1528,43 +1480,44 @@
@Override
protected void dumpFilter(PrintWriter out, String prefix,
- ParsedActivityIntentInfo filter) {
- ParsedActivity activity = null;
-
- AndroidPackage pkg = sPackageManagerInternal.getPackage(filter.getPackageName());
- if (pkg != null && pkg.getActivities() != null) {
- for (ParsedActivity parsedActivity : pkg.getActivities()) {
- if (Objects.equals(parsedActivity.className, filter.getClassName())) {
- activity = parsedActivity;
- }
- }
- }
+ Pair<ParsedActivity, ParsedIntentInfo> pair) {
+ ParsedActivity activity = pair.first;
+ ParsedIntentInfo filter = pair.second;
out.print(prefix);
out.print(Integer.toHexString(System.identityHashCode(activity)));
out.print(' ');
- ComponentName.printShortString(out, filter.getPackageName(), filter.getClassName());
+ ComponentName.printShortString(out, activity.getPackageName(),
+ activity.getClassName());
out.print(" filter ");
out.println(Integer.toHexString(System.identityHashCode(filter)));
}
@Override
- protected Object filterToLabel(ParsedActivityIntentInfo filter) {
+ protected Object filterToLabel(Pair<ParsedActivity, ParsedIntentInfo> filter) {
return filter;
}
protected void dumpFilterLabel(PrintWriter out, String prefix, Object label, int count) {
- ParsedActivityIntentInfo activity = (ParsedActivityIntentInfo) label;
+ @SuppressWarnings("unchecked") Pair<ParsedActivity, ParsedIntentInfo> pair =
+ (Pair<ParsedActivity, ParsedIntentInfo>) label;
out.print(prefix);
- out.print(Integer.toHexString(System.identityHashCode(activity)));
+ out.print(Integer.toHexString(System.identityHashCode(pair.first)));
out.print(' ');
- ComponentName.printShortString(out, activity.getPackageName(), activity.getClassName());
+ ComponentName.printShortString(out, pair.first.getPackageName(),
+ pair.first.getClassName());
if (count > 1) {
out.print(" ("); out.print(count); out.print(" filters)");
}
out.println();
}
+ @Override
+ protected IntentFilter getIntentFilter(
+ @NonNull Pair<ParsedActivity, ParsedIntentInfo> input) {
+ return input.second;
+ }
+
protected List<ParsedActivity> getResolveList(AndroidPackage pkg) {
return pkg.getActivities();
}
@@ -1586,7 +1539,7 @@
}
private static final class ProviderIntentResolver
- extends MimeGroupsAwareIntentResolver<ParsedProviderIntentInfo, ResolveInfo> {
+ extends MimeGroupsAwareIntentResolver<Pair<ParsedProvider, ParsedIntentInfo>, ResolveInfo> {
@Override
public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
boolean defaultOnly, int userId) {
@@ -1618,15 +1571,18 @@
mFlags = flags;
final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
final int providersSize = packageProviders.size();
- ArrayList<ParsedProviderIntentInfo[]> listCut = new ArrayList<>(providersSize);
+ ArrayList<Pair<ParsedProvider, ParsedIntentInfo>[]> listCut =
+ new ArrayList<>(providersSize);
- List<ParsedProviderIntentInfo> intentFilters;
+ List<ParsedIntentInfo> intentFilters;
for (int i = 0; i < providersSize; ++i) {
- intentFilters = packageProviders.get(i).getIntents();
- if (intentFilters != null && intentFilters.size() > 0) {
- ParsedProviderIntentInfo[] array =
- new ParsedProviderIntentInfo[intentFilters.size()];
- intentFilters.toArray(array);
+ ParsedProvider provider = packageProviders.get(i);
+ intentFilters = provider.getIntents();
+ if (!intentFilters.isEmpty()) {
+ Pair<ParsedProvider, ParsedIntentInfo>[] array = newArray(intentFilters.size());
+ for (int arrayIndex = 0; arrayIndex < intentFilters.size(); arrayIndex++) {
+ array[arrayIndex] = Pair.create(provider, intentFilters.get(arrayIndex));
+ }
listCut.add(array);
}
}
@@ -1641,17 +1597,13 @@
mProviders.put(p.getComponentName(), p);
if (DEBUG_SHOW_INFO) {
- Log.v(TAG, " "
- + (p.nonLocalizedLabel != null
- ? p.nonLocalizedLabel
- : p.getName())
- + ":");
+ Log.v(TAG, " provider:");
Log.v(TAG, " Class=" + p.getName());
}
final int intentsSize = p.getIntents().size();
int j;
for (j = 0; j < intentsSize; j++) {
- ParsedProviderIntentInfo intent = p.getIntents().get(j);
+ ParsedIntentInfo intent = p.getIntents().get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
@@ -1659,37 +1611,35 @@
if (!intent.debugCheck()) {
Log.w(TAG, "==> For Provider " + p.getName());
}
- addFilter(intent);
+ addFilter(Pair.create(p, intent));
}
}
void removeProvider(ParsedProvider p) {
mProviders.remove(p.getComponentName());
if (DEBUG_SHOW_INFO) {
- Log.v(TAG, " " + (p.nonLocalizedLabel != null
- ? p.nonLocalizedLabel
- : p.getName()) + ":");
+ Log.v(TAG, " provider:");
Log.v(TAG, " Class=" + p.getName());
}
final int intentsSize = p.getIntents().size();
int j;
for (j = 0; j < intentsSize; j++) {
- ParsedProviderIntentInfo intent = p.getIntents().get(j);
+ ParsedIntentInfo intent = p.getIntents().get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
- removeFilter(intent);
+ removeFilter(Pair.create(p, intent));
}
}
@Override
- protected boolean allowFilterResult(
- ParsedProviderIntentInfo filter, List<ResolveInfo> dest) {
+ protected boolean allowFilterResult(Pair<ParsedProvider, ParsedIntentInfo> filter,
+ List<ResolveInfo> dest) {
for (int i = dest.size() - 1; i >= 0; i--) {
ProviderInfo destPi = dest.get(i).providerInfo;
- if (Objects.equals(destPi.name, filter.getClassName())
- && Objects.equals(destPi.packageName, filter.getPackageName())) {
+ if (Objects.equals(destPi.name, filter.first.getClassName())
+ && Objects.equals(destPi.packageName, filter.first.getPackageName())) {
return false;
}
}
@@ -1697,59 +1647,35 @@
}
@Override
- protected ParsedProviderIntentInfo[] newArray(int size) {
- return new ParsedProviderIntentInfo[size];
+ protected Pair<ParsedProvider, ParsedIntentInfo>[] newArray(int size) {
+ //noinspection unchecked
+ return (Pair<ParsedProvider, ParsedIntentInfo>[]) new Pair<?, ?>[size];
}
@Override
- protected boolean isFilterStopped(ParsedProviderIntentInfo filter, int userId) {
- if (!sUserManager.exists(userId)) {
- return true;
- }
-
- AndroidPackage pkg = sPackageManagerInternal.getPackage(filter.getPackageName());
- if (pkg == null) {
- return false;
- }
-
- PackageSetting ps = (PackageSetting) sPackageManagerInternal.getPackageSetting(
- filter.getPackageName());
- if (ps == null) {
- return false;
- }
-
- // System apps are never considered stopped for purposes of
- // filtering, because there may be no way for the user to
- // actually re-launch them.
- return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0
- && ps.getStopped(userId);
+ protected boolean isFilterStopped(Pair<ParsedProvider, ParsedIntentInfo> filter,
+ int userId) {
+ return ComponentResolver.isFilterStopped(filter, userId);
}
@Override
protected boolean isPackageForFilter(String packageName,
- ParsedProviderIntentInfo info) {
- return packageName.equals(info.getPackageName());
+ Pair<ParsedProvider, ParsedIntentInfo> info) {
+ return packageName.equals(info.first.getPackageName());
}
@Override
- protected ResolveInfo newResult(ParsedProviderIntentInfo filter,
+ protected ResolveInfo newResult(Pair<ParsedProvider, ParsedIntentInfo> pair,
int match, int userId) {
if (!sUserManager.exists(userId)) {
return null;
}
- ParsedProvider provider = null;
+ ParsedProvider provider = pair.first;
+ ParsedIntentInfo filter = pair.second;
- AndroidPackage pkg = sPackageManagerInternal.getPackage(filter.getPackageName());
- if (pkg != null && pkg.getProviders() != null) {
- for (ParsedProvider parsedProvider : pkg.getProviders()) {
- if (Objects.equals(parsedProvider.className, filter.getClassName())) {
- provider = parsedProvider;
- }
- }
- }
-
- if (provider == null) {
+ AndroidPackage pkg = sPackageManagerInternal.getPackage(provider.getPackageName());
+ if (pkg == null) {
return null;
}
@@ -1758,7 +1684,7 @@
}
PackageSetting ps = (PackageSetting) sPackageManagerInternal.getPackageSetting(
- filter.getPackageName());
+ provider.getPackageName());
if (ps == null) {
return null;
}
@@ -1780,8 +1706,8 @@
if (userState.instantApp && ps.isUpdateAvailable()) {
return null;
}
- ProviderInfo pi = PackageInfoUtils.generateProviderInfo(pkg, provider,
- mFlags, userState, userId);
+ ProviderInfo pi = PackageInfoUtils.generateProviderInfo(pkg, provider, mFlags,
+ userState, userId);
if (pi == null) {
return null;
}
@@ -1794,10 +1720,10 @@
// TODO(b/135203078): This field was unwritten and does nothing
// res.preferredOrder = pkg.getPreferredOrder();
res.match = match;
- res.isDefault = filter.hasDefault;
- res.labelRes = filter.labelRes;
- res.nonLocalizedLabel = filter.nonLocalizedLabel;
- res.icon = filter.icon;
+ res.isDefault = filter.isHasDefault();
+ res.labelRes = filter.getLabelRes();
+ res.nonLocalizedLabel = filter.getNonLocalizedLabel();
+ res.icon = filter.getIcon();
res.system = res.providerInfo.applicationInfo.isSystemApp();
return res;
}
@@ -1809,37 +1735,31 @@
@Override
protected void dumpFilter(PrintWriter out, String prefix,
- ParsedProviderIntentInfo filter) {
- ParsedProvider provider = null;
-
- AndroidPackage pkg = sPackageManagerInternal.getPackage(filter.getPackageName());
- if (pkg != null && pkg.getProviders() != null) {
- for (ParsedProvider parsedProvider : pkg.getProviders()) {
- if (Objects.equals(parsedProvider.className, filter.getClassName())) {
- provider = parsedProvider;
- }
- }
- }
+ Pair<ParsedProvider, ParsedIntentInfo> pair) {
+ ParsedProvider provider = pair.first;
+ ParsedIntentInfo filter = pair.second;
out.print(prefix);
out.print(Integer.toHexString(System.identityHashCode(provider)));
out.print(' ');
- ComponentName.printShortString(out, filter.getPackageName(), filter.getClassName());
+ ComponentName.printShortString(out, provider.getPackageName(), provider.getClassName());
out.print(" filter ");
out.println(Integer.toHexString(System.identityHashCode(filter)));
}
@Override
- protected Object filterToLabel(ParsedProviderIntentInfo filter) {
+ protected Object filterToLabel(Pair<ParsedProvider, ParsedIntentInfo> filter) {
return filter;
}
protected void dumpFilterLabel(PrintWriter out, String prefix, Object label, int count) {
- final ParsedProviderIntentInfo provider = (ParsedProviderIntentInfo) label;
+ @SuppressWarnings("unchecked") final Pair<ParsedProvider, ParsedIntentInfo> pair =
+ (Pair<ParsedProvider, ParsedIntentInfo>) label;
out.print(prefix);
- out.print(Integer.toHexString(System.identityHashCode(provider)));
+ out.print(Integer.toHexString(System.identityHashCode(pair.first)));
out.print(' ');
- ComponentName.printShortString(out, provider.getPackageName(), provider.getClassName());
+ ComponentName.printShortString(out, pair.first.getPackageName(),
+ pair.first.getClassName());
if (count > 1) {
out.print(" (");
out.print(count);
@@ -1848,12 +1768,18 @@
out.println();
}
+ @Override
+ protected IntentFilter getIntentFilter(
+ @NonNull Pair<ParsedProvider, ParsedIntentInfo> input) {
+ return input.second;
+ }
+
private final ArrayMap<ComponentName, ParsedProvider> mProviders = new ArrayMap<>();
private int mFlags;
}
private static final class ServiceIntentResolver
- extends MimeGroupsAwareIntentResolver<ParsedServiceIntentInfo, ResolveInfo> {
+ extends MimeGroupsAwareIntentResolver<Pair<ParsedService, ParsedIntentInfo>, ResolveInfo> {
@Override
public List<ResolveInfo> queryIntent(Intent intent, String resolvedType,
boolean defaultOnly, int userId) {
@@ -1879,15 +1805,18 @@
mFlags = flags;
final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0;
final int servicesSize = packageServices.size();
- ArrayList<ParsedServiceIntentInfo[]> listCut = new ArrayList<>(servicesSize);
+ ArrayList<Pair<ParsedService, ParsedIntentInfo>[]> listCut =
+ new ArrayList<>(servicesSize);
- List<ParsedServiceIntentInfo> intentFilters;
+ List<ParsedIntentInfo> intentFilters;
for (int i = 0; i < servicesSize; ++i) {
- intentFilters = packageServices.get(i).intents;
- if (intentFilters != null && intentFilters.size() > 0) {
- ParsedServiceIntentInfo[] array =
- new ParsedServiceIntentInfo[intentFilters.size()];
- intentFilters.toArray(array);
+ ParsedService service = packageServices.get(i);
+ intentFilters = service.getIntents();
+ if (intentFilters.size() > 0) {
+ Pair<ParsedService, ParsedIntentInfo>[] array = newArray(intentFilters.size());
+ for (int arrayIndex = 0; arrayIndex < intentFilters.size(); arrayIndex++) {
+ array[arrayIndex] = Pair.create(service, intentFilters.get(arrayIndex));
+ }
listCut.add(array);
}
}
@@ -1897,15 +1826,13 @@
void addService(ParsedService s) {
mServices.put(s.getComponentName(), s);
if (DEBUG_SHOW_INFO) {
- Log.v(TAG, " "
- + (s.nonLocalizedLabel != null
- ? s.nonLocalizedLabel : s.getName()) + ":");
+ Log.v(TAG, " service:");
Log.v(TAG, " Class=" + s.getName());
}
- final int intentsSize = s.intents.size();
+ final int intentsSize = s.getIntents().size();
int j;
for (j = 0; j < intentsSize; j++) {
- ParsedServiceIntentInfo intent = s.intents.get(j);
+ ParsedIntentInfo intent = s.getIntents().get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
@@ -1913,36 +1840,35 @@
if (!intent.debugCheck()) {
Log.w(TAG, "==> For Service " + s.getName());
}
- addFilter(intent);
+ addFilter(Pair.create(s, intent));
}
}
void removeService(ParsedService s) {
mServices.remove(s.getComponentName());
if (DEBUG_SHOW_INFO) {
- Log.v(TAG, " " + (s.nonLocalizedLabel != null
- ? s.nonLocalizedLabel : s.getName()) + ":");
+ Log.v(TAG, " service:");
Log.v(TAG, " Class=" + s.getName());
}
- final int intentsSize = s.intents.size();
+ final int intentsSize = s.getIntents().size();
int j;
for (j = 0; j < intentsSize; j++) {
- ParsedServiceIntentInfo intent = s.intents.get(j);
+ ParsedIntentInfo intent = s.getIntents().get(j);
if (DEBUG_SHOW_INFO) {
Log.v(TAG, " IntentFilter:");
intent.dump(new LogPrinter(Log.VERBOSE, TAG), " ");
}
- removeFilter(intent);
+ removeFilter(Pair.create(s, intent));
}
}
@Override
- protected boolean allowFilterResult(
- ParsedServiceIntentInfo filter, List<ResolveInfo> dest) {
+ protected boolean allowFilterResult(Pair<ParsedService, ParsedIntentInfo> filter,
+ List<ResolveInfo> dest) {
for (int i = dest.size() - 1; i >= 0; --i) {
ServiceInfo destAi = dest.get(i).serviceInfo;
- if (Objects.equals(destAi.name, filter.getClassName())
- && Objects.equals(destAi.packageName, filter.getPackageName())) {
+ if (Objects.equals(destAi.name, filter.first.getClassName())
+ && Objects.equals(destAi.packageName, filter.first.getPackageName())) {
return false;
}
}
@@ -1950,55 +1876,32 @@
}
@Override
- protected ParsedServiceIntentInfo[] newArray(int size) {
- return new ParsedServiceIntentInfo[size];
+ protected Pair<ParsedService, ParsedIntentInfo>[] newArray(int size) {
+ //noinspection unchecked
+ return (Pair<ParsedService, ParsedIntentInfo>[]) new Pair<?, ?>[size];
}
@Override
- protected boolean isFilterStopped(ParsedServiceIntentInfo filter, int userId) {
- if (!sUserManager.exists(userId)) return true;
-
- AndroidPackage pkg = sPackageManagerInternal.getPackage(filter.getPackageName());
- if (pkg == null) {
- return false;
- }
-
- PackageSetting ps = (PackageSetting) sPackageManagerInternal.getPackageSetting(
- filter.getPackageName());
- if (ps == null) {
- return false;
- }
-
- // System apps are never considered stopped for purposes of
- // filtering, because there may be no way for the user to
- // actually re-launch them.
- return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) == 0
- && ps.getStopped(userId);
+ protected boolean isFilterStopped(Pair<ParsedService, ParsedIntentInfo> filter, int userId) {
+ return ComponentResolver.isFilterStopped(filter, userId);
}
@Override
protected boolean isPackageForFilter(String packageName,
- ParsedServiceIntentInfo info) {
- return packageName.equals(info.getPackageName());
+ Pair<ParsedService, ParsedIntentInfo> info) {
+ return packageName.equals(info.first.getPackageName());
}
@Override
- protected ResolveInfo newResult(ParsedServiceIntentInfo filter,
- int match, int userId) {
+ protected ResolveInfo newResult(Pair<ParsedService, ParsedIntentInfo> pair, int match,
+ int userId) {
if (!sUserManager.exists(userId)) return null;
- ParsedService service = null;
+ ParsedService service = pair.first;
+ ParsedIntentInfo filter = pair.second;
- AndroidPackage pkg = sPackageManagerInternal.getPackage(filter.getPackageName());
- if (pkg != null && pkg.getServices() != null) {
- for (ParsedService parsedService : pkg.getServices()) {
- if (Objects.equals(parsedService.className, filter.getClassName())) {
- service = parsedService;
- }
- }
- }
-
- if (service == null) {
+ AndroidPackage pkg = sPackageManagerInternal.getPackage(service.getPackageName());
+ if (pkg == null) {
return null;
}
@@ -2007,7 +1910,7 @@
}
PackageSetting ps = (PackageSetting) sPackageManagerInternal.getPackageSetting(
- filter.getPackageName());
+ service.getPackageName());
if (ps == null) {
return null;
}
@@ -2043,10 +1946,10 @@
// TODO(b/135203078): This field was unwritten and does nothing
// res.preferredOrder = pkg.getPreferredOrder();
res.match = match;
- res.isDefault = filter.hasDefault;
- res.labelRes = filter.labelRes;
- res.nonLocalizedLabel = filter.nonLocalizedLabel;
- res.icon = filter.icon;
+ res.isDefault = filter.isHasDefault();
+ res.labelRes = filter.getLabelRes();
+ res.nonLocalizedLabel = filter.getNonLocalizedLabel();
+ res.icon = filter.getIcon();
res.system = res.serviceInfo.applicationInfo.isSystemApp();
return res;
}
@@ -2058,25 +1961,17 @@
@Override
protected void dumpFilter(PrintWriter out, String prefix,
- ParsedServiceIntentInfo filter) {
- ParsedService service = null;
-
- AndroidPackage pkg = sPackageManagerInternal.getPackage(filter.getPackageName());
- if (pkg != null && pkg.getServices() != null) {
- for (ParsedService parsedService : pkg.getServices()) {
- if (Objects.equals(parsedService.className, filter.getClassName())) {
- service = parsedService;
- }
- }
- }
+ Pair<ParsedService, ParsedIntentInfo> pair) {
+ ParsedService service = pair.first;
+ ParsedIntentInfo filter = pair.second;
out.print(prefix);
out.print(Integer.toHexString(System.identityHashCode(service)));
out.print(' ');
- ComponentName.printShortString(out, filter.getPackageName(), filter.getClassName());
+ ComponentName.printShortString(out, service.getPackageName(), service.getClassName());
out.print(" filter ");
out.print(Integer.toHexString(System.identityHashCode(filter)));
- if (service != null && service.getPermission() != null) {
+ if (service.getPermission() != null) {
out.print(" permission "); out.println(service.getPermission());
} else {
out.println();
@@ -2084,22 +1979,30 @@
}
@Override
- protected Object filterToLabel(ParsedServiceIntentInfo filter) {
+ protected Object filterToLabel(Pair<ParsedService, ParsedIntentInfo> filter) {
return filter;
}
protected void dumpFilterLabel(PrintWriter out, String prefix, Object label, int count) {
- final ParsedServiceIntentInfo service = (ParsedServiceIntentInfo) label;
+ @SuppressWarnings("unchecked") final Pair<ParsedService, ParsedIntentInfo> pair =
+ (Pair<ParsedService, ParsedIntentInfo>) label;
out.print(prefix);
- out.print(Integer.toHexString(System.identityHashCode(service)));
+ out.print(Integer.toHexString(System.identityHashCode(pair.first)));
out.print(' ');
- ComponentName.printShortString(out, service.getPackageName(), service.getClassName());
+ ComponentName.printShortString(out, pair.first.getPackageName(),
+ pair.first.getClassName());
if (count > 1) {
out.print(" ("); out.print(count); out.print(" filters)");
}
out.println();
}
+ @Override
+ protected IntentFilter getIntentFilter(
+ @NonNull Pair<ParsedService, ParsedIntentInfo> input) {
+ return input.second;
+ }
+
// Keys are String (activity class name), values are Activity.
private final ArrayMap<ComponentName, ParsedService> mServices = new ArrayMap<>();
private int mFlags;
@@ -2186,11 +2089,40 @@
i--;
}
}
+
+ @Override
+ protected IntentFilter getIntentFilter(
+ @NonNull AuxiliaryResolveInfo.AuxiliaryFilter input) {
+ return input;
+ }
+ }
+
+ private static boolean isFilterStopped(Pair<? extends ParsedComponent, ParsedIntentInfo> pair,
+ int userId) {
+ if (!sUserManager.exists(userId)) {
+ return true;
+ }
+
+ AndroidPackage pkg = sPackageManagerInternal.getPackage(pair.first.getPackageName());
+ if (pkg == null) {
+ return false;
+ }
+
+ PackageSetting ps = (PackageSetting) sPackageManagerInternal.getPackageSetting(
+ pair.first.getPackageName());
+ if (ps == null) {
+ return false;
+ }
+
+ // System apps are never considered stopped for purposes of
+ // filtering, because there may be no way for the user to
+ // actually re-launch them.
+ return !ps.isSystem() && ps.getStopped(userId);
}
/** Generic to create an {@link Iterator} for a data type */
static class IterGenerator<E> {
- public Iterator<E> generate(ParsedActivityIntentInfo info) {
+ public Iterator<E> generate(ParsedIntentInfo info) {
return null;
}
}
@@ -2198,7 +2130,7 @@
/** Create an {@link Iterator} for intent actions */
static class ActionIterGenerator extends IterGenerator<String> {
@Override
- public Iterator<String> generate(ParsedActivityIntentInfo info) {
+ public Iterator<String> generate(ParsedIntentInfo info) {
return info.actionsIterator();
}
}
@@ -2206,7 +2138,7 @@
/** Create an {@link Iterator} for intent categories */
static class CategoriesIterGenerator extends IterGenerator<String> {
@Override
- public Iterator<String> generate(ParsedActivityIntentInfo info) {
+ public Iterator<String> generate(ParsedIntentInfo info) {
return info.categoriesIterator();
}
}
@@ -2214,7 +2146,7 @@
/** Create an {@link Iterator} for intent schemes */
static class SchemesIterGenerator extends IterGenerator<String> {
@Override
- public Iterator<String> generate(ParsedActivityIntentInfo info) {
+ public Iterator<String> generate(ParsedIntentInfo info) {
return info.schemesIterator();
}
}
@@ -2222,7 +2154,7 @@
/** Create an {@link Iterator} for intent authorities */
static class AuthoritiesIterGenerator extends IterGenerator<IntentFilter.AuthorityEntry> {
@Override
- public Iterator<IntentFilter.AuthorityEntry> generate(ParsedActivityIntentInfo info) {
+ public Iterator<IntentFilter.AuthorityEntry> generate(ParsedIntentInfo info) {
return info.authoritiesIterator();
}
}
diff --git a/services/core/java/com/android/server/pm/CrossProfileIntentResolver.java b/services/core/java/com/android/server/pm/CrossProfileIntentResolver.java
index 0e0096d..8e6b89a 100644
--- a/services/core/java/com/android/server/pm/CrossProfileIntentResolver.java
+++ b/services/core/java/com/android/server/pm/CrossProfileIntentResolver.java
@@ -18,6 +18,9 @@
package com.android.server.pm;
+import android.annotation.NonNull;
+import android.content.IntentFilter;
+
import com.android.server.IntentResolver;
import java.util.List;
@@ -40,4 +43,9 @@
protected void sortResults(List<CrossProfileIntentFilter> results) {
//We don't sort the results
}
+
+ @Override
+ protected IntentFilter getIntentFilter(@NonNull CrossProfileIntentFilter input) {
+ return input;
+ }
}
diff --git a/services/core/java/com/android/server/pm/IntentFilterVerificationState.java b/services/core/java/com/android/server/pm/IntentFilterVerificationState.java
index c97d85d..9dc545a 100644
--- a/services/core/java/com/android/server/pm/IntentFilterVerificationState.java
+++ b/services/core/java/com/android/server/pm/IntentFilterVerificationState.java
@@ -17,7 +17,7 @@
package com.android.server.pm;
import android.content.pm.PackageManager;
-import android.content.pm.parsing.ComponentParseUtils;
+import android.content.pm.parsing.component.ParsedIntentInfo;
import android.util.ArraySet;
import android.util.Slog;
@@ -35,7 +35,7 @@
private int mState;
- private ArrayList<ComponentParseUtils.ParsedActivityIntentInfo> mFilters = new ArrayList<>();
+ private ArrayList<ParsedIntentInfo> mFilters = new ArrayList<>();
private ArraySet<String> mHosts = new ArraySet<>();
private int mUserId;
@@ -66,7 +66,7 @@
setState(STATE_VERIFICATION_PENDING);
}
- public ArrayList<ComponentParseUtils.ParsedActivityIntentInfo> getFilters() {
+ public ArrayList<ParsedIntentInfo> getFilters() {
return mFilters;
}
@@ -123,7 +123,7 @@
return false;
}
- public void addFilter(ComponentParseUtils.ParsedActivityIntentInfo filter) {
+ public void addFilter(ParsedIntentInfo filter) {
mFilters.add(filter);
mHosts.addAll(filter.getHostsList());
}
diff --git a/services/core/java/com/android/server/pm/PackageAbiHelperImpl.java b/services/core/java/com/android/server/pm/PackageAbiHelperImpl.java
index 5041abb..e136613 100644
--- a/services/core/java/com/android/server/pm/PackageAbiHelperImpl.java
+++ b/services/core/java/com/android/server/pm/PackageAbiHelperImpl.java
@@ -274,7 +274,7 @@
// ABI that's higher on the list, i.e, a device that's configured to prefer
// 64 bit apps will see a 64 bit primary ABI,
- if ((pkg.getFlags() & ApplicationInfo.FLAG_MULTIARCH) == 0) {
+ if (!pkg.isMultiArch()) {
Slog.e(PackageManagerService.TAG,
"Package " + pkg + " has multiple bundled libs, but is not multiarch.");
}
@@ -305,7 +305,7 @@
pkg.isUpdatedSystemApp());
// We shouldn't attempt to extract libs from system app when it was not updated.
- if (PackageManagerService.isSystemApp(pkg) && !pkg.isUpdatedSystemApp()) {
+ if (pkg.isSystem() && !pkg.isUpdatedSystemApp()) {
extractLibs = false;
}
@@ -330,7 +330,7 @@
// Null out the abis so that they can be recalculated.
primaryCpuAbi = null;
secondaryCpuAbi = null;
- if ((pkg.getFlags() & ApplicationInfo.FLAG_MULTIARCH) != 0) {
+ if (pkg.isMultiArch()) {
// Warn if we've set an abiOverride for multi-lib packages..
// By definition, we need to copy both 32 and 64 bit libraries for
// such packages.
diff --git a/services/core/java/com/android/server/pm/PackageDexOptimizer.java b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
index 1ae9b5c..b1b1497 100644
--- a/services/core/java/com/android/server/pm/PackageDexOptimizer.java
+++ b/services/core/java/com/android/server/pm/PackageDexOptimizer.java
@@ -113,7 +113,7 @@
static boolean canOptimizePackage(AndroidPackage pkg) {
// We do not dexopt a package with no code.
- if ((pkg.getFlags() & ApplicationInfo.FLAG_HAS_CODE) == 0) {
+ if (!pkg.isHasCode()) {
return false;
}
@@ -174,7 +174,7 @@
// For each code path in the package, this array contains the class loader context that
// needs to be passed to dexopt in order to ensure correct optimizations.
boolean[] pathsWithCode = new boolean[paths.size()];
- pathsWithCode[0] = (pkg.getFlags() & ApplicationInfo.FLAG_HAS_CODE) != 0;
+ pathsWithCode[0] = pkg.isHasCode();
for (int i = 1; i < paths.size(); i++) {
pathsWithCode[i] = (pkg.getSplitFlags()[i - 1] & ApplicationInfo.FLAG_HAS_CODE) != 0;
}
@@ -563,8 +563,7 @@
// PackageDexOptimizer#canOptimizePackage or PackageManagerService#getOptimizablePackages
// but that would have the downside of possibly producing a big odex files which would
// be ignored anyway.
- boolean vmSafeModeOrDebuggable = ((pkg.getFlags() & ApplicationInfo.FLAG_VM_SAFE_MODE) != 0)
- || ((pkg.getFlags() & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
+ boolean vmSafeModeOrDebuggable = pkg.isVmSafeMode() || pkg.isDebuggable();
if (vmSafeModeOrDebuggable) {
return getSafeModeCompilerFilter(targetCompilerFilter);
@@ -584,13 +583,13 @@
}
private int getDexFlags(ApplicationInfo info, String compilerFilter, DexoptOptions options) {
- return getDexFlags(info.flags, info.getHiddenApiEnforcementPolicy(),
- info.splitDependencies, info.requestsIsolatedSplitLoading(), compilerFilter,
- options);
+ return getDexFlags((info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0,
+ info.getHiddenApiEnforcementPolicy(), info.splitDependencies,
+ info.requestsIsolatedSplitLoading(), compilerFilter, options);
}
- private int getDexFlags(AndroidPackage pkg, String compilerFilter,
- DexoptOptions options) {
- return getDexFlags(pkg.getFlags(), AndroidPackageUtils.getHiddenApiEnforcementPolicy(pkg),
+ private int getDexFlags(AndroidPackage pkg, String compilerFilter, DexoptOptions options) {
+ return getDexFlags(pkg.isDebuggable(),
+ AndroidPackageUtils.getHiddenApiEnforcementPolicy(pkg),
pkg.getSplitDependencies(), pkg.isIsolatedSplitLoading(), compilerFilter,
options);
}
@@ -599,10 +598,9 @@
* Computes the dex flags that needs to be pass to installd for the given package and compiler
* filter.
*/
- private int getDexFlags(int flags, int hiddenApiEnforcementPolicy,
+ private int getDexFlags(boolean debuggable, int hiddenApiEnforcementPolicy,
SparseArray<int[]> splitDependencies, boolean requestsIsolatedSplitLoading,
String compilerFilter, DexoptOptions options) {
- boolean debuggable = (flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
// Profile guide compiled oat files should not be public unles they are based
// on profiles from dex metadata archives.
// The flag isDexoptInstallWithDexMetadata applies only on installs when we know that
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index d9cb212..a66e696 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -209,16 +209,17 @@
import android.content.pm.dex.ArtManager;
import android.content.pm.dex.DexMetadataHelper;
import android.content.pm.dex.IArtManager;
-import android.content.pm.parsing.ComponentParseUtils;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation;
-import android.content.pm.parsing.ComponentParseUtils.ParsedMainComponent;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
-import android.content.pm.parsing.ComponentParseUtils.ParsedService;
+import android.content.pm.parsing.PackageInfoWithoutStateUtils;
import android.content.pm.parsing.ParsingPackageRead;
import android.content.pm.parsing.ParsingPackageUtils;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedInstrumentation;
+import android.content.pm.parsing.component.ParsedIntentInfo;
+import android.content.pm.parsing.component.ParsedMainComponent;
+import android.content.pm.parsing.component.ParsedPermission;
+import android.content.pm.parsing.component.ParsedProcess;
+import android.content.pm.parsing.component.ParsedProvider;
+import android.content.pm.parsing.component.ParsedService;
import android.content.res.Resources;
import android.content.rollback.IRollbackManager;
import android.database.ContentObserver;
@@ -1083,7 +1084,7 @@
boolean mResolverReplaced = false;
private final @Nullable ComponentName mIntentFilterVerifierComponent;
- private final @Nullable IntentFilterVerifier<ParsedActivityIntentInfo> mIntentFilterVerifier;
+ private final @Nullable IntentFilterVerifier<ParsedIntentInfo> mIntentFilterVerifier;
private int mIntentFilterVerificationToken = 0;
@@ -1144,7 +1145,7 @@
void receiveVerificationResponse(int verificationId);
}
- private class IntentVerifierProxy implements IntentFilterVerifier<ParsedActivityIntentInfo> {
+ private class IntentVerifierProxy implements IntentFilterVerifier<ParsedIntentInfo> {
private Context mContext;
private ComponentName mIntentFilterVerifierComponent;
private ArrayList<Integer> mCurrentIntentFilterVerifications = new ArrayList<>();
@@ -1169,11 +1170,11 @@
String packageName = ivs.getPackageName();
- ArrayList<ParsedActivityIntentInfo> filters = ivs.getFilters();
+ ArrayList<ParsedIntentInfo> filters = ivs.getFilters();
final int filterCount = filters.size();
ArraySet<String> domainsSet = new ArraySet<>();
for (int m=0; m<filterCount; m++) {
- ParsedActivityIntentInfo filter = filters.get(m);
+ ParsedIntentInfo filter = filters.get(m);
domainsSet.addAll(filter.getHostsList());
}
synchronized (mLock) {
@@ -1225,14 +1226,14 @@
final boolean verified = ivs.isVerified();
- ArrayList<ParsedActivityIntentInfo> filters = ivs.getFilters();
+ ArrayList<ParsedIntentInfo> filters = ivs.getFilters();
final int count = filters.size();
if (DEBUG_DOMAIN_VERIFICATION) {
Slog.i(TAG, "Received verification response " + verificationId
+ " for " + count + " filters, verified=" + verified);
}
for (int n=0; n<count; n++) {
- ParsedActivityIntentInfo filter = filters.get(n);
+ ParsedIntentInfo filter = filters.get(n);
filter.setVerified(verified);
if (DEBUG_DOMAIN_VERIFICATION) Slog.d(TAG, "IntentFilter " + filter.toString()
@@ -1345,7 +1346,7 @@
@Override
public boolean addOneIntentFilterVerification(int verifierUid, int userId, int verificationId,
- ParsedActivityIntentInfo filter, String packageName) {
+ ParsedIntentInfo filter, String packageName) {
if (!hasValidDomains(filter)) {
return false;
}
@@ -1374,7 +1375,7 @@
}
}
- private static boolean hasValidDomains(ParsedActivityIntentInfo filter) {
+ private static boolean hasValidDomains(ParsedIntentInfo filter) {
return filter.hasCategory(Intent.CATEGORY_BROWSABLE)
&& (filter.hasDataScheme(IntentFilter.SCHEME_HTTP) ||
filter.hasDataScheme(IntentFilter.SCHEME_HTTPS));
@@ -2150,7 +2151,7 @@
null /*package*/, null /*extras*/, 0 /*flags*/,
packageName /*targetPackage*/,
null /*finishedReceiver*/, updateUserIds, instantUserIds);
- } else if (launchedForRestore && !isSystemApp(res.pkg)) {
+ } else if (launchedForRestore && !res.pkg.isSystem()) {
// First-install and we did a restore, so we're responsible for the
// first-launch broadcast.
if (DEBUG_BACKUP) {
@@ -2162,14 +2163,14 @@
}
// Send broadcast package appeared if external for all users
- if (isExternal(res.pkg)) {
+ if (res.pkg.isExternalStorage()) {
if (!update) {
final StorageManager storage = mInjector.getStorageManager();
VolumeInfo volume =
storage.findVolumeByUuid(
res.pkg.getStorageUuid().toString());
int packageExternalStorageType =
- getPackageExternalStorageType(volume, isExternal(res.pkg));
+ getPackageExternalStorageType(volume, res.pkg.isExternalStorage());
// If the package was installed externally, log it.
if (packageExternalStorageType != StorageEnums.UNKNOWN) {
FrameworkStatsLog.write(
@@ -4011,15 +4012,13 @@
}
ArraySet<String> domains = null;
- if (pkg.getActivities() != null) {
- for (ParsedActivity a : pkg.getActivities()) {
- for (ParsedActivityIntentInfo filter : a.intents) {
- if (hasValidDomains(filter)) {
- if (domains == null) {
- domains = new ArraySet<>();
- }
- domains.addAll(filter.getHostsList());
+ for (ParsedActivity a : pkg.getActivities()) {
+ for (ParsedIntentInfo filter : a.getIntents()) {
+ if (hasValidDomains(filter)) {
+ if (domains == null) {
+ domains = new ArraySet<>();
}
+ domains.addAll(filter.getHostsList());
}
}
}
@@ -4290,7 +4289,7 @@
}
AndroidPackage p = mPackages.get(packageName);
- if (matchFactoryOnly && p != null && !isSystemApp(p)) {
+ if (matchFactoryOnly && p != null && !p.isSystem()) {
return null;
}
if (DEBUG_PACKAGE_INFO)
@@ -4345,9 +4344,9 @@
return false;
}
final boolean visibleToInstantApp =
- (activity.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0;
+ (activity.getFlags() & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0;
final boolean explicitlyVisibleToInstantApp =
- (activity.flags & ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP) == 0;
+ (activity.getFlags() & ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP) == 0;
return visibleToInstantApp && explicitlyVisibleToInstantApp;
} else if (type == TYPE_RECEIVER) {
final ParsedActivity activity = mComponentResolver.getReceiver(component);
@@ -4355,20 +4354,18 @@
return false;
}
final boolean visibleToInstantApp =
- (activity.flags & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0;
+ (activity.getFlags() & ActivityInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0;
final boolean explicitlyVisibleToInstantApp =
- (activity.flags & ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP) == 0;
+ (activity.getFlags() & ActivityInfo.FLAG_IMPLICITLY_VISIBLE_TO_INSTANT_APP) == 0;
return visibleToInstantApp && !explicitlyVisibleToInstantApp;
} else if (type == TYPE_SERVICE) {
final ParsedService service = mComponentResolver.getService(component);
return service != null
- ? (service.flags & ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0
- : false;
+ && (service.getFlags() & ServiceInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0;
} else if (type == TYPE_PROVIDER) {
final ParsedProvider provider = mComponentResolver.getProvider(component);
return provider != null
- ? (provider.getFlags() & ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0
- : false;
+ && (provider.getFlags() & ProviderInfo.FLAG_VISIBLE_TO_INSTANT_APP) != 0;
} else if (type == TYPE_UNKNOWN) {
return isComponentVisibleToInstantApp(component);
}
@@ -5141,8 +5138,8 @@
ps, callingUid, component, TYPE_ACTIVITY, callingUserId)) {
return false;
}
- for (int i=0; i<a.intents.size(); i++) {
- if (a.intents.get(i).match(intent.getAction(), resolvedType, intent.getScheme(),
+ for (int i=0; i< a.getIntents().size(); i++) {
+ if (a.getIntents().get(i).match(intent.getAction(), resolvedType, intent.getScheme(),
intent.getData(), intent.getCategories(), TAG) >= 0) {
return true;
}
@@ -8452,8 +8449,8 @@
final boolean matchesAware = ((flags & MATCH_DIRECT_BOOT_AWARE) != 0)
&& p.isDirectBootAware();
- if ((p.getFlags() & ApplicationInfo.FLAG_PERSISTENT) != 0
- && (!mSafeMode || isSystemApp(p))
+ if (p.isPersistent()
+ && (!mSafeMode || p.isSystem())
&& (matchesUnaware || matchesAware)) {
PackageSetting ps = mSettings.mPackages.get(p.getPackageName());
if (ps != null) {
@@ -9243,7 +9240,7 @@
boolean useProfileForDexopt = false;
- if ((isFirstBoot() || isDeviceUpgrading()) && isSystemApp(pkg)) {
+ if ((isFirstBoot() || isDeviceUpgrading()) && pkg.isSystem()) {
// Copy over initial preopt profiles since we won't get any JIT samples for methods
// that are already compiled.
File profileFile = new File(getPrebuildProfilePath(pkg));
@@ -10649,8 +10646,7 @@
/** Returns {@code true} if the package has been renamed. Otherwise, {@code false}. */
private static boolean isPackageRenamed(@NonNull AndroidPackage pkg,
@Nullable String renamedPkgName) {
- return pkg.getOriginalPackages() != null
- && pkg.getOriginalPackages().contains(renamedPkgName);
+ return pkg.getOriginalPackages().contains(renamedPkgName);
}
/**
@@ -10702,8 +10698,7 @@
*/
private static void ensurePackageRenamed(@NonNull ParsedPackage parsedPackage,
@NonNull String renamedPackageName) {
- if (parsedPackage.getOriginalPackages() == null
- || !parsedPackage.getOriginalPackages().contains(renamedPackageName)
+ if (!parsedPackage.getOriginalPackages().contains(renamedPackageName)
|| parsedPackage.getPackageName().equals(renamedPackageName)) {
return;
}
@@ -10754,6 +10749,8 @@
/**
* Sets the enabled state of components configured through {@link SystemConfig}.
* This modifies the {@link PackageSetting} object.
+ *
+ * TODO(b/135203078): Move this to package parsing
**/
static void configurePackageComponents(AndroidPackage pkg) {
final ArrayMap<String, Boolean> componentsEnabledStates = SystemConfig.getInstance()
@@ -10764,7 +10761,7 @@
for (int i = ArrayUtils.size(pkg.getActivities()) - 1; i >= 0; i--) {
final ParsedActivity component = pkg.getActivities().get(i);
- final Boolean enabled = componentsEnabledStates.get(component.className);
+ final Boolean enabled = componentsEnabledStates.get(component.getName());
if (enabled != null) {
component.setEnabled(enabled);
}
@@ -10772,7 +10769,7 @@
for (int i = ArrayUtils.size(pkg.getReceivers()) - 1; i >= 0; i--) {
final ParsedActivity component = pkg.getReceivers().get(i);
- final Boolean enabled = componentsEnabledStates.get(component.className);
+ final Boolean enabled = componentsEnabledStates.get(component.getName());
if (enabled != null) {
component.setEnabled(enabled);
}
@@ -10780,7 +10777,7 @@
for (int i = ArrayUtils.size(pkg.getProviders()) - 1; i >= 0; i--) {
final ParsedProvider component = pkg.getProviders().get(i);
- final Boolean enabled = componentsEnabledStates.get(component.className);
+ final Boolean enabled = componentsEnabledStates.get(component.getName());
if (enabled != null) {
component.setEnabled(enabled);
}
@@ -10788,7 +10785,7 @@
for (int i = ArrayUtils.size(pkg.getServices()) - 1; i >= 0; i--) {
final ParsedService component = pkg.getServices().get(i);
- final Boolean enabled = componentsEnabledStates.get(component.className);
+ final Boolean enabled = componentsEnabledStates.get(component.getName());
if (enabled != null) {
component.setEnabled(enabled);
}
@@ -10870,6 +10867,9 @@
usesStaticLibraries = new String[parsedPackage.getUsesStaticLibraries().size()];
parsedPackage.getUsesStaticLibraries().toArray(usesStaticLibraries);
}
+ // TODO(b/135203078): Remove appInfoFlag usage in favor of individually assigned booleans
+ // to avoid adding something that's unsupported due to lack of state, since it's called
+ // with null.
final boolean createNewPackage = (pkgSetting == null);
if (createNewPackage) {
final boolean instantApp = (scanFlags & SCAN_AS_INSTANT_APP) != 0;
@@ -10879,8 +10879,10 @@
originalPkgSetting, disabledPkgSetting, realPkgName, sharedUserSetting,
destCodeFile, destResourceFile, parsedPackage.getNativeLibraryRootDir(),
parsedPackage.getPrimaryCpuAbi(), parsedPackage.getSecondaryCpuAbi(),
- parsedPackage.getVersionCode(), parsedPackage.getFlags(),
- parsedPackage.getPrivateFlags(), user, true /*allowInstall*/, instantApp,
+ parsedPackage.getVersionCode(),
+ PackageInfoWithoutStateUtils.appInfoFlags(parsedPackage),
+ PackageInfoWithoutStateUtils.appInfoPrivateFlags(parsedPackage),
+ user, true /*allowInstall*/, instantApp,
virtualPreload, UserManagerService.getInstance(), usesStaticLibraries,
parsedPackage.getUsesStaticLibrariesVersions(), parsedPackage.getMimeGroups());
} else {
@@ -10896,7 +10898,8 @@
Settings.updatePackageSetting(pkgSetting, disabledPkgSetting, sharedUserSetting,
destCodeFile, destResourceFile, parsedPackage.getNativeLibraryDir(),
parsedPackage.getPrimaryCpuAbi(), parsedPackage.getSecondaryCpuAbi(),
- parsedPackage.getFlags(), parsedPackage.getPrivateFlags(),
+ PackageInfoWithoutStateUtils.appInfoFlags(parsedPackage),
+ PackageInfoWithoutStateUtils.appInfoPrivateFlags(parsedPackage),
UserManagerService.getInstance(),
usesStaticLibraries, parsedPackage.getUsesStaticLibrariesVersions(),
parsedPackage.getMimeGroups());
@@ -10934,11 +10937,6 @@
.setSeInfoUser(SELinuxUtil.assignSeinfoUser(pkgSetting.readUserState(
userId == UserHandle.USER_ALL ? UserHandle.USER_SYSTEM : userId)));
- if (!isPlatformPackage) {
- // Get all of our default paths setup
- parsedPackage.initForUser(UserHandle.USER_SYSTEM);
- }
-
if (parsedPackage.isSystem()) {
configurePackageComponents(parsedPackage);
}
@@ -10960,7 +10958,7 @@
// Some system apps still use directory structure for native libraries
// in which case we might end up not detecting abi solely based on apk
// structure. Try to detect abi based on directory structure.
- if (isSystemApp(parsedPackage) && !parsedPackage.isUpdatedSystemApp() &&
+ if (parsedPackage.isSystem() && !parsedPackage.isUpdatedSystemApp() &&
parsedPackage.getPrimaryCpuAbi() == null) {
final PackageAbiHelper.Abis abis = packageAbiHelper.getBundledAppAbis(
parsedPackage);
@@ -11020,7 +11018,7 @@
// would've already compiled the app without taking the package setting into
// account.
if ((scanFlags & SCAN_NO_DEX) == 0 && (scanFlags & SCAN_NEW_INSTALL) != 0) {
- if (cpuAbiOverride == null && parsedPackage.getPackageName() != null) {
+ if (cpuAbiOverride == null) {
Slog.w(TAG, "Ignoring persisted ABI override " + cpuAbiOverride +
" for package " + parsedPackage.getPackageName());
}
@@ -11090,7 +11088,7 @@
pkgSetting.setTimeStamp(scanFileTime);
// TODO(b/135203078): Remove, move to constructor
pkgSetting.pkg = parsedPackage;
- pkgSetting.pkgFlags = parsedPackage.getFlags();
+ pkgSetting.pkgFlags = PackageInfoUtils.appInfoFlags(parsedPackage, pkgSetting);
if (parsedPackage.getLongVersionCode() != pkgSetting.versionCode) {
pkgSetting.versionCode = parsedPackage.getLongVersionCode();
}
@@ -11153,7 +11151,7 @@
*/
private static void assertCodePolicy(AndroidPackage pkg)
throws PackageManagerException {
- final boolean shouldHaveCode = (pkg.getFlags() & ApplicationInfo.FLAG_HAS_CODE) != 0;
+ final boolean shouldHaveCode = pkg.isHasCode();
if (shouldHaveCode && !apkHasCode(pkg.getBaseCodePath())) {
throw new PackageManagerException(INSTALL_FAILED_INVALID_APK,
"Package " + pkg.getBaseCodePath() + " code is missing");
@@ -11223,7 +11221,7 @@
) == PackageManager.SIGNATURE_MATCH))
);
- if (!isSystemApp(parsedPackage)) {
+ if (!parsedPackage.isSystem()) {
// Only system apps can use these features.
parsedPackage.clearOriginalPackages()
.setRealPackage(null)
@@ -11241,19 +11239,19 @@
return object;
}
- private <T extends ComponentParseUtils.ParsedMainComponent>
+ private <T extends ParsedMainComponent>
void assertPackageProcesses(AndroidPackage pkg, List<T> components,
- Map<String, ComponentParseUtils.ParsedProcess> procs, String compName)
+ Map<String, ParsedProcess> procs, String compName)
throws PackageManagerException {
if (components == null) {
return;
}
for (int i = components.size() - 1; i >= 0; i--) {
- final ComponentParseUtils.ParsedMainComponent<?> component = components.get(i);
+ final ParsedMainComponent component = components.get(i);
if (!procs.containsKey(component.getProcessName())) {
throw new PackageManagerException(
INSTALL_FAILED_PROCESS_NOT_DEFINED,
- "Can't install because " + compName + " " + component.className
+ "Can't install because " + compName + " " + component.getClassName()
+ "'s process attribute " + component.getProcessName()
+ " (in package " + pkg.getPackageName()
+ ") is not included in the <processes> list");
@@ -11490,7 +11488,7 @@
// If this package has defined explicit processes, then ensure that these are
// the only processes used by its components.
- final Map<String, ComponentParseUtils.ParsedProcess> procs = pkg.getProcesses();
+ final Map<String, ParsedProcess> procs = pkg.getProcesses();
if (!procs.isEmpty()) {
if (!procs.containsKey(pkg.getProcessName())) {
throw new PackageManagerException(
@@ -11839,7 +11837,7 @@
if (DEBUG_PACKAGE_SCANNING) Log.d(TAG, " Instrumentation: " + r);
}
- if (pkg.getProtectedBroadcasts() != null) {
+ if (!pkg.getProtectedBroadcasts().isEmpty()) {
synchronized (mProtectedBroadcasts) {
mProtectedBroadcasts.addAll(pkg.getProtectedBroadcasts());
}
@@ -11990,21 +11988,19 @@
}
r = null;
- if ((pkg.getFlags() & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ if (pkg.isSystem()) {
// Only system apps can hold shared libraries.
- if (pkg.getLibraryNames() != null) {
- final int libraryNamesSize = pkg.getLibraryNames().size();
- for (i = 0; i < libraryNamesSize; i++) {
- String name = pkg.getLibraryNames().get(i);
- if (removeSharedLibraryLPw(name, 0)) {
- if (DEBUG_REMOVE && chatty) {
- if (r == null) {
- r = new StringBuilder(256);
- } else {
- r.append(' ');
- }
- r.append(name);
+ final int libraryNamesSize = pkg.getLibraryNames().size();
+ for (i = 0; i < libraryNamesSize; i++) {
+ String name = pkg.getLibraryNames().get(i);
+ if (removeSharedLibraryLPw(name, 0)) {
+ if (DEBUG_REMOVE && chatty) {
+ if (r == null) {
+ r = new StringBuilder(256);
+ } else {
+ r.append(' ');
}
+ r.append(name);
}
}
}
@@ -13448,15 +13444,15 @@
ArrayList<IntentFilter> result = new ArrayList<>();
for (int n=0; n<count; n++) {
ParsedActivity activity = pkg.getActivities().get(n);
- if (activity.intents != null && activity.intents.size() > 0) {
- result.addAll(activity.intents);
+ if (activity.getIntents() != null && activity.getIntents().size() > 0) {
+ result.addAll(activity.getIntents());
}
}
return new ParceledListSlice<IntentFilter>(result) {
@Override
protected void writeElement(IntentFilter parcelable, Parcel dest, int callFlags) {
// IntentFilter has final Parcelable methods, so redirect to the subclass
- ((ParsedActivityIntentInfo) parcelable).writeIntentInfoToParcel(dest,
+ ((ParsedIntentInfo) parcelable).writeIntentInfoToParcel(dest,
callFlags);
}
};
@@ -13641,9 +13637,8 @@
// package has not opted out of backup participation.
final boolean update = res.removedInfo != null
&& res.removedInfo.removedPackage != null;
- final int flags = (res.pkg == null) ? 0 : res.pkg.getFlags();
- boolean doRestore = !update
- && ((flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0);
+ boolean allowBackup = res.pkg != null && res.pkg.isAllowBackup();
+ boolean doRestore = !update && allowBackup;
// Set up the post-install work request bookkeeping. This will be used
// and cleaned up by the post-install event handling regardless of whether
@@ -14184,7 +14179,7 @@
if (dataOwnerPkg != null) {
if (!PackageManagerServiceUtils.isDowngradePermitted(installFlags,
- dataOwnerPkg.getFlags())) {
+ dataOwnerPkg.isDebuggable())) {
try {
checkDowngrade(dataOwnerPkg, pkgLite);
} catch (PackageManagerException e) {
@@ -14197,7 +14192,7 @@
if (installedPkg != null) {
if ((installFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
// Check for updated system application.
- if ((installedPkg.getFlags() & ApplicationInfo.FLAG_SYSTEM) != 0) {
+ if (installedPkg.isSystem()) {
return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
} else {
// If current upgrade specifies particular preference
@@ -14208,7 +14203,7 @@
// App explictly prefers external. Let policy decide
} else {
// Prefer previous location
- if (isExternal(installedPkg)) {
+ if (installedPkg.isExternalStorage()) {
return PackageHelper.RECOMMEND_INSTALL_EXTERNAL;
}
return PackageHelper.RECOMMEND_INSTALL_INTERNAL;
@@ -15285,7 +15280,7 @@
final PackageSetting ps = mSettings.mPackages.get(pkgName);
final int userId = installArgs.user.getIdentifier();
if (ps != null) {
- if (isSystemApp(pkg)) {
+ if (pkg.isSystem()) {
if (DEBUG_INSTALL) {
Slog.d(TAG, "Implicitly enabling system package on upgrade: " + pkgName);
}
@@ -15787,8 +15782,7 @@
if (scanResult.staticSharedLibraryInfo != null) {
return Collections.singletonList(scanResult.staticSharedLibraryInfo);
}
- final boolean hasDynamicLibraries =
- (parsedPackage.getFlags() & ApplicationInfo.FLAG_SYSTEM) != 0
+ final boolean hasDynamicLibraries = parsedPackage.isSystem()
&& scanResult.dynamicSharedLibraryInfos != null;
if (!hasDynamicLibraries) {
return null;
@@ -15912,7 +15906,7 @@
// If deleted package lived in a container, give users a chance to
// relinquish resources before killing.
- if (isExternal(oldPackage)) {
+ if (oldPackage.isExternalStorage()) {
if (DEBUG_INSTALL) {
Slog.i(TAG, "upgrading pkg " + oldPackage
+ " is ASEC-hosted -> UNAVAILABLE");
@@ -16159,7 +16153,7 @@
final boolean performDexopt =
(!instantApp || Global.getInt(mContext.getContentResolver(),
Global.INSTANT_APP_DEXOPT_ENABLED, 0) != 0)
- && ((pkg.getFlags() & ApplicationInfo.FLAG_DEBUGGABLE) == 0)
+ && !pkg.isDebuggable()
&& (!onIncremental);
if (performDexopt) {
@@ -16347,7 +16341,7 @@
}
String pkgName = res.name = parsedPackage.getPackageName();
- if ((parsedPackage.getFlags() & ApplicationInfo.FLAG_TEST_ONLY) != 0) {
+ if (parsedPackage.isTestOnly()) {
if ((installFlags & PackageManager.INSTALL_ALLOW_TEST) == 0) {
throw new PrepareFailure(INSTALL_FAILED_TEST_ONLY, "installPackageLI");
}
@@ -16382,8 +16376,7 @@
// Check if installing already existing package
if ((installFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
String oldName = mSettings.getRenamedPackageLPr(pkgName);
- if (parsedPackage.getOriginalPackages() != null
- && parsedPackage.getOriginalPackages().contains(oldName)
+ if (parsedPackage.getOriginalPackages().contains(oldName)
&& mPackages.containsKey(oldName)) {
// This package is derived from an original package,
// and this device has been updating from that original
@@ -16418,7 +16411,7 @@
+ " target SDK " + oldTargetSdk + " does.");
}
// Prevent persistent apps from being updated
- if (((oldPackage.getFlags() & ApplicationInfo.FLAG_PERSISTENT) != 0)
+ if (oldPackage.isPersistent()
&& ((installFlags & PackageManager.INSTALL_STAGED) == 0)) {
throw new PrepareFailure(PackageManager.INSTALL_FAILED_INVALID_APK,
"Package " + oldPackage.getPackageName() + " is a persistent app. "
@@ -16473,7 +16466,7 @@
}
if (ps.pkg != null) {
- systemApp = (ps.pkg.getFlags() & ApplicationInfo.FLAG_SYSTEM) != 0;
+ systemApp = ps.pkg.isSystem();
}
res.origUsers = ps.queryInstalledUsers(mUserManager.getUserIds(), true);
}
@@ -16485,12 +16478,12 @@
final BasePermission bp = mPermissionManager.getPermissionTEMP(perm.getName());
// Don't allow anyone but the system to define ephemeral permissions.
- if ((perm.protectionLevel & PermissionInfo.PROTECTION_FLAG_INSTANT) != 0
+ if ((perm.getProtectionLevel() & PermissionInfo.PROTECTION_FLAG_INSTANT) != 0
&& !systemApp) {
Slog.w(TAG, "Non-System package " + parsedPackage.getPackageName()
+ " attempting to delcare ephemeral permission "
+ perm.getName() + "; Removing ephemeral.");
- perm.protectionLevel &= ~PermissionInfo.PROTECTION_FLAG_INSTANT;
+ perm.setProtectionLevel(perm.getProtectionLevel() & ~PermissionInfo.PROTECTION_FLAG_INSTANT);
}
// Check whether the newly-scanned package wants to define an already-defined perm
@@ -16551,14 +16544,14 @@
// type as this would allow a privilege escalation where an app adds a
// normal/signature permission in other app's group and later redefines
// it as dangerous leading to the group auto-grant.
- if ((perm.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE)
+ if ((perm.getProtectionLevel() & PermissionInfo.PROTECTION_MASK_BASE)
== PermissionInfo.PROTECTION_DANGEROUS) {
if (bp != null && !bp.isRuntime()) {
Slog.w(TAG, "Package " + parsedPackage.getPackageName()
+ " trying to change a non-runtime permission "
+ perm.getName()
+ " to runtime; keeping old protection level");
- perm.protectionLevel = bp.getProtectionLevel();
+ perm.setProtectionLevel(bp.getProtectionLevel());
}
}
}
@@ -16781,14 +16774,14 @@
res.removedInfo.installReasons.put(userId, ps.getInstallReason(userId));
}
- sysPkg = (isSystemApp(oldPackage));
+ sysPkg = oldPackage.isSystem();
if (sysPkg) {
// Set the system/privileged/oem/vendor/product flags as needed
- final boolean privileged = isPrivilegedApp(oldPackage);
- final boolean oem = isOemApp(oldPackage);
- final boolean vendor = isVendorApp(oldPackage);
- final boolean product = isProductApp(oldPackage);
- final boolean odm = isOdmApp(oldPackage);
+ final boolean privileged = oldPackage.isPrivileged();
+ final boolean oem = oldPackage.isOem();
+ final boolean vendor = oldPackage.isVendor();
+ final boolean product = oldPackage.isProduct();
+ final boolean odm = oldPackage.isOdm();
final @ParseFlags int systemParseFlags = parseFlags;
final @ScanFlags int systemScanFlags = scanFlags
| SCAN_AS_SYSTEM
@@ -16970,7 +16963,7 @@
Message msg = mHandler.obtainMessage(START_INTENT_FILTER_VERIFICATIONS);
msg.obj = new IFVerificationParams(
pkg.getPackageName(),
- hasDomainURLs(pkg),
+ pkg.isHasDomainUrls(),
pkg.getActivities(),
replacing,
userId,
@@ -17022,11 +17015,12 @@
// examine handling policy even if not re-verifying.
boolean needToVerify = false;
for (ParsedActivity a : activities) {
- for (ParsedActivityIntentInfo filter : a.intents) {
+ for (ParsedIntentInfo filter : a.getIntents()) {
if (filter.handlesWebUris(true)) {
handlesWebUris = true;
}
- if (filter.needsVerification() && needsNetworkVerificationLPr(filter)) {
+ if (filter.needsVerification()
+ && needsNetworkVerificationLPr(a.getPackageName())) {
if (DEBUG_DOMAIN_VERIFICATION) {
Slog.d(TAG,
"Intent filter needs verification, so processing all filters");
@@ -17046,8 +17040,9 @@
if (needToVerify) {
final int verificationId = mIntentFilterVerificationToken++;
for (ParsedActivity a : activities) {
- for (ParsedActivityIntentInfo filter : a.intents) {
- if (filter.handlesWebUris(true) && needsNetworkVerificationLPr(filter)) {
+ for (ParsedIntentInfo filter : a.getIntents()) {
+ if (filter.handlesWebUris(true)
+ && needsNetworkVerificationLPr(a.getPackageName())) {
if (DEBUG_DOMAIN_VERIFICATION) Slog.d(TAG,
"Verification needed for IntentFilter:" + filter.toString());
mIntentFilterVerifier.addOneIntentFilterVerification(
@@ -17082,9 +17077,7 @@
}
@GuardedBy("mLock")
- private boolean needsNetworkVerificationLPr(ParsedActivityIntentInfo filter) {
- final String packageName = filter.getPackageName();
-
+ private boolean needsNetworkVerificationLPr(String packageName) {
IntentFilterVerificationInfo ivi = mSettings.getIntentFilterVerificationLPr(
packageName);
if (ivi == null) {
@@ -17103,47 +17096,10 @@
}
}
- private static boolean isExternal(AndroidPackage pkg) {
- return (pkg.getFlags() & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
- }
-
private static boolean isExternal(PackageSetting ps) {
return (ps.pkgFlags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0;
}
- static boolean isSystemApp(AndroidPackage pkg) {
- return (pkg.getFlags() & ApplicationInfo.FLAG_SYSTEM) != 0;
- }
-
- private static boolean isPrivilegedApp(AndroidPackage pkg) {
- return (pkg.getPrivateFlags() & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
- }
-
- private static boolean isOemApp(AndroidPackage pkg) {
- return (pkg.getPrivateFlags() & ApplicationInfo.PRIVATE_FLAG_OEM) != 0;
- }
-
- private static boolean isVendorApp(AndroidPackage pkg) {
- return (pkg.getPrivateFlags() & ApplicationInfo.PRIVATE_FLAG_VENDOR) != 0;
- }
-
- private static boolean isProductApp(AndroidPackage pkg) {
- return (pkg.getPrivateFlags() & ApplicationInfo.PRIVATE_FLAG_PRODUCT) != 0;
- }
-
- private static boolean isSystemExtApp(AndroidPackage pkg) {
- return (pkg.getPrivateFlags()
- & ApplicationInfo.PRIVATE_FLAG_SYSTEM_EXT) != 0;
- }
-
- private static boolean isOdmApp(AndroidPackage pkg) {
- return (pkg.getPrivateFlags() & ApplicationInfo.PRIVATE_FLAG_ODM) != 0;
- }
-
- private static boolean hasDomainURLs(AndroidPackage pkg) {
- return (pkg.getPrivateFlags() & ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS) != 0;
- }
-
private static boolean isSystemApp(PackageSetting ps) {
return (ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0;
}
@@ -17153,7 +17109,7 @@
}
private VersionInfo getSettingsVersionForPackage(AndroidPackage pkg) {
- if (isExternal(pkg)) {
+ if (pkg.isExternalStorage()) {
if (TextUtils.isEmpty(pkg.getVolumeUuid())) {
return mSettings.getExternalVersion();
} else {
@@ -22057,7 +22013,7 @@
"Failed to move already frozen package");
}
- isCurrentLocationExternal = isExternal(pkg);
+ isCurrentLocationExternal = pkg.isExternalStorage();
codeFile = new File(pkg.getCodePath());
installSource = ps.installSource;
packageAbiOverride = ps.cpuAbiOverrideString;
@@ -22237,15 +22193,15 @@
final StorageManager storage = mInjector.getStorageManager();;
VolumeInfo volume = storage.findVolumeByUuid(pkg.getStorageUuid().toString());
- int packageExternalStorageType = getPackageExternalStorageType(volume, isExternal(pkg));
+ int packageExternalStorageType = getPackageExternalStorageType(volume, pkg.isExternalStorage());
- if (!isPreviousLocationExternal && isExternal(pkg)) {
+ if (!isPreviousLocationExternal && pkg.isExternalStorage()) {
// Move from internal to external storage.
FrameworkStatsLog.write(FrameworkStatsLog.APP_MOVED_STORAGE_REPORTED,
packageExternalStorageType,
FrameworkStatsLog.APP_MOVED_STORAGE_REPORTED__MOVE_TYPE__TO_EXTERNAL,
packageName);
- } else if (isPreviousLocationExternal && !isExternal(pkg)) {
+ } else if (isPreviousLocationExternal && !pkg.isExternalStorage()) {
// Move from external to internal storage.
FrameworkStatsLog.write(FrameworkStatsLog.APP_MOVED_STORAGE_REPORTED,
packageExternalStorageType,
@@ -23411,11 +23367,7 @@
public boolean isPackagePersistent(String packageName) {
synchronized (mLock) {
AndroidPackage pkg = mPackages.get(packageName);
- return pkg != null
- ? ((pkg.getFlags() & (ApplicationInfo.FLAG_SYSTEM
- | ApplicationInfo.FLAG_PERSISTENT)) ==
- (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_PERSISTENT))
- : false;
+ return pkg != null && pkg.isSystem() && pkg.isPersistent();
}
}
diff --git a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
index 6040224..ac4e2b7 100644
--- a/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
+++ b/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java
@@ -824,11 +824,11 @@
* Checks whenever downgrade of an app is permitted.
*
* @param installFlags flags of the current install.
- * @param applicationFlags flags of the currently installed version of the app.
+ * @param isAppDebuggable if the currently installed version of the app is debuggable.
* @return {@code true} if downgrade is permitted according to the {@code installFlags} and
* {@code applicationFlags}.
*/
- public static boolean isDowngradePermitted(int installFlags, int applicationFlags) {
+ public static boolean isDowngradePermitted(int installFlags, boolean isAppDebuggable) {
// If installed, the package will get access to data left on the device by its
// predecessor. As a security measure, this is permitted only if this is not a
// version downgrade or if the predecessor package is marked as debuggable and
@@ -850,9 +850,7 @@
if (!downgradeRequested) {
return false;
}
- final boolean isDebuggable =
- Build.IS_DEBUGGABLE || ((applicationFlags
- & ApplicationInfo.FLAG_DEBUGGABLE) != 0);
+ final boolean isDebuggable = Build.IS_DEBUGGABLE || isAppDebuggable;
if (isDebuggable) {
return true;
}
diff --git a/services/core/java/com/android/server/pm/PersistentPreferredIntentResolver.java b/services/core/java/com/android/server/pm/PersistentPreferredIntentResolver.java
index ef29cb3..08a87d8 100644
--- a/services/core/java/com/android/server/pm/PersistentPreferredIntentResolver.java
+++ b/services/core/java/com/android/server/pm/PersistentPreferredIntentResolver.java
@@ -16,6 +16,9 @@
package com.android.server.pm;
+import android.annotation.NonNull;
+import android.content.IntentFilter;
+
import com.android.server.IntentResolver;
public class PersistentPreferredIntentResolver
@@ -26,6 +29,11 @@
}
@Override
+ protected IntentFilter getIntentFilter(@NonNull PersistentPreferredActivity input) {
+ return input;
+ }
+
+ @Override
protected boolean isPackageForFilter(String packageName, PersistentPreferredActivity filter) {
return packageName.equals(filter.mComponent.getPackageName());
}
diff --git a/services/core/java/com/android/server/pm/PreferredIntentResolver.java b/services/core/java/com/android/server/pm/PreferredIntentResolver.java
index bce24d7..a261e29 100644
--- a/services/core/java/com/android/server/pm/PreferredIntentResolver.java
+++ b/services/core/java/com/android/server/pm/PreferredIntentResolver.java
@@ -16,6 +16,9 @@
package com.android.server.pm;
+import android.annotation.NonNull;
+import android.content.IntentFilter;
+
import java.io.PrintWriter;
import com.android.server.IntentResolver;
@@ -37,4 +40,9 @@
PreferredActivity filter) {
filter.mPref.dump(out, prefix, filter);
}
+
+ @Override
+ protected IntentFilter getIntentFilter(@NonNull PreferredActivity input) {
+ return input;
+ }
}
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 37c194f..b06d7a9 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -49,10 +49,12 @@
import android.content.pm.SuspendDialogInfo;
import android.content.pm.UserInfo;
import android.content.pm.VerifierDeviceIdentity;
-import android.content.pm.parsing.ComponentParseUtils;
-import android.content.pm.parsing.ComponentParseUtils.ParsedComponent;
-import android.content.pm.parsing.ComponentParseUtils.ParsedMainComponent;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
+import android.content.pm.parsing.PackageInfoWithoutStateUtils;
+import android.content.pm.parsing.component.ParsedComponent;
+import android.content.pm.parsing.component.ParsedIntentInfo;
+import android.content.pm.parsing.component.ParsedMainComponent;
+import android.content.pm.parsing.component.ParsedPermission;
+import android.content.pm.parsing.component.ParsedProcess;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
@@ -76,6 +78,7 @@
import android.util.AtomicFile;
import android.util.Log;
import android.util.LogPrinter;
+import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;
import android.util.SparseBooleanArray;
@@ -96,6 +99,7 @@
import com.android.permission.persistence.RuntimePermissionsState;
import com.android.server.LocalServices;
import com.android.server.pm.Installer.InstallerException;
+import com.android.server.pm.parsing.PackageInfoUtils;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.permission.BasePermission;
import com.android.server.pm.permission.PermissionSettings;
@@ -2674,15 +2678,19 @@
StringBuilder sb = new StringBuilder();
for (final PackageSetting pkg : mPackages.values()) {
- if (pkg.pkg == null || pkg.pkg.getDataDir() == null) {
+ // TODO(b/135203078): This doesn't handle multiple users
+ final String dataPath = pkg.pkg == null ? null :
+ PackageInfoWithoutStateUtils.getDataDir(pkg.pkg,
+ UserHandle.USER_SYSTEM).getAbsolutePath();
+
+ if (pkg.pkg == null || dataPath == null) {
if (!"android".equals(pkg.name)) {
Slog.w(TAG, "Skipping " + pkg + " due to missing metadata");
}
continue;
}
- final String dataPath = pkg.pkg.getDataDir();
- final boolean isDebug = (pkg.pkg.getFlags() & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
+ final boolean isDebug = pkg.pkg.isDebuggable();
final int[] gids = pkg.getPermissionsState().computeGids(userIds);
// Avoid any application that has a space in its path.
@@ -3155,14 +3163,14 @@
final PackageManagerInternal pmInternal =
LocalServices.getService(PackageManagerInternal.class);
for (PackageSetting ps : mPackages.values()) {
- if ((ps.pkgFlags&ApplicationInfo.FLAG_SYSTEM) != 0 && ps.pkg != null
+ if ((ps.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0 && ps.pkg != null
&& !ps.pkg.getPreferredActivityFilters().isEmpty()) {
- List<ComponentParseUtils.ParsedActivityIntentInfo> intents
+ List<Pair<String, ParsedIntentInfo>> intents
= ps.pkg.getPreferredActivityFilters();
for (int i=0; i<intents.size(); i++) {
- ComponentParseUtils.ParsedActivityIntentInfo aii = intents.get(i);
- applyDefaultPreferredActivityLPw(pmInternal, aii, new ComponentName(
- ps.name, aii.getClassName()), userId);
+ Pair<String, ParsedIntentInfo> pair = intents.get(i);
+ applyDefaultPreferredActivityLPw(pmInternal, pair.second, new ComponentName(
+ ps.name, pair.first), userId);
}
}
}
@@ -4597,12 +4605,13 @@
pw.print(prefix); pw.print(" apkSigningVersion="); pw.println(apkSigningVersion);
// TODO(b/135203078): Is there anything to print here with AppInfo removed?
pw.print(prefix); pw.print(" applicationInfo=");
- pw.println(pkg.toAppInfoWithoutState().toString());
- pw.print(prefix); pw.print(" flags="); printFlags(pw, pkg.getFlags(),
- FLAG_DUMP_SPEC); pw.println();
- if (pkg.getPrivateFlags() != 0) {
+ pw.println(pkg.toAppInfoToString());
+ pw.print(prefix); pw.print(" flags=");
+ printFlags(pw, PackageInfoUtils.appInfoFlags(pkg, ps), FLAG_DUMP_SPEC); pw.println();
+ int privateFlags = PackageInfoUtils.appInfoPrivateFlags(pkg, ps);
+ if (privateFlags != 0) {
pw.print(prefix); pw.print(" privateFlags="); printFlags(pw,
- pkg.getPrivateFlags(), PRIVATE_FLAG_DUMP_SPEC); pw.println();
+ privateFlags, PRIVATE_FLAG_DUMP_SPEC); pw.println();
}
pw.print(prefix); pw.print(" forceQueryable="); pw.print(ps.pkg.isForceQueryable());
if (ps.forceQueryableOverride) {
@@ -4615,40 +4624,41 @@
if (!ps.pkg.getQueriesIntents().isEmpty()) {
pw.append(prefix).append(" queriesIntents=").println(ps.pkg.getQueriesIntents());
}
- pw.print(prefix); pw.print(" dataDir="); pw.println(ps.pkg.getDataDir());
+ File dataDir = PackageInfoWithoutStateUtils.getDataDir(pkg, UserHandle.myUserId());
+ pw.print(prefix); pw.print(" dataDir="); pw.println(dataDir.getAbsolutePath());
pw.print(prefix); pw.print(" supportsScreens=[");
boolean first = true;
- if ((pkg.getFlags() & ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS) != 0) {
+ if (pkg.isSupportsSmallScreens()) {
if (!first)
pw.print(", ");
first = false;
pw.print("small");
}
- if ((pkg.getFlags() & ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS) != 0) {
+ if (pkg.isSupportsNormalScreens()) {
if (!first)
pw.print(", ");
first = false;
pw.print("medium");
}
- if ((pkg.getFlags() & ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS) != 0) {
+ if (pkg.isSupportsLargeScreens()) {
if (!first)
pw.print(", ");
first = false;
pw.print("large");
}
- if ((pkg.getFlags() & ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS) != 0) {
+ if (pkg.isSupportsExtraLargeScreens()) {
if (!first)
pw.print(", ");
first = false;
pw.print("xlarge");
}
- if ((pkg.getFlags() & ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS) != 0) {
+ if (pkg.isResizeable()) {
if (!first)
pw.print(", ");
first = false;
pw.print("resizeable");
}
- if ((pkg.getFlags() & ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES) != 0) {
+ if (pkg.isAnyDensity()) {
if (!first)
pw.print(", ");
first = false;
@@ -4670,18 +4680,17 @@
pw.print(" version:"); pw.println(pkg.getStaticSharedLibVersion());
}
- final List<String> usesLibraries = pkg.getUsesLibraries();
- if (usesLibraries != null && usesLibraries.size() > 0) {
+ List<String> usesLibraries = pkg.getUsesLibraries();
+ if (usesLibraries.size() > 0) {
pw.print(prefix); pw.println(" usesLibraries:");
for (int i=0; i< usesLibraries.size(); i++) {
pw.print(prefix); pw.print(" "); pw.println(usesLibraries.get(i));
}
}
- final List<String> usesStaticLibraries = pkg.getUsesStaticLibraries();
- final long[] usesStaticLibrariesVersions = pkg.getUsesStaticLibrariesVersions();
- if (usesStaticLibraries != null
- && usesStaticLibraries.size() > 0) {
+ List<String> usesStaticLibraries = pkg.getUsesStaticLibraries();
+ long[] usesStaticLibrariesVersions = pkg.getUsesStaticLibrariesVersions();
+ if (usesStaticLibraries.size() > 0) {
pw.print(prefix); pw.println(" usesStaticLibraries:");
for (int i=0; i< usesStaticLibraries.size(); i++) {
pw.print(prefix); pw.print(" ");
@@ -4690,9 +4699,8 @@
}
}
- final List<String> usesOptionalLibraries = pkg.getUsesOptionalLibraries();
- if (usesOptionalLibraries != null
- && usesOptionalLibraries.size() > 0) {
+ List<String> usesOptionalLibraries = pkg.getUsesOptionalLibraries();
+ if (usesOptionalLibraries.size() > 0) {
pw.print(prefix); pw.println(" usesOptionalLibraries:");
for (int i=0; i< usesOptionalLibraries.size(); i++) {
pw.print(prefix); pw.print(" ");
@@ -4708,15 +4716,15 @@
pw.print(prefix); pw.print(" "); pw.println(usesLibraryFiles[i]);
}
}
- final Map<String, ComponentParseUtils.ParsedProcess> procs = pkg.getProcesses();
+ final Map<String, ParsedProcess> procs = pkg.getProcesses();
if (!procs.isEmpty()) {
pw.print(prefix); pw.println(" processes:");
- for (ComponentParseUtils.ParsedProcess proc : procs.values()) {
- pw.print(prefix); pw.print(" "); pw.println(proc.name);
- if (proc.deniedPermissions != null) {
- for (int j = 0; j < proc.deniedPermissions.size(); j++) {
+ for (ParsedProcess proc : procs.values()) {
+ pw.print(prefix); pw.print(" "); pw.println(proc.getName());
+ if (proc.getDeniedPermissions() != null) {
+ for (String deniedPermission : proc.getDeniedPermissions()) {
pw.print(prefix); pw.print(" deny: ");
- pw.println(proc.deniedPermissions.valueAt(j));
+ pw.println(deniedPermission);
}
}
}
@@ -4762,14 +4770,14 @@
}
pw.print(prefix); pw.print(" "); pw.print(perm.getName());
pw.print(": prot=");
- pw.print(PermissionInfo.protectionToString(perm.protectionLevel));
- if ((perm.flags&PermissionInfo.FLAG_COSTS_MONEY) != 0) {
+ pw.print(PermissionInfo.protectionToString(perm.getProtectionLevel()));
+ if ((perm.getFlags() &PermissionInfo.FLAG_COSTS_MONEY) != 0) {
pw.print(", COSTS_MONEY");
}
- if ((perm.flags&PermissionInfo.FLAG_REMOVED) != 0) {
+ if ((perm.getFlags() &PermissionInfo.FLAG_REMOVED) != 0) {
pw.print(", HIDDEN");
}
- if ((perm.flags&PermissionInfo.FLAG_INSTALLED) != 0) {
+ if ((perm.getFlags() &PermissionInfo.FLAG_INSTALLED) != 0) {
pw.print(", INSTALLED");
}
pw.println();
diff --git a/services/core/java/com/android/server/pm/SharedUserSetting.java b/services/core/java/com/android/server/pm/SharedUserSetting.java
index d60cfc7..952c2bf 100644
--- a/services/core/java/com/android/server/pm/SharedUserSetting.java
+++ b/services/core/java/com/android/server/pm/SharedUserSetting.java
@@ -18,7 +18,7 @@
import android.annotation.Nullable;
import android.content.pm.ApplicationInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProcess;
+import android.content.pm.parsing.component.ParsedProcess;
import android.service.pm.PackageServiceDumpProto;
import android.util.ArrayMap;
import android.util.ArraySet;
@@ -85,10 +85,10 @@
}
for (String key : newProcs.keySet()) {
ParsedProcess newProc = newProcs.get(key);
- ParsedProcess proc = processes.get(newProc.name);
+ ParsedProcess proc = processes.get(newProc.getName());
if (proc == null) {
proc = new ParsedProcess(newProc);
- processes.put(newProc.name, proc);
+ processes.put(newProc.getName(), proc);
} else {
proc.addStateFrom(newProc);
}
@@ -224,7 +224,7 @@
for (int i = 0; i < numProcs; i++) {
ParsedProcess proc =
new ParsedProcess(sharedUser.processes.valueAt(i));
- this.processes.put(proc.name, proc);
+ this.processes.put(proc.getName(), proc);
}
} else {
this.processes = null;
diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java
index 8a4cacb..42fce5a 100644
--- a/services/core/java/com/android/server/pm/StagingManager.java
+++ b/services/core/java/com/android/server/pm/StagingManager.java
@@ -29,6 +29,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
@@ -284,8 +285,10 @@
throws PackageManagerException {
final long activeVersion = activePackage.applicationInfo.longVersionCode;
final long newVersionCode = newPackage.applicationInfo.longVersionCode;
+ boolean isAppDebuggable = (activePackage.applicationInfo.flags
+ & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
final boolean allowsDowngrade = PackageManagerServiceUtils.isDowngradePermitted(
- session.params.installFlags, activePackage.applicationInfo.flags);
+ session.params.installFlags, isAppDebuggable);
if (activeVersion > newVersionCode && !allowsDowngrade) {
if (!mApexManager.abortStagedSession(session.sessionId)) {
Slog.e(TAG, "Failed to abort apex session " + session.sessionId);
diff --git a/services/core/java/com/android/server/pm/dex/ArtManagerService.java b/services/core/java/com/android/server/pm/dex/ArtManagerService.java
index cfba431..51e07faf 100644
--- a/services/core/java/com/android/server/pm/dex/ArtManagerService.java
+++ b/services/core/java/com/android/server/pm/dex/ArtManagerService.java
@@ -31,7 +31,7 @@
import android.content.pm.dex.DexMetadataHelper;
import android.content.pm.dex.ISnapshotRuntimeProfileCallback;
import android.content.pm.dex.PackageOptimizationInfo;
-import com.android.server.pm.parsing.pkg.AndroidPackage;
+import android.content.pm.parsing.PackageInfoWithoutStateUtils;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
@@ -54,6 +54,7 @@
import com.android.server.pm.Installer;
import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.PackageManagerServiceCompilerMapping;
+import com.android.server.pm.parsing.pkg.AndroidPackage;
import dalvik.system.DexFile;
import dalvik.system.VMRuntime;
@@ -482,7 +483,9 @@
try {
final String packageName = pkg.getPackageName();
final String apkPath = pkg.getBaseCodePath();
- final String outDexFile = pkg.getDataDir() + "/code_cache/compiled_view.dex";
+ // TODO(b/143971007): Use a cross-user directory
+ File dataDir = PackageInfoWithoutStateUtils.getDataDir(pkg, UserHandle.myUserId());
+ final String outDexFile = dataDir.getAbsolutePath() + "/code_cache/compiled_view.dex";
if (pkg.isPrivileged() || pkg.isUseEmbeddedDex()
|| pkg.isDefaultToDeviceProtectedStorage()) {
// Privileged apps prefer to load trusted code so they don't use compiled views.
@@ -516,7 +519,7 @@
*/
private ArrayMap<String, String> getPackageProfileNames(AndroidPackage pkg) {
ArrayMap<String, String> result = new ArrayMap<>();
- if ((pkg.getFlags() & ApplicationInfo.FLAG_HAS_CODE) != 0) {
+ if (pkg.isHasCode()) {
result.put(pkg.getBaseCodePath(), ArtManager.getProfileName(null));
}
diff --git a/services/core/java/com/android/server/pm/dex/ViewCompiler.java b/services/core/java/com/android/server/pm/dex/ViewCompiler.java
index 630b9bc..5506a52 100644
--- a/services/core/java/com/android/server/pm/dex/ViewCompiler.java
+++ b/services/core/java/com/android/server/pm/dex/ViewCompiler.java
@@ -16,12 +16,16 @@
package com.android.server.pm.dex;
-import com.android.server.pm.parsing.pkg.AndroidPackage;
+import android.content.pm.parsing.PackageInfoWithoutStateUtils;
import android.os.Binder;
+import android.os.UserHandle;
import android.util.Log;
import com.android.internal.annotations.GuardedBy;
import com.android.server.pm.Installer;
+import com.android.server.pm.parsing.pkg.AndroidPackage;
+
+import java.io.File;
public class ViewCompiler {
private final Object mInstallLock;
@@ -37,7 +41,9 @@
try {
final String packageName = pkg.getPackageName();
final String apkPath = pkg.getBaseCodePath();
- final String outDexFile = pkg.getDataDir() + "/code_cache/compiled_view.dex";
+ // TODO(b/143971007): Use a cross-user directory
+ File dataDir = PackageInfoWithoutStateUtils.getDataDir(pkg, UserHandle.myUserId());
+ final String outDexFile = dataDir.getAbsolutePath() + "/code_cache/compiled_view.dex";
Log.i("PackageManager", "Compiling layouts in " + packageName + " (" + apkPath +
") to " + outDexFile);
long callingId = Binder.clearCallingIdentity();
diff --git a/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java b/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java
index 3d56962..8640859 100644
--- a/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java
+++ b/services/core/java/com/android/server/pm/parsing/PackageInfoUtils.java
@@ -33,19 +33,22 @@
import android.content.pm.ProcessInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ServiceInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedComponent;
-import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation;
-import android.content.pm.parsing.ComponentParseUtils.ParsedMainComponent;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProcess;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
-import android.content.pm.parsing.ComponentParseUtils.ParsedService;
+import android.content.pm.SharedLibraryInfo;
import android.content.pm.parsing.PackageInfoWithoutStateUtils;
+import android.content.pm.parsing.component.ComponentParseUtils;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedComponent;
+import android.content.pm.parsing.component.ParsedInstrumentation;
+import android.content.pm.parsing.component.ParsedMainComponent;
+import android.content.pm.parsing.component.ParsedPermission;
+import android.content.pm.parsing.component.ParsedPermissionGroup;
+import android.content.pm.parsing.component.ParsedProcess;
+import android.content.pm.parsing.component.ParsedProvider;
+import android.content.pm.parsing.component.ParsedService;
import android.os.UserHandle;
import android.util.ArrayMap;
import android.util.ArraySet;
+import android.util.Pair;
import com.android.internal.util.ArrayUtils;
import com.android.server.pm.PackageSetting;
@@ -103,7 +106,8 @@
final ActivityInfo[] res = new ActivityInfo[N];
for (int i = 0; i < N; i++) {
final ParsedActivity a = pkg.getActivities().get(i);
- if (state.isMatch(pkg.isSystem(), pkg.isEnabled(), a, flags)) {
+ if (ComponentParseUtils.isMatch(state, pkg.isSystem(), pkg.isEnabled(), a,
+ flags)) {
if (PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME.equals(
a.getName())) {
continue;
@@ -122,7 +126,8 @@
final ActivityInfo[] res = new ActivityInfo[size];
for (int i = 0; i < size; i++) {
final ParsedActivity a = pkg.getReceivers().get(i);
- if (state.isMatch(pkg.isSystem(), pkg.isEnabled(), a, flags)) {
+ if (ComponentParseUtils.isMatch(state, pkg.isSystem(), pkg.isEnabled(), a,
+ flags)) {
res[num++] = generateActivityInfo(pkg, a, flags, state, applicationInfo,
userId, pkgSetting);
}
@@ -137,7 +142,8 @@
final ServiceInfo[] res = new ServiceInfo[size];
for (int i = 0; i < size; i++) {
final ParsedService s = pkg.getServices().get(i);
- if (state.isMatch(pkg.isSystem(), pkg.isEnabled(), s, flags)) {
+ if (ComponentParseUtils.isMatch(state, pkg.isSystem(), pkg.isEnabled(), s,
+ flags)) {
res[num++] = generateServiceInfo(pkg, s, flags, state, applicationInfo,
userId, pkgSetting);
}
@@ -153,7 +159,8 @@
for (int i = 0; i < size; i++) {
final ParsedProvider pr = pkg.getProviders()
.get(i);
- if (state.isMatch(pkg.isSystem(), pkg.isEnabled(), pr, flags)) {
+ if (ComponentParseUtils.isMatch(state, pkg.isSystem(), pkg.isEnabled(), pr,
+ flags)) {
res[num++] = generateProviderInfo(pkg, pr, flags, state, applicationInfo,
userId, pkgSetting);
}
@@ -342,9 +349,8 @@
ArrayMap<String, ProcessInfo> retProcs = new ArrayMap<>(numProcs);
for (String key : procs.keySet()) {
ParsedProcess proc = procs.get(key);
- retProcs.put(proc.name, new ProcessInfo(proc.name,
- proc.deniedPermissions != null
- ? new ArraySet<>(proc.deniedPermissions) : null));
+ retProcs.put(proc.getName(), new ProcessInfo(proc.getName(),
+ new ArraySet<>(proc.getDeniedPermissions())));
}
return retProcs;
}
@@ -374,7 +380,7 @@
private static void assignSharedFieldsForComponentInfo(@NonNull ComponentInfo componentInfo,
@NonNull ParsedMainComponent mainComponent, @Nullable PackageSetting pkgSetting) {
assignStateFieldsForPackageItemInfo(componentInfo, mainComponent, pkgSetting);
- componentInfo.descriptionRes = mainComponent.descriptionRes;
+ componentInfo.descriptionRes = mainComponent.getDescriptionRes();
componentInfo.directBootAware = mainComponent.isDirectBootAware();
componentInfo.enabled = mainComponent.isEnabled();
componentInfo.splitName = mainComponent.getSplitName();
diff --git a/services/core/java/com/android/server/pm/parsing/PackageParser2.java b/services/core/java/com/android/server/pm/parsing/PackageParser2.java
index 804f110..f99791a 100644
--- a/services/core/java/com/android/server/pm/parsing/PackageParser2.java
+++ b/services/core/java/com/android/server/pm/parsing/PackageParser2.java
@@ -19,8 +19,12 @@
import android.annotation.AnyThread;
import android.annotation.Nullable;
import android.content.pm.PackageParser;
+import android.content.pm.PackageParser.PackageParserException;
import android.content.pm.parsing.ParsingPackage;
import android.content.pm.parsing.ParsingPackageUtils;
+import android.content.pm.parsing.result.ParseInput;
+import android.content.pm.parsing.result.ParseResult;
+import android.content.pm.parsing.result.ParseTypeImpl;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.SystemClock;
@@ -43,17 +47,17 @@
private static final boolean LOG_PARSE_TIMINGS = Build.IS_DEBUGGABLE;
private static final int LOG_PARSE_TIMINGS_THRESHOLD_MS = 100;
- private ThreadLocal<ParsingPackageUtils.ParseResult> mSharedResult = ThreadLocal.withInitial(
- ParsingPackageUtils.ParseResult::new);
+ private ThreadLocal<ParseTypeImpl> mSharedResult = ThreadLocal.withInitial(ParseTypeImpl::new);
private final String[] mSeparateProcesses;
private final boolean mOnlyCoreApps;
private final DisplayMetrics mDisplayMetrics;
- private final Callback mCallback;
@Nullable
protected PackageCacher mCacher;
+ private ParsingPackageUtils parsingUtils;
+
/**
* @param onlyCoreApps Flag indicating this parser should only consider apps with
* {@code coreApp} manifest attribute to be valid apps. This is useful when
@@ -73,12 +77,14 @@
mCacher = cacheDir == null ? null : new PackageCacher(cacheDir);
// TODO(b/135203078): Remove nullability of callback
- mCallback = callback != null ? callback : new Callback() {
+ callback = callback != null ? callback : new Callback() {
@Override
public boolean hasFeature(String feature) {
return false;
}
};
+
+ parsingUtils = new ParsingPackageUtils(onlyCoreApps, separateProcesses, displayMetrics, callback);
}
/**
@@ -86,7 +92,7 @@
*/
@AnyThread
public ParsedPackage parsePackage(File packageFile, int flags, boolean useCaches)
- throws PackageParser.PackageParserException {
+ throws PackageParserException {
if (useCaches && mCacher != null) {
ParsedPackage parsed = mCacher.getCachedResult(packageFile, flags);
if (parsed != null) {
@@ -95,10 +101,14 @@
}
long parseTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0;
- ParsingPackageUtils.ParseInput parseInput = mSharedResult.get().reset();
- ParsedPackage parsed = (ParsedPackage) ParsingPackageUtils.parsePackage(parseInput,
- mSeparateProcesses, mCallback, mDisplayMetrics, mOnlyCoreApps, packageFile, flags)
- .hideAsParsed();
+ ParseInput input = mSharedResult.get().reset();
+ ParseResult<ParsingPackage> result = parsingUtils.parsePackage(input, packageFile, flags);
+ if (result.isError()) {
+ throw new PackageParserException(result.getErrorCode(), result.getErrorMessage(),
+ result.getException());
+ }
+
+ ParsedPackage parsed = (ParsedPackage) result.getResult().hideAsParsed();
long cacheTime = LOG_PARSE_TIMINGS ? SystemClock.uptimeMillis() : 0;
if (mCacher != null) {
diff --git a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java
index d0ec969..8db6c3f 100644
--- a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java
+++ b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java
@@ -16,8 +16,6 @@
package com.android.server.pm.parsing.pkg;
-import static android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo;
-
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Intent;
@@ -26,12 +24,14 @@
import android.content.pm.PackageParser;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.SharedLibraryInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedFeature;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup;
import android.content.pm.parsing.ParsingPackageRead;
+import android.content.pm.parsing.component.ParsedFeature;
+import android.content.pm.parsing.component.ParsedIntentInfo;
+import android.content.pm.parsing.component.ParsedPermissionGroup;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.ArraySet;
+import android.util.Pair;
import com.android.internal.R;
@@ -55,14 +55,6 @@
*/
public interface AndroidPackage extends PkgAppInfo, PkgPackageInfo, ParsingPackageRead, Parcelable {
- //TODO(b/135203078): Remove in favor of individual methods
- @Deprecated
- int getFlags();
-
- //TODO(b/135203078): Remove in favor of individual methods
- @Deprecated
- int getPrivateFlags();
-
//TODO(b/135203078): Move to PackageSetting
@Deprecated
@Nullable
@@ -78,15 +70,6 @@
@Deprecated
AndroidPackageWrite mutate();
- @Deprecated
- String getCredentialProtectedDataDir();
-
- @Deprecated
- String getDataDir();
-
- @Deprecated
- String getDeviceProtectedDataDir();
-
/**
* The names of packages to adopt ownership of permissions from, parsed under
* {@link PackageParser#TAG_ADOPT_PERMISSIONS}.
@@ -197,7 +180,7 @@
* TODO(b/135203078): Is this actually used/working?
*/
@NonNull
- List<ParsedActivityIntentInfo> getPreferredActivityFilters();
+ List<Pair<String, ParsedIntentInfo>> getPreferredActivityFilters();
/**
* System protected broadcasts.
diff --git a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java
index 781286e..c84e372 100644
--- a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java
+++ b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackageUtils.java
@@ -24,16 +24,15 @@
import android.content.pm.SharedLibraryInfo;
import android.content.pm.VersionedPackage;
import android.content.pm.dex.DexMetadataHelper;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
-import android.content.pm.parsing.ComponentParseUtils.ParsedService;
import android.content.pm.parsing.ParsingPackageRead;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedInstrumentation;
+import android.content.pm.parsing.component.ParsedProvider;
+import android.content.pm.parsing.component.ParsedService;
import com.android.internal.content.NativeLibraryHelper;
import com.android.internal.util.ArrayUtils;
import com.android.server.SystemConfig;
-import com.android.server.pm.PackageSetting;
import java.io.IOException;
import java.util.ArrayList;
diff --git a/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java b/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java
index 837cb3e..d636eb6 100644
--- a/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java
+++ b/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java
@@ -24,11 +24,12 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.SharedLibraryInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
-import android.content.pm.parsing.ComponentParseUtils.ParsedService;
import android.content.pm.parsing.ParsingPackage;
import android.content.pm.parsing.ParsingPackageImpl;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedMainComponent;
+import android.content.pm.parsing.component.ParsedProvider;
+import android.content.pm.parsing.component.ParsedService;
import android.content.res.TypedArray;
import android.os.Environment;
import android.os.Parcel;
@@ -43,6 +44,7 @@
import com.android.internal.util.Parcelling.BuiltIn.ForInternedString;
import com.android.server.pm.parsing.PackageInfoUtils;
+import java.util.Comparator;
import java.util.List;
import java.util.UUID;
@@ -150,16 +152,6 @@
@Deprecated
private boolean hiddenUntilInstalled;
- @Deprecated
- @Nullable
- private String credentialProtectedDataDir;
- @Deprecated
- @Nullable
- private String dataDir;
- @Deprecated
- @Nullable
- private String deviceProtectedDataDir;
-
/**
* This is an appId, the uid if the userId is == USER_SYSTEM
*/
@@ -192,16 +184,6 @@
}
@Override
- public int getFlags() {
- return PackageInfoUtils.appInfoFlags(this, null);
- }
-
- @Override
- public int getPrivateFlags() {
- return PackageInfoUtils.appInfoPrivateFlags(this, null);
- }
-
- @Override
public AndroidPackageWrite mutate() {
return this;
}
@@ -351,22 +333,22 @@
public PackageImpl setAllComponentsDirectBootAware(boolean allComponentsDirectBootAware) {
int activitiesSize = activities.size();
for (int index = 0; index < activitiesSize; index++) {
- activities.get(index).directBootAware = allComponentsDirectBootAware;
+ activities.get(index).setDirectBootAware(allComponentsDirectBootAware);
}
int receiversSize = receivers.size();
for (int index = 0; index < receiversSize; index++) {
- receivers.get(index).directBootAware = allComponentsDirectBootAware;
+ receivers.get(index).setDirectBootAware(allComponentsDirectBootAware);
}
int providersSize = providers.size();
for (int index = 0; index < providersSize; index++) {
- providers.get(index).directBootAware = allComponentsDirectBootAware;
+ providers.get(index).setDirectBootAware(allComponentsDirectBootAware);
}
int servicesSize = services.size();
for (int index = 0; index < servicesSize; index++) {
- services.get(index).directBootAware = allComponentsDirectBootAware;
+ services.get(index).setDirectBootAware(allComponentsDirectBootAware);
}
return this;
@@ -443,7 +425,7 @@
int size = permissionGroups.size();
for (int index = size - 1; index >= 0; --index) {
// TODO(b/135203078): Builder/immutability
- permissionGroups.get(index).priority = 0;
+ permissionGroups.get(index).setPriority(0);
}
return this;
}
@@ -454,8 +436,8 @@
int receiversSize = receivers.size();
for (int index = 0; index < receiversSize; index++) {
ParsedActivity receiver = receivers.get(index);
- if ((receiver.flags & ActivityInfo.FLAG_SINGLE_USER) != 0) {
- receiver.exported = false;
+ if ((receiver.getFlags() & ActivityInfo.FLAG_SINGLE_USER) != 0) {
+ receiver.setExported(false);
}
}
@@ -463,8 +445,8 @@
int servicesSize = services.size();
for (int index = 0; index < servicesSize; index++) {
ParsedService service = services.get(index);
- if ((service.flags & ActivityInfo.FLAG_SINGLE_USER) != 0) {
- service.exported = false;
+ if ((service.getFlags() & ActivityInfo.FLAG_SINGLE_USER) != 0) {
+ service.setExported(false);
}
}
@@ -494,32 +476,6 @@
}
@Override
- public PackageImpl initForUser(int userId) {
- // TODO(b/135203078): Move this user state to some other data structure
- this.uid = UserHandle.getUid(userId, UserHandle.getAppId(this.uid));
-
- if ("android".equals(packageName)) {
- dataDir = Environment.getDataSystemDirectory().getAbsolutePath();
- return this;
- }
-
- deviceProtectedDataDir = Environment
- .getDataUserDePackageDirectory(volumeUuid, userId, packageName)
- .getAbsolutePath();
- credentialProtectedDataDir = Environment
- .getDataUserCePackageDirectory(volumeUuid, userId, packageName)
- .getAbsolutePath();
-
- if (isDefaultToDeviceProtectedStorage()
- && PackageManager.APPLY_DEFAULT_TO_DEVICE_PROTECTED_STORAGE) {
- dataDir = deviceProtectedDataDir;
- } else {
- dataDir = credentialProtectedDataDir;
- }
- return this;
- }
-
- @Override
public PackageImpl setLastPackageUsageTimeInMills(int reason, long time) {
lastPackageUsageTimeInMills[reason] = time;
return this;
@@ -601,9 +557,6 @@
appInfo.uid = uid;
appInfo.sharedLibraryFiles = usesLibraryFiles;
appInfo.sharedLibraryInfos = usesLibraryInfos;
- appInfo.credentialProtectedDataDir = credentialProtectedDataDir;
- appInfo.dataDir = dataDir;
- appInfo.deviceProtectedDataDir = deviceProtectedDataDir;
return appInfo;
}
@@ -638,10 +591,7 @@
dest.writeBoolean(this.product);
dest.writeBoolean(this.odm);
dest.writeBoolean(this.signedWithPlatformKey);
- dest.writeBoolean(this.hiddenUntilInstalled);
- dest.writeString(this.credentialProtectedDataDir);
- dest.writeString(this.dataDir);
- dest.writeString(this.deviceProtectedDataDir);
+ dest.writeBoolean(this.hiddenUntilInstalled);;
dest.writeLongArray(this.lastPackageUsageTimeInMills);
dest.writeStringArray(this.usesLibraryFiles);
dest.writeTypedList(this.usesLibraryInfos);
@@ -673,9 +623,6 @@
this.odm = in.readBoolean();
this.signedWithPlatformKey = in.readBoolean();
this.hiddenUntilInstalled = in.readBoolean();
- this.credentialProtectedDataDir = in.readString();
- this.dataDir = in.readString();
- this.deviceProtectedDataDir = in.readString();
this.lastPackageUsageTimeInMills = in.createLongArray();
this.usesLibraryFiles = in.createStringArray();
this.usesLibraryInfos = in.createTypedArrayList(SharedLibraryInfo.CREATOR);
@@ -818,27 +765,6 @@
return hiddenUntilInstalled;
}
- @Deprecated
- @Nullable
- @Override
- public String getCredentialProtectedDataDir() {
- return credentialProtectedDataDir;
- }
-
- @Deprecated
- @Nullable
- @Override
- public String getDataDir() {
- return dataDir;
- }
-
- @Deprecated
- @Nullable
- @Override
- public String getDeviceProtectedDataDir() {
- return deviceProtectedDataDir;
- }
-
/**
* This is an appId, the uid if the userId is == USER_SYSTEM
*/
@@ -939,24 +865,6 @@
return this;
}
- @DataClass.Generated.Member
- public PackageImpl setCredentialProtectedDataDir(@Deprecated @Nullable String value) {
- credentialProtectedDataDir = value;
- return this;
- }
-
- @DataClass.Generated.Member
- public PackageImpl setDataDir(@Deprecated @Nullable String value) {
- dataDir = value;
- return this;
- }
-
- @DataClass.Generated.Member
- public PackageImpl setDeviceProtectedDataDir(@Deprecated @Nullable String value) {
- deviceProtectedDataDir = value;
- return this;
- }
-
/**
* This is an appId, the uid if the userId is == USER_SYSTEM
*/
@@ -965,4 +873,17 @@
uid = value;
return this;
}
+
+ @DataClass.Generated(
+ time = 1579914619453L,
+ codegenVersion = "1.0.14",
+ sourceFile = "frameworks/base/services/core/java/com/android/server/pm/parsing/pkg/PackageImpl.java",
+ inputSignatures = "private final @android.annotation.NonNull @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String manifestPackageName\nprivate boolean updatedSystemApp\nprotected @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String cpuAbiOverride\nprivate boolean stub\nprotected @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String nativeLibraryDir\nprotected @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String nativeLibraryRootDir\nprivate boolean nativeLibraryRootRequiresIsa\nprotected @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String primaryCpuAbi\nprotected @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String secondaryCpuAbi\nprotected @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String secondaryNativeLibraryDir\nprotected @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String seInfo\nprotected @android.annotation.Nullable @com.android.internal.util.DataClass.ParcelWith(com.android.internal.util.Parcelling.BuiltIn.ForInternedString.class) java.lang.String seInfoUser\nprivate boolean system\nprivate boolean factoryTest\nprivate boolean systemExt\nprivate boolean privileged\nprivate boolean oem\nprivate boolean vendor\nprivate boolean product\nprivate boolean odm\nprivate boolean signedWithPlatformKey\nprivate int uid\npublic static final com.android.server.pm.parsing.pkg.Creator<com.android.server.pm.parsing.pkg.PackageImpl> CREATOR\npublic static com.android.server.pm.parsing.pkg.PackageImpl forParsing(java.lang.String,java.lang.String,java.lang.String,android.content.res.TypedArray,boolean)\npublic static com.android.server.pm.parsing.pkg.AndroidPackage buildFakeForDeletion(java.lang.String,java.lang.String)\npublic static @com.android.internal.annotations.VisibleForTesting android.content.pm.parsing.ParsingPackage forTesting(java.lang.String)\npublic static @com.android.internal.annotations.VisibleForTesting android.content.pm.parsing.ParsingPackage forTesting(java.lang.String,java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.ParsedPackage hideAsParsed()\npublic @java.lang.Override com.android.server.pm.parsing.pkg.AndroidPackage hideAsFinal()\npublic @java.lang.Override int getFlags()\npublic @java.lang.Override int getPrivateFlags()\npublic @java.lang.Override long getLongVersionCode()\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl removePermission(int)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl addUsesOptionalLibrary(int,java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl addUsesLibrary(int,java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl removeUsesLibrary(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl removeUsesOptionalLibrary(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setSigningDetails(android.content.pm.PackageParser.SigningDetails)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setRestrictUpdateHash(byte)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setRealPackage(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setPersistent(boolean)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setDefaultToDeviceProtectedStorage(boolean)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setDirectBootAware(boolean)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl clearProtectedBroadcasts()\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl clearOriginalPackages()\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl clearAdoptPermissions()\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setCodePath(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setPackageName(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setAllComponentsDirectBootAware(boolean)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setBaseCodePath(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setCpuAbiOverride(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setNativeLibraryDir(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setNativeLibraryRootDir(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setPrimaryCpuAbi(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setSecondaryCpuAbi(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setSecondaryNativeLibraryDir(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setSeInfo(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setSeInfoUser(java.lang.String)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl setSplitCodePaths(java.lang.String[])\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl capPermissionPriorities()\npublic @java.lang.Override com.android.server.pm.parsing.pkg.PackageImpl markNotActivitiesAsNotExportedIfSingleUser()\npublic @java.lang.Override java.util.UUID getStorageUuid()\npublic @java.lang.Deprecated @java.lang.Override java.lang.String toAppInfoToString()\npublic @java.lang.Override com.android.server.pm.parsing.pkg.ParsedPackage setCoreApp(boolean)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.ParsedPackage setVersionCode(int)\npublic @java.lang.Override com.android.server.pm.parsing.pkg.ParsedPackage setVersionCodeMajor(int)\npublic @java.lang.Override android.content.pm.ApplicationInfo toAppInfoWithoutState()\npublic @java.lang.Override int describeContents()\npublic @java.lang.Override void writeToParcel(android.os.Parcel,int)\nclass PackageImpl extends android.content.pm.parsing.ParsingPackageImpl implements [com.android.server.pm.parsing.pkg.ParsedPackage, com.android.server.pm.parsing.pkg.AndroidPackage]\n@com.android.internal.util.DataClass(genConstructor=false, genParcelable=false, genAidl=false, genBuilder=false, genHiddenConstructor=false, genCopyConstructor=false)")
+ @Deprecated
+ private void __metadata() {}
+
+
+ //@formatter:on
+ // End of generated code
+
}
diff --git a/services/core/java/com/android/server/pm/parsing/pkg/ParsedPackage.java b/services/core/java/com/android/server/pm/parsing/pkg/ParsedPackage.java
index 4d49b98..b413560 100644
--- a/services/core/java/com/android/server/pm/parsing/pkg/ParsedPackage.java
+++ b/services/core/java/com/android/server/pm/parsing/pkg/ParsedPackage.java
@@ -65,9 +65,6 @@
ParsedPackage setSplitCodePaths(String[] splitCodePaths);
- @Deprecated
- ParsedPackage initForUser(int userId);
-
ParsedPackage setNativeLibraryRootRequiresIsa(boolean nativeLibraryRootRequiresIsa);
ParsedPackage setAllComponentsDirectBootAware(boolean allComponentsDirectBootAware);
diff --git a/services/core/java/com/android/server/pm/parsing/pkg/PkgPackageInfo.java b/services/core/java/com/android/server/pm/parsing/pkg/PkgPackageInfo.java
index 54f1efa..89330a9 100644
--- a/services/core/java/com/android/server/pm/parsing/pkg/PkgPackageInfo.java
+++ b/services/core/java/com/android/server/pm/parsing/pkg/PkgPackageInfo.java
@@ -27,11 +27,11 @@
import android.content.pm.PermissionInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ServiceInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
-import android.content.pm.parsing.ComponentParseUtils.ParsedService;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedInstrumentation;
+import android.content.pm.parsing.component.ParsedPermission;
+import android.content.pm.parsing.component.ParsedProvider;
+import android.content.pm.parsing.component.ParsedService;
import com.android.internal.R;
diff --git a/services/core/java/com/android/server/pm/permission/BasePermission.java b/services/core/java/com/android/server/pm/permission/BasePermission.java
index b44e345..f8e5082 100644
--- a/services/core/java/com/android/server/pm/permission/BasePermission.java
+++ b/services/core/java/com/android/server/pm/permission/BasePermission.java
@@ -32,8 +32,7 @@
import android.content.pm.PackageManagerInternal;
import android.content.pm.PermissionInfo;
import android.content.pm.Signature;
-import com.android.server.pm.parsing.pkg.AndroidPackage;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
+import android.content.pm.parsing.component.ParsedPermission;
import android.os.UserHandle;
import android.util.Log;
import android.util.Slog;
@@ -43,6 +42,7 @@
import com.android.server.pm.PackageSetting;
import com.android.server.pm.PackageSettingBase;
import com.android.server.pm.parsing.PackageInfoUtils;
+import com.android.server.pm.parsing.pkg.AndroidPackage;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
@@ -172,12 +172,12 @@
return 0;
}
- public boolean isPermission(@NonNull ParsedPermission perm) {
+ public boolean isPermission(ParsedPermission perm) {
if (this.perm == null) {
return false;
}
return Objects.equals(this.perm.getPackageName(), perm.getPackageName())
- && Objects.equals(this.perm.className, perm.className);
+ && Objects.equals(this.perm.getName(), perm.getName());
}
public boolean isDynamic() {
@@ -195,24 +195,24 @@
}
public boolean isRemoved() {
- return perm != null && (perm.flags & PermissionInfo.FLAG_REMOVED) != 0;
+ return perm != null && (perm.getFlags() & PermissionInfo.FLAG_REMOVED) != 0;
}
public boolean isSoftRestricted() {
- return perm != null && (perm.flags & PermissionInfo.FLAG_SOFT_RESTRICTED) != 0;
+ return perm != null && (perm.getFlags() & PermissionInfo.FLAG_SOFT_RESTRICTED) != 0;
}
public boolean isHardRestricted() {
- return perm != null && (perm.flags & PermissionInfo.FLAG_HARD_RESTRICTED) != 0;
+ return perm != null && (perm.getFlags() & PermissionInfo.FLAG_HARD_RESTRICTED) != 0;
}
public boolean isHardOrSoftRestricted() {
- return perm != null && (perm.flags & (PermissionInfo.FLAG_HARD_RESTRICTED
+ return perm != null && (perm.getFlags() & (PermissionInfo.FLAG_HARD_RESTRICTED
| PermissionInfo.FLAG_SOFT_RESTRICTED)) != 0;
}
public boolean isImmutablyRestricted() {
- return perm != null && (perm.flags & PermissionInfo.FLAG_IMMUTABLY_RESTRICTED) != 0;
+ return perm != null && (perm.getFlags() & PermissionInfo.FLAG_IMMUTABLY_RESTRICTED) != 0;
}
public boolean isSignature() {
@@ -326,15 +326,8 @@
final BasePermission tree = findPermissionTree(permissionTrees, name);
if (tree != null && tree.perm != null) {
sourcePackageSetting = tree.sourcePackageSetting;
- perm = new ParsedPermission(tree.perm);
- perm.protectionLevel = pendingPermissionInfo.protectionLevel;
- perm.flags = pendingPermissionInfo.flags;
- perm.setGroup(pendingPermissionInfo.group);
- perm.backgroundPermission = pendingPermissionInfo.backgroundPermission;
- perm.descriptionRes = pendingPermissionInfo.descriptionRes;
- perm.requestRes = pendingPermissionInfo.requestRes;
- perm.setPackageName(tree.perm.getPackageName());
- perm.setName(name);
+ perm = new ParsedPermission(tree.perm, pendingPermissionInfo,
+ tree.perm.getPackageName(), name);
uid = tree.uid;
}
}
@@ -364,7 +357,7 @@
if (pkg.isSystem()) {
if (bp.type == BasePermission.TYPE_BUILTIN && bp.perm == null) {
// It's a built-in permission and no owner, take ownership now
- p.flags |= PermissionInfo.FLAG_INSTALLED;
+ p.setFlags(p.getFlags() | PermissionInfo.FLAG_INSTALLED);
bp.sourcePackageSetting = pkgSetting;
bp.perm = p;
bp.uid = pkg.getUid();
@@ -387,7 +380,7 @@
final BasePermission tree = findPermissionTree(permissionTrees, p.getName());
if (tree == null
|| tree.sourcePackageName.equals(p.getPackageName())) {
- p.flags |= PermissionInfo.FLAG_INSTALLED;
+ p.setFlags(p.getFlags() | PermissionInfo.FLAG_INSTALLED);
bp.sourcePackageSetting = pkgSetting;
bp.perm = p;
bp.uid = pkg.getUid();
@@ -421,8 +414,8 @@
r.append(p.getName());
}
if (bp.perm != null && Objects.equals(bp.perm.getPackageName(), p.getPackageName())
- && Objects.equals(bp.perm.className, p.className)) {
- bp.protectionLevel = p.protectionLevel;
+ && Objects.equals(bp.perm.getName(), p.getName())) {
+ bp.protectionLevel = p.getProtectionLevel();
}
if (PackageManagerService.DEBUG_PACKAGE_SCANNING && r != null) {
Log.d(TAG, " Permissions: " + r);
@@ -572,9 +565,9 @@
if (type == BasePermission.TYPE_DYNAMIC) {
if (perm != null || pendingPermissionInfo != null) {
serializer.attribute(null, "type", "dynamic");
- int icon = perm != null ? perm.icon : pendingPermissionInfo.icon;
+ int icon = perm != null ? perm.getIcon() : pendingPermissionInfo.icon;
CharSequence nonLocalizedLabel = perm != null
- ? perm.nonLocalizedLabel
+ ? perm.getNonLocalizedLabel()
: pendingPermissionInfo.nonLocalizedLabel;
if (icon != 0) {
@@ -602,11 +595,11 @@
}
private static boolean comparePermissionInfos(ParsedPermission pi1, PermissionInfo pi2) {
- if (pi1.icon != pi2.icon) return false;
- if (pi1.logo != pi2.logo) return false;
- if (pi1.protectionLevel != pi2.protectionLevel) return false;
+ if (pi1.getIcon() != pi2.icon) return false;
+ if (pi1.getLogo() != pi2.logo) return false;
+ if (pi1.getProtectionLevel() != pi2.protectionLevel) return false;
if (!compareStrings(pi1.getName(), pi2.name)) return false;
- if (!compareStrings(pi1.nonLocalizedLabel, pi2.nonLocalizedLabel)) return false;
+ if (!compareStrings(pi1.getNonLocalizedLabel(), pi2.nonLocalizedLabel)) return false;
// We'll take care of setting this one.
if (!compareStrings(pi1.getPackageName(), pi2.packageName)) return false;
// These are not currently stored in settings.
@@ -644,9 +637,9 @@
pw.println(PermissionInfo.protectionToString(protectionLevel));
if (perm != null) {
pw.print(" perm="); pw.println(perm);
- if ((perm.flags & PermissionInfo.FLAG_INSTALLED) == 0
- || (perm.flags & PermissionInfo.FLAG_REMOVED) != 0) {
- pw.print(" flags=0x"); pw.println(Integer.toHexString(perm.flags));
+ if ((perm.getFlags() & PermissionInfo.FLAG_INSTALLED) == 0
+ || (perm.getFlags() & PermissionInfo.FLAG_REMOVED) != 0) {
+ pw.print(" flags=0x"); pw.println(Integer.toHexString(perm.getFlags()));
}
}
if (sourcePackageSetting != null) {
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
index f3aff36..da8b2fd 100644
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
@@ -71,9 +71,8 @@
import android.content.pm.ParceledListSlice;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
-import com.android.server.pm.parsing.pkg.AndroidPackage;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup;
+import android.content.pm.parsing.component.ParsedPermission;
+import android.content.pm.parsing.component.ParsedPermissionGroup;
import android.content.pm.permission.SplitPermissionInfoParcelable;
import android.metrics.LogMaker;
import android.os.Binder;
@@ -129,6 +128,7 @@
import com.android.server.pm.SharedUserSetting;
import com.android.server.pm.UserManagerService;
import com.android.server.pm.parsing.PackageInfoUtils;
+import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.permission.PermissionManagerServiceInternal.DefaultBrowserProvider;
import com.android.server.pm.permission.PermissionManagerServiceInternal.DefaultDialerProvider;
import com.android.server.pm.permission.PermissionManagerServiceInternal.DefaultHomeProvider;
@@ -2082,9 +2082,9 @@
for (int i = 0; i < numOldPackagePermissions; i++) {
final ParsedPermission permission = oldPackage.getPermissions().get(i);
- if (permission.parsedPermissionGroup != null) {
+ if (permission.getParsedPermissionGroup() != null) {
oldPermissionNameToGroupName.put(permission.getName(),
- permission.parsedPermissionGroup.getName());
+ permission.getParsedPermissionGroup().getName());
}
}
@@ -2098,8 +2098,9 @@
if ((newProtection & PermissionInfo.PROTECTION_DANGEROUS) != 0) {
final String permissionName = newPermission.getName();
- final String newPermissionGroupName = newPermission.parsedPermissionGroup == null
- ? null : newPermission.parsedPermissionGroup.getName();
+ final String newPermissionGroupName =
+ newPermission.getParsedPermissionGroup() == null
+ ? null : newPermission.getParsedPermissionGroup().getName();
final String oldPermissionGroupName = oldPermissionNameToGroupName.get(
permissionName);
@@ -2144,7 +2145,7 @@
ParsedPermission p = pkg.getPermissions().get(i);
// Assume by default that we did not install this permission into the system.
- p.flags &= ~PermissionInfo.FLAG_INSTALLED;
+ p.setFlags(p.getFlags() & ~PermissionInfo.FLAG_INSTALLED);
synchronized (PermissionManagerService.this.mLock) {
// Now that permission groups have a special meaning, we ignore permission
@@ -2152,16 +2153,16 @@
// permissions for one app being granted to someone just because they happen
// to be in a group defined by another app (before this had no implications).
if (pkg.getTargetSdkVersion() > Build.VERSION_CODES.LOLLIPOP_MR1) {
- p.parsedPermissionGroup = mSettings.mPermissionGroups.get(p.getGroup());
+ p.setParsedPermissionGroup(mSettings.mPermissionGroups.get(p.getGroup()));
// Warn for a permission in an unknown group.
if (DEBUG_PERMISSIONS
- && p.getGroup() != null && p.parsedPermissionGroup == null) {
+ && p.getGroup() != null && p.getParsedPermissionGroup() == null) {
Slog.i(TAG, "Permission " + p.getName() + " from package "
+ p.getPackageName() + " in an unknown group " + p.getGroup());
}
}
- if (p.tree) {
+ if (p.isTree()) {
final BasePermission bp = BasePermission.createOrUpdate(
mPackageManagerInt,
mSettings.getPermissionTreeLocked(p.getName()), p, pkg,
@@ -2766,7 +2767,8 @@
Slog.i(TAG, "Un-granting permission " + perm
+ " from package " + pkg.getPackageName()
+ " (protectionLevel=" + bp.getProtectionLevel()
- + " flags=0x" + Integer.toHexString(pkg.getFlags())
+ + " flags=0x"
+ + Integer.toHexString(PackageInfoUtils.appInfoFlags(pkg, ps))
+ ")");
}
} else if (bp.isAppOp()) {
@@ -2778,7 +2780,8 @@
Slog.i(TAG, "Not granting permission " + perm
+ " to package " + pkg.getPackageName()
+ " (protectionLevel=" + bp.getProtectionLevel()
- + " flags=0x" + Integer.toHexString(pkg.getFlags())
+ + " flags=0x"
+ + Integer.toHexString(PackageInfoUtils.appInfoFlags(pkg, ps))
+ ")");
}
}
@@ -3722,9 +3725,9 @@
// Only system declares background permissions, hence mapping does never change.
mBackgroundPermissions = new ArrayMap<>();
for (BasePermission bp : mSettings.getAllPermissionsLocked()) {
- if (bp.perm != null && bp.perm.backgroundPermission != null) {
+ if (bp.perm != null && bp.perm.getBackgroundPermission() != null) {
String fgPerm = bp.name;
- String bgPerm = bp.perm.backgroundPermission;
+ String bgPerm = bp.perm.getBackgroundPermission();
List<String> fgPerms = mBackgroundPermissions.get(bgPerm);
if (fgPerms == null) {
diff --git a/services/core/java/com/android/server/pm/permission/PermissionSettings.java b/services/core/java/com/android/server/pm/permission/PermissionSettings.java
index 254b720..355e243 100644
--- a/services/core/java/com/android/server/pm/permission/PermissionSettings.java
+++ b/services/core/java/com/android/server/pm/permission/PermissionSettings.java
@@ -18,7 +18,7 @@
import android.annotation.NonNull;
import android.annotation.Nullable;
-import android.content.pm.parsing.ComponentParseUtils;
+import android.content.pm.parsing.component.ParsedPermissionGroup;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
@@ -65,7 +65,7 @@
* name to permission group object.
*/
@GuardedBy("mLock")
- final ArrayMap<String, ComponentParseUtils.ParsedPermissionGroup> mPermissionGroups =
+ final ArrayMap<String, ParsedPermissionGroup> mPermissionGroups =
new ArrayMap<>();
/**
diff --git a/services/tests/servicestests/src/com/android/server/om/OverlayReferenceMapperTests.kt b/services/tests/servicestests/src/com/android/server/om/OverlayReferenceMapperTests.kt
index f97e7d3..063cd5da 100644
--- a/services/tests/servicestests/src/com/android/server/om/OverlayReferenceMapperTests.kt
+++ b/services/tests/servicestests/src/com/android/server/om/OverlayReferenceMapperTests.kt
@@ -196,11 +196,13 @@
whenever(packageName) { "$TARGET_PACKAGE_NAME$increment" }
whenever(overlayables) { mapOf("overlayableName$increment" to ACTOR_NAME) }
whenever(toString()) { "Package{$packageName}" }
+ whenever(isOverlay) { false }
}
private fun mockOverlay(increment: Int = 0) = mockThrowOnUnmocked<AndroidPackage> {
whenever(packageName) { "$OVERLAY_PACKAGE_NAME$increment" }
whenever(overlayables) { emptyMap<String, String>() }
whenever(toString()) { "Package{$packageName}" }
+ whenever(isOverlay) { true }
}
}
diff --git a/services/tests/servicestests/src/com/android/server/pm/AppsFilterTest.java b/services/tests/servicestests/src/com/android/server/pm/AppsFilterTest.java
index 236b9d6..5d5c714 100644
--- a/services/tests/servicestests/src/com/android/server/pm/AppsFilterTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/AppsFilterTest.java
@@ -29,10 +29,10 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageParser;
import android.content.pm.Signature;
-import android.content.pm.parsing.ComponentParseUtils;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo;
import android.content.pm.parsing.ParsingPackage;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedIntentInfo;
+import android.content.pm.parsing.component.ParsedProvider;
import android.os.Build;
import android.os.Process;
import android.platform.test.annotations.Presubmit;
@@ -114,7 +114,7 @@
ParsedActivity activity = new ParsedActivity();
activity.setPackageName(packageName);
for (IntentFilter filter : filters) {
- final ParsedActivityIntentInfo info = new ParsedActivityIntentInfo(packageName, null);
+ final ParsedIntentInfo info = new ParsedIntentInfo();
if (filter.countActions() > 0) {
filter.actionsIterator().forEachRemaining(info::addAction);
}
@@ -128,7 +128,7 @@
filter.schemesIterator().forEachRemaining(info::addDataScheme);
}
activity.addIntent(info);
- activity.exported = true;
+ activity.setExported(true);
}
return pkg(packageName)
@@ -136,7 +136,7 @@
}
private static ParsingPackage pkgWithProvider(String packageName, String authority) {
- ComponentParseUtils.ParsedProvider provider = new ComponentParseUtils.ParsedProvider();
+ ParsedProvider provider = new ParsedProvider();
provider.setPackageName(packageName);
provider.setExported(true);
provider.setAuthority(authority);
diff --git a/services/tests/servicestests/src/com/android/server/pm/PackageParserTest.java b/services/tests/servicestests/src/com/android/server/pm/PackageParserTest.java
index cb50929..825712b 100644
--- a/services/tests/servicestests/src/com/android/server/pm/PackageParserTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/PackageParserTest.java
@@ -33,16 +33,15 @@
import android.content.pm.ProviderInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.Signature;
-import android.content.pm.parsing.ComponentParseUtils;
-import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
-import android.content.pm.parsing.ComponentParseUtils.ParsedComponent;
-import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation;
-import android.content.pm.parsing.ComponentParseUtils.ParsedIntentInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup;
-import android.content.pm.parsing.ComponentParseUtils.ParsedProvider;
-import android.content.pm.parsing.ComponentParseUtils.ParsedService;
import android.content.pm.parsing.ParsingPackage;
+import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedComponent;
+import android.content.pm.parsing.component.ParsedInstrumentation;
+import android.content.pm.parsing.component.ParsedIntentInfo;
+import android.content.pm.parsing.component.ParsedPermission;
+import android.content.pm.parsing.component.ParsedPermissionGroup;
+import android.content.pm.parsing.component.ParsedProvider;
+import android.content.pm.parsing.component.ParsedService;
import android.os.Bundle;
import android.os.Parcel;
import android.platform.test.annotations.Presubmit;
@@ -357,44 +356,42 @@
assertEquals(a.toString(), b.toString());
}
- private static void assertComponentsEqual(ParsedComponent<?> a,
- ParsedComponent<?> b) {
- assertEquals(a.className, b.className);
+ private static void assertComponentsEqual(ParsedComponent a, ParsedComponent b) {
+ assertEquals(a.getName(), b.getName());
assertBundleApproximateEquals(a.getMetaData(), b.getMetaData());
assertEquals(a.getComponentName(), b.getComponentName());
- if (a.intents != null && b.intents != null) {
- assertEquals(a.intents.size(), b.intents.size());
- } else if (a.intents == null || b.intents == null) {
+ if (a.getIntents() != null && b.getIntents() != null) {
+ assertEquals(a.getIntents().size(), b.getIntents().size());
+ } else if (a.getIntents() == null || b.getIntents() == null) {
return;
}
- for (int i = 0; i < a.intents.size(); ++i) {
- ParsedIntentInfo aIntent = a.intents.get(i);
- ParsedIntentInfo bIntent = b.intents.get(i);
+ for (int i = 0; i < a.getIntents().size(); ++i) {
+ ParsedIntentInfo aIntent = a.getIntents().get(i);
+ ParsedIntentInfo bIntent = b.getIntents().get(i);
- assertEquals(aIntent.hasDefault, bIntent.hasDefault);
- assertEquals(aIntent.labelRes, bIntent.labelRes);
- assertEquals(aIntent.nonLocalizedLabel, bIntent.nonLocalizedLabel);
- assertEquals(aIntent.icon, bIntent.icon);
+ assertEquals(aIntent.isHasDefault(), bIntent.isHasDefault());
+ assertEquals(aIntent.getLabelRes(), bIntent.getLabelRes());
+ assertEquals(aIntent.getNonLocalizedLabel(), bIntent.getNonLocalizedLabel());
+ assertEquals(aIntent.getIcon(), bIntent.getIcon());
}
}
- private static void assertPermissionsEqual(ParsedPermission a,
- ParsedPermission b) {
+ private static void assertPermissionsEqual(ParsedPermission a, ParsedPermission b) {
assertComponentsEqual(a, b);
- assertEquals(a.tree, b.tree);
+ assertEquals(a.isTree(), b.isTree());
// Verify basic flags in PermissionInfo to make sure they're consistent. We don't perform
// a full structural equality here because the code that serializes them isn't parser
// specific and is tested elsewhere.
assertEquals(a.getProtection(), b.getProtection());
assertEquals(a.getGroup(), b.getGroup());
- assertEquals(a.flags, b.flags);
+ assertEquals(a.getFlags(), b.getFlags());
- if (a.parsedPermissionGroup != null && b.parsedPermissionGroup != null) {
- assertPermissionGroupsEqual(a.parsedPermissionGroup, b.parsedPermissionGroup);
- } else if (a.parsedPermissionGroup != null || b.parsedPermissionGroup != null) {
+ if (a.getParsedPermissionGroup() != null && b.getParsedPermissionGroup() != null) {
+ assertPermissionGroupsEqual(a.getParsedPermissionGroup(), b.getParsedPermissionGroup());
+ } else if (a.getParsedPermissionGroup() != null || b.getParsedPermissionGroup() != null) {
throw new AssertionError();
}
}
@@ -406,6 +403,8 @@
// Sanity check for InstrumentationInfo.
assertEquals(a.getTargetPackage(), b.getTargetPackage());
assertEquals(a.getTargetProcesses(), b.getTargetProcesses());
+ assertEquals(a.isHandleProfiling(), b.isHandleProfiling());
+ assertEquals(a.isFunctionalTest(), b.isFunctionalTest());
}
private static void assertServicesEqual(
@@ -465,7 +464,7 @@
// Sanity check for PermissionGroupInfo.
assertEquals(a.getName(), b.getName());
- assertEquals(a.descriptionRes, b.descriptionRes);
+ assertEquals(a.getDescriptionRes(), b.getDescriptionRes());
}
private static void assertApplicationInfoEqual(ApplicationInfo a, ApplicationInfo that) {
@@ -518,7 +517,7 @@
bundle.putString("key", "value");
ParsedPermission permission = new ParsedPermission();
- permission.parsedPermissionGroup = new ParsedPermissionGroup();
+ permission.setParsedPermissionGroup(new ParsedPermissionGroup());
((ParsedPackage) pkg.setBaseRevisionCode(100)
.setBaseHardwareAccelerated(true)
@@ -569,8 +568,7 @@
.setOverlayTarget("foo21")
.setOverlayPriority(100)
.setUpgradeKeySets(new ArraySet<>())
- .addPreferredActivityFilter(
- new ComponentParseUtils.ParsedActivityIntentInfo("foo", "className"))
+ .addPreferredActivityFilter("className", new ParsedIntentInfo())
.addConfigPreference(new ConfigurationInfo())
.addReqFeature(new FeatureInfo())
.addFeatureGroup(new FeatureGroupInfo())
diff --git a/services/tests/servicestests/src/com/android/server/pm/ScanTests.java b/services/tests/servicestests/src/com/android/server/pm/ScanTests.java
index e48c3f5..d230052 100644
--- a/services/tests/servicestests/src/com/android/server/pm/ScanTests.java
+++ b/services/tests/servicestests/src/com/android/server/pm/ScanTests.java
@@ -413,8 +413,9 @@
final PackageManagerService.ScanResult scanResult = executeScan(scanRequest);
- assertThat(scanResult.request.parsedPackage.getFlags(),
- hasFlag(ApplicationInfo.FLAG_UPDATED_SYSTEM_APP));
+ int appInfoFlags = PackageInfoUtils.appInfoFlags(scanResult.request.parsedPackage,
+ scanResult.pkgSetting);
+ assertThat(appInfoFlags, hasFlag(ApplicationInfo.FLAG_UPDATED_SYSTEM_APP));
}
@Test
@@ -428,8 +429,9 @@
true /*isUnderFactoryTest*/,
System.currentTimeMillis());
- assertThat(scanResult.request.parsedPackage.getFlags(),
- hasFlag(ApplicationInfo.FLAG_FACTORY_TEST));
+ int appInfoFlags = PackageInfoUtils.appInfoFlags(scanResult.request.parsedPackage,
+ scanResult.request.pkgSetting);
+ assertThat(appInfoFlags, hasFlag(ApplicationInfo.FLAG_FACTORY_TEST));
}
@Test
diff --git a/services/tests/servicestests/src/com/android/server/pm/parsing/PackageParserLegacyCoreTest.java b/services/tests/servicestests/src/com/android/server/pm/parsing/PackageParserLegacyCoreTest.java
index ec4776d..66cd466 100644
--- a/services/tests/servicestests/src/com/android/server/pm/parsing/PackageParserLegacyCoreTest.java
+++ b/services/tests/servicestests/src/com/android/server/pm/parsing/PackageParserLegacyCoreTest.java
@@ -29,8 +29,8 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
import android.content.pm.PermissionInfo;
-import android.content.pm.parsing.ComponentParseUtils.ParsedComponent;
-import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
+import android.content.pm.parsing.component.ParsedComponent;
+import android.content.pm.parsing.component.ParsedPermission;
import android.os.Build;
import android.os.Bundle;
import android.os.FileUtils;
@@ -369,9 +369,9 @@
/**
* Asserts basic properties about a component.
*/
- private void assertComponent(String className, int numIntents, ParsedComponent<?> component) {
- assertEquals(className, component.className);
- assertEquals(numIntents, component.intents.size());
+ private void assertComponent(String className, int numIntents, ParsedComponent component) {
+ assertEquals(className, component.getName());
+ assertEquals(numIntents, component.getIntents().size());
}
/**
@@ -467,7 +467,7 @@
// Hidden "app details" activity is added to every package.
boolean foundAppDetailsActivity = false;
for (int i = 0; i < ArrayUtils.size(p.getActivities()); i++) {
- if (p.getActivities().get(i).className.equals(
+ if (p.getActivities().get(i).getClassName().equals(
PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME)) {
foundAppDetailsActivity = true;
p.getActivities().remove(i);
@@ -501,11 +501,11 @@
assertEquals("Expected exactly one activity", 1, p.getActivities().size());
assertEquals("Expected exactly one intent filter",
- 1, p.getActivities().get(0).intents.size());
+ 1, p.getActivities().get(0).getIntents().size());
assertEquals("Expected exactly one mime group in intent filter",
- 1, p.getActivities().get(0).intents.get(0).countMimeGroups());
+ 1, p.getActivities().get(0).getIntents().get(0).countMimeGroups());
assertTrue("Did not find expected mime group 'mime_group_1'",
- p.getActivities().get(0).intents.get(0).hasMimeGroup("mime_group_1"));
+ p.getActivities().get(0).getIntents().get(0).hasMimeGroup("mime_group_1"));
}
@Test