Search in sources :

Example 1 with PackageManager

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);
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) Uri(android.net.Uri) PackageManager(android.content.pm.PackageManager)

Example 2 with PackageManager

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PackageManager

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;
}
Also used : PackageManager(android.content.pm.PackageManager) FeatureInfo(android.content.pm.FeatureInfo)

Example 4 with PackageManager

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;
}
Also used : PackageManager(android.content.pm.PackageManager) FeatureInfo(android.content.pm.FeatureInfo)

Example 5 with PackageManager

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";
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo)

Aggregations

PackageManager (android.content.pm.PackageManager)1429 Intent (android.content.Intent)483 ResolveInfo (android.content.pm.ResolveInfo)449 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)345 ApplicationInfo (android.content.pm.ApplicationInfo)249 PackageInfo (android.content.pm.PackageInfo)248 ComponentName (android.content.ComponentName)239 ArrayList (java.util.ArrayList)156 ActivityInfo (android.content.pm.ActivityInfo)135 IOException (java.io.IOException)126 RemoteException (android.os.RemoteException)105 IPackageManager (android.content.pm.IPackageManager)93 Drawable (android.graphics.drawable.Drawable)93 Resources (android.content.res.Resources)90 PendingIntent (android.app.PendingIntent)71 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)63 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)53 ServiceInfo (android.content.pm.ServiceInfo)46