Java Code Examples for android.content.IntentFilter#hasAction()

The following examples show how to use android.content.IntentFilter#hasAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CrashlyticsControllerTest.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Override
public Context getContext() {
  // Return a context wrapper that will allow us to override the behavior of registering
  // the receiver for battery changed events.
  return new ContextWrapper(super.getContext()) {
    @Override
    public Context getApplicationContext() {
      return this;
    }

    @Override
    public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter) {
      // For the BatteryIntent, use test values to avoid breaking from emulator changes.
      if (filter.hasAction(Intent.ACTION_BATTERY_CHANGED)) {
        // If we ever call this with a receiver, it will be broken.
        assertNull(receiver);
        return BatteryIntentProvider.getBatteryIntent();
      }
      return getBaseContext().registerReceiver(receiver, filter);
    }
  };
}
 
Example 2
Source File: ApkBundleLauncher.java    From Small with Apache License 2.0 6 votes vote down vote up
private String resolveActivity(Intent intent) {
    if (sLoadedIntentFilters == null) return null;

    Iterator<Map.Entry<String, List<IntentFilter>>> it =
            sLoadedIntentFilters.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, List<IntentFilter>> entry = it.next();
        List<IntentFilter> filters = entry.getValue();
        for (IntentFilter filter : filters) {
            if (filter.hasAction(Intent.ACTION_VIEW)) {
                // TODO: match uri
            }
            if (filter.hasCategory(Intent.CATEGORY_DEFAULT)) {
                // custom action
                if (filter.hasAction(intent.getAction())) {
                    // hit
                    return entry.getKey();
                }
            }
        }
    }
    return null;
}
 
Example 3
Source File: IntentResolver.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private boolean filterEquals(IntentFilter f1, IntentFilter f2) {
    int s1 = f1.countActions();
    int s2 = f2.countActions();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasAction(f1.getAction(i))) {
            return false;
        }
    }
    s1 = f1.countCategories();
    s2 = f2.countCategories();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasCategory(f1.getCategory(i))) {
            return false;
        }
    }
    s1 = f1.countDataTypes();
    s2 = f2.countDataTypes();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasExactDataType(f1.getDataType(i))) {
            return false;
        }
    }
    s1 = f1.countDataSchemes();
    s2 = f2.countDataSchemes();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataScheme(f1.getDataScheme(i))) {
            return false;
        }
    }
    s1 = f1.countDataAuthorities();
    s2 = f2.countDataAuthorities();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataAuthority(f1.getDataAuthority(i))) {
            return false;
        }
    }
    s1 = f1.countDataPaths();
    s2 = f2.countDataPaths();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataPath(f1.getDataPath(i))) {
            return false;
        }
    }
    s1 = f1.countDataSchemeSpecificParts();
    s2 = f2.countDataSchemeSpecificParts();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataSchemeSpecificPart(f1.getDataSchemeSpecificPart(i))) {
            return false;
        }
    }
    return true;
}
 
Example 4
Source File: IntentResolver.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public static boolean filterEquals(IntentFilter f1, IntentFilter f2) {
    int s1 = f1.countActions();
    int s2 = f2.countActions();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasAction(f1.getAction(i))) {
            return false;
        }
    }
    s1 = f1.countCategories();
    s2 = f2.countCategories();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasCategory(f1.getCategory(i))) {
            return false;
        }
    }
    s1 = f1.countDataTypes();
    s2 = f2.countDataTypes();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasExactDataType(f1.getDataType(i))) {
            return false;
        }
    }
    s1 = f1.countDataSchemes();
    s2 = f2.countDataSchemes();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataScheme(f1.getDataScheme(i))) {
            return false;
        }
    }
    s1 = f1.countDataAuthorities();
    s2 = f2.countDataAuthorities();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataAuthority(f1.getDataAuthority(i))) {
            return false;
        }
    }
    s1 = f1.countDataPaths();
    s2 = f2.countDataPaths();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataPath(f1.getDataPath(i))) {
            return false;
        }
    }
    s1 = f1.countDataSchemeSpecificParts();
    s2 = f2.countDataSchemeSpecificParts();
    if (s1 != s2) {
        return false;
    }
    for (int i=0; i<s1; i++) {
        if (!f2.hasDataSchemeSpecificPart(f1.getDataSchemeSpecificPart(i))) {
            return false;
        }
    }
    return true;
}
 
Example 5
Source File: InstantAppResolver.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Returns one of three states: <p/>
 * <ul>
 *     <li>{@code null} if there are no matches will not be; resolution is unnecessary.</li>
 *     <li>An empty list signifying that a 2nd phase of resolution is required.</li>
 *     <li>A populated list meaning that matches were found and should be sent directly to the
 *     installer</li>
 * </ul>
 *
 */
private static List<AuxiliaryResolveInfo.AuxiliaryFilter> computeResolveFilters(
        Intent origIntent, String resolvedType, int userId, String packageName, String token,
        InstantAppResolveInfo instantAppInfo) {
    if (instantAppInfo.shouldLetInstallerDecide()) {
        return Collections.singletonList(
                new AuxiliaryResolveInfo.AuxiliaryFilter(
                        instantAppInfo, null /* splitName */,
                        instantAppInfo.getExtras()));
    }
    if (packageName != null
            && !packageName.equals(instantAppInfo.getPackageName())) {
        return null;
    }
    final List<InstantAppIntentFilter> instantAppFilters =
            instantAppInfo.getIntentFilters();
    if (instantAppFilters == null || instantAppFilters.isEmpty()) {
        // No filters on web intent; no matches, 2nd phase unnecessary.
        if (origIntent.isWebIntent()) {
            return null;
        }
        // No filters; we need to start phase two
        if (DEBUG_INSTANT) {
            Log.d(TAG, "No app filters; go to phase 2");
        }
        return Collections.emptyList();
    }
    final PackageManagerService.InstantAppIntentResolver instantAppResolver =
            new PackageManagerService.InstantAppIntentResolver();
    for (int j = instantAppFilters.size() - 1; j >= 0; --j) {
        final InstantAppIntentFilter instantAppFilter = instantAppFilters.get(j);
        final List<IntentFilter> splitFilters = instantAppFilter.getFilters();
        if (splitFilters == null || splitFilters.isEmpty()) {
            continue;
        }
        for (int k = splitFilters.size() - 1; k >= 0; --k) {
            IntentFilter filter = splitFilters.get(k);
            Iterator<IntentFilter.AuthorityEntry> authorities =
                    filter.authoritiesIterator();
            // ignore http/s-only filters.
            if ((authorities == null || !authorities.hasNext())
                    && (filter.hasDataScheme("http") || filter.hasDataScheme("https"))
                    && filter.hasAction(Intent.ACTION_VIEW)
                    && filter.hasCategory(Intent.CATEGORY_BROWSABLE)) {
                continue;
            }
            instantAppResolver.addFilter(
                    new AuxiliaryResolveInfo.AuxiliaryFilter(
                            filter,
                            instantAppInfo,
                            instantAppFilter.getSplitName(),
                            instantAppInfo.getExtras()
                    ));
        }
    }
    List<AuxiliaryResolveInfo.AuxiliaryFilter> matchedResolveInfoList =
            instantAppResolver.queryIntent(
                    origIntent, resolvedType, false /*defaultOnly*/, userId);
    if (!matchedResolveInfoList.isEmpty()) {
        if (DEBUG_INSTANT) {
            Log.d(TAG, "[" + token + "] Found match(es); " + matchedResolveInfoList);
        }
        return matchedResolveInfoList;
    } else if (DEBUG_INSTANT) {
        Log.d(TAG, "[" + token + "] No matches found"
                + " package: " + instantAppInfo.getPackageName()
                + ", versionCode: " + instantAppInfo.getVersionCode());
    }
    return null;
}
 
Example 6
Source File: IntentResolver.java    From container with GNU General Public License v3.0 4 votes vote down vote up
private boolean filterEquals(IntentFilter f1, IntentFilter f2) {
	int s1 = f1.countActions();
	int s2 = f2.countActions();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasAction(f1.getAction(i))) {
			return false;
		}
	}
	s1 = f1.countCategories();
	s2 = f2.countCategories();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasCategory(f1.getCategory(i))) {
			return false;
		}
	}
	s1 = f1.countDataTypes();
	s2 = f2.countDataTypes();
	if (s1 != s2) {
		return false;
	}
	s1 = f1.countDataSchemes();
	s2 = f2.countDataSchemes();
	if (s1 != s2) {
		return false;
	}
	for (int i = 0; i < s1; i++) {
		if (!f2.hasDataScheme(f1.getDataScheme(i))) {
			return false;
		}
	}
	s1 = f1.countDataAuthorities();
	s2 = f2.countDataAuthorities();
	if (s1 != s2) {
		return false;
	}
	s1 = f1.countDataPaths();
	s2 = f2.countDataPaths();
	if (s1 != s2) {
		return false;
	}
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
		s1 = f1.countDataSchemeSpecificParts();
		s2 = f2.countDataSchemeSpecificParts();
		if (s1 != s2) {
			return false;
		}
	}
	return true;
}
 
Example 7
Source File: MediaRouter.java    From cwac-mediarouter with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the route supports the specified
 * {@link MediaControlIntent media control} category and action.
 * <p>
 * Media control actions describe specific requests that an application
 * can ask a route to perform.
 * </p>
 *
 * @param category A {@link MediaControlIntent media control} category
 * such as {@link MediaControlIntent#CATEGORY_LIVE_AUDIO},
 * {@link MediaControlIntent#CATEGORY_LIVE_VIDEO},
 * {@link MediaControlIntent#CATEGORY_REMOTE_PLAYBACK}, or a provider-defined
 * media control category.
 * @param action A {@link MediaControlIntent media control} action
 * such as {@link MediaControlIntent#ACTION_PLAY}.
 * @return True if the route supports the specified intent action.
 *
 * @see MediaControlIntent
 * @see #getControlFilters
 */
public boolean supportsControlAction(@NonNull String category, @NonNull String action) {
    if (category == null) {
        throw new IllegalArgumentException("category must not be null");
    }
    if (action == null) {
        throw new IllegalArgumentException("action must not be null");
    }
    checkCallingThread();

    int count = mControlFilters.size();
    for (int i = 0; i < count; i++) {
        IntentFilter filter = mControlFilters.get(i);
        if (filter.hasCategory(category) && filter.hasAction(action)) {
            return true;
        }
    }
    return false;
}