Search in sources :

Example 6 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class CompatModePackages method saveCompatModes.

void saveCompatModes() {
    HashMap<String, Integer> pkgs;
    synchronized (mService) {
        pkgs = new HashMap<String, Integer>(mPackages);
    }
    FileOutputStream fos = null;
    try {
        fos = mFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        out.startTag(null, "compat-packages");
        final IPackageManager pm = AppGlobals.getPackageManager();
        final int screenLayout = mService.mConfiguration.screenLayout;
        final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
        final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<String, Integer> entry = it.next();
            String pkg = entry.getKey();
            int mode = entry.getValue();
            if (mode == 0) {
                continue;
            }
            ApplicationInfo ai = null;
            try {
                ai = pm.getApplicationInfo(pkg, 0, 0);
            } catch (RemoteException e) {
            }
            if (ai == null) {
                continue;
            }
            CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, smallestScreenWidthDp, false);
            if (info.alwaysSupportsScreen()) {
                continue;
            }
            if (info.neverSupportsScreen()) {
                continue;
            }
            out.startTag(null, "pkg");
            out.attribute(null, "name", pkg);
            out.attribute(null, "mode", Integer.toString(mode));
            out.endTag(null, "pkg");
        }
        out.endTag(null, "compat-packages");
        out.endDocument();
        mFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing compat packages", e1);
        if (fos != null) {
            mFile.failWrite(fos);
        }
    }
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) CompatibilityInfo(android.content.res.CompatibilityInfo) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageManager(android.content.pm.IPackageManager) FileOutputStream(java.io.FileOutputStream) RemoteException(android.os.RemoteException) HashMap(java.util.HashMap) Map(java.util.Map) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 7 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class PackageManagerService method dump.

