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
f415ea23
authored
May 07, 2021
by
aquilescanta
Committed by
Andrew Lewis
May 10, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Make PlaybackException's Bundleable implementation subclass friendly
PiperOrigin-RevId: 372552003
parent
1a6984fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
40 deletions
library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java
library/common/src/main/java/com/google/android/exoplayer2/PlaybackException.java
View file @
f415ea23
...
@@ -192,7 +192,20 @@ public class PlaybackException extends Exception implements Bundleable {
...
@@ -192,7 +192,20 @@ public class PlaybackException extends Exception implements Bundleable {
this
(
message
,
cause
,
errorCode
,
Clock
.
DEFAULT
.
elapsedRealtime
());
this
(
message
,
cause
,
errorCode
,
Clock
.
DEFAULT
.
elapsedRealtime
());
}
}
private
PlaybackException
(
/** Creates a new instance using the fields obtained from the given {@link Bundle}. */
protected
PlaybackException
(
Bundle
bundle
)
{
this
(
/* message= */
bundle
.
getString
(
keyForField
(
FIELD_STRING_MESSAGE
)),
/* cause= */
getCauseFromBundle
(
bundle
),
/* errorCode= */
bundle
.
getInt
(
keyForField
(
FIELD_INT_ERROR_CODE
),
/* defaultValue= */
ERROR_CODE_UNSPECIFIED
),
/* timestampMs= */
bundle
.
getLong
(
keyForField
(
FIELD_LONG_TIMESTAMP_MS
),
/* defaultValue= */
SystemClock
.
elapsedRealtime
()));
}
/** Creates a new instance using the given values. */
protected
PlaybackException
(
@Nullable
String
message
,
@Nullable
String
message
,
@Nullable
Throwable
cause
,
@Nullable
Throwable
cause
,
@ErrorCode
int
errorCode
,
@ErrorCode
int
errorCode
,
...
@@ -227,9 +240,6 @@ public class PlaybackException extends Exception implements Bundleable {
...
@@ -227,9 +240,6 @@ public class PlaybackException extends Exception implements Bundleable {
private
static
final
int
FIELD_STRING_CAUSE_CLASS_NAME
=
3
;
private
static
final
int
FIELD_STRING_CAUSE_CLASS_NAME
=
3
;
private
static
final
int
FIELD_STRING_CAUSE_MESSAGE
=
4
;
private
static
final
int
FIELD_STRING_CAUSE_MESSAGE
=
4
;
/** Object that can restore {@link PlaybackException} from a {@link Bundle}. */
public
static
final
Creator
<
PlaybackException
>
CREATOR
=
PlaybackException:
:
fromBundle
;
/**
/**
* Defines a minimum field id value for subclasses to use when implementing {@link #toBundle()}
* Defines a minimum field id value for subclasses to use when implementing {@link #toBundle()}
* and {@link Bundleable.Creator}.
* and {@link Bundleable.Creator}.
...
@@ -239,6 +249,9 @@ public class PlaybackException extends Exception implements Bundleable {
...
@@ -239,6 +249,9 @@ public class PlaybackException extends Exception implements Bundleable {
*/
*/
protected
static
final
int
FIELD_CUSTOM_ID_BASE
=
1000
;
protected
static
final
int
FIELD_CUSTOM_ID_BASE
=
1000
;
/** Object that can create a {@link PlaybackException} from a {@link Bundle}. */
public
static
final
Creator
<
PlaybackException
>
CREATOR
=
PlaybackException:
:
new
;
@CallSuper
@CallSuper
@Override
@Override
public
Bundle
toBundle
()
{
public
Bundle
toBundle
()
{
...
@@ -255,21 +268,28 @@ public class PlaybackException extends Exception implements Bundleable {
...
@@ -255,21 +268,28 @@ public class PlaybackException extends Exception implements Bundleable {
}
}
/**
/**
* Creates and returns a new instance using the field data in the given {@link Bundle}.
* Converts the given {@link FieldNumber} to a string which can be used as a field key when
*
* implementing {@link #toBundle()} and {@link Bundleable.Creator}.
* @param bundle The {@link Bundle} from which to obtain the returned instance's contents.
* @return The created instance.
*/
*/
protected
static
PlaybackException
fromBundle
(
Bundle
bundle
)
{
protected
static
String
keyForField
(
@FieldNumber
int
field
)
{
@ErrorCode
return
Integer
.
toString
(
field
,
Character
.
MAX_RADIX
);
int
errorCode
=
}
bundle
.
getInt
(
keyForField
(
FIELD_INT_ERROR_CODE
),
/* defaultValue= */
ERROR_CODE_UNSPECIFIED
);
// Creates a new {@link Throwable} with possibly {@code null} message.
long
timestampMs
=
@SuppressWarnings
(
"nullness:argument.type.incompatible"
)
bundle
.
getLong
(
private
static
Throwable
createThrowable
(
Class
<?>
clazz
,
@Nullable
String
message
)
keyForField
(
FIELD_LONG_TIMESTAMP_MS
),
throws
Exception
{
/* defaultValue= */
SystemClock
.
elapsedRealtime
());
return
(
Throwable
)
clazz
.
getConstructor
(
String
.
class
).
newInstance
(
message
);
@Nullable
String
message
=
bundle
.
getString
(
keyForField
(
FIELD_STRING_MESSAGE
));
}
// Creates a new {@link RemoteException} with possibly {@code null} message.
@SuppressWarnings
(
"nullness:argument.type.incompatible"
)
private
static
RemoteException
createRemoteException
(
@Nullable
String
message
)
{
return
new
RemoteException
(
message
);
}
@Nullable
private
static
Throwable
getCauseFromBundle
(
Bundle
bundle
)
{
@Nullable
String
causeClassName
=
bundle
.
getString
(
keyForField
(
FIELD_STRING_CAUSE_CLASS_NAME
));
@Nullable
String
causeClassName
=
bundle
.
getString
(
keyForField
(
FIELD_STRING_CAUSE_CLASS_NAME
));
@Nullable
String
causeMessage
=
bundle
.
getString
(
keyForField
(
FIELD_STRING_CAUSE_MESSAGE
));
@Nullable
String
causeMessage
=
bundle
.
getString
(
keyForField
(
FIELD_STRING_CAUSE_MESSAGE
));
@Nullable
Throwable
cause
=
null
;
@Nullable
Throwable
cause
=
null
;
...
@@ -292,27 +312,6 @@ public class PlaybackException extends Exception implements Bundleable {
...
@@ -292,27 +312,6 @@ public class PlaybackException extends Exception implements Bundleable {
}
}
}
}
}
}
return
new
PlaybackException
(
message
,
cause
,
errorCode
,
timestampMs
);
return
cause
;
}
/**
* Converts the given {@link FieldNumber} to a string which can be used as a field key when
* implementing {@link #toBundle()} and {@link Bundleable.Creator}.
*/
protected
static
String
keyForField
(
@FieldNumber
int
field
)
{
return
Integer
.
toString
(
field
,
Character
.
MAX_RADIX
);
}
// Creates a new {@link Throwable} with possibly {@code null} message.
@SuppressWarnings
(
"nullness:argument.type.incompatible"
)
private
static
Throwable
createThrowable
(
Class
<?>
clazz
,
@Nullable
String
message
)
throws
Exception
{
return
(
Throwable
)
clazz
.
getConstructor
(
String
.
class
).
newInstance
(
message
);
}
// Creates a new {@link RemoteException} with possibly {@code null} message.
@SuppressWarnings
(
"nullness:argument.type.incompatible"
)
private
static
RemoteException
createRemoteException
(
@Nullable
String
message
)
{
return
new
RemoteException
(
message
);
}
}
}
}
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