use of android.content.pm.PackageManager in project Launcher3 by chislon.
the class MemoryDumpActivity method dumpHprofAndShare.
public static void dumpHprofAndShare(final Context context, MemoryTracker tracker) {
final StringBuilder body = new StringBuilder();
final ArrayList<String> paths = new ArrayList<String>();
final int myPid = android.os.Process.myPid();
final int[] pids_orig = tracker.getTrackedProcesses();
final int[] pids_copy = Arrays.copyOf(pids_orig, pids_orig.length);
for (int pid : pids_copy) {
MemoryTracker.ProcessMemInfo info = tracker.getMemInfo(pid);
if (info != null) {
body.append("pid ").append(pid).append(":").append(" up=").append(info.getUptime()).append(" pss=").append(info.currentPss).append(" uss=").append(info.currentUss).append("\n");
}
if (pid == myPid) {
final String path = String.format("%s/launcher-memory-%d.ahprof", Environment.getExternalStorageDirectory(), pid);
Log.v(TAG, "Dumping memory info for process " + pid + " to " + path);
try {
// will block
android.os.Debug.dumpHprofData(path);
} catch (IOException e) {
Log.e(TAG, "error dumping memory:", e);
}
paths.add(path);
}
}
String zipfile = zipUp(paths);
if (zipfile == null)
return;
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("application/zip");
final PackageManager pm = context.getPackageManager();
shareIntent.putExtra(Intent.EXTRA_SUBJECT, String.format("Launcher memory dump (%d)", myPid));
String appVersion;
try {
appVersion = pm.getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
appVersion = "?";
}
body.append("\nApp version: ").append(appVersion).append("\nBuild: ").append(Build.DISPLAY).append("\n");
shareIntent.putExtra(Intent.EXTRA_TEXT, body.toString());
final File pathFile = new File(zipfile);
final Uri pathUri = Uri.fromFile(pathFile);
shareIntent.putExtra(Intent.EXTRA_STREAM, pathUri);
context.startActivity(shareIntent);
}
use of android.content.pm.PackageManager in project android-betterpickers by code-troopers.
the class ListSamples method getData.
protected List<Map<String, Object>> getData(String prefix) {
List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(INTENT_SAMPLE);
PackageManager pm = getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
if (null == list) {
return myData;
}
String[] prefixPath;
String prefixWithSlash = prefix;
if (prefix.equals("")) {
prefixPath = null;
} else {
prefixPath = prefix.split("/");
prefixWithSlash = prefix + "/";
}
int len = list.size();
Map<String, Boolean> entries = new HashMap<String, Boolean>();
for (int i = 0; i < len; i++) {
ResolveInfo info = list.get(i);
CharSequence labelSeq = info.loadLabel(pm);
String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {
String[] labelPath = label.split("/");
String nextLabel = prefixPath == null ? labelPath[0] : labelPath[prefixPath.length];
if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
addItem(myData, nextLabel, activityIntent(info.activityInfo.applicationInfo.packageName, info.activityInfo.name));
} else {
if (entries.get(nextLabel) == null) {
addItem(myData, nextLabel, browseIntent(prefix.equals("") ? nextLabel : prefix + "/" + nextLabel));
entries.put(nextLabel, true);
}
}
}
}
Collections.sort(myData, NAME_COMPARATOR);
return myData;
}
use of android.content.pm.PackageManager in project cw-omnibus by commonsguy.
the class AbstractMapActivity method getVersionFromPackageManager.
// following from
// https://android.googlesource.com/platform/cts/+/master/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in
* writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing
* permissions and limitations under the License.
*/
private static int getVersionFromPackageManager(Context context) {
PackageManager packageManager = context.getPackageManager();
FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures();
if (featureInfos != null && featureInfos.length > 0) {
for (FeatureInfo featureInfo : featureInfos) {
// gl es version feature.
if (featureInfo.name == null) {
if (featureInfo.reqGlEsVersion != FeatureInfo.GL_ES_VERSION_UNDEFINED) {
return getMajorVersion(featureInfo.reqGlEsVersion);
} else {
// Lack of property means OpenGL ES
return 1;
// version 1
}
}
}
}
return 1;
}
use of android.content.pm.PackageManager in project cw-omnibus by commonsguy.
the class AbstractMapActivity method getVersionFromPackageManager.
// following from
// https://android.googlesource.com/platform/cts/+/master/tests/tests/graphics/src/android/opengl/cts/OpenGlEsVersionTest.java
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in
* writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See
* the License for the specific language governing
* permissions and limitations under the License.
*/
private static int getVersionFromPackageManager(Context context) {
PackageManager packageManager = context.getPackageManager();
FeatureInfo[] featureInfos = packageManager.getSystemAvailableFeatures();
if (featureInfos != null && featureInfos.length > 0) {
for (FeatureInfo featureInfo : featureInfos) {
// gl es version feature.
if (featureInfo.name == null) {
if (featureInfo.reqGlEsVersion != FeatureInfo.GL_ES_VERSION_UNDEFINED) {
return getMajorVersion(featureInfo.reqGlEsVersion);
} else {
// Lack of property means OpenGL ES
return 1;
// version 1
}
}
}
}
return 1;
}
use of android.content.pm.PackageManager in project android by cSploit.
the class System method getAppVersionName.
public static String getAppVersionName() {
if (mApkVersion != null)
return mApkVersion;
try {
PackageManager manager = mContext.getPackageManager();
PackageInfo info = manager != null ? manager.getPackageInfo(mContext.getPackageName(), 0) : null;
if (info != null)
return (mApkVersion = info.versionName);
} catch (NameNotFoundException e) {
errorLogging(e);
}
return "0.0.1";
}
Aggregations