Operation not allowed java lang securityexception
Ошибка при русификации смартфона Xiaomi с помощью MoreLocale 2
Сегодня пишем очередное дополнение. На этот раз к инструкции по русификации смартфона Xiaomi с помощью приложения MoreLocale 2. К сожалению, не у всех пользователей, она проходит гладко, о чем нам было сообщено с помощью формы обратной связи. Проблема, на которую были жалобы — это ошибка приблизительно такого вида:
C:ADB>adb shell pm grant jp.co.c_lis.ccl.morelocale android.permission.CHANGE_CONFIGURATION
Operation not allowed: java.lang.SecurityException: grantRuntimePermission: Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS.
Она возникает, если не активировать пункт USB Debugging (Security settings) в меню «Для разработчиков» (смотреть пункт 5.1 инструкции по русификации).
Но, при попытке его активации, возникает еще одна ошибка: «This devices is temporarily restricted». Для ее устранения необходимо:
- Отключить Wi-Fi и включить мобильный интернет. На телефоне должен быть Mi аккаунт
- Перезагрузиться и попробовать еще раз включить пункт «USB Debugging (Security settings)».
Если случилось так, что после этого ошибка не пропала и пункт по прежнему не включается, то нам придется воспользоваться VPN, чтобы показать смартфону, что он соединяется с сервером из Китая. Рассмотрим на примере бесплатного сайта VPNGate. Вы можете использовать любой другой.
- Заходим на сайт VPNGate. Здесь нам нужно выбрать китайский сервер с поддержкой L2TP/IPsec. Листаем вниз главную страницу, снимаем все лишние галочки (как на скриншоте) и нажимаем кнопку «Refresh server list»
Опять к сайту. Открываем ссылку L2TP/IPsec Connect guide. И увидим данные, которых нам не достает для подключения, а именно: Username (Имя пользователя); Password (Пароль); Pre-shared Key (Secret) (Общий ключ IPSec). В данном случае, все три одинаковые и имеют значение: vpn.

