title: Android: Grant permissions through ADB
body: <p>For my application for some functionalities, I need to use the camera, which is not required to the core functionality of the application, so I need to specify the it's optional to use camera. So in the manifest I declared the permission as follows:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CAMERA"/&gt;
  &lt;uses-feature android:name="android.hardware.camera" android:required="false"/&gt;
  &lt;uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/&gt; 
  </code></pre>
  
  <p>But when I try to grant permission through adb using the following command it gives an error:</p>
  
  <pre><code>pm grant my.app.package android.permission.CAMERA
  </code></pre>
  
  <p>gives the error:</p>
  
  <pre><code>Operation not allowed: java.lang.SecurityException: Can't change android.permission.CAMERA. It is required by the application
  </code></pre>
  
  <p>My device is a rooted one and it runs android 5.1.1(22). According to the ADB <a href="https://developer.android.com/studio/command-line/adb.html#pm" rel="noreferrer">documentation</a>, since the permission is declared as optional, I should be able to grant permission from adb as mentioned above. I have referenced <a href="http://www.londatiga.net/it/programming/android/solution-to-make-an-android-app-visible-to-all-devices-in-google-play-when-using-specific-feature-2/" rel="noreferrer">this</a>, <a href="https://stackoverflow.com/questions/9299993/optional-permissions-so-an-app-can-show-on-all-devices-and-enable-optional-featu">this</a> and <a href="https://stackoverflow.com/questions/5712375/is-it-possible-to-have-optional-permissions-in-android">this</a>. But still I couldn't figure out a reason for why it's not working.  </p>
  
  <p>Thank you in advance for suggestions and recommendations.</p>