Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
KazuCocoa opened this issue Jun 8, 2024 · 6 comments · Fixed by #182
Closed

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

KazuCocoa opened this issue Jun 8, 2024 · 6 comments · Fixed by #182
Labels

Comments

@KazuCocoa
Copy link
Member

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:

  • update readme to address the hidden API pocily
  • see if we have a way to change locale etc without hidden API policy stuff (if exists)

The emulator version was API level 34.

@mykola-mokhnach
Copy link
Contributor

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

@KazuCocoa
Copy link
Member Author

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

This comment was marked as duplicate.

@KazuCocoa
Copy link
Member Author

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

@KazuCocoa
Copy link
Member Author

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

Copy link

github-actions bot commented Jun 9, 2024

🎉 This issue has been resolved in version 5.12.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants