summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Winson <chiuwinson@google.com> 2020-04-30 12:27:40 -0700
committer Winson Chiu <chiuwinson@google.com> 2020-04-30 20:05:38 +0000
commit3b467df8dc0e838aa9b52b1006f2c51676bba68d (patch)
tree6c345ca33b2d7c2408e1cdcfbb2dc16248c355f8
parent094e5ddbd37640d7840bedabf64cbc0126835262 (diff)
Parse preferred-apps for all system partitions
Previously only /system/etc/preferred-apps was parsed. This reads PackageManagerService.SYSTEM_PARTITIONS instead so that these can be configured in any partition. Bug: 149779143 Test: manual device boots, works as expected Change-Id: I7e63aaaa3d050ee8f7be85e2e557bd1a2b88fd1b
-rw-r--r--services/core/java/com/android/server/pm/Settings.java92
1 files changed, 49 insertions, 43 deletions
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 7158af6d5310..9de34a92cdf7 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -3229,60 +3229,66 @@ public final class Settings {
}
}
- // Read preferred apps from .../etc/preferred-apps directory.
- File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps");
- if (!preferredDir.exists() || !preferredDir.isDirectory()) {
- return;
- }
- if (!preferredDir.canRead()) {
- Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
- return;
- }
-
- // Iterate over the files in the directory and scan .xml files
- for (File f : preferredDir.listFiles()) {
- if (!f.getPath().endsWith(".xml")) {
- Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring");
+ // Read preferred apps from .../etc/preferred-apps directories.
+ int size = PackageManagerService.SYSTEM_PARTITIONS.size();
+ for (int index = 0; index < size; index++) {
+ PackageManagerService.ScanPartition partition =
+ PackageManagerService.SYSTEM_PARTITIONS.get(index);
+
+ File preferredDir = new File(partition.folder, "etc/preferred-apps");
+ if (!preferredDir.exists() || !preferredDir.isDirectory()) {
continue;
}
- if (!f.canRead()) {
- Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
+
+ if (!preferredDir.canRead()) {
+ Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
continue;
}
- if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f);
- InputStream str = null;
- try {
- str = new BufferedInputStream(new FileInputStream(f));
- XmlPullParser parser = Xml.newPullParser();
- parser.setInput(str, null);
-
- int type;
- while ((type = parser.next()) != XmlPullParser.START_TAG
- && type != XmlPullParser.END_DOCUMENT) {
- ;
- }
+ // Iterate over the files in the directory and scan .xml files
+ File[] files = preferredDir.listFiles();
+ if (ArrayUtils.isEmpty(files)) {
+ continue;
+ }
- if (type != XmlPullParser.START_TAG) {
- Slog.w(TAG, "Preferred apps file " + f + " does not have start tag");
+ for (File f : files) {
+ if (!f.getPath().endsWith(".xml")) {
+ Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir
+ + " directory, ignoring");
continue;
}
- if (!"preferred-activities".equals(parser.getName())) {
- Slog.w(TAG, "Preferred apps file " + f
- + " does not start with 'preferred-activities'");
+ if (!f.canRead()) {
+ Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
continue;
}
- readDefaultPreferredActivitiesLPw(parser, userId);
- } catch (XmlPullParserException e) {
- Slog.w(TAG, "Error reading apps file " + f, e);
- } catch (IOException e) {
- Slog.w(TAG, "Error reading apps file " + f, e);
- } finally {
- if (str != null) {
- try {
- str.close();
- } catch (IOException e) {
+ if (PackageManagerService.DEBUG_PREFERRED) {
+ Log.d(TAG, "Reading default preferred " + f);
+ }
+
+ try (InputStream str = new BufferedInputStream(new FileInputStream(f))) {
+ XmlPullParser parser = Xml.newPullParser();
+ parser.setInput(str, null);
+
+ int type;
+ while ((type = parser.next()) != XmlPullParser.START_TAG
+ && type != XmlPullParser.END_DOCUMENT) {
+ ;
+ }
+
+ if (type != XmlPullParser.START_TAG) {
+ Slog.w(TAG, "Preferred apps file " + f + " does not have start tag");
+ continue;
+ }
+ if (!"preferred-activities".equals(parser.getName())) {
+ Slog.w(TAG, "Preferred apps file " + f
+ + " does not start with 'preferred-activities'");
+ continue;
}
+ readDefaultPreferredActivitiesLPw(parser, userId);
+ } catch (XmlPullParserException e) {
+ Slog.w(TAG, "Error reading apps file " + f, e);
+ } catch (IOException e) {
+ Slog.w(TAG, "Error reading apps file " + f, e);
}
}
}