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

Commit d9fb14a3 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Misc memory stuff."

parents 3fa263c6 2286cdc0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -2821,6 +2821,7 @@ package android.app {
    method public void recreate();
    method public void registerForContextMenu(android.view.View);
    method public final deprecated void removeDialog(int);
    method public void reportFullyDrawn();
    method public final boolean requestWindowFeature(int);
    method public final void runOnUiThread(java.lang.Runnable);
    method public void setContentView(int);
+24 −0
Original line number Diff line number Diff line
@@ -686,6 +686,7 @@ public class Activity extends ContextThemeWrapper
    boolean mFinished;
    boolean mStartedActivity;
    private boolean mDestroyed;
    private boolean mDoReportFullyDrawn = true;
    /** true if the activity is going through a transient pause */
    /*package*/ boolean mTemporaryPause = false;
    /** true if the activity is being destroyed in order to recreate it with a new configuration */
@@ -1448,6 +1449,27 @@ public class Activity extends ContextThemeWrapper
        getApplication().dispatchActivityDestroyed(this);
    }

    /**
     * Report to the system that your app is now fully drawn.  This is only used
     * to help instrument app launch times, so that the app can report when it is
     * fully in a usable state; without this, all the system can determine is when
     * its window is first drawn and displayed.  To participate in app launch time
     * measurement, you should always call this method after first launch (when
     * {@link #onCreate(android.os.Bundle)} is called) at the point where you have
     * entirely drawn your UI and populated with all of the significant data.  You
     * can safely call this method any time after first launch as well, in which case
     * it will simply be ignored.
     */
    public void reportFullyDrawn() {
        if (mDoReportFullyDrawn) {
            mDoReportFullyDrawn = false;
            try {
                ActivityManagerNative.getDefault().reportActivityFullyDrawn(mToken);
            } catch (RemoteException e) {
            }
        }
    }

    /**
     * Called by the system when the device configuration changes while your
     * activity is running.  Note that this will <em>only</em> be called if
@@ -5252,6 +5274,7 @@ public class Activity extends ContextThemeWrapper
    }

    final void performPause() {
        mDoReportFullyDrawn = false;
        mFragments.dispatchPause();
        mCalled = false;
        onPause();
@@ -5271,6 +5294,7 @@ public class Activity extends ContextThemeWrapper
    }
    
    final void performStop() {
        mDoReportFullyDrawn = false;
        if (mLoadersStarted) {
            mLoadersStarted = false;
            if (mLoaderManager != null) {
+19 −0
Original line number Diff line number Diff line
@@ -1949,6 +1949,14 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            return true;
        }

        case REPORT_ACTIVITY_FULLY_DRAWN_TRANSACTION: {
            data.enforceInterface(IActivityManager.descriptor);
            IBinder token = data.readStrongBinder();
            reportActivityFullyDrawn(token);
            reply.writeNoException();
            return true;
        }

        }

        return super.onTransact(code, data, reply, flags);
@@ -4463,5 +4471,16 @@ class ActivityManagerProxy implements IActivityManager
        reply.recycle();
    }

    public void reportActivityFullyDrawn(IBinder token) throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeStrongBinder(token);
        mRemote.transact(REPORT_ACTIVITY_FULLY_DRAWN_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
        reply.recycle();
    }

    private IBinder mRemote;
}
+3 −0
Original line number Diff line number Diff line
@@ -392,6 +392,8 @@ public interface IActivityManager extends IInterface {

    public void hang(IBinder who, boolean allowRestart) throws RemoteException;

    public void reportActivityFullyDrawn(IBinder token) throws RemoteException;

    /*
     * Private non-Binder interfaces
     */
