Skip to content

Commit

Permalink
Make lockscreen show again after dismissal if a DD notification is re…
Browse files Browse the repository at this point in the history
…ceived where DismissalEnabled is false (#1699)

* Fix corner case in LockScreenManager

* Update unit tests
  • Loading branch information
bilal-alsharifi authored Jun 7, 2021
1 parent 6522cd5 commit e6836ba
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.smartdevicelink.managers.lockscreen;

import android.content.Context;
import android.content.Intent;
import android.os.Looper;

import androidx.test.ext.junit.runners.AndroidJUnit4;

Expand Down Expand Up @@ -170,4 +172,34 @@ public void testLockScreenDismissibleWithEnableFalseAndDismissibilityTrue() {
assertTrue(lockScreenManager.isLockscreenDismissible);
}

@Test
public void testShowingLockscreenAfterDismissibleFalse() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
lockScreenManager.enableDismissGesture = true;
lockScreenManager.displayMode = LockScreenConfig.DISPLAY_MODE_ALWAYS;

// Send first notification (DD=OFF, Dismissible=true)
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
onDriverDistraction.setLockscreenDismissibility(true);
onDriverDistraction.setState(DriverDistractionState.DD_OFF);
onDDListener.onNotified(onDriverDistraction);

// Dismiss lock screen activity
lockScreenManager.mLockscreenDismissedReceiver.onReceive(null, new Intent(SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED, null));

// Lock screen should be set to auto dismiss in future
assertTrue(lockScreenManager.mLockScreenShouldBeAutoDismissed);

// Send second notification (DD=On, Dismissible=false)
onDriverDistraction = new OnDriverDistraction();
onDriverDistraction.setLockscreenDismissibility(false);
onDriverDistraction.setState(DriverDistractionState.DD_ON);
onDDListener.onNotified(onDriverDistraction);

// Lock screen should be set to NOT auto dismiss in future
assertFalse(lockScreenManager.mLockScreenShouldBeAutoDismissed);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public class LockScreenManager extends BaseSubManager {
final int customView;
int displayMode;
Bitmap deviceLogo;
private boolean mLockScreenHasBeenDismissed, lockscreenDismissReceiverRegistered, receivedFirstDDNotification;
private boolean lockscreenDismissReceiverRegistered, receivedFirstDDNotification;
boolean mLockScreenShouldBeAutoDismissed;
private String mLockscreenWarningMsg;
private BroadcastReceiver mLockscreenDismissedReceiver;
BroadcastReceiver mLockscreenDismissedReceiver;
private final LockScreenDeviceIconManager mLockScreenDeviceIconManager;
private String lastIntentUsed;

Expand Down Expand Up @@ -220,6 +221,11 @@ public void onNotified(RPCNotification notification) {
// enable the dismissal. There is a delay added to allow time for the activity
// time to completely start and handle the new intent. There seems to be odd behavior
// in Android when startActivity is called multiple times too quickly.
if (previousDismissibleState) {
// If lockscreen was dismissible, got dismissed by the user, then became not dismissible, the lockscreen activity should be allowed to launch again
// https://github.com/smartdevicelink/sdl_java_suite/issues/1695
mLockScreenShouldBeAutoDismissed = false;
}
if (!receivedFirstDDNotification) {
new Handler().postDelayed(new Runnable() {
@Override
Expand Down Expand Up @@ -296,7 +302,7 @@ public void onMoveToBackground() {
@Override
public void onReceive(Context context, Intent intent) {
if (SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED.equals(intent.getAction())) {
mLockScreenHasBeenDismissed = true;
mLockScreenShouldBeAutoDismissed = true;
lastIntentUsed = null;
}
}
Expand All @@ -318,7 +324,7 @@ public void onReceive(Context context, Intent intent) {
private void launchLockScreenActivity() {
synchronized (LOCKSCREEN_LAUNCH_LOCK) {
// If the user has dismissed the lockscreen for this run or has disabled it, do not show it
if (mLockScreenHasBeenDismissed || displayMode == LockScreenConfig.DISPLAY_MODE_NEVER) {
if (mLockScreenShouldBeAutoDismissed || displayMode == LockScreenConfig.DISPLAY_MODE_NEVER) {
return;
}
// intent to open SDLLockScreenActivity
Expand Down

0 comments on commit e6836ba

Please sign in to comment.