According to Google, the ANDROID_ID (also known as SSAID) should not be accessible on Android 10 systems, without some preconditions (see: https://developer.android.com/about/versions/10/privacy/changes)
• If your app targets Android 10 or higher, a SecurityException occurs.
• If your app targets Android 9 (API level 28) or lower, the method
returns null or placeholder data if the app has the READ_PHONE_STATE
permission. Otherwise, a SecurityException occurs.
My problem here is, that I am still able to access the ANDROID_ID without any of above mentioned preconditions.
I created a Kotlin project with target platform Android 10 API level 29.
In this project I ran this code:
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.provider.Settings
import android.util.Log
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Log.i("ANDROID ID", "##### READ Android ID ######")
try {
val my_android_id = Settings.Secure.getString(this.contentResolver, Settings.Secure.ANDROID_ID)
Log.i("ANDROID ID", my_android_id)
}
catch (e: SecurityException){
Log.i("ANDROID ID", "Secure Exception!")
}
}
}
The result is, that the ANDROID_ID gets written to the logcat without any problem. The value is no dummy value but the actual ANDROID_ID. This has been tested on a simulator and on a real device (Pixel 2).