diff options
| -rw-r--r-- | core/java/android/provider/Im.java | 28 | ||||
| -rw-r--r-- | core/java/android/provider/Settings.java | 38 |
2 files changed, 28 insertions, 38 deletions
diff --git a/core/java/android/provider/Im.java b/core/java/android/provider/Im.java index b11abe844daf..b1cf6485f54c 100644 --- a/core/java/android/provider/Im.java +++ b/core/java/android/provider/Im.java @@ -1620,6 +1620,9 @@ public class Im { /** specifies the last heartbeat interval received from the server */ public static final String SETTING_HEARTBEAT_INTERVAL = "heartbeat_interval"; + /** specifiy the JID resource used for Google Talk connection */ + public static final String SETTING_JID_RESOURCE = "jid_resource"; + /** * Used for reliable message queue (RMQ). This is for storing the last rmq id received * from the GTalk server @@ -1861,6 +1864,14 @@ public class Im { putLongValue(contentResolver, providerId, SETTING_HEARTBEAT_INTERVAL, interval); } + /** + * A convenience method to set the jid resource. + */ + public static void setJidResource(ContentResolver contentResolver, + long providerId, String jidResource) { + putStringValue(contentResolver, providerId, SETTING_JID_RESOURCE, jidResource); + } + public static class QueryMap extends ContentQueryMap { private ContentResolver mContentResolver; private long mProviderId; @@ -2047,6 +2058,23 @@ public class Im { } /** + * Set the JID resource. + * + * @param jidResource the jid resource to be stored. + */ + public void setJidResource(String jidResource) { + ProviderSettings.setJidResource(mContentResolver, mProviderId, jidResource); + } + /** + * Get the JID resource used for the Google Talk connection + * + * @return the JID resource stored. + */ + public String getJidResource() { + return getString(SETTING_JID_RESOURCE, null); + } + + /** * Convenience function for retrieving a single settings value * as a boolean. * diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 85a2041aae05..d3e4c4c97ac5 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -413,8 +413,6 @@ public final class Settings { private static final String TAG = "Settings"; - private static String sJidResource = null; - public static class SettingNotFoundException extends AndroidException { public SettingNotFoundException(String msg) { super(msg); @@ -3622,42 +3620,6 @@ public final class Settings { } /** - * Returns the GTalk JID resource associated with this device. - * - * @return String the JID resource of the device. It uses the device IMEI in the computation - * of the JID resource. If IMEI is not ready (i.e. telephony module not ready), we'll return - * an empty string. - * @hide - */ - // TODO: we shouldn't not have a permenant Jid resource, as that's an easy target for - // spams. We should change it once a while, like when we resubscribe to the subscription feeds - // server. - // (also, should this live in GTalkService?) - public static synchronized String getJidResource() { - if (sJidResource != null) { - return sJidResource; - } - - MessageDigest digest; - try { - digest = MessageDigest.getInstance("SHA-1"); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("this should never happen"); - } - - String deviceId = TelephonyManager.getDefault().getDeviceId(); - if (TextUtils.isEmpty(deviceId)) { - return ""; - } - - byte[] hashedDeviceId = digest.digest(deviceId.getBytes()); - String id = new String(Base64.encodeBase64(hashedDeviceId), 0, 12); - id = id.replaceAll("/", "_"); - sJidResource = JID_RESOURCE_PREFIX + id; - return sJidResource; - } - - /** * Returns the device ID that we should use when connecting to the mobile gtalk server. * This is a string like "android-0x1242", where the hex string is the Android ID obtained * from the GoogleLoginService. |