Search in sources :

Example 6 with IBackupTransport

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

the class BackupManagerService method restoreAtInstall.

// An application being installed will need a restore pass, then the Package Manager
// will need to be told when the restore is finished.
public void restoreAtInstall(String packageName, int token) {
    if (Binder.getCallingUid() != Process.SYSTEM_UID) {
        Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid() + " attemping install-time restore");
        return;
    }
    boolean skip = false;
    long restoreSet = getAvailableRestoreToken(packageName);
    if (DEBUG)
        Slog.v(TAG, "restoreAtInstall pkg=" + packageName + " token=" + Integer.toHexString(token) + " restoreSet=" + Long.toHexString(restoreSet));
    if (restoreSet == 0) {
        if (MORE_DEBUG)
            Slog.i(TAG, "No restore set");
        skip = true;
    }
    // Do we have a transport to fetch data for us?
    IBackupTransport transport = getTransport(mCurrentTransport);
    if (transport == null) {
        if (DEBUG)
            Slog.w(TAG, "No transport");
        skip = true;
    }
    if (!mAutoRestore) {
        if (DEBUG) {
            Slog.w(TAG, "Non-restorable state: auto=" + mAutoRestore);
        }
        skip = true;
    }
    if (!skip) {
        try {
            // okay, we're going to attempt a restore of this package from this restore set.
            // The eventual message back into the Package Manager to run the post-install
            // steps for 'token' will be issued from the restore handling code.
            // This can throw and so *must* happen before the wakelock is acquired
            String dirName = transport.transportDirName();
            mWakelock.acquire();
            if (MORE_DEBUG) {
                Slog.d(TAG, "Restore at install of " + packageName);
            }
            Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
            msg.obj = new RestoreParams(transport, dirName, null, restoreSet, packageName, token);
            mBackupHandler.sendMessage(msg);
        } catch (Exception e) {
            // Calling into the transport broke; back off and proceed with the installation.
            Slog.e(TAG, "Unable to contact transport: " + e.getMessage());
            skip = true;
        }
    }
    if (skip) {
        // Manager to proceed with the post-install handling for this package.
        if (DEBUG)
            Slog.v(TAG, "Finishing install immediately");
        try {
            mPackageManagerBinder.finishPackageInstall(token, false);
        } catch (RemoteException e) {
        /* can't happen */
        }
    }
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) Message(android.os.Message) RemoteException(android.os.RemoteException) 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 7 with IBackupTransport

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

the class BackupManagerService method dumpInternal.

