Search in sources :

Example 51 with ProtocolException

use of java.net.ProtocolException in project android_frameworks_base by DirtyUnicorns.

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 52 with ProtocolException

use of java.net.ProtocolException in project android_frameworks_base by DirtyUnicorns.

the class IconCache method notifyIconReceived.

public void notifyIconReceived(long bssid, String fileName, byte[] iconData) {
    Log.d("ZXZ", String.format("Icon '%s':%d received from %012x", fileName, iconData != null ? iconData.length : -1, bssid));
    IconKey key;
    HSIconFileElement iconFileElement = null;
    List<OSUInfo> updates = new ArrayList<>();
    LinkedList<QuerySet> querySets = mBssQueues.get(bssid);
    if (querySets == null || querySets.isEmpty()) {
        Log.d(OSUManager.TAG, String.format("Spurious icon response from %012x for '%s' (%d) bytes", bssid, fileName, iconData != null ? iconData.length : -1));
        Log.d("ZXZ", "query set: " + querySets + ", BSS queues: " + Utils.bssidsToString(mBssQueues.keySet()));
        return;
    } else {
        QuerySet querySet = querySets.removeFirst();
        if (iconData != null) {
            try {
                iconFileElement = new HSIconFileElement(HSIconFile, ByteBuffer.wrap(iconData).order(ByteOrder.LITTLE_ENDIAN));
            } catch (ProtocolException | BufferUnderflowException e) {
                Log.e(OSUManager.TAG, "Failed to parse ANQP icon file: " + e);
            }
        }
        key = querySet.updateIcon(fileName, iconFileElement);
        if (key == null) {
            Log.d(OSUManager.TAG, String.format("Spurious icon response from %012x for '%s' (%d) bytes", bssid, fileName, iconData != null ? iconData.length : -1));
            Log.d("ZXZ", "query set: " + querySets + ", BSS queues: " + Utils.bssidsToString(mBssQueues.keySet()));
            querySets.addFirst(querySet);
            return;
        }
        if (iconFileElement != null) {
            mCache.put(key, iconFileElement);
        }
        if (querySet.isEmpty()) {
            mBssQueues.remove(bssid);
        }
        updates.add(querySet.getOsuInfo());
    }
    // Update any other pending entries that matches the ESS of the currently resolved icon
    Iterator<Map.Entry<Long, LinkedList<QuerySet>>> bssIterator = mBssQueues.entrySet().iterator();
    while (bssIterator.hasNext()) {
        Map.Entry<Long, LinkedList<QuerySet>> bssEntries = bssIterator.next();
        Iterator<QuerySet> querySetIterator = bssEntries.getValue().iterator();
        while (querySetIterator.hasNext()) {
            QuerySet querySet = querySetIterator.next();
            if (querySet.updateIcon(key, iconFileElement)) {
                querySetIterator.remove();
                updates.add(querySet.getOsuInfo());
            }
        }
        if (bssEntries.getValue().isEmpty()) {
            bssIterator.remove();
        }
    }
    initiateQuery(bssid);
    mOSUManager.iconResults(updates);
}
Also used : ProtocolException(java.net.ProtocolException) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) HSIconFileElement(com.android.anqp.HSIconFileElement) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 53 with ProtocolException

use of java.net.ProtocolException in project android_frameworks_base by DirtyUnicorns.

the class OSUCache method putResult.

private void putResult(ScanResult scanResult, AnqpInformationElement[] elements) {
    for (AnqpInformationElement ie : elements) {
        if (ie.getElementId() == AnqpInformationElement.HS_OSU_PROVIDERS && ie.getVendorId() == AnqpInformationElement.HOTSPOT20_VENDOR_ID) {
            try {
                HSOsuProvidersElement providers = new HSOsuProvidersElement(Constants.ANQPElementType.HSOSUProviders, ByteBuffer.wrap(ie.getPayload()).order(ByteOrder.LITTLE_ENDIAN));
                putProviders(scanResult, providers);
            } catch (ProtocolException pe) {
                Log.w(OSUManager.TAG, "Failed to parse OSU element: " + pe);
            }
        }
    }
}
Also used : ProtocolException(java.net.ProtocolException) AnqpInformationElement(android.net.wifi.AnqpInformationElement) HSOsuProvidersElement(com.android.anqp.HSOsuProvidersElement)

