@Override public void onResume() { // TODO Auto-generated method stub super.onResume(); int settingsNetworkMode = Settings.Secure.getInt( getContentResolver(), Settings.Secure.PREFERRED_NETWORK_MODE, preferredNetworkMode); if ((settingsNetworkMode >= 0) && (settingsNetworkMode <= 2)) { mNetworkMode.setValue(Integer.toString(settingsNetworkMode)); } if (iTelephony == null) { return; } try { boolean Sim1Insert = iTelephony.isSimInsert(Phone.GEMINI_SIM_1); boolean Sim1Ready = false; if (Sim1Insert == true) { Sim1Ready = iTelephony.isRadioOnGemini(Phone.GEMINI_SIM_1); } mNetworkMode.setEnabled(Sim1Ready); } catch (RemoteException e) { Xlog.e(TAG, "RemoteException happens......"); } }
/** * while receiving one sms, check the sms count to see whether it reaches the max count. * * @param threadId * @param context * @param flag indicate the operator (increase/decrease) * @return true if the count is less than the max size, otherwise false. */ public void isFull(Long threadId, Context context, int flag) { try { ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); if (phone != null) { if (phone.isTestIccCard() || (Integer.parseInt(SystemProperties.get("gsm.gcf.testmode", "0")) == 2)) { Log.d(TAG, "Now using test icc card..."); if (flag == OP_FLAG_INCREASE) { if (get(threadId, context) >= THREAD_MAX_SIZE) { Log.d(TAG, "Storage is full. send notification..."); SmsManager.getDefault().setSmsMemoryStatus(false); } } else if (flag == OP_FLAG_DECREASE) { if (get(threadId, context) < THREAD_MAX_SIZE) { Log.d(TAG, "Storage is available. send notification..."); SmsManager.getDefault().setSmsMemoryStatus(true); } } } } else { Log.d(TAG, "Telephony service is not available!"); } } catch (Exception ex) { Log.e(TAG, " " + ex.getMessage()); } }
/** * enable or disable interface by apn type * * @param apnType the type of APN to be enabled or disabled (e.g., mms) * @param enable {@code true} to enable the specified APN type, {@code false} to disable it. * @param radioNum 0:sim1, 1:sim2 * @return an integer value representing the outcome of the request. */ private int setEnableApnGemini(String apnType, boolean enable, int radioNum) { getPhoneService(false); /* * If the phone process has crashed in the past, we'll get a * RemoteException and need to re-reference the service. */ for (int retry = 0; retry < 2; retry++) { if (mPhoneService == null) { log("Ignoring feature request because could not acquire PhoneService"); break; } try { if (enable) { log( "gemini before enableApnTypeGemini() and mApnType is " + mApnType + " ,radioNum is " + radioNum); return mPhoneService.enableApnTypeGemini(apnType, radioNum); } else { return mPhoneService.disableApnTypeGemini(apnType, radioNum); } } catch (RemoteException e) { if (retry == 0) getPhoneService(true); } } log("Could not " + (enable ? "enable" : "disable") + " APN type \"" + apnType + "\""); return PhoneConstants.APN_REQUEST_FAILED; }
/** * Resumes a call in progress. Typically launched from the EmergencyCall button on various * lockscreens. * * @return true if we were able to tell InCallScreen to show. */ public boolean resumeCall() { ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); try { if (phone != null && phone.showCallScreen()) { return true; } } catch (RemoteException e) { // What can we do? } return false; }
private int test01PhoneCall() { try { String packageName = ActivityThread.currentPackageName(); ITelephony iTel = ITelephony.Stub.asInterface(ServiceManager.getService(TELEPHONY_SERVICE)); Log.i(TAG, "test01PhoneCall " + phoneNumber()); iTel.call(packageName, phoneNumber()); return MSG_TEST_FINISH; } catch (RemoteException e) { Log.e(TAG, e.toString()); return MSG_TEST_FAILED; } }
private void ringOff() { try { Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class); IBinder binder = (IBinder) method.invoke(null, new Object[] {Context.TELEPHONY_SERVICE}); ITelephony mService = ITelephony.Stub.asInterface(binder); mService.endCall(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** for inheritence. */ protected String getFillListQuery() { boolean isMVNO = false; try { ITelephony telephony = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); if (FeatureOption.MTK_MVNO_SUPPORT) { if (FeatureOption.MTK_GEMINI_SUPPORT) { isMVNO = telephony.isIccCardProviderAsMvnoGemini(mSimId); } else { isMVNO = telephony.isIccCardProviderAsMvno(); } } } catch (android.os.RemoteException e) { Xlog.d(TAG, "RemoteException"); } boolean flagImsi = false; boolean flagSpn = false; boolean flagPnn = false; String sqlStr = ""; Xlog.d(TAG, "[isMVNO =" + isMVNO + "]"); if (FeatureOption.MTK_MVNO_SUPPORT) { if (isMVNO) { if (mIMSI != null && !mIMSI.isEmpty()) { flagImsi = true; sqlStr += " imsi=\"" + mIMSI + "\""; } if (mSpn != null && !mSpn.isEmpty()) { flagSpn = true; if (flagImsi) { sqlStr += " or spn=\"" + mSpn + "\""; } else { sqlStr += " spn=\"" + mSpn + "\""; } } if (mPnn != null && !mPnn.isEmpty()) { flagPnn = true; if (flagImsi || flagSpn) { sqlStr += " or pnn=\"" + mPnn + "\""; } else { sqlStr += " pnn=\"" + mPnn + "\""; } } } else { sqlStr = "(spn is NULL or spn=\"\") and (imsi is NULL or imsi=\"\") and (pnn is NULL or pnn=\"\") "; } } String result = "numeric=\"" + mNumeric + "\" and ( " + sqlStr + ")"; Xlog.e(TAG, "getFillListQuery result: " + result); return result; }
private void setSpn() { try { ITelephony telephony = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); if (FeatureOption.MTK_GEMINI_SUPPORT) { mSpn = telephony.getSpNameInEfSpnGemini(mSimId); } else { mSpn = telephony.getSpNameInEfSpn(); } Xlog.d(TAG, "spn = " + mSpn); } catch (android.os.RemoteException e) { Xlog.d(TAG, "RemoteException"); } }
private void setIMSI() { try { ITelephony telephony = ITelephony.Stub.asInterface(ServiceManager.getService(Context.TELEPHONY_SERVICE)); if (FeatureOption.MTK_GEMINI_SUPPORT) { mIMSI = telephony.isOperatorMvnoForImsiGemini(mSimId); } else { mIMSI = telephony.isOperatorMvnoForImsi(); } Xlog.d(TAG, "IMSI = " + mIMSI); } catch (android.os.RemoteException e) { Xlog.d(TAG, "RemoteException"); } Xlog.d(TAG, "IMSI = " + mIMSI); }
public NetworkInfo getNetworkInfo() { if (FeatureOption.MTK_GEMINI_SUPPORT) { getPhoneService(true); /* * If the phone process has crashed in the past, we'll get a * RemoteException and need to re-reference the service. */ for (int retry = 0; retry < 2; retry++) { if (mPhoneService == null) { loge("Ignoring feature request because could not acquire PhoneService"); break; } try { /** * M: update availabe info due to it may not correct when we received from * ACTION_ANY_DATA_CONNECTION_STATE_CHANGED */ mNetworkInfo.setIsAvailable(mPhoneService.isDataConnectivityPossible()); log("getNetworkInfo: updated IsAvailable=" + mNetworkInfo.isAvailable()); } catch (RemoteException e) { if (retry == 0) getPhoneService(true); } } } return mNetworkInfo; }
private void endCall() { try { mTelephony.endCall(); } catch (RemoteException e) { e.printStackTrace(); } }
@Override public synchronized void onResults(Bundle results) { ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); Log.i(TAG, "result:"); for (String i : matches) { Log.i(TAG, "onResults content: " + i); } if (MyService.this.isCalling && (matches.contains("no") || matches.contains("No") || matches.contains("nO") || matches.contains("NO"))) { try { Class clazz = Class.forName(tmgr.getClass().getName()); Method method = clazz.getDeclaredMethod("getITelephony"); method.setAccessible(true); ITelephony telephonyService = (ITelephony) method.invoke(tmgr); telephonyService.endCall(); // MyService.this.isCalling = false; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } else if (!MyService.this.isMakePhoneCall && (matches.contains("yes") || matches.contains("Yes") || matches.contains("yes") || matches.contains("YES"))) { PhoneUtil.answerRingingCall(MyService.this); } else { initComponent(); mSpeechRecognizer.startListening(mSpeechRecognizerIntent); } if (!MyService.this.isCalling) { ContentContact contentContact = MyService.this.getContactFromName(matches.get(0)); if (contentContact != null) { MyService.this.makePhoneCall(contentContact.getPhoneNumber()); } } }
/** * Returns a constant indicating the radio technology (network type) currently in use on the * device for data transmission. * * @return the network type * @see #NETWORK_TYPE_UNKNOWN * @see #NETWORK_TYPE_GPRS * @see #NETWORK_TYPE_EDGE * @see #NETWORK_TYPE_UMTS * @see #NETWORK_TYPE_HSDPA * @see #NETWORK_TYPE_HSUPA * @see #NETWORK_TYPE_HSPA * @see #NETWORK_TYPE_CDMA * @see #NETWORK_TYPE_EVDO_0 * @see #NETWORK_TYPE_EVDO_A * @see #NETWORK_TYPE_EVDO_B * @see #NETWORK_TYPE_1xRTT * @see #NETWORK_TYPE_IDEN * @see #NETWORK_TYPE_LTE * @see #NETWORK_TYPE_EHRPD * @see #NETWORK_TYPE_HSPAP */ public int getNetworkType() { try { ITelephony telephony = getITelephony(); if (telephony != null) { return telephony.getNetworkType(); } else { // This can happen when the ITelephony interface is not up yet. return NETWORK_TYPE_UNKNOWN; } } catch (RemoteException ex) { // This shouldn't happen in the normal case return NETWORK_TYPE_UNKNOWN; } catch (NullPointerException ex) { // This could happen before phone restarts due to crashing return NETWORK_TYPE_UNKNOWN; } }
/** * Returns true if the intent is due to hitting the green send key (hardware call button: * KEYCODE_CALL) while in a call. * * @param intent the intent that launched this activity * @param recentCallsRequest true if the intent is requesting to view recent calls * @return true if the intent is due to hitting the green send key while in a call */ private boolean isSendKeyWhileInCall(Intent intent, boolean recentCallsRequest) { // If there is a call in progress go to the call screen if (recentCallsRequest) { final boolean callKey = intent.getBooleanExtra("call_key", false); try { ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); if (callKey && phone != null && phone.showCallScreen()) { return true; } } catch (RemoteException e) { Log.e(TAG, "Failed to handle send while in call", e); } } return false; }
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); if (null == bundle) return; this.mContext = context; Log.d(TAG, "Intent action: " + intent.getAction()); String phonenumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); Log.d(TAG, "Outgoing Call = " + phonenumber); SharedPreferences preferences = context.getSharedPreferences("TRIP", 1); boolean isTripStarted = preferences.getBoolean("isTripStarted", false); if (isTripStarted && new ConfigurePreferences(mContext).isTripAbandon()) { Log.v(TAG, "Outgoing call received when trip abandon"); return; } if (isTripStarted && !TrackingService.ignoreLocationUpdates) { if (TAGS.disableCall) { telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); connectToTelephonyService(); if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) { if (!isEmergencyNumber(phonenumber)) { try { Log.d(TAG, "Ending Outgoing Call"); setResultData(null); telephonyService.endCall(); } catch (RemoteException e) { e.printStackTrace(); } } else { Log.v(TAG, "Allowing emergency outgoing call & activate emergency trip save"); // Activate trip save as background new ConfigurePreferences(context).setEmergencyTripSave(true); // Util.saveInterruption(context, SCInterruption.EMEO); } } } else { if (isEmergencyNumber(phonenumber)) { Log.v(TAG, "Allowing emergency outgoing call & activate emergency trip save"); // Activate trip save as background new ConfigurePreferences(context).setEmergencyTripSave(true); // Util.saveInterruption(context, SCInterruption.EMEO); } else { if (!new ConfigurePreferences(mContext).isTripAbandon()) { Toast.makeText(mContext, "Outgoing call interruption", Toast.LENGTH_LONG).show(); Util.saveInterruption(context, SCInterruption.CALL); } } } } }
private void setGprsTransferType(int type) { try { ITelephony telephony = ITelephony.Stub.asInterface(ServiceManager.getService("phone")); Settings.System.putInt(getContentResolver(), Settings.System.GPRS_TRANSFER_SETTING, type); if (FeatureOption.MTK_GEMINI_SUPPORT) { if (mGeminiPhone != null) { mGeminiPhone.getPhonebyId(PhoneConstants.GEMINI_SIM_1).setGprsTransferType(type, null); mGeminiPhone.getPhonebyId(PhoneConstants.GEMINI_SIM_2).setGprsTransferType(type, null); } } else { if (telephony != null) { telephony.setGprsTransferType(type); } } } catch (RemoteException e) { Elog.v(TAG, e.getMessage()); } }
@Override public void onWindowFocusChanged(boolean hasFocus) { super.onWindowFocusChanged(hasFocus); // Clear notifications only when window gains focus. This activity won't // immediately receive focus if the keyguard screen is above it. if (hasFocus) { try { ITelephony iTelephony = ITelephony.Stub.asInterface(ServiceManager.getService("phone")); if (iTelephony != null) { iTelephony.cancelMissedCallsNotification(); } else { Log.w(TAG, "Telephony service is null, can't call " + "cancelMissedCallsNotification"); } } catch (RemoteException e) { Log.e(TAG, "Failed to clear missed calls notification due to remote exception"); } } }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_CALL: try { ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); if (phone != null && !phone.isIdle()) { // Let the super class handle it break; } } catch (RemoteException re) { // Fall through and try to call the contact } callEntry(getListView().getSelectedItemPosition()); return true; } return super.onKeyUp(keyCode, event); }
/** * Returns the current phone type. TODO: This is a last minute change and hence hidden. * * @see #PHONE_TYPE_NONE * @see #PHONE_TYPE_GSM * @see #PHONE_TYPE_CDMA * @see #PHONE_TYPE_SIP * <p>{@hide} */ public int getCurrentPhoneType() { try { ITelephony telephony = getITelephony(); if (telephony != null) { return telephony.getActivePhoneType(); } else { // This can happen when the ITelephony interface is not up yet. return getPhoneTypeFromProperty(); } } catch (RemoteException ex) { // This shouldn't happen in the normal case, as a backup we // read from the system property. return getPhoneTypeFromProperty(); } catch (NullPointerException ex) { // This shouldn't happen in the normal case, as a backup we // read from the system property. return getPhoneTypeFromProperty(); } }
private int test01PhoneCallEnd() { try { Log.i(TAG, "test01PhoneCallEnd"); Method method = Class.forName("android.os.ServiceManager").getMethod("getService", String.class); method.setAccessible(true); IBinder binder = (IBinder) method.invoke(null, new Object[] {TELEPHONY_SERVICE}); ITelephony phone = (ITelephony) ITelephony.Stub.asInterface(binder); phone.endCall(); return MSG_TEST_FINISH; } catch (ClassNotFoundException e) { Log.e(TAG, e.toString()); } catch (NoSuchMethodException e) { Log.e(TAG, e.toString()); } catch (InvocationTargetException e) { Log.e(TAG, e.toString()); } catch (IllegalAccessException e) { Log.e(TAG, e.toString()); } catch (RemoteException e) { Log.e(TAG, e.toString()); } return MSG_TEST_FAILED; }
/** check whether phone is idle or not */ public boolean isIdle() { getPhoneService(false); for (int retry = 0; retry < 2; retry++) { if (mPhoneService == null) break; try { return mPhoneService.isVoiceIdle(); } catch (RemoteException e) { // First-time failed, get the phone service again if (retry == 0) getPhoneService(true); } } return false; }
/** * Turn on or off the mobile radio. No connectivity will be possible while the radio is off. The * operation is a no-op if the radio is already in the desired state. * * @param turnOn {@code true} if the radio should be turned on, {@code false} if */ public boolean setRadio(boolean turnOn) { getPhoneService(false); /* * If the phone process has crashed in the past, we'll get a * RemoteException and need to re-reference the service. */ for (int retry = 0; retry < 2; retry++) { if (mPhoneService == null) { loge("Ignoring mobile radio request because could not acquire PhoneService"); break; } try { return mPhoneService.setRadio(turnOn); } catch (RemoteException e) { if (retry == 0) getPhoneService(true); } } loge("Could not set radio power to " + (turnOn ? "on" : "off")); return false; }
/** * Makes sure we handle the shutdown gracefully. Shuts off power regardless of radio and bluetooth * state if the alloted time has passed. */ public void run() { boolean bluetoothOff; boolean radioOff; BroadcastReceiver br = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // We don't allow apps to cancel this, so ignore the result. broadcastDone(); } }; Log.i(TAG, "Sending shutdown broadcast..."); // First send the high-level shut down broadcast. mBroadcastDone = false; mContext.sendOrderedBroadcast( new Intent(Intent.ACTION_SHUTDOWN), null, br, mHandler, 0, null, null); final long endTime = System.currentTimeMillis() + MAX_BROADCAST_TIME; synchronized (mBroadcastDoneSync) { while (!mBroadcastDone) { long delay = endTime - System.currentTimeMillis(); if (delay <= 0) { Log.w(TAG, "Shutdown broadcast timed out"); break; } try { mBroadcastDoneSync.wait(delay); } catch (InterruptedException e) { } } } Log.i(TAG, "Shutting down activity manager..."); final IActivityManager am = ActivityManagerNative.asInterface(ServiceManager.checkService("activity")); if (am != null) { try { am.shutdown(MAX_BROADCAST_TIME); } catch (RemoteException e) { } } final ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone")); final IBluetooth bluetooth = IBluetooth.Stub.asInterface( ServiceManager.checkService(BluetoothAdapter.BLUETOOTH_SERVICE)); final IMountService mount = IMountService.Stub.asInterface(ServiceManager.checkService("mount")); try { bluetoothOff = bluetooth == null || bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF; if (!bluetoothOff) { Log.w(TAG, "Disabling Bluetooth..."); bluetooth.disable(false); // disable but don't persist new state } } catch (RemoteException ex) { Log.e(TAG, "RemoteException during bluetooth shutdown", ex); bluetoothOff = true; } try { radioOff = phone == null || !phone.isRadioOn(); if (!radioOff) { Log.w(TAG, "Turning off radio..."); phone.setRadio(false); } } catch (RemoteException ex) { Log.e(TAG, "RemoteException during radio shutdown", ex); radioOff = true; } Log.i(TAG, "Waiting for Bluetooth and Radio..."); // Wait a max of 32 seconds for clean shutdown for (int i = 0; i < MAX_NUM_PHONE_STATE_READS; i++) { if (!bluetoothOff) { try { bluetoothOff = bluetooth.getBluetoothState() == BluetoothAdapter.STATE_OFF; } catch (RemoteException ex) { Log.e(TAG, "RemoteException during bluetooth shutdown", ex); bluetoothOff = true; } } if (!radioOff) { try { radioOff = !phone.isRadioOn(); } catch (RemoteException ex) { Log.e(TAG, "RemoteException during radio shutdown", ex); radioOff = true; } } if (radioOff && bluetoothOff) { Log.i(TAG, "Radio and Bluetooth shutdown complete."); break; } SystemClock.sleep(PHONE_STATE_POLL_SLEEP_MSEC); } // Shutdown MountService to ensure media is in a safe state try { if (mount != null) { mount.shutdown(); } else { Log.w(TAG, "MountService unavailable for shutdown"); } } catch (Exception e) { Log.e(TAG, "Exception during MountService shutdown", e); } // shutdown power Log.i(TAG, "Performing low-level shutdown..."); Power.shutdown(); }