use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.
the class BackupManagerService method initPackageTracking.
private void initPackageTracking() {
if (DEBUG)
Slog.v(TAG, "Initializing package tracking");
// Remember our ancestral dataset
mTokenFile = new File(mBaseStateDir, "ancestral");
try {
RandomAccessFile tf = new RandomAccessFile(mTokenFile, "r");
int version = tf.readInt();
if (version == CURRENT_ANCESTRAL_RECORD_VERSION) {
mAncestralToken = tf.readLong();
mCurrentToken = tf.readLong();
int numPackages = tf.readInt();
if (numPackages >= 0) {
mAncestralPackages = new HashSet<String>();
for (int i = 0; i < numPackages; i++) {
String pkgName = tf.readUTF();
mAncestralPackages.add(pkgName);
}
}
}
tf.close();
} catch (FileNotFoundException fnf) {
// Probably innocuous
Slog.v(TAG, "No ancestral data");
} catch (IOException e) {
Slog.w(TAG, "Unable to read token file", e);
}
// Keep a log of what apps we've ever backed up. Because we might have
// rebooted in the middle of an operation that was removing something from
// this log, we sanity-check its contents here and reconstruct it.
mEverStored = new File(mBaseStateDir, "processed");
File tempProcessedFile = new File(mBaseStateDir, "processed.new");
// Ignore it -- we'll validate "processed" against the current package set.
if (tempProcessedFile.exists()) {
tempProcessedFile.delete();
}
// file to continue the recordkeeping.
if (mEverStored.exists()) {
RandomAccessFile temp = null;
RandomAccessFile in = null;
try {
temp = new RandomAccessFile(tempProcessedFile, "rws");
in = new RandomAccessFile(mEverStored, "r");
while (true) {
PackageInfo info;
String pkg = in.readUTF();
try {
info = mPackageManager.getPackageInfo(pkg, 0);
mEverStoredApps.add(pkg);
temp.writeUTF(pkg);
if (MORE_DEBUG)
Slog.v(TAG, " + " + pkg);
} catch (NameNotFoundException e) {
// nope, this package was uninstalled; don't include it
if (MORE_DEBUG)
Slog.v(TAG, " - " + pkg);
}
}
} catch (EOFException e) {
// old one with the new one then reopen the file for continuing use.
if (!tempProcessedFile.renameTo(mEverStored)) {
Slog.e(TAG, "Error renaming " + tempProcessedFile + " to " + mEverStored);
}
} catch (IOException e) {
Slog.e(TAG, "Error in processed file", e);
} finally {
try {
if (temp != null)
temp.close();
} catch (IOException e) {
}
try {
if (in != null)
in.close();
} catch (IOException e) {
}
}
}
// Register for broadcasts about package install, etc., so we can
// update the provider list.
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_PACKAGE_ADDED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
mContext.registerReceiver(mBroadcastReceiver, filter);
// Register for events related to sdcard installation.
IntentFilter sdFilter = new IntentFilter();
sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE);
sdFilter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE);
mContext.registerReceiver(mBroadcastReceiver, sdFilter);
}
use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.
the class AssetRedirectionManagerService method generatePackageRedirectionMap.
private PackageRedirectionMap generatePackageRedirectionMap(RedirectionKey key) {
AssetManager assets = new AssetManager();
boolean frameworkAssets = key.targetPackageName.equals("android");
if (!frameworkAssets) {
PackageInfo pi = getPackageInfo(mContext, key.targetPackageName);
if (pi == null || pi.applicationInfo == null || assets.addAssetPath(pi.applicationInfo.publicSourceDir) == 0) {
Log.w(TAG, "Unable to attach target package assets for " + key.targetPackageName);
return null;
}
}
PackageInfo pi = getPackageInfo(mContext, key.themePackageName);
if (pi == null || pi.applicationInfo == null || pi.themeInfos == null || assets.addAssetPath(pi.applicationInfo.publicSourceDir) == 0) {
Log.w(TAG, "Unable to attach theme package assets from " + key.themePackageName);
return null;
}
PackageRedirectionMap resMap = new PackageRedirectionMap();
/*
* Apply a special redirection hack for the highest level <style>
* replacing @android:style/Theme.
*/
if (frameworkAssets) {
int themeResourceId = findThemeResourceId(pi.themeInfos, key.themeId);
assets.generateStyleRedirections(resMap.getNativePointer(), android.R.style.Theme, themeResourceId);
}
Resources res = new Resources(assets, null, null);
generateExplicitRedirections(resMap, res, key.themePackageName, key.targetPackageName);
return resMap;
}
use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.
the class LocationManagerService method ensureFallbackFusedProviderPresentLocked.
private void ensureFallbackFusedProviderPresentLocked(ArrayList<String> pkgs) {
PackageManager pm = mContext.getPackageManager();
String systemPackageName = mContext.getPackageName();
ArrayList<HashSet<Signature>> sigSets = ServiceWatcher.getSignatureSets(mContext, pkgs);
List<ResolveInfo> rInfos = pm.queryIntentServicesAsUser(new Intent(FUSED_LOCATION_SERVICE_ACTION), PackageManager.GET_META_DATA, mCurrentUserId);
for (ResolveInfo rInfo : rInfos) {
String packageName = rInfo.serviceInfo.packageName;
// this list the standard provider binding logic won't bind to it.
try {
PackageInfo pInfo;
pInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
if (!ServiceWatcher.isSignatureMatch(pInfo.signatures, sigSets)) {
Log.w(TAG, packageName + " resolves service " + FUSED_LOCATION_SERVICE_ACTION + ", but has wrong signature, ignoring");
continue;
}
} catch (NameNotFoundException e) {
Log.e(TAG, "missing package: " + packageName);
continue;
}
// Get the version info
if (rInfo.serviceInfo.metaData == null) {
Log.w(TAG, "Found fused provider without metadata: " + packageName);
continue;
}
int version = rInfo.serviceInfo.metaData.getInt(ServiceWatcher.EXTRA_SERVICE_VERSION, -1);
if (version == 0) {
// Make sure it's in the system partition.
if ((rInfo.serviceInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
if (D)
Log.d(TAG, "Fallback candidate not in /system: " + packageName);
continue;
}
// as a proxy for coreApp="true"
if (pm.checkSignatures(systemPackageName, packageName) != PackageManager.SIGNATURE_MATCH) {
if (D)
Log.d(TAG, "Fallback candidate not signed the same as system: " + packageName);
continue;
}
// Found a valid fallback.
if (D)
Log.d(TAG, "Found fallback provider: " + packageName);
return;
} else {
if (D)
Log.d(TAG, "Fallback candidate not version 0: " + packageName);
}
}
throw new IllegalStateException("Unable to find a fused location provider that is in the " + "system partition with version 0 and signed with the platform certificate. " + "Such a package is needed to provide a default fused location provider in the " + "event that no other fused location provider has been installed or is currently " + "available. For example, coreOnly boot mode when decrypting the data " + "partition. The fallback must also be marked coreApp=\"true\" in the manifest");
}
use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.
the class BackupManagerService method clearBackupData.
// Clear the given package's backup data from the current transport
public void clearBackupData(String packageName) {
if (DEBUG)
Slog.v(TAG, "clearBackupData() of " + packageName);
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 (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)) {
if (DEBUG)
Slog.v(TAG, "Found the app - running clear process");
// found it; fire off the clear request
synchronized (mQueueLock) {
long oldId = Binder.clearCallingIdentity();
mWakelock.acquire();
Message msg = mBackupHandler.obtainMessage(MSG_RUN_CLEAR, new ClearParams(getTransport(mCurrentTransport), info));
mBackupHandler.sendMessage(msg);
Binder.restoreCallingIdentity(oldId);
}
}
}
use of android.content.pm.PackageInfo in project android_frameworks_base by ParanoidAndroid.
the class NotificationManagerService method importOldBlockDb.
/**
* Read the old XML-based app block database and import those blockages into the AppOps system.
*/
private void importOldBlockDb() {
loadBlockDb();
PackageManager pm = mContext.getPackageManager();
for (String pkg : mBlockedPackages) {
PackageInfo info = null;
try {
info = pm.getPackageInfo(pkg, 0);
setNotificationsEnabledForPackage(pkg, info.applicationInfo.uid, false);
} catch (NameNotFoundException e) {
// forget you
}
}
mBlockedPackages.clear();
if (mPolicyFile != null) {
mPolicyFile.delete();
}
ThemeUtils.registerThemeChangeReceiver(mContext, mThemeChangeReceiver);
}
Aggregations