/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.messaging.util; import android.content.Intent; import android.os.AsyncTask; import android.os.Debug; import android.os.SystemClock; import com.android.messaging.Factory; import com.android.messaging.util.Assert.RunsOnAnyThread; /** * Wrapper class which provides explicit API for: *
Use {@link #UNBOUNDED_TIME} if you do not know the maximum expected time. This
* is strongly discouraged as it can block other AsyncTasks indefinitely.
*
* @param cancelExecutionOnTimeout whether to attempt to cancel the task execution on timeout.
* If this is set, at execution timeout we will call cancel(), so doInBackgroundTimed()
* should periodically check if the task is to be cancelled and finish promptly if
* possible, and handle the cancel event in onCancelled(). Also, at the end of execution
* we will not crash the execution if it went over limit since we explicitly canceled it.
*/
public SafeAsyncTask(final long maxTimeMillis, final boolean cancelExecutionOnTimeout) {
Assert.isMainThread(); // AsyncTask has to be created on the main thread
mMaxExecutionTimeMillis = maxTimeMillis;
mCancelExecutionOnTimeout = cancelExecutionOnTimeout;
}
public final SafeAsyncTask