Java Code Examples for android.telephony.TelephonyManager#PHONE_TYPE_NONE

The following examples show how to use android.telephony.TelephonyManager#PHONE_TYPE_NONE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public boolean hasEarpiece() {
	if(USE_CONNECTION_SERVICE){
		if(systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
			int routeMask=systemCallConnection.getCallAudioState().getSupportedRouteMask();
			return (routeMask & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_WIRED_HEADSET))!=0;
		}
	}
	if(((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).getPhoneType()!=TelephonyManager.PHONE_TYPE_NONE)
		return true;
	if (mHasEarpiece != null) {
		return mHasEarpiece;
	}

	// not calculated yet, do it now
	try {
		AudioManager am=(AudioManager)getSystemService(AUDIO_SERVICE);
		Method method = AudioManager.class.getMethod("getDevicesForStream", Integer.TYPE);
		Field field = AudioManager.class.getField("DEVICE_OUT_EARPIECE");
		int earpieceFlag = field.getInt(null);
		int bitmaskResult = (int) method.invoke(am, AudioManager.STREAM_VOICE_CALL);

		// check if masked by the earpiece flag
		if ((bitmaskResult & earpieceFlag) == earpieceFlag) {
			mHasEarpiece = Boolean.TRUE;
		} else {
			mHasEarpiece = Boolean.FALSE;
		}
	} catch (Throwable error) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("Error while checking earpiece! ", error);
		}
		mHasEarpiece = Boolean.TRUE;
	}

	return mHasEarpiece;
}
 
Example 2
Source File: PhoneCapabilityTester.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private static void initialize(Context context) {
    final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    
    sIsPhone = (telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE);
    //sIsSipPhone = sIsPhone && SipManager.isVoipSupported(context);
    Intent pIntent = getPriviledgedIntent("123");
    callIntents = getPossibleActivities(context, pIntent);
    PackageManager pm = context.getPackageManager();
    defaultCallIntent = pm.resolveActivity(pIntent, PackageManager.MATCH_DEFAULT_ONLY);
    
    sIsInitialized = true;
}
 
Example 3
Source File: AppHelper.java    From Utils with Apache License 2.0 5 votes vote down vote up
/**
 * this device has phone radio?
 *
 * @param context
 * @return
 */
public static boolean isPhone(Context context) {
    TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int type = telephony.getPhoneType();
    if (type == TelephonyManager.PHONE_TYPE_NONE) {
        return false;
    } else {
        return true;
    }
}
 
Example 4
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public boolean hasEarpiece() {
	if(USE_CONNECTION_SERVICE){
		if(systemCallConnection!=null && systemCallConnection.getCallAudioState()!=null){
			int routeMask=systemCallConnection.getCallAudioState().getSupportedRouteMask();
			return (routeMask & (CallAudioState.ROUTE_EARPIECE | CallAudioState.ROUTE_WIRED_HEADSET))!=0;
		}
	}
	if(((TelephonyManager)getSystemService(TELEPHONY_SERVICE)).getPhoneType()!=TelephonyManager.PHONE_TYPE_NONE)
		return true;
	if (mHasEarpiece != null) {
		return mHasEarpiece;
	}

	// not calculated yet, do it now
	try {
		AudioManager am=(AudioManager)getSystemService(AUDIO_SERVICE);
		Method method = AudioManager.class.getMethod("getDevicesForStream", Integer.TYPE);
		Field field = AudioManager.class.getField("DEVICE_OUT_EARPIECE");
		int earpieceFlag = field.getInt(null);
		int bitmaskResult = (int) method.invoke(am, AudioManager.STREAM_VOICE_CALL);

		// check if masked by the earpiece flag
		if ((bitmaskResult & earpieceFlag) == earpieceFlag) {
			mHasEarpiece = Boolean.TRUE;
		} else {
			mHasEarpiece = Boolean.FALSE;
		}
	} catch (Throwable error) {
		if (BuildVars.LOGS_ENABLED) {
			FileLog.e("Error while checking earpiece! ", error);
		}
		mHasEarpiece = Boolean.TRUE;
	}

	return mHasEarpiece;
}
 
Example 5
Source File: Utils.java    From Noyze with Apache License 2.0 4 votes vote down vote up
/** @return True if the device has phone capabilities. */
public static boolean hasTelephone(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return (telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE);
}
 
