Remove OEM-specific bits from RadioInfo.

The extracted bits will move into the HTC vendor tree, and it (or
similar settings for other vendors) can be accessed via a generic
OEM_RADIO_INFO activity.

Addresses issue:
http://buganizer/issue?id=1645706

Change-Id: Iec5461bcb3e241a1230f5f6d53baa3bb838ff4a9
diff --git a/src/com/android/settings/RadioInfo.java b/src/com/android/settings/RadioInfo.java
index ce236fd..3dae8d4 100644
--- a/src/com/android/settings/RadioInfo.java
+++ b/src/com/android/settings/RadioInfo.java
@@ -20,6 +20,8 @@
 import android.app.AlertDialog;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
 import android.content.SharedPreferences;
 import android.content.res.Resources;
 import android.net.Uri;
@@ -57,7 +59,6 @@
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.PhoneStateIntentReceiver;
 import com.android.internal.telephony.TelephonyProperties;
-import com.android.internal.telephony.gsm.GSMPhone;
 import com.android.internal.telephony.gsm.PdpConnection;
 
 import org.apache.http.HttpResponse;
@@ -72,6 +73,8 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import android.util.Log;
+
 public class RadioInfo extends Activity {
     private final String TAG = "phone";
 
@@ -83,8 +86,6 @@
     private static final int EVENT_QUERY_PREFERRED_TYPE_DONE = 1000;
     private static final int EVENT_SET_PREFERRED_TYPE_DONE = 1001;
     private static final int EVENT_QUERY_NEIGHBORING_CIDS_DONE = 1002;
-    private static final int EVENT_SET_QXDMLOG_DONE = 1003;
-    private static final int EVENT_SET_CIPHER_DONE = 1004;
     private static final int EVENT_QUERY_SMSC_DONE = 1005;
     private static final int EVENT_UPDATE_SMSC_DONE = 1006;
 
@@ -94,7 +95,9 @@
     private static final int MENU_ITEM_VIEW_SDN     = 3;
     private static final int MENU_ITEM_GET_PDP_LIST = 4;
     private static final int MENU_ITEM_TOGGLE_DATA  = 5;
-    private static final int MENU_ITEM_TOGGLE_DATA_ON_BOOT = 6;
+
+    static final String ENABLE_DATA_STR = "Enable data connection";
+    static final String DISABLE_DATA_STR = "Disable data connection";
 
     private TextView mDeviceId; //DeviceId is the IMEI in GSM and the MEID in CDMA
     private TextView number;
@@ -119,16 +122,14 @@
     private TextView mPingIpAddr;
     private TextView mPingHostname;
     private TextView mHttpClientTest;
-    private TextView cipherState;
     private TextView dnsCheckState;
     private EditText smsc;
     private Button radioPowerButton;
-    private Button qxdmLogButton;
-    private Button cipherToggleButton;
     private Button dnsCheckToggleButton;
     private Button pingTestButton;
     private Button updateSmscButton;
     private Button refreshSmscButton;
+    private Button oemInfoButton;
     private Spinner preferredNetworkType;
 
     private TelephonyManager mTelephonyManager;
@@ -136,11 +137,6 @@
     private PhoneStateIntentReceiver mPhoneStateReceiver;
     private INetStatService netstat;
 
-    private OemCommands mOem = null;
-    private boolean mQxdmLogEnabled;
-    // The requested cipher state
-    private boolean mCipherOn;
-
     private String mPingIpAddrResult;
     private String mPingHostnameResult;
     private String mHttpClientTestResult;
@@ -220,22 +216,6 @@
                         mNeighboringCids.setText("unknown");
                     }
                     break;
-                case EVENT_SET_QXDMLOG_DONE:
-                    ar= (AsyncResult) msg.obj;
-                    if (ar.exception == null) {
-                        mQxdmLogEnabled = !mQxdmLogEnabled;
-
-                        updateQxdmState(mQxdmLogEnabled);
-                        displayQxdmEnableResult();
-                    }
-                    break;
-                case EVENT_SET_CIPHER_DONE:
-                    ar= (AsyncResult) msg.obj;
-                    if (ar.exception == null) {
-                        setCiphPref(mCipherOn);
-                    }
-                    updateCiphState();
-                    break;
                 case EVENT_QUERY_SMSC_DONE:
                     ar= (AsyncResult) msg.obj;
                     if (ar.exception != null) {
@@ -258,116 +238,6 @@
         }
     };
 
