Search in sources :

Example 11 with Time

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

the class TimeTest method testMillis1.

@SmallTest
public void testMillis1() throws Exception {
    Time t = new Time(Time.TIMEZONE_UTC);
    t.set(1, 0, 0, 1, 0, 1970);
    long r = t.toMillis(true);
// System.out.println("r=" + r);
}
Also used : Time(android.text.format.Time) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with Time

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

the class TimeTest method disableTestSetJulianDay.

@Suppress
public void disableTestSetJulianDay() throws Exception {
    Time time = new Time();
    // test that we can set the Julian day correctly.
    for (int monthDay = 1; monthDay <= 366; monthDay++) {
        for (int zoneIndex = 0; zoneIndex < mTimeZones.length; zoneIndex++) {
            // We leave the "month" as zero because we are changing the
            // "monthDay" from 1 to 366.  The call to normalize() will
            // then change the "month" (but we don't really care).
            time.set(0, 0, 0, monthDay, 0, 2008);
            time.timezone = mTimeZones[zoneIndex];
            long millis = time.normalize(true);
            if (zoneIndex == 0) {
                Log.i("TimeTest", time.format("%B %d, %Y"));
            }
            int julianDay = Time.getJulianDay(millis, time.gmtoff);
            time.setJulianDay(julianDay);
            // Some places change daylight saving time at 12am and so there
            // is no 12am on some days in some timezones.  In those cases,
            // the time is set to 1am.
            // Examples: Africa/Cairo on April 25, 2008
            //  America/Sao_Paulo on October 12, 2008
            //  Atlantic/Azores on March 30, 2008
            assertTrue(time.hour == 0 || time.hour == 1);
            assertEquals(0, time.minute);
            assertEquals(0, time.second);
            millis = time.toMillis(false);
            int day = Time.getJulianDay(millis, time.gmtoff);
            if (day != julianDay) {
                Log.i("TimeTest", "Error: gmtoff " + (time.gmtoff / 3600.0) + " day " + julianDay + " millis " + millis + " " + time.format("%B %d, %Y") + " " + time.timezone);
            }
            assertEquals(day, julianDay);
        }
    }
}
Also used : Time(android.text.format.Time) Suppress(android.test.suitebuilder.annotation.Suppress)

Example 13 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 14 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 15 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)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