Search in sources :

Example 21 with IBackupTransport

use of com.android.internal.backup.IBackupTransport in project android_frameworks_base by AOSPA.

the class BackupManagerService method requestBackup.

public int requestBackup(String[] packages, IBackupObserver observer) {
    mContext.enforceCallingPermission(android.Manifest.permission.BACKUP, "requestBackup");
    if (packages == null || packages.length < 1) {
        Slog.e(TAG, "No packages named for backup request");
        sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
        throw new IllegalArgumentException("No packages are provided for backup");
    }
    IBackupTransport transport = getTransport(mCurrentTransport);
    if (transport == null) {
        sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
        return BackupManager.ERROR_TRANSPORT_ABORTED;
    }
    ArrayList<String> fullBackupList = new ArrayList<>();
    ArrayList<String> kvBackupList = new ArrayList<>();
    for (String packageName : packages) {
        try {
            PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
            if (!appIsEligibleForBackup(packageInfo.applicationInfo)) {
                sendBackupOnPackageResult(observer, packageName, BackupManager.ERROR_BACKUP_NOT_ALLOWED);
                continue;
            }
            if (appGetsFullBackup(packageInfo)) {
                fullBackupList.add(packageInfo.packageName);
            } else {
                kvBackupList.add(packageInfo.packageName);
            }
        } catch (NameNotFoundException e) {
            sendBackupOnPackageResult(observer, packageName, BackupManager.ERROR_PACKAGE_NOT_FOUND);
        }
    }
    EventLog.writeEvent(EventLogTags.BACKUP_REQUESTED, packages.length, kvBackupList.size(), fullBackupList.size());
    if (MORE_DEBUG) {
        Slog.i(TAG, "Backup requested for " + packages.length + " packages, of them: " + fullBackupList.size() + " full backups, " + kvBackupList.size() + " k/v backups");
    }
    String dirName;
    try {
        dirName = transport.transportDirName();
    } catch (Exception e) {
        Slog.e(TAG, "Transport unavailable while attempting backup: " + e.getMessage());
        sendBackupFinished(observer, BackupManager.ERROR_TRANSPORT_ABORTED);
        return BackupManager.ERROR_TRANSPORT_ABORTED;
    }
    Message msg = mBackupHandler.obtainMessage(MSG_REQUEST_BACKUP);
    msg.obj = new BackupParams(transport, dirName, kvBackupList, fullBackupList, observer, true);
    mBackupHandler.sendMessage(msg);
    return BackupManager.SUCCESS;
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) Message(android.os.Message) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) RemoteException(android.os.RemoteException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException)

Example 22 with IBackupTransport

use of com.android.internal.backup.IBackupTransport in project android_frameworks_base by AOSPA.

the class BackupManagerService method recordInitPendingLocked.

// Maintain persistent state around whether need to do an initialize operation.
// Must be called with the queue lock held.
void recordInitPendingLocked(boolean isPending, String transportName) {
    if (MORE_DEBUG)
        Slog.i(TAG, "recordInitPendingLocked: " + isPending + " on transport " + transportName);
    mBackupHandler.removeMessages(MSG_RETRY_INIT);
    try {
        IBackupTransport transport = getTransport(transportName);
        if (transport != null) {
            String transportDirName = transport.transportDirName();
            File stateDir = new File(mBaseStateDir, transportDirName);
            File initPendingFile = new File(stateDir, INIT_SENTINEL_FILE_NAME);
            if (isPending) {
                // We need an init before we can proceed with sending backup data.
                // Record that with an entry in our set of pending inits, as well as
                // journaling it via creation of a sentinel file.
                mPendingInits.add(transportName);
                try {
                    (new FileOutputStream(initPendingFile)).close();
                } catch (IOException ioe) {
                // Something is badly wrong with our permissions; just try to move on
                }
            } else {
                // No more initialization needed; wipe the journal and reset our state.
                initPendingFile.delete();
                mPendingInits.remove(transportName);
            }
            // done; don't fall through to the error case
            return;
        }
    } catch (Exception e) {
        // transport threw when asked its name; fall through to the lookup-failed case
        Slog.e(TAG, "Transport " + transportName + " failed to report name: " + e.getMessage());
    }
    // to retry the init later.
    if (isPending) {
        mPendingInits.add(transportName);
        mBackupHandler.sendMessageDelayed(mBackupHandler.obtainMessage(MSG_RETRY_INIT, (isPending ? 1 : 0), 0, transportName), TRANSPORT_RETRY_INTERVAL);
    }
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) AtomicFile(android.util.AtomicFile) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) RemoteException(android.os.RemoteException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException)

Example 23 with IBackupTransport

use of com.android.internal.backup.IBackupTransport in project android_frameworks_base by AOSPA.

the class BackupManagerService method isAppEligibleForBackup.

