Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9c5bc56d
authored
May 24, 2022
by
tonihei
Committed by
Marc Baechinger
May 26, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Wrap TelephonyCallback in nested class to avoid class loading issues.
PiperOrigin-RevId: 450643824
parent
ccd61b1c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
22 deletions
library/common/src/main/java/com/google/android/exoplayer2/util/NetworkTypeObserver.java
library/common/src/main/java/com/google/android/exoplayer2/util/NetworkTypeObserver.java
View file @
9c5bc56d
...
@@ -215,34 +215,49 @@ public final class NetworkTypeObserver {
...
@@ -215,34 +215,49 @@ public final class NetworkTypeObserver {
@C
.
NetworkType
int
networkType
=
getNetworkTypeFromConnectivityManager
(
context
);
@C
.
NetworkType
int
networkType
=
getNetworkTypeFromConnectivityManager
(
context
);
if
(
Util
.
SDK_INT
>=
31
&&
networkType
==
C
.
NETWORK_TYPE_4G
)
{
if
(
Util
.
SDK_INT
>=
31
&&
networkType
==
C
.
NETWORK_TYPE_4G
)
{
// Delay update of the network type to check whether this is actually 5G-NSA.
// Delay update of the network type to check whether this is actually 5G-NSA.
try
{
Api31
.
disambiguate4gAnd5gNsa
(
context
,
/* instance= */
NetworkTypeObserver
.
this
);
TelephonyManager
telephonyManager
=
}
else
{
checkNotNull
((
TelephonyManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
));
updateNetworkType
(
networkType
);
DisplayInfoCallback
callback
=
new
DisplayInfoCallback
();
telephonyManager
.
registerTelephonyCallback
(
context
.
getMainExecutor
(),
callback
);
// We are only interested in the initial response with the current state, so unregister
// the listener immediately.
telephonyManager
.
unregisterTelephonyCallback
(
callback
);
return
;
}
catch
(
RuntimeException
e
)
{
// Ignore problems with listener registration and keep reporting as 4G.
}
}
}
updateNetworkType
(
networkType
);
}
}
}
}
@RequiresApi
(
31
)
@RequiresApi
(
31
)
private
final
class
DisplayInfoCallback
extends
TelephonyCallback
implements
DisplayInfoListener
{
private
static
final
class
Api31
{
@Override
public
static
void
disambiguate4gAnd5gNsa
(
Context
context
,
NetworkTypeObserver
instance
)
{
public
void
onDisplayInfoChanged
(
TelephonyDisplayInfo
telephonyDisplayInfo
)
{
try
{
int
overrideNetworkType
=
telephonyDisplayInfo
.
getOverrideNetworkType
();
TelephonyManager
telephonyManager
=
boolean
is5gNsa
=
checkNotNull
((
TelephonyManager
)
context
.
getSystemService
(
Context
.
TELEPHONY_SERVICE
));
overrideNetworkType
==
TelephonyDisplayInfo
.
OVERRIDE_NETWORK_TYPE_NR_NSA
DisplayInfoCallback
callback
=
new
DisplayInfoCallback
(
instance
);
||
overrideNetworkType
==
TelephonyDisplayInfo
.
OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE
telephonyManager
.
registerTelephonyCallback
(
context
.
getMainExecutor
(),
callback
);
||
overrideNetworkType
==
TelephonyDisplayInfo
.
OVERRIDE_NETWORK_TYPE_NR_ADVANCED
;
// We are only interested in the initial response with the current state, so unregister
updateNetworkType
(
is5gNsa
?
C
.
NETWORK_TYPE_5G_NSA
:
C
.
NETWORK_TYPE_4G
);
// the listener immediately.
telephonyManager
.
unregisterTelephonyCallback
(
callback
);
}
catch
(
RuntimeException
e
)
{
// Ignore problems with listener registration and keep reporting as 4G.
instance
.
updateNetworkType
(
C
.
NETWORK_TYPE_4G
);
}
}
private
static
final
class
DisplayInfoCallback
extends
TelephonyCallback
implements
DisplayInfoListener
{
private
final
NetworkTypeObserver
instance
;
public
DisplayInfoCallback
(
NetworkTypeObserver
instance
)
{
this
.
instance
=
instance
;
}
@Override
public
void
onDisplayInfoChanged
(
TelephonyDisplayInfo
telephonyDisplayInfo
)
{
int
overrideNetworkType
=
telephonyDisplayInfo
.
getOverrideNetworkType
();
boolean
is5gNsa
=
overrideNetworkType
==
TelephonyDisplayInfo
.
OVERRIDE_NETWORK_TYPE_NR_NSA
||
overrideNetworkType
==
TelephonyDisplayInfo
.
OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE
||
overrideNetworkType
==
TelephonyDisplayInfo
.
OVERRIDE_NETWORK_TYPE_NR_ADVANCED
;
instance
.
updateNetworkType
(
is5gNsa
?
C
.
NETWORK_TYPE_5G_NSA
:
C
.
NETWORK_TYPE_4G
);
}
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment