diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/java/com/android/server/pm/PackageManagerService.java | 42 | ||||
-rw-r--r-- | services/java/com/android/server/pm/Settings.java | 79 |
2 files changed, 112 insertions, 9 deletions
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index 6643d8c..9a79f86 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -30,6 +30,7 @@ import com.android.internal.app.IMediaContainerService; import com.android.internal.app.ResolverActivity; import com.android.internal.content.NativeLibraryHelper; import com.android.internal.content.PackageHelper; +import com.android.internal.util.FastXmlSerializer; import com.android.internal.util.XmlUtils; import com.android.server.DeviceStorageMonitorService; import com.android.server.EventLogTags; @@ -37,6 +38,7 @@ import com.android.server.IntentResolver; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import org.xmlpull.v1.XmlSerializer; import android.app.ActivityManagerNative; import android.app.IActivityManager; @@ -110,6 +112,7 @@ import android.util.Xml; import android.view.Display; import android.view.WindowManager; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; @@ -8362,6 +8365,10 @@ public class PackageManagerService extends IPackageManager.Stub { public static final int DUMP_VERIFIERS = 1 << 8; + public static final int DUMP_PREFERRED = 1 << 9; + + public static final int DUMP_PREFERRED_XML = 1 << 10; + public static final int OPTION_SHOW_FILTERS = 1 << 0; private int mTypes; @@ -8373,7 +8380,7 @@ public class PackageManagerService extends IPackageManager.Stub { private SharedUserSetting mSharedUser; public boolean isDumping(int type) { - if (mTypes == 0) { + if (mTypes == 0 && type != DUMP_PREFERRED_XML) { return true; } @@ -8450,6 +8457,8 @@ public class PackageManagerService extends IPackageManager.Stub { pw.println(" f[ibraries]: list device features"); pw.println(" r[esolvers]: dump intent resolvers"); pw.println(" perm[issions]: dump permissions"); + pw.println(" pref[erred]: print preferred package settings"); + pw.println(" preferred-xml: 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"); @@ -8479,6 +8488,10 @@ public class PackageManagerService extends IPackageManager.Stub { dumpState.setDump(DumpState.DUMP_RESOLVERS); } else if ("perm".equals(cmd) || "permissions".equals(cmd)) { dumpState.setDump(DumpState.DUMP_PERMISSIONS); + } 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); } else if ("p".equals(cmd) || "packages".equals(cmd)) { dumpState.setDump(DumpState.DUMP_PACKAGES); } else if ("s".equals(cmd) || "shared-users".equals(cmd)) { @@ -8547,6 +8560,9 @@ public class PackageManagerService extends IPackageManager.Stub { dumpState.isOptionEnabled(DumpState.OPTION_SHOW_FILTERS))) { dumpState.setTitlePrinted(true); } + } + + if (dumpState.isDumping(DumpState.DUMP_PREFERRED)) { if (mSettings.mPreferredActivities.dump(pw, dumpState.getTitlePrinted() ? "\nPreferred Activities:" : "Preferred Activities:", " ", @@ -8554,7 +8570,29 @@ public class PackageManagerService extends IPackageManager.Stub { dumpState.setTitlePrinted(true); } } - + + if (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, "utf-8"); + serializer.startDocument(null, true); + serializer.setFeature( + "http://xmlpull.org/v1/doc/features.html#indent-output", true); + mSettings.writePreferredActivitiesLPr(serializer); + 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 (dumpState.isDumping(DumpState.DUMP_PERMISSIONS)) { mSettings.dumpPermissionsLPr(pw, packageName, dumpState); } diff --git a/services/java/com/android/server/pm/Settings.java b/services/java/com/android/server/pm/Settings.java index ffb69fa..91cd458 100644 --- a/services/java/com/android/server/pm/Settings.java +++ b/services/java/com/android/server/pm/Settings.java @@ -1174,13 +1174,7 @@ final class Settings { writeDisabledSysPackageLPr(serializer, pkg); } - serializer.startTag(null, "preferred-activities"); - for (final PreferredActivity pa : mPreferredActivities.filterSet()) { - serializer.startTag(null, TAG_ITEM); - pa.writeToXml(serializer); - serializer.endTag(null, TAG_ITEM); - } - serializer.endTag(null, "preferred-activities"); + writePreferredActivitiesLPr(serializer); for (final SharedUserSetting usr : mSharedUsers.values()) { serializer.startTag(null, "shared-user"); @@ -1306,6 +1300,17 @@ final class Settings { //Debug.stopMethodTracing(); } + void writePreferredActivitiesLPr(XmlSerializer serializer) + throws IllegalArgumentException, IllegalStateException, IOException { + serializer.startTag(null, "preferred-activities"); + for (final PreferredActivity pa : mPreferredActivities.filterSet()) { + serializer.startTag(null, TAG_ITEM); + pa.writeToXml(serializer); + serializer.endTag(null, TAG_ITEM); + } + serializer.endTag(null, "preferred-activities"); + } + void writeDisabledSysPackageLPr(XmlSerializer serializer, final PackageSetting pkg) throws java.io.IOException { serializer.startTag(null, "updated-package"); @@ -1477,6 +1482,7 @@ final class Settings { mReadMessages.append("No settings file found\n"); PackageManagerService.reportSettingsProblem(Log.INFO, "No settings file; creating initial state"); + readDefaultPreferredAppsLPw(); return false; } str = new FileInputStream(mSettingsFilename); @@ -1641,6 +1647,65 @@ final class Settings { return true; } + private void readDefaultPreferredAppsLPw() { + // 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"); + continue; + } + if (!f.canRead()) { + Slog.w(TAG, "Preferred apps file " + f + " cannot be read"); + continue; + } + + FileInputStream str = null; + try { + str = 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; + } + readPreferredActivitiesLPw(parser); + } 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) { + } + } + } + } + } + private int readInt(XmlPullParser parser, String ns, String name, int defValue) { String v = parser.getAttributeValue(ns, name); try { |