Example 6
Source File: CancelAccountDeletionActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNextPressed() {
    if (getParentActivity() == null || nextPressed) {
        return;
    }
    TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
    boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    boolean allowCall = true;
    if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
        //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
        /*if (checkPermissions) {
            permissionsItems.clear();
            if (!allowCall) {
                permissionsItems.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (!permissionsItems.isEmpty()) {
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) {
                    preferences.edit().putBoolean("firstlogin", false).commit();
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall));
                    permissionsDialog = showDialog(builder.create());
                } else {
                    getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6);
                }
                return;
            }
        }*/
    }

    final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode();
    req.hash = hash;
    req.settings = new TLRPC.TL_codeSettings();
    req.settings.allow_flashcall = false;//simcardAvailable && allowCall;
    req.settings.allow_app_hash = ApplicationLoader.hasPlayServices;
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
    if (req.settings.allow_app_hash) {
        preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit();
    } else {
        preferences.edit().remove("sms_hash").commit();
    }
    if (req.settings.allow_flashcall) {
        try {
            @SuppressLint("HardwareIds") String number = tm.getLine1Number();
            if (!TextUtils.isEmpty(number)) {
                req.settings.current_number = PhoneNumberUtils.compare(phone, number);
                if (!req.settings.current_number) {
                    req.settings.allow_flashcall = false;
                }
            } else {
                req.settings.current_number = false;
            }
        } catch (Exception e) {
            req.settings.allow_flashcall = false;
            FileLog.e(e);
        }
    }

    final Bundle params = new Bundle();
    params.putString("phone", phone);
    nextPressed = true;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        nextPressed = false;
        if (error == null) {
            fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
        } else {
            errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req);
        }
    }), ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 7
Source File: PaymentFormActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@SuppressLint("HardwareIds")
public void fillNumber(String number) {
    try {
        TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
        boolean allowCall = true;
        boolean allowSms = true;
        if (number != null || tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
            if (Build.VERSION.SDK_INT >= 23) {
                allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
            }
            if (number != null || allowCall) {
                if (number == null) {
                    number = PhoneFormat.stripExceptNumbers(tm.getLine1Number());
                }
                String textToSet = null;
                boolean ok = false;
                if (!TextUtils.isEmpty(number)) {
                    if (number.length() > 4) {
                        for (int a = 4; a >= 1; a--) {
                            String sub = number.substring(0, a);
                            String country = codesMap.get(sub);
                            if (country != null) {
                                ok = true;
                                textToSet = number.substring(a);
                                inputFields[FIELD_PHONECODE].setText(sub);
                                break;
                            }
                        }
                        if (!ok) {
                            textToSet = number.substring(1);
                            inputFields[FIELD_PHONECODE].setText(number.substring(0, 1));
                        }
                    }
                    if (textToSet != null) {
                        inputFields[FIELD_PHONE].setText(textToSet);
                        inputFields[FIELD_PHONE].setSelection(inputFields[FIELD_PHONE].length());
                    }
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 8
Source File: MyDialerActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 4 votes vote down vote up
private void listing20_6() {
  String srvcName = Context.TELEPHONY_SERVICE;
  TelephonyManager telephonyManager = (TelephonyManager)getSystemService(srvcName);

  // Listing 20-6: Accessing phone-type and the device’s phone number
  String phoneTypeStr = "unknown";

  int phoneType = telephonyManager.getPhoneType();

  switch (phoneType) {
    case (TelephonyManager.PHONE_TYPE_CDMA):
      phoneTypeStr = "CDMA";
      break;
    case (TelephonyManager.PHONE_TYPE_GSM) :
      phoneTypeStr = "GSM";
      break;
    case (TelephonyManager.PHONE_TYPE_SIP):
      phoneTypeStr = "SIP";
      break;
    case (TelephonyManager.PHONE_TYPE_NONE):
      phoneTypeStr = "None";
      break;
    default: break;
  }

  Log.d(TAG, phoneTypeStr);

  // -- These require READ_PHONE_STATE uses-permission --
  int permission = ActivityCompat.checkSelfPermission(this,
    android.Manifest.permission.READ_PHONE_STATE);
  if (permission == PackageManager.PERMISSION_GRANTED) {

    // Read the IMEI for GSM or MEID for CDMA
    String deviceId = telephonyManager.getDeviceId();

    // Read the software version on the phone (note -- not the SDK version)
    String softwareVersion = telephonyManager.getDeviceSoftwareVersion();

    // Get the phone's number (if available)
    String phoneNumber = telephonyManager.getLine1Number();

    // If permission hasn't been granted, request it.
  } else {
    if (ActivityCompat.shouldShowRequestPermissionRationale(
      this, android.Manifest.permission.READ_PHONE_STATE)) {
      // TODO Display additional rationale for the requested permission.
    }
    ActivityCompat.requestPermissions(this,
      new String[]{android.Manifest.permission.READ_PHONE_STATE},
      PHONE_STATE_PERMISSION_REQUEST);
  }
}
 
Example 9
Source File: LoginActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void fillNumber()
{
    try
    {
        TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE)
        {
            boolean allowCall = true;
            boolean allowSms = true;
            if (Build.VERSION.SDK_INT >= 23)
            {
                allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
                allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED;
                if (checkShowPermissions && !allowCall && !allowSms)
                {
                    permissionsShowItems.clear();
                    if (!allowCall)
                    {
                        permissionsShowItems.add(Manifest.permission.READ_PHONE_STATE);
                    }
                    if (!allowSms)
                    {
                        permissionsShowItems.add(Manifest.permission.RECEIVE_SMS);
                        if (Build.VERSION.SDK_INT >= 23)
                        {
                            permissionsShowItems.add(Manifest.permission.READ_SMS);
                        }
                    }
                    if (!permissionsShowItems.isEmpty())
                    {
                        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                        if (preferences.getBoolean("firstloginshow", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS))
                        {
                            preferences.edit().putBoolean("firstloginshow", false).commit();
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                            builder.setMessage(LocaleController.getString("AllowFillNumber", R.string.AllowFillNumber));
                            permissionsShowDialog = showDialog(builder.create());
                        }
                        else
                        {
                            getParentActivity().requestPermissions(permissionsShowItems.toArray(new String[permissionsShowItems.size()]), 7);
                        }
                    }
                    return;
                }
            }
            if (!newAccount && (allowCall || allowSms))
            {
                String number = PhoneFormat.stripExceptNumbers(tm.getLine1Number());
                String textToSet = null;
                boolean ok = false;
                if (!TextUtils.isEmpty(number))
                {
                    if (number.length() > 4)
                    {
                        for (int a = 4; a >= 1; a--)
                        {
                            String sub = number.substring(0, a);
                            String country = codesMap.get(sub);
                            if (country != null)
                            {
                                ok = true;
                                textToSet = number.substring(a, number.length());
                                codeField.setText(sub);
                                break;
                            }
                        }
                        if (!ok)
                        {
                            textToSet = number.substring(1, number.length());
                            codeField.setText(number.substring(0, 1));
                        }
                    }
                    if (textToSet != null)
                    {
                        phoneField.requestFocus();
                        phoneField.setText(textToSet);
                        phoneField.setSelection(phoneField.length());
                    }
                }
            }
        }
    }
    catch (Exception e)
    {
        FileLog.e(e);
    }
}
 
Example 10
Source File: TraceDeviceInfo.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static String getTelephonyHeader() {
	// Telephony manager can tell us a few things...
	String info = "";

	if (m_telephonyManager != null) {
		try { // getDeviceId() requires android.permission.READ_PHONE_STATE
			info = "<deviceid>" + m_telephonyManager.getDeviceId() + "</deviceid>";
		} catch (Exception e1) {
			DebugTool.logError("Failure getting telephony device ID: " + e1.toString(), e1);
		}

		info = "<pt>";
		switch (m_telephonyManager.getPhoneType()) {
			case TelephonyManager.PHONE_TYPE_NONE:
				info += "NONE";
				break;
			case TelephonyManager.PHONE_TYPE_GSM:
				info += "GSM";
				break;
			case TelephonyManager.PHONE_TYPE_CDMA:
				info += "CDMA";
				break;
			default:
				info += "UNKNOWN";
		} // end-switch

		info += "</pt>" + "<nt>";

		switch (m_telephonyManager.getNetworkType()) {
			case TelephonyManager.NETWORK_TYPE_UNKNOWN:
				info += "UKNOWN";
				break;
			case TelephonyManager.NETWORK_TYPE_GPRS:
				info += "GPRS";
				break;
			case TelephonyManager.NETWORK_TYPE_EDGE:
				info += "EDGE";
				break;
			case TelephonyManager.NETWORK_TYPE_UMTS:
				info += "UMTS";
				break;
			case TelephonyManager.NETWORK_TYPE_HSDPA:
				info += "HSDPA";
				break;
			case TelephonyManager.NETWORK_TYPE_HSUPA:
				info += "HSUPA";
				break;
			case TelephonyManager.NETWORK_TYPE_HSPA:
				info += "HSPA";
				break;
			case TelephonyManager.NETWORK_TYPE_CDMA:
				info += "CDMA";
				break;
			case TelephonyManager.NETWORK_TYPE_EVDO_0:
				info += "EVDO_O";
				break;
			case TelephonyManager.NETWORK_TYPE_EVDO_A:
				info += "EVDO_A";
				break;
			case TelephonyManager.NETWORK_TYPE_1xRTT:
				info += "1xRTT";
				break;
			default:
				info += "UNKNOWN";
				break;
		} // end-switch

		info += "</nt>";
	} // end-if
	return info;
}
 
Example 11
Source File: CancelAccountDeletionActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNextPressed() {
    if (getParentActivity() == null || nextPressed) {
        return;
    }
    TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
    boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    boolean allowCall = true;
    if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
        //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
        //boolean allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED;
        /*if (checkPermissions) {
            permissionsItems.clear();
            if (!allowCall) {
                permissionsItems.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (!allowSms) {
                permissionsItems.add(Manifest.permission.RECEIVE_SMS);
            }
            if (!permissionsItems.isEmpty()) {
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.RECEIVE_SMS)) {
                    preferences.edit().putBoolean("firstlogin", false).commit();
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    if (permissionsItems.size() == 2) {
                        builder.setMessage(LocaleController.getString("AllowReadCallAndSms", R.string.AllowReadCallAndSms));
                    } else if (!allowSms) {
                        builder.setMessage(LocaleController.getString("AllowReadSms", R.string.AllowReadSms));
                    } else {
                        builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall));
                    }
                    permissionsDialog = showDialog(builder.create());
                } else {
                    getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6);
                }
                return;
            }
        }*/
    }

    final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode();
    req.allow_flashcall = false;//simcardAvailable && allowCall;
    req.hash = hash;
    if (req.allow_flashcall) {
        try {
            @SuppressLint("HardwareIds") String number = tm.getLine1Number();
            if (!TextUtils.isEmpty(number)) {
                req.current_number = phone.contains(number) || number.contains(phone);
                if (!req.current_number) {
                    req.allow_flashcall = false;
                }
            } else {
                req.current_number = false;
            }
        } catch (Exception e) {
            req.allow_flashcall = false;
            FileLog.e(e);
        }
    }

    final Bundle params = new Bundle();
    params.putString("phone", phone);
    nextPressed = true;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate() {
        @Override
        public void run(final TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public void run() {
                    nextPressed = false;
                    if (error == null) {
                        fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
                    } else {
                        errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req);
                    }
                }
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 12
Source File: DeviceUtils.java    From Android-utils with Apache License 2.0 4 votes vote down vote up
public static boolean isPhone() {
    TelephonyManager tm =
            (TelephonyManager) UtilsApp.getApp().getSystemService(Context.TELEPHONY_SERVICE);
    // noinspection ConstantConditions
    return tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}
 
Example 13
Source File: CellTracker.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Description:    Add entries to the "DBi_measure" DB table
 *
 * Issues:
 *                  [ ]
 *
 * Notes:           (a)
 *
 *
 * TODO:  Remove OLD notes below, once we have new ones relevant to our new table
 *
 *  From "locationinfo":
 *
 *      $ sqlite3.exe -header aimsicd.db 'select * from locationinfo;'
 *      _id|Lac|CellID|Net|Lat|Lng|Signal|Connection|Timestamp
 *      1|10401|6828xxx|10|54.67874392|25.28693531|24|[10401,6828320,126]No|Di|HSPA||2015-01-21 20:45:10
 *
 *  From "cellinfo":
 *
 *      $ sqlite3.exe -header aimsicd.db 'select * from cellinfo;'
 *      _id|Lac|CellID|Net|Lat|Lng|Signal|Mcc|Mnc|Accuracy|Speed|Direction|NetworkType|MeasurementTaken|OCID_SUBMITTED|Timestamp
 *      1|10401|6828xxx|10|54.67874392|25.28693531|24|246|2|69.0|0.0|0.0|HSPA|82964|0|2015-01-21 20:45:10
 *
 *  Issues:
 *
 */
public void onLocationChanged(Location loc) {

    DeviceApi18.loadCellInfo(tm, mDevice);

    if (!mDevice.mCell.isValid()) {
        CellLocation cellLocation = tm.getCellLocation();
        if (cellLocation != null) {
            switch (mDevice.getPhoneID()) {

                case TelephonyManager.PHONE_TYPE_NONE:
                case TelephonyManager.PHONE_TYPE_SIP:
                case TelephonyManager.PHONE_TYPE_GSM:
                    GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
                    mDevice.mCell.setCID(gsmCellLocation.getCid()); // CID
                    mDevice.mCell.setLAC(gsmCellLocation.getLac()); // LAC
                    mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC
                    break;

                case TelephonyManager.PHONE_TYPE_CDMA:
                    CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) cellLocation;
                    mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId()); // BSID ??
                    mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId());     // NID
                    mDevice.mCell.setSID(cdmaCellLocation.getSystemId());      // SID
                    mDevice.mCell.setMNC(cdmaCellLocation.getSystemId());      // MNC <== BUG!??

                    break;
            }
        }
    }

    if (loc != null &&  (Double.doubleToRawLongBits(loc.getLatitude()) != 0  &&  Double.doubleToRawLongBits(loc.getLongitude()) != 0)) {

        mDevice.mCell.setLon(loc.getLongitude());       // gpsd_lon
        mDevice.mCell.setLat(loc.getLatitude());        // gpsd_lat
        mDevice.mCell.setSpeed(loc.getSpeed());         // speed        // TODO: Remove, we're not using it!
        mDevice.mCell.setAccuracy(loc.getAccuracy());   // gpsd_accu
        mDevice.mCell.setBearing(loc.getBearing());     // -- [deg]??   // TODO: Remove, we're not using it!
        mDevice.setLastLocation(loc);                   //

        // Store last known location in preference
        SharedPreferences.Editor prefsEditor;
        prefsEditor = prefs.edit();
        prefsEditor.putString(context.getString(R.string.data_last_lat_lon),
                String.valueOf(loc.getLatitude()) + ":" + String.valueOf(loc.getLongitude()));
        prefsEditor.apply();

        // This only logs a BTS if we have GPS lock
        // Test: ~~Is correct behaviour? We should consider logging all cells, even without GPS.~~
        //if (mTrackingCell) {
            // This also checks that the lac are cid are not in DB before inserting
            dbHelper.insertBTS(mDevice.mCell);
        //}
    }
}
 
Example 14
Source File: SmsUtilities.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Opens the system sms app to send the message.
 *
 * @param context the {@link Context} to use.
 * @param number  the number to which to send to or <code>null</code>, in which
 *                case the number will be prompted in the sms app.
 * @param msg     the message to send or <code>null</code>.
 */
public static void sendSMSViaApp(Context context, String number, String msg) {
    Object systemService = context.getSystemService(Context.TELEPHONY_SERVICE);
    if (systemService instanceof TelephonyManager) {

        TelephonyManager telManager = (TelephonyManager) systemService;
        int phoneType = telManager.getPhoneType();
        if (phoneType == TelephonyManager.PHONE_TYPE_NONE) {
            // no phone
            GPDialogs.warningDialog(context, "This functionality works only when connected to a GSM network.", null);
            return;
        }
    }

    if (number == null) {
        number = "";
    }
    if (msg == null) {
        msg = "";
    }

    if (Build.VERSION.SDK_INT >= 19 && number.length() == 0) {
        // if no number is here show a nice list of last used conversations to choose from
        try {
            Class<?> smsClass = Class.forName("android.provider.Telephony$Sms");
            Method getPackageMethod = smsClass.getMethod("getDefaultSmsPackage", Context.class);
            Object defaultSmsPackageNameObj = getPackageMethod.invoke(null, context);
            if (defaultSmsPackageNameObj instanceof String) {
                String defaultSmsPackageName = (String) defaultSmsPackageNameObj;
                // String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context);
                Intent sendIntent = new Intent(Intent.ACTION_SEND);
                sendIntent.setType("text/plain");
                sendIntent.putExtra(Intent.EXTRA_TEXT, msg);
                sendIntent.setPackage(defaultSmsPackageName);
                context.startActivity(sendIntent);
            }
        } catch (Exception e) {
            GPLog.error("SmsUtilities", "Error sending sms in > 4.4.", e);
        }
    } else {
        // if a number is available, then set the message for that contact/number
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:" + number));
        intent.putExtra("sms_body", msg);
        context.startActivity(intent);
    }
}
 
Example 15
Source File: CFCallNumber.java    From CordovaCallNumberPlugin with MIT License 4 votes vote down vote up
private boolean isTelephonyEnabled() {
  TelephonyManager tm = (TelephonyManager) cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE);
  return tm != null && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}
 
Example 16
Source File: CellTracker.java    From AIMSICDL with GNU General Public License v3.0 4 votes vote down vote up
public void onCellLocationChanged(CellLocation location) {

            checkForNeighbourCount(location);
            compareLac(location);
            refreshDevice();
            mDevice.setNetID(tm);
            mDevice.getNetworkTypeName();

            switch (mDevice.getPhoneID()) {

                case TelephonyManager.PHONE_TYPE_NONE:
                case TelephonyManager.PHONE_TYPE_SIP:
                case TelephonyManager.PHONE_TYPE_GSM:
                    GsmCellLocation gsmCellLocation = (GsmCellLocation) location;
                    if (gsmCellLocation != null) {
                        //TODO @EVA where are we sending this setCellInfo data?

                        //TODO
                        /*@EVA
                            Is it a good idea to dump all cells to db because if we spot a known cell
                            with different lac then this will also be dump to db.

                        */
                        mDevice.setCellInfo(
                                gsmCellLocation.toString() +                // ??
                                mDevice.getDataActivityTypeShort() + "|" +  // No,In,Ou,IO,Do
                                mDevice.getDataStateShort() + "|" +         // Di,Ct,Cd,Su
                                mDevice.getNetworkTypeName() + "|"          // HSPA,LTE etc
                        );

                        mDevice.mCell.setLAC(gsmCellLocation.getLac());     // LAC
                        mDevice.mCell.setCID(gsmCellLocation.getCid());     // CID
                        if (gsmCellLocation.getPsc() != -1) {
                            mDevice.mCell.setPSC(gsmCellLocation.getPsc()); // PSC
                        }

                        /*
                            Add cell if gps is not enabled
                            when gps enabled lat lon will be updated
                            by function below

                         */
                    }
                    break;

                case TelephonyManager.PHONE_TYPE_CDMA:
                    CdmaCellLocation cdmaCellLocation = (CdmaCellLocation) location;
                    if (cdmaCellLocation != null) {
                        mDevice.setCellInfo(
                                cdmaCellLocation.toString() +                       // ??
                                mDevice.getDataActivityTypeShort() + "|" +  // No,In,Ou,IO,Do
                                mDevice.getDataStateShort() + "|" +         // Di,Ct,Cd,Su
                                mDevice.getNetworkTypeName() + "|"          // HSPA,LTE etc
                        );
                        mDevice.mCell.setLAC(cdmaCellLocation.getNetworkId());      // NID
                        mDevice.mCell.setCID(cdmaCellLocation.getBaseStationId());  // BID
                        mDevice.mCell.setSID(cdmaCellLocation.getSystemId());       // SID
                        mDevice.mCell.setMNC(cdmaCellLocation.getSystemId());       // MNC <== BUG!??
                        mDevice.setNetworkName(tm.getNetworkOperatorName());        // ??
                    }
            }

        }
 
Example 17
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@SuppressLint("HardwareIds")
public void fillNumber(String number) {
    try {
        TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
        boolean allowCall = true;
        boolean allowSms = true;
        if (number != null || tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE) {
            if (Build.VERSION.SDK_INT >= 23) {
                allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
                allowSms = getParentActivity().checkSelfPermission(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED;
            }
            if (number != null || allowCall || allowSms) {
                if (number == null) {
                    number = PhoneFormat.stripExceptNumbers(tm.getLine1Number());
                }
                String textToSet = null;
                boolean ok = false;
                if (!TextUtils.isEmpty(number)) {
                    if (number.length() > 4) {
                        for (int a = 4; a >= 1; a--) {
                            String sub = number.substring(0, a);
                            String country = codesMap.get(sub);
                            if (country != null) {
                                ok = true;
                                textToSet = number.substring(a, number.length());
                                inputFields[FIELD_PHONECODE].setText(sub);
                                break;
                            }
                        }
                        if (!ok) {
                            textToSet = number.substring(1, number.length());
                            inputFields[FIELD_PHONECODE].setText(number.substring(0, 1));
                        }
                    }
                    if (textToSet != null) {
                        inputFields[FIELD_PHONE].setText(textToSet);
                        inputFields[FIELD_PHONE].setSelection(inputFields[FIELD_PHONE].length());
                    }
                }
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 18
Source File: CancelAccountDeletionActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNextPressed() {
    if (getParentActivity() == null || nextPressed) {
        return;
    }
    TelephonyManager tm = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
    boolean simcardAvailable = tm.getSimState() != TelephonyManager.SIM_STATE_ABSENT && tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
    boolean allowCall = true;
    if (Build.VERSION.SDK_INT >= 23 && simcardAvailable) {
        //allowCall = getParentActivity().checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
        /*if (checkPermissions) {
            permissionsItems.clear();
            if (!allowCall) {
                permissionsItems.add(Manifest.permission.READ_PHONE_STATE);
            }
            if (!permissionsItems.isEmpty()) {
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                if (preferences.getBoolean("firstlogin", true) || getParentActivity().shouldShowRequestPermissionRationale(Manifest.permission.READ_PHONE_STATE)) {
                    preferences.edit().putBoolean("firstlogin", false).commit();
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    builder.setMessage(LocaleController.getString("AllowReadCall", R.string.AllowReadCall));
                    permissionsDialog = showDialog(builder.create());
                } else {
                    getParentActivity().requestPermissions(permissionsItems.toArray(new String[permissionsItems.size()]), 6);
                }
                return;
            }
        }*/
    }

    final TLRPC.TL_account_sendConfirmPhoneCode req = new TLRPC.TL_account_sendConfirmPhoneCode();
    req.hash = hash;
    req.settings = new TLRPC.TL_codeSettings();
    req.settings.allow_flashcall = false;//simcardAvailable && allowCall;
    req.settings.allow_app_hash = ApplicationLoader.hasPlayServices;
    SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
    if (req.settings.allow_app_hash) {
        preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit();
    } else {
        preferences.edit().remove("sms_hash").commit();
    }
    if (req.settings.allow_flashcall) {
        try {
            @SuppressLint("HardwareIds") String number = tm.getLine1Number();
            if (!TextUtils.isEmpty(number)) {
                req.settings.current_number = PhoneNumberUtils.compare(phone, number);
                if (!req.settings.current_number) {
                    req.settings.allow_flashcall = false;
                }
            } else {
                req.settings.current_number = false;
            }
        } catch (Exception e) {
            req.settings.allow_flashcall = false;
            FileLog.e(e);
        }
    }

    final Bundle params = new Bundle();
    params.putString("phone", phone);
    nextPressed = true;
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
        nextPressed = false;
        if (error == null) {
            fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response);
        } else {
            errorDialog = AlertsCreator.processError(currentAccount, error, CancelAccountDeletionActivity.this, req);
        }
    }), ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 19
Source File: PhoneUtils.java    From DevUtils with Apache License 2.0 3 votes vote down vote up
/**
 * 获取手机类型
 * <pre>
 *     {@link TelephonyManager#PHONE_TYPE_NONE} 0 手机制式未知
 *     {@link TelephonyManager#PHONE_TYPE_GSM} 1 手机制式为 GSM, 移动和联通
 *     {@link TelephonyManager#PHONE_TYPE_CDMA} 2 手机制式为 CDMA, 电信
 *     {@link TelephonyManager#PHONE_TYPE_SIP} 3 手机制式为 SIP
 * </pre>
 * @return 手机类型
 */
public static int getPhoneType() {
    try {
        return AppUtils.getTelephonyManager().getPhoneType();
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getPhoneType");
    }
    return TelephonyManager.PHONE_TYPE_NONE;
}
 
Example 20
Source File: RxDeviceTool.java    From RxTools-master with Apache License 2.0 2 votes vote down vote up
/**
 * 判断设备是否是手机
 *
 * @param context 上下文
 * @return {@code true}: 是<br>{@code false}: 否
 */
public static boolean isPhone(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
}