Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c650bf58 authored by Wei Huang's avatar Wei Huang
Browse files

Get rid of Settings.getJIDResource(), which really should live in...

Get rid of Settings.getJIDResource(), which really should live in GTalkService. Add API to store the JID resource in IM provider settings.
parent adb4a72d
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -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;
@@ -2046,6 +2057,23 @@ public class Im {
                return getLong(SETTING_HEARTBEAT_INTERVAL, 0L /* an invalid default interval */);
            }

            /**
             * 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.
+0 −38
Original line number Diff line number Diff line
@@ -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);
@@ -3621,42 +3619,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