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

Commit 8e9d78ff authored by Rubin Xu's avatar Rubin Xu
Browse files

Delay gargabe collection during onDestroy()

Allow the activity object to become unreachable before
iniating a gargabe collection to sanitize memory.

Bug: 189315376
Test: add device lock, confirm device lock in Settings,
      then a memory dump and search for password shards.
Change-Id: I807d74628e1355814807855ad309d86ca1fb38a1
parent cf5bb135
Loading
Loading
Loading
Loading
+10 −5
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.settings.password;


import android.app.KeyguardManager;
import android.app.KeyguardManager;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserManager;
import android.os.UserManager;
import android.util.Log;
import android.util.Log;
import android.view.MenuItem;
import android.view.MenuItem;
@@ -163,11 +165,14 @@ public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivi
    @Override
    @Override
    public void onDestroy() {
    public void onDestroy() {
        super.onDestroy();
        super.onDestroy();
        // Force a garbage collection immediately to remove remnant of user password shards
        // Force a garbage collection to remove remnant of user password shards from memory.
        // from memory.
        // Execute this with a slight delay to allow the activity lifecycle to complete and
        // the instance to become gc-able.
        new Handler(Looper.myLooper()).postDelayed(() -> {
            System.gc();
            System.gc();
            System.runFinalization();
            System.runFinalization();
            System.gc();
            System.gc();
        }, 5000);
    }
    }


    @Override
    @Override
+10 −5
Original line number Original line Diff line number Diff line
@@ -25,6 +25,8 @@ import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.UserManager;
import android.os.UserManager;
import android.os.storage.StorageManager;
import android.os.storage.StorageManager;
@@ -216,11 +218,14 @@ public class ConfirmLockPassword extends ConfirmDeviceCredentialBaseActivity {
        public void onDestroy() {
        public void onDestroy() {
            super.onDestroy();
            super.onDestroy();
            mPasswordEntry.setText(null);
            mPasswordEntry.setText(null);
            // Force a garbage collection immediately to remove remnant of user password shards
            // Force a garbage collection to remove remnant of user password shards from memory.
            // from memory.
            // Execute this with a slight delay to allow the activity lifecycle to complete and
            // the instance to become gc-able.
            new Handler(Looper.myLooper()).postDelayed(() -> {
                System.gc();
                System.gc();
                System.runFinalization();
                System.runFinalization();
                System.gc();
                System.gc();
            }, 5000);
        }
        }


        private int getDefaultHeader() {
        private int getDefaultHeader() {