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;
}
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();
}
}
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();
}
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));
}
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;
}
Aggregations