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.MORE_DEBUG; 20 import static com.android.server.backup.BackupManagerService.TAG; 21 22 import android.database.ContentObserver; 23 import android.os.Handler; 24 import android.util.Slog; 25 26 import com.android.server.backup.BackupManagerService; 27 import com.android.server.backup.KeyValueBackupJob; 28 29 public class ProvisionedObserver extends ContentObserver { 30 31 private BackupManagerService backupManagerService; 32 33 public ProvisionedObserver( 34 BackupManagerService backupManagerService, Handler handler) { 35 super(handler); 36 this.backupManagerService = backupManagerService; 37 } 38 39 public void onChange(boolean selfChange) { 40 final boolean wasProvisioned = backupManagerService.isProvisioned(); 41 final boolean isProvisioned = backupManagerService.deviceIsProvisioned(); 42 // latch: never unprovision 43 backupManagerService.setProvisioned(wasProvisioned || isProvisioned); 44 if (MORE_DEBUG) { 45 Slog.d(TAG, "Provisioning change: was=" + wasProvisioned 46 + " is=" + isProvisioned + " now=" + backupManagerService.isProvisioned()); 47 } 48 49 synchronized (backupManagerService.getQueueLock()) { 50 if (backupManagerService.isProvisioned() && !wasProvisioned 51 && backupManagerService.isEnabled()) { 52 // we're now good to go, so start the backup alarms 53 if (MORE_DEBUG) { 54 Slog.d(TAG, "Now provisioned, so starting backups"); 55 } 56 KeyValueBackupJob.schedule(backupManagerService.getContext(), 57 backupManagerService.getConstants()); 58 backupManagerService.scheduleNextFullBackupJob(0); 59 } 60 } 61 } 62 } 63