Android: Taking Complete Control of Phone(Kiosk Mode), Is It Possible? How

Android: Taking complete control of phone(kiosk mode), is it possible? How?

Yes it is possible but you can not control the behaviour of Home key and end call key.

for full screen add android:theme="@android:style/Theme.NoTitleBar.Fullscreen" to activity tag in manifest file.

To disable incoming call you need to listen phone calls:

import android.app.Service;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

public class MyPhoneStateListener extends Service{

@Override
public IBinder onBind(Intent arg0) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
StateListener phoneStateListener = new StateListener();
TelephonyManager telephonymanager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonymanager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

}

class StateListener extends PhoneStateListener{
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
//Disconnect the call here...
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
break;
case TelephonyManager.CALL_STATE_IDLE:
break;
}
}
};

@Override
public void onDestroy() {

}
}

Note: While stopping service don't foget to remove the listener and add these permissions to your manifest file:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

and disconnect the call programmatically:

try{
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
Class c = Class.forName(manager.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
ITelephony telephony = (ITelephony)m.invoke(manager);
telephony.endCall();
} catch(Exception e){
Log.d("",e.getMessage());
}

Note: Add this file to disconnect the call:
http://dl.dropbox.com/u/31740476/ITelephony.aidl

To disable keys you need to override:

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(KeyEvent.KEYCODE_MENU == event.getKeyCode() || KeyEvent.KEYCODE_DPAD_LEFT==event.getKeyCode()
|| KeyEvent.KEYCODE_DPAD_DOWN==event.getKeyCode() || KeyEvent.KEYCODE_DPAD_RIGHT==event.getKeyCode()
|| KeyEvent.KEYCODE_DPAD_UP==event.getKeyCode() || KeyEvent.KEYCODE_DPAD_CENTER==event.getKeyCode()
|| KeyEvent.KEYCODE_BACK==event.getKeyCode())
{
return false;
}
return true;
}

On Home key press the Home screen will come, so to overcome this you need to implement a service and there you need to implement a infinite thread to relaunch your app like this:

public class AppTrackingService extends Service {

private RunnableThread thread;
private Context ctx;

@Override
public IBinder onBind(Intent intent) {
return null;
}

public void onCreate(){
super.onCreate();
ctx = AppTrackingService.this;
thread = new RunnableThread();
}

public void onStart(Intent intent, int startid) {
try{
if(thread==null) thread = new RunnableThread();
thread.startThread();
}catch(Exception e){ }
}

class RunnableThread extends Thread {

Handler back_handler = new Handler();
boolean isContinue = false;

public RunnableThread(){
isContinue = false;
}

public void setIsContinue(boolean val){
this.isContinue = val;
}

public void startThread(){
isContinue = true;
start();
}

public void run(){
ActivityManager actMngr = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
while(isContinue){
try{
//Maintain a boolean "isyourapprunning" to know if your app was running or not....
if(isyourapprunning){
String runningPkg = actMngr.getRunningTasks(1).get(0).topActivity.getPackageName();
if (!runningPkg.equals(ctx.getPackageName())){
launchApp(ctx.getPackageName());
}
Thread.sleep(2500); //2.5 secs
}else{
isContinue = false;
stopSelf();
}

}catch(Exception e){ }
}//end of while loop
}

protected void launchApp(String packageName) {
Intent mIntent = getPackageManager().getLaunchIntentForPackage(packageName);
mIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mIntent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
if (null != mIntent) {
try {
startActivity(mIntent);
} catch(Exception e) { }
}
}
}
}

EDIT

You would need to add the following permission to be able to end calls:

<uses-permission android:name="android.permission.CALL_PHONE" />

And you can use the following AIDL file:

package com.android.internal.telephony;

/**
* Interface used to interact with the phone. Mostly this is used by the
* TelephonyManager class. A few places are still using this directly.
* Please clean them up if possible and use TelephonyManager instead.
*
* {@hide}
*/
interface ITelephony {
/**
* End call if there is a call in progress, otherwise does nothing.
*
* @return whether it hung up
*/
boolean endCall();

/**
* Silence the ringer if an incoming call is currently ringing.
* (If vibrating, stop the vibrator also.)
*
* It's safe to call this if the ringer has already been silenced, or
* even if there's no incoming call. (If so, this method will do nothing.)
*
* TODO: this should be a oneway call too (see above).
* (Actually *all* the methods here that return void can
* probably be oneway.)
*/
void silenceRinger();
}

Kiosk mode in Android

You can autostart applications on boot by listening to the android.intent.action.BOOT_COMPLETED intent in a BroadcastReceiver and start your Activity from there. In the Activity you can register yourself as the new default homescreen[1] and handle the keys.

I think there are some instances that you can't handle without modifying the framework (like longpress on Home to show currently active Applications) - I could also be mistaken though.

But for a prototype that could be sufficient.

Have fun tinkering!

[1]:

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

Develop app run in kiosk mode in android

If your app acts like a home screen and you have no other home screen installed (or checked your app as default) it will start on boot and you won't be able to exit it. Unless you kill the task somehow, but that's not preventable.

Your app has to use the

android.intent.category.HOME

intent to be the first visible app on boot.

If you want some source you can look at Anderweb's ADW Launcher
https://github.com/AnderWeb/android_packages_apps_Launcher

Need more details to automate Kiosk mode android app

This is not supported behavior of Kiosk mode. The whole point of Kiosk mode is to lock down any non-surface level activity, including automation. You cannot access developer settings in Kiosk mode at all. I have been down this path with my current project and we were told by our device provider that this was not possible.

You have to put the device in admin mode in order to automate it. This is a limitation of adb.



Related Topics



Leave a reply



Submit