use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by DirtyUnicorns.
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;
}
use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by DirtyUnicorns.
the class ShortcutService method openIconFileForWrite.
/**
* Build the cached bitmap filename for a shortcut icon.
*
* The filename will be based on the ID, except certain characters will be escaped.
*/
@VisibleForTesting
FileOutputStreamWithPath openIconFileForWrite(@UserIdInt int userId, ShortcutInfo shortcut) throws IOException {
final File packagePath = new File(getUserBitmapFilePath(userId), shortcut.getPackage());
if (!packagePath.isDirectory()) {
packagePath.mkdirs();
if (!packagePath.isDirectory()) {
throw new IOException("Unable to create directory " + packagePath);
}
SELinux.restorecon(packagePath);
}
final String baseName = String.valueOf(injectCurrentTimeMillis());
for (int suffix = 0; ; suffix++) {
final String filename = (suffix == 0 ? baseName : baseName + "_" + suffix) + ".png";
final File file = new File(packagePath, filename);
if (!file.exists()) {
if (DEBUG) {
Slog.d(TAG, "Saving icon to " + file.getAbsolutePath());
}
return new FileOutputStreamWithPath(file);
}
}
}
use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by DirtyUnicorns.
the class InputMethodUtils method getImplicitlyApplicableSubtypesLocked.
@VisibleForTesting
public static ArrayList<InputMethodSubtype> getImplicitlyApplicableSubtypesLocked(Resources res, InputMethodInfo imi) {
final LocaleList systemLocales = res.getConfiguration().getLocales();
synchronized (sCacheLock) {
// it does not check if subtypes are also identical.
if (systemLocales.equals(sCachedSystemLocales) && sCachedInputMethodInfo == imi) {
return new ArrayList<>(sCachedResult);
}
}
// Note: Only resource info in "res" is used in getImplicitlyApplicableSubtypesLockedImpl().
// TODO: Refactor getImplicitlyApplicableSubtypesLockedImpl() so that it can receive
// LocaleList rather than Resource.
final ArrayList<InputMethodSubtype> result = getImplicitlyApplicableSubtypesLockedImpl(res, imi);
synchronized (sCacheLock) {
// Both LocaleList and InputMethodInfo are immutable. No need to copy them here.
sCachedSystemLocales = systemLocales;
sCachedInputMethodInfo = imi;
sCachedResult = new ArrayList<>(result);
}
return result;
}
use of com.android.internal.annotations.VisibleForTesting 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;
}
use of com.android.internal.annotations.VisibleForTesting in project android_frameworks_base by DirtyUnicorns.
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();
}
Aggregations