private void dumpInternal(PrintWriter pw) {
    synchronized (mQueueLock) {
        pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled") + " / " + (!mProvisioned ? "not " : "") + "provisioned / " + (this.mPendingInits.size() == 0 ? "not " : "") + "pending init");
        pw.println("Auto-restore is " + (mAutoRestore ? "enabled" : "disabled"));
        if (mBackupRunning)
            pw.println("Backup currently running");
        pw.println("Last backup pass started: " + mLastBackupPass + " (now = " + System.currentTimeMillis() + ')');
        pw.println("  next scheduled: " + KeyValueBackupJob.nextScheduled());
        pw.println("Transport whitelist:");
        for (ComponentName transport : mTransportWhitelist) {
            pw.print("    ");
            pw.println(transport.flattenToShortString());
        }
        pw.println("Available transports:");
        final String[] transports = listAllTransports();
        if (transports != null) {
            for (String t : listAllTransports()) {
                pw.println((t.equals(mCurrentTransport) ? "  * " : "    ") + t);
                try {
                    IBackupTransport transport = getTransport(t);
                    File dir = new File(mBaseStateDir, transport.transportDirName());
                    pw.println("       destination: " + transport.currentDestinationString());
                    pw.println("       intent: " + transport.configurationIntent());
                    for (File f : dir.listFiles()) {
                        pw.println("       " + f.getName() + " - " + f.length() + " state bytes");
                    }
                } catch (Exception e) {
                    Slog.e(TAG, "Error in transport", e);
                    pw.println("        Error: " + e);
                }
            }
        }
        pw.println("Pending init: " + mPendingInits.size());
        for (String s : mPendingInits) {
            pw.println("    " + s);
        }
        if (DEBUG_BACKUP_TRACE) {
            synchronized (mBackupTrace) {
                if (!mBackupTrace.isEmpty()) {
                    pw.println("Most recent backup trace:");
                    for (String s : mBackupTrace) {
                        pw.println("   " + s);
                    }
                }
            }
        }
        pw.print("Ancestral: ");
        pw.println(Long.toHexString(mAncestralToken));
        pw.print("Current:   ");
        pw.println(Long.toHexString(mCurrentToken));
        int N = mBackupParticipants.size();
        pw.println("Participants:");
        for (int i = 0; i < N; i++) {
            int uid = mBackupParticipants.keyAt(i);
            pw.print("  uid: ");
            pw.println(uid);
            HashSet<String> participants = mBackupParticipants.valueAt(i);
            for (String app : participants) {
                pw.println("    " + app);
            }
        }
        pw.println("Ancestral packages: " + (mAncestralPackages == null ? "none" : mAncestralPackages.size()));
        if (mAncestralPackages != null) {
            for (String pkg : mAncestralPackages) {
                pw.println("    " + pkg);
            }
        }
        pw.println("Ever backed up: " + mEverStoredApps.size());
        for (String pkg : mEverStoredApps) {
            pw.println("    " + pkg);
        }
        pw.println("Pending key/value backup: " + mPendingBackups.size());
        for (BackupRequest req : mPendingBackups.values()) {
            pw.println("    " + req);
        }
        pw.println("Full backup queue:" + mFullBackupQueue.size());
        for (FullBackupEntry entry : mFullBackupQueue) {
            pw.print("    ");
            pw.print(entry.lastBackup);
            pw.print(" : ");
            pw.println(entry.packageName);
        }
    }
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) ComponentName(android.content.ComponentName) 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 8 with IBackupTransport

use of com.android.internal.backup.IBackupTransport in project platform_frameworks_base by android.

the class BackupManagerService method dumpInternal.

private void dumpInternal(PrintWriter pw) {
    synchronized (mQueueLock) {
        pw.println("Backup Manager is " + (mEnabled ? "enabled" : "disabled") + " / " + (!mProvisioned ? "not " : "") + "provisioned / " + (this.mPendingInits.size() == 0 ? "not " : "") + "pending init");
        pw.println("Auto-restore is " + (mAutoRestore ? "enabled" : "disabled"));
        if (mBackupRunning)
            pw.println("Backup currently running");
        pw.println("Last backup pass started: " + mLastBackupPass + " (now = " + System.currentTimeMillis() + ')');
        pw.println("  next scheduled: " + KeyValueBackupJob.nextScheduled());
        pw.println("Transport whitelist:");
        for (ComponentName transport : mTransportWhitelist) {
            pw.print("    ");
            pw.println(transport.flattenToShortString());
        }
        pw.println("Available transports:");
        final String[] transports = listAllTransports();
        if (transports != null) {
            for (String t : listAllTransports()) {
                pw.println((t.equals(mCurrentTransport) ? "  * " : "    ") + t);
                try {
                    IBackupTransport transport = getTransport(t);
                    File dir = new File(mBaseStateDir, transport.transportDirName());
                    pw.println("       destination: " + transport.currentDestinationString());
                    pw.println("       intent: " + transport.configurationIntent());
                    for (File f : dir.listFiles()) {
                        pw.println("       " + f.getName() + " - " + f.length() + " state bytes");
                    }
                } catch (Exception e) {
                    Slog.e(TAG, "Error in transport", e);
                    pw.println("        Error: " + e);
                }
            }
        }
        pw.println("Pending init: " + mPendingInits.size());
        for (String s : mPendingInits) {
            pw.println("    " + s);
        }
        if (DEBUG_BACKUP_TRACE) {
            synchronized (mBackupTrace) {
                if (!mBackupTrace.isEmpty()) {
                    pw.println("Most recent backup trace:");
                    for (String s : mBackupTrace) {
                        pw.println("   " + s);
                    }
                }
            }
        }
        pw.print("Ancestral: ");
        pw.println(Long.toHexString(mAncestralToken));
        pw.print("Current:   ");
        pw.println(Long.toHexString(mCurrentToken));
        int N = mBackupParticipants.size();
        pw.println("Participants:");
        for (int i = 0; i < N; i++) {
            int uid = mBackupParticipants.keyAt(i);
            pw.print("  uid: ");
            pw.println(uid);
            HashSet<String> participants = mBackupParticipants.valueAt(i);
            for (String app : participants) {
                pw.println("    " + app);
            }
        }
        pw.println("Ancestral packages: " + (mAncestralPackages == null ? "none" : mAncestralPackages.size()));
        if (mAncestralPackages != null) {
            for (String pkg : mAncestralPackages) {
                pw.println("    " + pkg);
            }
        }
        pw.println("Ever backed up: " + mEverStoredApps.size());
        for (String pkg : mEverStoredApps) {
            pw.println("    " + pkg);
        }
        pw.println("Pending key/value backup: " + mPendingBackups.size());
        for (BackupRequest req : mPendingBackups.values()) {
            pw.println("    " + req);
        }
        pw.println("Full backup queue:" + mFullBackupQueue.size());
        for (FullBackupEntry entry : mFullBackupQueue) {
            pw.print("    ");
            pw.print(entry.lastBackup);
            pw.print(" : ");
            pw.println(entry.packageName);
        }
    }
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) ComponentName(android.content.ComponentName) 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 9 with IBackupTransport

