Neil Traft
Neil Traft

Reputation: 19706

Change the device ID on an Android emulator?

Is there a way to change the IMEI that will be returned by the emulator's TelephonyManager? Also, is there a way to change the ID returned by Settings.Secure.ANDROID_ID?

I use these IDs to distinguish my users from one another when storing their data on the server side. It would be nice if my QA team could change these IDs so that they are not all using the same set of user data.

Upvotes: 7

Views: 56833

Answers (8)

hannes ach
hannes ach

Reputation: 17743

Additional to @zyc-zyc answer

settings get secure android_id

settings put secure android_id xxxxxxxxxxxxxxxx

Which doesn't work at least on Android P (28) I tried to update via sql

adb shell content delete --uri content://settings/secure --where "name=\'android_id\'"

adb shell content insert --uri content://settings/secure --bind name:s:android_id --bind value:s:XYXYXYX

check the result:

adb shell content query --uri content://settings/secure --where "name=\'android_id\'"

Row: 0 _id=186, name=android_id, value=XYXYXYX

adb shell settings get secure android_id

XYXYXYX

Update works, but all solutions have no affect in device when I read value

Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID)

Upvotes: 1

Tim Baverstock
Tim Baverstock

Reputation: 568

In case you still need to change the IMEI, and need to do it from a script:

EMU=$ANDROID_BASE/emulator/qemu/linux-x86_64/qemu-system-x86_64
p=$$ # Something unique enough
perl -e '
  $imei=substr("'$p'"."0"x15,0,15); $/=undef;
  open IN, "'$EMU'" or die "$!"; $b=<IN>; close IN;
  $b=~s/(\+CGSN.)0{15}/${1}$imei/;
  open OUT, ">'$EMU'-imei" or die "$!"; print OUT $b ; close OUT
'

then move your original qemu-system-x86_64 binary so you can rename the new -imei one into its place. Use CIMI in the $b=~ line instead of CGSN to change the IMSI (copy and adapt the $b=~ line if you need both).

Obviously you'll need a different path for Mac/Windows.

Upvotes: 2

Hoa Nguyen
Hoa Nguyen

Reputation: 705

Wipe Data

Hi, I just wipe the data of the emulator. It's resolved. But mean your "new" device.

Upvotes: 0

user823738
user823738

Reputation: 17521

Since Oreo, android id is unique per user per package and stored in:

/data/system/users/(user_id)/settings_ssaid.xml

There's even an open-source project on github with prebuilt binaries that can query and modify the id for you. You will need root access, however, that should be not an issue on emulators.

Changes seem to take effect only after reboot.

Upvotes: 2

aorlando
aorlando

Reputation: 668

answer of zyc zyc is the best one until android 7.1.1 (25). From android 8 rules of android_id has changed as described in the official developer documentation: https://android-developers.googleblog.com/2017/04/changes-to-device-identifiers-in.html

In O, Android ID (Settings.Secure.ANDROID_ID or SSAID) has a different value for each app and each user on the device. Developers requiring a device-scoped identifier, should instead use a resettable identifier, such as Advertising ID, giving users more control. Advertising ID also provides a user-facing setting to limit ad tracking. Additionally in Android O: The ANDROID_ID value won't change on package uninstall/reinstall, as long as the package name and signing key are the same. Apps can rely on this value to maintain state across reinstalls. If an app was installed on a device running an earlier version of Android, the Android ID remains the same when the device is updated to Android O, unless the app is uninstalled and reinstalled. The Android ID value only changes if the device is factory reset or if the signing key rotates between uninstall and reinstall events. This change is only required for device manufacturers shipping with Google Play services and Advertising ID. Other device manufacturers may provide an alternative resettable ID or continue to provide ANDROID ID.

Upvotes: 4

zyc zyc
zyc zyc

Reputation: 3885

query android_id use this command in adb shell:

settings get secure android_id

change android_id use this command in adb shell:

settings put secure android_id xxxxxxxxxxxxxxxx

Upvotes: 2

Oren
Oren

Reputation: 1906

As far as Settings.Secure.ANDROID_ID goes, this should do the trick:

adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "UPDATE secure SET value='newid' WHERE name='android_id'"

Where newid is usually the 16 hex digit code (i.e. don't append "Android_" to it).
I only tried this on the emulator. I imagine a real phone would need to be rooted first.

Upvotes: 8

Ginger McMurray
Ginger McMurray

Reputation: 1157

I haven't tried it, but this page outlines a method that involves manually modifying the emaultor.exe file. It seems pretty straightforward, though you'd have to create a separate emulator for each QA team member.

Upvotes: 2

Related Questions