Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclusive access to the microphone in Android

Is it possible to get exclusive access to Android microphone from an application ?

I am trying to extend CSipSimple application and my goal is to improve it's security. One of the goals, which I have no idea how to approach, is to block other applications to record my conversations.

I have downloaded an app from PlayStore, Call Recorder it's called, and it gets automatically on when I dial a phone number and it is recording my phone conversation. That is what I need to avoid.

So, can I stop any application from recording my voice while I am on call ?

like image 573
Iftemi Alin Avatar asked Mar 23 '23 07:03

Iftemi Alin


1 Answers

As Harsha C Alva mentioned, one way of doing this is to iterate installed applications, check their permissions and kill them if they are running.

In order to iterate install apps

private void iterateInstalledApps()
{
    PackageManager p = this.getPackageManager();
    final List <PackageInfo> appinstall = 
        p.getInstalledPackages(PackageManager.GET_PERMISSIONS);
    for(PackageInfo pInfo:appinstall)
    {
        String[] reqPermission=pInfo.requestedPermissions;
        if(reqPermission!=null)
        {
            for(int i=0;i<reqPermission.length;i++)
            {
                if (((String)reqPermission[i]).equals("android.permission.RECORD_AUDIO"))
                {
                    killPackage(pInfo.packageName.toString());
                    break;
                }
            }
        }
    }       
}

In order to kill one package

private void killPackage(String packageToKill)
{
    ActivityManager actvityManager = 
        (ActivityManager) this.getSystemService( ACTIVITY_SERVICE );
    final List<RunningAppProcessInfo> procInfos = 
        actvityManager.getRunningAppProcesses();
    for (RunningAppProcessInfo runningAppProcessInfo : procInfos) 
    {
        if(runningAppProcessInfo.processName.equals(packageToKill)) 
        {
            android.os.Process.sendSignal(runningAppProcessInfo.pid, 
                                android.os.Process.SIGNAL_KILL);
            actvityManager.killBackgroundProcesses(packageToKill);
        }           
    }       
}

You can call iterateInstalledApps in a timer because Android is restarting the app on the spot. If you keep killing the application it will not manage to record anything. Testing with Call Recorder while speaking on the phone.

like image 126
Iftemi Alin Avatar answered Apr 02 '23 05:04

Iftemi Alin