Search in sources :

Example 51 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by AOSPA.

the class CaptivePortalLoginActivity method setWebViewProxy.

// Find WebView's proxy BroadcastReceiver and prompt it to read proxy system properties.
private void setWebViewProxy() {
    LoadedApk loadedApk = getApplication().mLoadedApk;
    try {
        Field receiversField = LoadedApk.class.getDeclaredField("mReceivers");
        receiversField.setAccessible(true);
        ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object rec : ((ArrayMap) receiverMap).keySet()) {
                Class clazz = rec.getClass();
                if (clazz.getName().contains("ProxyChangeListener")) {
                    Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class);
                    Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION);
                    onReceiveMethod.invoke(rec, getApplicationContext(), intent);
                    Log.v(TAG, "Prompting WebView proxy reload.");
                }
            }
        }
    } catch (Exception e) {
        Log.e(TAG, "Exception while setting WebView proxy: " + e);
    }
}
Also used : Field(java.lang.reflect.Field) LoadedApk(android.app.LoadedApk) ArrayMap(android.util.ArrayMap) Intent(android.content.Intent) Method(java.lang.reflect.Method) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InterruptedException(java.lang.InterruptedException)

Example 52 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by AOSPA.

the class OverlayManagerService method updateSelectedAssets.

private void updateSelectedAssets(final int userId, List<String> targetPackageNames) {
    final PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
    final boolean updateFrameworkRes = targetPackageNames.contains("android");
    if (updateFrameworkRes) {
        targetPackageNames = pm.getTargetPackageNames(userId);
    }
    final Map<String, String[]> allPaths = new ArrayMap<>(targetPackageNames.size());
    synchronized (mLock) {
        final List<String> frameworkPaths = mImpl.onGetEnabledOverlayPaths("android", userId);
        for (final String packageName : targetPackageNames) {
            final List<String> paths = new ArrayList<>();
            paths.addAll(frameworkPaths);
            if (!"android".equals(packageName)) {
                paths.addAll(mImpl.onGetEnabledOverlayPaths(packageName, userId));
            }
            allPaths.put(packageName, paths.isEmpty() ? null : paths.toArray(new String[paths.size()]));
        }
    }
    for (String packageName : targetPackageNames) {
        pm.setResourceDirs(userId, packageName, allPaths.get(packageName));
    }
    final IActivityManager am = ActivityManagerNative.getDefault();
    try {
        am.updateAssets(userId, targetPackageNames);
    } catch (RemoteException e) {
    // Intentionally left empty.
    }
}
Also used : ArrayList(java.util.ArrayList) PackageManagerInternal(android.content.pm.PackageManagerInternal) ArrayMap(android.util.ArrayMap) RemoteException(android.os.RemoteException) IActivityManager(android.app.IActivityManager)

Example 53 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by AOSPA.

the class ResourcesManager method appendLibAssetForMainAssetPath.

/**
     * Appends the library asset path to any ResourcesImpl object that contains the main
     * assetPath.
     * @param assetPath The main asset path for which to add the library asset path.
     * @param libAsset The library asset path to add.
     */
public void appendLibAssetForMainAssetPath(String assetPath, String libAsset) {
    synchronized (this) {
        // Record which ResourcesImpl need updating
        // (and what ResourcesKey they should update to).
        final ArrayMap<ResourcesImpl, ResourcesKey> updatedResourceKeys = new ArrayMap<>();
        final int implCount = mResourceImpls.size();
        for (int i = 0; i < implCount; i++) {
            final ResourcesImpl impl = mResourceImpls.valueAt(i).get();
            final ResourcesKey key = mResourceImpls.keyAt(i);
            if (impl != null && key.mResDir.equals(assetPath)) {
                if (!ArrayUtils.contains(key.mLibDirs, libAsset)) {
                    final int newLibAssetCount = 1 + (key.mLibDirs != null ? key.mLibDirs.length : 0);
                    final String[] newLibAssets = new String[newLibAssetCount];
                    if (key.mLibDirs != null) {
                        System.arraycopy(key.mLibDirs, 0, newLibAssets, 0, key.mLibDirs.length);
                    }
                    newLibAssets[newLibAssetCount - 1] = libAsset;
                    updatedResourceKeys.put(impl, new ResourcesKey(key.mResDir, key.mSplitResDirs, key.mOverlayDirs, newLibAssets, key.mDisplayId, key.mOverrideConfiguration, key.mCompatInfo));
                }
            }
        }
        redirectResourcesToNewImplLocked(updatedResourceKeys);
    }
}
Also used : ResourcesKey(android.content.res.ResourcesKey) ArrayMap(android.util.ArrayMap) ResourcesImpl(android.content.res.ResourcesImpl)

