summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2014-03-27 13:25:14 -0700
committerMarco Nelissen <marcone@google.com>2014-03-27 13:25:14 -0700
commit1632fae376eb460cf992e543b13c8690b71fe8d5 (patch)
tree941cd97ff6a694fa11d3e9832e9853769b5cdc69 /media
parentbc9a5a0fb71f505dc66a8a7d676d69dd8448466d (diff)
downloadframeworks_base-1632fae376eb460cf992e543b13c8690b71fe8d5.zip
frameworks_base-1632fae376eb460cf992e543b13c8690b71fe8d5.tar.gz
frameworks_base-1632fae376eb460cf992e543b13c8690b71fe8d5.tar.bz2
Make setServer() safe to call multiple times
This makes it safe to call setServer() multiple times with the same server, different servers, or null. b/13622801 Change-Id: Id04440df720f830e67106eb543653ace42430d97
Diffstat (limited to 'media')
-rwxr-xr-xmedia/java/android/mtp/MtpDatabase.java9
1 files changed, 7 insertions, 2 deletions
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index 15ae238..fce3fd0 100755
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -202,12 +202,17 @@ public class MtpDatabase {
public void setServer(MtpServer server) {
mServer = server;
+ // always unregister before registering
+ try {
+ mContext.unregisterReceiver(mBatteryReceiver);
+ } catch (IllegalArgumentException e) {
+ // wasn't previously registered, ignore
+ }
+
// register for battery notifications when we are connected
if (server != null) {
mContext.registerReceiver(mBatteryReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
- } else {
- mContext.unregisterReceiver(mBatteryReceiver);
}
}