Perform calls in Android Locktask mode
Asked Answered
O

2

2

TL;DR How to make a phone call while using Activity.startLockTask()?

I'm trying to setup a restricted environment on an Android device, i.e. what is usually called "Kiosk-Mode".

Official documentation can be found here: https://developer.android.com/work/cosu.html

The official way of doing this suggest to use Activity.startLockTask.

This works fine until you want to start other apps from within your Activity which is in startLockTask() mode. Any activity that launches must not start on a new task stack otherwise the system blocks the launch intent, i.e. no Intent.FLAG_ACTIVITY_NEW_TASK.

Some apps can just be launched, other seem to implicitly set this flag, but can be workedaround by using startActivityForResult(...) which seems remove the NEW_TASK flag. For apps that still don't work I could code my own replacement.

The real issue is the call application, which enforces a new task stack. Triggering a call initiated the call, doesn't show the call activity, but also puts a call notification in the status bar (which is not accessible in while using startLockTask(). In contrast to other apps the call app is also one that can't be replaced with a custom app...

DevicePolicyManager.html.setLockTaskPackages() has no effect on this behavior.

Orcus answered 23/1, 2017 at 12:29 Comment(3)
I'm having the same issue. I need a way to make incoming/outgoing calls while in kiosk mode, and couldn't make this work. Did you find a solution?Gluck
we are also facing same issue. we have handle the outgoing call but for incoming call it did not show the incoming call activityPerrone
Solved this yet?Signora
C
3

I tried to make start call intent under locked mode and this line pop up:

    system_process E/ActivityManager: Attempted Lock Task Mode violation mStartActivity=ActivityRecord{56ab302 u0 com.android.server.telecom/.components.UserCallActivity t155}

So I add

    setLockTaskPackages(<ComponentName>,new String[]{getPackageName(),"com.google.android.dialer","com.android.server.telecom"});

Managed to get the dialler out. Of course if I push the home button or back button, there's no way to get the dialler back... the recent button is still locked though. Receiving call works perfectly (all buttons are disabled)

Compliance answered 23/4, 2017 at 15:50 Comment(12)
What happens if you then launch a call from the dialer?Orcus
Sorry, my call intent supplied the phone number directly.Compliance
We need to make sure we talk about the same thing. There is the call activity and the dialer activity. The call activity is what starts when you press "call" from the dailer.Orcus
linkCompliance
'Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + "<phone number>"));'Compliance
This launches a call, but can the user then access the call activity, hang up the call or put it on speaker?Orcus
It does launch the call through dialer activity.. So all the controls are there. I mean the standard phone app is at the foreground.Compliance
It launches the call, but can you interact with the call activity? I mean the call activity, the new one that was started by pressing "call", I don't mean the dialer. On the devices I tested it (Samsung S5/Pixel) the call starts but you never see the call activity.Orcus
In the logs it shows as Recent #0: TaskRecord{46cf2af #7366 A=com.android.incallui U=0 StackId=1 sz=1}Orcus
Actually I've not tried com.android.server.telecom yet, let me test it with that. What device/ROM are you testing this on?Orcus
i tested on samsung galaxy s3 / resurrection remix nougat 7.1.1. when i tested it, i can interact with the call activity. before i added the last package, indeed the call started but the call activity is inaccessible.Compliance
I've noticed on my phone, when I set device owner using adb, even without launching and locking my app, when I'm using the phone dialer and press call, it does not launch the call activity UI. Going through setting->app->Phone, on App Info it says Phone App:No. Changing it to Yes solve the problem. For good measure I even register the google account (after device owner has been set).Compliance
C
0

Have you tried this?

setLockTaskPackages(new ComponentName(this, DeviceAdminReceiver.class),new String[]{getPackageName(),"com.google.android.dialer"});
Compliance answered 23/4, 2017 at 10:58 Comment(1)
It doesn't make a difference. The issue is that the call app/activity forces a new task stack, which is exactly what the lockmode prevents, thus hiding the call UI.Orcus

© 2022 - 2024 — McMap. All rights reserved.