Example #1
0
  /** Reset the audio mode */
  private synchronized void actualUnsetAudioInCall() {

    if (!prefs.getBoolean("isSavedAudioState", false) || !isSetAudioMode) {
      return;
    }

    Log.d(THIS_FILE, "Unset Audio In call");

    int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
    if (bluetoothWrapper != null) {
      // This fixes the BT activation but... but... seems to introduce a
      // lot of other issues
      // bluetoothWrapper.setBluetoothOn(true);
      Log.d(THIS_FILE, "Unset bt");
      bluetoothWrapper.setBluetoothOn(false);
    }
    audioManager.setMicrophoneMute(false);
    if (doFocusAudio) {
      audioManager.setStreamSolo(inCallStream, false);
      audioFocusWrapper.unFocus();
    }
    restoreAudioState();

    if (wifiLock != null && wifiLock.isHeld()) {
      wifiLock.release();
    }
    if (screenLock != null && screenLock.isHeld()) {
      Log.d(THIS_FILE, "Release screen lock");
      screenLock.release();
    }

    isSetAudioMode = false;
  }
Example #2
0
  @Override
  public void fillLayout(final SipProfile account) {
    super.fillLayout(account);

    accountUsername.setTitle(R.string.w_advanced_caller_id);
    accountUsername.setDialogTitle(R.string.w_advanced_caller_id_desc);

    boolean recycle = true;
    providerListPref = (ListPreference) findPreference(PROVIDER_LIST_KEY);
    if (providerListPref == null) {
      Log.d(THIS_FILE, "Create new list pref");
      providerListPref = new ListPreference(parent);
      providerListPref.setKey(PROVIDER_LIST_KEY);
      recycle = false;
    } else {
      Log.d(THIS_FILE, "Recycle existing list pref");
    }

    CharSequence[] v = new CharSequence[providers.size()];
    int i = 0;
    for (String pv : providers.keySet()) {
      v[i] = pv;
      i++;
    }

    providerListPref.setEntries(v);
    providerListPref.setEntryValues(v);
    providerListPref.setKey(PROVIDER);
    providerListPref.setDialogTitle("Provider");
    providerListPref.setTitle("Provider");
    providerListPref.setSummary("Betamax clone provider");
    providerListPref.setDefaultValue("12VoIP");

    if (!recycle) {
      addPreference(providerListPref);
    }
    hidePreference(null, SERVER);

    String domain = account.getDefaultDomain();
    if (domain != null) {
      for (Entry<String, String[]> entry : providers.entrySet()) {
        String[] val = entry.getValue();
        if (val[0].equalsIgnoreCase(domain)) {
          Log.d(THIS_FILE, "Set provider list pref value to " + entry.getKey());
          providerListPref.setValue(entry.getKey());
          break;
        }
      }
    }
    Log.d(THIS_FILE, providerListPref.getValue());

    // Get wizard specific row
    customWizardText = (TextView) parent.findViewById(R.id.custom_wizard_text);
    customWizard = (LinearLayout) parent.findViewById(R.id.custom_wizard_row);

    updateAccountInfos(account);
  }
  /**
   * Hide a preference from the preference screen.
   *
   * @param parentGroup key for parent group if any. If null no parent group are searched
   * @param fieldName key for the field to remove
   */
  protected void hidePreference(String parentGroup, String fieldName) {
    PreferenceScreen pfs = parent.getPreferenceScreen();
    PreferenceGroup parentPref = pfs;
    if (parentGroup != null) {
      parentPref = (PreferenceGroup) pfs.findPreference(parentGroup);
    }

    Preference toRemovePref = pfs.findPreference(fieldName);

    if (toRemovePref != null && parentPref != null) {
      boolean rem = parentPref.removePreference(toRemovePref);
      Log.d("Generic prefs", "Has removed it : " + rem);
    } else {
      Log.d("Generic prefs", "Not able to find" + parent + " " + fieldName);
    }
  }
Example #4
0
 @Override
 public void onItemClick(AdapterView<?> ad, View view, int position, long arg3) {
   String number = (String) view.getTag();
   SipProfile account = accountChooserButtonText.getSelectedAccount();
   String rewritten = Filter.rewritePhoneNumber(getContext(), account.id, number);
   setTextValue(rewritten);
   Log.d(THIS_FILE, "Clicked contact " + number);
 }