-    static private class OemCommands {
-
-        public static final int OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE = 32;
-        public static final int OEM_QXDM_SDLOG_DEFAULT_MASK = 0;
-        public static final int OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX = 8;
-
-        static final int SIZE_OF_INT = 4;
-        static final int OEM_FEATURE_ENABLE = 1;
-        static final int OEM_FEATURE_DISABLE = 0;
-        static final int OEM_SIMPE_FEAUTURE_LEN = 1;
-
-        static final int OEM_QXDM_SDLOG_FUNCTAG = 0x00010000;
-        static final int OEM_QXDM_SDLOG_LEN = 4;
-        static final int OEM_PS_AUTO_ATTACH_FUNCTAG = 0x00020000;
-        static final int OEM_CIPHERING_FUNCTAG = 0x00020001;
-
-        /**
-         * The OEM interface to store QXDM to SD.
-         *
-         * To start/stop logging QXDM logs to SD card, use tag
-         * OEM_RIL_HOOK_QXDM_SD_LOG_SETUP 0x00010000
-         *
-         * "data" is a const oem_ril_hook_qxdm_sdlog_setup_data_st *
-         * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->head.func_tag
-         * should be OEM_RIL_HOOK_QXDM_SD_LOG_SETUP
-         * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->head.len
-         * should be "sizeof(unsigned int) * 4"
-         * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->mode
-         * could be 0 for 'stop logging', or 1 for 'start logging'
-         * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->log_file_size
-         * will assign the size of each log file, and it could be a value between
-         * 1 and 512 (in megabytes, default value is recommended to set as 32).
-         * This value will be ignored when mode == 0.
-         * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->log_mask will
-         * assign the rule to filter logs, and it is a bitmask (bit0 is for MsgAll,
-         * bit1 is for LogAll, and bit2 is for EventAll) recommended to be set as 0
-         * by default. This value will be ignored when mode == 0.
-         * ((const oem_ril_hook_qxdm_sdlog_setup_data_st *)data)->log_max_fileindex
-         * set the how many logfiles will storted before roll over. This value will
-         * be ignored when mode == 0.
-         *
-         * "response" is NULL
-         *
-         * typedef struct _oem_ril_hook_raw_head_st {
-         *      unsigned int func_tag;
-         *      unsigned int len;
-         * } oem_ril_hook_raw_head_st;
-         *
-         * typedef struct _oem_ril_hook_qxdm_sdlog_setup_data_st {
-         *      oem_ril_hook_raw_head_st head;
-         *      unsigned int mode;
-         *      unsigned int log_file_size;
-         *      unsigned int log_mask;
-         *      unsigned int log_max_fileindex;
-         * } oem_ril_hook_qxdm_sdlog_setup_data_st;
-         *
-         * @param enable set true to start logging QXDM in SD card
-         * @param fileSize is the log file size in MB
-         * @param mask is the log mask to filter
-         * @param maxIndex is the maximum roll-over file number
-         * @return byteArray to use in RIL RAW command
-         */
-        byte[] getQxdmSdlogData(boolean enable, int fileSize, int mask, int maxIndex) {
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            DataOutputStream dos = new DataOutputStream(bos);
-            try {
-                writeIntLittleEndian(dos, OEM_QXDM_SDLOG_FUNCTAG);
-                writeIntLittleEndian(dos, OEM_QXDM_SDLOG_LEN * SIZE_OF_INT);
-                writeIntLittleEndian(dos, enable ?
-                        OEM_FEATURE_ENABLE : OEM_FEATURE_DISABLE);
-                writeIntLittleEndian(dos, fileSize);
-                writeIntLittleEndian(dos, mask);
-                writeIntLittleEndian(dos, maxIndex);
-            } catch (IOException e) {
-                return null;
-            }
-            return bos.toByteArray();
-        }
-
-        byte[] getPsAutoAttachData(boolean enable) {
-            return getSimpleFeatureData(OEM_PS_AUTO_ATTACH_FUNCTAG, enable);
-        }
-
-        byte[] getCipheringData(boolean enable) {
-            return getSimpleFeatureData(OEM_CIPHERING_FUNCTAG, enable);
-        }
-
-        private byte[] getSimpleFeatureData(int tag, boolean enable) {
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            DataOutputStream dos = new DataOutputStream(bos);
-            try {
-                writeIntLittleEndian(dos, tag);
-                writeIntLittleEndian(dos, OEM_SIMPE_FEAUTURE_LEN * SIZE_OF_INT);
-                writeIntLittleEndian(dos, enable ?
-                        OEM_FEATURE_ENABLE : OEM_FEATURE_DISABLE);
-            } catch (IOException e) {
-                return null;
-            }
-            return bos.toByteArray();
-        }
-
-        private void writeIntLittleEndian(DataOutputStream dos, int val)
-                throws IOException {
-            dos.writeByte(val);
-            dos.writeByte(val >> 8);
-            dos.writeByte(val >> 16);
-            dos.writeByte(val >> 24);
-        }
-    }
-
     @Override
     public void onCreate(Bundle icicle) {
         super.onCreate(icicle);
@@ -398,7 +268,6 @@
         sentSinceReceived = (TextView) findViewById(R.id.sentSinceReceived);
         sent = (TextView) findViewById(R.id.sent);
         received = (TextView) findViewById(R.id.received);
-        cipherState = (TextView) findViewById(R.id.ciphState);
         smsc = (EditText) findViewById(R.id.smsc);
         dnsCheckState = (TextView) findViewById(R.id.dnsCheckState);
 
@@ -416,11 +285,6 @@
         radioPowerButton = (Button) findViewById(R.id.radio_power);
         radioPowerButton.setOnClickListener(mPowerButtonHandler);
 
-        qxdmLogButton = (Button) findViewById(R.id.qxdm_log);
-        qxdmLogButton.setOnClickListener(mQxdmButtonHandler);
-
-        cipherToggleButton = (Button) findViewById(R.id.ciph_toggle);
-        cipherToggleButton.setOnClickListener(mCipherButtonHandler);
         pingTestButton = (Button) findViewById(R.id.ping_test);
         pingTestButton.setOnClickListener(mPingButtonHandler);
         updateSmscButton = (Button) findViewById(R.id.update_smsc);
@@ -430,14 +294,20 @@
         dnsCheckToggleButton = (Button) findViewById(R.id.dns_check_toggle);
         dnsCheckToggleButton.setOnClickListener(mDnsCheckButtonHandler);
 
+        oemInfoButton = (Button) findViewById(R.id.oem_info);
+        oemInfoButton.setOnClickListener(mOemInfoButtonHandler);
+        PackageManager pm = getPackageManager();
+        Intent oemInfoIntent = new Intent("com.android.settings.OEM_RADIO_INFO");
+        List<ResolveInfo> oemInfoIntentList = pm.queryIntentActivities(oemInfoIntent, 0);
+        if (oemInfoIntentList.size() == 0) {
+            oemInfoButton.setEnabled(false);
+        }
+
         mPhoneStateReceiver = new PhoneStateIntentReceiver(this, mHandler);
         mPhoneStateReceiver.notifySignalStrength(EVENT_SIGNAL_STRENGTH_CHANGED);
         mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED);
         mPhoneStateReceiver.notifyPhoneCallState(EVENT_PHONE_STATE_CHANGED);
 
