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.

darken
  • 807
  • 12
  • 25

2 Answers2

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)

hadifikri
  • 434
  • 3
  • 10
  • What happens if you then launch a call from the dialer? – darken Apr 23 '17 at 15:53
  • Sorry, my call intent supplied the phone number directly. – hadifikri Apr 23 '17 at 16:12
  • 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. – darken Apr 23 '17 at 16:19
  • [link](https://hadifikri@gitlab.com/hadifikri/android-example-COSU.git) – hadifikri Apr 23 '17 at 16:19
  • 'Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + ""));' – hadifikri Apr 23 '17 at 16:25
  • This launches a call, but can the user then access the call activity, hang up the call or put it on speaker? – darken Apr 23 '17 at 16:26
  • It does launch the call through dialer activity.. So all the controls are there. I mean the standard phone app is at the foreground. – hadifikri Apr 23 '17 at 16:37
  • 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. – darken Apr 23 '17 at 16:58
  • In the logs it shows as `Recent #0: TaskRecord{46cf2af #7366 A=com.android.incallui U=0 StackId=1 sz=1}` – darken Apr 23 '17 at 17:04
  • Actually I've not tried `com.android.server.telecom` yet, let me test it with that. What device/ROM are you testing this on? – darken Apr 23 '17 at 17:08
  • 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. – hadifikri Apr 23 '17 at 17:18
  • 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). – hadifikri Apr 24 '17 at 11:40
0

Have you tried this?

setLockTaskPackages(new ComponentName(this, DeviceAdminReceiver.class),new String[]{getPackageName(),"com.google.android.dialer"});
FelixSFD
  • 6,052
  • 10
  • 43
  • 117
hadifikri
  • 434
  • 3
  • 10
  • 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. – darken Apr 23 '17 at 16:31