use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.
the class NetworkPolicyManagerServiceTest method formatTime.
private static String formatTime(long millis) {
final Time time = new Time(Time.TIMEZONE_UTC);
time.set(millis);
return time.format3339(false);
}
use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.
the class NetworkPolicyManagerServiceTest method parseTime.
private static long parseTime(String time) {
final Time result = new Time();
result.parse3339(time);
return result.toMillis(true);
}
use of android.text.format.Time in project cornerstone by Onskreen.
the class ActivityManagerService method logAppTooSlow.
final void logAppTooSlow(ProcessRecord app, long startTime, String msg) {
if (true || IS_USER_BUILD) {
return;
}
String tracesPath = SystemProperties.get("dalvik.vm.stack-trace-file", null);
if (tracesPath == null || tracesPath.length() == 0) {
return;
}
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
StrictMode.allowThreadDiskWrites();
try {
final File tracesFile = new File(tracesPath);
final File tracesDir = tracesFile.getParentFile();
final File tracesTmp = new File(tracesDir, "__tmp__");
try {
if (!tracesDir.exists())
tracesFile.mkdirs();
// drwxrwxr-x
FileUtils.setPermissions(tracesDir.getPath(), 0775, -1, -1);
if (tracesFile.exists()) {
tracesTmp.delete();
tracesFile.renameTo(tracesTmp);
}
StringBuilder sb = new StringBuilder();
Time tobj = new Time();
tobj.set(System.currentTimeMillis());
sb.append(tobj.format("%Y-%m-%d %H:%M:%S"));
sb.append(": ");
TimeUtils.formatDuration(SystemClock.uptimeMillis() - startTime, sb);
sb.append(" since ");
sb.append(msg);
FileOutputStream fos = new FileOutputStream(tracesFile);
fos.write(sb.toString().getBytes());
if (app == null) {
fos.write("\n*** No application process!".getBytes());
}
fos.close();
// -rw-rw-rw-
FileUtils.setPermissions(tracesFile.getPath(), 0666, -1, -1);
} catch (IOException e) {
Slog.w(TAG, "Unable to prepare slow app traces file: " + tracesPath, e);
return;
}
if (app != null) {
ArrayList<Integer> firstPids = new ArrayList<Integer>();
firstPids.add(app.pid);
dumpStackTraces(tracesPath, firstPids, null, null, null);
}
File lastTracesFile = null;
File curTracesFile = null;
for (int i = 9; i >= 0; i--) {
String name = String.format("slow%02d.txt", i);
curTracesFile = new File(tracesDir, name);
if (curTracesFile.exists()) {
if (lastTracesFile != null) {
curTracesFile.renameTo(lastTracesFile);
} else {
curTracesFile.delete();
}
}
lastTracesFile = curTracesFile;
}
tracesFile.renameTo(curTracesFile);
if (tracesTmp.exists()) {
tracesTmp.renameTo(tracesFile);
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
use of android.text.format.Time in project Android-Developers-Samples by johnjohndoe.
the class FeedParser method readEntry.
/**
* Parses the contents of an entry. If it encounters a title, summary, or link tag, hands them
* off to their respective "read" methods for processing. Otherwise, skips the tag.
*/
private Entry readEntry(XmlPullParser parser) throws XmlPullParserException, IOException, ParseException {
parser.require(XmlPullParser.START_TAG, ns, "entry");
String id = null;
String title = null;
String link = null;
long publishedOn = 0;
while (parser.next() != XmlPullParser.END_TAG) {
if (parser.getEventType() != XmlPullParser.START_TAG) {
continue;
}
String name = parser.getName();
if (name.equals("id")) {
// Example: <id>urn:uuid:218AC159-7F68-4CC6-873F-22AE6017390D</id>
id = readTag(parser, TAG_ID);
} else if (name.equals("title")) {
// Example: <title>Article title</title>
title = readTag(parser, TAG_TITLE);
} else if (name.equals("link")) {
// Example: <link rel="alternate" type="text/html" href="http://example.com/article/1234"/>
//
// Multiple link types can be included. readAlternateLink() will only return
// non-null when reading an "alternate"-type link. Ignore other responses.
String tempLink = readTag(parser, TAG_LINK);
if (tempLink != null) {
link = tempLink;
}
} else if (name.equals("published")) {
// Example: <published>2003-06-27T12:00:00Z</published>
Time t = new Time();
t.parse3339(readTag(parser, TAG_PUBLISHED));
publishedOn = t.toMillis(false);
} else {
skip(parser);
}
}
return new Entry(id, title, link, publishedOn);
}
use of android.text.format.Time in project k-9 by k9mail.
the class K9 method isQuietTime.
public static boolean isQuietTime() {
if (!mQuietTimeEnabled) {
return false;
}
Time time = new Time();
time.setToNow();
Integer startHour = Integer.parseInt(mQuietTimeStarts.split(":")[0]);
Integer startMinute = Integer.parseInt(mQuietTimeStarts.split(":")[1]);
Integer endHour = Integer.parseInt(mQuietTimeEnds.split(":")[0]);
Integer endMinute = Integer.parseInt(mQuietTimeEnds.split(":")[1]);
Integer now = (time.hour * 60) + time.minute;
Integer quietStarts = startHour * 60 + startMinute;
Integer quietEnds = endHour * 60 + endMinute;
// If start and end times are the same, we're never quiet
if (quietStarts.equals(quietEnds)) {
return false;
}
// 21:00 - 05:00 means we want to be quiet if it's after 9 or before 5
if (quietStarts > quietEnds) {
// if it's 22:00 or 03:00 but not 8:00
if (now >= quietStarts || now <= quietEnds) {
return true;
}
} else // 01:00 - 05:00
{
// if it' 2:00 or 4:00 but not 8:00 or 0:00
if (now >= quietStarts && now <= quietEnds) {
return true;
}
}
return false;
}
Aggregations