浏览代码

dismiss keyguard for CallNotificationActivity (WIP, see TODO)

Whenever i click the button to accept the call, CallActivity is started by intent.
CallActivity itself has the same logic to dismiss the keyguard.

The problem is: When switching from CallNotificationActivity to CallActivity the lockscreen is shown indeed!
So i guess Android recognizes "oh, CallNotificationActivity is gone. Let's show the lockscreen" before it recognizes that
the new activity also dismiss the lockscreen ?!

I fear for this scenario it was not the best idea to have 2 different activies.. (before it was only 1 activity and 2 condcutor controllers..)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 3 年之前
父节点
当前提交
57804c8d62

+ 4 - 2
app/src/main/AndroidManifest.xml

@@ -129,7 +129,8 @@
             android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
             android:launchMode="singleTask"
             android:taskAffinity=".call"
-            android:excludeFromRecents="true" />
+            android:excludeFromRecents="true"
+            android:showOnLockScreen="true"/>
 
         <activity
             android:name=".activities.CallNotificationActivity"
@@ -138,7 +139,8 @@
             android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
             android:launchMode="singleTask"
             android:taskAffinity=".call"
-            android:excludeFromRecents="true" />
+            android:excludeFromRecents="true"
+            android:showOnLockScreen="true" />
 
         <activity
             android:name=".activities.FullScreenImageActivity"

+ 21 - 1
app/src/main/java/com/nextcloud/talk/activities/CallNotificationActivity.java

@@ -21,6 +21,7 @@
 package com.nextcloud.talk.activities;
 
 import android.annotation.SuppressLint;
+import android.app.KeyguardManager;
 import android.app.PictureInPictureParams;
 import android.content.Context;
 import android.content.Intent;
@@ -39,6 +40,7 @@ import android.text.TextUtils;
 import android.util.Log;
 import android.util.Rational;
 import android.view.View;
+import android.view.WindowManager;
 
 import com.bluelinelabs.logansquare.LoganSquare;
 import com.facebook.common.executors.UiThreadImmediateExecutorService;
@@ -130,6 +132,10 @@ public class CallNotificationActivity extends BaseActivity {
         super.onCreate(savedInstanceState);
         NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
 
+        dismissKeyguard();
+        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
+
         eventBus.post(new CallNotificationClick());
 
         binding = CallNotificationActivityBinding.inflate(getLayoutInflater());
@@ -489,7 +495,6 @@ public class CallNotificationActivity extends BaseActivity {
     }
 
     void enterPipMode() {
-//        enableKeyguard();
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
             enterPictureInPictureMode(getPipParams());
         } else {
@@ -526,4 +531,19 @@ public class CallNotificationActivity extends BaseActivity {
         binding.callAnswerButtons.setVisibility(View.VISIBLE);
         binding.incomingCallRelativeLayout.setVisibility(View.VISIBLE);
     }
+
+    // TODO: dismiss keyguard works, but whenever accepting the call and switch to CallActivity by intent, the
+    //  lockscreen is shown (although CallActivity also dismisses the keyguard in the same way.)
+    private void dismissKeyguard() {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
+            setShowWhenLocked(true);
+            setTurnScreenOn(true);
+            KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
+            keyguardManager.requestDismissKeyguard(this, null);
+        } else {
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
+            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
+        }
+    }
 }