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

Commit 3058334a authored by Jiakai Zhang's avatar Jiakai Zhang
Browse files

Remove unused code around getLastPackageUsageTimeInMills.

1. Remove the code for version 0. Version 1 was introduced in 2016
   (commit ca82e616), so there's no
   point to keep the support for version 0.
2. Remove leftover code from PackageParser. There are a value and a
   getter, but the value is never set. The functionality was moved to
   AndroidPackageWrite by
   commit 14ff7171, but the old code
   were left in PackageParser and nobody sets the value there since
   then.
3. Remove unused methods from PackageStateUnserialized and
   PackageSetting.

Bug: 258223472
Bug: 6527146
Test: Presubmit
Flag: EXEMPT cleanup
Change-Id: Ic53352fa575a76f76310f6384a94e44681ad235f
parent 2f3a527d
Loading
Loading
Loading
Loading
+0 −25
Original line number Diff line number Diff line
@@ -6891,10 +6891,6 @@ public class PackageParser {
        @UnsupportedAppUsage
        public int mPreferredOrder = 0;

        // For use by package manager to keep track of when a package was last used.
        public long[] mLastPackageUsageTimeInMills =
                new long[PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT];

        // // User set enabled state.
        // public int mSetEnabled = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT;
        //
@@ -7281,27 +7277,6 @@ public class PackageParser {
            return true;
        }

        public long getLatestPackageUseTimeInMills() {
            long latestUse = 0L;
            for (long use : mLastPackageUsageTimeInMills) {
                latestUse = Math.max(latestUse, use);
            }
            return latestUse;
        }

        public long getLatestForegroundPackageUseTimeInMills() {
            int[] foregroundReasons = {
                PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY,
                PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE
            };

            long latestUse = 0L;
            for (int reason : foregroundReasons) {
                latestUse = Math.max(latestUse, mLastPackageUsageTimeInMills[reason]);
            }
            return latestUse;
        }

        public String toString() {
            return "Package{"
                + Integer.toHexString(System.identityHashCode(this))
+0 −6
Original line number Diff line number Diff line
@@ -1617,12 +1617,6 @@ public class PackageSetting extends SettingBase implements PackageStateInternal
        return pkgState.isHiddenUntilInstalled();
    }

    @NonNull
    @Override
    public long[] getLastPackageUsageTime() {
        return pkgState.getLastPackageUsageTimeInMills();
    }

    @Override
    public boolean isUpdatedSystemApp() {
        return pkgState.isUpdatedSystemApp();
+1 −37
Original line number Diff line number Diff line
@@ -40,16 +40,10 @@ class PackageUsage extends AbstractStatsBase<Map<String, PackageSetting>> {
    private static final String USAGE_FILE_MAGIC = "PACKAGE_USAGE__VERSION_";
    private static final String USAGE_FILE_MAGIC_VERSION_1 = USAGE_FILE_MAGIC + "1";

    private boolean mIsHistoricalPackageUsageAvailable = true;

    PackageUsage() {
        super("package-usage.list", "PackageUsage_DiskWriter", /* lock */ true);
    }

    boolean isHistoricalPackageUsageAvailable() {
        return mIsHistoricalPackageUsageAvailable;
    }

    @Override
    protected void writeInternal(Map<String, PackageSetting> pkgSettings) {
        AtomicFile file = getFile();
@@ -103,11 +97,9 @@ class PackageUsage extends AbstractStatsBase<Map<String, PackageSetting>> {
                // Empty file. Do nothing.
            } else if (USAGE_FILE_MAGIC_VERSION_1.equals(firstLine)) {
                readVersion1LP(pkgSettings, in, sb);
            } else {
                readVersion0LP(pkgSettings, in, sb, firstLine);
            }
        } catch (FileNotFoundException expected) {
            mIsHistoricalPackageUsageAvailable = false;
            // Expected. Nothing to do.
        } catch (IOException e) {
            Log.w(PackageManagerService.TAG, "Failed to read package usage times", e);
        } finally {
@@ -115,34 +107,6 @@ class PackageUsage extends AbstractStatsBase<Map<String, PackageSetting>> {
        }
    }

    private void readVersion0LP(Map<String, PackageSetting> pkgSettings, InputStream in,
            StringBuilder sb, String firstLine)
            throws IOException {
        // Initial version of the file had no version number and stored one
        // package-timestamp pair per line.
        // Note that the first line has already been read from the InputStream.
        for (String line = firstLine; line != null; line = readLine(in, sb)) {
            String[] tokens = line.split(" ");
            if (tokens.length != 2) {
                throw new IOException("Failed to parse " + line +
                        " as package-timestamp pair.");
            }

            String packageName = tokens[0];
            PackageSetting pkgSetting = pkgSettings.get(packageName);
            if (pkgSetting == null) {
                continue;
            }

            long timestamp = parseAsLong(tokens[1]);
            for (int reason = 0;
                    reason < PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT;
                    reason++) {
                pkgSetting.getPkgState().setLastPackageUsageTimeInMills(reason, timestamp);
            }
        }
    }

    private void readVersion1LP(Map<String, PackageSetting> pkgSettings, InputStream in,
            StringBuilder sb) throws IOException {
        // Version 1 of the file started with the corresponding version
+0 −13
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.server.pm.pkg;
import android.annotation.AppIdInt;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
import android.annotation.SystemApi;
import android.annotation.UserIdInt;
import android.content.Context;
@@ -231,18 +230,6 @@ public interface PackageState {
     */
    long getLastModifiedTime();

    /**
     * An aggregation across the framework of the last time an app was used for a particular reason.
     * Keys are indexes into the array represented by {@link PackageManager.NotifyReason}, values
     * are in epoch milliseconds.
     *
     * @hide
     */
    @Immutable.Ignore
    @Size(PackageManager.NOTIFY_PACKAGE_USE_REASONS_COUNT)
    @NonNull
    long[] getLastPackageUsageTime();

    /**
     * In epoch milliseconds. The timestamp of the last time the package on device went through
     * an update package installation.
+0 −13
Original line number Diff line number Diff line
@@ -115,19 +115,6 @@ public class PackageStateUnserialized {
        return latestUse;
    }

    public long getLatestForegroundPackageUseTimeInMills() {
        int[] foregroundReasons = {
                PackageManager.NOTIFY_PACKAGE_USE_ACTIVITY,
                PackageManager.NOTIFY_PACKAGE_USE_FOREGROUND_SERVICE
        };

        long latestUse = 0L;
        for (int reason : foregroundReasons) {
            latestUse = Math.max(latestUse, getLastPackageUsageTimeInMills()[reason]);
        }
        return latestUse;
    }

    public void updateFrom(PackageStateUnserialized other) {
        this.hiddenUntilInstalled = other.hiddenUntilInstalled;