Example #5
0
 /**
  * Start ringing announce for a given contact. It will also focus audio for us.
  *
  * @param remoteContact the contact to ring for. May resolve the contact ringtone if any.
  */
 public synchronized void startRing(String remoteContact) {
   saveAudioState();
   if (!ringer.isRinging()) {
     ringer.ring(remoteContact, service.getPrefs().getRingtone());
   } else {
     Log.d(THIS_FILE, "Already ringing ....");
   }
 }
Example #6
0
  /** Initialize datas list */
  private void initDatas() {
    if (codecsList == null) {
      codecsList = new ArrayList<Map<String, Object>>();
    } else {
      codecsList.clear();
    }

    bandtype = (String) getArguments().get(BAND_TYPE);
    mediatype = (Integer) getArguments().get(MEDIA_TYPE);

    String[] codecNames;
    if (mediatype == MEDIA_AUDIO) {
      codecNames = prefsWrapper.getCodecList();
    } else {
      codecNames = prefsWrapper.getVideoCodecList();
    }

    int current_prio = 130;
    for (String codecName : codecNames) {
      Log.d(THIS_FILE, "Fill codec " + codecName + " for " + bandtype);
      String[] codecParts = codecName.split("/");
      if (codecParts.length >= 2) {
        HashMap<String, Object> codecInfo = new HashMap<String, Object>();
        codecInfo.put(CODEC_ID, codecName);
        if (mediatype == MEDIA_AUDIO) {
          codecInfo.put(
              CODEC_NAME,
              codecParts[0]
                  + " "
                  + codecParts[1].substring(0, codecParts[1].length() - 3)
                  + " kHz");
        } else if (mediatype == MEDIA_VIDEO) {
          codecInfo.put(CODEC_NAME, codecParts[0]);
        }
        codecInfo.put(
            CODEC_PRIORITY,
            prefsWrapper.getCodecPriority(codecName, bandtype, Integer.toString(current_prio)));
        codecsList.add(codecInfo);
        current_prio--;
        Log.d(THIS_FILE, "Found priority is " + codecInfo.get(CODEC_PRIORITY));
      }
    }

    Collections.sort(codecsList, codecsComparator);
  }
Example #7
0
  private int getAudioTargetMode() {
    int targetMode = modeSipInCall;

    if (service.getPrefs().useModeApi()) {
      Log.d(THIS_FILE, "User want speaker now..." + userWantSpeaker);
      if (!service.getPrefs().generateForSetCall()) {
        return userWantSpeaker ? AudioManager.MODE_NORMAL : AudioManager.MODE_IN_CALL;
      } else {
        return userWantSpeaker ? AudioManager.MODE_IN_CALL : AudioManager.MODE_NORMAL;
      }
    }
    if (userWantBluetooth) {
      targetMode = AudioManager.MODE_NORMAL;
    }

    Log.d(THIS_FILE, "Target mode... : " + targetMode);
    return targetMode;
  }
Example #8
0
 public void setBluetoothOn(boolean on) throws SameThreadException {
   Log.d(THIS_FILE, "Set BT " + on);
   if (service != null && restartAudioWhenRoutingChange && !ringer.isRinging()) {
     service.setNoSnd();
     userWantBluetooth = on;
     service.setSnd();
   } else {
     userWantBluetooth = on;
     bluetoothWrapper.setBluetoothOn(on);
   }
   broadcastMediaChanged();
 }
Example #9
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   Log.d(THIS_FILE, "On activity result");
   if (requestCode == PICKUP_SIP_URI) {
     if (resultCode == Activity.RESULT_OK) {
       String from = data.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
       setupFrom(from, from);
     }
     if (TextUtils.isEmpty(remoteFrom)) {
       if (quitListener != null) {
         quitListener.onQuit();
       }
     } else {
       loadMessageContent();
     }
     return;
   }
   super.onActivityResult(requestCode, resultCode, data);
 }
