diff options
author | Marco Nelissen <marcone@google.com> | 2014-03-27 13:25:14 -0700 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2014-03-27 13:25:14 -0700 |
commit | 1632fae376eb460cf992e543b13c8690b71fe8d5 (patch) | |
tree | 941cd97ff6a694fa11d3e9832e9853769b5cdc69 | |
parent | bc9a5a0fb71f505dc66a8a7d676d69dd8448466d (diff) | |
download | frameworks_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
-rwxr-xr-x | media/java/android/mtp/MtpDatabase.java | 9 |
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); } } |