am d0688beb: Merge "Sanity check users before committing new Android ID" into klp-dev

* commit 'd0688beb6890ca3888d08d250ad33655a2a588d5':
  Sanity check users before committing new Android ID
This commit is contained in:
Christopher Tate
2013-09-03 17:51:18 -07:00
committed by Android Git Automerger

View File

@@ -33,6 +33,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
import android.database.AbstractCursor; import android.database.AbstractCursor;
import android.database.Cursor; import android.database.Cursor;
@@ -477,6 +478,13 @@ public class SettingsProvider extends ContentProvider {
try { try {
final String value = c.moveToNext() ? c.getString(0) : null; final String value = c.moveToNext() ? c.getString(0) : null;
if (value == null) { if (value == null) {
// sanity-check the user before touching the db
final UserInfo user = mUserManager.getUserInfo(userHandle);
if (user == null) {
// can happen due to races when deleting users; treat as benign
return false;
}
final SecureRandom random = new SecureRandom(); final SecureRandom random = new SecureRandom();
final String newAndroidIdValue = Long.toHexString(random.nextLong()); final String newAndroidIdValue = Long.toHexString(random.nextLong());
final ContentValues values = new ContentValues(); final ContentValues values = new ContentValues();
@@ -490,7 +498,7 @@ public class SettingsProvider extends ContentProvider {
Slog.d(TAG, "Generated and saved new ANDROID_ID [" + newAndroidIdValue Slog.d(TAG, "Generated and saved new ANDROID_ID [" + newAndroidIdValue
+ "] for user " + userHandle); + "] for user " + userHandle);
// Write a dropbox entry if it's a restricted profile // Write a dropbox entry if it's a restricted profile
if (mUserManager.getUserInfo(userHandle).isRestricted()) { if (user.isRestricted()) {
DropBoxManager dbm = (DropBoxManager) DropBoxManager dbm = (DropBoxManager)
getContext().getSystemService(Context.DROPBOX_SERVICE); getContext().getSystemService(Context.DROPBOX_SERVICE);
if (dbm != null && dbm.isTagEnabled(DROPBOX_TAG_USERLOG)) { if (dbm != null && dbm.isTagEnabled(DROPBOX_TAG_USERLOG)) {