Search in sources :

Example 16 with Time

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);
}
Also used : Time(android.text.format.Time) TrustedTime(android.util.TrustedTime)

Example 17 with Time

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);
}
Also used : Time(android.text.format.Time) TrustedTime(android.util.TrustedTime)

Example 18 with Time

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);
    }
}
Also used : StrictMode(android.os.StrictMode) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) Time(android.text.format.Time) IOException(java.io.IOException) File(java.io.File)

Example 19 with Time

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);
}
Also used : Time(android.text.format.Time)

Example 20 with Time

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;
}
Also used : Time(android.text.format.Time)

Aggregations

Time (android.text.format.Time)394 SmallTest (android.test.suitebuilder.annotation.SmallTest)97 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 Date (java.util.Date)21 NetworkPolicy (android.net.NetworkPolicy)16 TrustedTime (android.util.TrustedTime)16 TextView (android.widget.TextView)15 Bundle (android.os.Bundle)13 TimeFormatException (android.util.TimeFormatException)13 Suppress (android.test.suitebuilder.annotation.Suppress)12 View (android.view.View)12 Paint (android.graphics.Paint)11 IOException (java.io.IOException)11 Matcher (java.util.regex.Matcher)9 IntentFilter (android.content.IntentFilter)7 File (java.io.File)7 DateFormat (java.text.DateFormat)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ContentValues (android.content.ContentValues)6