Search in sources :

Example 1 with BackupAgent

use of android.app.backup.BackupAgent in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method handleCreateBackupAgent.

// Instantiate a BackupAgent and tell it that it's alive
private void handleCreateBackupAgent(CreateBackupAgentData data) {
    if (DEBUG_BACKUP)
        Slog.v(TAG, "handleCreateBackupAgent: " + data);
    // Sanity check the requested target package's uid against ours
    try {
        PackageInfo requestedPackage = getPackageManager().getPackageInfo(data.appInfo.packageName, 0, UserHandle.myUserId());
        if (requestedPackage.applicationInfo.uid != Process.myUid()) {
            Slog.w(TAG, "Asked to instantiate non-matching package " + data.appInfo.packageName);
            return;
        }
    } catch (RemoteException e) {
        Slog.e(TAG, "Can't reach package manager", e);
        return;
    }
    // no longer idle; we have backup work to do
    unscheduleGcIdler();
    // instantiate the BackupAgent class named in the manifest
    LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
    String packageName = packageInfo.mPackageName;
    if (packageName == null) {
        Slog.d(TAG, "Asked to create backup agent for nonexistent package");
        return;
    }
    if (mBackupAgents.get(packageName) != null) {
        Slog.d(TAG, "BackupAgent " + "  for " + packageName + " already exists");
        return;
    }
    BackupAgent agent = null;
    String classname = data.appInfo.backupAgentName;
    // full backup operation but no app-supplied agent?  use the default implementation
    if (classname == null && (data.backupMode == IApplicationThread.BACKUP_MODE_FULL || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL)) {
        classname = "android.app.backup.FullBackupAgent";
    }
    try {
        IBinder binder = null;
        try {
            if (DEBUG_BACKUP)
                Slog.v(TAG, "Initializing agent class " + classname);
            java.lang.ClassLoader cl = packageInfo.getClassLoader();
            agent = (BackupAgent) cl.loadClass(classname).newInstance();
            // set up the agent's context
            ContextImpl context = new ContextImpl();
            context.init(packageInfo, null, this);
            context.setOuterContext(agent);
            agent.attach(context);
            agent.onCreate();
            binder = agent.onBind();
            mBackupAgents.put(packageName, agent);
        } catch (Exception e) {
            // If this is during restore, fail silently; otherwise go
            // ahead and let the user see the crash.
            Slog.e(TAG, "Agent threw during creation: " + e);
            if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) {
                throw e;
            }
        // falling through with 'binder' still null
        }
        // tell the OS that we're live now
        try {
            ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder);
        } catch (RemoteException e) {
        // nothing to do.
        }
    } catch (Exception e) {
        throw new RuntimeException("Unable to create BackupAgent " + classname + ": " + e.toString(), e);
    }
}
Also used : IBinder(android.os.IBinder) AndroidRuntimeException(android.util.AndroidRuntimeException) PackageInfo(android.content.pm.PackageInfo) BackupAgent(android.app.backup.BackupAgent) RemoteException(android.os.RemoteException) java.lang(java.lang) InflateException(android.view.InflateException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 2 with BackupAgent

use of android.app.backup.BackupAgent in project android_frameworks_base by ParanoidAndroid.

the class ActivityThread method handleDestroyBackupAgent.

// Tear down a BackupAgent
private void handleDestroyBackupAgent(CreateBackupAgentData data) {
    if (DEBUG_BACKUP)
        Slog.v(TAG, "handleDestroyBackupAgent: " + data);
    LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
    String packageName = packageInfo.mPackageName;
    BackupAgent agent = mBackupAgents.get(packageName);
    if (agent != null) {
        try {
            agent.onDestroy();
        } catch (Exception e) {
            Slog.w(TAG, "Exception thrown in onDestroy by backup agent of " + data.appInfo);
            e.printStackTrace();
        }
        mBackupAgents.remove(packageName);
    } else {
        Slog.w(TAG, "Attempt to destroy unknown backup agent " + data);
    }
}
Also used : BackupAgent(android.app.backup.BackupAgent) InflateException(android.view.InflateException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException)

Example 3 with BackupAgent

use of android.app.backup.BackupAgent in project android_frameworks_base by ResurrectionRemix.

the class ActivityThread method handleCreateBackupAgent.

// Instantiate a BackupAgent and tell it that it's alive
private void handleCreateBackupAgent(CreateBackupAgentData data) {
    if (DEBUG_BACKUP)
        Slog.v(TAG, "handleCreateBackupAgent: " + data);
    // Sanity check the requested target package's uid against ours
    try {
        PackageInfo requestedPackage = getPackageManager().getPackageInfo(data.appInfo.packageName, 0, UserHandle.myUserId());
        if (requestedPackage.applicationInfo.uid != Process.myUid()) {
            Slog.w(TAG, "Asked to instantiate non-matching package " + data.appInfo.packageName);
            return;
        }
    } catch (RemoteException e) {
        throw e.rethrowFromSystemServer();
    }
    // no longer idle; we have backup work to do
    unscheduleGcIdler();
    // instantiate the BackupAgent class named in the manifest
    LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
    String packageName = packageInfo.mPackageName;
    if (packageName == null) {
        Slog.d(TAG, "Asked to create backup agent for nonexistent package");
        return;
    }
    String classname = data.appInfo.backupAgentName;
    // full backup operation but no app-supplied agent?  use the default implementation
    if (classname == null && (data.backupMode == IApplicationThread.BACKUP_MODE_FULL || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL)) {
        classname = "android.app.backup.FullBackupAgent";
    }
    try {
        IBinder binder = null;
        BackupAgent agent = mBackupAgents.get(packageName);
        if (agent != null) {
            // reusing the existing instance
            if (DEBUG_BACKUP) {
                Slog.v(TAG, "Reusing existing agent instance");
            }
            binder = agent.onBind();
        } else {
            try {
                if (DEBUG_BACKUP)
                    Slog.v(TAG, "Initializing agent class " + classname);
                java.lang.ClassLoader cl = packageInfo.getClassLoader();
                agent = (BackupAgent) cl.loadClass(classname).newInstance();
                // set up the agent's context
                ContextImpl context = ContextImpl.createAppContext(this, packageInfo);
                context.setOuterContext(agent);
                agent.attach(context);
                agent.onCreate();
                binder = agent.onBind();
                mBackupAgents.put(packageName, agent);
            } catch (Exception e) {
                // If this is during restore, fail silently; otherwise go
                // ahead and let the user see the crash.
                Slog.e(TAG, "Agent threw during creation: " + e);
                if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) {
                    throw e;
                }
            // falling through with 'binder' still null
            }
        }
        // tell the OS that we're live now
        try {
            ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    } catch (Exception e) {
        throw new RuntimeException("Unable to create BackupAgent " + classname + ": " + e.toString(), e);
    }
}
Also used : IBinder(android.os.IBinder) AndroidRuntimeException(android.util.AndroidRuntimeException) PackageInfo(android.content.pm.PackageInfo) BackupAgent(android.app.backup.BackupAgent) RemoteException(android.os.RemoteException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) ErrnoException(android.system.ErrnoException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) SuperNotCalledException(android.util.SuperNotCalledException) TransactionTooLargeException(android.os.TransactionTooLargeException)

Example 4 with BackupAgent

use of android.app.backup.BackupAgent in project XobotOS by xamarin.

the class ActivityThread method handleDestroyBackupAgent.

// Tear down a BackupAgent
private void handleDestroyBackupAgent(CreateBackupAgentData data) {
    if (DEBUG_BACKUP)
        Slog.v(TAG, "handleDestroyBackupAgent: " + data);
    LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
    String packageName = packageInfo.mPackageName;
    BackupAgent agent = mBackupAgents.get(packageName);
    if (agent != null) {
        try {
            agent.onDestroy();
        } catch (Exception e) {
            Slog.w(TAG, "Exception thrown in onDestroy by backup agent of " + data.appInfo);
            e.printStackTrace();
        }
        mBackupAgents.remove(packageName);
    } else {
        Slog.w(TAG, "Attempt to destroy unknown backup agent " + data);
    }
}
Also used : BackupAgent(android.app.backup.BackupAgent) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Example 5 with BackupAgent

use of android.app.backup.BackupAgent in project XobotOS by xamarin.

the class ActivityThread method handleCreateBackupAgent.

// Instantiate a BackupAgent and tell it that it's alive
private void handleCreateBackupAgent(CreateBackupAgentData data) {
    if (DEBUG_BACKUP)
        Slog.v(TAG, "handleCreateBackupAgent: " + data);
    // no longer idle; we have backup work to do
    unscheduleGcIdler();
    // instantiate the BackupAgent class named in the manifest
    LoadedApk packageInfo = getPackageInfoNoCheck(data.appInfo, data.compatInfo);
    String packageName = packageInfo.mPackageName;
    if (mBackupAgents.get(packageName) != null) {
        Slog.d(TAG, "BackupAgent " + "  for " + packageName + " already exists");
        return;
    }
    BackupAgent agent = null;
    String classname = data.appInfo.backupAgentName;
    // full backup operation but no app-supplied agent?  use the default implementation
    if (classname == null && (data.backupMode == IApplicationThread.BACKUP_MODE_FULL || data.backupMode == IApplicationThread.BACKUP_MODE_RESTORE_FULL)) {
        classname = "android.app.backup.FullBackupAgent";
    }
    try {
        IBinder binder = null;
        try {
            if (DEBUG_BACKUP)
                Slog.v(TAG, "Initializing agent class " + classname);
            java.lang.ClassLoader cl = packageInfo.getClassLoader();
            agent = (BackupAgent) cl.loadClass(classname).newInstance();
            // set up the agent's context
            ContextImpl context = new ContextImpl();
            context.init(packageInfo, null, this);
            context.setOuterContext(agent);
            agent.attach(context);
            agent.onCreate();
            binder = agent.onBind();
            mBackupAgents.put(packageName, agent);
        } catch (Exception e) {
            // If this is during restore, fail silently; otherwise go
            // ahead and let the user see the crash.
            Slog.e(TAG, "Agent threw during creation: " + e);
            if (data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE && data.backupMode != IApplicationThread.BACKUP_MODE_RESTORE_FULL) {
                throw e;
            }
        // falling through with 'binder' still null
        }
        // tell the OS that we're live now
        try {
            ActivityManagerNative.getDefault().backupAgentCreated(packageName, binder);
        } catch (RemoteException e) {
        // nothing to do.
        }
    } catch (Exception e) {
        throw new RuntimeException("Unable to create BackupAgent " + classname + ": " + e.toString(), e);
    }
}
Also used : IBinder(android.os.IBinder) AndroidRuntimeException(android.util.AndroidRuntimeException) BackupAgent(android.app.backup.BackupAgent) RemoteException(android.os.RemoteException) AndroidRuntimeException(android.util.AndroidRuntimeException) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) RemoteException(android.os.RemoteException) IOException(java.io.IOException)

Aggregations

BackupAgent (android.app.backup.BackupAgent)14 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)14 RemoteException (android.os.RemoteException)14 AndroidRuntimeException (android.util.AndroidRuntimeException)14 IOException (java.io.IOException)14 TransactionTooLargeException (android.os.TransactionTooLargeException)10 ErrnoException (android.system.ErrnoException)10 SuperNotCalledException (android.util.SuperNotCalledException)10 IBinder (android.os.IBinder)7 PackageInfo (android.content.pm.PackageInfo)6 InflateException (android.view.InflateException)2 java.lang (java.lang)1