Search in sources :

Example 71 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class AppOpsService method writeState.

void writeState() {
    synchronized (mFile) {
        FileOutputStream stream;
        try {
            stream = mFile.startWrite();
        } catch (IOException e) {
            Slog.w(TAG, "Failed to write state: " + e);
            return;
        }
        SparseArray<UidState> outUidStates = null;
        synchronized (this) {
            final int uidStateCount = mUidStates.size();
            for (int i = 0; i < uidStateCount; i++) {
                UidState uidState = mUidStates.valueAt(i);
                SparseIntArray opModes = uidState.opModes;
                if (opModes != null && opModes.size() > 0) {
                    UidState outUidState = new UidState(uidState.uid);
                    outUidState.opModes = opModes.clone();
                    if (outUidStates == null) {
                        outUidStates = new SparseArray<>();
                    }
                    outUidStates.put(mUidStates.keyAt(i), outUidState);
                }
            }
        }
        List<AppOpsManager.PackageOps> allOps = getPackagesForOps(null);
        try {
            XmlSerializer out = new FastXmlSerializer();
            out.setOutput(stream, StandardCharsets.UTF_8.name());
            out.startDocument(null, true);
            out.startTag(null, "app-ops");
            final int uidStateCount = outUidStates != null ? outUidStates.size() : 0;
            for (int i = 0; i < uidStateCount; i++) {
                UidState uidState = outUidStates.valueAt(i);
                if (uidState.opModes != null && uidState.opModes.size() > 0) {
                    out.startTag(null, "uid");
                    out.attribute(null, "n", Integer.toString(uidState.uid));
                    SparseIntArray uidOpModes = uidState.opModes;
                    final int opCount = uidOpModes.size();
                    for (int j = 0; j < opCount; j++) {
                        final int op = uidOpModes.keyAt(j);
                        final int mode = uidOpModes.valueAt(j);
                        out.startTag(null, "op");
                        out.attribute(null, "n", Integer.toString(op));
                        out.attribute(null, "m", Integer.toString(mode));
                        out.endTag(null, "op");
                    }
                    out.endTag(null, "uid");
                }
            }
            if (allOps != null) {
                String lastPkg = null;
                for (int i = 0; i < allOps.size(); i++) {
                    AppOpsManager.PackageOps pkg = allOps.get(i);
                    if (!pkg.getPackageName().equals(lastPkg)) {
                        if (lastPkg != null) {
                            out.endTag(null, "pkg");
                        }
                        lastPkg = pkg.getPackageName();
                        out.startTag(null, "pkg");
                        out.attribute(null, "n", lastPkg);
                    }
                    out.startTag(null, "uid");
                    out.attribute(null, "n", Integer.toString(pkg.getUid()));
                    synchronized (this) {
                        Ops ops = getOpsRawLocked(pkg.getUid(), pkg.getPackageName(), false);
                        // from Ops.
                        if (ops != null) {
                            out.attribute(null, "p", Boolean.toString(ops.isPrivileged));
                        } else {
                            out.attribute(null, "p", Boolean.toString(false));
                        }
                    }
                    List<AppOpsManager.OpEntry> ops = pkg.getOps();
                    for (int j = 0; j < ops.size(); j++) {
                        AppOpsManager.OpEntry op = ops.get(j);
                        out.startTag(null, "op");
                        out.attribute(null, "n", Integer.toString(op.getOp()));
                        out.attribute(null, "ns", AppOpsManager.opToName(op.getOp()));
                        int defaultMode = getDefaultMode(op.getOp(), pkg.getUid(), pkg.getPackageName());
                        if (op.getMode() != defaultMode) {
                            out.attribute(null, "m", Integer.toString(op.getMode()));
                        } else {
                            out.attribute(null, "dm", Integer.toString(defaultMode));
                        }
                        long time = op.getTime();
                        if (time != 0) {
                            out.attribute(null, "t", Long.toString(time));
                        }
                        time = op.getRejectTime();
                        if (time != 0) {
                            out.attribute(null, "r", Long.toString(time));
                        }
                        int dur = op.getDuration();
                        if (dur != 0) {
                            out.attribute(null, "d", Integer.toString(dur));
                        }
                        int proxyUid = op.getProxyUid();
                        if (proxyUid != -1) {
                            out.attribute(null, "pu", Integer.toString(proxyUid));
                        }
                        String proxyPackageName = op.getProxyPackageName();
                        if (proxyPackageName != null) {
                            out.attribute(null, "pp", proxyPackageName);
                        }
                        int allowed = op.getAllowedCount();
                        if (allowed != 0) {
                            out.attribute(null, "ac", Integer.toString(allowed));
                        }
                        int ignored = op.getIgnoredCount();
                        if (ignored != 0) {
                            out.attribute(null, "ic", Integer.toString(ignored));
                        }
                        out.endTag(null, "op");
                    }
                    out.endTag(null, "uid");
                }
                if (lastPkg != null) {
                    out.endTag(null, "pkg");
                }
            }
            out.endTag(null, "app-ops");
            out.endDocument();
            mFile.finishWrite(stream);
        } catch (IOException e) {
            Slog.w(TAG, "Failed to write state, restoring backup.", e);
            mFile.failWrite(stream);
        }
    }
}
Also used : IOException(java.io.IOException) AppOpsManager(android.app.AppOpsManager) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) SparseIntArray(android.util.SparseIntArray) FileOutputStream(java.io.FileOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 72 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class PackageInstallerService method writeSessionsLocked.

private void writeSessionsLocked() {
    if (LOGD)
        Slog.v(TAG, "writeSessionsLocked()");
    FileOutputStream fos = null;
    try {
        fos = mSessionsFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_SESSIONS);
        final int size = mSessions.size();
        for (int i = 0; i < size; i++) {
            final PackageInstallerSession session = mSessions.valueAt(i);
            writeSessionLocked(out, session);
        }
        out.endTag(null, TAG_SESSIONS);
        out.endDocument();
        mSessionsFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mSessionsFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) IPackageInstallerSession(android.content.pm.IPackageInstallerSession) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 73 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class MountService method writeSettingsLocked.

private void writeSettingsLocked() {
    FileOutputStream fos = null;
    try {
        fos = mSettingsFile.startWrite();
        XmlSerializer out = new FastXmlSerializer();
        out.setOutput(fos, StandardCharsets.UTF_8.name());
        out.startDocument(null, true);
        out.startTag(null, TAG_VOLUMES);
        writeIntAttribute(out, ATTR_VERSION, VERSION_FIX_PRIMARY);
        writeStringAttribute(out, ATTR_PRIMARY_STORAGE_UUID, mPrimaryStorageUuid);
        writeBooleanAttribute(out, ATTR_FORCE_ADOPTABLE, mForceAdoptable);
        final int size = mRecords.size();
        for (int i = 0; i < size; i++) {
            final VolumeRecord rec = mRecords.valueAt(i);
            writeVolumeRecord(out, rec);
        }
        out.endTag(null, TAG_VOLUMES);
        out.endDocument();
        mSettingsFile.finishWrite(fos);
    } catch (IOException e) {
        if (fos != null) {
            mSettingsFile.failWrite(fos);
        }
    }
}
Also used : VolumeRecord(android.os.storage.VolumeRecord) FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 74 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class SyncStorageEngine method writeAccountInfoLocked.

/**
     * Write all account information to the account file.
     */
private void writeAccountInfoLocked() {
    if (Log.isLoggable(TAG_FILE, Log.VERBOSE)) {
        Slog.v(TAG_FILE, "Writing new " + mAccountInfoFile.getBaseFile());
    }
    FileOutputStream fos = null;
    try {
        fos = mAccountInfoFile.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, "accounts");
        out.attribute(null, "version", Integer.toString(ACCOUNTS_VERSION));
        out.attribute(null, XML_ATTR_NEXT_AUTHORITY_ID, Integer.toString(mNextAuthorityId));
        out.attribute(null, XML_ATTR_SYNC_RANDOM_OFFSET, Integer.toString(mSyncRandomOffset));
        // Write the Sync Automatically flags for each user
        final int M = mMasterSyncAutomatically.size();
        for (int m = 0; m < M; m++) {
            int userId = mMasterSyncAutomatically.keyAt(m);
            Boolean listen = mMasterSyncAutomatically.valueAt(m);
            out.startTag(null, XML_TAG_LISTEN_FOR_TICKLES);
            out.attribute(null, XML_ATTR_USER, Integer.toString(userId));
            out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(listen));
            out.endTag(null, XML_TAG_LISTEN_FOR_TICKLES);
        }
        final int N = mAuthorities.size();
        for (int i = 0; i < N; i++) {
            AuthorityInfo authority = mAuthorities.valueAt(i);
            EndPoint info = authority.target;
            out.startTag(null, "authority");
            out.attribute(null, "id", Integer.toString(authority.ident));
            out.attribute(null, XML_ATTR_USER, Integer.toString(info.userId));
            out.attribute(null, XML_ATTR_ENABLED, Boolean.toString(authority.enabled));
            out.attribute(null, "account", info.account.name);
            out.attribute(null, "type", info.account.type);
            out.attribute(null, "authority", info.provider);
            out.attribute(null, "syncable", Integer.toString(authority.syncable));
            out.endTag(null, "authority");
        }
        out.endTag(null, "accounts");
        out.endDocument();
        mAccountInfoFile.finishWrite(fos);
    } catch (java.io.IOException e1) {
        Slog.w(TAG, "Error writing accounts", e1);
        if (fos != null) {
            mAccountInfoFile.failWrite(fos);
        }
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) FileOutputStream(java.io.FileOutputStream) XmlSerializer(org.xmlpull.v1.XmlSerializer) FastXmlSerializer(com.android.internal.util.FastXmlSerializer)

