Search in sources :

Example 36 with PatternMatcher

use of android.os.PatternMatcher in project VirtualXposed by android-hacker.

the class ResolverActivity method onIntentSelected.

protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
    if (mAlwaysUseOption && mAdapter.mOrigResolveList != null) {
        // Build a reasonable intent filter, based on what matched.
        IntentFilter filter = new IntentFilter();
        if (intent.getAction() != null) {
            filter.addAction(intent.getAction());
        }
        Set<String> categories = intent.getCategories();
        if (categories != null) {
            for (String cat : categories) {
                filter.addCategory(cat);
            }
        }
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK;
        Uri data = intent.getData();
        if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
            String mimeType = intent.resolveType(this);
            if (mimeType != null) {
                try {
                    filter.addDataType(mimeType);
                } catch (IntentFilter.MalformedMimeTypeException e) {
                    VLog.w("ResolverActivity", "mimeType\n" + VLog.getStackTraceString(e));
                    filter = null;
                }
            }
        }
        if (data != null && data.getScheme() != null) {
            // or "content:" schemes (see IntentFilter for the reason).
            if (cat != IntentFilter.MATCH_CATEGORY_TYPE || (!"file".equals(data.getScheme()) && !"content".equals(data.getScheme()))) {
                filter.addDataScheme(data.getScheme());
                if (Build.VERSION.SDK_INT >= 19) {
                    // Look through the resolved filter to determine which part
                    // of it matched the original Intent.
                    Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator();
                    if (pIt != null) {
                        String ssp = data.getSchemeSpecificPart();
                        while (ssp != null && pIt.hasNext()) {
                            PatternMatcher p = pIt.next();
                            if (p.match(ssp)) {
                                filter.addDataSchemeSpecificPart(p.getPath(), p.getType());
                                break;
                            }
                        }
                    }
                    Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
                    if (aIt != null) {
                        while (aIt.hasNext()) {
                            IntentFilter.AuthorityEntry a = aIt.next();
                            if (a.match(data) >= 0) {
                                int port = a.getPort();
                                filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null);
                                break;
                            }
                        }
                    }
                    pIt = ri.filter.pathsIterator();
                    if (pIt != null) {
                        String path = data.getPath();
                        while (path != null && pIt.hasNext()) {
                            PatternMatcher p = pIt.next();
                            if (p.match(path)) {
                                filter.addDataPath(p.getPath(), p.getType());
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (filter != null) {
            final int N = mAdapter.mOrigResolveList.size();
            ComponentName[] set = new ComponentName[N];
            int bestMatch = 0;
            for (int i = 0; i < N; i++) {
                ResolveInfo r = mAdapter.mOrigResolveList.get(i);
                set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name);
                if (r.match > bestMatch)
                    bestMatch = r.match;
            }
            if (alwaysCheck) {
                getPackageManager().addPreferredActivity(filter, bestMatch, set, intent.getComponent());
            } else {
                try {
                    Reflect.on(VClientImpl.get().getCurrentApplication().getPackageManager()).call("setLastChosenActivity", intent, intent.resolveTypeIfNeeded(getContentResolver()), PackageManager.MATCH_DEFAULT_ONLY, filter, bestMatch, intent.getComponent());
                } catch (Exception re) {
                    VLog.d(TAG, "Error calling setLastChosenActivity\n" + VLog.getStackTraceString(re));
                }
            }
        }
    }
    if (intent != null) {
        ActivityInfo info = VirtualCore.get().resolveActivityInfo(intent, mLaunchedFromUid);
        if (info == null) {
            // 外面的
            startActivity(intent);
        // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // startActivity(intent);//, mRequestCode, mOptions);
        // }else{
        // startActivity(intent);//, mRequestCode);
        // }
        } else {
            VActivityManager.get().startActivity(intent, info, null, mOptions, mResultWho, mRequestCode, mLaunchedFromUid);
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) ActivityInfo(android.content.pm.ActivityInfo) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) ResolveInfo(android.content.pm.ResolveInfo) ComponentName(android.content.ComponentName) PatternMatcher(android.os.PatternMatcher)

Example 37 with PatternMatcher

use of android.os.PatternMatcher in project UnityModManager by xausky.

the class ResolverActivity method onIntentSelected.

protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
    if (mAlwaysUseOption && mAdapter.mOrigResolveList != null) {
        // Build a reasonable intent filter, based on what matched.
        IntentFilter filter = new IntentFilter();
        if (intent.getAction() != null) {
            filter.addAction(intent.getAction());
        }
        Set<String> categories = intent.getCategories();
        if (categories != null) {
            for (String cat : categories) {
                filter.addCategory(cat);
            }
        }
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        int cat = ri.match & IntentFilter.MATCH_CATEGORY_MASK;
        Uri data = intent.getData();
        if (cat == IntentFilter.MATCH_CATEGORY_TYPE) {
            String mimeType = intent.resolveType(this);
            if (mimeType != null) {
                try {
                    filter.addDataType(mimeType);
                } catch (IntentFilter.MalformedMimeTypeException e) {
                    VLog.w("ResolverActivity", "mimeType\n" + VLog.getStackTraceString(e));
                    filter = null;
                }
            }
        }
        if (data != null && data.getScheme() != null) {
            // or "content:" schemes (see IntentFilter for the reason).
            if (cat != IntentFilter.MATCH_CATEGORY_TYPE || (!"file".equals(data.getScheme()) && !"content".equals(data.getScheme()))) {
                filter.addDataScheme(data.getScheme());
                if (Build.VERSION.SDK_INT >= 19) {
                    // Look through the resolved filter to determine which part
                    // of it matched the original Intent.
                    Iterator<PatternMatcher> pIt = ri.filter.schemeSpecificPartsIterator();
                    if (pIt != null) {
                        String ssp = data.getSchemeSpecificPart();
                        while (ssp != null && pIt.hasNext()) {
                            PatternMatcher p = pIt.next();
                            if (p.match(ssp)) {
                                filter.addDataSchemeSpecificPart(p.getPath(), p.getType());
                                break;
                            }
                        }
                    }
                    Iterator<IntentFilter.AuthorityEntry> aIt = ri.filter.authoritiesIterator();
                    if (aIt != null) {
                        while (aIt.hasNext()) {
                            IntentFilter.AuthorityEntry a = aIt.next();
                            if (a.match(data) >= 0) {
                                int port = a.getPort();
                                filter.addDataAuthority(a.getHost(), port >= 0 ? Integer.toString(port) : null);
                                break;
                            }
                        }
                    }
                    pIt = ri.filter.pathsIterator();
                    if (pIt != null) {
                        String path = data.getPath();
                        while (path != null && pIt.hasNext()) {
                            PatternMatcher p = pIt.next();
                            if (p.match(path)) {
                                filter.addDataPath(p.getPath(), p.getType());
                                break;
                            }
                        }
                    }
                }
            }
        }
        if (filter != null) {
            final int N = mAdapter.mOrigResolveList.size();
            ComponentName[] set = new ComponentName[N];
            int bestMatch = 0;
            for (int i = 0; i < N; i++) {
                ResolveInfo r = mAdapter.mOrigResolveList.get(i);
                set[i] = new ComponentName(r.activityInfo.packageName, r.activityInfo.name);
                if (r.match > bestMatch)
                    bestMatch = r.match;
            }
            if (alwaysCheck) {
                getPackageManager().addPreferredActivity(filter, bestMatch, set, intent.getComponent());
            } else {
                try {
                    Reflect.on(VClientImpl.get().getCurrentApplication().getPackageManager()).call("setLastChosenActivity", intent, intent.resolveTypeIfNeeded(getContentResolver()), PackageManager.MATCH_DEFAULT_ONLY, filter, bestMatch, intent.getComponent());
                } catch (Exception re) {
                    VLog.d(TAG, "Error calling setLastChosenActivity\n" + VLog.getStackTraceString(re));
                }
            }
        }
    }
    if (intent != null) {
        ActivityInfo info = VirtualCore.get().resolveActivityInfo(intent, mLaunchedFromUid);
        if (info == null) {
            // 外面的
            startActivity(intent);
        // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        // startActivity(intent);//, mRequestCode, mOptions);
        // }else{
        // startActivity(intent);//, mRequestCode);
        // }
        } else {
            VActivityManager.get().startActivity(intent, info, null, mOptions, mResultWho, mRequestCode, mLaunchedFromUid);
        }
    }
}
Also used : IntentFilter(android.content.IntentFilter) ActivityInfo(android.content.pm.ActivityInfo) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint) ResolveInfo(android.content.pm.ResolveInfo) ComponentName(android.content.ComponentName) PatternMatcher(android.os.PatternMatcher)

Aggregations

PatternMatcher (android.os.PatternMatcher)37 IntentFilter (android.content.IntentFilter)16 Uri (android.net.Uri)16 ComponentName (android.content.ComponentName)12 ResolveInfo (android.content.pm.ResolveInfo)12 Intent (android.content.Intent)10 TypedArray (android.content.res.TypedArray)7 LabeledIntent (android.content.pm.LabeledIntent)5 PackageManager (android.content.pm.PackageManager)5 RemoteException (android.os.RemoteException)5 LogPrinter (android.util.LogPrinter)5 ActivityInfo (android.content.pm.ActivityInfo)4 SuppressLint (android.annotation.SuppressLint)3 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1