@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
    if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
        pw.println("Permission Denial: can't dump ActivityManager from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " without permission " + android.Manifest.permission.DUMP);
        return;
    }
    DumpState dumpState = new DumpState();
    boolean fullPreferred = false;
    boolean checkin = false;
    String packageName = null;
    ArraySet<String> permissionNames = null;
    int opti = 0;
    while (opti < args.length) {
        String opt = args[opti];
        if (opt == null || opt.length() <= 0 || opt.charAt(0) != '-') {
            break;
        }
        opti++;
        if ("-a".equals(opt)) {
        // Right now we only know how to print all.
        } else if ("-h".equals(opt)) {
            pw.println("Package manager dump options:");
            pw.println("  [-h] [-f] [--checkin] [cmd] ...");
            pw.println("    --checkin: dump for a checkin");
            pw.println("    -f: print details of intent filters");
            pw.println("    -h: print this help");
            pw.println("  cmd may be one of:");
            pw.println("    l[ibraries]: list known shared libraries");
            pw.println("    f[eatures]: list device features");
            pw.println("    k[eysets]: print known keysets");
            pw.println("    r[esolvers] [activity|service|receiver|content]: dump intent resolvers");
            pw.println("    perm[issions]: dump permissions");
            pw.println("    permission [name ...]: dump declaration and use of given permission");
            pw.println("    pref[erred]: print preferred package settings");
            pw.println("    preferred-xml [--full]: print preferred package settings as xml");
            pw.println("    prov[iders]: dump content providers");
            pw.println("    p[ackages]: dump installed packages");
            pw.println("    s[hared-users]: dump shared user IDs");
            pw.println("    m[essages]: print collected runtime messages");
            pw.println("    v[erifiers]: print package verifier info");
            pw.println("    d[omain-preferred-apps]: print domains preferred apps");
            pw.println("    i[ntent-filter-verifiers]|ifv: print intent filter verifier info");
            pw.println("    version: print database version info");
            pw.println("    write: write current settings now");
            pw.println("    installs: details about install sessions");
            pw.println("    check-permission <permission> <package> [<user>]: does pkg hold perm?");
            pw.println("    dexopt: dump dexopt state");
            pw.println("    compiler-stats: dump compiler statistics");
            pw.println("    <package.name>: info about given package");
            return;
        } else if ("--checkin".equals(opt)) {
            checkin = true;
        } else if ("-f".equals(opt)) {
            dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);
        } else {
            pw.println("Unknown argument: " + opt + "; use -h for help");
        }
    }
    // Is the caller requesting to dump a particular piece of data?
    if (opti < args.length) {
        String cmd = args[opti];
        opti++;
        // Is this a package name?
        if ("android".equals(cmd) || cmd.contains(".")) {
            packageName = cmd;
            // When dumping a single package, we always dump all of its
            // filter information since the amount of data will be reasonable.
            dumpState.setOptionEnabled(DumpState.OPTION_SHOW_FILTERS);
        } else if ("check-permission".equals(cmd)) {
            if (opti >= args.length) {
                pw.println("Error: check-permission missing permission argument");
                return;
            }
            String perm = args[opti];
            opti++;
            if (opti >= args.length) {
                pw.println("Error: check-permission missing package argument");
                return;
            }
            String pkg = args[opti];
            opti++;
            int user = UserHandle.getUserId(Binder.getCallingUid());
            if (opti < args.length) {
                try {
                    user = Integer.parseInt(args[opti]);
                } catch (NumberFormatException e) {
                    pw.println("Error: check-permission user argument is not a number: " + args[opti]);
                    return;
                }
            }
            pw.println(checkPermission(perm, pkg, user));
            return;
        } else if ("l".equals(cmd) || "libraries".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_LIBS);
        } else if ("f".equals(cmd) || "features".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_FEATURES);
        } else if ("r".equals(cmd) || "resolvers".equals(cmd)) {
            if (opti >= args.length) {
                dumpState.setDump(DumpState.DUMP_ACTIVITY_RESOLVERS | DumpState.DUMP_SERVICE_RESOLVERS | DumpState.DUMP_RECEIVER_RESOLVERS | DumpState.DUMP_CONTENT_RESOLVERS);
            } else {
                while (opti < args.length) {
                    String name = args[opti];
                    if ("a".equals(name) || "activity".equals(name)) {
                        dumpState.setDump(DumpState.DUMP_ACTIVITY_RESOLVERS);
                    } else if ("s".equals(name) || "service".equals(name)) {
                        dumpState.setDump(DumpState.DUMP_SERVICE_RESOLVERS);
                    } else if ("r".equals(name) || "receiver".equals(name)) {
                        dumpState.setDump(DumpState.DUMP_RECEIVER_RESOLVERS);
                    } else if ("c".equals(name) || "content".equals(name)) {
                        dumpState.setDump(DumpState.DUMP_CONTENT_RESOLVERS);
                    } else {
                        pw.println("Error: unknown resolver table type: " + name);
                        return;
                    }
                    opti++;
                }
            }
        } else if ("perm".equals(cmd) || "permissions".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_PERMISSIONS);
        } else if ("permission".equals(cmd)) {
            if (opti >= args.length) {
                pw.println("Error: permission requires permission name");
                return;
            }
            permissionNames = new ArraySet<>();
            while (opti < args.length) {
                permissionNames.add(args[opti]);
                opti++;
            }
            dumpState.setDump(DumpState.DUMP_PERMISSIONS | DumpState.DUMP_PACKAGES | DumpState.DUMP_SHARED_USERS);
        } else if ("pref".equals(cmd) || "preferred".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_PREFERRED);
        } else if ("preferred-xml".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_PREFERRED_XML);
            if (opti < args.length && "--full".equals(args[opti])) {
                fullPreferred = true;
                opti++;
            }
        } else if ("d".equals(cmd) || "domain-preferred-apps".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_DOMAIN_PREFERRED);
        } else if ("p".equals(cmd) || "packages".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_PACKAGES);
        } else if ("s".equals(cmd) || "shared-users".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_SHARED_USERS);
        } else if ("prov".equals(cmd) || "providers".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_PROVIDERS);
        } else if ("m".equals(cmd) || "messages".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_MESSAGES);
        } else if ("v".equals(cmd) || "verifiers".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_VERIFIERS);
        } else if ("i".equals(cmd) || "ifv".equals(cmd) || "intent-filter-verifiers".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_INTENT_FILTER_VERIFIERS);
        } else if ("version".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_VERSION);
        } else if ("k".equals(cmd) || "keysets".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_KEYSETS);
        } else if ("installs".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_INSTALLS);
        } else if ("frozen".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_FROZEN);
        } else if ("dexopt".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_DEXOPT);
        } else if ("compiler-stats".equals(cmd)) {
            dumpState.setDump(DumpState.DUMP_COMPILER_STATS);
        } else if ("write".equals(cmd)) {
            synchronized (mPackages) {
                mSettings.writeLPr();
                pw.println("Settings written.");
                return;
            }
        }
    }
    if (checkin) {
        pw.println("vers,1");
    }
    // reader
    synchronized (mPackages) {
        if (dumpState.isDumping(DumpState.DUMP_VERSION) && packageName == null) {
            if (!checkin) {
                if (dumpState.onTitlePrinted())
                    pw.println();
                pw.println("Database versions:");
                mSettings.dumpVersionLPr(new IndentingPrintWriter(pw, "  "));
            }
        }
        if (dumpState.isDumping(DumpState.DUMP_VERIFIERS) && packageName == null) {
            if (!checkin) {
                if (dumpState.onTitlePrinted())
                    pw.println();
                pw.println("Verifiers:");
                pw.print("  Required: ");
                pw.print(mRequiredVerifierPackage);
                pw.print(" (uid=");
                pw.print(getPackageUid(mRequiredVerifierPackage, MATCH_DEBUG_TRIAGED_MISSING, UserHandle.USER_SYSTEM));
                pw.println(")");
            } else if (mRequiredVerifierPackage != null) {
                pw.print("vrfy,");
                pw.print(mRequiredVerifierPackage);
                pw.print(",");
                pw.println(getPackageUid(mRequiredVerifierPackage, MATCH_DEBUG_TRIAGED_MISSING, UserHandle.USER_SYSTEM));
            }
        }
        if (dumpState.isDumping(DumpState.DUMP_INTENT_FILTER_VERIFIERS) && packageName == null) {
            if (mIntentFilterVerifierComponent != null) {
                String verifierPackageName = mIntentFilterVerifierComponent.getPackageName();
                if (!checkin) {
                    if (dumpState.onTitlePrinted())
                        pw.println();
                    pw.println("Intent Filter Verifier:");
                    pw.print("  Using: ");
                    pw.print(verifierPackageName);
                    pw.print(" (uid=");
                    pw.print(getPackageUid(verifierPackageName, MATCH_DEBUG_TRIAGED_MISSING, UserHandle.USER_SYSTEM));
                    pw.println(")");
                } else if (verifierPackageName != null) {
                    pw.print("ifv,");
                    pw.print(verifierPackageName);
                    pw.print(",");
                    pw.println(getPackageUid(verifierPackageName, MATCH_DEBUG_TRIAGED_MISSING, UserHandle.USER_SYSTEM));
                }
            } else {
                pw.println();
                pw.println("No Intent Filter Verifier available!");
            }
        }
        if (dumpState.isDumping(DumpState.DUMP_LIBS) && packageName == null) {
            boolean printedHeader = false;
            final Iterator<String> it = mSharedLibraries.keySet().iterator();
            while (it.hasNext()) {
                String name = it.next();
                SharedLibraryEntry ent = mSharedLibraries.get(name);
                if (!checkin) {
                    if (!printedHeader) {
                        if (dumpState.onTitlePrinted())
                            pw.println();
                        pw.println("Libraries:");
                        printedHeader = true;
                    }
                    pw.print("  ");
                } else {
                    pw.print("lib,");
                }
                pw.print(name);
                if (!checkin) {
                    pw.print(" -> ");
                }
                if (ent.path != null) {
                    if (!checkin) {
                        pw.print("(jar) ");
                        pw.print(ent.path);
                    } else {
                        pw.print(",jar,");
                        pw.print(ent.path);
                    }
                } else {
                    if (!checkin) {
                        pw.print("(apk) ");
                        pw.print(ent.apk);
                    } else {
                        pw.print(",apk,");
                        pw.print(ent.apk);
                    }
                }
                pw.println();
            }
        }
        if (dumpState.isDumping(DumpState.DUMP_FEATURES) && packageName == null) {
            if (dumpState.onTitlePrinted())
                pw.println();
            if (!checkin) {
                pw.println("Features:");
            }
            for (FeatureInfo feat : mAvailableFeatures.values()) {
                if (checkin) {
                    pw.print("feat,");
                    pw.print(feat.name);
                    pw.print(",");
                    pw.println(feat.version);
                } else {
                    pw.print("  ");
                    pw.print(feat.name);
                    if (feat.version > 0) {
                        pw.print(" version=");
                        pw.print(feat.version);
                    }
                    pw.println();
                }
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_ACTIVITY_RESOLVERS)) {
            if (mActivities.dump(pw, dumpState.getTitlePrinted() ? "\nActivity Resolver Table:" : "Activity Resolver Table:", "  ", packageName, dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS), true)) {
                dumpState.setTitlePrinted(true);
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_RECEIVER_RESOLVERS)) {
            if (mReceivers.dump(pw, dumpState.getTitlePrinted() ? "\nReceiver Resolver Table:" : "Receiver Resolver Table:", "  ", packageName, dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS), true)) {
                dumpState.setTitlePrinted(true);
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_SERVICE_RESOLVERS)) {
            if (mServices.dump(pw, dumpState.getTitlePrinted() ? "\nService Resolver Table:" : "Service Resolver Table:", "  ", packageName, dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS), true)) {
                dumpState.setTitlePrinted(true);
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_CONTENT_RESOLVERS)) {
            if (mProviders.dump(pw, dumpState.getTitlePrinted() ? "\nProvider Resolver Table:" : "Provider Resolver Table:", "  ", packageName, dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS), true)) {
                dumpState.setTitlePrinted(true);
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_PREFERRED)) {
            for (int i = 0; i < mSettings.mPreferredActivities.size(); i++) {
                PreferredIntentResolver pir = mSettings.mPreferredActivities.valueAt(i);
                int user = mSettings.mPreferredActivities.keyAt(i);
                if (pir.dump(pw, dumpState.getTitlePrinted() ? "\nPreferred Activities User " + user + ":" : "Preferred Activities User " + user + ":", "  ", packageName, true, false)) {
                    dumpState.setTitlePrinted(true);
                }
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_PREFERRED_XML)) {
            pw.flush();
            FileOutputStream fout = new FileOutputStream(fd);
            BufferedOutputStream str = new BufferedOutputStream(fout);
            XmlSerializer serializer = new FastXmlSerializer();
            try {
                serializer.setOutput(str, StandardCharsets.UTF_8.name());
                serializer.startDocument(null, true);
                serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
                mSettings.writePreferredActivitiesLPr(serializer, 0, fullPreferred);
                serializer.endDocument();
                serializer.flush();
            } catch (IllegalArgumentException e) {
                pw.println("Failed writing: " + e);
            } catch (IllegalStateException e) {
                pw.println("Failed writing: " + e);
            } catch (IOException e) {
                pw.println("Failed writing: " + e);
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_DOMAIN_PREFERRED) && packageName == null) {
            pw.println();
            int count = mSettings.mPackages.size();
            if (count == 0) {
                pw.println("No applications!");
                pw.println();
            } else {
                final String prefix = "  ";
                Collection<PackageSetting> allPackageSettings = mSettings.mPackages.values();
                if (allPackageSettings.size() == 0) {
                    pw.println("No domain preferred apps!");
                    pw.println();
                } else {
                    pw.println("App verification status:");
                    pw.println();
                    count = 0;
                    for (PackageSetting ps : allPackageSettings) {
                        IntentFilterVerificationInfo ivi = ps.getIntentFilterVerificationInfo();
                        if (ivi == null || ivi.getPackageName() == null)
                            continue;
                        pw.println(prefix + "Package: " + ivi.getPackageName());
                        pw.println(prefix + "Domains: " + ivi.getDomainsString());
                        pw.println(prefix + "Status:  " + ivi.getStatusString());
                        pw.println();
                        count++;
                    }
                    if (count == 0) {
                        pw.println(prefix + "No app verification established.");
                        pw.println();
                    }
                    for (int userId : sUserManager.getUserIds()) {
                        pw.println("App linkages for user " + userId + ":");
                        pw.println();
                        count = 0;
                        for (PackageSetting ps : allPackageSettings) {
                            final long status = ps.getDomainVerificationStatusForUser(userId);
                            if (status >> 32 == INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_UNDEFINED) {
                                continue;
                            }
                            pw.println(prefix + "Package: " + ps.name);
                            pw.println(prefix + "Domains: " + dumpDomainString(ps.name));
                            String statusStr = IntentFilterVerificationInfo.getStatusStringFromValue(status);
                            pw.println(prefix + "Status:  " + statusStr);
                            pw.println();
                            count++;
                        }
                        if (count == 0) {
                            pw.println(prefix + "No configured app linkages.");
                            pw.println();
                        }
                    }
                }
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_PERMISSIONS)) {
            mSettings.dumpPermissionsLPr(pw, packageName, permissionNames, dumpState);
            if (packageName == null && permissionNames == null) {
                for (int iperm = 0; iperm < mAppOpPermissionPackages.size(); iperm++) {
                    if (iperm == 0) {
                        if (dumpState.onTitlePrinted())
                            pw.println();
                        pw.println("AppOp Permissions:");
                    }
                    pw.print("  AppOp Permission ");
                    pw.print(mAppOpPermissionPackages.keyAt(iperm));
                    pw.println(":");
                    ArraySet<String> pkgs = mAppOpPermissionPackages.valueAt(iperm);
                    for (int ipkg = 0; ipkg < pkgs.size(); ipkg++) {
                        pw.print("    ");
                        pw.println(pkgs.valueAt(ipkg));
                    }
                }
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_PROVIDERS)) {
            boolean printedSomething = false;
            for (PackageParser.Provider p : mProviders.mProviders.values()) {
                if (packageName != null && !packageName.equals(p.info.packageName)) {
                    continue;
                }
                if (!printedSomething) {
                    if (dumpState.onTitlePrinted())
                        pw.println();
                    pw.println("Registered ContentProviders:");
                    printedSomething = true;
                }
                pw.print("  ");
                p.printComponentShortName(pw);
                pw.println(":");
                pw.print("    ");
                pw.println(p.toString());
            }
            printedSomething = false;
            for (Map.Entry<String, PackageParser.Provider> entry : mProvidersByAuthority.entrySet()) {
                PackageParser.Provider p = entry.getValue();
                if (packageName != null && !packageName.equals(p.info.packageName)) {
                    continue;
                }
                if (!printedSomething) {
                    if (dumpState.onTitlePrinted())
                        pw.println();
                    pw.println("ContentProvider Authorities:");
                    printedSomething = true;
                }
                pw.print("  [");
                pw.print(entry.getKey());
                pw.println("]:");
                pw.print("    ");
                pw.println(p.toString());
                if (p.info != null && p.info.applicationInfo != null) {
                    final String appInfo = p.info.applicationInfo.toString();
                    pw.print("      applicationInfo=");
                    pw.println(appInfo);
                }
            }
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_KEYSETS)) {
            mSettings.mKeySetManagerService.dumpLPr(pw, packageName, dumpState);
        }
        if (dumpState.isDumping(DumpState.DUMP_PACKAGES)) {
            mSettings.dumpPackagesLPr(pw, packageName, permissionNames, dumpState, checkin);
        }
        if (dumpState.isDumping(DumpState.DUMP_SHARED_USERS)) {
            mSettings.dumpSharedUsersLPr(pw, packageName, permissionNames, dumpState, checkin);
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_PERMISSIONS) && packageName == null) {
            mSettings.dumpRestoredPermissionGrantsLPr(pw, dumpState);
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_INSTALLS) && packageName == null) {
            // the given package is involved with.
            if (dumpState.onTitlePrinted())
                pw.println();
            mInstallerService.dump(new IndentingPrintWriter(pw, "  ", 120));
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_FROZEN) && packageName == null) {
            // the given package is involved with.
            if (dumpState.onTitlePrinted())
                pw.println();
            final IndentingPrintWriter ipw = new IndentingPrintWriter(pw, "  ", 120);
            ipw.println();
            ipw.println("Frozen packages:");
            ipw.increaseIndent();
            if (mFrozenPackages.size() == 0) {
                ipw.println("(none)");
            } else {
                for (int i = 0; i < mFrozenPackages.size(); i++) {
                    ipw.println(mFrozenPackages.valueAt(i));
                }
            }
            ipw.decreaseIndent();
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_DEXOPT)) {
            if (dumpState.onTitlePrinted())
                pw.println();
            dumpDexoptStateLPr(pw, packageName);
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_COMPILER_STATS)) {
            if (dumpState.onTitlePrinted())
                pw.println();
            dumpCompilerStatsLPr(pw, packageName);
        }
        if (!checkin && dumpState.isDumping(DumpState.DUMP_MESSAGES) && packageName == null) {
            if (dumpState.onTitlePrinted())
                pw.println();
            mSettings.dumpReadMessagesLPr(pw, dumpState);
            pw.println();
            pw.println("Package warning messages:");
            BufferedReader in = null;
            String line = null;
            try {
                in = new BufferedReader(new FileReader(getSettingsProblemFile()));
                while ((line = in.readLine()) != null) {
                    if (line.contains("ignored: updated version"))
                        continue;
                    pw.println(line);
                }
            } catch (IOException ignored) {
            } finally {
                IoUtils.closeQuietly(in);
            }
        }
        if (checkin && dumpState.isDumping(DumpState.DUMP_MESSAGES)) {
            BufferedReader in = null;
            String line = null;
            try {
                in = new BufferedReader(new FileReader(getSettingsProblemFile()));
                while ((line = in.readLine()) != null) {
                    if (line.contains("ignored: updated version"))
                        continue;
                    pw.print("msg,");
                    pw.println(line);
                }
            } catch (IOException ignored) {
            } finally {
                IoUtils.closeQuietly(in);
            }
        }
    }
}
Also used : FeatureInfo(android.content.pm.FeatureInfo) FileReader(java.io.FileReader) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) PackageParser(android.content.pm.PackageParser) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) IntentFilterVerificationInfo(android.content.pm.IntentFilterVerificationInfo) Map(java.util.Map) ArrayMap(android.util.ArrayMap) HashMap(java.util.HashMap) IndentingPrintWriter(com.android.internal.util.IndentingPrintWriter) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 8 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class PackageManagerService method getPreferredActivityBackup.

/**
     * Non-Binder method, support for the backup/restore mechanism: write the
     * full set of preferred activities in its canonical XML format.  Returns the
     * XML output as a byte array, or null if there is none.
     */
@Override
public byte[] getPreferredActivityBackup(int userId) {
    if (Binder.getCallingUid() != Process.SYSTEM_UID) {
        throw new SecurityException("Only the system may call getPreferredActivityBackup()");
    }
    ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    try {
        final XmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(dataStream, StandardCharsets.UTF_8.name());
        serializer.startDocument(null, true);
        serializer.startTag(null, TAG_PREFERRED_BACKUP);
        synchronized (mPackages) {
            mSettings.writePreferredActivitiesLPr(serializer, userId, true);
        }
        serializer.endTag(null, TAG_PREFERRED_BACKUP);
        serializer.endDocument();
        serializer.flush();
    } catch (Exception e) {
        if (DEBUG_BACKUP) {
            Slog.e(TAG, "Unable to write preferred activities for backup", e);
        }
        return null;
    }
    return dataStream.toByteArray();
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CertificateEncodingException(java.security.cert.CertificateEncodingException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) PackageParserException(android.content.pm.PackageParser.PackageParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InstallerException(com.android.server.pm.Installer.InstallerException) SendIntentException(android.content.IntentSender.SendIntentException) FileNotFoundException(java.io.FileNotFoundException) CertificateException(java.security.cert.CertificateException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 9 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class PackageManagerService method getPermissionGrantBackup.

@Override
public byte[] getPermissionGrantBackup(int userId) {
    if (Binder.getCallingUid() != Process.SYSTEM_UID) {
        throw new SecurityException("Only the system may call getPermissionGrantBackup()");
    }
    ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    try {
        final XmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(dataStream, StandardCharsets.UTF_8.name());
        serializer.startDocument(null, true);
        serializer.startTag(null, TAG_PERMISSION_BACKUP);
        synchronized (mPackages) {
            serializeRuntimePermissionGrantsLPr(serializer, userId);
        }
        serializer.endTag(null, TAG_PERMISSION_BACKUP);
        serializer.endDocument();
        serializer.flush();
    } catch (Exception e) {
        if (DEBUG_BACKUP) {
            Slog.e(TAG, "Unable to write default apps for backup", e);
        }
        return null;
    }
    return dataStream.toByteArray();
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CertificateEncodingException(java.security.cert.CertificateEncodingException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) PackageParserException(android.content.pm.PackageParser.PackageParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InstallerException(com.android.server.pm.Installer.InstallerException) SendIntentException(android.content.IntentSender.SendIntentException) FileNotFoundException(java.io.FileNotFoundException) CertificateException(java.security.cert.CertificateException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 10 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project platform_frameworks_base by android.

the class PackageManagerService method getIntentFilterVerificationBackup.

@Override
public byte[] getIntentFilterVerificationBackup(int userId) {
    if (Binder.getCallingUid() != Process.SYSTEM_UID) {
        throw new SecurityException("Only the system may call getIntentFilterVerificationBackup()");
    }
    ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
    try {
        final XmlSerializer serializer = new FastXmlSerializer();
        serializer.setOutput(dataStream, StandardCharsets.UTF_8.name());
        serializer.startDocument(null, true);
        serializer.startTag(null, TAG_INTENT_FILTER_VERIFICATION);
        synchronized (mPackages) {
            mSettings.writeAllDomainVerificationsLPr(serializer, userId);
        }
        serializer.endTag(null, TAG_INTENT_FILTER_VERIFICATION);
        serializer.endDocument();
        serializer.flush();
    } catch (Exception e) {
        if (DEBUG_BACKUP) {
            Slog.e(TAG, "Unable to write default apps for backup", e);
        }
        return null;
    }
    return dataStream.toByteArray();
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CertificateEncodingException(java.security.cert.CertificateEncodingException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) PackageParserException(android.content.pm.PackageParser.PackageParserException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InstallerException(com.android.server.pm.Installer.InstallerException) SendIntentException(android.content.IntentSender.SendIntentException) FileNotFoundException(java.io.FileNotFoundException) CertificateException(java.security.cert.CertificateException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Aggregations

FastXmlSerializer (com.android.internal.util.FastXmlSerializer)169 XmlSerializer (org.xmlpull.v1.XmlSerializer)156 IOException (java.io.IOException)138 FileOutputStream (java.io.FileOutputStream)132 BufferedOutputStream (java.io.BufferedOutputStream)56 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)35 RemoteException (android.os.RemoteException)29 AtomicFile (android.util.AtomicFile)28 FileNotFoundException (java.io.FileNotFoundException)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 Map (java.util.Map)22 ErrnoException (android.system.ErrnoException)20 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)15 JournaledFile (com.android.internal.util.JournaledFile)15 File (java.io.File)13 HashMap (java.util.HashMap)11 UserInfo (android.content.pm.UserInfo)9 SendIntentException (android.content.IntentSender.SendIntentException)8 PackageParserException (android.content.pm.PackageParser.PackageParserException)8 Point (android.graphics.Point)8