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

Commit a7fe759d authored by Jason Monk's avatar Jason Monk Committed by Android (Google) Code Review
Browse files

Merge "More memory updates" into mnc-dev

parents 9dbd6165 ab2046aa
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -6664,6 +6664,21 @@
    <!-- Label for maximum memory use section [CHAR LIMIT=30] -->
    <string name="maximum_memory_use">Maximum memory use</string>

    <!-- Label for app list of memory use [CHAR LIMIT=30] -->
    <string name="memory_usage">Memory usage</string>

    <!-- Label for app list of memory use [CHAR LIMIT=30] -->
    <string name="app_list_memory_use">App usage</string>

    <!-- Label for details about an app's memory use [CHAR LIMIT=30] -->
    <string name="memory_details">Details</string>

    <!-- Summary for how much memory an app has used [CHAR LIMIT=NONE] -->
    <string name="memory_use_summary"><xliff:g id="size" example="30MB">%1$s</xliff:g> avg memory used in last 3 hours</string>

    <!-- Summary for no memory use for an app [CHAR LIMIT=NONE] -->
    <string name="no_memory_use_summary">No memory used in last 3 hours</string>

    <!-- Menu item for Sorting list by average memory use [CHAR LIMIT=NONE]-->
    <string name="sort_avg_use">Sort by avg use</string>

+4 −3
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                  android:title="@string/memory_details_title">
                  android:title="@string/memory_usage">

    <PreferenceCategory
        android:title="@string/average_memory_use" />
@@ -36,7 +36,8 @@
        android:layout="@layout/horizontal_preference"
        android:title="@string/memory_maximum_usage" />

    <com.android.settings.applications.SpacePreference
        android:layout_height="15dp" />
    <PreferenceCategory
        android:key="processes"
        android:title="@string/memory_details" />

</PreferenceScreen>
+6 −0
Original line number Diff line number Diff line
@@ -51,4 +51,10 @@
        android:title="@string/power_usage_summary_title"
        android:selectable="true" />

    <Preference
        android:key="memory"
        android:title="@string/memory_settings_title"
        android:enabled="false"
        android:selectable="true" />

</PreferenceScreen>
+57 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@ public class InstalledAppDetails extends AppInfoBase
    private static final String KEY_DATA = "data_settings";
    private static final String KEY_LAUNCH = "preferred_settings";
    private static final String KEY_BATTERY = "battery";
    private static final String KEY_MEMORY = "memory";

    private final HashSet<String> mHomePackages = new HashSet<String>();

@@ -130,6 +131,7 @@ public class InstalledAppDetails extends AppInfoBase
    private Preference mPermissionsPreference;
    private Preference mLaunchPreference;
    private Preference mDataPreference;
    private Preference mMemoryPreference;

    private boolean mDisableAfterUninstall;
    // Used for updating notification preference.
@@ -143,6 +145,9 @@ public class InstalledAppDetails extends AppInfoBase
    private BatteryStatsHelper mBatteryHelper;
    private BatterySipper mSipper;

    protected ProcStatsData mStatsManager;
    protected ProcStatsPackageEntry mStats;

    private boolean handleDisableable(Button button) {
        boolean disableable = false;
        // Try to prevent the user from bricking their phone
@@ -260,6 +265,7 @@ public class InstalledAppDetails extends AppInfoBase
                    mDataCallbacks);
        }
        new BatteryUpdater().execute();
        new MemoryUpdater().execute();
    }

    @Override
@@ -295,6 +301,8 @@ public class InstalledAppDetails extends AppInfoBase
        mBatteryPreference = findPreference(KEY_BATTERY);
        mBatteryPreference.setEnabled(false);
        mBatteryPreference.setOnPreferenceClickListener(this);
        mMemoryPreference = findPreference(KEY_MEMORY);
        mMemoryPreference.setOnPreferenceClickListener(this);

        mLaunchPreference = findPreference(KEY_LAUNCH);
        if (mAppEntry.info != null) {
@@ -701,6 +709,9 @@ public class InstalledAppDetails extends AppInfoBase
            startManagePermissionsActivity();
        } else if (preference == mLaunchPreference) {
            startAppInfoFragment(AppLaunchSettings.class, mLaunchPreference.getTitle());
        } else if (preference == mMemoryPreference) {
            ProcessStatsBase.launchMemoryDetail((SettingsActivity) getActivity(),
                    mStatsManager.getMemInfo(), mStats);
        } else if (preference == mDataPreference) {
            Bundle args = new Bundle();
            args.putString(DataUsageSummary.EXTRA_SHOW_APP_IMMEDIATE_PKG,
@@ -767,6 +778,49 @@ public class InstalledAppDetails extends AppInfoBase
        }
    }

    private class MemoryUpdater extends AsyncTask<Void, Void, ProcStatsPackageEntry> {

        @Override
        protected ProcStatsPackageEntry doInBackground(Void... params) {
            if (mPackageInfo == null) {
                return null;
            }
            if (mStatsManager == null) {
                mStatsManager = new ProcStatsData(getActivity(), false);
                mStatsManager.setDuration(ProcessStatsBase.sDurations[0]);
            }
            mStatsManager.refreshStats(true);
            for (ProcStatsPackageEntry pkgEntry : mStatsManager.getEntries()) {
                for (ProcStatsEntry entry : pkgEntry.mEntries) {
                    if (entry.mUid == mPackageInfo.applicationInfo.uid) {
                        pkgEntry.updateMetrics();
                        return pkgEntry;
                    }
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(ProcStatsPackageEntry entry) {
            if (getActivity() == null) {
                return;
            }
            if (entry != null) {
                mStats = entry;
                mMemoryPreference.setEnabled(true);
                double amount = Math.max(entry.mRunWeight, entry.mBgWeight)
                        * mStatsManager.getMemInfo().weightToRam;
                mMemoryPreference.setSummary(getString(R.string.memory_use_summary,
                        Formatter.formatShortFileSize(getContext(), (long) amount)));
            } else {
                mMemoryPreference.setEnabled(false);
                mMemoryPreference.setSummary(getString(R.string.no_memory_use_summary));
            }
        }

    }

    private class BatteryUpdater extends AsyncTask<Void, Void, Void> {
        @Override
        protected Void doInBackground(Void... params) {
@@ -787,6 +841,9 @@ public class InstalledAppDetails extends AppInfoBase

        @Override
        protected void onPostExecute(Void result) {
            if (getActivity() == null) {
                return;
            }
            refreshUi();
        }
    }
+16 −1
Original line number Diff line number Diff line
@@ -18,14 +18,16 @@ package com.android.settings.applications;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import com.android.internal.app.ProcessStats;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.applications.ProcStatsData.MemInfo;

public abstract class ProcessStatsBase extends SettingsPreferenceFragment
        implements OnItemSelectedListener {
@@ -124,4 +126,17 @@ public abstract class ProcessStatsBase extends SettingsPreferenceFragment
    }

    public abstract void refreshUi();

    public static void launchMemoryDetail(SettingsActivity activity, MemInfo memInfo,
            ProcStatsPackageEntry entry) {
        Bundle args = new Bundle();
        args.putParcelable(ProcessStatsDetail.EXTRA_PACKAGE_ENTRY, entry);
        args.putDouble(ProcessStatsDetail.EXTRA_WEIGHT_TO_RAM, memInfo.weightToRam);
        args.putLong(ProcessStatsDetail.EXTRA_TOTAL_TIME, memInfo.memTotalTime);
        args.putDouble(ProcessStatsDetail.EXTRA_MAX_MEMORY_USAGE,
                memInfo.usedWeight * memInfo.weightToRam);
        args.putDouble(ProcessStatsDetail.EXTRA_TOTAL_SCALE, memInfo.totalScale);
        activity.startPreferencePanel(ProcessStatsDetail.class.getName(), args,
                R.string.memory_usage, null, null, 0);
    }
}
Loading