-        updateQxdmState(null);
-        mOem = new OemCommands();
-
         phone.getPreferredNetworkType(
                 mHandler.obtainMessage(EVENT_QUERY_PREFERRED_TYPE_DONE));
         phone.getNeighboringCids(
@@ -462,9 +332,7 @@
         updateDataStats();
         updateDataStats2();
         updatePowerState();
-        updateQxdmState(null);
         updateProperties();
-        updateCiphState();
         updateDnsCheckState();
 
         Log.i(TAG, "[RadioInfo] onResume: register phone & data intents");
@@ -502,14 +370,10 @@
         menu.add(1, MENU_ITEM_GET_PDP_LIST,
                 0, R.string.radioInfo_menu_getPDP).setOnMenuItemClickListener(mGetPdpList);
         menu.add(1, MENU_ITEM_TOGGLE_DATA,
-                0, R.string.radioInfo_menu_disableData).setOnMenuItemClickListener(mToggleData);
-        menu.add(1, MENU_ITEM_TOGGLE_DATA_ON_BOOT,
-                0, R.string.radioInfo_menu_disableDataOnBoot).setOnMenuItemClickListener(
-                mToggleDataOnBoot);
+                0, DISABLE_DATA_STR).setOnMenuItemClickListener(mToggleData);
         return true;
     }
 
