How to identify Android devices correctly

Hello everyone! If you need to create a unique and stable Android device identifier for use inside an application, then you probably noticed the chaos that is present in the documentation and in the answers on stackoverflow . Let's take a look at how to tackle this challenge in 2020. In this brief overview, where to get an identifier that is resistant to reinstalling your application, and what difficulties may be in the future. Go!





Why identification is needed

Recently, discussions about the privacy of user data are gaining popularity. Perhaps this is due to the growing revenue of advertising giants. Perhaps underneath these discussions is concern about monopolies that identify users and their devices. So, Apple, fighting surveillance and limiting all developers to use IDFA, at the same time does not limit it to itself . What can be said for sure: the process of identifying a user of an application for developers has become more complicated. 





Identification-based tasks include return analytics, content and advertising personalization, and fraud prevention. 





Among the latter, there are several urgent problems:





  1. Shared accounts in services with paid subscriptions or unique paid content. Just imagine how much services like Netflix or Coursera are losing when users have one account for several people.





  2. Account theft.





Both problems lead to either loss of revenue or reputational loss. The reliability of their solution directly depends on the reliability of device identification. 





Basic identification methods

  1. Using hardware identifiers

Outdated and currently not viable method. Google has done a good job of blocking access to them as they don't change even after a factory reset. Among such identifiers:





  1. IMEI





  2. IMSI





  3. MAC address





. , , Play Market. , . . 





, : , .





  1. UUID

cookie: , ( SharedPreferences), . , cookie — . . 





- . — . (app instance ID). 





  1. ,

ANDROID_ID. , , , . Android 8.0 , — . ( ).





, . ( ) Google . , , ( 2020 ). 





:





<uses-permission android:name="com.google.android.providers.gsf.permission.READGSERVICES" />
      
      



:





public static String getGsfAndroidId(Context context) {
  String params[] = { ID_KEY };
  Cursor c = context.getContentResolver().query(URI, null, null, params,
                                                null);
  if (!c.moveToFirst() || c.getColumnCount() < 2)
    return null;
  try {
    return Long.toHexString(Long.parseLong(c.getString(1)));
  } catch (NumberFormatException e) {
    return null;
  }
}
      
      



: ContentProvider-a, Google. , Google . , .. Play Market.





. , , Xposed, ANDROID_ID, GSF_ID. , . 





The Device ID Changer app in conjunction with Xposed allows you to change almost any identifier.  Free version - only ANDROID_ID
Device ID Changer Xposed . — ANDROID_ID
  1. (fingerprint)  

device-fingerprinting , . — FingerprintJS — 13 GitHub. cookie. 





( ).





- Android-. 4 . Samsung? , 600 . Samsung , Android 9? 150 . , ? , , . 25000 . , . — , . , . 





Android, , , , , . 





, . .





— (   ANDROID_ID), . — . 





— . , . , , . — , . 





, .





, . ? ,   . .  





— . , . , . , android-arsenal, , .





  1. Android-device-identification — . , , , ANDROID_ID, Build. , 2 , . , , .





  2. Fingerprint-android — . 2 : getDeviceId getFingerprint. GSF_ID ANDROID_ID, , , . getFingerprint — . . , Kotlin, .





, ,   ANDROID_ID GSF_ID. Android, , .





If you have questions or additions - share them in the comments. And that's all, thanks for your attention! 












All Articles