java.lang.SecurityException
This small simple program compiles but while executing it throws
java.lang.SecurityException. etc
I have read that this exception signals that an operation is not permitted for security reasons. Hm..no idea how that can support this problem.
package java;
import java.io.*;
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(reader);
for(;;) <
System.out.println(«Geb nen Radius ein. «);
String input = in.readLine();
// int r = Integer.parseInt(input);
if (input == null) break;
int r = Integer.parseInt(input);
double c =PI * r * r;
System.out.println(«Der Umfang betr�gt» + c);
>
>catch (IOException e)
- 29 Просмотров
- Метки: нет (добавить)
1. Re: java.lang.SecurityException
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
2. Re: java.lang.SecurityException
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
3. Re: java.lang.SecurityException
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
4. Re: java.lang.SecurityException
Thanks for the response but it still doesn�t work. Now (including your suggestion) it looks like that:
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(reader);
for(;;) <
System.out.println(«Geb nen Radius ein. «);
String input = in.readLine();
// int r = Integer.parseInt(input);
if (input == null) break;
int r = Integer.parseInt(input);
double c =PI * r * r;
System.out.println(«Der Umfang betr�gt» + c);
>
>catch (IOException e)
But it still throws this exception.
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
5. Re: java.lang.SecurityException
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
6. Re: java.lang.SecurityException
Sorry.
Here is the exception:
java.lang.SecurityException: Prohibited package name: java
at java.lang.ClassLoader.defineClass(ClassLoader.java:477)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
7. Re: java.lang.SecurityException
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
8. Re: java.lang.SecurityException
It seems it is still using your old .class file!
Delete the class file and recompile. This should work
- Мне нравится Показать отметки «Мне нравится» (0) (0)
- Действия
9. Re: java.lang.SecurityException
LOOK at the posts timestamps!!
What is this, a RACE!! :-))
Error: Requires permission android.permission.WRITE_SECURE_SETTINGS #5
Comments
Copy link Quote reply
CoderBuck commented Apr 6, 2017 •
XiaoMi4 Android 6.0 MIUI8
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 6, 2017 •
Arf, it seems that your shell user does not have this permission… It should have it.
This requirement (a bit hacky) had been introduced by commit e7b8407 (the commit message provides some details).
Does anyone have an idea to get the same «restriction» without the WRITE_SECURE_SETTINGS permission?
This comment has been minimized.
Copy link Quote reply
yashrajtalan commented Apr 10, 2017 •
Have same issue with Xiaomi Redmi 3S Prime MIUI8 Android 6.0.1
Permissions granted to the app according to the phone are ‘full network access’ and ‘view network connections’.
When I try
adb shell pm grant com.genymobile.gnirehtet android.permission.WRITE_SECURE_SETTINGS
I get
Operation not allowed: java.lang.SecurityException: grantRuntimePermission: Neither user 2000 nor current process has android.permission.GRANT_RUNTIME_PERMISSIONS.
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 12, 2017 •
@CoderBuck @yashrajtalan Could you give the permissions of your Android shell, please?
First, locate Shell.apk :
Finally, print its permissions:
( aapt is available in $ANDROID_SDK/build-tools/25.0.2/aapt , or there is an aapt package in Debian)
Maybe we could find a better permission which works also for your devices 😉
This comment has been minimized.
Copy link Quote reply
CoderBuck commented Apr 12, 2017 •
This comment has been minimized.
Copy link Quote reply
CoderBuck commented Apr 12, 2017
I am not familiar with this ;-0
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 12, 2017 •
Try with cmd.exe instead, since git bash mangles pathes at some point.
This comment has been minimized.
Copy link Quote reply
CoderBuck commented Apr 12, 2017
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 12, 2017 •
OK so it declares using android.permission.WRITE_SECURE_SETTINGS .
Could you give the result of the following commands, please:
EDIT: in fact, these commands will not help.
This comment has been minimized.
Copy link Quote reply
CoderBuck commented Apr 12, 2017
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 12, 2017
- android.permission.WRITE_SECURE_SETTINGS has protection level «signature»
- sending the intent from shell leads to error Requires permission android.permission.WRITE_SECURE_SETTINGS
- shell declares using the permission android.permission.WRITE_SECURE_SETTINGS
One possibility is that Shell.apk is not signed with the same signature as the ROM. Which is very strange…
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 12, 2017
Could you replace android.permission.WRITE_SECURE_SETTINGS by android.permission.WRITE_SETTINGS (a permission with normal protection level) here, build, and try again, please?
If it works, it suggests that the problem is related to Shell.apk signature…
This comment has been minimized.
Copy link Quote reply
CoderBuck commented Apr 13, 2017
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 13, 2017
So you have a shell with no permissions… Can you find a permission listed from Shell.apk that does work?
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 14, 2017
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 14, 2017
The result of this command may also be interesting:
This comment has been minimized.
Copy link Quote reply
rom1v commented Apr 18, 2017
@CoderBuck @yashrajtalan Could you please give the result of:
This comment has been minimized.
Copy link Quote reply
yashrajtalan commented Apr 25, 2017
The issue seems to be resolved by heading over to Developer Options on MIUI, and enabling the following:
USB debugging -Debug mode when USB is connected
Install via USB -Allow installing apps via USB
USB debugging (Security Settings)— Allow granting permissions and simulating input via USB debugging
The first was already enabled, and I installed the apk file manually so I didn’t need the second option.
I’m guessing the issue can be pinned down to the last option, which allows granting the necessary permissions. @CoderBuck please confirm.
Thank you @rom1v for this amazing app. This is a worthy free replacement for ReverseTethering NoRoot.
java.lang.SecurityException – How to solve SecurityException
In this tutorial we will discuss about SecurityException in Java. This exception is thrown by the security manager, in order to indicate a security violation.
The SecurityException class extends the RuntimeException class and thus, belongs to those exceptions that can be thrown during the operation of the Java Virtual Machine (JVM). It is an unchecked exception and thus, it does not need to be declared in a method’s or a constructor’s throws clause.
Finally the SecurityException class exists since the 1.0 version of Java.
The Structure of SecurityException
Constructors
- SecurityException()
Creates an instance of the SecurityException class, setting null as its message.
SecurityException(String s)
Creates an instance of the SecurityException class, using the specified string as message. The string argument indicates the name of the class that threw the error.
SecurityException(String message, Throwable cause)
Creates an instance of the SecurityException class, using the specified string as message and the specified Throwable as its cause.
SecurityException(Throwable cause)
Creates an instance of the SecurityException class, using the specified Throwable as its cause.
The SecurityException in Java
The SecurityException indicates that a security violation has occurred an thus, the application cannot be executed. A simple example is to use a package name that is already defined in Java.
For example, let’s create a simple hierarchy, where the parent directory is called java and the sub-directory is called util . Then, we create a sample Java class inside the java/util/ directory, which only prints a message:
We compile and execute our sample code by issuing the following commands:
A sample execution is shown below:
When the Java Virtual Machine (JVM) tries to load our class, it recognizes its package name as invalid and thus, a SecurityException is thrown.
How to deal with the SecurityException
- In the aforementioned case, it is sufficient to change the package name of your application, in order to be executed by the Java Virtual Machine (JVM). In general, you must avoid using package names that are reserved by Java.
- Sometimes, executing a .jar file can result in a SecurityException be possibly thrown. In such cases, you must verify that the .jar file is properly signed, otherwise you will not be able to execute it. For more information on how to sign a .jar please refer to the instructions here.
- Finally, running an applet from an external source may also result in a SecurityException be thrown. The most frequent reason is that Java applications are blocked by the underlying security settings. For more information on how to change these settings and how to update your Exception Site list, please refer to the instructions here.
Like This Article? Read More From Java Code Geeks
This site uses Akismet to reduce spam. Learn how your comment data is processed.
thanks sir..
security exception is a rare topic i found in internet and the best of them are gets from your site..