@@ -669,4 +671,5 @@ public interface IActivityManager extends IInterface {
    int SET_FOCUSED_STACK_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+171;
    int GET_STACK_BOX_INFO_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+172;
    int CONVERT_TO_OPAQUE_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+173;
    int REPORT_ACTIVITY_FULLY_DRAWN_TRANSACTION = IBinder.FIRST_CALL_TRANSACTION+174;
}
+36 −8
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.internal.os.ProcessStats;
import com.android.internal.os.TransferPipe;
import com.android.internal.util.FastPrintWriter;
import com.android.internal.util.FastXmlSerializer;
import com.android.internal.util.MemInfoReader;
import com.android.server.AppOpsService;
import com.android.server.AttributeCache;
import com.android.server.IntentResolver;
@@ -2988,6 +2989,17 @@ public final class ActivityManagerService extends ActivityManagerNative
        mRecentTasks.add(0, task);
    }
    @Override
    public void reportActivityFullyDrawn(IBinder token) {
        synchronized (this) {
            ActivityRecord r = ActivityRecord.isInStackLocked(token);
            if (r == null) {
                return;
            }
            r.reportFullyDrawnLocked();
        }
    }
    @Override
    public void setRequestedOrientation(IBinder token, int requestedOrientation) {
        synchronized (this) {
@@ -11100,6 +11112,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                new ArrayList[DUMP_MEM_OOM_LABEL.length];
        long totalPss = 0;
        long cachedPss = 0;
        Debug.MemoryInfo mi = null;
        for (int i = procs.size() - 1 ; i >= 0 ; i--) {
@@ -11108,7 +11121,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            int oomAdj;
            synchronized (this) {
                thread = r.thread;
                oomAdj = r.setAdj;
                oomAdj = r.getSetAdjWithServices();
            }
            if (thread != null) {
                if (!isCheckinRequest && dumpDetails) {
@@ -11139,7 +11152,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                final long myTotalPss = mi.getTotalPss();
                synchronized (this) {
                    if (r.thread != null && oomAdj == r.setAdj) {
                    if (r.thread != null && oomAdj == r.getSetAdjWithServices()) {
                        // Record this for posterity if the process has been stable.
                        r.baseProcessTracker.addPss(myTotalPss, true);
                    }
@@ -11160,6 +11173,10 @@ public final class ActivityManagerService extends ActivityManagerNative
                        otherPss -= mem;
                    }
                    if (oomAdj >= ProcessList.CACHED_APP_MIN_ADJ) {
                        cachedPss += myTotalPss;
                    }
                    for (int oomIndex=0; oomIndex<oomPss.length; oomIndex++) {
                        if (r.setAdj <= DUMP_MEM_OOM_ADJ[oomIndex]
                                || oomIndex == (oomPss.length-1)) {
@@ -11274,7 +11291,14 @@ public final class ActivityManagerService extends ActivityManagerNative
                dumpMemItems(out, "  ", catMems, true);
            }
            pw.println();
            pw.print("Total PSS: "); pw.print(totalPss); pw.println(" kB");
            if (!brief) {
                MemInfoReader memInfo = new MemInfoReader();
                memInfo.readMemInfo();
                pw.print("Total RAM: "); pw.print(memInfo.getTotalSize()/1024); pw.println(" kB");
                pw.print(" Free RAM: "); pw.print(cachedPss + (memInfo.getCachedSize()/1024)
                        + (memInfo.getFreeSize()/1024)); pw.println(" kB");
            }
            pw.print(" Used PSS: "); pw.print(totalPss - cachedPss); pw.println(" kB");
            if (!brief) {
                final int[] SINGLE_LONG_FORMAT = new int[] {
                    Process.PROC_SPACE_TERM|Process.PROC_OUT_LONG
@@ -11295,6 +11319,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                Process.readProcFile("/sys/kernel/mm/ksm/pages_volatile",
                        SINGLE_LONG_FORMAT, null, longOut, null);
                long voltile = longOut[0] * ProcessList.PAGE_SIZE / 1024;
                if (sharing != 0 || shared != 0 || unshared != 0 || voltile != 0) {
                    pw.print("      KSM: "); pw.print(sharing); pw.print(" kB saved from shared ");
                            pw.print(shared); pw.println(" kB");
                    pw.print("           "); pw.print(unshared); pw.print(" kB unshared; ");
@@ -11302,6 +11327,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                }
            }
        }
    }
    /**
     * Searches array of arguments for the specified string
@@ -13469,6 +13495,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        // infinite recursion.
        app.adjSeq = mAdjSeq;
        app.curRawAdj = app.nonStoppingAdj = adj;
        app.hasStartedServices = false;
        if (mBackupTarget != null && app == mBackupTarget.app) {
            // If possible we want to avoid killing apps while they're being backed up
@@ -13489,6 +13516,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            while (jt.hasNext() && adj > ProcessList.FOREGROUND_APP_ADJ) {
                ServiceRecord s = jt.next();
                if (s.startRequested) {
                    app.hasStartedServices = true;
                    if (app.hasShownUi && app != mHomeProcess) {
                        // If this process has shown some UI, let it immediately
                        // go to the LRU list because it may be pretty heavy with
@@ -14333,7 +14361,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            emptyProcessLimit = 1;
            cachedProcessLimit = 0;
        } else {
            emptyProcessLimit = (mProcessLimit*2)/3;
            emptyProcessLimit = ProcessList.computeEmptyProcessLimit(mProcessLimit);
            cachedProcessLimit = mProcessLimit - emptyProcessLimit;
        }
Loading