Saturday, November 29, 2014

http://www.androidwebterminal.com/

My pet project Android Web Terminal was homeless for few months. I found a new home and everyone is welcome http://www.androidwebterminal.com/

Thursday, September 4, 2014

Rooting Samsung Galexy S5 - Stuck or failed in flashing cache

Today I wanted to root my S5. When i rooted using CF-Auto-Root-k3g-k3gxx-smg900h.zip Odin got stuck in the flashing cache. I tried doing the same thing few times and still get stuck. Then i thought of trying with latest Odin v3.09 and it worked.

You can download Odin v3.09 from here
http://www.android.gs/download-odin-3-09/

Friday, August 29, 2014

Is 24 Hour date format in Android using java code.

private boolean is24HourFormat(Context context) {
   Locale locale = Locale.getDefault();
   java.text.DateFormat natural =
                java.text.DateFormat.getTimeInstance(java.text.DateFormat.LONG, locale);
   String value = "";
   if (natural instanceof SimpleDateFormat) {
            SimpleDateFormat sdf = (SimpleDateFormat) natural;
            String pattern = sdf.toPattern();
            if (pattern.indexOf('H') >= 0) {
                value = "24";
            } else {
                value = "12";
            }
        } else {
            value = "12";
        }
 
        return value.equals("24");
    }

Thursday, August 14, 2014

dalvikvm: DexOpt: source file mod time mismatch

Today, When I was running my app, I started to see this error

dalvikvm: DexOpt: source file mod time mismatch
dalvikvm: Cached DEX 'aaaa.zip' (/data/dalvik-cache/aaaa.zip@classes.dex) is stale and not writable
After Googling this error I could not found anything useful. Then I took a look at the /data/dalvik-cache/. There was a aaaa.zip@classes.dex already in this folder even the application was not installed. So I removed the existing file and did a new installation. all worked fine. 

I have not seen this error in previous versions of Android (below 4.4.2) . If you are going to launch a new pre-compiled zip make sure to remove previously cached files in /data/dalvik-cache/


Thursday, August 7, 2014

NullPointerException when new PhoneStateListener

When I new PhoneStateListener() I am getting this error

java.lang.NullPointerException
  at android.os.Handler.<init>(Handler.java:229)
  at android.os.Handler.<init>(Handler.java:137)
  at android.telephony.PhoneStateListener$2.<init>(PhoneStateListener.java:420)
  at android.telephony.PhoneStateListener.<init>(PhoneStateListener.java:420)

I looked at the Handler.java:. I believe the reason for this error is mQueue = looper.mQueue; so looper is null.  Only way to fix this problem is to call Looper.prepareMainLooper(); at the beginning of the process

Wednesday, July 30, 2014

How to check whether device is running CyanogenMod in Android

Today, I wanted to know how to detect whether device is running CyanogenMod. System.getProperty("os.version") used to return cyanogenmod however it is not the case when i checked it today. CyanogenMod. System.getProperty("os.version")  was returning something like 3.0.64-CM-g9d16c8a. So I wrote this function. Hope it will be use full for someone else.

private boolean isCyanogenMod(PackageManager pm) {
    boolean isCyanogenMod = false;
    String version = System.getProperty("os.version");
    BufferedReader reader = null;

    try {
        if (version.contains("cyanogenmod") || pm.hasSystemFeature("com.cyanogenmod.android")) {
            isCyanogenMod = true;
        }
        else {                
            // This does not require root
            reader = new BufferedReader(new FileReader("/proc/version"), 256);
            version = reader.readLine();

            if (version.contains("cyanogenmod")) {
                isCyanogenMod = true;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        if(reader != null) {
            try { reader.close(); } catch (IOException e) { }
        }
    }

    return isCyanogenMod;
}



Monday, July 28, 2014

Samsung S4 RILConstants class

No more magic ril requests.

package com.android.internal.telephony;

public abstract interface RILConstants
{
  public static final int BRIL_HOOK_PBK_READ_ENTRY_REQ = 10;
  public static final int BRIL_HOOK_PBK_SEND_INFO_REQ = 9;
  public static final int BRIL_HOOK_PBK_UPDATE_ENTRY_REQ = 11;
  public static final int BRIL_HOOK_POWER_ONOFF_CARD = 8;
  public static final int BRIL_HOOK_QUERY_SIM_PIN_REMAINING = 1;
  public static final int BRIL_HOOK_SET_BPM_MODE = 3;
  public static final int BRIL_HOOK_SET_FAST_DORMANCY = 12;
  public static final int BRIL_HOOK_SET_PREFDATA = 0;
  public static final int CDMA_CELL_BROADCAST_SMS_DISABLED = 1;
  public static final int CDMA_CELL_BROADCAST_SMS_ENABLED = 0;
  public static final int CDMA_PHONE = 2;
  public static final int CDM_TTY_FULL_MODE = 1;
  public static final int CDM_TTY_HCO_MODE = 2;
  public static final int CDM_TTY_MODE_DISABLED = 0;
  public static final int CDM_TTY_MODE_ENABLED = 1;
  public static final int CDM_TTY_VCO_MODE = 3;
  public static final int DATA_PROFILE_BIP = 1003;
  public static final int DATA_PROFILE_CAS = 1004;
  public static final int DATA_PROFILE_CBS = 4;
  public static final int DATA_PROFILE_CMDM = 9;
  public static final int DATA_PROFILE_CMMAIL = 10;
  public static final int DATA_PROFILE_DEFAULT = 0;
  public static final int DATA_PROFILE_DM = 8;
  public static final int DATA_PROFILE_E911 = 1001;
  public static final int DATA_PROFILE_EMBMS = 1002;
  public static final int DATA_PROFILE_FOTA = 3;
  public static final int DATA_PROFILE_HIPRI = 7;
  public static final int DATA_PROFILE_IMS = 2;
  public static final int DATA_PROFILE_MMS = 5;
  public static final int DATA_PROFILE_OEM_BASE = 1000;
  public static final int DATA_PROFILE_SUPL = 6;
  public static final int DATA_PROFILE_TETHERED = 1;
  public static final int DATA_PROFILE_WAP = 11;
  public static final int DEACTIVATE_REASON_NONE = 0;
  public static final int DEACTIVATE_REASON_PDP_RESET = 2;
  public static final int DEACTIVATE_REASON_RADIO_OFF = 1;
  public static final int DIAL_MODIFIED_TO_DIAL = 19;
  public static final int DIAL_MODIFIED_TO_SS = 18;
  public static final int DIAL_MODIFIED_TO_USSD = 17;
  public static final int DIAL_STR_TOO_LONG = 1004;
  public static final int FDN_CHECK_FAILURE = 14;
  public static final int GENERIC_FAILURE = 2;
  public static final int GSM_PHONE = 1;
  public static final int ILLEGAL_SIM_OR_ME = 15;
  public static final int IMS_PHONE = 5;
  public static final int INVALID_CHARACTERS_IN_DIAL_STR = 1006;
  public static final int INVALID_CHARACTERS_IN_TEXT_STR = 1005;
  public static final int INVALID_INDEX = 1002;
  public static final int INVALID_PARAMETER = 31;
  public static final int LTE_ON_CDMA_FALSE = 0;
  public static final int LTE_ON_CDMA_TRUE = 1;
  public static final int LTE_ON_CDMA_UNKNOWN = -1;
  public static final int MAX_INT = 2147483647;
  public static final int MEMORY_ERROR = 1001;
  public static final int MISSING_RESOURCE = 29;
  public static final int MODE_NOT_SUPPORTED = 13;
  public static final int NETWORK_MODE_CDMA = 4;
  public static final int NETWORK_MODE_CDMA_NO_EVDO = 5;
  public static final int NETWORK_MODE_EVDO_NO_CDMA = 6;
  public static final int NETWORK_MODE_GLOBAL = 7;
  public static final int NETWORK_MODE_GSM_ONLY = 1;
  public static final int NETWORK_MODE_GSM_UMTS = 3;
  public static final int NETWORK_MODE_LTE_CDMA_EVDO = 8;
  public static final int NETWORK_MODE_LTE_CMDA_EVDO_GSM_WCDMA = 10;
  public static final int NETWORK_MODE_LTE_GSM_WCDMA = 9;
  public static final int NETWORK_MODE_LTE_ONLY = 11;
  public static final int NETWORK_MODE_LTE_WCDMA = 12;
  public static final int NETWORK_MODE_TDSCDMA_PREF = 23;
  public static final int NETWORK_MODE_TD_SCDMA_CDMA_EVDO_GSM_WCDMA = 21;
  public static final int NETWORK_MODE_TD_SCDMA_GSM = 16;
  public static final int NETWORK_MODE_TD_SCDMA_GSM_LTE = 17;
  public static final int NETWORK_MODE_TD_SCDMA_GSM_WCDMA = 18;
  public static final int NETWORK_MODE_TD_SCDMA_GSM_WCDMA_LTE = 20;
  public static final int NETWORK_MODE_TD_SCDMA_LTE = 15;
  public static final int NETWORK_MODE_TD_SCDMA_LTE_CDMA_EVDO_GSM_WCDMA = 22;
  public static final int NETWORK_MODE_TD_SCDMA_ONLY = 13;
  public static final int NETWORK_MODE_TD_SCDMA_WCDMA = 14;
  public static final int NETWORK_MODE_TD_SCDMA_WCDMA_LTE = 19;
  public static final int NETWORK_MODE_WCDMA_ONLY = 2;
  public static final int NETWORK_MODE_WCDMA_PREF = 0;
  public static final int NOT_SUBCRIBED_USER = 28;
  public static final int NO_PHONE = 0;
  public static final int NO_SUCH_ELEMENT = 30;
  public static final int OPER_NOT_ALLOWED = 1000;
  public static final int OP_NOT_ALLOWED_BEFORE_REG_NW = 9;
  public static final int OP_NOT_ALLOWED_DURING_VOICE_CALL = 8;
  public static final int PASSWORD_INCORRECT = 3;
  public static final int PREFERRED_NETWORK_MODE = 0;
  public static final int RADIO_NOT_AVAILABLE = 1;
  public static final int REQUEST_CANCELLED = 7;
  public static final int REQUEST_NOT_SUPPORTED = 6;
  public static final int RIL_CHN_CDMA_REQUEST_BASE = 10057;
  public static final int RIL_CHN_REQUEST_BASE = 10053;
  public static final int RIL_CHN_REQUEST_LAST = 10057;
  public static final int RIL_ERRNO_INVALID_RESPONSE = -1;
  public static final int RIL_KOR_REQUEST_BASE = 10036;
  public static final int RIL_KOR_REQUEST_LAST = 10040;
  public static final int RIL_KOR_UNSOL_BASE = 11036;
  public static final int RIL_KOR_UNSOL_LAST = 11040;
  public static final int RIL_LTE_REQUEST_BASE = 10033;
  public static final int RIL_LTE_REQUEST_LAST = 10036;
  public static final int RIL_LTE_UNSOL_BASE = 11033;
  public static final int RIL_LTE_UNSOL_LAST = 11036;
  public static final int RIL_OEM_REQUEST_BASE = 10000;
  public static final int RIL_OEM_UNSOL_LAST = 11033;
  public static final int RIL_OEM_UNSOL_RESPONSE_BASE = 11000;
  public static final int RIL_REQUEST_ACCESS_PHONEBOOK_ENTRY = 10009;
  public static final int RIL_REQUEST_ACKNOWLEDGE_INCOMING_GSM_SMS_WITH_PDU = 106;
  public static final int RIL_REQUEST_ACTIVATE_DATA_CALL = 10036;
  public static final int RIL_REQUEST_ANSWER = 40;
  public static final int RIL_REQUEST_BASEBAND_VERSION = 51;
  public static final int RIL_REQUEST_CALL_DEFLECTION = 10011;
  public static final int RIL_REQUEST_CANCEL_USSD = 30;
  public static final int RIL_REQUEST_CDMA_BROADCAST_ACTIVATION = 94;
  public static final int RIL_REQUEST_CDMA_BURST_DTMF = 85;
  public static final int RIL_REQUEST_CDMA_DELETE_SMS_ON_RUIM = 97;
  public static final int RIL_REQUEST_CDMA_FLASH = 84;
  public static final int RIL_REQUEST_CDMA_GET_BROADCAST_CONFIG = 92;
  public static final int RIL_REQUEST_CDMA_GET_DATAPROFILE = 10045;
  public static final int RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE = 104;
  public static final int RIL_REQUEST_CDMA_GET_SYSTEMPROPERTIES = 10047;
  public static final int RIL_REQUEST_CDMA_QUERY_PREFERRED_VOICE_PRIVACY_MODE = 83;
  public static final int RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE = 79;
  public static final int RIL_REQUEST_CDMA_SEND_SMS = 87;
  public static final int RIL_REQUEST_CDMA_SEND_SMS_EXPECT_MORE = 10040;
  public static final int RIL_REQUEST_CDMA_SET_BROADCAST_CONFIG = 93;
  public static final int RIL_REQUEST_CDMA_SET_DATAPROFILE = 10046;
  public static final int RIL_REQUEST_CDMA_SET_PREFERRED_VOICE_PRIVACY_MODE = 82;
  public static final int RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE = 78;
  public static final int RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE = 77;
  public static final int RIL_REQUEST_CDMA_SET_SYSTEMPROPERTIES = 10048;
  public static final int RIL_REQUEST_CDMA_SMS_ACKNOWLEDGE = 88;
  public static final int RIL_REQUEST_CDMA_SUBSCRIPTION = 95;
  public static final int RIL_REQUEST_CDMA_VALIDATE_AND_WRITE_AKEY = 86;
  public static final int RIL_REQUEST_CDMA_WRITE_SMS_TO_RUIM = 96;
  public static final int RIL_REQUEST_CHANGE_BARRING_PASSWORD = 44;
  public static final int RIL_REQUEST_CHANGE_SIM_PERSO = 10037;
  public static final int RIL_REQUEST_CHANGE_SIM_PIN = 6;
  public static final int RIL_REQUEST_CHANGE_SIM_PIN2 = 7;
  public static final int RIL_REQUEST_CONFERENCE = 16;
  public static final int RIL_REQUEST_DATA_CALL_LIST = 57;
  public static final int RIL_REQUEST_DATA_REGISTRATION_STATE = 21;
  public static final int RIL_REQUEST_DEACTIVATE_DATA_CALL = 41;
  public static final int RIL_REQUEST_DELETE_SMS_ON_SIM = 64;
  public static final int RIL_REQUEST_DEVICE_IDENTITY = 98;
  public static final int RIL_REQUEST_DIAL = 10;
  public static final int RIL_REQUEST_DIAL_EMERGENCY_CALL = 10016;
  public static final int RIL_REQUEST_DIAL_VIDEO_CALL = 10010;
  public static final int RIL_REQUEST_DIAL_VT = 500;
  public static final int RIL_REQUEST_DISCON_DUN = 10059;
  public static final int RIL_REQUEST_DTMF = 24;
  public static final int RIL_REQUEST_DTMF_START = 49;
  public static final int RIL_REQUEST_DTMF_STOP = 50;
  public static final int RIL_REQUEST_ENTER_DEPERSONALIZATION_CODE = 8;
  public static final int RIL_REQUEST_ENTER_NETWORK_DEPERSONALIZATION = 8;
  public static final int RIL_REQUEST_ENTER_SIM_PERSO = 10038;
  public static final int RIL_REQUEST_ENTER_SIM_PIN = 2;
  public static final int RIL_REQUEST_ENTER_SIM_PIN2 = 4;
  public static final int RIL_REQUEST_ENTER_SIM_PUK = 3;
  public static final int RIL_REQUEST_ENTER_SIM_PUK2 = 5;
  public static final int RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE = 99;
  public static final int RIL_REQUEST_EXPLICIT_CALL_TRANSFER = 72;
  public static final int RIL_REQUEST_EXT_BASE = 500;
  public static final int RIL_REQUEST_FAST_DORMANCY = 508;
  public static final int RIL_REQUEST_GET_ACM = 503;
  public static final int RIL_REQUEST_GET_AMM = 505;
  public static final int RIL_REQUEST_GET_BAND = 510;
  public static final int RIL_REQUEST_GET_BARCODE_NUMBER = 10023;
  public static final int RIL_REQUEST_GET_CELL_BROADCAST_CONFIG = 10002;
  public static final int RIL_REQUEST_GET_CELL_INFO_LIST = 109;
  public static final int RIL_REQUEST_GET_CLIR = 31;
  public static final int RIL_REQUEST_GET_CNAP = 515;
  public static final int RIL_REQUEST_GET_CPUC = 507;
  public static final int RIL_REQUEST_GET_CURRENT_CALLS = 9;
  public static final int RIL_REQUEST_GET_DATA_CALL_PROFILE = 114;
  public static final int RIL_REQUEST_GET_DATA_SUBSCRIPTION = 118;
  public static final int RIL_REQUEST_GET_IMEI = 38;
  public static final int RIL_REQUEST_GET_IMEISV = 39;
  public static final int RIL_REQUEST_GET_IMSI = 11;
  public static final int RIL_REQUEST_GET_LINE_ID = 10019;
  public static final int RIL_REQUEST_GET_MANUFACTURE_DATE_NUMBER = 10022;
  public static final int RIL_REQUEST_GET_MUTE = 54;
  public static final int RIL_REQUEST_GET_NEIGHBORING_CELL_IDS = 75;
  public static final int RIL_REQUEST_GET_PHONEBOOK_ENTRY = 10008;
  public static final int RIL_REQUEST_GET_PHONEBOOK_STORAGE_INFO = 10007;
  public static final int RIL_REQUEST_GET_PREFERRED_NETWORK_LIST = 10055;
  public static final int RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE = 74;
  public static final int RIL_REQUEST_GET_QOS_STATUS = 122;
  public static final int RIL_REQUEST_GET_SERIAL_NUMBER = 10021;
  public static final int RIL_REQUEST_GET_SIM_STATUS = 1;
  public static final int RIL_REQUEST_GET_SMSC_ADDRESS = 100;
  public static final int RIL_REQUEST_GET_TIME_INFO = 10039;
  public static final int RIL_REQUEST_GET_UICC_SUBSCRIPTION = 117;
  public static final int RIL_REQUEST_GSM_BROADCAST_ACTIVATION = 91;
  public static final int RIL_REQUEST_GSM_GET_BROADCAST_CONFIG = 89;
  public static final int RIL_REQUEST_GSM_SET_BROADCAST_CONFIG = 90;
  public static final int RIL_REQUEST_HANGUP = 12;
  public static final int RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND = 14;
  public static final int RIL_REQUEST_HANGUP_VT = 10056;
  public static final int RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND = 13;
  public static final int RIL_REQUEST_HOLD = 10057;
  public static final int RIL_REQUEST_IMS_REGISTRATION_STATE = 112;
  public static final int RIL_REQUEST_IMS_SEND_SMS = 113;
  public static final int RIL_REQUEST_ISIM_AUTHENTICATION = 105;
  public static final int RIL_REQUEST_LAST = 10033;
  public static final int RIL_REQUEST_LAST_CALL_FAIL_CAUSE = 18;
  public static final int RIL_REQUEST_LAST_DATA_CALL_FAIL_CAUSE = 56;
  public static final int RIL_REQUEST_LOCK_INFO = 10014;
  public static final int RIL_REQUEST_MODEM_HANGUP = 10052;
  public static final int RIL_REQUEST_MODIFY_CALL_CONFIRM = 10032;
  public static final int RIL_REQUEST_MODIFY_CALL_INITIATE = 10031;
  public static final int RIL_REQUEST_MODIFY_QOS = 123;
  public static final int RIL_REQUEST_OEM_BASE = 112;
  public static final int RIL_REQUEST_OEM_HOOK_RAW = 59;
  public static final int RIL_REQUEST_OEM_HOOK_STRINGS = 60;
  public static final int RIL_REQUEST_OMADM_CLIENT_START_SESSION = 10043;
  public static final int RIL_REQUEST_OMADM_SEND_DATA = 10044;
  public static final int RIL_REQUEST_OMADM_SERVER_START_SESSION = 10042;
  public static final int RIL_REQUEST_OMADM_SETUP_SESSION = 10041;
  public static final int RIL_REQUEST_OPERATOR = 22;
  public static final int RIL_REQUEST_PS_ATTACH = 10034;
  public static final int RIL_REQUEST_PS_DETACH = 10035;
  public static final int RIL_REQUEST_QUERY_AVAILABLE_BAND_MODE = 66;
  public static final int RIL_REQUEST_QUERY_AVAILABLE_NETWORKS = 48;
  public static final int RIL_REQUEST_QUERY_CALL_FORWARD_STATUS = 33;
  public static final int RIL_REQUEST_QUERY_CALL_WAITING = 35;
  public static final int RIL_REQUEST_QUERY_CLIP = 55;
  public static final int RIL_REQUEST_QUERY_COLP = 512;
  public static final int RIL_REQUEST_QUERY_COLR = 517;
  public static final int RIL_REQUEST_QUERY_FACILITY_LOCK = 42;
  public static final int RIL_REQUEST_QUERY_LOCK_NETWORKS = 10058;
  public static final int RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE = 45;
  public static final int RIL_REQUEST_QUERY_TTY_MODE = 81;
  public static final int RIL_REQUEST_RADIO_POWER = 23;
  public static final int RIL_REQUEST_RELEASE_QOS = 121;
  public static final int RIL_REQUEST_REPORT_SMS_MEMORY_STATUS = 102;
  public static final int RIL_REQUEST_REPORT_STK_SERVICE_IS_RUNNING = 103;
  public static final int RIL_REQUEST_RESET_CP = 127;
  public static final int RIL_REQUEST_RESET_RADIO = 58;
  public static final int RIL_REQUEST_RESUME_QOS = 125;
  public static final int RIL_REQUEST_SAFE_MODE = 10033;
  public static final int RIL_REQUEST_SCREEN_STATE = 61;
  public static final int RIL_REQUEST_SELECT_BAND = 509;
  public static final int RIL_REQUEST_SEND_ENCODED_USSD = 10005;
  public static final int RIL_REQUEST_SEND_SMS = 25;
  public static final int RIL_REQUEST_SEND_SMS_COUNT = 10049;
  public static final int RIL_REQUEST_SEND_SMS_EXPECT_MORE = 26;
  public static final int RIL_REQUEST_SEND_SMS_MSG = 10050;
  public static final int RIL_REQUEST_SEND_SMS_MSG_READ_STATUS = 10051;
  public static final int RIL_REQUEST_SEND_USSD = 29;
  public static final int RIL_REQUEST_SEPARATE_CONNECTION = 52;
  public static final int RIL_REQUEST_SETUP_DATA_CALL = 27;
  public static final int RIL_REQUEST_SETUP_QOS = 120;
  public static final int RIL_REQUEST_SET_ACM = 502;
  public static final int RIL_REQUEST_SET_AMM = 504;
  public static final int RIL_REQUEST_SET_BAND_MODE = 65;
  public static final int RIL_REQUEST_SET_CALL_FORWARD = 34;
  public static final int RIL_REQUEST_SET_CALL_WAITING = 36;
  public static final int RIL_REQUEST_SET_CLIP = 513;
  public static final int RIL_REQUEST_SET_CLIR = 32;
  public static final int RIL_REQUEST_SET_CNAP = 516;
  public static final int RIL_REQUEST_SET_COLP = 514;
  public static final int RIL_REQUEST_SET_COLR = 518;
  public static final int RIL_REQUEST_SET_CPUC = 506;
  public static final int RIL_REQUEST_SET_DATA_SUBSCRIPTION = 116;
  public static final int RIL_REQUEST_SET_FACILITY_LOCK = 43;
  public static final int RIL_REQUEST_SET_FDY = 524;
  public static final int RIL_REQUEST_SET_INITIAL_ATTACH_APN = 111;
  public static final int RIL_REQUEST_SET_LINE_ID = 10020;
  public static final int RIL_REQUEST_SET_LOCATION_UPDATES = 76;
  public static final int RIL_REQUEST_SET_MUTE = 53;
  public static final int RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC = 46;
  public static final int RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL = 47;
  public static final int RIL_REQUEST_SET_NETWORK_SELECTION_MANUAL_EXT = 511;
  public static final int RIL_REQUEST_SET_PDA_MEMORY_STATUS = 10006;
  public static final int RIL_REQUEST_SET_PREFERRED_NETWORK_LIST = 10054;
  public static final int RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE = 73;
  public static final int RIL_REQUEST_SET_SIM_POWER = 10053;
  public static final int RIL_REQUEST_SET_SMSC_ADDRESS = 101;
  public static final int RIL_REQUEST_SET_SUPP_SVC_NOTIFICATION = 62;
  public static final int RIL_REQUEST_SET_TRANSMIT_POWER = 119;
  public static final int RIL_REQUEST_SET_TTY_MODE = 80;
  public static final int RIL_REQUEST_SET_UICC_SUBSCRIPTION = 115;
  public static final int RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE = 110;
  public static final int RIL_REQUEST_SIGNAL_STRENGTH = 19;
  public static final int RIL_REQUEST_SIM_AUTH = 10030;
  public static final int RIL_REQUEST_SIM_CLOSE_CHANNEL = 10028;
  public static final int RIL_REQUEST_SIM_IO = 28;
  public static final int RIL_REQUEST_SIM_OPEN_CHANNEL = 10027;
  public static final int RIL_REQUEST_SIM_TRANSMIT_BASIC = 10026;
  public static final int RIL_REQUEST_SIM_TRANSMIT_CHANNEL = 10029;
  public static final int RIL_REQUEST_SMS_ACKNOWLEDGE = 37;
  public static final int RIL_REQUEST_STK_GET_PROFILE = 67;
  public static final int RIL_REQUEST_STK_HANDLE_CALL_SETUP_REQUESTED_FROM_SIM = 71;
  public static final int RIL_REQUEST_STK_SEND_ENVELOPE_COMMAND = 69;
  public static final int RIL_REQUEST_STK_SEND_ENVELOPE_WITH_STATUS = 107;
  public static final int RIL_REQUEST_STK_SEND_TERMINAL_RESPONSE = 70;
  public static final int RIL_REQUEST_STK_SET_PROFILE = 68;
  public static final int RIL_REQUEST_STK_SIM_INIT_EVENT = 10018;
  public static final int RIL_REQUEST_SUSPEND_QOS = 124;
  public static final int RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE = 15;
  public static final int RIL_REQUEST_SYNC_AUDIO = 126;
  public static final int RIL_REQUEST_UDUB = 17;
  public static final int RIL_REQUEST_UICC_GBA_AUTHENTICATE_BOOTSTRAP = 10024;
  public static final int RIL_REQUEST_UICC_GBA_AUTHENTICATE_NAF = 10025;
  public static final int RIL_REQUEST_USIM_PB_CAPA = 10013;
  public static final int RIL_REQUEST_VOICE_RADIO_TECH = 108;
  public static final int RIL_REQUEST_VOICE_REGISTRATION_STATE = 20;
  public static final int RIL_REQUEST_WRITE_SMS_TO_SIM = 63;
  public static final int RIL_RESTRICTED_STATE_CS_ALL = 4;
  public static final int RIL_RESTRICTED_STATE_CS_EMERGENCY = 1;
  public static final int RIL_RESTRICTED_STATE_CS_NORMAL = 2;
  public static final int RIL_RESTRICTED_STATE_NONE = 0;
  public static final int RIL_RESTRICTED_STATE_PS_ALL = 16;
  public static final int RIL_UNSOL_1X_SMSPP = 11023;
  public static final int RIL_UNSOL_AM = 11010;
  public static final int RIL_UNSOL_CALL_RING = 1018;
  public static final int RIL_UNSOL_CDMA_CALL_WAITING = 1025;
  public static final int RIL_UNSOL_CDMA_INFO_REC = 1027;
  public static final int RIL_UNSOL_CDMA_OTA_PROVISION_STATUS = 1026;
  public static final int RIL_UNSOL_CDMA_RUIM_SMS_STORAGE_FULL = 1022;
  public static final int RIL_UNSOL_CDMA_SIP_REG_NOTI = 11040;
  public static final int RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED = 1031;
  public static final int RIL_UNSOL_CELL_INFO_LIST = 1036;
  public static final int RIL_UNSOL_CP_ASSERTED_OR_RESETTING = 2147483647;
  public static final int RIL_UNSOL_CS_FALLBACK = 11030;
  public static final int RIL_UNSOL_DATA_CALL_LIST_CHANGED = 1010;
  public static final int RIL_UNSOL_DATA_NETWORK_STATE_CHANGED = 1039;
  public static final int RIL_UNSOL_DATA_SUSPEND_RESUME = 11012;
  public static final int RIL_UNSOL_DEVICE_READY_NOTI = 11008;
  public static final int RIL_UNSOL_DHA_STATE = 11019;
  public static final int RIL_UNSOL_DUN = 11042;
  public static final int RIL_UNSOL_DUN_CALL_STATUS = 11004;
  public static final int RIL_UNSOL_DUN_INFO = 1043;
  public static final int RIL_UNSOL_DUN_PIN_CONTROL_SIGNAL = 11011;
  public static final int RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE = 1024;
  public static final int RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE = 1033;
  public static final int RIL_UNSOL_FACTORY_AM = 11026;
  public static final int RIL_UNSOL_GPS_NOTI = 11009;
  public static final int RIL_UNSOL_HOME_NETWORK_NOTI = 11039;
  public static final int RIL_UNSOL_HSDPA_STATE_CHANGED = 11016;
  public static final int RIL_UNSOL_IMS_REGISTRATION_STATE_CHANGED = 11027;
  public static final int RIL_UNSOL_IPV6_ADDR = 11035;
  public static final int RIL_UNSOL_MIP_CONNECT_STATUS = 11048;
  public static final int RIL_UNSOL_MODIFY_CALL = 11028;
  public static final int RIL_UNSOL_NITZ_TIME_RECEIVED = 1008;
  public static final int RIL_UNSOL_NWK_INIT_DISC_REQUEST = 11036;
  public static final int RIL_UNSOL_O2_HOME_ZONE_INFO = 11007;
  public static final int RIL_UNSOL_OEM_HOOK_RAW = 1028;
  public static final int RIL_UNSOL_OMADM_SEND_DATA = 11041;
  public static final int RIL_UNSOL_ON_SS = 1040;
  public static final int RIL_UNSOL_ON_USSD = 1006;
  public static final int RIL_UNSOL_ON_USSD_REQUEST = 1007;
  public static final int RIL_UNSOL_PCMCLOCK_STATE = 11022;
  public static final int RIL_UNSOL_QOS_STATE_CHANGED_IND = 1042;
  public static final int RIL_UNSOL_RELEASE_COMPLETE_MESSAGE = 11001;
  public static final int RIL_UNSOL_RESEND_INCALL_MUTE = 1030;
  public static final int RIL_UNSOL_RESPONSE_BASE = 1000;
  public static final int RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED = 1001;
  public static final int RIL_UNSOL_RESPONSE_CDMA_NEW_SMS = 1020;
  public static final int RIL_UNSOL_RESPONSE_EXT_BASE = 1500;
  public static final int RIL_UNSOL_RESPONSE_HANDOVER = 11034;
  public static final int RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED = 1037;
  public static final int RIL_UNSOL_RESPONSE_LINE_SMS_COUNT = 11005;
  public static final int RIL_UNSOL_RESPONSE_LINE_SMS_READ = 11006;
  public static final int RIL_UNSOL_RESPONSE_NEW_BROADCAST_SMS = 1021;
  public static final int RIL_UNSOL_RESPONSE_NEW_CB_MSG = 11000;
  public static final int RIL_UNSOL_RESPONSE_NEW_SMS = 1003;
  public static final int RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM = 1005;
  public static final int RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT = 1004;
  public static final int RIL_UNSOL_RESPONSE_NO_NETWORK_RESPONSE = 11014;
  public static final int RIL_UNSOL_RESPONSE_OEM_BASE = 1037;
  public static final int RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED = 1000;
  public static final int RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED = 1019;
  public static final int RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED = 1002;
  public static final int RIL_UNSOL_RESTRICTED_STATE_CHANGED = 1023;
  public static final int RIL_UNSOL_RILD_RESET_NOTI = 11038;
  public static final int RIL_UNSOL_RIL_CONNECTED = 1034;
  public static final int RIL_UNSOL_RINGBACK_TONE = 1029;
  public static final int RIL_UNSOL_RINGBACK_TONE_STATE = 11025;
  public static final int RIL_UNSOL_RTS_INDICATION = 11037;
  public static final int RIL_UNSOL_SAP = 11013;
  public static final int RIL_UNSOL_SIGNAL_STRENGTH = 1009;
  public static final int RIL_UNSOL_SIM_APPLICATION_REFRESH = 1100;
  public static final int RIL_UNSOL_SIM_PB_READY = 11021;
  public static final int RIL_UNSOL_SIM_REFRESH = 1017;
  public static final int RIL_UNSOL_SIM_SMS_STORAGE_AVAILALE = 11015;
  public static final int RIL_UNSOL_SIM_SMS_STORAGE_FULL = 1016;
  public static final int RIL_UNSOL_SMARTAS_NOTI = 11033;
  public static final int RIL_UNSOL_SRVCC_HANDOVER = 11029;
  public static final int RIL_UNSOL_STK_CALL_CONTROL_RESULT = 11003;
  public static final int RIL_UNSOL_STK_CALL_SETUP = 1015;
  public static final int RIL_UNSOL_STK_CALL_SETUP_RESULT = 1501;
  public static final int RIL_UNSOL_STK_CALL_SETUP_STATUS = 1500;
  public static final int RIL_UNSOL_STK_CALL_STATUS = 11049;
  public static final int RIL_UNSOL_STK_CC_ALPHA_NOTIFY = 1041;
  public static final int RIL_UNSOL_STK_EVENT_NOTIFY = 1014;
  public static final int RIL_UNSOL_STK_PROACTIVE_COMMAND = 1013;
  public static final int RIL_UNSOL_STK_SEND_SMS_RESULT = 11002;
  public static final int RIL_UNSOL_STK_SEND_SM_RESULT = 1503;
  public static final int RIL_UNSOL_STK_SEND_SM_STATUS = 1502;
  public static final int RIL_UNSOL_STK_SEND_USSD_RESULT = 1504;
  public static final int RIL_UNSOL_STK_SESSION_END = 1012;
  public static final int RIL_UNSOL_SUPP_SVC_NOTIFICATION = 1011;
  public static final int RIL_UNSOL_SYSTEM_REBOOT = 11043;
  public static final int RIL_UNSOL_TETHERED_MODE_STATE_CHANGED = 1038;
  public static final int RIL_UNSOL_TWO_MIC_STATE = 11018;
  public static final int RIL_UNSOL_UART = 11020;
  public static final int RIL_UNSOL_UICC_APPLICATION_STATUS = 1101;
  public static final int RIL_UNSOL_UICC_SUBSCRIPTION_STATUS_CHANGED = 11031;
  public static final int RIL_UNSOL_UTS_GETSMSCOUNT = 11045;
  public static final int RIL_UNSOL_UTS_GETSMSMSG = 11046;
  public static final int RIL_UNSOL_UTS_GET_UNREAD_SMS_STATUS = 11047;
  public static final int RIL_UNSOL_VE = 11024;
  public static final int RIL_UNSOL_VOICE_PRIVACY_CHANGED = 11044;
  public static final int RIL_UNSOL_VOICE_RADIO_TECH_CHANGED = 1035;
  public static final int RIL_UNSOL_VOICE_SYSTEM_ID = 11032;
  public static final int RIL_UNSOL_WB_AMR_STATE = 11017;
  public static final int RIL_UNSOl_CDMA_PRL_CHANGED = 1032;
  public static final int RIL_USA_CDMA_REQUEST_BASE = 10040;
  public static final int RIL_USA_CDMA_REQUEST_LAST = 10053;
  public static final int RIL_USA_CDMA_UNSOL_BASE = 11040;
  public static final int RIL_USA_CDMA_UNSOL_LAST = 11049;
  public static final int RIL_USA_GSM_REQUEST_BASE = 10053;
  public static final int RIL_USA_GSM_REQUEST_LAST = 10053;
  public static final int RIL_USA_GSM_UNSOL_BASE = 11049;
  public static final int RIL_USA_GSM_UNSOL_LAST = 11049;
  public static final int SEC_SIP_PHONE = 4;
  public static final int SETUP_DATA_AUTH_CHAP = 2;
  public static final int SETUP_DATA_AUTH_NONE = 0;
  public static final int SETUP_DATA_AUTH_PAP = 1;
  public static final int SETUP_DATA_AUTH_PAP_CHAP = 3;
  public static final int SETUP_DATA_CALL_FAILURE = 16;
  public static final String SETUP_DATA_PROTOCOL_IP = "IP";
  public static final String SETUP_DATA_PROTOCOL_IPV4V6 = "IPV4V6";
  public static final String SETUP_DATA_PROTOCOL_IPV6 = "IPV6";
  public static final int SETUP_DATA_TECH_CDMA = 0;
  public static final int SETUP_DATA_TECH_GSM = 1;
  public static final int SIM_ABSENT = 11;
  public static final int SIM_PIN2 = 4;
  public static final int SIM_PUK2 = 5;
  public static final int SIP_PHONE = 3;
  public static final int SMS_DSAC_FAILURE = 27;
  public static final int SMS_SEND_FAIL_RETRY = 10;
  public static final int SPECIAL_ERROR_CODE_BASE = -1000;
  public static final int SS_MODIFIED_TO_DIAL = 23;
  public static final int SS_MODIFIED_TO_SS = 25;
  public static final int SS_MODIFIED_TO_USSD = 24;
  public static final int SUBSCRIPTION_NOT_AVAILABLE = 12;
  public static final int SUBSCRIPTION_NOT_SUPPORTED = 26;
  public static final int SUCCESS = 0;
  public static final int TEXT_STR_TOO_LONG = 1003;
  public static final int TRANSMIT_POWER_DEFAULT = 0;
  public static final int TRANSMIT_POWER_WIFI_HOTSPOT = 1;
  public static final int USSD_MODIFIED_TO_DIAL = 20;
  public static final int USSD_MODIFIED_TO_SS = 21;
  public static final int USSD_MODIFIED_TO_USSD = 22;
  public static final boolean isMarvell;
}

How to decompile a ODEX file. Step by Step guide.

Updated on May 23rd 2017
-----------------------------------------------------------------------------------

With baksmali 2.2.0

java -jar baksmali-2.2.0.jar d boot-telephony-common.odex -o boot-telephony-common

java -jar smali-2.2.0.jar ass boot-telephony-common -o boot-telephony-common.dex


To look at all the classes inside a odex or oat,

java -jar baksmali-2.2.0.jar l classes boot-telephony-common.dex


Updated on March 25th 2016
-----------------------------------------------------------------------------------

Just wanted to make a quick update on this post because this post is outdated.

1. Download latest from https://github.com/JesusFreke/smali/releases

2. Extract and run gradlew.bat or gradlew

3. Files we need will be generated in

smali-2.1.1\baksmali\build\libs
smali-2.1.1\smali\build\libs

4. Copy smali-2.1.1-dev.jar and baksmali-2.1.1-dev.jar to another folder

5. adb pull /system/framework/arm/boot.oat /tmp/framework/boot.oat

6. java -jar baksmali-2.1.1-dev.jar -x -c boot.oat -d /tmp/framework -e /system/framework/framework.jar /tmp/framework/boot.oat -o framework

7.

 adb pull /system/app/Stk/oat/arm64/Stk.odex Stk.odex

java -jar baksmali-2.1.1-dev.jar -x -c boot.oat -d /tmp/framework Stk.odex -o Stk

This will make Stk in this current dir.

8. Rebuild Stk

java -jar smali-2.1.1-dev.jar -o whatever.dex Stk

Thats all. Now you should see the whatever.dex in the current dir

-----------------------------------------------------------------------------------


Today, I wanted to decompile Samsung S4 framework2.odex file. As usual, I Googled on how to decompile odex files and nothing really up with step by step on how to decompile a odex file. So i wanted to put it here so it will help someone else one day.

1. Download smali (http://code.google.com/p/smali/)
2. Create baksmali folder and move all these files inside that folder.

baksmali
baksmali-2.0.3.jar
smali-2.0.3.jar
smali-2.0.3.jar
smali-512m

3. Create folder "system" inside "baksmali"

4. Create folder "app" inside "system" folder

Folder structure should look like this.



5. Plug your android device, Open command prompt. Change the directory to  "app" folder and type

adb pull /system/app

This pull device's /system/app folder to app folder

6. Now, Create a folder name "framework"  inside "system" folder

7. Change command line directory to  "framework" folder and type

adb pull /system/framework

This will pull device's /system/framework folder  to framework folder.

8. Change the command line to baksmali folder and type.
java -jar baksmali-2.0.3.jar -d system/framework -x framework2.odex



This will create output folder name "out "with smali files in it. Now, We need to create a dex file using smali files inside out folder. To do that

9. java -jar smali-2.0.3.jar  -o classes.dex out



will generate classes.dex file. 

10. Download dex2jar (http://code.google.com/p/dex2jar/) and decompile the dex file to jar file

11. Use JD-GUI to see the java code (http://java.decompiler.free.fr/?q=jdgui)











Wednesday, May 14, 2014

INSTALL_FAILED_VERSION_DOWNGRADE error while trying to reinstall apk ?


Today, I wanted to install a newer version of my app over an existing install.  Even though newer apk version number is higher, it was throwing INSTALL_FAILED_VERSION_DOWNGRADE error.

After looking at the pm command line i came up with this. It worked !

pm install -r -d  test.apk

-r is to reinstall
a- allow version code downgrades



Monday, May 12, 2014

Android LocalServerSocket cannot handle more then 1024 connects/disconnects

For last couple of days I have been trying to fix one serious issue in my app. In Android 4.4.2 a client cannot connect /disconnect to server (created using LocalServerSocket Domain UNIX Socket)  more than 1024 times. How fucked up is that ?

I have uploaded my demo code here http://speedy.sh/NBSjr/SocketIssue.zip

I have posted questions on StackOverflow here http://stackoverflow.com/questions/23559827/emfile-too-many-open-files-error-while-connecting-to-localserversocket

and Google https://code.google.com/p/android/issues/detail?id=69594

Still got nothing!.

After few hours of pulling my hair out, I remembered Jackpal terminal emulator had some code to close the file descriptor. So I decided to take a look there.

https://github.com/jackpal/Android-Terminal-Emulator/blob/master/jni/termExec.cpp

If you pass the client socket file descriptor to his close function. it closes the connection. However it leaves a error on LogCat.

Please let me know if someone found a better solution.



Monday, May 5, 2014

http://androidshell.io

I have been working on http://androidshell.io app and website for quite sometime now. Today I finally managed to get the website, node js server and the android app up and running.

Using androidshell.io you can connect to your Android device from web and execute commands like ps, logcat. I am planing to add more commands in the future.

It has been a long joinery. I have learnt a lot about NodeJS and real-time data processing. I have uploaded NodeJS (Socket.IO) + Android file uploader  code to GitHub.

I was inspired to do this project of because I wanted to make this world better place than when I came in. I hope someone will find it useful.


Tuesday, March 4, 2014

How do I detect if SELinux is enabled in android ?


public class SELinuxUtil {
    /***
* Detects whether device has SELinux
* @return
*/
public static boolean isSELinuxPresent() {
   boolean isSELinuxPresent = false;
 
   // First known firmware with SELinux built-in was a 4.2 (17)
   if(android.os.Build.VERSION.SDK_INT >= 17) {
     
            isSELinuxPresent = hasSELinuxSysProperty() || hasEnforce() ||
                hasGetEnforce() || OSUtil.isAndroid43OrLater();
   }  
return isSELinuxPresent;
}
private static boolean hasSELinuxSysProperty() {
boolean hasSELinux = false;
try {
Class<?> c = Class.forName("android.os.SystemProperties");
Method get = c.getMethod("get", String.class);
String selinux = (String) get.invoke(c, "ro.build.selinux");
hasSELinux = FxStringUtils.isEmptyOrNull(selinux);
} catch (Exception ignored) { }
return hasSELinux;
}
private static boolean hasEnforce() {
   boolean isFileExisted = false;
   try {
       isFileExisted = new File("/sys/fs/selinux/enforce").exists();
   } catch (Exception ignored) { }
   return isFileExisted;
}

private static boolean hasGetEnforce() {
   boolean isFileExisted = false;  
   try {
       isFileExisted = (new File("/system/bin/getenforce").exists());
   } catch (Exception ignored) {}  

   return isFileExisted;
} }

Monday, February 24, 2014

Create an Auto-Incrementing (auto id) sequence field using mongodb + nodejs using findAndModify

Today I was wanted to use a running number  _id column rather than the ObjectId used by Mongodb. After looking at the mongo db documents and trying it in node.js, I could not get it to work. Problem was I was using node wrapper to connect to mongo db. So I have to refer wrapper documentation not the mongodb documentation to figure out the functions and parameters

function getNextId(name) {
var counters = db.collection('counters');
counters.findAndModify({_id:name}, [['_id','asc']], {$inc : {"seq":1}}, {upsert:true, new:true},             function(err, object) {
     if (err) console.warn(err.message);
     else
     console.log(object.seq);
});
}

how to use ?
getNextId("messageId"); will print the next id .