Search in sources :

Example 61 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by crdroidandroid.

the class UserManagerService method readApplicationRestrictionsLP.

@VisibleForTesting
static Bundle readApplicationRestrictionsLP(AtomicFile restrictionsFile) {
    final Bundle restrictions = new Bundle();
    final ArrayList<String> values = new ArrayList<>();
    if (!restrictionsFile.getBaseFile().exists()) {
        return restrictions;
    }
    FileInputStream fis = null;
    try {
        fis = restrictionsFile.openRead();
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(fis, StandardCharsets.UTF_8.name());
        XmlUtils.nextElement(parser);
        if (parser.getEventType() != XmlPullParser.START_TAG) {
            Slog.e(LOG_TAG, "Unable to read restrictions file " + restrictionsFile.getBaseFile());
            return restrictions;
        }
        while (parser.next() != XmlPullParser.END_DOCUMENT) {
            readEntry(restrictions, values, parser);
        }
    } catch (IOException | XmlPullParserException e) {
        Log.w(LOG_TAG, "Error parsing " + restrictionsFile.getBaseFile(), e);
    } finally {
        IoUtils.closeQuietly(fis);
    }
    return restrictions;
}
Also used : Bundle(android.os.Bundle) PersistableBundle(android.os.PersistableBundle) ArrayList(java.util.ArrayList) XmlPullParser(org.xmlpull.v1.XmlPullParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 62 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by crdroidandroid.

the class NetworkStatsObservers method getHandlerLooperLocked.

@VisibleForTesting
protected Looper getHandlerLooperLocked() {
    HandlerThread handlerThread = new HandlerThread(TAG);
    handlerThread.start();
    return handlerThread.getLooper();
}
Also used : HandlerThread(android.os.HandlerThread) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 63 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by AOSPA.

the class NetworkStatsFactory method javaReadNetworkStatsDetail.

/**
     * Parse and return {@link NetworkStats} with UID-level details. Values are
     * expected to monotonically increase since device boot.
     */
@VisibleForTesting
public static NetworkStats javaReadNetworkStatsDetail(File detailPath, int limitUid, String[] limitIfaces, int limitTag) throws IOException {
    final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
    final NetworkStats stats = new NetworkStats(SystemClock.elapsedRealtime(), 24);
    final NetworkStats.Entry entry = new NetworkStats.Entry();
    int idx = 1;
    int lastIdx = 1;
    ProcFileReader reader = null;
    try {
        // open and consume header line
        reader = new ProcFileReader(new FileInputStream(detailPath));
        reader.finishLine();
        while (reader.hasMoreData()) {
            idx = reader.nextInt();
            if (idx != lastIdx + 1) {
                throw new ProtocolException("inconsistent idx=" + idx + " after lastIdx=" + lastIdx);
            }
            lastIdx = idx;
            entry.iface = reader.nextString();
            entry.tag = kernelToTag(reader.nextString());
            entry.uid = reader.nextInt();
            entry.set = reader.nextInt();
            entry.rxBytes = reader.nextLong();
            entry.rxPackets = reader.nextLong();
            entry.txBytes = reader.nextLong();
            entry.txPackets = reader.nextLong();
            if ((limitIfaces == null || ArrayUtils.contains(limitIfaces, entry.iface)) && (limitUid == UID_ALL || limitUid == entry.uid) && (limitTag == TAG_ALL || limitTag == entry.tag)) {
                stats.addValues(entry);
            }
            reader.finishLine();
        }
    } catch (NullPointerException e) {
        throw new ProtocolException("problem parsing idx " + idx, e);
    } catch (NumberFormatException e) {
        throw new ProtocolException("problem parsing idx " + idx, e);
    } finally {
        IoUtils.closeQuietly(reader);
        StrictMode.setThreadPolicy(savedPolicy);
    }
    return stats;
}
Also used : StrictMode(android.os.StrictMode) ProcFileReader(com.android.internal.util.ProcFileReader) ProtocolException(java.net.ProtocolException) NetworkStats(android.net.NetworkStats) FileInputStream(java.io.FileInputStream) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 64 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by AOSPA.

the class RegisteredServicesCache method parseServiceInfo.

@VisibleForTesting
protected ServiceInfo<V> parseServiceInfo(ResolveInfo service) throws XmlPullParserException, IOException {
    android.content.pm.ServiceInfo si = service.serviceInfo;
    ComponentName componentName = new ComponentName(si.packageName, si.name);
    PackageManager pm = mContext.getPackageManager();
    XmlResourceParser parser = null;
    try {
        parser = si.loadXmlMetaData(pm, mMetaDataName);
        if (parser == null) {
            throw new XmlPullParserException("No " + mMetaDataName + " meta-data");
        }
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        }
        String nodeName = parser.getName();
        if (!mAttributesName.equals(nodeName)) {
            throw new XmlPullParserException("Meta-data does not start with " + mAttributesName + " tag");
        }
        V v = parseServiceAttributes(pm.getResourcesForApplication(si.applicationInfo), si.packageName, attrs);
        if (v == null) {
            return null;
        }
        final android.content.pm.ServiceInfo serviceInfo = service.serviceInfo;
        return new ServiceInfo<V>(v, serviceInfo, componentName);
    } catch (NameNotFoundException e) {
        throw new XmlPullParserException("Unable to load resources for pacakge " + si.packageName);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) AttributeSet(android.util.AttributeSet) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 65 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by AOSPA.

the class TaskPersister method writePersistedTaskIdsForUser.

@VisibleForTesting
void writePersistedTaskIdsForUser(@NonNull SparseBooleanArray taskIds, int userId) {
    if (userId < 0) {
        return;
    }
    final File persistedTaskIdsFile = getUserPersistedTaskIdsFile(userId);
    synchronized (mIoLock) {
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(persistedTaskIdsFile));
            for (int i = 0; i < taskIds.size(); i++) {
                if (taskIds.valueAt(i)) {
                    writer.write(String.valueOf(taskIds.keyAt(i)));
                    writer.newLine();
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Error while writing taskIds file for user " + userId, e);
        } finally {
            IoUtils.closeQuietly(writer);
        }
    }
}
Also used : FileWriter(java.io.FileWriter) AtomicFile(android.util.AtomicFile) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) BufferedWriter(java.io.BufferedWriter) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.android.internal.annotations.VisibleForTesting)141 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)26 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)18 ComponentName (android.content.ComponentName)15 File (java.io.File)14 RemoteException (android.os.RemoteException)13 ArraySet (android.util.ArraySet)10 AtomicFile (android.util.AtomicFile)10 FileInputStream (java.io.FileInputStream)10 Locale (java.util.Locale)10 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)9 FileNotFoundException (java.io.FileNotFoundException)9 Notification (android.app.Notification)6 ErrnoException (android.system.ErrnoException)6 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)6 FileOutputStream (java.io.FileOutputStream)6 XmlSerializer (org.xmlpull.v1.XmlSerializer)6 ITransientNotification (android.app.ITransientNotification)5 UserInfo (android.content.pm.UserInfo)5