Example 54 with ProtocolException

use of java.net.ProtocolException in project android_frameworks_base by DirtyUnicorns.

the class NetworkStatsCollection method read.

public void read(DataInputStream in) throws IOException {
    // verify file magic header intact
    final int magic = in.readInt();
    if (magic != FILE_MAGIC) {
        throw new ProtocolException("unexpected magic: " + magic);
    }
    final int version = in.readInt();
    switch(version) {
        case VERSION_UNIFIED_INIT:
            {
                // uid := size *(NetworkIdentitySet size *(uid set tag NetworkStatsHistory))
                final int identSize = in.readInt();
                for (int i = 0; i < identSize; i++) {
                    final NetworkIdentitySet ident = new NetworkIdentitySet(in);
                    final int size = in.readInt();
                    for (int j = 0; j < size; j++) {
                        final int uid = in.readInt();
                        final int set = in.readInt();
                        final int tag = in.readInt();
                        final Key key = new Key(ident, uid, set, tag);
                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
                        recordHistory(key, history);
                    }
                }
                break;
            }
        default:
            {
                throw new ProtocolException("unexpected version: " + version);
            }
    }
}
Also used : ProtocolException(java.net.ProtocolException) NetworkStatsHistory(android.net.NetworkStatsHistory)

Example 55 with ProtocolException

use of java.net.ProtocolException in project android_frameworks_base by DirtyUnicorns.

the class NetworkStatsCollection method readLegacyNetwork.

@Deprecated
public void readLegacyNetwork(File file) throws IOException {
    final AtomicFile inputFile = new AtomicFile(file);
    DataInputStream in = null;
    try {
        in = new DataInputStream(new BufferedInputStream(inputFile.openRead()));
        // verify file magic header intact
        final int magic = in.readInt();
        if (magic != FILE_MAGIC) {
            throw new ProtocolException("unexpected magic: " + magic);
        }
        final int version = in.readInt();
        switch(version) {
            case VERSION_NETWORK_INIT:
                {
                    // network := size *(NetworkIdentitySet NetworkStatsHistory)
                    final int size = in.readInt();
                    for (int i = 0; i < size; i++) {
                        final NetworkIdentitySet ident = new NetworkIdentitySet(in);
                        final NetworkStatsHistory history = new NetworkStatsHistory(in);
                        final Key key = new Key(ident, UID_ALL, SET_ALL, TAG_NONE);
                        recordHistory(key, history);
                    }
                    break;
                }
            default:
                {
                    throw new ProtocolException("unexpected version: " + version);
                }
        }
    } catch (FileNotFoundException e) {
    // missing stats is okay, probably first boot
    } finally {
        IoUtils.closeQuietly(in);
    }
}
Also used : ProtocolException(java.net.ProtocolException) AtomicFile(android.util.AtomicFile) BufferedInputStream(java.io.BufferedInputStream) FileNotFoundException(java.io.FileNotFoundException) NetworkStatsHistory(android.net.NetworkStatsHistory) DataInputStream(java.io.DataInputStream)

Aggregations

ProtocolException (java.net.ProtocolException)153 IOException (java.io.IOException)41 HttpURLConnection (java.net.HttpURLConnection)32 URL (java.net.URL)28 FileInputStream (java.io.FileInputStream)19 NetworkStats (android.net.NetworkStats)18 NetworkStatsHistory (android.net.NetworkStatsHistory)18 StrictMode (android.os.StrictMode)18 ProcFileReader (com.android.internal.util.ProcFileReader)18 BufferedInputStream (java.io.BufferedInputStream)17 FileNotFoundException (java.io.FileNotFoundException)17 MalformedURLException (java.net.MalformedURLException)15 InputStream (java.io.InputStream)13 OutputStream (java.io.OutputStream)13 AtomicFile (android.util.AtomicFile)12 DataInputStream (java.io.DataInputStream)12 Map (java.util.Map)12 Test (org.junit.Test)12 BufferedReader (java.io.BufferedReader)11 InputStreamReader (java.io.InputStreamReader)11