appium / io.appium.settings

App for dealing with Android settings
Apache License 2.0
122 stars 56 forks source link

find a method to set location without hidden api policy #180

Closed KazuCocoa closed 3 months ago

KazuCocoa commented 3 months ago

It looks like we need to call hidden policy to modify the location as well?

adb -P 5037 -s emulator-5554 shell 'settings put global hidden_api_policy_pre_p_apps 1;settings put global hidden_api_policy_p_apps 1;settings put global hidden_api_policy 1'

I saw via Appium worked but once I uninstall the settings app and install again, below command did not change the language.

adb -s emulator-5554 shell am broadcast -a io.appium.settings.locale -n io.appium.settings/.receivers.LocaleSettingReceiver --es lang ja --es country JP
adb -s emulator-5554 shell am broadcast -a io.appium.settings.locale -n io.appium.settings/.receivers.LocaleSettingReceiver --es lang en --es country US

When I run the app installation after relaxing hidden API policy, it worked. I'll investigate a bit further. We may need to:

The emulator version was API level 34.

mykola-mokhnach commented 3 months ago

The described behaviour makes a lot of sense to me as the current method for changing language calls private system APIs

KazuCocoa commented 3 months ago

Hm, this was not clear. A fresh emulator did not require any changes to change the language via the LocaleSettingReceiver. But I saw no-update behavior as this description as well.

KazuCocoa commented 3 months ago

One interesting thing was the relaxing hidden policy command needed to run before the app installation. This could be weird tho.

Actually the logcat had:

2024-06-08 18:54:30.655  9092-9092  LocaleSettingReceiver   io.appium.settings                   I  Obtained locale: ja_JP
2024-06-08 18:54:30.676  9092-9092  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/ActivityManagerNative;->getDefault()Landroid/app/IActivityManager; (unsupported, reflection, allowed)
2024-06-08 18:54:30.677  9092-9092  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/IActivityManager$Stub$Proxy;->getConfiguration()Landroid/content/res/Configuration; (unsupported, reflection, allowed)
2024-06-08 18:54:30.678  9092-9092  appium.settings         io.appium.settings                   W  Accessing hidden field Landroid/content/res/Configuration;->userSetLocale:Z (unsupported, reflection, allowed)
2024-06-08 18:54:30.681  9092-9092  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/IActivityManager$Stub$Proxy;->updateConfiguration(Landroid/content/res/Configuration;)Z (max-target-o, reflection, denied)
2024-06-08 18:54:30.681  9092-9092  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/IActivityManager;->updateConfiguration(Landroid/content/res/Configuration;)Z (max-target-r, reflection, allowed)
2024-06-08 18:54:30.897  9092-9092  LocaleSettingReceiver   io.appium.settings                   I  Set locale: ja_JP
KazuCocoa commented 3 months ago

targetSdkVersion 33 gradle config requires this relaxing hidden policy. So it would be nice to address this hidden api policy at least

KazuCocoa commented 3 months ago

Exception example via adb logcat with the denied behavior

2024-06-08 19:34:13.195  3567-3567  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/IActivityManager$Stub$Proxy;->updateConfiguration(Landroid/content/res/Configuration;)Z (max-target-o, reflection, denied)
2024-06-08 19:34:13.195  3567-3567  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/IActivityManager;->updateConfiguration(Landroid/content/res/Configuration;)Z (max-target-r, reflection, denied)
2024-06-08 19:34:13.196  3567-3567  APPIUM SETTINGS(LOCALE) io.appium.settings                   E  Failed to set locale
                                                                                                    java.lang.NoSuchMethodException: android.app.IActivityManager$Stub$Proxy.updateConfiguration [class android.content.res.Configuration]
                                                                                                        at java.lang.Class.getMethod(Class.java:2937)
                                                                                                        at java.lang.Class.getMethod(Class.java:2449)
                                                                                                        at io.appium.settings.handlers.LocaleSettingHandler.setLocaleWith(LocaleSettingHandler.java:72)
                                                                                                        at io.appium.settings.handlers.LocaleSettingHandler.setLocale(LocaleSettingHandler.java:40)
                                                                                                        at io.appium.settings.receivers.LocaleSettingReceiver.onReceive(LocaleSettingReceiver.java:97)
                                                                                                        at android.app.ActivityThread.handleReceiver(ActivityThread.java:4449)
                                                                                                        at android.app.ActivityThread.-$$Nest$mhandleReceiver(Unknown Source:0)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2256)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:205)
                                                                                                        at android.os.Looper.loop(Looper.java:294)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:8177)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
2024-06-08 19:34:13.196  3567-3567  LocaleSettingReceiver   io.appium.settings                   I  Set locale: en_US

This is allowed behavior:

2024-06-08 19:36:08.603  2321-2321  LocaleSettingReceiver   io.appium.settings                   I  Obtained locale: ja_JP
2024-06-08 19:36:08.658  2321-2321  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/ActivityManagerNative;->getDefault()Landroid/app/IActivityManager; (unsupported, reflection, allowed)
2024-06-08 19:36:08.658  2321-2321  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/IActivityManager$Stub$Proxy;->getConfiguration()Landroid/content/res/Configuration; (unsupported, reflection, allowed)
2024-06-08 19:36:08.662  2321-2321  appium.settings         io.appium.settings                   W  Accessing hidden field Landroid/content/res/Configuration;->userSetLocale:Z (unsupported, reflection, allowed)
2024-06-08 19:36:08.662  2321-2321  appium.settings         io.appium.settings                   W  Accessing hidden method Landroid/app/IActivityManager$Stub$Proxy;->updateConfiguration(Landroid/content/res/Configuration;)Z (max-target-o, reflection, allowed)
2024-06-08 19:36:09.083  2321-2321  LocaleSettingReceiver   io.appium.settings                   I  Set locale: ja_JP
github-actions[bot] commented 3 months ago

:tada: This issue has been resolved in version 5.12.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: