Merge "Parse preferred-apps for all system partitions" into rvc-dev
This commit is contained in:
@@ -3229,60 +3229,66 @@ 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();
|
||||||
if (!preferredDir.exists() || !preferredDir.isDirectory()) {
|
for (int index = 0; index < size; index++) {
|
||||||
return;
|
PackageManagerService.ScanPartition partition =
|
||||||
}
|
PackageManagerService.SYSTEM_PARTITIONS.get(index);
|
||||||
if (!preferredDir.canRead()) {
|
|
||||||
Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Iterate over the files in the directory and scan .xml files
|
File preferredDir = new File(partition.folder, "etc/preferred-apps");
|
||||||
for (File f : preferredDir.listFiles()) {
|
if (!preferredDir.exists() || !preferredDir.isDirectory()) {
|
||||||
if (!f.getPath().endsWith(".xml")) {
|
|
||||||
Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!f.canRead()) {
|
|
||||||
Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f);
|
if (!preferredDir.canRead()) {
|
||||||
InputStream str = null;
|
Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
|
||||||
try {
|
continue;
|
||||||
str = new BufferedInputStream(new FileInputStream(f));
|
}
|
||||||
XmlPullParser parser = Xml.newPullParser();
|
|
||||||
parser.setInput(str, null);
|
|
||||||
|
|
||||||
int type;
|
// Iterate over the files in the directory and scan .xml files
|
||||||
while ((type = parser.next()) != XmlPullParser.START_TAG
|
File[] files = preferredDir.listFiles();
|
||||||
&& type != XmlPullParser.END_DOCUMENT) {
|
if (ArrayUtils.isEmpty(files)) {
|
||||||
;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type != XmlPullParser.START_TAG) {
|
for (File f : files) {
|
||||||
Slog.w(TAG, "Preferred apps file " + f + " does not have start tag");
|
if (!f.getPath().endsWith(".xml")) {
|
||||||
|
Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir
|
||||||
|
+ " directory, ignoring");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!"preferred-activities".equals(parser.getName())) {
|
if (!f.canRead()) {
|
||||||
Slog.w(TAG, "Preferred apps file " + f
|
Slog.w(TAG, "Preferred apps file " + f + " cannot be read");
|
||||||
+ " does not start with 'preferred-activities'");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
readDefaultPreferredActivitiesLPw(parser, userId);
|
if (PackageManagerService.DEBUG_PREFERRED) {
|
||||||
} catch (XmlPullParserException e) {
|
Log.d(TAG, "Reading default preferred " + f);
|
||||||
Slog.w(TAG, "Error reading apps file " + f, e);
|
}
|
||||||
} catch (IOException e) {
|
|
||||||
Slog.w(TAG, "Error reading apps file " + f, e);
|
try (InputStream str = new BufferedInputStream(new FileInputStream(f))) {
|
||||||
} finally {
|
XmlPullParser parser = Xml.newPullParser();
|
||||||
if (str != null) {
|
parser.setInput(str, null);
|
||||||
try {
|
|
||||||
str.close();
|
int type;
|
||||||
} catch (IOException e) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user