use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class BatteryStatsService method dump.
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) != PackageManager.PERMISSION_GRANTED) {
pw.println("Permission Denial: can't dump BatteryStats from from pid=" + Binder.getCallingPid() + ", uid=" + Binder.getCallingUid() + " without permission " + android.Manifest.permission.DUMP);
return;
}
int flags = 0;
boolean useCheckinFormat = false;
boolean isRealCheckin = false;
boolean noOutput = false;
boolean writeData = false;
long historyStart = -1;
int reqUid = -1;
if (args != null) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if ("--checkin".equals(arg)) {
useCheckinFormat = true;
isRealCheckin = true;
} else if ("--history".equals(arg)) {
flags |= BatteryStats.DUMP_HISTORY_ONLY;
} else if ("--history-start".equals(arg)) {
flags |= BatteryStats.DUMP_HISTORY_ONLY;
i++;
if (i >= args.length) {
pw.println("Missing time argument for --history-since");
dumpHelp(pw);
return;
}
historyStart = Long.parseLong(args[i]);
writeData = true;
} else if ("-c".equals(arg)) {
useCheckinFormat = true;
flags |= BatteryStats.DUMP_INCLUDE_HISTORY;
} else if ("--charged".equals(arg)) {
flags |= BatteryStats.DUMP_CHARGED_ONLY;
} else if ("--daily".equals(arg)) {
flags |= BatteryStats.DUMP_DAILY_ONLY;
} else if ("--reset".equals(arg)) {
synchronized (mStats) {
mStats.resetAllStatsCmdLocked();
pw.println("Battery stats reset.");
noOutput = true;
}
updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
} else if ("--write".equals(arg)) {
updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
synchronized (mStats) {
mStats.writeSyncLocked();
pw.println("Battery stats written.");
noOutput = true;
}
} else if ("--new-daily".equals(arg)) {
synchronized (mStats) {
mStats.recordDailyStatsLocked();
pw.println("New daily stats written.");
noOutput = true;
}
} else if ("--read-daily".equals(arg)) {
synchronized (mStats) {
mStats.readDailyStatsLocked();
pw.println("Last daily stats read.");
noOutput = true;
}
} else if ("--enable".equals(arg) || "enable".equals(arg)) {
i = doEnableOrDisable(pw, i, args, true);
if (i < 0) {
return;
}
pw.println("Enabled: " + args[i]);
return;
} else if ("--disable".equals(arg) || "disable".equals(arg)) {
i = doEnableOrDisable(pw, i, args, false);
if (i < 0) {
return;
}
pw.println("Disabled: " + args[i]);
return;
} else if ("-h".equals(arg)) {
dumpHelp(pw);
return;
} else if ("-a".equals(arg)) {
flags |= BatteryStats.DUMP_VERBOSE;
} else if (arg.length() > 0 && arg.charAt(0) == '-') {
pw.println("Unknown option: " + arg);
dumpHelp(pw);
return;
} else {
// Not an option, last argument must be a package name.
try {
reqUid = mContext.getPackageManager().getPackageUidAsUser(arg, UserHandle.getCallingUserId());
} catch (PackageManager.NameNotFoundException e) {
pw.println("Unknown package: " + arg);
dumpHelp(pw);
return;
}
}
}
}
if (noOutput) {
return;
}
long ident = Binder.clearCallingIdentity();
try {
if (BatteryStatsHelper.checkWifiOnly(mContext)) {
flags |= BatteryStats.DUMP_DEVICE_WIFI_ONLY;
}
// Fetch data from external sources and update the BatteryStatsImpl object with them.
updateExternalStatsSync("dump", BatteryStatsImpl.ExternalStatsSync.UPDATE_ALL);
} finally {
Binder.restoreCallingIdentity(ident);
}
if (reqUid >= 0) {
// we only dump the aggregated data since charged.
if ((flags & (BatteryStats.DUMP_HISTORY_ONLY | BatteryStats.DUMP_CHARGED_ONLY)) == 0) {
flags |= BatteryStats.DUMP_CHARGED_ONLY;
// Also if they are doing -c, we don't want history.
flags &= ~BatteryStats.DUMP_INCLUDE_HISTORY;
}
}
if (useCheckinFormat) {
List<ApplicationInfo> apps = mContext.getPackageManager().getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_ALL);
if (isRealCheckin) {
// file if there is one.
synchronized (mStats.mCheckinFile) {
if (mStats.mCheckinFile.exists()) {
try {
byte[] raw = mStats.mCheckinFile.readFully();
if (raw != null) {
Parcel in = Parcel.obtain();
in.unmarshall(raw, 0, raw.length);
in.setDataPosition(0);
BatteryStatsImpl checkinStats = new BatteryStatsImpl(null, mStats.mHandler, null);
checkinStats.readSummaryFromParcel(in);
in.recycle();
checkinStats.dumpCheckinLocked(mContext, pw, apps, flags, historyStart);
mStats.mCheckinFile.delete();
return;
}
} catch (IOException | ParcelFormatException e) {
Slog.w(TAG, "Failure reading checkin file " + mStats.mCheckinFile.getBaseFile(), e);
}
}
}
}
synchronized (mStats) {
mStats.dumpCheckinLocked(mContext, pw, apps, flags, historyStart);
if (writeData) {
mStats.writeAsyncLocked();
}
}
} else {
synchronized (mStats) {
mStats.dumpLocked(mContext, pw, flags, reqUid, historyStart);
if (writeData) {
mStats.writeAsyncLocked();
}
}
}
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class CompatModePackages method setPackageScreenCompatModeLocked.
public void setPackageScreenCompatModeLocked(String packageName, int mode) {
ApplicationInfo ai = null;
try {
ai = AppGlobals.getPackageManager().getApplicationInfo(packageName, 0, 0);
} catch (RemoteException e) {
}
if (ai == null) {
Slog.w(TAG, "setPackageScreenCompatMode failed: unknown package " + packageName);
return;
}
setPackageScreenCompatModeLocked(ai, mode);
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class CompatModePackages method saveCompatModes.
void saveCompatModes() {
HashMap<String, Integer> pkgs;
synchronized (mService) {
pkgs = new HashMap<String, Integer>(mPackages);
}
FileOutputStream fos = null;
try {
fos = mFile.startWrite();
XmlSerializer out = new FastXmlSerializer();
out.setOutput(fos, StandardCharsets.UTF_8.name());
out.startDocument(null, true);
out.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
out.startTag(null, "compat-packages");
final IPackageManager pm = AppGlobals.getPackageManager();
final int screenLayout = mService.mConfiguration.screenLayout;
final int smallestScreenWidthDp = mService.mConfiguration.smallestScreenWidthDp;
final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Integer> entry = it.next();
String pkg = entry.getKey();
int mode = entry.getValue();
if (mode == 0) {
continue;
}
ApplicationInfo ai = null;
try {
ai = pm.getApplicationInfo(pkg, 0, 0);
} catch (RemoteException e) {
}
if (ai == null) {
continue;
}
CompatibilityInfo info = new CompatibilityInfo(ai, screenLayout, smallestScreenWidthDp, false);
if (info.alwaysSupportsScreen()) {
continue;
}
if (info.neverSupportsScreen()) {
continue;
}
out.startTag(null, "pkg");
out.attribute(null, "name", pkg);
out.attribute(null, "mode", Integer.toString(mode));
out.endTag(null, "pkg");
}
out.endTag(null, "compat-packages");
out.endDocument();
mFile.finishWrite(fos);
} catch (java.io.IOException e1) {
Slog.w(TAG, "Error writing compat packages", e1);
if (fos != null) {
mFile.failWrite(fos);
}
}
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class AppPickerAdapter method getView.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (null == view) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(R.layout.app_picker_list_item, null);
}
ApplicationInfo data = appList.get(position);
if (null != data) {
TextView appName = (TextView) view.findViewById(R.id.app_name);
TextView packageName = (TextView) view.findViewById(R.id.app_package);
ImageView iconView = (ImageView) view.findViewById(R.id.app_icon);
appName.setText(data.loadLabel(packageManager));
packageName.setText(data.packageName);
iconView.setImageDrawable(data.loadIcon(packageManager));
}
return view;
}
use of android.content.pm.ApplicationInfo in project android_frameworks_base by ResurrectionRemix.
the class BaseShortcutManagerTest method genPackage.
protected PackageInfo genPackage(String packageName, int uid, int version, String... signatures) {
final PackageInfo pi = new PackageInfo();
pi.packageName = packageName;
pi.applicationInfo = new ApplicationInfo();
pi.applicationInfo.uid = uid;
pi.applicationInfo.flags = ApplicationInfo.FLAG_INSTALLED | ApplicationInfo.FLAG_ALLOW_BACKUP;
pi.versionCode = version;
pi.applicationInfo.versionCode = version;
pi.signatures = genSignatures(signatures);
return pi;
}
Aggregations