Search in sources :

Example 81 with ResolveInfo

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

the class UsbSettingsManager method getAccessoryMatchesLocked.

private final ArrayList<ResolveInfo> getAccessoryMatchesLocked(UsbAccessory accessory, Intent intent) {
    ArrayList<ResolveInfo> matches = new ArrayList<ResolveInfo>();
    List<ResolveInfo> resolveInfos = mPackageManager.queryIntentActivities(intent, PackageManager.GET_META_DATA);
    int count = resolveInfos.size();
    for (int i = 0; i < count; i++) {
        ResolveInfo resolveInfo = resolveInfos.get(i);
        if (packageMatchesLocked(resolveInfo, intent.getAction(), null, accessory)) {
            matches.add(resolveInfo);
        }
    }
    return matches;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ArrayList(java.util.ArrayList)

Example 82 with ResolveInfo

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

the class UsbSettingsManager method resolveActivity.

private void resolveActivity(Intent intent, ArrayList<ResolveInfo> matches, String defaultPackage, UsbDevice device, UsbAccessory accessory) {
    int count = matches.size();
    // don't show the resolver activity if there are no choices available
    if (count == 0) {
        if (accessory != null) {
            String uri = accessory.getUri();
            if (uri != null && uri.length() > 0) {
                // display URI to user
                // start UsbResolverActivity so user can choose an activity
                Intent dialogIntent = new Intent();
                dialogIntent.setClassName("com.android.systemui", "com.android.systemui.usb.UsbAccessoryUriActivity");
                dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                dialogIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
                dialogIntent.putExtra("uri", uri);
                try {
                    mUserContext.startActivityAsUser(dialogIntent, mUser);
                } catch (ActivityNotFoundException e) {
                    Slog.e(TAG, "unable to start UsbAccessoryUriActivity");
                }
            }
        }
        // do nothing
        return;
    }
    ResolveInfo defaultRI = null;
    if (count == 1 && defaultPackage == null) {
        // Check to see if our single choice is on the system partition.
        // If so, treat it as our default without calling UsbResolverActivity
        ResolveInfo rInfo = matches.get(0);
        if (rInfo.activityInfo != null && rInfo.activityInfo.applicationInfo != null && (rInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            defaultRI = rInfo;
        }
        if (mDisablePermissionDialogs) {
            // bypass dialog and launch the only matching activity
            rInfo = matches.get(0);
            if (rInfo.activityInfo != null) {
                defaultPackage = rInfo.activityInfo.packageName;
            }
        }
    }
    if (defaultRI == null && defaultPackage != null) {
        // look for default activity
        for (int i = 0; i < count; i++) {
            ResolveInfo rInfo = matches.get(i);
            if (rInfo.activityInfo != null && defaultPackage.equals(rInfo.activityInfo.packageName)) {
                defaultRI = rInfo;
                break;
            }
        }
    }
    if (defaultRI != null) {
        // grant permission for default activity
        if (device != null) {
            grantDevicePermission(device, defaultRI.activityInfo.applicationInfo.uid);
        } else if (accessory != null) {
            grantAccessoryPermission(accessory, defaultRI.activityInfo.applicationInfo.uid);
        }
        // start default activity directly
        try {
            intent.setComponent(new ComponentName(defaultRI.activityInfo.packageName, defaultRI.activityInfo.name));
            mUserContext.startActivityAsUser(intent, mUser);
        } catch (ActivityNotFoundException e) {
            Slog.e(TAG, "startActivity failed", e);
        }
    } else {
        Intent resolverIntent = new Intent();
        resolverIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if (count == 1) {
            // start UsbConfirmActivity if there is only one choice
            resolverIntent.setClassName("com.android.systemui", "com.android.systemui.usb.UsbConfirmActivity");
            resolverIntent.putExtra("rinfo", matches.get(0));
            if (device != null) {
                resolverIntent.putExtra(UsbManager.EXTRA_DEVICE, device);
            } else {
                resolverIntent.putExtra(UsbManager.EXTRA_ACCESSORY, accessory);
            }
        } else {
            // start UsbResolverActivity so user can choose an activity
            resolverIntent.setClassName("com.android.systemui", "com.android.systemui.usb.UsbResolverActivity");
            resolverIntent.putParcelableArrayListExtra("rlist", matches);
            resolverIntent.putExtra(Intent.EXTRA_INTENT, intent);
        }
        try {
            mUserContext.startActivityAsUser(resolverIntent, mUser);
        } catch (ActivityNotFoundException e) {
            Slog.e(TAG, "unable to start activity " + resolverIntent);
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ComponentName(android.content.ComponentName)

Example 83 with ResolveInfo

use of android.content.pm.ResolveInfo in project androidquery by androidquery.

the class FacebookHandle method validateAppSignatureForIntent.

private boolean validateAppSignatureForIntent(Context context, Intent intent) {
    PackageManager pm = context.getPackageManager();
    ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
    if (resolveInfo == null) {
        return false;
    }
    String packageName = resolveInfo.activityInfo.packageName;
    PackageInfo packageInfo;
    try {
        packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
    } catch (NameNotFoundException e) {
        return false;
    }
    for (Signature signature : packageInfo.signatures) {
        if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
            return true;
        }
    }
    return false;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Signature(android.content.pm.Signature)

Example 84 with ResolveInfo

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

the class Vpn method establish.

/**
     * Establish a VPN network and return the file descriptor of the VPN
     * interface. This methods returns {@code null} if the application is
     * revoked or not prepared.
     *
     * @param config The parameters to configure the network.
     * @return The file descriptor of the VPN interface.
     */
public synchronized ParcelFileDescriptor establish(VpnConfig config) {
    // Check if the caller is already prepared.
    UserManager mgr = UserManager.get(mContext);
    if (Binder.getCallingUid() != mOwnerUID) {
        return null;
    }
    // Check to ensure consent hasn't been revoked since we were prepared.
    if (!isVpnUserPreConsented(mPackage)) {
        return null;
    }
    // Check if the service is properly declared.
    Intent intent = new Intent(VpnConfig.SERVICE_INTERFACE);
    intent.setClassName(mPackage, config.user);
    long token = Binder.clearCallingIdentity();
    try {
        // Restricted users are not allowed to create VPNs, they are tied to Owner
        UserInfo user = mgr.getUserInfo(mUserHandle);
        if (user.isRestricted()) {
            throw new SecurityException("Restricted users cannot establish VPNs");
        }
        ResolveInfo info = AppGlobals.getPackageManager().resolveService(intent, null, 0, mUserHandle);
        if (info == null) {
            throw new SecurityException("Cannot find " + config.user);
        }
        if (!BIND_VPN_SERVICE.equals(info.serviceInfo.permission)) {
            throw new SecurityException(config.user + " does not require " + BIND_VPN_SERVICE);
        }
    } catch (RemoteException e) {
        throw new SecurityException("Cannot find " + config.user);
    } finally {
        Binder.restoreCallingIdentity(token);
    }
    // Save the old config in case we need to go back.
    VpnConfig oldConfig = mConfig;
    String oldInterface = mInterface;
    Connection oldConnection = mConnection;
    NetworkAgent oldNetworkAgent = mNetworkAgent;
    mNetworkAgent = null;
    Set<UidRange> oldUsers = mVpnUsers;
    // Configure the interface. Abort if any of these steps fails.
    ParcelFileDescriptor tun = ParcelFileDescriptor.adoptFd(jniCreate(config.mtu));
    try {
        updateState(DetailedState.CONNECTING, "establish");
        String interfaze = jniGetName(tun.getFd());
        // TEMP use the old jni calls until there is support for netd address setting
        StringBuilder builder = new StringBuilder();
        for (LinkAddress address : config.addresses) {
            builder.append(" " + address);
        }
        if (jniSetAddresses(interfaze, builder.toString()) < 1) {
            throw new IllegalArgumentException("At least one address must be specified");
        }
        Connection connection = new Connection();
        if (!mContext.bindServiceAsUser(intent, connection, Context.BIND_AUTO_CREATE | Context.BIND_FOREGROUND_SERVICE, new UserHandle(mUserHandle))) {
            throw new IllegalStateException("Cannot bind " + config.user);
        }
        mConnection = connection;
        mInterface = interfaze;
        // Fill more values.
        config.user = mPackage;
        config.interfaze = mInterface;
        config.startTime = SystemClock.elapsedRealtime();
        mConfig = config;
        // Set up forwarding and DNS rules.
        agentConnect();
        if (oldConnection != null) {
            mContext.unbindService(oldConnection);
        }
        // Remove the old tun's user forwarding rules
        // The new tun's user rules have already been added so they will take over
        // as rules are deleted. This prevents data leakage as the rules are moved over.
        agentDisconnect(oldNetworkAgent);
        if (oldInterface != null && !oldInterface.equals(interfaze)) {
            jniReset(oldInterface);
        }
        try {
            IoUtils.setBlocking(tun.getFileDescriptor(), config.blocking);
        } catch (IOException e) {
            throw new IllegalStateException("Cannot set tunnel's fd as blocking=" + config.blocking, e);
        }
    } catch (RuntimeException e) {
        IoUtils.closeQuietly(tun);
        agentDisconnect();
        // restore old state
        mConfig = oldConfig;
        mConnection = oldConnection;
        mVpnUsers = oldUsers;
        mNetworkAgent = oldNetworkAgent;
        mInterface = oldInterface;
        throw e;
    }
    Log.i(TAG, "Established by " + config.user + " on " + mInterface);
    return tun;
}
Also used : LinkAddress(android.net.LinkAddress) NetworkAgent(android.net.NetworkAgent) VpnConfig(com.android.internal.net.VpnConfig) UidRange(android.net.UidRange) ServiceConnection(android.content.ServiceConnection) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) UserInfo(android.content.pm.UserInfo) IOException(java.io.IOException) ResolveInfo(android.content.pm.ResolveInfo) UserManager(android.os.UserManager) UserHandle(android.os.UserHandle) ParcelFileDescriptor(android.os.ParcelFileDescriptor) RemoteException(android.os.RemoteException)

Example 85 with ResolveInfo

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

the class DefaultPermissionGrantPolicy method getDefaultSystemHandlerActivityPackageLPr.

private PackageParser.Package getDefaultSystemHandlerActivityPackageLPr(Intent intent, int userId) {
    ResolveInfo handler = mService.resolveIntent(intent, intent.resolveType(mService.mContext.getContentResolver()), DEFAULT_FLAGS, userId);
    if (handler == null || handler.activityInfo == null) {
        return null;
    }
    ActivityInfo activityInfo = handler.activityInfo;
    if (activityInfo.packageName.equals(mService.mResolveActivity.packageName) && activityInfo.name.equals(mService.mResolveActivity.name)) {
        return null;
    }
    return getSystemPackageLPr(handler.activityInfo.packageName);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo)

Aggregations

ResolveInfo (android.content.pm.ResolveInfo)1211 Intent (android.content.Intent)760 PackageManager (android.content.pm.PackageManager)470 ComponentName (android.content.ComponentName)375 ActivityInfo (android.content.pm.ActivityInfo)209 ArrayList (java.util.ArrayList)205 PendingIntent (android.app.PendingIntent)159 RemoteException (android.os.RemoteException)137 ServiceInfo (android.content.pm.ServiceInfo)120 ApplicationInfo (android.content.pm.ApplicationInfo)73 EphemeralResolveInfo (android.content.pm.EphemeralResolveInfo)58 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)53 Bundle (android.os.Bundle)47 HashMap (java.util.HashMap)46 IOException (java.io.IOException)43 HashSet (java.util.HashSet)43 Point (android.graphics.Point)42 ActivityNotFoundException (android.content.ActivityNotFoundException)38 PackageInfo (android.content.pm.PackageInfo)37 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)33