Search in sources :

Example 1 with VisibleForTesting

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

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) 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 (limitUid == UID_ALL || limitUid == entry.uid) {
                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 2 with VisibleForTesting

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

the class MountService method buildObbPath.

@VisibleForTesting
public static String buildObbPath(final String canonicalPath, int userId, boolean forVold) {
    // Only adjust paths when storage is emulated
    if (!Environment.isExternalStorageEmulated()) {
        return canonicalPath;
    }
    String path = canonicalPath.toString();
    // First trim off any external storage prefix
    final UserEnvironment userEnv = new UserEnvironment(userId);
    // /storage/emulated/0
    final String externalPath = userEnv.getExternalStorageDirectory().toString();
    // /storage/emulated_legacy
    final String legacyExternalPath = Environment.getLegacyExternalStorageDirectory().toString();
    if (path.startsWith(externalPath)) {
        path = path.substring(externalPath.length() + 1);
    } else if (path.startsWith(legacyExternalPath)) {
        path = path.substring(legacyExternalPath.length() + 1);
    } else {
        return canonicalPath;
    }
    // Handle special OBB paths on emulated storage
    final String obbPath = "Android/obb";
    if (path.startsWith(obbPath)) {
        path = path.substring(obbPath.length() + 1);
        if (forVold) {
            return new File(Environment.getEmulatedStorageObbSource(), path).toString();
        } else {
            final UserEnvironment ownerEnv = new UserEnvironment(UserHandle.USER_OWNER);
            return new File(ownerEnv.getExternalStorageObbDirectory(), path).toString();
        }
    }
    // Handle normal external storage paths
    if (forVold) {
        return new File(Environment.getEmulatedStorageSource(userId), path).toString();
    } else {
        return new File(userEnv.getExternalStorageDirectory(), path).toString();
    }
}
Also used : UserEnvironment(android.os.Environment.UserEnvironment) File(java.io.File) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 3 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class AccountManagerService method getPreNDatabaseName.

@VisibleForTesting
String getPreNDatabaseName(int userId) {
    File systemDir = Environment.getDataSystemDirectory();
    File databaseFile = new File(Environment.getUserSystemDirectory(userId), PRE_N_DATABASE_NAME);
    if (userId == 0) {
        // Migrate old file, if it exists, to the new location.
        // Make sure the new file doesn't already exist. A dummy file could have been
        // accidentally created in the old location, causing the new one to become corrupted
        // as well.
        File oldFile = new File(systemDir, PRE_N_DATABASE_NAME);
        if (oldFile.exists() && !databaseFile.exists()) {
            // Check for use directory; create if it doesn't exist, else renameTo will fail
            File userDir = Environment.getUserSystemDirectory(userId);
            if (!userDir.exists()) {
                if (!userDir.mkdirs()) {
                    throw new IllegalStateException("User dir cannot be created: " + userDir);
                }
            }
            if (!oldFile.renameTo(databaseFile)) {
                throw new IllegalStateException("User dir cannot be migrated: " + databaseFile);
            }
        }
    }
    return databaseFile.getPath();
}
Also used : File(java.io.File) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 4 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class NetworkScoreService method refreshRecommendationRequestTimeoutMs.

@VisibleForTesting
public void refreshRecommendationRequestTimeoutMs() {
    final ContentResolver cr = mContext.getContentResolver();
    long timeoutMs = Settings.Global.getLong(cr, Global.NETWORK_RECOMMENDATION_REQUEST_TIMEOUT_MS, -1L);
    if (timeoutMs < 0) {
        timeoutMs = TimedRemoteCaller.DEFAULT_CALL_TIMEOUT_MILLIS;
    }
    if (DBG)
        Log.d(TAG, "Updating the recommendation request timeout to " + timeoutMs + " ms");
    mRecommendationRequestTimeoutMs = timeoutMs;
    mReqRecommendationCallerRef.set(new RequestRecommendationCaller(timeoutMs));
}
Also used : ContentResolver(android.content.ContentResolver) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 5 with VisibleForTesting

use of com.android.internal.annotations.VisibleForTesting in project platform_frameworks_base by android.

the class InputMethodUtils method parseInputMethodsAndSubtypesString.

/**
     * Parses the setting stored input methods and subtypes string value.
     *
     * @param inputMethodsAndSubtypesString The input method subtypes value stored in settings.
     * @return Map from input method ID to set of input method subtypes IDs.
     */
@VisibleForTesting
public static ArrayMap<String, ArraySet<String>> parseInputMethodsAndSubtypesString(@Nullable final String inputMethodsAndSubtypesString) {
    final ArrayMap<String, ArraySet<String>> imeMap = new ArrayMap<>();
    if (TextUtils.isEmpty(inputMethodsAndSubtypesString)) {
        return imeMap;
    }
    final SimpleStringSplitter typeSplitter = new SimpleStringSplitter(INPUT_METHOD_SEPARATOR);
    final SimpleStringSplitter subtypeSplitter = new SimpleStringSplitter(INPUT_METHOD_SUBTYPE_SEPARATOR);
    List<Pair<String, ArrayList<String>>> allImeSettings = InputMethodSettings.buildInputMethodsAndSubtypeList(inputMethodsAndSubtypesString, typeSplitter, subtypeSplitter);
    for (Pair<String, ArrayList<String>> ime : allImeSettings) {
        ArraySet<String> subtypes = new ArraySet<>();
        if (ime.second != null) {
            subtypes.addAll(ime.second);
        }
        imeMap.put(ime.first, subtypes);
    }
    return imeMap;
}
Also used : ArraySet(android.util.ArraySet) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) SimpleStringSplitter(android.text.TextUtils.SimpleStringSplitter) Pair(android.util.Pair) 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