4

If an application has the "android.permission.CAMERA", and I wanted my app to block the use of this permission when it tries to access the Camera Hardware,"for security reasons" how could I block the process?

*NOTE: Let's assume that My app has all of the permissions...

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Abdullah Rasheed
  • 3,562
  • 4
  • 33
  • 51

3 Answers3

4

You need to use the Device Administration API. Starting with Android 4.0 you can disable use of the camera with setCameraDisabled

Wesley Wiser
  • 9,491
  • 4
  • 50
  • 69
  • Do you know of any non-root solutions for Android <4.0 ? – miniBill Mar 19 '12 at 00:18
  • @miniBill This is the only way that I know of. – Wesley Wiser Mar 19 '12 at 00:20
  • Wow, this is a big help. I read over the pages, and took a look at the classes in the Device Administration API Overview. How could I do the same thing I asked about for the camera, for other things like writing or sending sms messages? @miniBill, do you mean will I have root access? if so yes I intend to create the app in the way to use the root. – Abdullah Rasheed Mar 19 '12 at 00:41
  • @inspired: No, you cannot use this for arbitrary other things, only what is listed in the table on the Device Administration API page linked to above. – CommonsWare Mar 19 '12 at 10:45
  • @CommonsWare is there anyway possible to do it? I don't necessarily have to use the Device Administration API if there is another way? I have seen apps that claim to do this, so I'm thinking that there is some way to block another android app from using some other permissions. – Abdullah Rasheed Mar 19 '12 at 11:22
  • 1
    @inspired: With a rooted device, it is possible. With an unrooted device, a USB cable, and some desktop software, it may be possible. With just an unrooted device, it had better not be possible, otherwise it is a serious security hole. I do not like the specific techniques that I have seen used for this in the first two scenarios, so I will not disclose them here. This sort of "optional permission" stuff needs to be part of the OS -- all you will do is break apps by going down the path that you are. – CommonsWare Mar 19 '12 at 11:28
  • @CommonsWare thanks alot. I have researched it more,and come to the conclusion to that this sort of thing should be apart of the OS. – Abdullah Rasheed Mar 26 '12 at 00:44
3

I don't know of any non-rooted solutions, however there is an app on the android market called "Android Permission Blocker" that can block individual app permissions on an app basis. It only costs 99 cents so I tried it out and have been using it with success every since. Worth every penny in my opinion.

Rob
  • 126
  • 6
2

I hate when programmers say "this is impossible!" I think "there is always a way out"

        public static void      killAppByPermission (Context context, String permissionToKill)
        {
            try
            {
                PackageManager p = context.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]).toLowerCase().contains(permissionToKill.toLowerCase()))
                            {
                                killAppByPackName(pInfo.packageName.toString());
                                break;
                            }
                        }
                    }
                }
            }
            catch (Throwable t){t.printStackTrace();}
        }

    public static void      killAppByPackName   (String packageToKill)
    {
        try
        {
            ActivityManager actvityManager = (ActivityManager) Sett.context.getSystemService(Context.ACTIVITY_SERVICE);
            final List<RunningAppProcessInfo> procInfos = actvityManager.getRunningAppProcesses();
            for (RunningAppProcessInfo runningAppProcessInfo : procInfos) 
            {
                //Log.e("running",runningAppProcessInfo.processName);
                if(runningAppProcessInfo.processName.toLowerCase().contains(packageToKill.toLowerCase())) 
                {
                    android.os.Process.sendSignal(runningAppProcessInfo.pid, android.os.Process.SIGNAL_KILL);
                    actvityManager.killBackgroundProcesses(packageToKill);
                    //Log.e("killed", "!!! killed "+ packageToKill);
                }           
            }
        }
        catch (Throwable t){History.Error(t);}
    }

    public static void      killAppByName       (Context context, String appNameToKill)
    {
        try
        {
            ActivityManager  manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
            List<ActivityManager.RunningAppProcessInfo> listOfProcesses = manager.getRunningAppProcesses();
            for (ActivityManager.RunningAppProcessInfo process : listOfProcesses)
            {
                if (process.processName.toLowerCase().contains(appNameToKill.toLowerCase()))
                {
                    //Log.e("killed", process.processName);
                    manager.killBackgroundProcesses(process.processName);
                    break;
                }
            }
        }
        catch (Throwable t){t.printStackTrace();}
    }
XXX
  • 8,996
  • 7
  • 44
  • 53