use of com.android.internal.backup.IBackupTransport in project platform_frameworks_base by android.

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 10 with IBackupTransport

use of com.android.internal.backup.IBackupTransport in project platform_frameworks_base by android.

the class BackupManagerService method restoreAtInstall.

// An application being installed will need a restore pass, then the Package Manager
// will need to be told when the restore is finished.
public void restoreAtInstall(String packageName, int token) {
    if (Binder.getCallingUid() != Process.SYSTEM_UID) {
        Slog.w(TAG, "Non-system process uid=" + Binder.getCallingUid() + " attemping install-time restore");
        return;
    }
    boolean skip = false;
    long restoreSet = getAvailableRestoreToken(packageName);
    if (DEBUG)
        Slog.v(TAG, "restoreAtInstall pkg=" + packageName + " token=" + Integer.toHexString(token) + " restoreSet=" + Long.toHexString(restoreSet));
    if (restoreSet == 0) {
        if (MORE_DEBUG)
            Slog.i(TAG, "No restore set");
        skip = true;
    }
    // Do we have a transport to fetch data for us?
    IBackupTransport transport = getTransport(mCurrentTransport);
    if (transport == null) {
        if (DEBUG)
            Slog.w(TAG, "No transport");
        skip = true;
    }
    if (!mAutoRestore) {
        if (DEBUG) {
            Slog.w(TAG, "Non-restorable state: auto=" + mAutoRestore);
        }
        skip = true;
    }
    if (!skip) {
        try {
            // okay, we're going to attempt a restore of this package from this restore set.
            // The eventual message back into the Package Manager to run the post-install
            // steps for 'token' will be issued from the restore handling code.
            // This can throw and so *must* happen before the wakelock is acquired
            String dirName = transport.transportDirName();
            mWakelock.acquire();
            if (MORE_DEBUG) {
                Slog.d(TAG, "Restore at install of " + packageName);
            }
            Message msg = mBackupHandler.obtainMessage(MSG_RUN_RESTORE);
            msg.obj = new RestoreParams(transport, dirName, null, restoreSet, packageName, token);
            mBackupHandler.sendMessage(msg);
        } catch (Exception e) {
            // Calling into the transport broke; back off and proceed with the installation.
            Slog.e(TAG, "Unable to contact transport: " + e.getMessage());
            skip = true;
        }
    }
    if (skip) {
        // Manager to proceed with the post-install handling for this package.
        if (DEBUG)
            Slog.v(TAG, "Finishing install immediately");
        try {
            mPackageManagerBinder.finishPackageInstall(token, false);
        } catch (RemoteException e) {
        /* can't happen */
        }
    }
}
Also used : IBackupTransport(com.android.internal.backup.IBackupTransport) Message(android.os.Message) RemoteException(android.os.RemoteException) 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