use of android.content.pm.PackageInfo in project android_frameworks_base by ResurrectionRemix.
the class OverlayManagerServiceImpl method onOverlayPackageAdded.
void onOverlayPackageAdded(@NonNull final String packageName, final int userId) {
if (DEBUG) {
Slog.d(TAG, "onOverlayPackageAdded packageName=" + packageName + " userId=" + userId);
}
final PackageInfo overlayPackage = mPackageManager.getPackageInfo(packageName, userId);
if (overlayPackage == null) {
Slog.w(TAG, "overlay package " + packageName + " was added, but couldn't be found");
onOverlayPackageRemoved(packageName, userId);
return;
}
final PackageInfo targetPackage = mPackageManager.getPackageInfo(overlayPackage.overlayTarget, userId);
mSettings.init(packageName, userId, overlayPackage.overlayTarget, overlayPackage.applicationInfo.getBaseCodePath());
try {
updateState(targetPackage, overlayPackage, userId);
} catch (OverlayManagerSettings.BadKeyException e) {
Slog.e(TAG, "failed to update settings", e);
mSettings.remove(packageName, userId);
}
}
use of android.content.pm.PackageInfo in project android_frameworks_base by ResurrectionRemix.
the class OverlayManagerServiceImpl method onSetEnabled.
boolean onSetEnabled(@NonNull final String packageName, final boolean enable, final int userId, final boolean shouldWait) {
if (DEBUG) {
Slog.d(TAG, String.format("onSetEnabled packageName=%s enable=%s userId=%d", packageName, enable, userId));
}
final PackageInfo overlayPackage = mPackageManager.getPackageInfo(packageName, userId);
if (overlayPackage == null) {
return false;
}
try {
final OverlayInfo oi = mSettings.getOverlayInfo(packageName, userId);
final PackageInfo targetPackage = mPackageManager.getPackageInfo(oi.targetPackageName, userId);
mSettings.setEnabled(packageName, userId, enable);
updateState(targetPackage, overlayPackage, userId, shouldWait);
return true;
} catch (OverlayManagerSettings.BadKeyException e) {
return false;
}
}
use of android.content.pm.PackageInfo in project android_frameworks_base by ResurrectionRemix.
the class PackageManagerShellCommand method runListPackages.
private int runListPackages(boolean showSourceDir) throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
int getFlags = 0;
boolean listDisabled = false, listEnabled = false;
boolean listSystem = false, listThirdParty = false;
boolean listInstaller = false;
int userId = UserHandle.USER_SYSTEM;
try {
String opt;
while ((opt = getNextOption()) != null) {
switch(opt) {
case "-d":
listDisabled = true;
break;
case "-e":
listEnabled = true;
break;
case "-f":
showSourceDir = true;
break;
case "-i":
listInstaller = true;
break;
case "-l":
// old compat
break;
case "-lf":
showSourceDir = true;
break;
case "-s":
listSystem = true;
break;
case "-u":
getFlags |= PackageManager.GET_UNINSTALLED_PACKAGES;
break;
case "-3":
listThirdParty = true;
break;
case "--user":
userId = UserHandle.parseUserArg(getNextArgRequired());
break;
default:
pw.println("Error: Unknown option: " + opt);
return -1;
}
}
} catch (RuntimeException ex) {
pw.println("Error: " + ex.toString());
return -1;
}
final String filter = getNextArg();
@SuppressWarnings("unchecked") final ParceledListSlice<PackageInfo> slice = mInterface.getInstalledPackages(getFlags, userId);
final List<PackageInfo> packages = slice.getList();
final int count = packages.size();
for (int p = 0; p < count; p++) {
final PackageInfo info = packages.get(p);
if (filter != null && !info.packageName.contains(filter)) {
continue;
}
final boolean isSystem = (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
if ((!listDisabled || !info.applicationInfo.enabled) && (!listEnabled || info.applicationInfo.enabled) && (!listSystem || isSystem) && (!listThirdParty || !isSystem)) {
pw.print("package:");
if (showSourceDir) {
pw.print(info.applicationInfo.sourceDir);
pw.print("=");
}
pw.print(info.packageName);
if (listInstaller) {
pw.print(" installer=");
pw.print(mInterface.getInstallerPackageName(info.packageName));
}
pw.println();
}
}
return 0;
}
use of android.content.pm.PackageInfo in project android_frameworks_base by ResurrectionRemix.
the class PackageManagerShellCommand method runUninstall.
private int runUninstall() throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
int flags = 0;
int userId = UserHandle.USER_ALL;
String opt;
while ((opt = getNextOption()) != null) {
switch(opt) {
case "-k":
flags |= PackageManager.DELETE_KEEP_DATA;
break;
case "--user":
userId = UserHandle.parseUserArg(getNextArgRequired());
break;
default:
pw.println("Error: Unknown option: " + opt);
return 1;
}
}
final String packageName = getNextArg();
if (packageName == null) {
pw.println("Error: package name not specified");
return 1;
}
// if a split is specified, just remove it and not the whole package
final String splitName = getNextArg();
if (splitName != null) {
return runRemoveSplit(packageName, splitName);
}
userId = translateUserId(userId, "runUninstall");
if (userId == UserHandle.USER_ALL) {
userId = UserHandle.USER_SYSTEM;
flags |= PackageManager.DELETE_ALL_USERS;
} else {
final PackageInfo info = mInterface.getPackageInfo(packageName, 0, userId);
if (info == null) {
pw.println("Failure [not installed for " + userId + "]");
return 1;
}
final boolean isSystem = (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
// version of the app.
if (isSystem) {
flags |= PackageManager.DELETE_SYSTEM_APP;
}
}
final LocalIntentReceiver receiver = new LocalIntentReceiver();
mInterface.getPackageInstaller().uninstall(packageName, null, /*callerPackageName*/
flags, receiver.getIntentSender(), userId);
final Intent result = receiver.getResult();
final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE);
if (status == PackageInstaller.STATUS_SUCCESS) {
pw.println("Success");
return 0;
} else {
pw.println("Failure [" + result.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE) + "]");
return 1;
}
}
use of android.content.pm.PackageInfo in project android_frameworks_base by ResurrectionRemix.
the class ShortcutPackage method rescanPackageIfNeeded.
/**
* Called when the package may be added or updated, or its activities may be disabled, and
* if so, rescan the package and do the necessary stuff.
*
* Add case:
* - Publish manifest shortcuts.
*
* Update case:
* - Re-publish manifest shortcuts.
* - If there are shortcuts with resources (icons or strings), update their timestamps.
* - Disable shortcuts whose target activities are disabled.
*
* @return TRUE if any shortcuts have been changed.
*/
public boolean rescanPackageIfNeeded(boolean isNewApp, boolean forceRescan) {
final ShortcutService s = mShortcutUser.mService;
final long start = s.injectElapsedRealtime();
final PackageInfo pi;
try {
pi = mShortcutUser.mService.getPackageInfo(getPackageName(), getPackageUserId());
if (pi == null) {
// Shouldn't happen.
return false;
}
// Always scan the settings app, since its version code is the same for DR and MR1.
// TODO Fix it properly: b/32554059
final boolean isSettings = "com.android.settings".equals(getPackageName());
if (!isNewApp && !forceRescan && !isSettings) {
// really change on OTAs.
if ((getPackageInfo().getVersionCode() == pi.versionCode) && (getPackageInfo().getLastUpdateTime() == pi.lastUpdateTime) && areAllActivitiesStillEnabled()) {
return false;
}
}
if (isSettings) {
if (ShortcutService.DEBUG) {
Slog.d(TAG, "Always scan settings.");
}
}
} finally {
s.logDurationStat(Stats.PACKAGE_UPDATE_CHECK, start);
}
// Now prepare to publish manifest shortcuts.
List<ShortcutInfo> newManifestShortcutList = null;
try {
newManifestShortcutList = ShortcutParser.parseShortcuts(mShortcutUser.mService, getPackageName(), getPackageUserId());
} catch (IOException | XmlPullParserException e) {
Slog.e(TAG, "Failed to load shortcuts from AndroidManifest.xml.", e);
}
final int manifestShortcutSize = newManifestShortcutList == null ? 0 : newManifestShortcutList.size();
if (ShortcutService.DEBUG) {
Slog.d(TAG, String.format("Package %s has %d manifest shortcut(s)", getPackageName(), manifestShortcutSize));
}
if (isNewApp && (manifestShortcutSize == 0)) {
// disabled.
return false;
}
if (ShortcutService.DEBUG) {
Slog.d(TAG, String.format("Package %s %s, version %d -> %d", getPackageName(), (isNewApp ? "added" : "updated"), getPackageInfo().getVersionCode(), pi.versionCode));
}
getPackageInfo().updateVersionInfo(pi);
boolean changed = false;
// Also check if shortcuts' activities are still main activities. Otherwise, disable them.
if (!isNewApp) {
Resources publisherRes = null;
for (int i = mShortcuts.size() - 1; i >= 0; i--) {
final ShortcutInfo si = mShortcuts.valueAt(i);
if (si.isDynamic()) {
if (!s.injectIsMainActivity(si.getActivity(), getPackageUserId())) {
Slog.w(TAG, String.format("%s is no longer main activity. Disabling shorcut %s.", getPackageName(), si.getId()));
if (disableDynamicWithId(si.getId())) {
// Actually removed.
continue;
}
// Still pinned, so fall-through and possibly update the resources.
}
changed = true;
}
if (si.hasAnyResources()) {
if (!si.isOriginallyFromManifest()) {
if (publisherRes == null) {
publisherRes = getPackageResources();
if (publisherRes == null) {
// Resources couldn't be loaded.
break;
}
}
// If this shortcut is not from a manifest, then update all resource IDs
// from resource names. (We don't allow resource strings for
// non-manifest at the moment, but icons can still be resources.)
si.lookupAndFillInResourceIds(publisherRes);
}
changed = true;
si.setTimestamp(s.injectCurrentTimeMillis());
}
}
}
// (Re-)publish manifest shortcut.
changed |= publishManifestShortcuts(newManifestShortcutList);
if (newManifestShortcutList != null) {
changed |= pushOutExcessShortcuts();
}
s.verifyStates();
if (changed) {
// This will send a notification to the launcher, and also save .
s.packageShortcutsChanged(getPackageName(), getPackageUserId());
} else {
// Still save the version code.
s.scheduleSaveUser(getPackageUserId());
}
return changed;
}
Aggregations