-
     @Override
     public boolean onPrepareOptionsMenu(Menu menu) {
         // Get the TOGGLE DATA menu item in the right state.
@@ -520,26 +384,16 @@
         switch (state) {
             case TelephonyManager.DATA_CONNECTED:
             case TelephonyManager.DATA_SUSPENDED:
-                item.setTitle(R.string.radioInfo_menu_disableData);
+                item.setTitle(DISABLE_DATA_STR);
                 break;
             case TelephonyManager.DATA_DISCONNECTED:
-                item.setTitle(R.string.radioInfo_menu_enableData);
+                item.setTitle(ENABLE_DATA_STR);
                 break;
             default:
                 visible = false;
                 break;
         }
         item.setVisible(visible);
-
-        // Get the toggle-data-on-boot menu item in the right state.
-        item = menu.findItem(MENU_ITEM_TOGGLE_DATA_ON_BOOT);
-        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
-        boolean value = sp.getBoolean(GSMPhone.DATA_DISABLED_ON_BOOT_KEY, false);
-        if (value) {
-            item.setTitle(R.string.radioInfo_menu_enableDataOnBoot);
-        } else {
-            item.setTitle(R.string.radioInfo_menu_disableDataOnBoot);
-        }
         return true;
     }
 
@@ -554,42 +408,6 @@
         radioPowerButton.setText(buttonText);
     }
 
-    private void updateQxdmState(Boolean newQxdmStatus) {
-        SharedPreferences sp =
-          PreferenceManager.getDefaultSharedPreferences(phone.getContext());
-        mQxdmLogEnabled = sp.getBoolean("qxdmstatus", false);
-        // This is called from onCreate, onResume, and the handler when the status
-        // is updated.
-        if (newQxdmStatus != null) {
-            SharedPreferences.Editor editor = sp.edit();
-            editor.putBoolean("qxdmstatus", newQxdmStatus);
-            editor.commit();
-            mQxdmLogEnabled = newQxdmStatus;
-        }
-
-        String buttonText = mQxdmLogEnabled ?
-                            getString(R.string.turn_off_qxdm) :
-                            getString(R.string.turn_on_qxdm);
-        qxdmLogButton.setText(buttonText);
-    }
-
-    private void setCiphPref(boolean value) {
-        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
-        SharedPreferences.Editor editor = sp.edit();
-        editor.putBoolean(GSMPhone.CIPHERING_KEY, value);
-        editor.commit();
-    }
-
-    private boolean getCiphPref() {
-        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
-        boolean ret = sp.getBoolean(GSMPhone.CIPHERING_KEY, true);
-        return ret;
-    }
-
-    private void updateCiphState() {
-        cipherState.setText(getCiphPref() ? "Ciphering ON" : "Ciphering OFF");
-    }
-
     private void updateDnsCheckState() {
         dnsCheckState.setText(phone.isDnsCheckDisabled() ?
                 "0.0.0.0 allowed" :"0.0.0.0 not allowed");
@@ -987,19 +805,6 @@
         disconnects.setText(sb.toString());
     }
 
-    private void displayQxdmEnableResult() {
-        String status = mQxdmLogEnabled ? "Start QXDM Log" : "Stop QXDM Log";
-
-        new AlertDialog.Builder(this).setMessage(status).show();
-
-        mHandler.postDelayed(
-                new Runnable() {
-                    public void run() {
-                        finish();
-                    }
-                }, 2000);
-    }
-
     private MenuItem.OnMenuItemClickListener mViewADNCallback = new MenuItem.OnMenuItemClickListener() {
         public boolean onMenuItemClick(MenuItem item) {
             Intent intent = new Intent(Intent.ACTION_VIEW);
@@ -1046,24 +851,18 @@
         }
     };
 
