4

i'm facing Security Exception while executing my Appium scripts

Hi all, i'm new to appium and i'm in learning stage with appium tool. I created one script to start a basic test. i'm getting below updated error.

I Connected my device through USB debugging and device also listed out in adb. but when i executing it is throwing an error. below is the attached code and error logs.

DesiredCapabilities desire=new DesiredCapabilities();
        desire.setCapability("deviceName", "Redmi");
        desire.setCapability("udid", "3cbaf93d");
        desire.setCapability("platformName", "Android");
        desire.setCapability("platformVersion", "9.0");
        desire.setCapability("appPackage", "com.androi.camera");
        desire.setCapability("appActivity", "com.androi.camera.Camera");
        URL url=new URL("http://127.0.0.1:4723/wd/hub");
        appium=new AppiumDriver<MobileElement>(url,desire);
        System.out.println("app started");
Error log:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
    at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:1815)
    at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1023)
    at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1006)
    at com.android.providers.settings.SettingsProvider.delete(SettingsProvider.java:592)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:343)
    at com.android.providers.settings.SettingsService$MyShellCommand.deleteForUser(SettingsService.java:406)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:289)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:735)'; Code: '255'
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-S3RV3MH', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: AppiumDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
    at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:1815)
    at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1023)
    at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1006)
    at com.android.providers.settings.SettingsProvider.delete(SettingsProvider.java:592)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:343)
    at com.android.providers.settings.SettingsService$MyShellCommand.deleteForUser(SettingsService.java:406)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:289)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:735)'; Code: '255'
    at getResponseForW3CError (C:\Users\DELL\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:826:9)
    at asyncHandler (C:\Users\DELL\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:447:37)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-S3RV3MH', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: AppiumDriver
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
    at test1.Class1.main(Class1.java:27)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)
    ... 11 more
Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
    at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:1815)
    at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1023)
    at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1006)
    at com.android.providers.settings.SettingsProvider.delete(SettingsProvider.java:592)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:343)
    at com.android.providers.settings.SettingsService$MyShellCommand.deleteForUser(SettingsService.java:406)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:289)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:735)'; Code: '255'
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-S3RV3MH', ip: '192.168.1.5', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
Driver info: driver.version: AppiumDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS

java.lang.SecurityException: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS
    at com.android.providers.settings.SettingsProvider.enforceWritePermission(SettingsProvider.java:1815)
    at com.android.providers.settings.SettingsProvider.mutateGlobalSetting(SettingsProvider.java:1023)
    at com.android.providers.settings.SettingsProvider.deleteGlobalSetting(SettingsProvider.java:1006)
    at com.android.providers.settings.SettingsProvider.delete(SettingsProvider.java:592)
    at android.content.ContentProvider$Transport.delete(ContentProvider.java:343)
    at com.android.providers.settings.SettingsService$MyShellCommand.deleteForUser(SettingsService.java:406)
    at com.android.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:289)
    at android.os.ShellCommand.exec(ShellCommand.java:103)
    at com.android.providers.settings.SettingsService.onShellCommand(SettingsService.java:51)
    at android.os.Binder.shellCommand(Binder.java:634)
    at android.os.Binder.onTransact(Binder.java:532)
    at android.os.Binder.execTransact(Binder.java:735)'; Code: '255'
    at getResponseForW3CError (C:\Users\DELL\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:826:9)
    at asyncHandler (C:\Users\DELL\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:447:37)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    ... 16 more
Satish Rongala
  • 209
  • 6
  • 19

5 Answers5

8
  1. go to developer option.
  2. go to last option called --> Disable Permission Monitoring --> enable it.
Adriaan
  • 17,741
  • 7
  • 42
  • 75
Sandeep Duve
  • 131
  • 1
  • 5
1
desiredCapabilities.setCapability("ignoreHiddenApiPolicyError" , true) 

will work.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Nikhil
  • 11
  • 2
  • 1
    Please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post. – Adriaan Feb 09 '23 at 12:57
0

Hmm, sounds like Appium needs some permission to interact with the app. Try using the autoGrantPermissions capability and set that to true and see if that helps.


[Update] the error message in this case was not from Appium but from adb. Based on the information so far it looks like the package name and activity name might not be valid. If the adb command don't work then app Appium won't work either.

Can you provide the tutorial you're following to automate the Amazon shopping app and also why did the problem set change to using the amazon shopping app?

I don't believe the package name is correct:

adb shell pm list packages -f | grep mShop

OUTPUTs:

package:/data/app/com.amazon.mShop.android.shopping-6T5__wDlES2DKVGacorMSw==/base.apk=com.amazon.mShop.android.shopping 
jmp
  • 2,175
  • 2
  • 17
  • 16
  • it didn't worked..still facing the same error. `Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps' exited with code 255'; Stderr: 'Security exception: Permission denial: writing to settings requires:android.permission.WRITE_SECURE_SETTINGS` – Satish Rongala Jul 13 '19 at 18:39
  • Hmm, is there any log from the Appium server? Also is the package name correct? Looks like it's missing a `d` in Android. – jmp Jul 13 '19 at 18:54
  • oo okay, this looks like a permission issue with adb and not appium then. What does this command output? `adb -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps` – jmp Jul 13 '19 at 18:55
  • yes, i attached the device to adb in cmd and i gave the package name from my mobile. but i tried by enabling USB Debugging(Security Service) enable to debug a app.. so now it is not gibing error but it is throwing a new error posting below – Satish Rongala Jul 13 '19 at 18:56
  • `Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command 'C\:\\Users\\DELL\\AppData\\Local\\Android\\sdk\\platform-tools\\adb.exe -P 5037 -s 3cbaf93d shell pm install -g /data/local/tmp/appium_cache/12bb63270ecd4315cfaaa8d8202b809bbfccca11.apk' exited with code 1'; Stderr: ''; Code: '1'` – Satish Rongala Jul 13 '19 at 18:57
  • the out put of this command 'adb -P 5037 -s 3cbaf93d shell settings delete global hidden_api_policy_pre_p_apps` is that Security issue only – Satish Rongala Jul 13 '19 at 18:59
  • https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md#javalangsecurityexception-permission-denial-starting-intent can you check the appPackage and appActivity again for the correct names? – jmp Jul 13 '19 at 19:19
  • ' capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("appPackage", "in.amazon.mShop.android.shopping"); capabilities.setCapability("appActivity", "com.amazon.mShop.home.HomeActivity");` – Satish Rongala Jul 13 '19 at 19:40
  • i tried this one and i placed the amazon apk in my system also.. but this is not able to find the apk and throwing error `"-P 5037 -s 3cbaf93d shell pm install -g /data/local/tmp/appium_cache/12bb63270ecd4315cfaaa8d8202b809bbfccca11.apk' exited with code 1'; Stderr: '';` – Satish Rongala Jul 13 '19 at 19:42
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/196426/discussion-between-jmp-and-satish-rongala). – jmp Jul 13 '19 at 19:42
0

Are you sure that you are using correct app activity, because if it is not a launchable activity, then also it will give you permission exception, double-check the launchable activity name

Puneet Jain
  • 11
  • 1
  • 4
0

In my case, for similar problem (connecting to phone from Appium) solution was to enable "USB debugging (security settings)" and "USB installation" in developer options. I have faced another issue there as it (I do not know why) requires internet connection and I was not able to switch these option on using my telecom operator connection, I had to connect to wifi.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
sjanisz
  • 57
  • 8