Home | History | Annotate | Download | only in scheduling
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.voicemail.impl.scheduling;
     18 
     19 import android.content.Context;
     20 import android.os.Bundle;
     21 import com.android.dialer.proguard.UsedByReflection;
     22 import com.android.voicemail.impl.VvmLog;
     23 
     24 /** Task to block another task of the same ID from being queued for a certain amount of time. */
     25 @UsedByReflection(value = "Tasks.java")
     26 public class BlockerTask extends BaseTask {
     27 
     28   private static final String TAG = "BlockerTask";
     29 
     30   public static final String EXTRA_TASK_ID = "extra_task_id";
     31   public static final String EXTRA_BLOCK_FOR_MILLIS = "extra_block_for_millis";
     32 
     33   public BlockerTask() {
     34     super(TASK_INVALID);
     35   }
     36 
     37   @Override
     38   public void onCreate(Context context, Bundle extras) {
     39     super.onCreate(context, extras);
     40     setId(extras.getInt(EXTRA_TASK_ID, TASK_INVALID));
     41     setExecutionTime(getTimeMillis() + extras.getInt(EXTRA_BLOCK_FOR_MILLIS, 0));
     42   }
     43 
     44   @Override
     45   public void onExecuteInBackgroundThread() {
     46     // Do nothing.
     47   }
     48 
     49   @Override
     50   public void onDuplicatedTaskAdded(Task task) {
     51     VvmLog.i(TAG, task + "blocked, " + getReadyInMilliSeconds() + "millis remaining");
     52   }
     53 }
     54