-    private void toggleDataDisabledOnBoot() {
-        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(phone.getContext());
-        SharedPreferences.Editor editor = sp.edit();
-        boolean value = sp.getBoolean(GSMPhone.DATA_DISABLED_ON_BOOT_KEY, false);
-        editor.putBoolean(GSMPhone.DATA_DISABLED_ON_BOOT_KEY, !value);
-        byte[] data = mOem.getPsAutoAttachData(value);
-        if (data == null) {
-            // don't commit
-            return;
-        }
-
-        editor.commit();
-        phone.invokeOemRilRequestRaw(data, null);
-    }
-
-    private MenuItem.OnMenuItemClickListener mToggleDataOnBoot = new MenuItem.OnMenuItemClickListener() {
+    private MenuItem.OnMenuItemClickListener mGetPdpList = new MenuItem.OnMenuItemClickListener() {
         public boolean onMenuItemClick(MenuItem item) {
-            toggleDataDisabledOnBoot();
+            phone.getDataCallList(null);
+            return true;
+        }
+    };
+
+    private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
+        public boolean onMenuItemClick(MenuItem item) {
+            Intent intent = new Intent();
+            intent.setClass(RadioInfo.this, BandMode.class);
+            startActivity(intent);
             return true;
         }
     };
@@ -1086,22 +885,6 @@
         }
     };
 
-    private MenuItem.OnMenuItemClickListener mGetPdpList = new MenuItem.OnMenuItemClickListener() {
-        public boolean onMenuItemClick(MenuItem item) {
-            phone.getDataCallList(null);
-            return true;
-        }
-    };
-
-    private MenuItem.OnMenuItemClickListener mSelectBandCallback = new MenuItem.OnMenuItemClickListener() {
-        public boolean onMenuItemClick(MenuItem item) {
-            Intent intent = new Intent();
-            intent.setClass(RadioInfo.this, BandMode.class);
-            startActivity(intent);
-            return true;
-        }
-    };
-
     OnClickListener mPowerButtonHandler = new OnClickListener() {
         public void onClick(View v) {
             //log("toggle radio power: currently " + (isRadioOn()?"on":"off"));
@@ -1109,20 +892,6 @@
         }
     };
 
-    OnClickListener mCipherButtonHandler = new OnClickListener() {
-        public void onClick(View v) {
-            mCipherOn = !getCiphPref();
-            byte[] data = mOem.getCipheringData(mCipherOn);
-
-            if (data == null)
-                return;
-
-            cipherState.setText("Setting...");
-            phone.invokeOemRilRequestRaw(data,
-                    mHandler.obtainMessage(EVENT_SET_CIPHER_DONE));
-        }
-    };
-
     OnClickListener mDnsCheckButtonHandler = new OnClickListener() {
         public void onClick(View v) {
             phone.disableDnsCheck(!phone.isDnsCheckDisabled());
@@ -1130,6 +899,19 @@
         }
     };
 
+    OnClickListener mOemInfoButtonHandler = new OnClickListener() {
+        public void onClick(View v) {
+            Intent intent = new Intent("com.android.settings.OEM_RADIO_INFO");
+            try {
+                startActivity(intent);
+            } catch (android.content.ActivityNotFoundException ex) {
+                Log.d(TAG, "OEM-specific Info/Settings Activity Not Found : " + ex);
+                // If the activity does not exist, there are no OEM
+                // settings, and so we can just do nothing...
+            }
+        }
+    };
+
     OnClickListener mPingButtonHandler = new OnClickListener() {
         public void onClick(View v) {
             updatePingState();
@@ -1150,22 +932,6 @@
         }
     };
 
-    OnClickListener mQxdmButtonHandler = new OnClickListener() {
-        public void onClick(View v) {
-            byte[] data = mOem.getQxdmSdlogData(
-                    !mQxdmLogEnabled,
-                    mOem.OEM_QXDM_SDLOG_DEFAULT_FILE_SIZE,
-                    mOem.OEM_QXDM_SDLOG_DEFAULT_MASK,
-                    mOem.OEM_QXDM_SDLOG_DEFAULT_MAX_INDEX);
-
-            if (data == null)
-                return;
-
-            phone.invokeOemRilRequestRaw(data,
-                    mHandler.obtainMessage(EVENT_SET_QXDMLOG_DONE));
-        }
-    };
-
     AdapterView.OnItemSelectedListener
             mPreferredNetworkHandler = new AdapterView.OnItemSelectedListener() {
         public void onItemSelected(AdapterView parent, View v, int pos, long id) {