Example #10
0
  public void fillLayout(final SipProfile account) {
    bindFields();

    accountDisplayName.setText(account.display_name);
    accountAccId.setText(account.acc_id);
    accountRegUri.setText(account.reg_uri);
    accountRealm.setText(account.realm);
    accountUserName.setText(account.username);
    accountData.setText(account.data);

    {
      String scheme = account.scheme;
      if (scheme != null && !scheme.equals("")) {
        accountScheme.setValue(scheme);
      } else {
        accountScheme.setValue(SipProfile.CRED_SCHEME_DIGEST);
      }
    }
    {
      int ctype = account.datatype;
      if (ctype == SipProfile.CRED_DATA_PLAIN_PASSWD) {
        accountDataType.setValueIndex(0);
      } else if (ctype == SipProfile.CRED_DATA_DIGEST) {
        accountDataType.setValueIndex(1);
      }
      // DISABLED SINCE NOT SUPPORTED YET
      /*
      else if (ctype ==SipProfile.CRED_CRED_DATA_EXT_AKA) {
      	accountDataType.setValueIndex(2);
      } */ else {
        accountDataType.setValueIndex(0);
      }
    }
    accountInitAuth.setChecked(account.initial_auth);
    accountAuthAlgo.setText(account.auth_algo);

    accountTransport.setValue(account.transport.toString());
    if (!TextUtils.isEmpty(account.default_uri_scheme)) {
      accountDefaultUriScheme.setValue(account.default_uri_scheme);
    }
    accountPublishEnabled.setChecked((account.publish_enabled == 1));
    accountRegTimeout.setText(Long.toString(account.reg_timeout));
    accountRegDelayRefresh.setText(Long.toString(account.reg_delay_before_refresh));

    accountForceContact.setText(account.force_contact);
    accountAllowContactRewrite.setChecked(account.allow_contact_rewrite);
    accountAllowViaRewrite.setChecked(account.allow_via_rewrite);
    accountContactRewriteMethod.setValue(Integer.toString(account.contact_rewrite_method));
    if (account.proxies != null) {
      accountProxy.setText(TextUtils.join(SipProfile.PROXIES_SEPARATOR, account.proxies));
    } else {
      accountProxy.setText("");
    }
    Log.d(THIS_FILE, "use srtp : " + account.use_srtp);
    accountUseSrtp.setValueIndex(account.use_srtp + 1);
    accountUseZrtp.setValueIndex(account.use_zrtp + 1);

    useRfc5626.setChecked(account.use_rfc5626);
    rfc5626_instanceId.setText(account.rfc5626_instance_id);
    rfc5626_regId.setText(account.rfc5626_reg_id);

    rtpEnableQos.setValue(Integer.toString(account.rtp_enable_qos));
    rtpQosDscp.setText(Integer.toString(account.rtp_qos_dscp));
    rtpPort.setText(Integer.toString(account.rtp_port));
    rtpBoundAddr.setText(account.rtp_bound_addr);
    rtpPublicAddr.setText(account.rtp_public_addr);

    vidInAutoShow.setValue(Integer.toString(account.vid_in_auto_show));
    vidOutAutoTransmit.setValue(Integer.toString(account.vid_out_auto_transmit));

    accountVm.setText(account.vm_nbr);
    mwiEnabled.setChecked(account.mwi_enabled);
    tryCleanRegisters.setChecked(account.try_clean_registers != 0);

    sipStunUse.setValue(Integer.toString(account.sip_stun_use));
    mediaStunUse.setValue(Integer.toString(account.media_stun_use));
    iceCfgUse.setChecked(account.ice_cfg_use == 1);
    iceCfgEnable.setChecked(account.ice_cfg_enable == 1);
    turnCfgUse.setChecked(account.turn_cfg_use == 1);
    turnCfgEnable.setChecked(account.turn_cfg_enable == 1);
    turnCfgServer.setText(account.turn_cfg_server);
    turnCfgUser.setText(account.turn_cfg_user);
    turnCfgPassword.setText(account.turn_cfg_password);

    ipv6MediaEnable.setChecked(account.ipv6_media_use == 1);
  }
  @Override
  public void onReceive(Context context, Intent intent) {

    PreferencesProviderWrapper prefWrapper = new PreferencesProviderWrapper(context);
    String intentAction = intent.getAction();

    //
    // ACTION_DATA_STATE_CHANGED
    // Data state change is used to detect changes in the mobile
    // network such as a switch of network type (GPRS, EDGE, 3G)
    // which are not detected by the Connectivity changed broadcast.
    //
    //
    // ACTION_CONNECTIVITY_CHANGED
    // Connectivity change is used to detect changes in the overall
    // data network status as well as a switch between wifi and mobile
    // networks.
    //
    if (
    /*intentAction.equals(ACTION_DATA_STATE_CHANGED) ||*/
    intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION)
        || intentAction.equals(Intent.ACTION_BOOT_COMPLETED)) {

      if (prefWrapper.isValidConnectionForIncoming()
          && !prefWrapper.getPreferenceBooleanValue(PreferencesProviderWrapper.HAS_BEEN_QUIT)) {
        Log.d(THIS_FILE, "Try to start service if not already started");
        Intent sip_service_intent = new Intent(context, SipService.class);
        context.startService(sip_service_intent);
      }

    } else if (intentAction.equals(SipManager.INTENT_SIP_ACCOUNT_ACTIVATE)) {
      context.enforceCallingOrSelfPermission(SipManager.PERMISSION_CONFIGURE_SIP, null);

      long accId;
      accId = intent.getLongExtra(SipProfile.FIELD_ID, SipProfile.INVALID_ID);

      if (accId == SipProfile.INVALID_ID) {
        // allow remote side to send us integers.
        // previous call will warn, but that's fine, no worries
        accId = intent.getIntExtra(SipProfile.FIELD_ID, (int) SipProfile.INVALID_ID);
      }

      if (accId != SipProfile.INVALID_ID) {
        boolean active = intent.getBooleanExtra(SipProfile.FIELD_ACTIVE, true);
        ContentValues cv = new ContentValues();
        cv.put(SipProfile.FIELD_ACTIVE, active);
        int done =
            context
                .getContentResolver()
                .update(
                    ContentUris.withAppendedId(SipProfile.ACCOUNT_ID_URI_BASE, accId),
                    cv,
                    null,
                    null);
        if (done > 0) {
          if (prefWrapper.isValidConnectionForIncoming()) {
            Intent sipServiceIntent = new Intent(context, SipService.class);
            context.startService(sipServiceIntent);
          }
        }
      }
    } else if (Intent.ACTION_PACKAGE_ADDED.equalsIgnoreCase(intentAction)
        || Intent.ACTION_PACKAGE_REMOVED.equalsIgnoreCase(intentAction)) {
      CallHandlerPlugin.clearAvailableCallHandlers();
      RewriterPlugin.clearAvailableRewriters();
      ExtraPlugins.clearDynPlugins();
      PhoneCapabilityTester.deinit();
    } else if (APPLY_NIGHTLY_UPLOAD.equals(intentAction)) {
      NightlyUpdater nu = new NightlyUpdater(context);
      nu.applyUpdate(intent);
    }
  }
