Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0d019c4 authored by Marco Nelissen's avatar Marco Nelissen Committed by Android (Google) Code Review
Browse files

Merge "Make setServer() safe to call multiple times"

parents a79501cd 1632fae3
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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);
        }
    }