public boolean isAppEligibleForBackup(String packageName) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "isAppEligibleForBackup");
    try {
        PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
        if (!appIsEligibleForBackup(packageInfo.applicationInfo) || appIsStopped(packageInfo.applicationInfo)) {
            return false;
        }
        IBackupTransport transport = getTransport(mCurrentTransport);
        if (transport != null) {
            try {
                return transport.isAppEligibleForBackup(packageInfo, appGetsFullBackup(packageInfo));
            } catch (Exception e) {
                Slog.e(TAG, "Unable to ask about eligibility: " + e.getMessage());
            }
        }
        // If transport is not present we couldn't tell that the package is not eligible.
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) RemoteException(android.os.RemoteException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException)

Example 24 with IBackupTransport

use of com.android.internal.backup.IBackupTransport in project android_frameworks_base by AOSPA.

the class BackupManagerService method clearBackupData.

// Clear the given package's backup data from the current transport
public void clearBackupData(String transportName, String packageName) {
    if (DEBUG)
        Slog.v(TAG, "clearBackupData() of " + packageName + " on " + transportName);
    PackageInfo info;
    try {
        info = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    } catch (NameNotFoundException e) {
        Slog.d(TAG, "No such package '" + packageName + "' - not clearing backup data");
        return;
    }
    // If the caller does not hold the BACKUP permission, it can only request a
    // wipe of its own backed-up data.
    HashSet<String> apps;
    if ((mContext.checkPermission(android.Manifest.permission.BACKUP, Binder.getCallingPid(), Binder.getCallingUid())) == PackageManager.PERMISSION_DENIED) {
        apps = mBackupParticipants.get(Binder.getCallingUid());
    } else {
        // !!! TODO: allow data-clear of ANY app?
        if (MORE_DEBUG)
            Slog.v(TAG, "Privileged caller, allowing clear of other apps");
        apps = new HashSet<String>();
        int N = mBackupParticipants.size();
        for (int i = 0; i < N; i++) {
            HashSet<String> s = mBackupParticipants.valueAt(i);
            if (s != null) {
                apps.addAll(s);
            }
        }
    }
    // Is the given app an available participant?
    if (apps.contains(packageName)) {
        // found it; fire off the clear request
        if (MORE_DEBUG)
            Slog.v(TAG, "Found the app - running clear process");
        mBackupHandler.removeMessages(MSG_RETRY_CLEAR);
        synchronized (mQueueLock) {
            final IBackupTransport transport = getTransport(transportName);
            if (transport == null) {
                // transport is currently unavailable -- make sure to retry
                Message msg = mBackupHandler.obtainMessage(MSG_RETRY_CLEAR, new ClearRetryParams(transportName, packageName));
                mBackupHandler.sendMessageDelayed(msg, TRANSPORT_RETRY_INTERVAL);
                return;
            }
            long oldId = Binder.clearCallingIdentity();
            mWakelock.acquire();
            Message msg = mBackupHandler.obtainMessage(MSG_RUN_CLEAR, new ClearParams(transport, info));
            mBackupHandler.sendMessage(msg);
            Binder.restoreCallingIdentity(oldId);
        }
    }
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) Message(android.os.Message) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

Example 25 with IBackupTransport

use of com.android.internal.backup.IBackupTransport in project android_frameworks_base by ResurrectionRemix.

the class BackupManagerService method isAppEligibleForBackup.

public boolean isAppEligibleForBackup(String packageName) {
    mContext.enforceCallingOrSelfPermission(android.Manifest.permission.BACKUP, "isAppEligibleForBackup");
    try {
        PackageInfo packageInfo = mPackageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
        if (!appIsEligibleForBackup(packageInfo.applicationInfo) || appIsStopped(packageInfo.applicationInfo)) {
            return false;
        }
        IBackupTransport transport = getTransport(mCurrentTransport);
        if (transport != null) {
            try {
                return transport.isAppEligibleForBackup(packageInfo, appGetsFullBackup(packageInfo));
            } catch (Exception e) {
                Slog.e(TAG, "Unable to ask about eligibility: " + e.getMessage());
            }
        }
        // If transport is not present we couldn't tell that the package is not eligible.
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) RemoteException(android.os.RemoteException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) ActivityNotFoundException(android.content.ActivityNotFoundException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) BadPaddingException(javax.crypto.BadPaddingException)

Aggregations

IBackupTransport (com.android.internal.backup.IBackupTransport)26 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)25 RemoteException (android.os.RemoteException)22 IOException (java.io.IOException)22 ActivityNotFoundException (android.content.ActivityNotFoundException)21 EOFException (java.io.EOFException)21 FileNotFoundException (java.io.FileNotFoundException)21 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)21 InvalidKeyException (java.security.InvalidKeyException)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)21 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)21 BadPaddingException (javax.crypto.BadPaddingException)21 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)21 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)21 ErrnoException (android.system.ErrnoException)20 PackageInfo (android.content.pm.PackageInfo)12 Message (android.os.Message)12 File (java.io.File)10 RandomAccessFile (java.io.RandomAccessFile)10 AtomicFile (android.util.AtomicFile)8