am 66cc5900
: Merge change Ic70239e8 into eclair-mr2
Merge commit '66cc5900a53b22326bce053973730a301732efe9' into eclair-mr2-plus-aosp * commit '66cc5900a53b22326bce053973730a301732efe9': changed SettingsProvider to manage the androidid itself
This commit is contained in:
@ -17,6 +17,9 @@
|
|||||||
package com.android.providers.settings;
|
package com.android.providers.settings;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import android.backup.BackupManager;
|
import android.backup.BackupManager;
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
@ -26,6 +29,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.AssetFileDescriptor;
|
import android.content.res.AssetFileDescriptor;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.database.SQLException;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteQueryBuilder;
|
import android.database.sqlite.SQLiteQueryBuilder;
|
||||||
import android.media.Ringtone;
|
import android.media.Ringtone;
|
||||||
@ -189,9 +193,41 @@ public class SettingsProvider extends ContentProvider {
|
|||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
mOpenHelper = new DatabaseHelper(getContext());
|
mOpenHelper = new DatabaseHelper(getContext());
|
||||||
mBackupManager = new BackupManager(getContext());
|
mBackupManager = new BackupManager(getContext());
|
||||||
|
|
||||||
|
if (!ensureAndroidIdIsSet()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean ensureAndroidIdIsSet() {
|
||||||
|
final Cursor c = query(Settings.Secure.CONTENT_URI,
|
||||||
|
new String[] { Settings.NameValueTable.VALUE },
|
||||||
|
Settings.NameValueTable.NAME + "=?",
|
||||||
|
new String[]{Settings.Secure.ANDROID_ID}, null);
|
||||||
|
try {
|
||||||
|
final String value = c.moveToNext() ? c.getString(0) : null;
|
||||||
|
if (value == null) {
|
||||||
|
final SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
||||||
|
final String newAndroidIdValue = Long.toHexString(random.nextLong());
|
||||||
|
Log.d(TAG, "Generated and saved new ANDROID_ID");
|
||||||
|
final ContentValues values = new ContentValues();
|
||||||
|
values.put(Settings.NameValueTable.NAME, Settings.Secure.ANDROID_ID);
|
||||||
|
values.put(Settings.NameValueTable.VALUE, newAndroidIdValue);
|
||||||
|
final Uri uri = insert(Settings.Secure.CONTENT_URI, values);
|
||||||
|
if (uri == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
c.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cursor query(Uri url, String[] select, String where, String[] whereArgs, String sort) {
|
public Cursor query(Uri url, String[] select, String where, String[] whereArgs, String sort) {
|
||||||
SqlArguments args = new SqlArguments(url, where, whereArgs);
|
SqlArguments args = new SqlArguments(url, where, whereArgs);
|
||||||
|
Reference in New Issue
Block a user