Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e72f6eef authored by Winson Chiu's avatar Winson Chiu Committed by Automerger Merge Worker
Browse files

Merge "Parse preferred-apps for all system partitions" into rvc-dev am: cc850fcf am: 7059eb1c

Change-Id: If1afb21e9f1319439114114af3bba3bc2cbf2754
parents fae63d23 7059eb1c
Loading
Loading
Loading
Loading
+49 −43
Original line number Diff line number Diff line
@@ -3229,31 +3229,43 @@ public final class Settings {
            }
        }

        // Read preferred apps from .../etc/preferred-apps directory.
        File preferredDir = new File(Environment.getRootDirectory(), "etc/preferred-apps");
        // 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()) {
            return;
                continue;
            }

            if (!preferredDir.canRead()) {
                Slog.w(TAG, "Directory " + preferredDir + " cannot be read");
            return;
                continue;
            }

            // 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")) {
                Slog.i(TAG, "Non-xml file " + f + " in " + preferredDir + " directory, ignoring");
                    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;
                }
                if (PackageManagerService.DEBUG_PREFERRED) {
                    Log.d(TAG, "Reading default preferred " + f);
                }

            if (PackageManagerService.DEBUG_PREFERRED) Log.d(TAG, "Reading default preferred " + f);
            InputStream str = null;
            try {
                str = new BufferedInputStream(new FileInputStream(f));
                try (InputStream str = new BufferedInputStream(new FileInputStream(f))) {
                    XmlPullParser parser = Xml.newPullParser();
                    parser.setInput(str, null);

@@ -3277,12 +3289,6 @@ public final class Settings {
                    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) {
                    }
                }
            }
        }