4

Using API 25 on an emulator:

adb shell settings put secure android_id 8af8770a27cfd182
adb shell settings get secure android_id //gives 8af8770a27cfd182
Secure.getString(context.getContentResolver(), Secure.ANDROID_ID) //gives 8af8770a27cfd182

Using API 26 on an emulator:

adb shell settings put secure android_id 8af8770a27cfd182
adb shell settings get secure android_id //gives 8af8770a27cfd182
Secure.getString(context.getContentResolver(), Secure.ANDROID_ID) //gives 6e4f84f5513b80e1

I've read about the changes of ANDROID_ID between API 25 and 26 but why is adb and code giving me different results for it?

UPDATE:

Created a simple app to take out the complexity of the old one. New app has a single main activity with a button on it:

package com.example.diolaj01.testandroidid;

import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}

protected void GetAndroidId(View view){
    Log.e("myDebugTag", Settings.Secure.getString(view.getContext().getContentResolver(),
            Settings.Secure.ANDROID_ID));

}
}

When clicking the button on a device with API 25 I get the same value as when requesting the ANDROID_ID from adb:

adb shell settings get secure android_id

If I change the android_id I still get the updated one in both the console using the button and using adb.

When clicking the button on a device with API 26 I get a different value than the one I get when using adb. If I change the android_id using adb I'll get the updated value when using adb but not using the button.

Jason
  • 437
  • 1
  • 5
  • 15
  • can u share your code – Goku Nov 29 '17 at 11:07
  • may be this links can solve your problem https://stackoverflow.com/questions/14891738/settings-secure-android-id-is-not-unique-how-to-solve -- https://stackoverflow.com/questions/13744565/android-device-id-confusion – ND1010_ Nov 29 '17 at 11:14
  • @ND1010_ **`IMEI`** is deprecated in api 26 – Goku Nov 29 '17 at 11:18
  • @Prem that's why i tell him that may be please read cmt first bfr any comment – ND1010_ Nov 29 '17 at 11:20
  • @Prem It's not a simple app I can share unfortunately. In the end to end test using adb I get one value and in code logging the output I get another value (same test run session obviously). I was just hoping for someone to say that this is normal for whatever reason or that it shouldn't happen, in which case I have another issue. – Jason Nov 29 '17 at 11:23
  • @ND1010_ from what I understand the content of the links apply to older API versions and APi 26 changes the functionality. If there's something specific in the links that have to do with the question of having different values in adb and in code let me know – Jason Nov 29 '17 at 11:26
  • @Jason are you using this **`tm.getDeviceId()`**..? – Goku Nov 29 '17 at 11:27
  • @Prem nope, not using TelephonyManager, just the third line in the original post in order to get the ANDROID_ID value – Jason Nov 29 '17 at 11:31
  • @Jason **`TelephonyManager.getDeviceId()`** is deprecated in api 26 – Goku Nov 29 '17 at 11:32
  • @Prem not using TelephonyManager – Jason Nov 29 '17 at 11:36

1 Answers1

5

From https://developer.android.com/about/versions/oreo/android-8.0-changes.html#privacy-all

Privacy Android 8.0 (API level 26) makes the following privacy-related changes to the platform.

The platform now handles identifiers differently.

For apps that were installed prior to an OTA to a version of Android 8.0 (API level 26) (API level 26), the value of ANDROID_ID remains the same unless uninstalled and then reinstalled after the OTA. To preserve values across uninstalls after OTA, developers can associate the old and new values by using Key/Value Backup.

For apps installed on a device running Android 8.0, the value of ANDROID_ID is now scoped per app signing key, as well as per user. The value of ANDROID_ID is unique for each combination of app-signing key, user, and device. As a result, apps with different signing keys running on the same device no longer see the same Android ID (even for the same user).

The value of ANDROID_ID does not change on package uninstall or reinstall, as long as the signing key is the same (and the app was not installed prior to an OTA to a version of Android 8.0).

The value of ANDROID_ID does not change even if a system update causes the package signing key to change.

On devices shipping with Google Play services and Advertising ID, you must use Advertising ID. A simple, standard system to monetize apps, Advertising ID is a unique, user-resettable ID for advertising. It is provided by Google Play services.

Other device manufacturers should continue to provide ANDROID_ID.

The shell user is different from your app's user id - thus the difference.

chwarr
  • 5,726
  • 1
  • 24
  • 52
Alex P.
  • 27,029
  • 16
  • 103
  • 156
  • 1
    Thanks Alex, but this doesn't mention anything about the difference in what is returned when querying from adb and from code? Unless it's implied and I can't see it? – Jason Nov 29 '17 at 15:04
  • 5
    It is implied. *The value of `ANDROID_ID` is unique for each combination of app-signing key, user, and device. As a result, apps with different signing keys running on the same device no longer see the same Android ID*. The `shell` user is different from your app's user id - thus the difference – Alex P. Nov 29 '17 at 15:07