Skip to content

Commit

Permalink
Fixes bug where Lock Screen would show "Cast" slider and IllegalArgum…
Browse files Browse the repository at this point in the history
…ent crash in some devices
  • Loading branch information
anselm94 committed Jun 7, 2019
1 parent f83933f commit 9e58400
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 5 deletions.
1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2017 Merbin J Anselm <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2016 Merbin J Anselm <[email protected]>
*
Expand Down Expand Up @@ -102,8 +120,8 @@ android {
applicationId "in.blogspot.anselmbros.torchie"
minSdkVersion 15
targetSdkVersion 28
versionCode 33
versionName "3.2"
versionCode 34
versionName "3.2.1"
}
buildTypes {
release {
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-->

<!--
~ Copyright (C) 2017 Merbin J Anselm <[email protected]>
~
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License along
~ with this program; if not, write to the Free Software Foundation, Inc.,
~ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-->

<!--
~ Copyright (C) 2016 Merbin J Anselm <[email protected]>
~
Expand Down Expand Up @@ -125,6 +143,12 @@
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>

<receiver android:name=".receiver.RockerReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2017 Merbin J Anselm <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2016 Merbin J Anselm <[email protected]>
*
Expand Down Expand Up @@ -199,6 +217,7 @@ private void onScreenOff() {

private void onScreenLock() {
DeviceManager.getInstance(this.mContext).setVolumeKeyDeviceEnabled(SettingsUtils.isScreenLockEnabled(this.mContext));
WakeLockManager.getInstance().release();
if (isLegacyDevice()) {
DeviceManager.getInstance(this.mContext).setVolumeKeyDeviceType(VolumeKeyRocker.TYPE);
if (SettingsUtils.isScreenLockEnabled(this.mContext)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2017 Merbin J Anselm <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2016 Merbin J Anselm <[email protected]>
*
Expand All @@ -54,11 +72,15 @@

package in.blogspot.anselmbros.torchie.main.manager.wakelock;

import android.content.ComponentName;
import android.content.Context;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;

import androidx.media.VolumeProviderCompat;

import in.blogspot.anselmbros.torchie.receiver.RockerReceiver;

/**
* Created by Merbin J Anselm on 05-Feb-17.
*/
Expand All @@ -79,7 +101,8 @@ public WakeLock() {
public void acquire(Context context, VolumeProviderCompat volumeProvider) {
if (!this.isWakelockHeld && this.isEnabled) {
if (this.mMediaSession == null) {
this.mMediaSession = new MediaSessionCompat(context, TYPE);
ComponentName mediaReceiver = new ComponentName(context, RockerReceiver.class.getName());
this.mMediaSession = new MediaSessionCompat(context, TYPE, mediaReceiver, null);

this.mMediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
Expand All @@ -96,6 +119,7 @@ public void acquire(Context context, VolumeProviderCompat volumeProvider) {
public void release() {
if (this.isWakelockHeld && this.isEnabled) {
if (this.mMediaSession != null) {
this.mMediaSession.setActive(false);
this.mMediaSession.release();
this.mMediaSession = null;
this.isWakelockHeld = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2017 Merbin J Anselm <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2017 Merbin J Anselm <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package in.blogspot.anselmbros.torchie.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.view.KeyEvent;

import in.blogspot.anselmbros.torchie.service.TorchieQuick;

public class RockerReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event != null && event.getAction() == KeyEvent.ACTION_DOWN) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (this.isTorchieQuickServiceRunning()) {
TorchieQuick.getInstance().setVolumeValues(1);
}
break;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (this.isTorchieQuickServiceRunning()) {
TorchieQuick.getInstance().setVolumeValues(-1);
}
break;
default:
if (this.isTorchieQuickServiceRunning()) {
TorchieQuick.getInstance().setVolumeValues(0);
}
}
}
}
}

private boolean isTorchieQuickServiceRunning() {
return TorchieQuick.getInstance() != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2017 Merbin J Anselm <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

/*
* Copyright (C) 2016 Merbin J Anselm <[email protected]>
*
Expand Down Expand Up @@ -143,7 +161,7 @@ public boolean onUnbind(Intent intent) {
protected boolean onKeyEvent(KeyEvent event) {
super.onKeyEvent(event);
if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) || (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP)) { //Filters ONLY the Volume Button key events
return TorchieManager.getInstance(this).setVolumeKeyEvent(new VolumeKeyEvent(event));
TorchieManager.getInstance(this).setVolumeKeyEvent(new VolumeKeyEvent(event));
}
return false;
}
Expand Down

0 comments on commit 9e58400

Please sign in to comment.