From d8c160351c94e57ee7310ee1f3215f6a8b3a2fc2 Mon Sep 17 00:00:00 2001 From: Koji Fukui Date: Thu, 6 Oct 2016 23:00:00 +0900 Subject: [PATCH] Ignore toast request of pinning if request interval is too short Symptom: System crash happens if an application repeatedly requests to finish itself in pinning state. Root cause: Toast for pinning state is shown when the application requests to finish itself. Every toasts use file descripters and they consumes all available file descripters. System crash happens because of file descriptor shortage. Solution: Ignore toast request for pinning state if request interval is too short. Bug: 34211454 Change-Id: I4c3b45825270ab96fcfb24723195e9189709c2ec --- .../java/com/android/server/am/LockTaskNotify.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/core/java/com/android/server/am/LockTaskNotify.java b/services/core/java/com/android/server/am/LockTaskNotify.java index 8c18c462e956a..0412db5e49c92 100644 --- a/services/core/java/com/android/server/am/LockTaskNotify.java +++ b/services/core/java/com/android/server/am/LockTaskNotify.java @@ -20,6 +20,8 @@ import android.app.ActivityManager; import android.content.Context; import android.os.Handler; import android.os.Message; +import android.os.SystemClock; +import android.util.Slog; import android.view.WindowManager; import android.widget.Toast; @@ -31,10 +33,12 @@ import com.android.internal.R; */ public class LockTaskNotify { private static final String TAG = "LockTaskNotify"; + private static final long SHOW_TOAST_MINIMUM_INTERVAL = 1000; private final Context mContext; private final H mHandler; private Toast mLastToast; + private long mLastShowToastTime; public LockTaskNotify(Context context) { mContext = context; @@ -55,10 +59,16 @@ public class LockTaskNotify { if (text == null) { return; } + long showToastTime = SystemClock.elapsedRealtime(); + if ((showToastTime - mLastShowToastTime) < SHOW_TOAST_MINIMUM_INTERVAL) { + Slog.i(TAG, "Ignore toast since it is requested in very short interval."); + return; + } if (mLastToast != null) { mLastToast.cancel(); } mLastToast = makeAllUserToastAndShow(text); + mLastShowToastTime = showToastTime; } public void show(boolean starting) {