Search in sources :

Example 1 with Time

use of android.text.format.Time in project android-betterpickers by code-troopers.

the class RecurrencePickerDialogFragment method onDateSet.

@Override
public void onDateSet(CalendarDatePickerDialogFragment view, int year, int monthOfYear, int dayOfMonth) {
    if (mModel.endDate == null) {
        mModel.endDate = new Time(mTime.timezone);
        mModel.endDate.hour = mModel.endDate.minute = mModel.endDate.second = 0;
    }
    mModel.endDate.year = year;
    mModel.endDate.month = monthOfYear;
    mModel.endDate.monthDay = dayOfMonth;
    mModel.endDate.normalize(false);
    updateDialog();
}
Also used : Time(android.text.format.Time)

Example 2 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 3 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class ActivityManagerService method logAppTooSlow.

final void logAppTooSlow(int pid, 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();
                if (!SELinux.restorecon(tracesDir.getPath())) {
                    return;
                }
            }
            // 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 (pid <= 0) {
                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 (pid > 0) {
            ArrayList<Integer> firstPids = new ArrayList<Integer>();
            firstPids.add(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 4 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class SyncManager method formatTime.

static String formatTime(long time) {
    Time tobj = new Time();
    tobj.set(time);
    return tobj.format("%Y-%m-%d %H:%M:%S");
}
Also used : Time(android.text.format.Time)

Example 5 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class SyncManager method dumpRecentHistory.

private void dumpRecentHistory(PrintWriter pw) {
    final ArrayList<SyncStorageEngine.SyncHistoryItem> items = mSyncStorageEngine.getSyncHistory();
    if (items != null && items.size() > 0) {
        final Map<String, AuthoritySyncStats> authorityMap = Maps.newHashMap();
        long totalElapsedTime = 0;
        long totalTimes = 0;
        final int N = items.size();
        int maxAuthority = 0;
        int maxAccount = 0;
        for (SyncStorageEngine.SyncHistoryItem item : items) {
            SyncStorageEngine.AuthorityInfo authority = mSyncStorageEngine.getAuthority(item.authorityId);
            final String authorityName;
            final String accountKey;
            if (authority != null) {
                authorityName = authority.authority;
                accountKey = authority.account.name + "/" + authority.account.type + " u" + authority.userId;
            } else {
                authorityName = "Unknown";
                accountKey = "Unknown";
            }
            int length = authorityName.length();
            if (length > maxAuthority) {
                maxAuthority = length;
            }
            length = accountKey.length();
            if (length > maxAccount) {
                maxAccount = length;
            }
            final long elapsedTime = item.elapsedTime;
            totalElapsedTime += elapsedTime;
            totalTimes++;
            AuthoritySyncStats authoritySyncStats = authorityMap.get(authorityName);
            if (authoritySyncStats == null) {
                authoritySyncStats = new AuthoritySyncStats(authorityName);
                authorityMap.put(authorityName, authoritySyncStats);
            }
            authoritySyncStats.elapsedTime += elapsedTime;
            authoritySyncStats.times++;
            final Map<String, AccountSyncStats> accountMap = authoritySyncStats.accountMap;
            AccountSyncStats accountSyncStats = accountMap.get(accountKey);
            if (accountSyncStats == null) {
                accountSyncStats = new AccountSyncStats(accountKey);
                accountMap.put(accountKey, accountSyncStats);
            }
            accountSyncStats.elapsedTime += elapsedTime;
            accountSyncStats.times++;
        }
        if (totalElapsedTime > 0) {
            pw.println();
            pw.printf("Detailed Statistics (Recent history):  " + "%d (# of times) %ds (sync time)\n", totalTimes, totalElapsedTime / 1000);
            final List<AuthoritySyncStats> sortedAuthorities = new ArrayList<AuthoritySyncStats>(authorityMap.values());
            Collections.sort(sortedAuthorities, new Comparator<AuthoritySyncStats>() {

                @Override
                public int compare(AuthoritySyncStats lhs, AuthoritySyncStats rhs) {
                    // reverse order
                    int compare = Integer.compare(rhs.times, lhs.times);
                    if (compare == 0) {
                        compare = Long.compare(rhs.elapsedTime, lhs.elapsedTime);
                    }
                    return compare;
                }
            });
            final int maxLength = Math.max(maxAuthority, maxAccount + 3);
            final int padLength = 2 + 2 + maxLength + 2 + 10 + 11;
            final char[] chars = new char[padLength];
            Arrays.fill(chars, '-');
            final String separator = new String(chars);
            final String authorityFormat = String.format("  %%-%ds: %%-9s  %%-11s\n", maxLength + 2);
            final String accountFormat = String.format("    %%-%ds:   %%-9s  %%-11s\n", maxLength);
            pw.println(separator);
            for (AuthoritySyncStats authoritySyncStats : sortedAuthorities) {
                String name = authoritySyncStats.name;
                long elapsedTime;
                int times;
                String timeStr;
                String timesStr;
                elapsedTime = authoritySyncStats.elapsedTime;
                times = authoritySyncStats.times;
                timeStr = String.format("%ds/%d%%", elapsedTime / 1000, elapsedTime * 100 / totalElapsedTime);
                timesStr = String.format("%d/%d%%", times, times * 100 / totalTimes);
                pw.printf(authorityFormat, name, timesStr, timeStr);
                final List<AccountSyncStats> sortedAccounts = new ArrayList<AccountSyncStats>(authoritySyncStats.accountMap.values());
                Collections.sort(sortedAccounts, new Comparator<AccountSyncStats>() {

                    @Override
                    public int compare(AccountSyncStats lhs, AccountSyncStats rhs) {
                        // reverse order
                        int compare = Integer.compare(rhs.times, lhs.times);
                        if (compare == 0) {
                            compare = Long.compare(rhs.elapsedTime, lhs.elapsedTime);
                        }
                        return compare;
                    }
                });
                for (AccountSyncStats stats : sortedAccounts) {
                    elapsedTime = stats.elapsedTime;
                    times = stats.times;
                    timeStr = String.format("%ds/%d%%", elapsedTime / 1000, elapsedTime * 100 / totalElapsedTime);
                    timesStr = String.format("%d/%d%%", times, times * 100 / totalTimes);
                    pw.printf(accountFormat, stats.name, timesStr, timeStr);
                }
                pw.println(separator);
            }
        }
        pw.println();
        pw.println("Recent Sync History");
        final String format = "  %-" + maxAccount + "s  %-" + maxAuthority + "s %s\n";
        final Map<String, Long> lastTimeMap = Maps.newHashMap();
        final PackageManager pm = mContext.getPackageManager();
        for (int i = 0; i < N; i++) {
            SyncStorageEngine.SyncHistoryItem item = items.get(i);
            SyncStorageEngine.AuthorityInfo authority = mSyncStorageEngine.getAuthority(item.authorityId);
            final String authorityName;
            final String accountKey;
            if (authority != null) {
                authorityName = authority.authority;
                accountKey = authority.account.name + "/" + authority.account.type + " u" + authority.userId;
            } else {
                authorityName = "Unknown";
                accountKey = "Unknown";
            }
            final long elapsedTime = item.elapsedTime;
            final Time time = new Time();
            final long eventTime = item.eventTime;
            time.set(eventTime);
            final String key = authorityName + "/" + accountKey;
            final Long lastEventTime = lastTimeMap.get(key);
            final String diffString;
            if (lastEventTime == null) {
                diffString = "";
            } else {
                final long diff = (lastEventTime - eventTime) / 1000;
                if (diff < 60) {
                    diffString = String.valueOf(diff);
                } else if (diff < 3600) {
                    diffString = String.format("%02d:%02d", diff / 60, diff % 60);
                } else {
                    final long sec = diff % 3600;
                    diffString = String.format("%02d:%02d:%02d", diff / 3600, sec / 60, sec % 60);
                }
            }
            lastTimeMap.put(key, eventTime);
            pw.printf("  #%-3d: %s %8s  %5.1fs  %8s", i + 1, formatTime(eventTime), SyncStorageEngine.SOURCES[item.source], ((float) elapsedTime) / 1000, diffString);
            pw.printf(format, accountKey, authorityName, SyncOperation.reasonToString(pm, item.reason));
            if (item.event != SyncStorageEngine.EVENT_STOP || item.upstreamActivity != 0 || item.downstreamActivity != 0) {
                pw.printf("    event=%d upstreamActivity=%d downstreamActivity=%d\n", item.event, item.upstreamActivity, item.downstreamActivity);
            }
            if (item.mesg != null && !SyncStorageEngine.MESG_SUCCESS.equals(item.mesg)) {
                pw.printf("    mesg=%s\n", item.mesg);
            }
        }
        pw.println();
        pw.println("Recent Sync History Extras");
        for (int i = 0; i < N; i++) {
            final SyncStorageEngine.SyncHistoryItem item = items.get(i);
            final Bundle extras = item.extras;
            if (extras == null || extras.size() == 0) {
                continue;
            }
            final SyncStorageEngine.AuthorityInfo authority = mSyncStorageEngine.getAuthority(item.authorityId);
            final String authorityName;
            final String accountKey;
            if (authority != null) {
                authorityName = authority.authority;
                accountKey = authority.account.name + "/" + authority.account.type + " u" + authority.userId;
            } else {
                authorityName = "Unknown";
                accountKey = "Unknown";
            }
            final Time time = new Time();
            final long eventTime = item.eventTime;
            time.set(eventTime);
            pw.printf("  #%-3d: %s %8s ", i + 1, formatTime(eventTime), SyncStorageEngine.SOURCES[item.source]);
            pw.printf(format, accountKey, authorityName, extras);
        }
    }
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) Time(android.text.format.Time) PackageManager(android.content.pm.PackageManager)

Aggregations

Time (android.text.format.Time)413 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 TimeFormatException (android.util.TimeFormatException)14 Bundle (android.os.Bundle)13 IOException (java.io.IOException)13 Suppress (android.test.suitebuilder.annotation.Suppress)12 View (android.view.View)12 Paint (android.graphics.Paint)11 Intent (android.content.Intent)10 Matcher (java.util.regex.Matcher)9 IntentFilter (android.content.IntentFilter)8 File (java.io.File)8 DateFormat (java.text.DateFormat)7 SimpleDateFormat (java.text.SimpleDateFormat)7