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

Commit 78c64cdb authored by RoboErik's avatar RoboErik
Browse files

Fix crash in legacy apps that register without a looper

Some legacy apps registered their media button receiver in a thread
without a looper. If this happens we need to use the main looper to
prevent a crash.

bug: 16306226
Change-Id: Idf472e649393e2a7ce2a3e1cbb3476003ab17f34
parent 1d2a1c91
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ public class Media extends BaseCommand {
        void printUsageMessage() {
            try {
                System.out.println("V2Monitoring session " + mController.getTag()
                        + "...  available commands:");
                        + "...  available commands: play, pause, next, previous");
            } catch (RemoteException e) {
                System.out.println("Error trying to monitor session!");
            }
@@ -257,6 +257,14 @@ public class Media extends BaseCommand {
                        addNewline = false;
                    } else if ("q".equals(line) || "quit".equals(line)) {
                        break;
                    } else if ("play".equals(line)) {
                        mController.play();
                    } else if ("pause".equals(line)) {
                        mController.pause();
                    } else if ("next".equals(line)) {
                        mController.next();
                    } else if ("previous".equals(line)) {
                        mController.previous();
                    } else {
                        System.out.println("Invalid command: " + line);
                    }
+5 −2
Original line number Diff line number Diff line
@@ -290,7 +290,6 @@ public class MediaSessionLegacyHelper {
            if (DEBUG) {
                Log.d(TAG, "addMediaButtonListener already added " + pi);
            }
            return;
        }
        holder.mMediaButtonListener = new MediaButtonListener(pi, context);
        // TODO determine if handling transport performer commands should also
@@ -468,7 +467,11 @@ public class MediaSessionLegacyHelper {
                mSessions.remove(mPi);
            } else if (mCb == null) {
                mCb = new SessionCallback();
                mSession.setCallback(mCb);
                Handler handler = null;
                if (Looper.myLooper() == null) {
                    handler = new Handler(Looper.getMainLooper());
                }
                mSession.setCallback(mCb, handler);
            }
        }