Search in sources :

Example 31 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class CameraBinderTestUtils method isFeatureAvailable.

public static final boolean isFeatureAvailable(Context context, String feature) {
    final PackageManager packageManager = context.getPackageManager();
    final FeatureInfo[] featuresList = packageManager.getSystemAvailableFeatures();
    for (FeatureInfo f : featuresList) {
        if (f.name != null && f.name.equals(feature)) {
            return true;
        }
    }
    return false;
}
Also used : PackageManager(android.content.pm.PackageManager) FeatureInfo(android.content.pm.FeatureInfo)

Example 32 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class CarNavigationBarController method facetHasMultiplePackages.

/**
     * Helper method to check if a given facet has multiple packages associated with it.
     * This can be resource defined package names or package names filtered by facet category.
     */
private boolean facetHasMultiplePackages(int index) {
    PackageManager pm = mContext.getPackageManager();
    // Check if the packages defined for the filter actually exists on the device
    String[] packages = mFacetPackages.get(index);
    if (packages.length > 1) {
        int count = 0;
        for (int i = 0; i < packages.length; i++) {
            count += pm.getLaunchIntentForPackage(packages[i]) != null ? 1 : 0;
            if (count > 1) {
                return true;
            }
        }
    }
    // If there weren't multiple packages defined for the facet, check the categories
    // and see if they resolve to multiple package names
    String[] categories = mFacetCategories.get(index);
    int count = 0;
    for (int i = 0; i < categories.length; i++) {
        String category = categories[i];
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_MAIN);
        intent.addCategory(category);
        count += pm.queryIntentActivities(intent, 0).size();
        if (count > 1) {
            return true;
        }
    }
    return false;
}
Also used : PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent)

Example 33 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class MediaSessions method getControllerName.

protected String getControllerName(MediaController controller) {
    final PackageManager pm = mContext.getPackageManager();
    final String pkg = controller.getPackageName();
    try {
        if (USE_SERVICE_LABEL) {
            final List<ResolveInfo> ris = pm.queryIntentServices(new Intent("android.media.MediaRouteProviderService").setPackage(pkg), 0);
            if (ris != null) {
                for (ResolveInfo ri : ris) {
                    if (ri.serviceInfo == null)
                        continue;
                    if (pkg.equals(ri.serviceInfo.packageName)) {
                        final String serviceLabel = Objects.toString(ri.serviceInfo.loadLabel(pm), "").trim();
                        if (serviceLabel.length() > 0) {
                            return serviceLabel;
                        }
                    }
                }
            }
        }
        final ApplicationInfo ai = pm.getApplicationInfo(pkg, 0);
        final String appLabel = Objects.toString(ai.loadLabel(pm), "").trim();
        if (appLabel.length() > 0) {
            return appLabel;
        }
    } catch (NameNotFoundException e) {
    }
    return pkg;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 34 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class PipUI method start.

@Override
public void start() {
    PackageManager pm = mContext.getPackageManager();
    mSupportPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE) && pm.hasSystemFeature(FEATURE_LEANBACK);
    if (!mSupportPip) {
        return;
    }
    PipManager pipManager = PipManager.getInstance();
    pipManager.initialize(mContext);
}
Also used : PackageManager(android.content.pm.PackageManager)

Example 35 with PackageManager

use of android.content.pm.PackageManager in project platform_frameworks_base by android.

the class UsbConfirmActivity method onCreate.

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    Intent intent = getIntent();
    mDevice = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    mAccessory = (UsbAccessory) intent.getParcelableExtra(UsbManager.EXTRA_ACCESSORY);
    mResolveInfo = (ResolveInfo) intent.getParcelableExtra("rinfo");
    PackageManager packageManager = getPackageManager();
    String appName = mResolveInfo.loadLabel(packageManager).toString();
    final AlertController.AlertParams ap = mAlertParams;
    ap.mIcon = mResolveInfo.loadIcon(packageManager);
    ap.mTitle = appName;
    if (mDevice == null) {
        ap.mMessage = getString(R.string.usb_accessory_confirm_prompt, appName);
        mDisconnectedReceiver = new UsbDisconnectedReceiver(this, mAccessory);
    } else {
        ap.mMessage = getString(R.string.usb_device_confirm_prompt, appName);
        mDisconnectedReceiver = new UsbDisconnectedReceiver(this, mDevice);
    }
    ap.mPositiveButtonText = getString(android.R.string.ok);
    ap.mNegativeButtonText = getString(android.R.string.cancel);
    ap.mPositiveButtonListener = this;
    ap.mNegativeButtonListener = this;
    // add "always use" checkbox
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    ap.mView = inflater.inflate(com.android.internal.R.layout.always_use_checkbox, null);
    mAlwaysUse = (CheckBox) ap.mView.findViewById(com.android.internal.R.id.alwaysUse);
    if (mDevice == null) {
        mAlwaysUse.setText(R.string.always_use_accessory);
    } else {
        mAlwaysUse.setText(R.string.always_use_device);
    }
    mAlwaysUse.setOnCheckedChangeListener(this);
    mClearDefaultHint = (TextView) ap.mView.findViewById(com.android.internal.R.id.clearDefaultHint);
    mClearDefaultHint.setVisibility(View.GONE);
    setupAlert();
}
Also used : PackageManager(android.content.pm.PackageManager) LayoutInflater(android.view.LayoutInflater) Intent(android.content.Intent) AlertController(com.android.internal.app.AlertController)

Aggregations

PackageManager (android.content.pm.PackageManager)1475 Intent (android.content.Intent)499 ResolveInfo (android.content.pm.ResolveInfo)456 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)351 PackageInfo (android.content.pm.PackageInfo)268 ApplicationInfo (android.content.pm.ApplicationInfo)253 ComponentName (android.content.ComponentName)241 ArrayList (java.util.ArrayList)158 ActivityInfo (android.content.pm.ActivityInfo)140 IOException (java.io.IOException)126 RemoteException (android.os.RemoteException)105 Drawable (android.graphics.drawable.Drawable)94 IPackageManager (android.content.pm.IPackageManager)93 Resources (android.content.res.Resources)90 PendingIntent (android.app.PendingIntent)75 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Context (android.content.Context)68 Bundle (android.os.Bundle)60 HashMap (java.util.HashMap)53 ServiceInfo (android.content.pm.ServiceInfo)48