All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src.com.android.server.backup.keyvalue.TaskException Maven / Gradle / Ivy

Go to download

A library jar that provides APIs for Applications written for the Google Android Platform.

There is a newer version: 15-robolectric-12650502
Show newest version
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.server.backup.keyvalue;

import android.app.backup.BackupTransport;

import com.android.internal.util.Preconditions;

/**
 * The key-value backup task has failed, no more packages will be processed and we shouldn't attempt
 * any more backups now. These can be caused by transport failures (as opposed to agent failures).
 *
 * @see KeyValueBackupTask
 * @see AgentException
 */
class TaskException extends BackupException {
    private static final int DEFAULT_STATUS = BackupTransport.TRANSPORT_ERROR;

    static TaskException stateCompromised() {
        return new TaskException(/* stateCompromised */ true, DEFAULT_STATUS);
    }

    static TaskException stateCompromised(Exception cause) {
        if (cause instanceof TaskException) {
            TaskException exception = (TaskException) cause;
            return new TaskException(cause, /* stateCompromised */ true, exception.getStatus());
        }
        return new TaskException(cause, /* stateCompromised */ true, DEFAULT_STATUS);
    }

    static TaskException forStatus(int status) {
        Preconditions.checkArgument(
                status != BackupTransport.TRANSPORT_OK, "Exception based on TRANSPORT_OK");
        return new TaskException(/* stateCompromised */ false, status);
    }

    static TaskException causedBy(Exception cause) {
        if (cause instanceof TaskException) {
            return (TaskException) cause;
        }
        return new TaskException(cause, /* stateCompromised */ false, DEFAULT_STATUS);
    }

    static TaskException create() {
        return new TaskException(/* stateCompromised */ false, DEFAULT_STATUS);
    }

    private final boolean mStateCompromised;
    private final int mStatus;

    private TaskException(Exception cause, boolean stateCompromised, int status) {
        super(cause);
        mStateCompromised = stateCompromised;
        mStatus = status;
    }

    private TaskException(boolean stateCompromised, int status) {
        mStateCompromised = stateCompromised;
        mStatus = status;
    }

    boolean isStateCompromised() {
        return mStateCompromised;
    }

    int getStatus() {
        return mStatus;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy