summaryrefslogtreecommitdiffstats
path: root/core/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/com')
-rw-r--r--core/java/com/android/internal/logging/MetricsLogger.java15
-rw-r--r--core/java/com/android/internal/midi/MidiConstants.java26
-rw-r--r--core/java/com/android/internal/midi/MidiFramer.java31
-rw-r--r--core/java/com/android/internal/os/BatteryStatsHelper.java24
-rw-r--r--core/java/com/android/internal/os/BatteryStatsImpl.java32
5 files changed, 80 insertions, 48 deletions
diff --git a/core/java/com/android/internal/logging/MetricsLogger.java b/core/java/com/android/internal/logging/MetricsLogger.java
index cbe535f..91ae27b 100644
--- a/core/java/com/android/internal/logging/MetricsLogger.java
+++ b/core/java/com/android/internal/logging/MetricsLogger.java
@@ -27,7 +27,20 @@ import android.view.View;
*/
public class MetricsLogger implements MetricsConstants {
// Temporary constants go here, to await migration to MetricsConstants.
- // next value is 227;
+ // next value is 238;
+
+ public static final int TUNER = 227;
+ public static final int TUNER_QS = 228;
+ public static final int TUNER_DEMO_MODE = 229;
+
+ public static final int TUNER_QS_REORDER = 230;
+ public static final int TUNER_QS_ADD = 231;
+ public static final int TUNER_QS_REMOVE = 232;
+ public static final int TUNER_STATUS_BAR_ENABLE = 233;
+ public static final int TUNER_STATUS_BAR_DISABLE = 234;
+ public static final int TUNER_DEMO_MODE_ENABLED = 235;
+ public static final int TUNER_DEMO_MODE_ON = 236;
+ public static final int TUNER_BATTERY_PERCENTAGE = 237;
public static void visible(Context context, int category) throws IllegalArgumentException {
if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) {
diff --git a/core/java/com/android/internal/midi/MidiConstants.java b/core/java/com/android/internal/midi/MidiConstants.java
index c13e5fc..b6b8bf0 100644
--- a/core/java/com/android/internal/midi/MidiConstants.java
+++ b/core/java/com/android/internal/midi/MidiConstants.java
@@ -55,18 +55,30 @@ public final class MidiConstants {
public final static int SYSTEM_BYTE_LENGTHS[] = { 1, 2, 3, 2, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1 };
- /********************************************************************/
- public static int getBytesPerMessage(int command) {
- if ((command < 0x80) || (command > 0xFF)) {
- return 0;
- } else if (command >= 0xF0) {
- return SYSTEM_BYTE_LENGTHS[command & 0x0F];
+ /**
+ * MIDI messages, except for SysEx, are 1,2 or 3 bytes long.
+ * You can tell how long a MIDI message is from the first status byte.
+ * Do not call this for SysEx, which has variable length.
+ * @param statusByte
+ * @return number of bytes in a complete message or zero if data byte passed
+ */
+ public static int getBytesPerMessage(byte statusByte) {
+ // Java bytes are signed so we need to mask off the high bits
+ // to get a value between 0 and 255.
+ int statusInt = statusByte & 0xFF;
+ if (statusInt >= 0xF0) {
+ // System messages use low nibble for size.
+ return SYSTEM_BYTE_LENGTHS[statusInt & 0x0F];
+ } else if(statusInt >= 0x80) {
+ // Channel voice messages use high nibble for size.
+ return CHANNEL_BYTE_LENGTHS[(statusInt >> 4) - 8];
} else {
- return CHANNEL_BYTE_LENGTHS[(command >> 4) - 8];
+ return 0; // data byte
}
}
+
/**
* @param msg
* @param offset
diff --git a/core/java/com/android/internal/midi/MidiFramer.java b/core/java/com/android/internal/midi/MidiFramer.java
index 058f57c..62517fa 100644
--- a/core/java/com/android/internal/midi/MidiFramer.java
+++ b/core/java/com/android/internal/midi/MidiFramer.java
@@ -17,7 +17,7 @@
package com.android.internal.midi;
import android.media.midi.MidiReceiver;
-import android.util.Log;
+//import android.util.Log;
import java.io.IOException;
@@ -37,7 +37,7 @@ public class MidiFramer extends MidiReceiver {
private MidiReceiver mReceiver;
private byte[] mBuffer = new byte[3];
private int mCount;
- private int mRunningStatus;
+ private byte mRunningStatus;
private int mNeeded;
private boolean mInSysEx;
@@ -59,22 +59,22 @@ public class MidiFramer extends MidiReceiver {
@Override
public void onSend(byte[] data, int offset, int count, long timestamp)
throws IOException {
- // Log.i(TAG, formatMidiData(data, offset, count));
int sysExStartOffset = (mInSysEx ? offset : -1);
for (int i = 0; i < count; i++) {
- int b = data[offset] & 0xFF;
- if (b >= 0x80) { // status byte?
- if (b < 0xF0) { // channel message?
- mRunningStatus = (byte) b;
+ final byte currentByte = data[offset];
+ final int currentInt = currentByte & 0xFF;
+ if (currentInt >= 0x80) { // status byte?
+ if (currentInt < 0xF0) { // channel message?
+ mRunningStatus = currentByte;
mCount = 1;
- mNeeded = MidiConstants.getBytesPerMessage(b) - 1;
- } else if (b < 0xF8) { // system common?
- if (b == 0xF0 /* SysEx Start */) {
+ mNeeded = MidiConstants.getBytesPerMessage(currentByte) - 1;
+ } else if (currentInt < 0xF8) { // system common?
+ if (currentInt == 0xF0 /* SysEx Start */) {
// Log.i(TAG, "SysEx Start");
mInSysEx = true;
sysExStartOffset = offset;
- } else if (b == 0xF7 /* SysEx End */) {
+ } else if (currentInt == 0xF7 /* SysEx End */) {
// Log.i(TAG, "SysEx End");
if (mInSysEx) {
mReceiver.send(data, sysExStartOffset,
@@ -83,10 +83,10 @@ public class MidiFramer extends MidiReceiver {
sysExStartOffset = -1;
}
} else {
- mBuffer[0] = (byte) b;
+ mBuffer[0] = currentByte;
mRunningStatus = 0;
mCount = 1;
- mNeeded = MidiConstants.getBytesPerMessage(b) - 1;
+ mNeeded = MidiConstants.getBytesPerMessage(currentByte) - 1;
}
} else { // real-time?
// Single byte message interleaved with other data.
@@ -98,12 +98,11 @@ public class MidiFramer extends MidiReceiver {
mReceiver.send(data, offset, 1, timestamp);
}
} else { // data byte
- // Save SysEx data for SysEx End marker or end of buffer.
if (!mInSysEx) {
- mBuffer[mCount++] = (byte) b;
+ mBuffer[mCount++] = currentByte;
if (--mNeeded == 0) {
if (mRunningStatus != 0) {
- mBuffer[0] = (byte) mRunningStatus;
+ mBuffer[0] = mRunningStatus;
}
mReceiver.send(mBuffer, 0, mCount, timestamp);
mNeeded = MidiConstants.getBytesPerMessage(mBuffer[0]) - 1;
diff --git a/core/java/com/android/internal/os/BatteryStatsHelper.java b/core/java/com/android/internal/os/BatteryStatsHelper.java
index 264b8c1..9caf78a 100644
--- a/core/java/com/android/internal/os/BatteryStatsHelper.java
+++ b/core/java/com/android/internal/os/BatteryStatsHelper.java
@@ -47,6 +47,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.Locale;
/**
* A helper class for retrieving the power usage information for all applications and services.
@@ -267,15 +268,20 @@ public final class BatteryStatsHelper {
public static String makemAh(double power) {
if (power == 0) return "0";
- else if (power < .00001) return String.format("%.8f", power);
- else if (power < .0001) return String.format("%.7f", power);
- else if (power < .001) return String.format("%.6f", power);
- else if (power < .01) return String.format("%.5f", power);
- else if (power < .1) return String.format("%.4f", power);
- else if (power < 1) return String.format("%.3f", power);
- else if (power < 10) return String.format("%.2f", power);
- else if (power < 100) return String.format("%.1f", power);
- else return String.format("%.0f", power);
+
+ final String format;
+ if (power < .00001) format = "%.8f";
+ else if (power < .0001) format = "%.7f";
+ else if (power < .001) format = "%.6f";
+ else if (power < .01) format = "%.5f";
+ else if (power < .1) format = "%.4f";
+ else if (power < 1) format = "%.3f";
+ else if (power < 10) format = "%.2f";
+ else if (power < 100) format = "%.1f";
+ else format = "%.0f";
+
+ // Use English locale because this is never used in UI (only in checkin and dump).
+ return String.format(Locale.ENGLISH, format, power);
}
/**
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 60f47d6..e7c58f4 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -2560,14 +2560,24 @@ public final class BatteryStatsImpl extends BatteryStats {
addHistoryEventLocked(elapsedRealtime, uptime, code, name, uid);
}
+ boolean ensureStartClockTime(final long currentTime) {
+ final long ABOUT_ONE_YEAR = 365*24*60*60*1000L;
+ if (currentTime > ABOUT_ONE_YEAR && mStartClockTime < (currentTime-ABOUT_ONE_YEAR)) {
+ // If the start clock time has changed by more than a year, then presumably
+ // the previous time was completely bogus. So we are going to figure out a
+ // new time based on how much time has elapsed since we started counting.
+ mStartClockTime = currentTime - (SystemClock.elapsedRealtime()-(mRealtimeStart/1000));
+ return true;
+ }
+ return false;
+ }
+
public void noteCurrentTimeChangedLocked() {
final long currentTime = System.currentTimeMillis();
final long elapsedRealtime = SystemClock.elapsedRealtime();
final long uptime = SystemClock.uptimeMillis();
recordCurrentTimeChangeLocked(currentTime, elapsedRealtime, uptime);
- if (isStartClockTimeValid()) {
- mStartClockTime = currentTime;
- }
+ ensureStartClockTime(currentTime);
}
public void noteProcessStartLocked(String name, int uid) {
@@ -4306,19 +4316,11 @@ public final class BatteryStatsImpl extends BatteryStats {
}
}
- boolean isStartClockTimeValid() {
- return mStartClockTime > 365*24*60*60*1000L;
- }
-
@Override public long getStartClockTime() {
- if (!isStartClockTimeValid()) {
- // If the last clock time we got was very small, then we hadn't had a real
- // time yet, so try to get it again.
- mStartClockTime = System.currentTimeMillis();
- if (isStartClockTimeValid()) {
- recordCurrentTimeChangeLocked(mStartClockTime, SystemClock.elapsedRealtime(),
- SystemClock.uptimeMillis());
- }
+ final long currentTime = System.currentTimeMillis();
+ if (ensureStartClockTime(currentTime)) {
+ recordCurrentTimeChangeLocked(currentTime, SystemClock.elapsedRealtime(),
+ SystemClock.uptimeMillis());
}
return mStartClockTime;
}