|
20 | 20 |
|
21 | 21 | import android.annotation.SuppressLint;
|
22 | 22 | import android.app.Application;
|
| 23 | +import android.app.KeyguardManager; |
23 | 24 | import android.content.Context;
|
24 | 25 | import android.content.Intent;
|
25 | 26 | import android.os.AsyncTask;
|
26 | 27 | import android.os.Handler;
|
27 | 28 | import android.os.HandlerThread;
|
28 |
| - |
| 29 | +import android.os.PowerManager; |
29 | 30 | import androidx.annotation.NonNull;
|
30 | 31 | import androidx.core.content.pm.ShortcutInfoCompat;
|
31 | 32 | import androidx.core.content.pm.ShortcutManagerCompat;
|
32 | 33 | import androidx.core.graphics.drawable.IconCompat;
|
33 | 34 | import androidx.lifecycle.DefaultLifecycleObserver;
|
34 | 35 | import androidx.lifecycle.LifecycleOwner;
|
35 | 36 | import androidx.lifecycle.ProcessLifecycleOwner;
|
36 |
| - |
| 37 | +import dagger.hilt.EntryPoints; |
| 38 | +import dagger.hilt.android.HiltAndroidApp; |
| 39 | +import java.io.IOException; |
| 40 | +import java.io.InputStream; |
| 41 | +import java.security.Security; |
| 42 | +import java.util.Arrays; |
| 43 | +import java.util.List; |
| 44 | +import java.util.Timer; |
| 45 | +import java.util.concurrent.Executors; |
| 46 | +import javax.inject.Inject; |
| 47 | +import network.loki.messenger.BuildConfig; |
| 48 | +import network.loki.messenger.R; |
| 49 | +import network.loki.messenger.libsession_util.ConfigBase; |
| 50 | +import network.loki.messenger.libsession_util.UserProfile; |
37 | 51 | import org.conscrypt.Conscrypt;
|
38 | 52 | import org.session.libsession.database.MessageDataProvider;
|
39 | 53 | import org.session.libsession.messaging.MessagingModuleConfiguration;
|
|
44 | 58 | import org.session.libsession.utilities.ConfigFactoryUpdateListener;
|
45 | 59 | import org.session.libsession.utilities.Device;
|
46 | 60 | import org.session.libsession.utilities.Environment;
|
| 61 | +import org.session.libsession.utilities.NonTranslatableStringConstants; |
47 | 62 | import org.session.libsession.utilities.ProfilePictureUtilities;
|
48 | 63 | import org.session.libsession.utilities.SSKEnvironment;
|
49 | 64 | import org.session.libsession.utilities.TextSecurePreferences;
|
|
88 | 103 | import org.thoughtcrime.securesms.util.Broadcaster;
|
89 | 104 | import org.thoughtcrime.securesms.util.VersionDataFetcher;
|
90 | 105 | import org.thoughtcrime.securesms.webrtc.CallMessageProcessor;
|
91 |
| -import org.webrtc.PeerConnectionFactory; |
92 | 106 | import org.webrtc.PeerConnectionFactory.InitializationOptions;
|
93 |
| - |
94 |
| -import java.io.IOException; |
95 |
| -import java.io.InputStream; |
96 |
| -import java.security.Security; |
97 |
| -import java.util.Arrays; |
98 |
| -import java.util.List; |
99 |
| -import java.util.Timer; |
100 |
| -import java.util.concurrent.Executors; |
101 |
| - |
102 |
| -import javax.inject.Inject; |
103 |
| - |
104 |
| -import dagger.hilt.EntryPoints; |
105 |
| -import dagger.hilt.android.HiltAndroidApp; |
106 |
| -import network.loki.messenger.BuildConfig; |
107 |
| -import network.loki.messenger.R; |
108 |
| -import network.loki.messenger.libsession_util.ConfigBase; |
109 |
| -import network.loki.messenger.libsession_util.UserProfile; |
| 107 | +import org.webrtc.PeerConnectionFactory; |
110 | 108 |
|
111 | 109 | /**
|
112 | 110 | * Will be called once when the TextSecure process is created.
|
@@ -148,7 +146,9 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
148 | 146 | CallMessageProcessor callMessageProcessor;
|
149 | 147 | MessagingModuleConfiguration messagingModuleConfiguration;
|
150 | 148 |
|
151 |
| - private volatile boolean isAppVisible; |
| 149 | + public volatile boolean isAppVisible; |
| 150 | + public String KEYGUARD_LOCK_TAG = NonTranslatableStringConstants.APP_NAME + ":KeyguardLock"; |
| 151 | + public String WAKELOCK_TAG = NonTranslatableStringConstants.APP_NAME + ":WakeLock"; |
152 | 152 |
|
153 | 153 | @Override
|
154 | 154 | public Object getSystemService(String name) {
|
@@ -457,11 +457,6 @@ private void loadEmojiSearchIndexIfNeeded() {
|
457 | 457 | }
|
458 | 458 |
|
459 | 459 | // Method to clear the local data - returns true on success otherwise false
|
460 |
| - |
461 |
| - /** |
462 |
| - * Clear all local profile data and message history. |
463 |
| - * @return true on success, false otherwise. |
464 |
| - */ |
465 | 460 | @SuppressLint("ApplySharedPref")
|
466 | 461 | public boolean clearAllData() {
|
467 | 462 | TextSecurePreferences.clearAll(this);
|
@@ -492,4 +487,35 @@ public void restartApplication() {
|
492 | 487 | }
|
493 | 488 |
|
494 | 489 | // endregion
|
| 490 | + |
| 491 | + // Method to wake up the screen and dismiss the keyguard |
| 492 | + public void wakeUpDeviceAndDismissKeyguardIfRequired() { |
| 493 | + // Get the KeyguardManager and PowerManager |
| 494 | + KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE); |
| 495 | + PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE); |
| 496 | + |
| 497 | + // Check if the phone is locked & if the screen is awake |
| 498 | + boolean isPhoneLocked = keyguardManager.isKeyguardLocked(); |
| 499 | + boolean isScreenAwake = powerManager.isInteractive(); |
| 500 | + |
| 501 | + if (!isScreenAwake) { |
| 502 | + PowerManager.WakeLock wakeLock = powerManager.newWakeLock( |
| 503 | + PowerManager.FULL_WAKE_LOCK |
| 504 | + | PowerManager.ACQUIRE_CAUSES_WAKEUP |
| 505 | + | PowerManager.ON_AFTER_RELEASE, |
| 506 | + WAKELOCK_TAG); |
| 507 | + |
| 508 | + // Acquire the wake lock to wake up the device |
| 509 | + wakeLock.acquire(3000); |
| 510 | + } |
| 511 | + |
| 512 | + // Dismiss the keyguard. |
| 513 | + // Note: This will not bypass any app-level (Session) lock; only the device-level keyguard. |
| 514 | + // TODO: When moving to a minimum Android API of 27, replace these deprecated calls with new APIs. |
| 515 | + if (isPhoneLocked) { |
| 516 | + KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(KEYGUARD_LOCK_TAG); |
| 517 | + keyguardLock.disableKeyguard(); |
| 518 | + } |
| 519 | + } |
| 520 | + |
495 | 521 | }
|
0 commit comments