Merge "Parse preferred-apps for all system partitions" into rvc-dev

This commit is contained in:
Winson Chiu
2020-04-30 23:22:39 +00:00
committed by Android (Google) Code Review

View File

@@ -3229,31 +3229,43 @@ public final class Settings {
} }
} }
// Read preferred apps from .../etc/preferred-apps directory. // Read preferred apps from .../etc/preferred-apps directories.
File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps"); 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()) { if (!preferredDir.exists() || !preferredDir.isDirectory()) {
return; continue;
} }
if (!preferredDir.canRead()) { if (!preferredDir.canRead()) {
Slog.w(TAG, "Directory " + preferredDir + " cannot be read"); Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
return; continue;
} }
// Iterate over the files in the directory and scan .xml files // Iterate over the files in the directory and scan .xml files
for (File f : preferredDir.listFiles()) { File[] files = preferredDir.listFiles();
if (ArrayUtils.isEmpty(files)) {
continue;
}
for (File f : files) {
if (!f.getPath().endsWith(".xml")) { if (!f.getPath().endsWith(".xml")) {
Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring"); Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir
+ " directory, ignoring");
continue; continue;
} }
if (!f.canRead()) { if (!f.canRead()) {
Slog.w(TAG, "Preferred apps file " + f + " cannot be read"); Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
continue; continue;
} }
if (PackageManagerService.DEBUG_PREFERRED) {
Log.d(TAG, "Reading default preferred " + f);
}
if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f); try (InputStream str = new BufferedInputStream(new FileInputStream(f))) {
InputStream str = null;
try {
str = new BufferedInputStream(new FileInputStream(f));
XmlPullParser parser = Xml.newPullParser(); XmlPullParser parser = Xml.newPullParser();
parser.setInput(str, null); parser.setInput(str, null);
@@ -3277,12 +3289,6 @@ public final class Settings {
Slog.w(TAG, "Error reading apps file " + f, e); Slog.w(TAG, "Error reading apps file " + f, e);
} catch (IOException e) { } catch (IOException e) {
Slog.w(TAG, "Error reading apps file " + f, e); Slog.w(TAG, "Error reading apps file " + f, e);
} finally {
if (str != null) {
try {
str.close();
} catch (IOException e) {
}
} }
} }
} }