/** @return the URL converted to string, or null if it's invalid. */ private static String checkAndConvertUri(Uri uri) { if (uri == null) return null; // Don't do anything for unknown schemes. Not having a scheme is allowed, as we allow // "www.example.com". String scheme = uri.normalizeScheme().getScheme(); boolean allowedScheme = scheme == null || scheme.equals("http") || scheme.equals("https"); if (!allowedScheme) return null; return uri.toString(); }
if (uri == null) throw new NullPointerException("uri is null"); uri = uri.normalizeScheme(); String uriString = uri.toString(); if (uriString.length() == 0) throw new IllegalArgumentException("uri is empty");
private Uri toUri(boolean inSmartPoster) { switch (mTnf) { case TNF_WELL_KNOWN: if (Arrays.equals(mType, RTD_SMART_POSTER) && !inSmartPoster) { try { // check payload for a nested NDEF Message containing a URI NdefMessage nestedMessage = new NdefMessage(mPayload); for (NdefRecord nestedRecord : nestedMessage.getRecords()) { Uri uri = nestedRecord.toUri(true); if (uri != null) { return uri; } } } catch (FormatException e) { } } else if (Arrays.equals(mType, RTD_URI)) { Uri wktUri = parseWktUri(); return (wktUri != null ? wktUri.normalizeScheme() : null); } break; case TNF_ABSOLUTE_URI: Uri uri = Uri.parse(new String(mType, Charset.forName("utf-8"))); return uri.normalizeScheme(); case TNF_EXTERNAL_TYPE: if (inSmartPoster) { break; } return Uri.parse("vnd.android.nfc://ext/" + new String(mType, Charset.forName("US-ASCII"))); } return null; }
String scheme = uri.normalizeScheme().getScheme(); if (!"http".equals(scheme) && !"https".equals(scheme)) return false; String path = uri.getPath();
@Override public List<Channel> getChannels() { Assert.assertNotNull("Please set the static mContext before running", mContext); // Wrap our list in an ArrayList so we will be able to make modifications if necessary Assert.assertNotNull("Set TestJobService.mContext.", mContext); InternalProviderData internalProviderData = new InternalProviderData(); internalProviderData.setRepeatable(true); ArrayList<Channel> testChannels = new ArrayList<>(); testChannels.add(new Channel.Builder() .setOriginalNetworkId(0) .setDisplayName("Test Channel") .setDisplayNumber("1") .setInternalProviderData(internalProviderData) .build()); // Add an XML parsed channel Uri xmlUri = Uri.parse("android.resource://" + mContext.getPackageName() + "/" + com.google.android.media.tv.companionlibrary.test.R.raw.xmltv) .normalizeScheme(); try { InputStream inputStream = mContext.getContentResolver() .openInputStream(xmlUri); Assert.assertNotNull(inputStream); testChannels.addAll(XmlTvParser.parse(inputStream).getChannels()); } catch (FileNotFoundException | XmlTvParser.XmlTvParseException e) { throw new RuntimeException("Exception found of type " + e.getClass().getCanonicalName() + ": " + e.getMessage()); } return testChannels; }
.normalizeScheme(); try { InputStream inputStream = mContext.getContentResolver()