Skip to content

Commit e6836ba

Browse files
Make lockscreen show again after dismissal if a DD notification is received where DismissalEnabled is false (#1699)
* Fix corner case in LockScreenManager * Update unit tests
1 parent 6522cd5 commit e6836ba

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/lockscreen/LockScreenManagerTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.smartdevicelink.managers.lockscreen;
22

33
import android.content.Context;
4+
import android.content.Intent;
5+
import android.os.Looper;
46

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

@@ -170,4 +172,34 @@ public void testLockScreenDismissibleWithEnableFalseAndDismissibilityTrue() {
170172
assertTrue(lockScreenManager.isLockscreenDismissible);
171173
}
172174

175+
@Test
176+
public void testShowingLockscreenAfterDismissibleFalse() {
177+
if (Looper.myLooper() == null) {
178+
Looper.prepare();
179+
}
180+
lockScreenManager.enableDismissGesture = true;
181+
lockScreenManager.displayMode = LockScreenConfig.DISPLAY_MODE_ALWAYS;
182+
183+
// Send first notification (DD=OFF, Dismissible=true)
184+
OnDriverDistraction onDriverDistraction = new OnDriverDistraction();
185+
onDriverDistraction.setLockscreenDismissibility(true);
186+
onDriverDistraction.setState(DriverDistractionState.DD_OFF);
187+
onDDListener.onNotified(onDriverDistraction);
188+
189+
// Dismiss lock screen activity
190+
lockScreenManager.mLockscreenDismissedReceiver.onReceive(null, new Intent(SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED, null));
191+
192+
// Lock screen should be set to auto dismiss in future
193+
assertTrue(lockScreenManager.mLockScreenShouldBeAutoDismissed);
194+
195+
// Send second notification (DD=On, Dismissible=false)
196+
onDriverDistraction = new OnDriverDistraction();
197+
onDriverDistraction.setLockscreenDismissibility(false);
198+
onDriverDistraction.setState(DriverDistractionState.DD_ON);
199+
onDDListener.onNotified(onDriverDistraction);
200+
201+
// Lock screen should be set to NOT auto dismiss in future
202+
assertFalse(lockScreenManager.mLockScreenShouldBeAutoDismissed);
203+
}
204+
173205
}

android/sdl_android/src/main/java/com/smartdevicelink/managers/lockscreen/LockScreenManager.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ public class LockScreenManager extends BaseSubManager {
8787
final int customView;
8888
int displayMode;
8989
Bitmap deviceLogo;
90-
private boolean mLockScreenHasBeenDismissed, lockscreenDismissReceiverRegistered, receivedFirstDDNotification;
90+
private boolean lockscreenDismissReceiverRegistered, receivedFirstDDNotification;
91+
boolean mLockScreenShouldBeAutoDismissed;
9192
private String mLockscreenWarningMsg;
92-
private BroadcastReceiver mLockscreenDismissedReceiver;
93+
BroadcastReceiver mLockscreenDismissedReceiver;
9394
private final LockScreenDeviceIconManager mLockScreenDeviceIconManager;
9495
private String lastIntentUsed;
9596

@@ -220,6 +221,11 @@ public void onNotified(RPCNotification notification) {
220221
// enable the dismissal. There is a delay added to allow time for the activity
221222
// time to completely start and handle the new intent. There seems to be odd behavior
222223
// in Android when startActivity is called multiple times too quickly.
224+
if (previousDismissibleState) {
225+
// If lockscreen was dismissible, got dismissed by the user, then became not dismissible, the lockscreen activity should be allowed to launch again
226+
// https://github.com/smartdevicelink/sdl_java_suite/issues/1695
227+
mLockScreenShouldBeAutoDismissed = false;
228+
}
223229
if (!receivedFirstDDNotification) {
224230
new Handler().postDelayed(new Runnable() {
225231
@Override
@@ -296,7 +302,7 @@ public void onMoveToBackground() {
296302
@Override
297303
public void onReceive(Context context, Intent intent) {
298304
if (SDLLockScreenActivity.KEY_LOCKSCREEN_DISMISSED.equals(intent.getAction())) {
299-
mLockScreenHasBeenDismissed = true;
305+
mLockScreenShouldBeAutoDismissed = true;
300306
lastIntentUsed = null;
301307
}
302308
}
@@ -318,7 +324,7 @@ public void onReceive(Context context, Intent intent) {
318324
private void launchLockScreenActivity() {
319325
synchronized (LOCKSCREEN_LAUNCH_LOCK) {
320326
// If the user has dismissed the lockscreen for this run or has disabled it, do not show it
321-
if (mLockScreenHasBeenDismissed || displayMode == LockScreenConfig.DISPLAY_MODE_NEVER) {
327+
if (mLockScreenShouldBeAutoDismissed || displayMode == LockScreenConfig.DISPLAY_MODE_NEVER) {
322328
return;
323329
}
324330
// intent to open SDLLockScreenActivity

0 commit comments

Comments
 (0)