Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VLC-Android
Manage
Activity
Members
Labels
Plan
Issues
531
Issue boards
Milestones
Wiki
Code
Merge requests
14
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VideoLAN
VLC-Android
Commits
8fa95d2d
Commit
8fa95d2d
authored
7 years ago
by
Geoffrey Métais
Browse files
Options
Downloads
Patches
Plain Diff
Improve ext storages management
(cherry picked from commit
b41e68f8
)
parent
535abe2c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
vlc-android/src/org/videolan/vlc/ExternalMonitor.java
+33
-21
33 additions, 21 deletions
vlc-android/src/org/videolan/vlc/ExternalMonitor.java
with
33 additions
and
21 deletions
vlc-android/src/org/videolan/vlc/ExternalMonitor.java
+
33
−
21
View file @
8fa95d2d
...
...
@@ -55,9 +55,6 @@ import java.util.Enumeration;
import
java.util.LinkedList
;
import
java.util.List
;
import
static
org
.
videolan
.
vlc
.
MediaParsingService
.
ACTION_NEW_STORAGE
;
import
static
org
.
videolan
.
vlc
.
MediaParsingService
.
EXTRA_PATH
;
public
class
ExternalMonitor
extends
BroadcastReceiver
{
public
final
static
String
TAG
=
"VLC/ExternalMonitor"
;
private
static
volatile
boolean
connected
=
true
;
...
...
@@ -93,28 +90,31 @@ public class ExternalMonitor extends BroadcastReceiver {
public
void
run
()
{
final
SharedPreferences
sharedPreferences
=
PreferenceManager
.
getDefaultSharedPreferences
(
ctx
);
final
List
<
String
>
devices
=
AndroidDevices
.
getExternalStorageDirectories
();
if
(
Util
.
isListEmpty
(
devices
))
return
;
final
String
[]
knownDevices
=
ml
.
getDevices
();
final
List
<
String
>
missingDevices
=
Util
.
arrayToArrayList
(
knownDevices
);
missingDevices
.
remove
(
"file://"
+
AndroidDevices
.
EXTERNAL_PUBLIC_DIRECTORY
);
boolean
refresh
=
false
;
for
(
final
String
device
:
devices
)
{
final
String
uuid
=
FileUtils
.
getFileNameFromPath
(
device
);
if
(
TextUtils
.
isEmpty
(
device
)
||
TextUtils
.
isEmpty
(
uuid
)
||
containsDevice
(
knownDevices
,
device
))
if
(
TextUtils
.
isEmpty
(
device
)
||
TextUtils
.
isEmpty
(
uuid
))
continue
;
if
(
containsDevice
(
knownDevices
,
device
))
{
missingDevices
.
remove
(
"file://"
+
device
);
continue
;
}
final
boolean
isNew
=
ml
.
addDevice
(
uuid
,
device
,
true
);
final
boolean
isIgnored
=
sharedPreferences
.
getBoolean
(
"ignore_"
+
uuid
,
false
);
if
(
isNew
&&
!
isIgnored
)
LocalBroadcastManager
.
getInstance
(
ctx
).
sendBroadcast
(
new
Intent
(
ACTION_NEW_STORAGE
).
putExtra
(
EXTRA_PATH
,
device
));
if
(!
isIgnored
)
{
if
(
isNew
)
LocalBroadcastManager
.
getInstance
(
ctx
).
sendBroadcast
(
new
Intent
(
MediaParsingService
.
ACTION_NEW_STORAGE
).
putExtra
(
MediaParsingService
.
EXTRA_PATH
,
device
));
else
refresh
=
true
;
}
}
}
private
boolean
containsDevice
(
String
[]
devices
,
String
device
)
{
if
(
Util
.
isArrayEmpty
(
devices
))
return
false
;
for
(
String
dev
:
devices
)
if
(
device
.
startsWith
(
Strings
.
removeFileProtocole
(
dev
)))
return
true
;
return
false
;
for
(
String
device
:
missingDevices
)
ml
.
removeDevice
(
FileUtils
.
getFileNameFromPath
(
device
));
if
(
refresh
||
!
missingDevices
.
isEmpty
())
LocalBroadcastManager
.
getInstance
(
ctx
).
sendBroadcast
(
new
Intent
(
MediaParsingService
.
ACTION_SERVICE_ENDED
));
}
});
}
...
...
@@ -172,10 +172,13 @@ public class ExternalMonitor extends BroadcastReceiver {
removeMessages
(
ACTION_MEDIA_UNMOUNTED
);
if
(!
TextUtils
.
isEmpty
(
uuid
)
&&
!
PreferenceManager
.
getDefaultSharedPreferences
(
appCtx
).
getBoolean
(
"ignore_"
+
uuid
,
false
))
{
if
(
VLCApplication
.
getMLInstance
().
addDevice
(
uuid
,
path
,
true
))
{
final
Medialibrary
ml
=
VLCApplication
.
getMLInstance
();
final
String
[]
knownDevices
=
ml
.
getDevices
();
if
(!
containsDevice
(
knownDevices
,
path
)
&&
ml
.
addDevice
(
uuid
,
path
,
true
))
{
notifyStorageChanges
(
path
);
}
else
}
else
{
LocalBroadcastManager
.
getInstance
(
appCtx
).
sendBroadcast
(
new
Intent
(
MediaParsingService
.
ACTION_SERVICE_ENDED
));
}
}
break
;
case
ACTION_MEDIA_UNMOUNTED:
...
...
@@ -191,7 +194,7 @@ public class ExternalMonitor extends BroadcastReceiver {
obs
.
onNetworkConnectionChanged
(
connected
);
}
private
synchronized
void
notifyStorageChanges
(
String
path
)
{
private
static
synchronized
void
notifyStorageChanges
(
String
path
)
{
final
Activity
activity
=
storageObserver
!=
null
?
storageObserver
.
get
()
:
null
;
if
(
activity
!=
null
)
UiTools
.
newStorageDetected
(
activity
,
path
);
...
...
@@ -257,4 +260,13 @@ public class ExternalMonitor extends BroadcastReceiver {
return
false
;
}
}
private
static
boolean
containsDevice
(
String
[]
devices
,
String
device
)
{
if
(
Util
.
isArrayEmpty
(
devices
))
return
false
;
for
(
String
dev
:
devices
)
if
(
device
.
startsWith
(
Strings
.
removeFileProtocole
(
dev
)))
return
true
;
return
false
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment