Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d95346a3 authored by Felix Lopez Luis's avatar Felix Lopez Luis
Browse files

Add new atoms to log Downgraded Apps and Low Storage

Change-Id: I211696c836cb9c8a7b72e3693ecba3061ca599bf
Bug-Id: b/120911106
Test: refactoring CL. Existing unit tests still pass.
parent 0485504d
Loading
Loading
Loading
Loading
+44 −0
Original line number Original line Diff line number Diff line
@@ -188,6 +188,9 @@ message Atom {
        BluetoothLinkLayerConnectionEvent bluetooth_link_layer_connection_event = 125;
        BluetoothLinkLayerConnectionEvent bluetooth_link_layer_connection_event = 125;
        BluetoothAclConnectionStateChanged bluetooth_acl_connection_state_changed = 126;
        BluetoothAclConnectionStateChanged bluetooth_acl_connection_state_changed = 126;
        BluetoothScoConnectionStateChanged bluetooth_sco_connection_state_changed = 127;
        BluetoothScoConnectionStateChanged bluetooth_sco_connection_state_changed = 127;
        AppDowngraded app_downgraded = 128;
        AppOptimizedAfterDowngraded app_optimized_after_downgraded = 129;
        LowStorageStateChanged low_storage_state_changed = 130;
    }
    }


    // Pulled events will start at field 10000.
    // Pulled events will start at field 10000.
@@ -1786,6 +1789,47 @@ message ActivityForegroundStateChanged {
    optional State state = 4;
    optional State state = 4;
}
}


/**
 * Logs when a volume entered low Storage state.
 * Logged from:
 *      frameworks/base/services/core/java/com/android/server/storage/DeviceStorageMonitorService.java
 */
message LowStorageStateChanged {
    // Volume that ran out of storage.
    optional string volume_description = 1;

    enum State {
        UNKNOWN = 0;
        OFF = 1;
        ON = 2;
    }
    optional State state = 2;
}

/**
 * Logs when an app is downgraded.
 * Logged from:
 *      frameworks/base/services/core/java/com/android/server/pm/BackgroundDexOptService.java
 */
message AppDowngraded {
    optional string package_name = 1;
    // Size of the package (all data) before being downgraded.
    optional int64 size_in_bytes_before = 2;
    // Size of the package (all data) after being downgraded.
    optional int64 size_in_bytes_after = 3;

    optional bool aggressive = 4;
}

/**
 * Logs when an app is optimized after being downgraded.
 * Logged from:
 *      frameworks/base/services/core/java/com/android/server/pm/BackgroundDexOptService.java
 */
message AppOptimizedAfterDowngraded {
    optional string package_name = 1;
}

/**
/**
 * Logs when an app crashes.
 * Logs when an app crashes.
 * Logged from:
 * Logged from:
+57 −2
Original line number Original line Diff line number Diff line
@@ -27,24 +27,29 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.os.BatteryManager;
import android.os.BatteryManager;
import android.os.Environment;
import android.os.Environment;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.os.storage.StorageManager;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.Log;
import android.util.Log;
import android.util.StatsLog;


import com.android.server.pm.dex.DexManager;
import com.android.internal.util.ArrayUtils;
import com.android.server.LocalServices;
import com.android.server.LocalServices;
import com.android.server.PinnerService;
import com.android.server.PinnerService;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.dex.DexoptOptions;
import com.android.server.pm.dex.DexoptOptions;


import java.io.File;
import java.io.File;
import java.nio.file.Paths;
import java.util.List;
import java.util.List;
import java.util.Set;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;


/**
/**
 * {@hide}
 * {@hide}
@@ -289,6 +294,50 @@ public class BackgroundDexOptService extends JobService {
        return result;
        return result;
    }
    }


    /**
     * Get the size of the directory. It uses recursion to go over all files.
     * @param f
     * @return
     */
    private long getDirectorySize(File f) {
        long size = 0;
        if (f.isDirectory()) {
            for (File file: f.listFiles()) {
                size += getDirectorySize(file);
            }
        } else {
            size = f.length();
        }
        return size;
    }

    /**
     * Get the size of a package.
     * @param pkg
     */
    private long getPackageSize(PackageManagerService pm, String pkg) {
        PackageInfo info = pm.getPackageInfo(pkg, 0, UserHandle.USER_SYSTEM);
        long size = 0;
        if (info != null && info.applicationInfo != null) {
            File path = Paths.get(info.applicationInfo.sourceDir).toFile();
            if (path.isFile()) {
                path = path.getParentFile();
            }
            size += getDirectorySize(path);
            if (!ArrayUtils.isEmpty(info.applicationInfo.splitSourceDirs)) {
                for (String splitSourceDir : info.applicationInfo.splitSourceDirs) {
                    path = Paths.get(splitSourceDir).toFile();
                    if (path.isFile()) {
                        path = path.getParentFile();
                    }
                    size += getDirectorySize(path);
                }
            }
            return size;
        }
        return 0;
    }

    private int optimizePackages(PackageManagerService pm, ArraySet<String> pkgs,
    private int optimizePackages(PackageManagerService pm, ArraySet<String> pkgs,
            long lowStorageThreshold, boolean is_for_primary_dex,
            long lowStorageThreshold, boolean is_for_primary_dex,
            ArraySet<String> failedPackageNames) {
            ArraySet<String> failedPackageNames) {
@@ -315,8 +364,10 @@ public class BackgroundDexOptService extends JobService {


            int reason;
            int reason;
            boolean downgrade;
            boolean downgrade;
            long package_size_before = 0; //used when the app is downgraded
            // Downgrade unused packages.
            // Downgrade unused packages.
            if (unusedPackages.contains(pkg) && shouldDowngrade) {
            if (unusedPackages.contains(pkg) && shouldDowngrade) {
                package_size_before = getPackageSize(pm, pkg);
                // This applies for system apps or if packages location is not a directory, i.e.
                // This applies for system apps or if packages location is not a directory, i.e.
                // monolithic install.
                // monolithic install.
                if (is_for_primary_dex && !pm.canHaveOatDir(pkg)) {
                if (is_for_primary_dex && !pm.canHaveOatDir(pkg)) {
@@ -366,6 +417,10 @@ public class BackgroundDexOptService extends JobService {
                synchronized (failedPackageNames) {
                synchronized (failedPackageNames) {
                    failedPackageNames.remove(pkg);
                    failedPackageNames.remove(pkg);
                }
                }
                if (downgrade) {
                    StatsLog.write(StatsLog.APP_DOWNGRADED, pkg, package_size_before,
                            getPackageSize(pm, pkg), /*aggressive=*/ false);
                }
            }
            }
        }
        }
        notifyPinService(updatedPackages);
        notifyPinService(updatedPackages);
+7 −2
Original line number Original line Diff line number Diff line
@@ -24,7 +24,6 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.net.TrafficStats;
import android.os.Binder;
import android.os.Binder;
import android.os.Environment;
import android.os.Environment;
import android.os.FileObserver;
import android.os.FileObserver;
@@ -42,13 +41,13 @@ import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.ArrayMap;
import android.util.DataUnit;
import android.util.DataUnit;
import android.util.Slog;
import android.util.Slog;
import android.util.StatsLog;


import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.DumpUtils;
import com.android.internal.util.IndentingPrintWriter;
import com.android.internal.util.IndentingPrintWriter;
import com.android.server.EventLogTags;
import com.android.server.EventLogTags;
import com.android.server.IoThread;
import com.android.server.SystemService;
import com.android.server.SystemService;
import com.android.server.pm.InstructionSets;
import com.android.server.pm.InstructionSets;
import com.android.server.pm.PackageManagerService;
import com.android.server.pm.PackageManagerService;
@@ -499,9 +498,15 @@ public class DeviceStorageMonitorService extends SystemService {
            notification.flags |= Notification.FLAG_NO_CLEAR;
            notification.flags |= Notification.FLAG_NO_CLEAR;
            mNotifManager.notifyAsUser(uuid.toString(), SystemMessage.NOTE_LOW_STORAGE,
            mNotifManager.notifyAsUser(uuid.toString(), SystemMessage.NOTE_LOW_STORAGE,
                    notification, UserHandle.ALL);
                    notification, UserHandle.ALL);
            StatsLog.write(StatsLog.LOW_STORAGE_STATE_CHANGED,
                    Objects.toString(vol.getDescription()),
                    StatsLog.LOW_STORAGE_STATE_CHANGED__STATE__ON);
        } else if (State.isLeaving(State.LEVEL_LOW, oldLevel, newLevel)) {
        } else if (State.isLeaving(State.LEVEL_LOW, oldLevel, newLevel)) {
            mNotifManager.cancelAsUser(uuid.toString(), SystemMessage.NOTE_LOW_STORAGE,
            mNotifManager.cancelAsUser(uuid.toString(), SystemMessage.NOTE_LOW_STORAGE,
                    UserHandle.ALL);
                    UserHandle.ALL);
            StatsLog.write(StatsLog.LOW_STORAGE_STATE_CHANGED,
                    Objects.toString(vol.getDescription()),
                    StatsLog.LOW_STORAGE_STATE_CHANGED__STATE__OFF);
        }
        }
    }
    }