How to whitelist READ_PHONE_STATE permission (Privilaged Permissions)? - java

Android 10 changes the permissions For device identifiers so that all device identifiers are now protected by the READ_PRIVILEGED_PHONE_STATE permission. and I cannot find a way to Use READ_PHONE_STATE permission to get all those identifiers (e.g IMEI, IMSI and Build serial) using TelephonyManager.
I tried getImei() and getDeviceId() but I am still getting Null when I Call them all. I Know there should be a way to whitelist my app or permission but I don't know how!!!
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
telephonyManager.getImei(0);
telephonyManager.getDeviceId();

That permissions is not available for 3rd party apps installed via the Play store. Only OEM apps which are bundled with the platform can have that permission. This is outlined in the Android 10 notes:
https://developer.android.com/about/versions/10/privacy/changes

Related

checking if FOREGROUND_SERVICE permission is granted allways returns false

Having followed the migration notes and added the following line to the manifest :
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
I could not figure out why I am getting a failing test case where the permission android.permission.FOREGROUND_SERVICE is not being granted (at least when it's being checked on run-time).
Based on the docs, which states that android.permission.FOREGROUND_SERVICEshould be automatically granted by the system.
apps wanting to use foreground services must now request the
FOREGROUND_SERVICE permission first. This is a normal permission, so
the system automatically grants it to the requesting app.
Can somebody explain why my test case (which uses a variant of the the following code) is failing?
assertEquals(ActivityCompat.checkSelfPermission(activity, "android.permission.FOREGROUND_SERVICE"), PackageManager.PERMISSION_GRANTED);
Yet! I am not having any SecurityException thrown. What am I missing?
This is failing because you probably run it on device with API < 28. This method field works only on API 28 and up. If you write as you should Manifest.permission.FOREGROUND_SERVICE instead of plain string, Android Studio will warn you.
FOREGROUND_SERVICE is not a dangerous permission. Hence, it has nothing to do with the runtime permission system and methods like checkSelfPermission().

How to get "Device ID" from Android device under software update settings

Does anyone know of a way to retrieve the Device ID found under Settings -> About tablet -> System updates -> Software update settings under the Device information header in Android versions 4.x or 5.x?
Agreed with #G.hakim , but additional to that, this API requires android.permission.READ_PHONE_STATE permission.So you need to declare the permission in AndroidManifest.xml if you want to use this api:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
If i'm not wrong you are looking for your mobile phone's device id which you can get using these line of code
TelephonyManager tm = (TelephonyManager)context.GetSystemService(Context.TelephonyService);
deviceId = tm.DeviceId;
Also requires the following permission:
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
Also after Android Marshmallow Or API 23 you need to ask for permissions on the fly the code reference for that can be found here:
https://blog.xamarin.com/requesting-runtime-permissions-in-android-marshmallow/

hide another application in Android

I'm trying to hide another application by using the following code:
PackageManager pm = this.getPackageManager();
pm.setComponentEnabledSetting(new ComponentName("com.sas.remotesample",".Player"),
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
and with the following permission:
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>
but it throws
java.lang.SecurityException: Permission Denial: attempt to change component state
CHANGE_COMPONENT_ENABLED_STATE has a protectionLevel of signature|privileged. This means that either:
You have to build your own custom ROM, then sign your app with the same signing key that you used to sign your custom ROM. Then, devices with your custom ROM installed will allow your app to control component states of other apps.
Your app has to be pushed to the system partition on rooted devices by their users.
Otherwise, you cannot hold this permission. Or, as the documentation for the permission states, "Not for use by third-party applications".

Android HTC/Sony External Storage Permission Denied

I do not understand what is going on here.
I get permission denied try trying to access External Storage on HTC Wildfire S although i set
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
in the manifest file.
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state))
return false.
File storage= new File(Environment.getExternalStorageDirectory(),FILENAME);
By calling storage.createNewFile(); i get permission denied.
Stacktrace: java.io.IOException: Permission denied
NOTE: The same application is working correctly on all Android Samsung devices. I have the problem only on HTC and Sony devices
Thanks for your help
Is your device plugged in your PC (USB) ? Did you check the status of your SDCard (how it is mounted, USB options while plugged in) ?
For this error : java.io.IOException: Permission denied
The destination file may aldready exist. Did you check that ?
I get the anwser by myself.
Quiet simple: i just use internal storage instead of
External one.

Java.lang.SecurityException:SECURE PERMISSION in android?

Iam getting this error on my log
07-06 06:22:07.419: ERROR/AndroidRuntime(2618): java.lang.SecurityException: SECURE PERMISSION: Neither user 10070 nor current process has android.permission.WRITE_SECURE_SETTINGS.
I used like this
in activity file
private static final String SECURE_SETTINGS = android.Manifest.permission.WRITE_SECURE_SETTINGS;
mContext.enforceCallingOrSelfPermission(SECURE_SETTINGS,
"BLUETOOTH_ADMIN permission");
in manifest file
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
Why does it give error?
The WRITE_SECURE_SETTINGS permission is not available to apps which aren't part of the firmware because secure settings are designed to be secured against modification by third party apps.
You can only read this settings if your phone doesn't have root access. To enable bluetooth you can use this references http://developer.android.com/guide/topics/wireless/bluetooth.html.
However, this is above sdk5... I'm not really sure if it is a good idea to use bluetooth with sdk3. I also wanted to do an app which uses bluetooth and I had to switch my target level to above 2.0.1 because bluetooth below this sdk is not supported very well.

Categories

Resources