Example 54 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by AOSPA.

the class ResourcesManager method applyNewResourceDirsLocked.

final void applyNewResourceDirsLocked(@NonNull final String baseCodePath, @NonNull final String[] newResourceDirs) {
    try {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#applyNewResourceDirsLocked");
        ApplicationPackageManager.configurationChanged();
        if (Process.myUid() == Process.SYSTEM_UID) {
            // Resources.getSystem() will *not* use overlays for applications.)
            if (FRAMEWORK_RESOURCES_PATH.equals(baseCodePath)) {
                final ResourcesKey key = new ResourcesKey(FRAMEWORK_RESOURCES_PATH, null, newResourceDirs, null, Display.DEFAULT_DISPLAY, null, null);
                final ResourcesImpl impl = createResourcesImpl(key);
                Resources.getSystem().setImpl(impl);
            }
        }
        final ArrayMap<ResourcesImpl, ResourcesKey> updatedResourceKeys = new ArrayMap<>();
        final int implCount = mResourceImpls.size();
        for (int i = 0; i < implCount; i++) {
            final ResourcesImpl impl = mResourceImpls.valueAt(i).get();
            final ResourcesKey key = mResourceImpls.keyAt(i);
            if (impl != null && key.mResDir != null && key.mResDir.equals(baseCodePath)) {
                updatedResourceKeys.put(impl, new ResourcesKey(key.mResDir, key.mSplitResDirs, newResourceDirs, key.mLibDirs, key.mDisplayId, key.mOverrideConfiguration, key.mCompatInfo));
            }
        }
        invalidatePath("/");
        redirectResourcesToNewImplLocked(updatedResourceKeys);
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
    }
}
Also used : ResourcesKey(android.content.res.ResourcesKey) ArrayMap(android.util.ArrayMap) ResourcesImpl(android.content.res.ResourcesImpl)

Example 55 with ArrayMap

use of android.util.ArrayMap in project android_frameworks_base by AOSPA.

the class BatteryStats method dumpCheckinLocked.

/**
     * Checkin server version of dump to produce more compact, computer-readable log.
     * 
     * NOTE: all times are expressed in 'ms'.
     */
public final void dumpCheckinLocked(Context context, PrintWriter pw, int which, int reqUid, boolean wifiOnly) {
    final long rawUptime = SystemClock.uptimeMillis() * 1000;
    final long rawRealtime = SystemClock.elapsedRealtime() * 1000;
    final long batteryUptime = getBatteryUptime(rawUptime);
    final long whichBatteryUptime = computeBatteryUptime(rawUptime, which);
    final long whichBatteryRealtime = computeBatteryRealtime(rawRealtime, which);
    final long whichBatteryScreenOffUptime = computeBatteryScreenOffUptime(rawUptime, which);
    final long whichBatteryScreenOffRealtime = computeBatteryScreenOffRealtime(rawRealtime, which);
    final long totalRealtime = computeRealtime(rawRealtime, which);
    final long totalUptime = computeUptime(rawUptime, which);
    final long screenOnTime = getScreenOnTime(rawRealtime, which);
    final long interactiveTime = getInteractiveTime(rawRealtime, which);
    final long powerSaveModeEnabledTime = getPowerSaveModeEnabledTime(rawRealtime, which);
    final long deviceIdleModeLightTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT, rawRealtime, which);
    final long deviceIdleModeFullTime = getDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP, rawRealtime, which);
    final long deviceLightIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_LIGHT, rawRealtime, which);
    final long deviceIdlingTime = getDeviceIdlingTime(DEVICE_IDLE_MODE_DEEP, rawRealtime, which);
    final int connChanges = getNumConnectivityChange(which);
    final long phoneOnTime = getPhoneOnTime(rawRealtime, which);
    final long dischargeCount = getDischargeCoulombCounter().getCountLocked(which);
    final long dischargeScreenOffCount = getDischargeScreenOffCoulombCounter().getCountLocked(which);
    final StringBuilder sb = new StringBuilder(128);
    final SparseArray<? extends Uid> uidStats = getUidStats();
    final int NU = uidStats.size();
    final String category = STAT_NAMES[which];
    // Dump "battery" stat
    dumpLine(pw, 0, /* uid */
    category, BATTERY_DATA, which == STATS_SINCE_CHARGED ? getStartCount() : "N/A", whichBatteryRealtime / 1000, whichBatteryUptime / 1000, totalRealtime / 1000, totalUptime / 1000, getStartClockTime(), whichBatteryScreenOffRealtime / 1000, whichBatteryScreenOffUptime / 1000, getEstimatedBatteryCapacity());
    // Calculate wakelock times across all uids.
    long fullWakeLockTimeTotal = 0;
    long partialWakeLockTimeTotal = 0;
    for (int iu = 0; iu < NU; iu++) {
        final Uid u = uidStats.valueAt(iu);
        final ArrayMap<String, ? extends BatteryStats.Uid.Wakelock> wakelocks = u.getWakelockStats();
        for (int iw = wakelocks.size() - 1; iw >= 0; iw--) {
            final Uid.Wakelock wl = wakelocks.valueAt(iw);
            final Timer fullWakeTimer = wl.getWakeTime(WAKE_TYPE_FULL);
            if (fullWakeTimer != null) {
                fullWakeLockTimeTotal += fullWakeTimer.getTotalTimeLocked(rawRealtime, which);
            }
            final Timer partialWakeTimer = wl.getWakeTime(WAKE_TYPE_PARTIAL);
            if (partialWakeTimer != null) {
                partialWakeLockTimeTotal += partialWakeTimer.getTotalTimeLocked(rawRealtime, which);
            }
        }
    }
    // Dump network stats
    final long mobileRxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
    final long mobileTxTotalBytes = getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
    final long wifiRxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
    final long wifiTxTotalBytes = getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
    final long mobileRxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
    final long mobileTxTotalPackets = getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
    final long wifiRxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
    final long wifiTxTotalPackets = getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
    final long btRxTotalBytes = getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
    final long btTxTotalBytes = getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
    dumpLine(pw, 0, /* uid */
    category, GLOBAL_NETWORK_DATA, mobileRxTotalBytes, mobileTxTotalBytes, wifiRxTotalBytes, wifiTxTotalBytes, mobileRxTotalPackets, mobileTxTotalPackets, wifiRxTotalPackets, wifiTxTotalPackets, btRxTotalBytes, btTxTotalBytes);
    // Dump Modem controller stats
    dumpControllerActivityLine(pw, 0, /* uid */
    category, GLOBAL_MODEM_CONTROLLER_DATA, getModemControllerActivity(), which);
    // Dump Wifi controller stats
    final long wifiOnTime = getWifiOnTime(rawRealtime, which);
    final long wifiRunningTime = getGlobalWifiRunningTime(rawRealtime, which);
    dumpLine(pw, 0, /* uid */
    category, GLOBAL_WIFI_DATA, wifiOnTime / 1000, wifiRunningTime / 1000, /* legacy fields follow, keep at 0 */
    0, 0, 0);
    dumpControllerActivityLine(pw, 0, /* uid */
    category, GLOBAL_WIFI_CONTROLLER_DATA, getWifiControllerActivity(), which);
    // Dump Bluetooth controller stats
    dumpControllerActivityLine(pw, 0, /* uid */
    category, GLOBAL_BLUETOOTH_CONTROLLER_DATA, getBluetoothControllerActivity(), which);
    // Dump misc stats
    dumpLine(pw, 0, /* uid */
    category, MISC_DATA, screenOnTime / 1000, phoneOnTime / 1000, fullWakeLockTimeTotal / 1000, partialWakeLockTimeTotal / 1000, getMobileRadioActiveTime(rawRealtime, which) / 1000, getMobileRadioActiveAdjustedTime(which) / 1000, interactiveTime / 1000, powerSaveModeEnabledTime / 1000, connChanges, deviceIdleModeFullTime / 1000, getDeviceIdleModeCount(DEVICE_IDLE_MODE_DEEP, which), deviceIdlingTime / 1000, getDeviceIdlingCount(DEVICE_IDLE_MODE_DEEP, which), getMobileRadioActiveCount(which), getMobileRadioActiveUnknownTime(which) / 1000, deviceIdleModeLightTime / 1000, getDeviceIdleModeCount(DEVICE_IDLE_MODE_LIGHT, which), deviceLightIdlingTime / 1000, getDeviceIdlingCount(DEVICE_IDLE_MODE_LIGHT, which), getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_LIGHT), getLongestDeviceIdleModeTime(DEVICE_IDLE_MODE_DEEP));
    // Dump screen brightness stats
    Object[] args = new Object[NUM_SCREEN_BRIGHTNESS_BINS];
    for (int i = 0; i < NUM_SCREEN_BRIGHTNESS_BINS; i++) {
        args[i] = getScreenBrightnessTime(i, rawRealtime, which) / 1000;
    }
    dumpLine(pw, 0, /* uid */
    category, SCREEN_BRIGHTNESS_DATA, args);
    // Dump signal strength stats
    args = new Object[SignalStrength.NUM_SIGNAL_STRENGTH_BINS];
    for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
        args[i] = getPhoneSignalStrengthTime(i, rawRealtime, which) / 1000;
    }
    dumpLine(pw, 0, /* uid */
    category, SIGNAL_STRENGTH_TIME_DATA, args);
    dumpLine(pw, 0, /* uid */
    category, SIGNAL_SCANNING_TIME_DATA, getPhoneSignalScanningTime(rawRealtime, which) / 1000);
    for (int i = 0; i < SignalStrength.NUM_SIGNAL_STRENGTH_BINS; i++) {
        args[i] = getPhoneSignalStrengthCount(i, which);
    }
    dumpLine(pw, 0, /* uid */
    category, SIGNAL_STRENGTH_COUNT_DATA, args);
    // Dump network type stats
    args = new Object[NUM_DATA_CONNECTION_TYPES];
    for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; i++) {
        args[i] = getPhoneDataConnectionTime(i, rawRealtime, which) / 1000;
    }
    dumpLine(pw, 0, /* uid */
    category, DATA_CONNECTION_TIME_DATA, args);
    for (int i = 0; i < NUM_DATA_CONNECTION_TYPES; i++) {
        args[i] = getPhoneDataConnectionCount(i, which);
    }
    dumpLine(pw, 0, /* uid */
    category, DATA_CONNECTION_COUNT_DATA, args);
    // Dump wifi state stats
    args = new Object[NUM_WIFI_STATES];
    for (int i = 0; i < NUM_WIFI_STATES; i++) {
        args[i] = getWifiStateTime(i, rawRealtime, which) / 1000;
    }
    dumpLine(pw, 0, /* uid */
    category, WIFI_STATE_TIME_DATA, args);
    for (int i = 0; i < NUM_WIFI_STATES; i++) {
        args[i] = getWifiStateCount(i, which);
    }
    dumpLine(pw, 0, /* uid */
    category, WIFI_STATE_COUNT_DATA, args);
    // Dump wifi suppl state stats
    args = new Object[NUM_WIFI_SUPPL_STATES];
    for (int i = 0; i < NUM_WIFI_SUPPL_STATES; i++) {
        args[i] = getWifiSupplStateTime(i, rawRealtime, which) / 1000;
    }
    dumpLine(pw, 0, /* uid */
    category, WIFI_SUPPL_STATE_TIME_DATA, args);
    for (int i = 0; i < NUM_WIFI_SUPPL_STATES; i++) {
        args[i] = getWifiSupplStateCount(i, which);
    }
    dumpLine(pw, 0, /* uid */
    category, WIFI_SUPPL_STATE_COUNT_DATA, args);
    // Dump wifi signal strength stats
    args = new Object[NUM_WIFI_SIGNAL_STRENGTH_BINS];
    for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
        args[i] = getWifiSignalStrengthTime(i, rawRealtime, which) / 1000;
    }
    dumpLine(pw, 0, /* uid */
    category, WIFI_SIGNAL_STRENGTH_TIME_DATA, args);
    for (int i = 0; i < NUM_WIFI_SIGNAL_STRENGTH_BINS; i++) {
        args[i] = getWifiSignalStrengthCount(i, which);
    }
    dumpLine(pw, 0, /* uid */
    category, WIFI_SIGNAL_STRENGTH_COUNT_DATA, args);
    if (which == STATS_SINCE_UNPLUGGED) {
        dumpLine(pw, 0, /* uid */
        category, BATTERY_LEVEL_DATA, getDischargeStartLevel(), getDischargeCurrentLevel());
    }
    if (which == STATS_SINCE_UNPLUGGED) {
        dumpLine(pw, 0, /* uid */
        category, BATTERY_DISCHARGE_DATA, getDischargeStartLevel() - getDischargeCurrentLevel(), getDischargeStartLevel() - getDischargeCurrentLevel(), getDischargeAmountScreenOn(), getDischargeAmountScreenOff(), dischargeCount / 1000, dischargeScreenOffCount / 1000);
    } else {
        dumpLine(pw, 0, /* uid */
        category, BATTERY_DISCHARGE_DATA, getLowDischargeAmountSinceCharge(), getHighDischargeAmountSinceCharge(), getDischargeAmountScreenOnSinceCharge(), getDischargeAmountScreenOffSinceCharge(), dischargeCount / 1000, dischargeScreenOffCount / 1000);
    }
    if (reqUid < 0) {
        final Map<String, ? extends Timer> kernelWakelocks = getKernelWakelockStats();
        if (kernelWakelocks.size() > 0) {
            for (Map.Entry<String, ? extends Timer> ent : kernelWakelocks.entrySet()) {
                sb.setLength(0);
                printWakeLockCheckin(sb, ent.getValue(), rawRealtime, null, which, "");
                dumpLine(pw, 0, /* uid */
                category, KERNEL_WAKELOCK_DATA, ent.getKey(), sb.toString());
            }
        }
        final Map<String, ? extends Timer> wakeupReasons = getWakeupReasonStats();
        if (wakeupReasons.size() > 0) {
            for (Map.Entry<String, ? extends Timer> ent : wakeupReasons.entrySet()) {
                // Not doing the regular wake lock formatting to remain compatible
                // with the old checkin format.
                long totalTimeMicros = ent.getValue().getTotalTimeLocked(rawRealtime, which);
                int count = ent.getValue().getCountLocked(which);
                dumpLine(pw, 0, /* uid */
                category, WAKEUP_REASON_DATA, "\"" + ent.getKey() + "\"", (totalTimeMicros + 500) / 1000, count);
            }
        }
    }
    final BatteryStatsHelper helper = new BatteryStatsHelper(context, false, wifiOnly);
    helper.create(this);
    helper.refreshStats(which, UserHandle.USER_ALL);
    final List<BatterySipper> sippers = helper.getUsageList();
    if (sippers != null && sippers.size() > 0) {
        dumpLine(pw, 0, /* uid */
        category, POWER_USE_SUMMARY_DATA, BatteryStatsHelper.makemAh(helper.getPowerProfile().getBatteryCapacity()), BatteryStatsHelper.makemAh(helper.getComputedPower()), BatteryStatsHelper.makemAh(helper.getMinDrainedPower()), BatteryStatsHelper.makemAh(helper.getMaxDrainedPower()));
        for (int i = 0; i < sippers.size(); i++) {
            final BatterySipper bs = sippers.get(i);
            int uid = 0;
            String label;
            switch(bs.drainType) {
                case IDLE:
                    label = "idle";
                    break;
                case CELL:
                    label = "cell";
                    break;
                case PHONE:
                    label = "phone";
                    break;
                case WIFI:
                    label = "wifi";
                    break;
                case BLUETOOTH:
                    label = "blue";
                    break;
                case SCREEN:
                    label = "scrn";
                    break;
                case FLASHLIGHT:
                    label = "flashlight";
                    break;
                case APP:
                    uid = bs.uidObj.getUid();
                    label = "uid";
                    break;
                case USER:
                    uid = UserHandle.getUid(bs.userId, 0);
                    label = "user";
                    break;
                case UNACCOUNTED:
                    label = "unacc";
                    break;
                case OVERCOUNTED:
                    label = "over";
                    break;
                case CAMERA:
                    label = "camera";
                    break;
                default:
                    label = "???";
            }
            dumpLine(pw, uid, category, POWER_USE_ITEM_DATA, label, BatteryStatsHelper.makemAh(bs.totalPowerMah));
        }
    }
    for (int iu = 0; iu < NU; iu++) {
        final int uid = uidStats.keyAt(iu);
        if (reqUid >= 0 && uid != reqUid) {
            continue;
        }
        final Uid u = uidStats.valueAt(iu);
        // Dump Network stats per uid, if any
        final long mobileBytesRx = u.getNetworkActivityBytes(NETWORK_MOBILE_RX_DATA, which);
        final long mobileBytesTx = u.getNetworkActivityBytes(NETWORK_MOBILE_TX_DATA, which);
        final long wifiBytesRx = u.getNetworkActivityBytes(NETWORK_WIFI_RX_DATA, which);
        final long wifiBytesTx = u.getNetworkActivityBytes(NETWORK_WIFI_TX_DATA, which);
        final long mobilePacketsRx = u.getNetworkActivityPackets(NETWORK_MOBILE_RX_DATA, which);
        final long mobilePacketsTx = u.getNetworkActivityPackets(NETWORK_MOBILE_TX_DATA, which);
        final long mobileActiveTime = u.getMobileRadioActiveTime(which);
        final int mobileActiveCount = u.getMobileRadioActiveCount(which);
        final long mobileWakeup = u.getMobileRadioApWakeupCount(which);
        final long wifiPacketsRx = u.getNetworkActivityPackets(NETWORK_WIFI_RX_DATA, which);
        final long wifiPacketsTx = u.getNetworkActivityPackets(NETWORK_WIFI_TX_DATA, which);
        final long wifiWakeup = u.getWifiRadioApWakeupCount(which);
        final long btBytesRx = u.getNetworkActivityBytes(NETWORK_BT_RX_DATA, which);
        final long btBytesTx = u.getNetworkActivityBytes(NETWORK_BT_TX_DATA, which);
        if (mobileBytesRx > 0 || mobileBytesTx > 0 || wifiBytesRx > 0 || wifiBytesTx > 0 || mobilePacketsRx > 0 || mobilePacketsTx > 0 || wifiPacketsRx > 0 || wifiPacketsTx > 0 || mobileActiveTime > 0 || mobileActiveCount > 0 || btBytesRx > 0 || btBytesTx > 0 || mobileWakeup > 0 || wifiWakeup > 0) {
            dumpLine(pw, uid, category, NETWORK_DATA, mobileBytesRx, mobileBytesTx, wifiBytesRx, wifiBytesTx, mobilePacketsRx, mobilePacketsTx, wifiPacketsRx, wifiPacketsTx, mobileActiveTime, mobileActiveCount, btBytesRx, btBytesTx, mobileWakeup, wifiWakeup);
        }
        // Dump modem controller data, per UID.
        dumpControllerActivityLine(pw, uid, category, MODEM_CONTROLLER_DATA, u.getModemControllerActivity(), which);
        // Dump Wifi controller data, per UID.
        final long fullWifiLockOnTime = u.getFullWifiLockTime(rawRealtime, which);
        final long wifiScanTime = u.getWifiScanTime(rawRealtime, which);
        final int wifiScanCount = u.getWifiScanCount(which);
        final long uidWifiRunningTime = u.getWifiRunningTime(rawRealtime, which);
        if (fullWifiLockOnTime != 0 || wifiScanTime != 0 || wifiScanCount != 0 || uidWifiRunningTime != 0) {
            dumpLine(pw, uid, category, WIFI_DATA, fullWifiLockOnTime, wifiScanTime, uidWifiRunningTime, wifiScanCount, /* legacy fields follow, keep at 0 */
            0, 0, 0);
        }
        dumpControllerActivityLine(pw, uid, category, WIFI_CONTROLLER_DATA, u.getWifiControllerActivity(), which);
        dumpTimer(pw, uid, category, BLUETOOTH_MISC_DATA, u.getBluetoothScanTimer(), rawRealtime, which);
        dumpControllerActivityLine(pw, uid, category, BLUETOOTH_CONTROLLER_DATA, u.getBluetoothControllerActivity(), which);
        if (u.hasUserActivity()) {
            args = new Object[Uid.NUM_USER_ACTIVITY_TYPES];
            boolean hasData = false;
            for (int i = 0; i < Uid.NUM_USER_ACTIVITY_TYPES; i++) {
                int val = u.getUserActivityCount(i, which);
                args[i] = val;
                if (val != 0)
                    hasData = true;
            }
            if (hasData) {
                dumpLine(pw, uid, /* uid */
                category, USER_ACTIVITY_DATA, args);
            }
        }
        final ArrayMap<String, ? extends Uid.Wakelock> wakelocks = u.getWakelockStats();
        for (int iw = wakelocks.size() - 1; iw >= 0; iw--) {
            final Uid.Wakelock wl = wakelocks.valueAt(iw);
            String linePrefix = "";
            sb.setLength(0);
            linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_FULL), rawRealtime, "f", which, linePrefix);
            linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_PARTIAL), rawRealtime, "p", which, linePrefix);
            linePrefix = printWakeLockCheckin(sb, wl.getWakeTime(WAKE_TYPE_WINDOW), rawRealtime, "w", which, linePrefix);
            // Only log if we had at lease one wakelock...
            if (sb.length() > 0) {
                String name = wakelocks.keyAt(iw);
                if (name.indexOf(',') >= 0) {
                    name = name.replace(',', '_');
                }
                dumpLine(pw, uid, category, WAKELOCK_DATA, name, sb.toString());
            }
        }
        final ArrayMap<String, ? extends Timer> syncs = u.getSyncStats();
        for (int isy = syncs.size() - 1; isy >= 0; isy--) {
            final Timer timer = syncs.valueAt(isy);
            // Convert from microseconds to milliseconds with rounding
            final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
            final int count = timer.getCountLocked(which);
            if (totalTime != 0) {
                dumpLine(pw, uid, category, SYNC_DATA, syncs.keyAt(isy), totalTime, count);
            }
        }
        final ArrayMap<String, ? extends Timer> jobs = u.getJobStats();
        for (int ij = jobs.size() - 1; ij >= 0; ij--) {
            final Timer timer = jobs.valueAt(ij);
            // Convert from microseconds to milliseconds with rounding
            final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
            final int count = timer.getCountLocked(which);
            if (totalTime != 0) {
                dumpLine(pw, uid, category, JOB_DATA, jobs.keyAt(ij), totalTime, count);
            }
        }
        dumpTimer(pw, uid, category, FLASHLIGHT_DATA, u.getFlashlightTurnedOnTimer(), rawRealtime, which);
        dumpTimer(pw, uid, category, CAMERA_DATA, u.getCameraTurnedOnTimer(), rawRealtime, which);
        dumpTimer(pw, uid, category, VIDEO_DATA, u.getVideoTurnedOnTimer(), rawRealtime, which);
        dumpTimer(pw, uid, category, AUDIO_DATA, u.getAudioTurnedOnTimer(), rawRealtime, which);
        final SparseArray<? extends BatteryStats.Uid.Sensor> sensors = u.getSensorStats();
        final int NSE = sensors.size();
        for (int ise = 0; ise < NSE; ise++) {
            final Uid.Sensor se = sensors.valueAt(ise);
            final int sensorNumber = sensors.keyAt(ise);
            final Timer timer = se.getSensorTime();
            if (timer != null) {
                // Convert from microseconds to milliseconds with rounding
                final long totalTime = (timer.getTotalTimeLocked(rawRealtime, which) + 500) / 1000;
                final int count = timer.getCountLocked(which);
                if (totalTime != 0) {
                    dumpLine(pw, uid, category, SENSOR_DATA, sensorNumber, totalTime, count);
                }
            }
        }
        dumpTimer(pw, uid, category, VIBRATOR_DATA, u.getVibratorOnTimer(), rawRealtime, which);
        dumpTimer(pw, uid, category, FOREGROUND_DATA, u.getForegroundActivityTimer(), rawRealtime, which);
        final Object[] stateTimes = new Object[Uid.NUM_PROCESS_STATE];
        long totalStateTime = 0;
        for (int ips = 0; ips < Uid.NUM_PROCESS_STATE; ips++) {
            final long time = u.getProcessStateTime(ips, rawRealtime, which);
            totalStateTime += time;
            stateTimes[ips] = (time + 500) / 1000;
        }
        if (totalStateTime > 0) {
            dumpLine(pw, uid, category, STATE_TIME_DATA, stateTimes);
        }
        final long userCpuTimeUs = u.getUserCpuTimeUs(which);
        final long systemCpuTimeUs = u.getSystemCpuTimeUs(which);
        final long powerCpuMaUs = u.getCpuPowerMaUs(which);
        if (userCpuTimeUs > 0 || systemCpuTimeUs > 0 || powerCpuMaUs > 0) {
            dumpLine(pw, uid, category, CPU_DATA, userCpuTimeUs / 1000, systemCpuTimeUs / 1000, powerCpuMaUs / 1000);
        }
        final ArrayMap<String, ? extends BatteryStats.Uid.Proc> processStats = u.getProcessStats();
        for (int ipr = processStats.size() - 1; ipr >= 0; ipr--) {
            final Uid.Proc ps = processStats.valueAt(ipr);
            final long userMillis = ps.getUserTime(which);
            final long systemMillis = ps.getSystemTime(which);
            final long foregroundMillis = ps.getForegroundTime(which);
            final int starts = ps.getStarts(which);
            final int numCrashes = ps.getNumCrashes(which);
            final int numAnrs = ps.getNumAnrs(which);
            if (userMillis != 0 || systemMillis != 0 || foregroundMillis != 0 || starts != 0 || numAnrs != 0 || numCrashes != 0) {
                dumpLine(pw, uid, category, PROCESS_DATA, processStats.keyAt(ipr), userMillis, systemMillis, foregroundMillis, starts, numAnrs, numCrashes);
            }
        }
        final ArrayMap<String, ? extends BatteryStats.Uid.Pkg> packageStats = u.getPackageStats();
        for (int ipkg = packageStats.size() - 1; ipkg >= 0; ipkg--) {
            final Uid.Pkg ps = packageStats.valueAt(ipkg);
            int wakeups = 0;
            final ArrayMap<String, ? extends Counter> alarms = ps.getWakeupAlarmStats();
            for (int iwa = alarms.size() - 1; iwa >= 0; iwa--) {
                int count = alarms.valueAt(iwa).getCountLocked(which);
                wakeups += count;
                String name = alarms.keyAt(iwa).replace(',', '_');
                dumpLine(pw, uid, category, WAKEUP_ALARM_DATA, name, count);
            }
            final ArrayMap<String, ? extends Uid.Pkg.Serv> serviceStats = ps.getServiceStats();
            for (int isvc = serviceStats.size() - 1; isvc >= 0; isvc--) {
                final BatteryStats.Uid.Pkg.Serv ss = serviceStats.valueAt(isvc);
                final long startTime = ss.getStartTime(batteryUptime, which);
                final int starts = ss.getStarts(which);
                final int launches = ss.getLaunches(which);
                if (startTime != 0 || starts != 0 || launches != 0) {
                    dumpLine(pw, uid, category, APK_DATA, // wakeup alarms
                    wakeups, // Apk
                    packageStats.keyAt(ipkg), // service
                    serviceStats.keyAt(isvc), // time spent started, in ms
                    startTime / 1000, starts, launches);
                }
            }
        }
    }
}
Also used : BatterySipper(com.android.internal.os.BatterySipper) HashMap(java.util.HashMap) Map(java.util.Map) ArrayMap(android.util.ArrayMap) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper)

Aggregations

ArrayMap (android.util.ArrayMap)365 ArraySet (android.util.ArraySet)77 ArrayList (java.util.ArrayList)75 PublicKey (java.security.PublicKey)49 HashMap (java.util.HashMap)32 Preference (android.support.v7.preference.Preference)30 IOException (java.io.IOException)30 Map (java.util.Map)29 HashSet (java.util.HashSet)28 Intent (android.content.Intent)24 Test (org.junit.Test)24 ComponentName (android.content.ComponentName)22 RemoteException (android.os.RemoteException)22 Field (java.lang.reflect.Field)21 Activity (android.app.Activity)20 SparseArray (android.util.SparseArray)18 List (java.util.List)18 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)18 Point (android.graphics.Point)17 Method (java.lang.reflect.Method)17