Example 75 with FastXmlSerializer

use of com.android.internal.util.FastXmlSerializer in project android_frameworks_base by crdroidandroid.

the class AppIdleHistory method writeAppIdleTimesLocked.

public void writeAppIdleTimesLocked(int userId) {
    FileOutputStream fos = null;
    AtomicFile appIdleFile = new AtomicFile(getUserFile(userId));
    try {
        fos = appIdleFile.startWrite();
        final BufferedOutputStream bos = new BufferedOutputStream(fos);
        FastXmlSerializer xml = new FastXmlSerializer();
        xml.setOutput(bos, StandardCharsets.UTF_8.name());
        xml.startDocument(null, true);
        xml.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        xml.startTag(null, TAG_PACKAGES);
        ArrayMap<String, PackageHistory> userHistory = getUserHistoryLocked(userId);
        final int N = userHistory.size();
        for (int i = 0; i < N; i++) {
            String packageName = userHistory.keyAt(i);
            PackageHistory history = userHistory.valueAt(i);
            xml.startTag(null, TAG_PACKAGE);
            xml.attribute(null, ATTR_NAME, packageName);
            xml.attribute(null, ATTR_ELAPSED_IDLE, Long.toString(history.lastUsedElapsedTime));
            xml.attribute(null, ATTR_SCREEN_IDLE, Long.toString(history.lastUsedScreenTime));
            xml.endTag(null, TAG_PACKAGE);
        }
        xml.endTag(null, TAG_PACKAGES);
        xml.endDocument();
        appIdleFile.finishWrite(fos);
    } catch (Exception e) {
        appIdleFile.failWrite(fos);
        Slog.e(TAG, "Error writing app idle file for user " + userId);
    }
}
Also used : FastXmlSerializer(com.android.internal.util.FastXmlSerializer) AtomicFile(android.util.AtomicFile) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

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