示例#1
0
        public void handleMessage(Message message) {
          switch (message.what) {
            case DID_SUCCEED:
              {
                // Here we get the credit info, now add a row in the interface
                String response = (String) message.obj;
                try {
                  float value = Float.parseFloat(response.trim());
                  if (value >= 0) {
                    customWizardText.setText(
                        "Credit : " + Math.round(value * 100.0) / 100.0 + " euros");
                    customWizard.setVisibility(View.VISIBLE);
                  }
                } catch (NumberFormatException e) {
                  Log.e(THIS_FILE, "Impossible to parse result", e);
                } catch (NullPointerException e) {
                  Log.e(THIS_FILE, "Null result");
                }

                break;
              }
            case DID_ERROR:
              {
                Exception e = (Exception) message.obj;
                Log.e(THIS_FILE, "Error here", e);
                break;
              }
          }
        }
示例#2
0
  @Override
  @SuppressWarnings("unchecked")
  public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {
      info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    } catch (ClassCastException e) {
      Log.e(THIS_FILE, "bad menuInfo", e);
      return false;
    }

    HashMap<String, Object> codec = null;
    codec = (HashMap<String, Object>) mAdapter.getItem(info.position);

    if (codec == null) {
      // If for some reason the requested item isn't available, do nothing
      return false;
    }
    int selId = item.getItemId();
    if (selId == MENU_ITEM_ACTIVATE) {
      boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0);
      userActivateCodec(codec, isDisabled);
      return true;
    }
    return false;
  }
示例#3
0
 private static int getIntValue(EditTextPreference pref, int defaultValue) {
   try {
     return Integer.parseInt(pref.getText());
   } catch (NumberFormatException e) {
     Log.e(THIS_FILE, "List item is not a number");
   }
   return defaultValue;
 }
示例#4
0
  @Override
  public CallerInfo findSelfInfo(Context ctxt) {

    CallerInfo callerInfo = new CallerInfo();

    String[] projection =
        new String[] {Profile._ID, Profile.DISPLAY_NAME, Profile.PHOTO_ID, Profile.PHOTO_URI};
    Cursor cursor =
        ctxt.getContentResolver()
            .query(ContactsContract.Profile.CONTENT_URI, projection, null, null, null);
    if (cursor != null) {
      try {
        if (cursor.getCount() > 0) {
          cursor.moveToFirst();

          ContentValues cv = new ContentValues();
          DatabaseUtils.cursorRowToContentValues(cursor, cv);
          callerInfo.contactExists = true;
          if (cv.containsKey(Profile.DISPLAY_NAME)) {
            callerInfo.name = cv.getAsString(Profile.DISPLAY_NAME);
          }

          if (cv.containsKey(Profile._ID)) {
            callerInfo.personId = cv.getAsLong(Profile._ID);
            callerInfo.contactContentUri =
                ContentUris.withAppendedId(Contacts.CONTENT_URI, callerInfo.personId);
          }

          if (cv.containsKey(Profile.PHOTO_ID)) {
            Long photoId = cv.getAsLong(Profile.PHOTO_ID);
            if (photoId != null) {
              callerInfo.photoId = photoId;
            }
          }

          if (cv.containsKey(Profile.PHOTO_URI)) {
            String photoUri = cv.getAsString(Profile.PHOTO_URI);
            if (!TextUtils.isEmpty(photoUri)) {
              callerInfo.photoUri = Uri.parse(photoUri);
            }
          }

          if (callerInfo.name != null && callerInfo.name.length() == 0) {
            callerInfo.name = null;
          }
        }
      } catch (Exception e) {
        Log.e(THIS_FILE, "Exception while retrieving cursor infos", e);
      } finally {
        cursor.close();
      }
    }

    return callerInfo;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    resetInternals();

    // Sanity check
    if (TextUtils.isEmpty(getPhoneNumber())) {
      Log.e(THIS_FILE, "No number detected for : " + getIntent().getAction());
      finish();
      return;
    }
    setContentView(R.layout.outgoing_call_view);
    connectService();
  }
