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.phone.vvm.omtp.scheduling; 18 19 import android.content.Intent; 20 21 import com.android.phone.vvm.omtp.scheduling.Task.TaskId; 22 23 /** 24 * If a task with this policy succeeds, a {@link BlockerTask} with the same {@link TaskId} of the 25 * task will be queued immediately, preventing the same task from running for a certain amount of 26 * time. 27 */ 28 public class MinimalIntervalPolicy implements Policy { 29 30 BaseTask mTask; 31 TaskId mId; 32 int mBlockForMillis; 33 MinimalIntervalPolicy(int blockForMillis)34 public MinimalIntervalPolicy(int blockForMillis) { 35 mBlockForMillis = blockForMillis; 36 } 37 38 @Override onCreate(BaseTask task, Intent intent, int flags, int startId)39 public void onCreate(BaseTask task, Intent intent, int flags, int startId) { 40 mTask = task; 41 mId = mTask.getId(); 42 } 43 44 @Override onBeforeExecute()45 public void onBeforeExecute() { 46 47 } 48 49 @Override onCompleted()50 public void onCompleted() { 51 if (!mTask.hasFailed()) { 52 Intent intent = mTask 53 .createIntent(mTask.getContext(), BlockerTask.class, mId.subId); 54 intent.putExtra(BlockerTask.EXTRA_TASK_ID, mId.id); 55 intent.putExtra(BlockerTask.EXTRA_BLOCK_FOR_MILLIS, mBlockForMillis); 56 mTask.getContext().startService(intent); 57 } 58 } 59 60 @Override onFail()61 public void onFail() { 62 63 } 64 65 @Override onDuplicatedTaskAdded()66 public void onDuplicatedTaskAdded() { 67 68 } 69 } 70