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
28dca0b3
authored
Dec 14, 2018
by
eguven
Committed by
Oliver Woodman
Dec 18, 2018
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add method to Requirements to get not met requirements
PiperOrigin-RevId: 225549778
parent
1a3d735b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
14 deletions
extensions/jobdispatcher/src/main/java/com/google/android/exoplayer2/ext/jobdispatcher/JobDispatcherScheduler.java
library/core/src/main/java/com/google/android/exoplayer2/scheduler/PlatformScheduler.java
library/core/src/main/java/com/google/android/exoplayer2/scheduler/Requirements.java
extensions/jobdispatcher/src/main/java/com/google/android/exoplayer2/ext/jobdispatcher/JobDispatcherScheduler.java
View file @
28dca0b3
...
...
@@ -129,7 +129,7 @@ public final class JobDispatcherScheduler implements Scheduler {
Bundle
extras
=
new
Bundle
();
extras
.
putString
(
KEY_SERVICE_ACTION
,
serviceAction
);
extras
.
putString
(
KEY_SERVICE_PACKAGE
,
servicePackage
);
extras
.
putInt
(
KEY_REQUIREMENTS
,
requirements
.
getRequirements
Data
());
extras
.
putInt
(
KEY_REQUIREMENTS
,
requirements
.
getRequirements
());
builder
.
setExtras
(
extras
);
return
builder
.
build
();
...
...
library/core/src/main/java/com/google/android/exoplayer2/scheduler/PlatformScheduler.java
View file @
28dca0b3
...
...
@@ -130,7 +130,7 @@ public final class PlatformScheduler implements Scheduler {
PersistableBundle
extras
=
new
PersistableBundle
();
extras
.
putString
(
KEY_SERVICE_ACTION
,
serviceAction
);
extras
.
putString
(
KEY_SERVICE_PACKAGE
,
servicePackage
);
extras
.
putInt
(
KEY_REQUIREMENTS
,
requirements
.
getRequirements
Data
());
extras
.
putInt
(
KEY_REQUIREMENTS
,
requirements
.
getRequirements
());
builder
.
setExtras
(
extras
);
return
builder
.
build
();
...
...
library/core/src/main/java/com/google/android/exoplayer2/scheduler/Requirements.java
View file @
28dca0b3
...
...
@@ -25,6 +25,7 @@ import android.net.NetworkInfo;
import
android.os.BatteryManager
;
import
android.os.PowerManager
;
import
android.support.annotation.IntDef
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Util
;
import
java.lang.annotation.Documented
;
...
...
@@ -50,22 +51,49 @@ public final class Requirements {
NETWORK_TYPE_METERED
,
})
public
@interface
NetworkType
{}
/**
* Requirement flags.
*
* <p>Combination of the following values is possible:
*
* <ul>
* <li>Only one of {@link #NETWORK_TYPE_ANY}, {@link #NETWORK_TYPE_UNMETERED}, {@link
* #NETWORK_TYPE_NOT_ROAMING} or {@link #NETWORK_TYPE_METERED}.
* <li>{@link #DEVICE_IDLE}
* <li>{@link #DEVICE_CHARGING}
* <ul>
*/
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
(
flag
=
true
,
value
=
{
NETWORK_TYPE_ANY
,
NETWORK_TYPE_UNMETERED
,
NETWORK_TYPE_NOT_ROAMING
,
NETWORK_TYPE_METERED
,
DEVICE_IDLE
,
DEVICE_CHARGING
})
public
@interface
RequirementFlags
{}
/** This job doesn't require network connectivity. */
public
static
final
int
NETWORK_TYPE_NONE
=
0
;
/** This job requires network connectivity. */
public
static
final
int
NETWORK_TYPE_ANY
=
1
;
/** This job requires network connectivity that is unmetered. */
public
static
final
int
NETWORK_TYPE_UNMETERED
=
2
;
public
static
final
int
NETWORK_TYPE_UNMETERED
=
1
<<
1
;
/** This job requires network connectivity that is not roaming. */
public
static
final
int
NETWORK_TYPE_NOT_ROAMING
=
3
;
public
static
final
int
NETWORK_TYPE_NOT_ROAMING
=
1
<<
2
;
/** This job requires metered connectivity such as most cellular data networks. */
public
static
final
int
NETWORK_TYPE_METERED
=
4
;
public
static
final
int
NETWORK_TYPE_METERED
=
1
<<
3
;
/** This job requires the device to be idle. */
p
rivate
static
final
int
DEVICE_IDLE
=
8
;
p
ublic
static
final
int
DEVICE_IDLE
=
1
<<
4
;
/** This job requires the device to be charging. */
p
rivate
static
final
int
DEVICE_CHARGING
=
16
;
p
ublic
static
final
int
DEVICE_CHARGING
=
1
<<
5
;
private
static
final
int
NETWORK_TYPE_MASK
=
7
;
private
static
final
int
NETWORK_TYPE_MASK
=
0b1111
;
private
static
final
String
TAG
=
"Requirements"
;
...
...
@@ -86,7 +114,7 @@ public final class Requirements {
}
}
private
final
int
requirements
;
@RequirementFlags
private
final
int
requirements
;
/**
* @param networkType Required network type.
...
...
@@ -97,9 +125,12 @@ public final class Requirements {
this
(
networkType
|
(
charging
?
DEVICE_CHARGING
:
0
)
|
(
idle
?
DEVICE_IDLE
:
0
));
}
/** @param requirementsData The value returned by {@link #getRequirementsData()}. */
public
Requirements
(
int
requirementsData
)
{
this
.
requirements
=
requirementsData
;
/** @param requirements A combination of requirement flags. */
public
Requirements
(
@RequirementFlags
int
requirements
)
{
this
.
requirements
=
requirements
;
int
networkType
=
getRequiredNetworkType
();
// Check if only one network type is specified.
Assertions
.
checkState
((
networkType
&
(
networkType
-
1
))
==
0
);
}
/** Returns required network type. */
...
...
@@ -121,6 +152,7 @@ public final class Requirements {
* Returns whether the requirements are met.
*
* @param context Any context.
* @return Whether the requirements are met.
*/
public
boolean
checkRequirements
(
Context
context
)
{
return
checkNetworkRequirements
(
context
)
...
...
@@ -128,8 +160,22 @@ public final class Requirements {
&&
checkIdleRequirement
(
context
);
}
/** Returns the encoded requirements data which can be used with {@link #Requirements(int)}. */
public
int
getRequirementsData
()
{
/**
* Returns the requirement flags that are not met, or 0.
*
* @param context Any context.
* @return The requirement flags that are not met, or 0.
*/
@RequirementFlags
public
int
getNotMetRequirements
(
Context
context
)
{
return
(!
checkNetworkRequirements
(
context
)
?
getRequiredNetworkType
()
:
0
)
|
(!
checkChargingRequirement
(
context
)
?
DEVICE_CHARGING
:
0
)
|
(!
checkIdleRequirement
(
context
)
?
DEVICE_IDLE
:
0
);
}
/** Returns the requirement flags. */
@RequirementFlags
public
int
getRequirements
()
{
return
requirements
;
}
...
...
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