Example #12
0
 @Override
 public void onResume() {
   Log.d(THIS_FILE, "Resume compose message act");
   super.onResume();
   notifications.setViewingMessageFrom(remoteFrom);
 }
Example #13
0
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      Log.w(THIS_FILE, "Upgrading database from version " + oldVersion + " to " + newVersion);
      if (oldVersion < 1) {
        db.execSQL("DROP TABLE IF EXISTS " + SipProfile.ACCOUNTS_TABLE_NAME);
      }
      if (oldVersion < 5) {
        try {
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_KA_INTERVAL
                  + " INTEGER");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 6) {
        db.execSQL("DROP TABLE IF EXISTS " + SipManager.FILTERS_TABLE_NAME);
      }
      if (oldVersion < 10) {
        try {
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_ALLOW_CONTACT_REWRITE
                  + " INTEGER");
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_CONTACT_REWRITE_METHOD
                  + " INTEGER");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 13) {
        try {
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_TRANSPORT
                  + " INTEGER");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TRANSPORT
                  + "="
                  + SipProfile.TRANSPORT_UDP
                  + " WHERE prevent_tcp=1");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TRANSPORT
                  + "="
                  + SipProfile.TRANSPORT_TCP
                  + " WHERE use_tcp=1");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TRANSPORT
                  + "="
                  + SipProfile.TRANSPORT_AUTO
                  + " WHERE use_tcp=0 AND prevent_tcp=0");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 17) {
        try {
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_KA_INTERVAL
                  + "=0");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 18) {
        try {
          // As many users are crying... remove auto transport and force udp
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TRANSPORT
                  + "="
                  + SipProfile.TRANSPORT_UDP
                  + " WHERE "
                  + SipProfile.FIELD_TRANSPORT
                  + "="
                  + SipProfile.TRANSPORT_AUTO);
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 22) {
        try {
          // Add use proxy row
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_REG_USE_PROXY
                  + " INTEGER");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_REG_USE_PROXY
                  + "=3");
          // Add stack field
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_SIP_STACK
                  + " INTEGER");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_SIP_STACK
                  + "=0");
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 23) {
        try {
          // Add use zrtp row
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_USE_ZRTP
                  + " INTEGER");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_USE_ZRTP
                  + "=-1");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 24) {
        try {
          // Add voice mail row
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_VOICE_MAIL_NBR
                  + " TEXT");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_VOICE_MAIL_NBR
                  + "=''");
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 25) {
        try {
          // Add voice mail row
          db.execSQL(
              "ALTER TABLE "
                  + SipMessage.MESSAGES_TABLE_NAME
                  + " ADD "
                  + SipMessage.FIELD_FROM_FULL
                  + " TEXT");
          db.execSQL(
              "UPDATE "
                  + SipMessage.MESSAGES_TABLE_NAME
                  + " SET "
                  + SipMessage.FIELD_FROM_FULL
                  + "="
                  + SipMessage.FIELD_FROM);
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 26) {
        try {
          // Add reg delay before refresh row
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_REG_DELAY_BEFORE_REFRESH,
              "INTEGER DEFAULT -1");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_REG_DELAY_BEFORE_REFRESH
                  + "=-1");
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 27) {
        try {
          // Add reg delay before refresh row
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_TRY_CLEAN_REGISTERS,
              "INTEGER DEFAULT 0");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TRY_CLEAN_REGISTERS
                  + "=0");
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 28) {
        try {
          // Add call log profile id
          addColumn(
              db, SipManager.CALLLOGS_TABLE_NAME, SipManager.CALLLOG_PROFILE_ID_FIELD, "INTEGER");
          // Add call log status code
          addColumn(
              db, SipManager.CALLLOGS_TABLE_NAME, SipManager.CALLLOG_STATUS_CODE_FIELD, "INTEGER");
          db.execSQL(
              "UPDATE "
                  + SipManager.CALLLOGS_TABLE_NAME
                  + " SET "
                  + SipManager.CALLLOG_STATUS_CODE_FIELD
                  + "=200");
          // Add call log status text
          addColumn(
              db, SipManager.CALLLOGS_TABLE_NAME, SipManager.CALLLOG_STATUS_TEXT_FIELD, "TEXT");
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 30) {
        try {
          // Add reg delay before refresh row
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_USE_RFC5626,
              "INTEGER DEFAULT 1");
          addColumn(
              db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_RFC5626_INSTANCE_ID, "TEXT");
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_RFC5626_REG_ID, "TEXT");

          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_VID_IN_AUTO_SHOW,
              "INTEGER DEFAULT -1");
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_VID_OUT_AUTO_TRANSMIT,
              "INTEGER DEFAULT -1");
          addColumn(
              db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_RTP_PORT, "INTEGER DEFAULT -1");

          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_RTP_ENABLE_QOS,
              "INTEGER DEFAULT -1");
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_RTP_QOS_DSCP,
              "INTEGER DEFAULT -1");
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_RTP_PUBLIC_ADDR, "TEXT");
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_RTP_BOUND_ADDR, "TEXT");

          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      // Nightly build bug -- restore mime type field to mime_type
      if (oldVersion == 30) {
        try {
          addColumn(db, SipMessage.MESSAGES_TABLE_NAME, SipMessage.FIELD_MIME_TYPE, "TEXT");
          db.execSQL(
              "UPDATE "
                  + SipMessage.MESSAGES_TABLE_NAME
                  + " SET "
                  + SipMessage.FIELD_MIME_TYPE
                  + "='text/plain'");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }

      if (oldVersion < 32) {
        try {
          // Add android group for buddy list
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_ANDROID_GROUP, "TEXT");
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 33) {
        try {
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_ALLOW_VIA_REWRITE,
              "INTEGER DEFAULT 0");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_ALLOW_VIA_REWRITE
                  + "=0");
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 34) {
        try {
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_SIP_STUN_USE,
              "INTEGER DEFAULT -1");
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_MEDIA_STUN_USE,
              "INTEGER DEFAULT -1");
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_ICE_CFG_USE,
              "INTEGER DEFAULT -1");
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_ICE_CFG_ENABLE,
              "INTEGER DEFAULT 0");
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_TURN_CFG_USE,
              "INTEGER DEFAULT -1");
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_TURN_CFG_ENABLE,
              "INTEGER DEFAULT 0");
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_TURN_CFG_SERVER, "TEXT");
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_TURN_CFG_USER, "TEXT");
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_TURN_CFG_PASSWORD, "TEXT");

          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_SIP_STUN_USE
                  + "=-1");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_MEDIA_STUN_USE
                  + "=-1");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_ICE_CFG_USE
                  + "=-1");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_ICE_CFG_ENABLE
                  + "=0");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TURN_CFG_USE
                  + "=-1");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TURN_CFG_ENABLE
                  + "=0");

          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 35) {
        try {
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_IPV6_MEDIA_USE,
              "INTEGER DEFAULT 0");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_IPV6_MEDIA_USE
                  + "=0");
          Log.d(THIS_FILE, "Upgrade done");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 36) {
        try {
          // Enable try to clean register for all but ones that doesn't support contact rewrite
          // normal (legacy)
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TRY_CLEAN_REGISTERS
                  + "=1 WHERE 1");
          db.execSQL(
              "UPDATE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " SET "
                  + SipProfile.FIELD_TRY_CLEAN_REGISTERS
                  + "=0 WHERE "
                  + SipProfile.FIELD_CONTACT_REWRITE_METHOD
                  + "=1");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 37) {
        try {
          addColumn(
              db,
              SipProfile.ACCOUNTS_TABLE_NAME,
              SipProfile.FIELD_AUTH_INITIAL_AUTH,
              "INTEGER DEFAULT 0");
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_AUTH_ALGO, "TEXT");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 38) {
        try {
          addColumn(db, SipProfile.ACCOUNTS_TABLE_NAME, SipProfile.FIELD_WIZARD_DATA, "TEXT");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      if (oldVersion < 39) {
        try {
          db.execSQL(
              "ALTER TABLE "
                  + SipProfile.ACCOUNTS_TABLE_NAME
                  + " ADD "
                  + SipProfile.FIELD_DEFAULT_URI_SCHEME
                  + " TEXT");
        } catch (SQLiteException e) {
          Log.e(THIS_FILE, "Upgrade fail... maybe a crappy rom...", e);
        }
      }
      onCreate(db);
    }
Example #14
0
    @Override
    public void run() {
      Log.d(THIS_FILE, "InCallTonePlayer.run(toneId = " + mToneId + ")...");

      int toneType; // passed to ToneGenerator.startTone()
      int toneVolume; // passed to the ToneGenerator constructor
      int toneLengthMillis;
      switch (mToneId) {
        case TONE_CALL_WAITING:
          toneType = ToneGenerator.TONE_SUP_CALL_WAITING;
          toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
          toneLengthMillis = 5000;
          break;
        case TONE_BUSY:
          toneType = ToneGenerator.TONE_SUP_BUSY;
          toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
          toneLengthMillis = 4000;
          break;
        case TONE_CONGESTION:
          toneType = ToneGenerator.TONE_SUP_CONGESTION;
          toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
          toneLengthMillis = 4000;
          break;
        case TONE_BATTERY_LOW:
          // For now, use ToneGenerator.TONE_PROP_ACK (two quick
          // beeps). TODO: is there some other ToneGenerator
          // tone that would be more appropriate here? Or
          // should we consider adding a new custom tone?
          toneType = ToneGenerator.TONE_PROP_ACK;
          toneVolume = TONE_RELATIVE_VOLUME_HIPRI;
          toneLengthMillis = 1000;
          break;
        case TONE_CALL_ENDED:
          toneType = ToneGenerator.TONE_PROP_PROMPT;
          toneVolume = TONE_RELATIVE_VOLUME_LOPRI;
          toneLengthMillis = 2000;
          break;
        default:
          throw new IllegalArgumentException("Bad toneId: " + mToneId);
      }

      // If the mToneGenerator creation fails, just continue without it.
      // It is
      // a local audio signal, and is not as important.
      ToneGenerator toneGenerator;
      try {
        toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, toneVolume);
        // if (DBG) log("- created toneGenerator: " + toneGenerator);
      } catch (RuntimeException e) {
        Log.w(THIS_FILE, "InCallTonePlayer: Exception caught while creating ToneGenerator: " + e);
        toneGenerator = null;
      }

      // Using the ToneGenerator (with the CALL_WAITING / BUSY /
      // CONGESTION tones at least), the ToneGenerator itself knows
      // the right pattern of tones to play; we do NOT need to
      // manually start/stop each individual tone, or manually
      // insert the correct delay between tones. (We just start it
      // and let it run for however long we want the tone pattern to
      // continue.)
      //
      // TODO: When we stop the ToneGenerator in the middle of a
      // "tone pattern", it sounds bad if we cut if off while the
      // tone is actually playing. Consider adding API to the
      // ToneGenerator to say "stop at the next silent part of the
      // pattern", or simply "play the pattern N times and then
      // stop."

      if (toneGenerator != null) {
        toneGenerator.startTone(toneType);
        SystemClock.sleep(toneLengthMillis);
        toneGenerator.stopTone();

        Log.v(THIS_FILE, "- InCallTonePlayer: done playing.");
        toneGenerator.release();
      }
    }
Example #15
0
  /** Set the audio mode as in call */
  @SuppressWarnings("deprecation")
  private synchronized void actualSetAudioInCall() {
    // Ensure not already set
    if (isSetAudioMode) {
      return;
    }
    stopRing();
    saveAudioState();

    // Set the rest of the phone in a better state to not interferate with
    // current call
    // Do that only if we were not already in silent mode
    /*
     * Not needed anymore with on flight gsm call capture
     * if(audioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) {
     * audioManager.setVibrateSetting(AudioManager.VIBRATE_TYPE_RINGER,
     * AudioManager.VIBRATE_SETTING_ON);
     * audioManager.setVibrateSetting(AudioManager
     * .VIBRATE_TYPE_NOTIFICATION, AudioManager.VIBRATE_SETTING_OFF);
     * audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); }
     */

    // LOCKS

    // Wifi management if necessary
    ContentResolver ctntResolver = service.getContentResolver();
    Settings.System.putInt(
        ctntResolver, Settings.System.WIFI_SLEEP_POLICY, Settings.System.WIFI_SLEEP_POLICY_NEVER);

    // Acquire wifi lock
    WifiManager wman = (WifiManager) service.getSystemService(Context.WIFI_SERVICE);
    if (wifiLock == null) {
      wifiLock =
          wman.createWifiLock(
              (Compatibility.isCompatible(9))
                  ? WifiManager.WIFI_MODE_FULL_HIGH_PERF
                  : WifiManager.WIFI_MODE_FULL,
              "com.csipsimple.InCallLock");
      wifiLock.setReferenceCounted(false);
    }
    WifiInfo winfo = wman.getConnectionInfo();
    if (winfo != null) {
      DetailedState dstate = WifiInfo.getDetailedStateOf(winfo.getSupplicantState());
      // We assume that if obtaining ip addr, we are almost connected so
      // can keep wifi lock
      if (dstate == DetailedState.OBTAINING_IPADDR || dstate == DetailedState.CONNECTED) {
        if (!wifiLock.isHeld()) {
          wifiLock.acquire();
        }
      }

      // This wake lock purpose is to prevent PSP wifi mode
      if (service.getPrefs().getPreferenceBooleanValue(SipConfigManager.KEEP_AWAKE_IN_CALL)) {
        if (screenLock == null) {
          PowerManager pm = (PowerManager) service.getSystemService(Context.POWER_SERVICE);
          screenLock =
              pm.newWakeLock(
                  PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
                  "com.csipsimple.onIncomingCall.SCREEN");
          screenLock.setReferenceCounted(false);
        }
        // Ensure single lock
        if (!screenLock.isHeld()) {
          screenLock.acquire();
        }
      }
    }

    if (!useWebRTCImpl) {
      // Audio routing
      int targetMode = getAudioTargetMode();
      Log.d(THIS_FILE, "Set mode audio in call to " + targetMode);

      if (service.getPrefs().generateForSetCall()) {
        boolean needOutOfSilent = (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT);
        if (needOutOfSilent) {
          audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
        }
        ToneGenerator toneGenerator = new ToneGenerator(AudioManager.STREAM_VOICE_CALL, 1);
        toneGenerator.startTone(41 /* ToneGenerator.TONE_CDMA_CONFIRM */);
        toneGenerator.stopTone();
        toneGenerator.release();
        // Restore silent mode
        if (needOutOfSilent) {
          audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
        }
      }

      // Set mode
      if (targetMode != AudioManager.MODE_IN_CALL && useSgsWrkAround) {
        // For galaxy S we need to set in call mode before to reset
        // stack
        audioManager.setMode(AudioManager.MODE_IN_CALL);
      }

      audioManager.setMode(targetMode);

      // Routing
      if (service.getPrefs().useRoutingApi()) {
        audioManager.setRouting(
            targetMode,
            userWantSpeaker ? AudioManager.ROUTE_SPEAKER : AudioManager.ROUTE_EARPIECE,
            AudioManager.ROUTE_ALL);
      } else {
        audioManager.setSpeakerphoneOn(userWantSpeaker ? true : false);
      }

      audioManager.setMicrophoneMute(false);
      if (bluetoothWrapper != null && userWantBluetooth && bluetoothWrapper.canBluetooth()) {
        Log.d(THIS_FILE, "Try to enable bluetooth");
        bluetoothWrapper.setBluetoothOn(true);
      }

    } else {
      // WebRTC implementation for routing
      int apiLevel = Compatibility.getApiLevel();

      // SetAudioMode
      // ***IMPORTANT*** When the API level for honeycomb (H) has been
      // decided,
      // the condition should be changed to include API level 8 to H-1.
      if (android.os.Build.BRAND.equalsIgnoreCase("Samsung") && (8 == apiLevel)) {
        // Set Samsung specific VoIP mode for 2.2 devices
        int mode = 4;
        audioManager.setMode(mode);
        if (audioManager.getMode() != mode) {
          Log.e(THIS_FILE, "Could not set audio mode for Samsung device");
        }
      }

      // SetPlayoutSpeaker
      if ((3 == apiLevel) || (4 == apiLevel)) {
        // 1.5 and 1.6 devices
        if (userWantSpeaker) {
          // route audio to back speaker
          audioManager.setMode(AudioManager.MODE_NORMAL);
        } else {
          // route audio to earpiece
          audioManager.setMode(AudioManager.MODE_IN_CALL);
        }
      } else {
        // 2.x devices
        if ((android.os.Build.BRAND.equalsIgnoreCase("samsung"))
            && ((5 == apiLevel) || (6 == apiLevel) || (7 == apiLevel))) {
          // Samsung 2.0, 2.0.1 and 2.1 devices
          if (userWantSpeaker) {
            // route audio to back speaker
            audioManager.setMode(AudioManager.MODE_IN_CALL);
            audioManager.setSpeakerphoneOn(userWantSpeaker);
          } else {
            // route audio to earpiece
            audioManager.setSpeakerphoneOn(userWantSpeaker);
            audioManager.setMode(AudioManager.MODE_NORMAL);
          }
        } else {
          // Non-Samsung and Samsung 2.2 and up devices
          audioManager.setSpeakerphoneOn(userWantSpeaker);
        }
      }
    }

    // Set stream solo/volume/focus

    int inCallStream = Compatibility.getInCallStream(userWantBluetooth);
    if (doFocusAudio) {
      if (!accessibilityManager.isEnabled()) {
        audioManager.setStreamSolo(inCallStream, true);
      }
      audioFocusWrapper.focus(userWantBluetooth);
    }
    Log.d(THIS_FILE, "Initial volume level : " + service.getPrefs().getInitialVolumeLevel());
    setStreamVolume(
        inCallStream,
        (int)
            (audioManager.getStreamMaxVolume(inCallStream)
                * service.getPrefs().getInitialVolumeLevel()),
        0);

    isSetAudioMode = true;
    // System.gc();
  }