1 /* 2 * Copyright (C) 2014 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.server.backup; 18 19 import android.app.job.JobInfo; 20 import android.app.job.JobParameters; 21 import android.app.job.JobScheduler; 22 import android.app.job.JobService; 23 import android.content.ComponentName; 24 import android.content.Context; 25 26 public class FullBackupJob extends JobService { 27 private static final String TAG = "FullBackupJob"; 28 private static final boolean DEBUG = true; 29 30 private static ComponentName sIdleService = 31 new ComponentName("android", FullBackupJob.class.getName()); 32 33 private static final int JOB_ID = 0x5038; 34 35 JobParameters mParams; 36 schedule(Context ctx, long minDelay, BackupManagerConstants constants)37 public static void schedule(Context ctx, long minDelay, BackupManagerConstants constants) { 38 JobScheduler js = (JobScheduler) ctx.getSystemService(Context.JOB_SCHEDULER_SERVICE); 39 JobInfo.Builder builder = new JobInfo.Builder(JOB_ID, sIdleService); 40 synchronized (constants) { 41 builder.setRequiresDeviceIdle(true) 42 .setRequiredNetworkType(constants.getFullBackupRequiredNetworkType()) 43 .setRequiresCharging(constants.getFullBackupRequireCharging()); 44 } 45 if (minDelay > 0) { 46 builder.setMinimumLatency(minDelay); 47 } 48 js.schedule(builder.build()); 49 } 50 51 // callback from the Backup Manager Service: it's finished its work for this pass finishBackupPass()52 public void finishBackupPass() { 53 if (mParams != null) { 54 jobFinished(mParams, false); 55 mParams = null; 56 } 57 } 58 59 // ----- scheduled job interface ----- 60 61 @Override onStartJob(JobParameters params)62 public boolean onStartJob(JobParameters params) { 63 mParams = params; 64 Trampoline service = BackupManagerService.getInstance(); 65 return service.beginFullBackup(this); 66 } 67 68 @Override onStopJob(JobParameters params)69 public boolean onStopJob(JobParameters params) { 70 if (mParams != null) { 71 mParams = null; 72 Trampoline service = BackupManagerService.getInstance(); 73 service.endFullBackup(); 74 } 75 return false; 76 } 77 78 } 79