Target API 28
Apps targeting API 28 by default do not grant permission for cleartext traffic, so update the demo app to show a warning if loading an HTTP URI will fail. See https://developer.android.com/about/versions/pie/android-9.0-changes-28 for information on behavior changes in API 28. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=208204937
This commit is contained in:
parent
bac597cb07
commit
5f75d6ea13
@ -5,6 +5,7 @@
|
|||||||
* Add a flag to opt-in to automatic audio focus handling via
|
* Add a flag to opt-in to automatic audio focus handling via
|
||||||
`SimpleExoPlayer.setAudioAttributes`.
|
`SimpleExoPlayer.setAudioAttributes`.
|
||||||
* Distribute Cronet extension via jCenter.
|
* Distribute Cronet extension via jCenter.
|
||||||
|
* Set compileSdkVersion and targetSdkVersion to 28.
|
||||||
* Add `AudioListener` for listening to changes in audio configuration during
|
* Add `AudioListener` for listening to changes in audio configuration during
|
||||||
playback ([#3994](https://github.com/google/ExoPlayer/issues/3994)).
|
playback ([#3994](https://github.com/google/ExoPlayer/issues/3994)).
|
||||||
* Improved seeking support:
|
* Improved seeking support:
|
||||||
|
@ -20,9 +20,9 @@ project.ext {
|
|||||||
// However, please note that the core media playback functionality provided
|
// However, please note that the core media playback functionality provided
|
||||||
// by the library requires API level 16 or greater.
|
// by the library requires API level 16 or greater.
|
||||||
minSdkVersion = 14
|
minSdkVersion = 14
|
||||||
targetSdkVersion = 27
|
targetSdkVersion = 28
|
||||||
compileSdkVersion = 27
|
compileSdkVersion = 28
|
||||||
buildToolsVersion = '27.0.3'
|
buildToolsVersion = '28.0.2'
|
||||||
testSupportLibraryVersion = '0.5'
|
testSupportLibraryVersion = '0.5'
|
||||||
supportLibraryVersion = '27.1.1'
|
supportLibraryVersion = '27.1.1'
|
||||||
dexmakerVersion = '1.2'
|
dexmakerVersion = '1.2'
|
||||||
|
@ -360,7 +360,11 @@ public class PlayerActivity extends Activity
|
|||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Util.maybeRequestReadExternalStoragePermission(this, uris)) {
|
if (!Util.checkCleartextTrafficPermitted(uris)) {
|
||||||
|
showToast(R.string.error_cleartext_not_permitted);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Util.maybeRequestReadExternalStoragePermission(/* activity= */ this, uris)) {
|
||||||
// The player will be reinitialized if the permission is granted.
|
// The player will be reinitialized if the permission is granted.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
<string name="unexpected_intent_action">Unexpected intent action: <xliff:g id="action">%1$s</xliff:g></string>
|
<string name="unexpected_intent_action">Unexpected intent action: <xliff:g id="action">%1$s</xliff:g></string>
|
||||||
|
|
||||||
|
<string name="error_cleartext_not_permitted">Cleartext traffic not permitted</string>
|
||||||
|
|
||||||
<string name="error_generic">Playback failed</string>
|
<string name="error_generic">Playback failed</string>
|
||||||
|
|
||||||
<string name="error_unrecognized_abr_algorithm">Unrecognized ABR algorithm</string>
|
<string name="error_unrecognized_abr_algorithm">Unrecognized ABR algorithm</string>
|
||||||
|
@ -33,6 +33,7 @@ import android.os.Build;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
import android.security.NetworkSecurityPolicy;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
@ -184,6 +185,29 @@ public final class Util {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether it may be possible to load the given URIs based on the network security
|
||||||
|
* policy's cleartext traffic permissions.
|
||||||
|
*
|
||||||
|
* @param uris A list of URIs that will be loaded.
|
||||||
|
* @return Whether it may be possible to load the given URIs.
|
||||||
|
*/
|
||||||
|
@TargetApi(24)
|
||||||
|
public static boolean checkCleartextTrafficPermitted(Uri... uris) {
|
||||||
|
if (Util.SDK_INT < 24) {
|
||||||
|
// We assume cleartext traffic is permitted.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (Uri uri : uris) {
|
||||||
|
if ("http".equals(uri.getScheme())
|
||||||
|
&& !NetworkSecurityPolicy.getInstance().isCleartextTrafficPermitted(uri.getHost())) {
|
||||||
|
// The security policy prevents cleartext traffic.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the URI is a path to a local file or a reference to a local file.
|
* Returns true if the URI is a path to a local file or a reference to a local file.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user