use of android.util.SparseLongArray in project android_frameworks_base by ResurrectionRemix.
the class BatteryStatsImpl method updateWifiStateLocked.
/**
* Distribute WiFi energy info and network traffic to apps.
* @param info The energy information from the WiFi controller.
*/
public void updateWifiStateLocked(@Nullable final WifiActivityEnergyInfo info) {
if (DEBUG_ENERGY) {
Slog.d(TAG, "Updating wifi stats");
}
final long elapsedRealtimeMs = mClocks.elapsedRealtime();
NetworkStats delta = null;
try {
if (!ArrayUtils.isEmpty(mWifiIfaces)) {
delta = getNetworkStatsDeltaLocked(mWifiIfaces, mWifiNetworkStats);
}
} catch (IOException e) {
Slog.wtf(TAG, "Failed to get wifi network stats", e);
return;
}
if (!mOnBatteryInternal) {
return;
}
SparseLongArray rxPackets = new SparseLongArray();
SparseLongArray txPackets = new SparseLongArray();
long totalTxPackets = 0;
long totalRxPackets = 0;
if (delta != null) {
final int size = delta.size();
for (int i = 0; i < size; i++) {
final NetworkStats.Entry entry = delta.getValues(i, mTmpNetworkStatsEntry);
if (DEBUG_ENERGY) {
Slog.d(TAG, "Wifi uid " + entry.uid + ": delta rx=" + entry.rxBytes + " tx=" + entry.txBytes + " rxPackets=" + entry.rxPackets + " txPackets=" + entry.txPackets);
}
if (entry.rxBytes == 0 && entry.txBytes == 0) {
// Skip the lookup below since there is no work to do.
continue;
}
final Uid u = getUidStatsLocked(mapUid(entry.uid));
if (entry.rxBytes != 0) {
u.noteNetworkActivityLocked(NETWORK_WIFI_RX_DATA, entry.rxBytes, entry.rxPackets);
mNetworkByteActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(entry.rxBytes);
mNetworkPacketActivityCounters[NETWORK_WIFI_RX_DATA].addCountLocked(entry.rxPackets);
rxPackets.put(u.getUid(), entry.rxPackets);
// Sum the total number of packets so that the Rx Power can
// be evenly distributed amongst the apps.
totalRxPackets += entry.rxPackets;
}
if (entry.txBytes != 0) {
u.noteNetworkActivityLocked(NETWORK_WIFI_TX_DATA, entry.txBytes, entry.txPackets);
mNetworkByteActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked(entry.txBytes);
mNetworkPacketActivityCounters[NETWORK_WIFI_TX_DATA].addCountLocked(entry.txPackets);
txPackets.put(u.getUid(), entry.txPackets);
// Sum the total number of packets so that the Tx Power can
// be evenly distributed amongst the apps.
totalTxPackets += entry.txPackets;
}
}
}
if (info != null) {
mHasWifiReporting = true;
// Measured in mAms
final long txTimeMs = info.getControllerTxTimeMillis();
final long rxTimeMs = info.getControllerRxTimeMillis();
final long idleTimeMs = info.getControllerIdleTimeMillis();
final long totalTimeMs = txTimeMs + rxTimeMs + idleTimeMs;
long leftOverRxTimeMs = rxTimeMs;
long leftOverTxTimeMs = txTimeMs;
if (DEBUG_ENERGY) {
Slog.d(TAG, "------ BEGIN WiFi power blaming ------");
Slog.d(TAG, " Tx Time: " + txTimeMs + " ms");
Slog.d(TAG, " Rx Time: " + rxTimeMs + " ms");
Slog.d(TAG, " Idle Time: " + idleTimeMs + " ms");
Slog.d(TAG, " Total Time: " + totalTimeMs + " ms");
}
long totalWifiLockTimeMs = 0;
long totalScanTimeMs = 0;
// On the first pass, collect some totals so that we can normalize power
// calculations if we need to.
final int uidStatsSize = mUidStats.size();
for (int i = 0; i < uidStatsSize; i++) {
final Uid uid = mUidStats.valueAt(i);
// Sum the total scan power for all apps.
totalScanTimeMs += uid.mWifiScanTimer.getTimeSinceMarkLocked(elapsedRealtimeMs * 1000) / 1000;
// Sum the total time holding wifi lock for all apps.
totalWifiLockTimeMs += uid.mFullWifiLockTimer.getTimeSinceMarkLocked(elapsedRealtimeMs * 1000) / 1000;
}
if (DEBUG_ENERGY && totalScanTimeMs > rxTimeMs) {
Slog.d(TAG, " !Estimated scan time > Actual rx time (" + totalScanTimeMs + " ms > " + rxTimeMs + " ms). Normalizing scan time.");
}
if (DEBUG_ENERGY && totalScanTimeMs > txTimeMs) {
Slog.d(TAG, " !Estimated scan time > Actual tx time (" + totalScanTimeMs + " ms > " + txTimeMs + " ms). Normalizing scan time.");
}
// Actually assign and distribute power usage to apps.
for (int i = 0; i < uidStatsSize; i++) {
final Uid uid = mUidStats.valueAt(i);
long scanTimeSinceMarkMs = uid.mWifiScanTimer.getTimeSinceMarkLocked(elapsedRealtimeMs * 1000) / 1000;
if (scanTimeSinceMarkMs > 0) {
// Set the new mark so that next time we get new data since this point.
uid.mWifiScanTimer.setMark(elapsedRealtimeMs);
long scanRxTimeSinceMarkMs = scanTimeSinceMarkMs;
long scanTxTimeSinceMarkMs = scanTimeSinceMarkMs;
// blamed for this, but this is fine as scans are relatively more expensive.
if (totalScanTimeMs > rxTimeMs) {
scanRxTimeSinceMarkMs = (rxTimeMs * scanRxTimeSinceMarkMs) / totalScanTimeMs;
}
if (totalScanTimeMs > txTimeMs) {
scanTxTimeSinceMarkMs = (txTimeMs * scanTxTimeSinceMarkMs) / totalScanTimeMs;
}
if (DEBUG_ENERGY) {
Slog.d(TAG, " ScanTime for UID " + uid.getUid() + ": Rx:" + scanRxTimeSinceMarkMs + " ms Tx:" + scanTxTimeSinceMarkMs + " ms)");
}
ControllerActivityCounterImpl activityCounter = uid.getOrCreateWifiControllerActivityLocked();
activityCounter.getRxTimeCounter().addCountLocked(scanRxTimeSinceMarkMs);
activityCounter.getTxTimeCounters()[0].addCountLocked(scanTxTimeSinceMarkMs);
leftOverRxTimeMs -= scanRxTimeSinceMarkMs;
leftOverTxTimeMs -= scanTxTimeSinceMarkMs;
}
// Distribute evenly the power consumed while Idle to each app holding a WiFi
// lock.
final long wifiLockTimeSinceMarkMs = uid.mFullWifiLockTimer.getTimeSinceMarkLocked(elapsedRealtimeMs * 1000) / 1000;
if (wifiLockTimeSinceMarkMs > 0) {
// Set the new mark so that next time we get new data since this point.
uid.mFullWifiLockTimer.setMark(elapsedRealtimeMs);
final long myIdleTimeMs = (wifiLockTimeSinceMarkMs * idleTimeMs) / totalWifiLockTimeMs;
if (DEBUG_ENERGY) {
Slog.d(TAG, " IdleTime for UID " + uid.getUid() + ": " + myIdleTimeMs + " ms");
}
uid.getOrCreateWifiControllerActivityLocked().getIdleTimeCounter().addCountLocked(myIdleTimeMs);
}
}
if (DEBUG_ENERGY) {
Slog.d(TAG, " New RxPower: " + leftOverRxTimeMs + " ms");
Slog.d(TAG, " New TxPower: " + leftOverTxTimeMs + " ms");
}
// packets.
for (int i = 0; i < txPackets.size(); i++) {
final Uid uid = getUidStatsLocked(txPackets.keyAt(i));
final long myTxTimeMs = (txPackets.valueAt(i) * leftOverTxTimeMs) / totalTxPackets;
if (DEBUG_ENERGY) {
Slog.d(TAG, " TxTime for UID " + uid.getUid() + ": " + myTxTimeMs + " ms");
}
uid.getOrCreateWifiControllerActivityLocked().getTxTimeCounters()[0].addCountLocked(myTxTimeMs);
}
// packets.
for (int i = 0; i < rxPackets.size(); i++) {
final Uid uid = getUidStatsLocked(rxPackets.keyAt(i));
final long myRxTimeMs = (rxPackets.valueAt(i) * leftOverRxTimeMs) / totalRxPackets;
if (DEBUG_ENERGY) {
Slog.d(TAG, " RxTime for UID " + uid.getUid() + ": " + myRxTimeMs + " ms");
}
uid.getOrCreateWifiControllerActivityLocked().getRxTimeCounter().addCountLocked(myRxTimeMs);
}
// Any left over power use will be picked up by the WiFi category in BatteryStatsHelper.
// Update WiFi controller stats.
mWifiActivity.getRxTimeCounter().addCountLocked(info.getControllerRxTimeMillis());
mWifiActivity.getTxTimeCounters()[0].addCountLocked(info.getControllerTxTimeMillis());
mWifiActivity.getIdleTimeCounter().addCountLocked(info.getControllerIdleTimeMillis());
// POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE is measured in mV, so convert to V.
final double opVolt = mPowerProfile.getAveragePower(PowerProfile.POWER_WIFI_CONTROLLER_OPERATING_VOLTAGE) / 1000.0;
if (opVolt != 0) {
// We store the power drain as mAms.
mWifiActivity.getPowerCounter().addCountLocked((long) (info.getControllerEnergyUsed() / opVolt));
}
}
}
use of android.util.SparseLongArray in project android_frameworks_base by DirtyUnicorns.
the class Transition method createAnimators.
/**
* This method, essentially a wrapper around all calls to createAnimator for all
* possible target views, is called with the entire set of start/end
* values. The implementation in Transition iterates through these lists
* and calls {@link #createAnimator(ViewGroup, TransitionValues, TransitionValues)}
* with each set of start/end values on this transition. The
* TransitionSet subclass overrides this method and delegates it to
* each of its children in succession.
*
* @hide
*/
protected void createAnimators(ViewGroup sceneRoot, TransitionValuesMaps startValues, TransitionValuesMaps endValues, ArrayList<TransitionValues> startValuesList, ArrayList<TransitionValues> endValuesList) {
if (DBG) {
Log.d(LOG_TAG, "createAnimators() for " + this);
}
ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
long minStartDelay = Long.MAX_VALUE;
int minAnimator = mAnimators.size();
SparseLongArray startDelays = new SparseLongArray();
int startValuesListCount = startValuesList.size();
for (int i = 0; i < startValuesListCount; ++i) {
TransitionValues start = startValuesList.get(i);
TransitionValues end = endValuesList.get(i);
if (start != null && !start.targetedTransitions.contains(this)) {
start = null;
}
if (end != null && !end.targetedTransitions.contains(this)) {
end = null;
}
if (start == null && end == null) {
continue;
}
// Only bother trying to animate with values that differ between start/end
boolean isChanged = start == null || end == null || isTransitionRequired(start, end);
if (isChanged) {
if (DBG) {
View view = (end != null) ? end.view : start.view;
Log.d(LOG_TAG, " differing start/end values for view " + view);
if (start == null || end == null) {
Log.d(LOG_TAG, " " + ((start == null) ? "start null, end non-null" : "start non-null, end null"));
} else {
for (String key : start.values.keySet()) {
Object startValue = start.values.get(key);
Object endValue = end.values.get(key);
if (startValue != endValue && !startValue.equals(endValue)) {
Log.d(LOG_TAG, " " + key + ": start(" + startValue + "), end(" + endValue + ")");
}
}
}
}
// TODO: what to do about targetIds and itemIds?
Animator animator = createAnimator(sceneRoot, start, end);
if (animator != null) {
// Save animation info for future cancellation purposes
View view = null;
TransitionValues infoValues = null;
if (end != null) {
view = end.view;
String[] properties = getTransitionProperties();
if (view != null && properties != null && properties.length > 0) {
infoValues = new TransitionValues();
infoValues.view = view;
TransitionValues newValues = endValues.viewValues.get(view);
if (newValues != null) {
for (int j = 0; j < properties.length; ++j) {
infoValues.values.put(properties[j], newValues.values.get(properties[j]));
}
}
int numExistingAnims = runningAnimators.size();
for (int j = 0; j < numExistingAnims; ++j) {
Animator anim = runningAnimators.keyAt(j);
AnimationInfo info = runningAnimators.get(anim);
if (info.values != null && info.view == view && ((info.name == null && getName() == null) || info.name.equals(getName()))) {
if (info.values.equals(infoValues)) {
// Favor the old animator
animator = null;
break;
}
}
}
}
} else {
view = (start != null) ? start.view : null;
}
if (animator != null) {
if (mPropagation != null) {
long delay = mPropagation.getStartDelay(sceneRoot, this, start, end);
startDelays.put(mAnimators.size(), delay);
minStartDelay = Math.min(delay, minStartDelay);
}
AnimationInfo info = new AnimationInfo(view, getName(), this, sceneRoot.getWindowId(), infoValues);
runningAnimators.put(animator, info);
mAnimators.add(animator);
}
}
}
}
if (startDelays.size() != 0) {
for (int i = 0; i < startDelays.size(); i++) {
int index = startDelays.keyAt(i);
Animator animator = mAnimators.get(index);
long delay = startDelays.valueAt(i) - minStartDelay + animator.getStartDelay();
animator.setStartDelay(delay);
}
}
}
use of android.util.SparseLongArray in project android_frameworks_base by ParanoidAndroid.
the class AccessibilityNodeInfo method initFromParcel.
/**
* Creates a new instance from a {@link Parcel}.
*
* @param parcel A parcel containing the state of a {@link AccessibilityNodeInfo}.
*/
private void initFromParcel(Parcel parcel) {
mSealed = (parcel.readInt() == 1);
mSourceNodeId = parcel.readLong();
mWindowId = parcel.readInt();
mParentNodeId = parcel.readLong();
mLabelForId = parcel.readLong();
mLabeledById = parcel.readLong();
mConnectionId = parcel.readInt();
SparseLongArray childIds = mChildNodeIds;
final int childrenSize = parcel.readInt();
for (int i = 0; i < childrenSize; i++) {
final long childId = parcel.readLong();
childIds.put(i, childId);
}
mBoundsInParent.top = parcel.readInt();
mBoundsInParent.bottom = parcel.readInt();
mBoundsInParent.left = parcel.readInt();
mBoundsInParent.right = parcel.readInt();
mBoundsInScreen.top = parcel.readInt();
mBoundsInScreen.bottom = parcel.readInt();
mBoundsInScreen.left = parcel.readInt();
mBoundsInScreen.right = parcel.readInt();
mActions = parcel.readInt();
mMovementGranularities = parcel.readInt();
mBooleanProperties = parcel.readInt();
mPackageName = parcel.readCharSequence();
mClassName = parcel.readCharSequence();
mText = parcel.readCharSequence();
mContentDescription = parcel.readCharSequence();
mViewIdResourceName = parcel.readString();
mTextSelectionStart = parcel.readInt();
mTextSelectionEnd = parcel.readInt();
}
use of android.util.SparseLongArray in project android_frameworks_base by ParanoidAndroid.
the class AccessibilityNodeInfoCache method checkIntegrity.
/**
* Check the integrity of the cache which is it does not have nodes
* from more than one window, there are no duplicates, all nodes are
* connected, there is a single input focused node, and there is a
* single accessibility focused node.
*/
private void checkIntegrity() {
synchronized (mLock) {
// Get the root.
if (mCacheImpl.size() <= 0) {
return;
}
// If the cache is a tree it does not matter from
// which node we start to search for the root.
AccessibilityNodeInfo root = mCacheImpl.valueAt(0);
AccessibilityNodeInfo parent = root;
while (parent != null) {
root = parent;
parent = mCacheImpl.get(parent.getParentNodeId());
}
// Traverse the tree and do some checks.
final int windowId = root.getWindowId();
AccessibilityNodeInfo accessFocus = null;
AccessibilityNodeInfo inputFocus = null;
HashSet<AccessibilityNodeInfo> seen = new HashSet<AccessibilityNodeInfo>();
Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>();
fringe.add(root);
while (!fringe.isEmpty()) {
AccessibilityNodeInfo current = fringe.poll();
// Check for duplicates
if (!seen.add(current)) {
Log.e(LOG_TAG, "Duplicate node: " + current);
return;
}
// Check for one accessibility focus.
if (current.isAccessibilityFocused()) {
if (accessFocus != null) {
Log.e(LOG_TAG, "Duplicate accessibility focus:" + current);
} else {
accessFocus = current;
}
}
// Check for one input focus.
if (current.isFocused()) {
if (inputFocus != null) {
Log.e(LOG_TAG, "Duplicate input focus: " + current);
} else {
inputFocus = current;
}
}
SparseLongArray childIds = current.getChildNodeIds();
final int childCount = childIds.size();
for (int i = 0; i < childCount; i++) {
final long childId = childIds.valueAt(i);
AccessibilityNodeInfo child = mCacheImpl.get(childId);
if (child != null) {
fringe.add(child);
}
}
}
// Check for disconnected nodes or ones from another window.
final int cacheSize = mCacheImpl.size();
for (int i = 0; i < cacheSize; i++) {
AccessibilityNodeInfo info = mCacheImpl.valueAt(i);
if (!seen.contains(info)) {
if (info.getWindowId() == windowId) {
Log.e(LOG_TAG, "Disconneced node: ");
} else {
Log.e(LOG_TAG, "Node from: " + info.getWindowId() + " not from:" + windowId + " " + info);
}
}
}
}
}
use of android.util.SparseLongArray in project android_frameworks_base by ParanoidAndroid.
the class AccessibilityNodeInfoCache method clearSubTreeLocked.
/**
* Clears a subtree rooted at the node with the given id.
*
* @param rootNodeId The root id.
*/
private void clearSubTreeLocked(long rootNodeId) {
AccessibilityNodeInfo current = mCacheImpl.get(rootNodeId);
if (current == null) {
return;
}
mCacheImpl.remove(rootNodeId);
SparseLongArray childNodeIds = current.getChildNodeIds();
final int childCount = childNodeIds.size();
for (int i = 0; i < childCount; i++) {
final long childNodeId = childNodeIds.valueAt(i);
clearSubTreeLocked(childNodeId);
}
}
Aggregations