示例#6
0
 private void sendMessage() {
   if (service != null) {
     SipProfile acc = accountChooserButton.getSelectedAccount();
     if (acc != null && acc.id != SipProfile.INVALID_ID) {
       try {
         String textToSend = bodyInput.getText().toString();
         if (!TextUtils.isEmpty(textToSend)) {
           service.sendMessage(textToSend, remoteFrom, (int) acc.id);
           bodyInput.getText().clear();
         }
       } catch (RemoteException e) {
         Log.e(THIS_FILE, "Not able to send message");
       }
     }
   }
 }
示例#7
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info;
    try {
      info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
      long id = info.id;
      int selId = item.getItemId();

      if (id >= 0 && selId == MENU_ITEM_DELETE) {
        getContentResolver()
            .delete(ContentUris.withAppendedId(SipManager.FILTER_ID_URI_BASE, id), null, null);
        cursor.requery();
        return true;
      }
    } catch (ClassCastException e) {
      Log.e(THIS_FILE, "bad menuInfo", e);
    }

    return super.onContextItemSelected(item);
  }
示例#8
0
  @Override
  @SuppressWarnings("unchecked")
  public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {
      info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
      Log.e(THIS_FILE, "bad menuInfo", e);
      return;
    }

    HashMap<String, Object> codec = (HashMap<String, Object>) mAdapter.getItem(info.position);
    if (codec == null) {
      // If for some reason the requested item isn't available, do nothing
      return;
    }

    boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0);
    menu.add(0, MENU_ITEM_ACTIVATE, 0, isDisabled ? R.string.activate : R.string.deactivate);
  }
示例#9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
      accountId = extras.getLong(SipProfile.FIELD_ID, -1);
    }

    if (accountId == -1) {
      Log.e(THIS_FILE, "You provide an empty account id....");
      finish();
    }

    // Custom title listing the account name for filters
    // final boolean customTitleOk =
    // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.filters_list);
    /*
     * if(customTitleOk) {
     * getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
     * R.layout.account_filters_title); final TextView titleText =
     * (TextView) findViewById(R.id.account_filters_title); if (titleText !=
     * null) { SipProfile acct = SipProfile.getProfileFromDbId(this,
     * accountId, new String[] {SipProfile.FIELD_ID,
     * SipProfile.FIELD_DISPLAY_NAME});
     * titleText.setText(R.string.filters_for); titleText.append(" " +
     * acct.display_name); } }
     */

    database = new DBAdapter(this);
    database.open();
    // Add add row
    TextView add_row = (TextView) findViewById(R.id.add_filter);
    add_row.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            editFilterActivity(-1);
          }
        });

    cursor = database.getFiltersForAccount(accountId);
    if (cursor != null) {
      startManagingCursor(cursor);
    }
    CursorAdapter adapter = new FiltersCursorAdapter(this, cursor);
    setListAdapter(adapter);

    DragnDropListView listView = (DragnDropListView) getListView();
    listView.setOnDropListener(
        new DropListener() {
          @Override
          public void drop(int from, int to) {
            // Update priorities
            CursorAdapter ad = (CursorAdapter) getListAdapter();
            int numRows = ad.getCount();

            for (int i = 0; i < numRows; i++) {
              // Log.d(THIS_FILE, "i= "+i+" from ="+from+" to="+to);
              if (i != from) {
                if (from > i && i >= to) {
                  updateFilterPriority(ad.getItemId(i), i + 1);
                } else if (from < i && i <= to) {
                  updateFilterPriority(ad.getItemId(i), i - 1);
                } else {
                  updateFilterPriority(ad.getItemId(i), i);
                }
              } else {
                updateFilterPriority(ad.getItemId(from), to);
              }
            }
            cursor.requery();
          }
        });

    listView.setOnCreateContextMenuListener(this);
  }
示例#10
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);
    }
示例#11
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();
  }