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