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);
}
}
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);
}
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;
}
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;
}
}
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;
}
}
Aggregations