Search in sources :

Example 26 with PackageInfo

use of android.content.pm.PackageInfo 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 27 with PackageInfo

use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.

the class PackageManagerTests method testGetInstalledPackagesAll.

/**
     * Test that getInstalledPackages returns all the data specified in flags.
     */
public void testGetInstalledPackagesAll() throws Exception {
    int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_GIDS | PackageManager.GET_CONFIGURATIONS | PackageManager.GET_INSTRUMENTATION | PackageManager.GET_PERMISSIONS | PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS | PackageManager.GET_SERVICES | PackageManager.GET_SIGNATURES | PackageManager.GET_UNINSTALLED_PACKAGES;
    List<PackageInfo> packages = getPm().getInstalledPackages(flags);
    assertNotNull("installed packages cannot be null", packages);
    assertTrue("installed packages cannot be empty", packages.size() > 0);
    PackageInfo packageInfo = null;
    // to ensure no null values
    for (PackageInfo pi : packages) {
        if ("com.android.frameworks.coretests.install_complete_package_info".equals(pi.packageName)) {
            packageInfo = pi;
            break;
        }
    }
    assertNotNull("activities should not be null", packageInfo.activities);
    assertNotNull("configPreferences should not be null", packageInfo.configPreferences);
    assertNotNull("instrumentation should not be null", packageInfo.instrumentation);
    assertNotNull("permissions should not be null", packageInfo.permissions);
    assertNotNull("providers should not be null", packageInfo.providers);
    assertNotNull("receivers should not be null", packageInfo.receivers);
    assertNotNull("services should not be null", packageInfo.services);
    assertNotNull("signatures should not be null", packageInfo.signatures);
}
Also used : PackageInfo(android.content.pm.PackageInfo)

Example 28 with PackageInfo

use of android.content.pm.PackageInfo in project k-9 by k9mail.

the class Accounts method getVersionNumber.

/**
     * Get current version number.
     *
     * @return String version
     */
private String getVersionNumber() {
    String version = "?";
    try {
        PackageInfo pi = getPackageManager().getPackageInfo(getPackageName(), 0);
        version = pi.versionName;
    } catch (PackageManager.NameNotFoundException e) {
    //Log.e(TAG, "Package name not found", e);
    }
    return version;
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 29 with PackageInfo

use of android.content.pm.PackageInfo in project UltimateAndroid by cymcsg.

the class BasicUtils method getVersionName.

/**
     * get the version name which defines in AndroidManifest.xml
     *
     * @param context
     * @return
     */
public static String getVersionName(Context context) {
    String version = "";
    try {
        // get packagemanager
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()--your current package name,0 means get package info
        PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        version = packInfo.versionName;
    } catch (Exception e) {
        e.printStackTrace();
        Logs.e(e.getMessage());
    } finally {
        return version;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Example 30 with PackageInfo

use of android.content.pm.PackageInfo in project UltimateAndroid by cymcsg.

the class BasicUtils method getVersionCode.

/**
     * get the version code which defines in AndroidManifest.xml
     *
     * @param context
     * @return
     */
public static int getVersionCode(Context context) {
    int version = 0;
    try {
        // get packagemanager
        PackageManager packageManager = context.getPackageManager();
        // getPackageName()--your current package name,0 means get package info
        PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
        version = packInfo.versionCode;
    } catch (Exception e) {
        e.printStackTrace();
        Logs.e(e.getMessage());
    } finally {
        return version;
    }
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo)

Aggregations

PackageInfo (android.content.pm.PackageInfo)1566 PackageManager (android.content.pm.PackageManager)702 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)327 ApplicationInfo (android.content.pm.ApplicationInfo)217 Test (org.junit.Test)193 RemoteException (android.os.RemoteException)179 ArrayList (java.util.ArrayList)166 Intent (android.content.Intent)126 IOException (java.io.IOException)121 Context (android.content.Context)81 IPackageManager (android.content.pm.IPackageManager)65 ResolveInfo (android.content.pm.ResolveInfo)65 File (java.io.File)62 SuppressLint (android.annotation.SuppressLint)58 ComponentName (android.content.ComponentName)57 ActivityInfo (android.content.pm.ActivityInfo)57 View (android.view.View)57 TextView (android.widget.TextView)54 Signature (android.content.pm.Signature)51 OverlayInfo (android.content.om.OverlayInfo)42