1 /* 2 * Copyright (C) 2017 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.internal; 18 19 import static com.android.server.backup.BackupManagerService.DEBUG; 20 import static com.android.server.backup.BackupManagerService.RUN_INITIALIZE_ACTION; 21 import static com.android.server.backup.BackupManagerService.TAG; 22 23 import android.content.BroadcastReceiver; 24 import android.content.Context; 25 import android.content.Intent; 26 import android.os.PowerManager; 27 import android.util.ArraySet; 28 import android.util.Slog; 29 30 import com.android.server.backup.BackupManagerService; 31 32 public class RunInitializeReceiver extends BroadcastReceiver { 33 private final BackupManagerService mBackupManagerService; 34 35 public RunInitializeReceiver(BackupManagerService backupManagerService) { 36 mBackupManagerService = backupManagerService; 37 } 38 39 public void onReceive(Context context, Intent intent) { 40 if (RUN_INITIALIZE_ACTION.equals(intent.getAction())) { 41 synchronized (mBackupManagerService.getQueueLock()) { 42 final ArraySet<String> pendingInits = mBackupManagerService.getPendingInits(); 43 if (DEBUG) { 44 Slog.v(TAG, "Running a device init; " + pendingInits.size() + " pending"); 45 } 46 47 if (pendingInits.size() > 0) { 48 final String[] transports = 49 pendingInits.toArray(new String[pendingInits.size()]); 50 51 mBackupManagerService.clearPendingInits(); 52 53 PowerManager.WakeLock wakelock = mBackupManagerService.getWakelock(); 54 wakelock.acquire(); 55 OnTaskFinishedListener listener = caller -> wakelock.release(); 56 57 Runnable task = 58 new PerformInitializeTask( 59 mBackupManagerService, transports, null, listener); 60 mBackupManagerService.getBackupHandler().post(task); 61 } 62 } 63 } 64 } 65 } 66