YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.share.SharedContentPolicy Class Reference

Decides which shared local content may be registered for serving. More...

Collaboration diagram for de.yaacc.share.SharedContentPolicy:
Collaboration graph

Static Public Member Functions

static boolean isAcceptableUri (String uriString, String ownAuthority)
 Accepts a URI only if all of these hold: not null, at most MAX_URI_LENGTH chars, only printable ASCII (no whitespace, no control characters, no non-ASCII), scheme content (ASCII case-insensitive) followed by //, a non-empty authority (up to the next /, ? or #) without @ (Android user id prefix) and without % (Android decodes authorities), and an authority that is not ownAuthority (ASCII case-insensitive).
 
static String authorityOf (String uriString)
 The authority of a URI text that is well-formed in the sense of isAcceptableUri (the own-authority rule aside), for the checks that need the Android package manager (does a provider of this app own it?).
 
static boolean isAcceptableMimeType (String mime)
 Accepts only concrete audio, video and image types: audio/<subtype>, video/<subtype>, image/<subtype> (type ASCII case-insensitive), the subtype a non-empty token of letters, digits and . + - _ ! # $ & ^ that starts with a letter or digit.
 
static long maxCopyBytes ()
 The cap for the copy fallback in bytes, see MAX_COPY_BYTES.
 
static boolean isWithinCopyLimit (long sizeBytes)
 
static String chooseMimeType (String providerType, String intentType)
 Picks the MIME type of a shared file.
 

Static Public Attributes

static final int MAX_URI_LENGTH = 2048
 Longer URI texts are dropped, not truncated.
 
static final int MAX_MIME_LENGTH = 255
 Longest MIME type text that is looked at.
 
static final long MAX_COPY_BYTES = 512L * 1024L * 1024L
 Cap for the copy fallback (provider descriptor is not seekable): 512 MiB.
 

Detailed Description

Decides which shared local content may be registered for serving.

Plain Java so it can be unit tested on the JVM; http/https text links stay with de.yaacc.browser.ShareUriPolicy.

The input comes from another app and is untrusted. Only content:// URIs of OTHER apps are accepted: a file: URI or a URI of yaacc's own file provider would let any app make yaacc read and serve its private data. Checks are on the text, ASCII only, nothing is trimmed or decoded, so what is checked is what Android would use.

Member Function Documentation

◆ authorityOf()

static String de.yaacc.share.SharedContentPolicy.authorityOf ( String uriString)
static

The authority of a URI text that is well-formed in the sense of isAcceptableUri (the own-authority rule aside), for the checks that need the Android package manager (does a provider of this app own it?).

Returns
the authority as written (not lower-cased), or null if the text is not acceptable

Referenced by de.yaacc.share.ContentDuration.read(), and de.yaacc.share.StreamIntake.validate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ chooseMimeType()

static String de.yaacc.share.SharedContentPolicy.chooseMimeType ( String providerType,
String intentType )
static

Picks the MIME type of a shared file.

The provider's answer (ContentResolver.getType, untrusted but about the actual content) wins; the type declared on the intent is only a fallback:

  1. providerType if isAcceptableMimeType(String) accepts it;
  2. else intentType if it is accepted too (so a wildcard such as audio/*, */* or a non-media type never wins);
  3. else null (reject the share).

The result is the lower-case canonical form (ASCII, Locale.ROOT) of the chosen input, so callers compare and store one spelling. Nothing is trimmed or stripped: a type with whitespace or parameters is not accepted (see isAcceptableMimeType(String)), and the provider type application/octet-stream falls through to the intent type. Never throws; null and empty inputs count as "not acceptable".

Returns
the chosen type in lower case, or null if neither input is acceptable
Here is the call graph for this function:

◆ isAcceptableMimeType()

static boolean de.yaacc.share.SharedContentPolicy.isAcceptableMimeType ( String mime)
static

Accepts only concrete audio, video and image types: audio/<subtype>, video/<subtype>, image/<subtype> (type ASCII case-insensitive), the subtype a non-empty token of letters, digits and . + - _ ! # $ & ^ that starts with a letter or digit.

Wildcards, parameters (; charset=...), whitespace, a missing subtype, null, empty and over-long texts are rejected.

Referenced by de.yaacc.share.SharedContentPolicy.chooseMimeType(), and de.yaacc.share.LinkContentType.concreteMediaType().

Here is the caller graph for this function:

◆ isAcceptableUri()

static boolean de.yaacc.share.SharedContentPolicy.isAcceptableUri ( String uriString,
String ownAuthority )
static

Accepts a URI only if all of these hold: not null, at most MAX_URI_LENGTH chars, only printable ASCII (no whitespace, no control characters, no non-ASCII), scheme content (ASCII case-insensitive) followed by //, a non-empty authority (up to the next /, ? or #) without @ (Android user id prefix) and without % (Android decodes authorities), and an authority that is not ownAuthority (ASCII case-insensitive).

Parameters
uriStringthe URI text from the sending app, may be null
ownAuthoritythe authority of yaacc's own file provider; null or empty means the caller has a bug and nothing is accepted

Referenced by de.yaacc.share.SharedContentPolicy.authorityOf(), de.yaacc.browser.LauncherForwardPolicy.decideStream(), de.yaacc.browser.LauncherForwardPolicy.rejectionReason(), and de.yaacc.share.StreamIntake.validate().

Here is the caller graph for this function:

◆ isWithinCopyLimit()

static boolean de.yaacc.share.SharedContentPolicy.isWithinCopyLimit ( long sizeBytes)
static
Parameters
sizeBytesthe number of bytes read or announced, negative for unknown
Returns
true if 0 <= size <= MAX_COPY_BYTES; unknown sizes are not accepted

The documentation for this class was generated from the following file: