Asking permission for device ring tone at the start

This commit is contained in:
Erwan Croze 2016-10-10 16:37:37 +02:00
parent 2f54f90dd5
commit 69f1888b4f
10 changed files with 96 additions and 79 deletions

View file

@ -3,7 +3,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:1.3.0' classpath 'com.android.tools.build:gradle:2.2.0'
} }
} }
apply plugin: 'android' apply plugin: 'android'
@ -14,7 +14,7 @@ dependencies {
android { android {
compileSdkVersion 23 compileSdkVersion 23
buildToolsVersion "20.0.0" buildToolsVersion "23.0.2"
sourceSets { sourceSets {
main { main {

View file

@ -1,6 +1,6 @@
#Tue Dec 09 14:35:04 CET 2014 #Sun Oct 09 18:19:14 CEST 2016
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

View file

@ -38,6 +38,7 @@ max_calls=10
[app] [app]
activation_code_length=4 activation_code_length=4
debug=1
[in-app-purchase] [in-app-purchase]
server_url=https://sip3.linphone.org:444/inapp.php server_url=https://sip3.linphone.org:444/inapp.php

View file

@ -115,7 +115,7 @@
<string name="use_email_for_validation">Use email address for account validation</string> <string name="use_email_for_validation">Use email address for account validation</string>
<string name="login_with_username">Use your username and password instead of your phone number</string> <string name="login_with_username">Use your username and password instead of your phone number</string>
<string name="phone_number_info_title">What will my phone number be used for?</string> <string name="phone_number_info_title">What will my phone number be used for?</string>
<string name="phone_number_info_content">\nThanks to your phone number, your friends will find you more easily.\n\n You will see in your addressbook who is using Linphone and your friends will know that they can rach you on Linphone as well.\n</string> <string name="phone_number_info_content">\nThanks to your phone number, your friends will find you more easily.\n\n You will see in your address book who is using Linphone and your friends will know that they can rach you on Linphone as well.\n</string>
<string name="phone_number_link_info_content">\nYour friends will find you more easily if you link your account to your phone number\n\nYou will see in your address book who is using Linphone and your friends will know that they can reach you on Linphone as well.\n</string> <string name="phone_number_link_info_content">\nYour friends will find you more easily if you link your account to your phone number\n\nYou will see in your address book who is using Linphone and your friends will know that they can reach you on Linphone as well.\n</string>
<string name="phone_number_link_info_content_already_account">You can only use your phone number with one linphone account.\n\nIf you had already linked your number to an other account but you prefer to use this one simply link it now and your number will automatically be moved to this account.</string> <string name="phone_number_link_info_content_already_account">You can only use your phone number with one linphone account.\n\nIf you had already linked your number to an other account but you prefer to use this one simply link it now and your number will automatically be moved to this account.</string>

View file

@ -168,6 +168,9 @@ public class DialerFragment extends Fragment {
} }
public void resetLayout(boolean callTransfer) { public void resetLayout(boolean callTransfer) {
if (!LinphoneActivity.isInstanciated()) {
return;
}
isCallTransferOngoing = LinphoneActivity.instance().isCallTransfer(); isCallTransferOngoing = LinphoneActivity.instance().isCallTransfer();
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc == null) { if (lc == null) {

View file

@ -1271,7 +1271,11 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
break; break;
case PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE: case PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE:
((SettingsFragment) fragment).enableDeviceRingtone(grantResults[0] == PackageManager.PERMISSION_GRANTED); if (permissions[0].compareTo(Manifest.permission.READ_EXTERNAL_STORAGE) != 0)
break;
boolean enableRingtone = (grantResults[0] == PackageManager.PERMISSION_GRANTED);
LinphonePreferences.instance().enableDeviceRingtone(enableRingtone);
LinphoneManager.getInstance().enableDeviceRingtone(enableRingtone);
break; break;
case PERMISSIONS_RECORD_AUDIO_ECHO_TESTER: case PERMISSIONS_RECORD_AUDIO_ECHO_TESTER:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
@ -1283,6 +1287,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
ArrayList<String> permissionsList = new ArrayList<String>();
int contacts = getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName()); int contacts = getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName());
Log.i("[Permission] Contacts permission is " + (contacts == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); Log.i("[Permission] Contacts permission is " + (contacts == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
@ -1290,24 +1295,33 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
int readPhone = getPackageManager().checkPermission(Manifest.permission.READ_PHONE_STATE, getPackageName()); int readPhone = getPackageManager().checkPermission(Manifest.permission.READ_PHONE_STATE, getPackageName());
Log.i("[Permission] Read phone state permission is " + (readPhone == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); Log.i("[Permission] Read phone state permission is " + (readPhone == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
if (contacts == PackageManager.PERMISSION_GRANTED) { int ringtone = getPackageManager().checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE, getPackageName());
if (readPhone == PackageManager.PERMISSION_DENIED) { Log.i("[Permission] Read external storage for ring tone permission is " + (ringtone == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
checkAndRequestReadPhoneStatePermission();
if (ringtone != PackageManager.PERMISSION_GRANTED) {
if (LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
Log.i("[Permission] Asking for read external storage for ring tone");
permissionsList.add(Manifest.permission.READ_EXTERNAL_STORAGE);
} }
if (!fetchedContactsOnce) { }
ContactsManager.getInstance().enableContactsAccess(); if (readPhone != PackageManager.PERMISSION_GRANTED) {
ContactsManager.getInstance().fetchContactsAsync(); if (LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_PHONE_STATE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_PHONE_STATE)) {
fetchedContactsOnce = true; Log.i("[Permission] Asking for read phone state");
permissionsList.add(Manifest.permission.READ_PHONE_STATE);
} }
} else { }
if (!willContactsPermissionBeAsked()) { if (contacts != PackageManager.PERMISSION_GRANTED) {
ContactsManager.getInstance().fetchContactsAsync(); if (LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)) {
fetchedContactsOnce = true; Log.i("[Permission] Asking for contacts");
checkAndRequestReadPhoneStatePermission(); permissionsList.add(Manifest.permission.READ_CONTACTS);
} else {
checkAndRequestReadContactsPermission(); // This will ask for Read_Phone_State permission on it's cb
} }
} }
if (permissionsList.size() > 0) {
String[] permissions = new String[permissionsList.size()];
permissions = permissionsList.toArray(permissions);
ActivityCompat.requestPermissions(this, permissions, PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE);
}
} }
@Override @Override

View file

@ -1248,9 +1248,8 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
routeAudioToSpeaker(); // Need to be able to ear the ringtone during the early media routeAudioToSpeaker(); // Need to be able to ear the ringtone during the early media
} }
if (Hacks.needGalaxySAudioHack()) { if (Hacks.needGalaxySAudioHack())
mAudioManager.setMode(MODE_RINGTONE); mAudioManager.setMode(MODE_RINGTONE);
}
try { try {
if ((mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE || mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) && mVibrator != null) { if ((mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE || mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) && mVibrator != null) {

View file

@ -591,15 +591,12 @@ public final class LinphoneUtils {
if (ctxt != null) { if (ctxt != null) {
if (status.equals(LinphoneAccountCreator.Status.EmailInvalid)) if (status.equals(LinphoneAccountCreator.Status.EmailInvalid))
return ctxt.getString(R.string.invalid_email); return ctxt.getString(R.string.invalid_email);
if (status.equals(LinphoneAccountCreator.Status.UsernameInvalid)) { if (status.equals(LinphoneAccountCreator.Status.UsernameInvalid))
return ctxt.getString(R.string.invalid_username); return ctxt.getString(R.string.invalid_username);
} if (status.equals(LinphoneAccountCreator.Status.UsernameTooShort))
if (status.equals(LinphoneAccountCreator.Status.UsernameTooShort)) {
return ctxt.getString(R.string.username_too_short); return ctxt.getString(R.string.username_too_short);
} if (status.equals(LinphoneAccountCreator.Status.UsernameTooLong))
if (status.equals(LinphoneAccountCreator.Status.UsernameTooLong)) {
return ctxt.getString(R.string.username_too_long); return ctxt.getString(R.string.username_too_long);
}
if (status.equals(LinphoneAccountCreator.Status.UsernameInvalidSize)) if (status.equals(LinphoneAccountCreator.Status.UsernameInvalidSize))
return ctxt.getString(R.string.username_invalid_size); return ctxt.getString(R.string.username_invalid_size);
if (status.equals(LinphoneAccountCreator.Status.PhoneNumberTooShort)) if (status.equals(LinphoneAccountCreator.Status.PhoneNumberTooShort))
@ -635,7 +632,7 @@ public final class LinphoneUtils {
|| status.equals(LinphoneAccountCreator.Status.AccountAlreadyActivated) || status.equals(LinphoneAccountCreator.Status.AccountAlreadyActivated)
|| status.equals(LinphoneAccountCreator.Status.AccountActivated) || status.equals(LinphoneAccountCreator.Status.AccountActivated)
|| status.equals(LinphoneAccountCreator.Status.Ok)) { || status.equals(LinphoneAccountCreator.Status.Ok)) {
return ""; return "allo";
} }
} }
return null; return null;

View file

@ -516,8 +516,6 @@ private static AssistantActivity instance;
} }
} }
try { try {
builder.saveNewAccount(); builder.saveNewAccount();
if(!newAccount) { if(!newAccount) {
@ -737,13 +735,13 @@ private static AssistantActivity instance;
return json; return json;
} }
public boolean countryExist(String countryCode) { public Country getCountryFromCountryCode(String countryCode) {
countryCode = (countryCode.startsWith("+")) ? countryCode : "+" + countryCode;
for (Country c : allCountries) { for (Country c : allCountries) {
if (c.dial_code.equals("+"+countryCode)) { if (c.dial_code.compareTo("+"+countryCode) == 0)
return true; return c;
}
} }
return false; return null;
} }
@Override @Override

View file

@ -285,11 +285,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
} }
case R.id.assistant_create: { case R.id.assistant_create: {
if (linkAccount) { accountCreator.isAccountActivated();
addAlias();
} else {
createAccount();
}
break; break;
} }
} }
@ -378,6 +374,8 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
boolean isOk = status.equals(LinphoneAccountCreator.Status.Ok); boolean isOk = status.equals(LinphoneAccountCreator.Status.Ok);
LinphoneUtils.displayError(isOk, phoneNumberError, LinphoneUtils.errorForStatus(status)); LinphoneUtils.displayError(isOk, phoneNumberError, LinphoneUtils.errorForStatus(status));
accountCreator.setUsername(getUsername());
// Username or phone number // Username or phone number
if (getResources().getBoolean(R.bool.assistant_allow_username) && useUsername.isChecked() if (getResources().getBoolean(R.bool.assistant_allow_username) && useUsername.isChecked()
|| (getResources().getBoolean(R.bool.isTablet) || useEmail.isChecked() || (getResources().getBoolean(R.bool.isTablet) || useEmail.isChecked()
@ -410,7 +408,15 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
private void addPhoneNumberHandler(final EditText field, final ImageView icon) { private void addPhoneNumberHandler(final EditText field, final ImageView icon) {
field.addTextChangedListener(new TextWatcher() { field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {} public void afterTextChanged(Editable s) {
if (field.equals(dialCode)) {
AssistantActivity.Country c = AssistantActivity.instance().getCountryListAdapter().getCountryFromCountryCode(dialCode.getText().toString());
if (c != null) {
AssistantActivity.instance().country = c;
LinphoneUtils.setCountry(AssistantActivity.instance().country, dialCode, selectCountry, countryCode);
}
}
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@ -434,18 +440,6 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
} }
public void onTextChanged(CharSequence s, int start, int count, int after) { public void onTextChanged(CharSequence s, int start, int count, int after) {
if(s.length() > 0){
usernameOk = false;
Status status = accountCreator.setUsername(field.getText().toString());
if(status.equals(Status.Ok)){
accountCreator.isAccountUsed();
} else {
LinphoneUtils.displayError(usernameOk, usernameError, LinphoneUtils.errorForStatus(status));
sipUri.setText("");
}
} else {
LinphoneUtils.displayError(true, usernameError, "");
}
onTextChanged2(); onTextChanged2();
} }
}); });
@ -559,15 +553,26 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
@Override @Override
public void onAccountCreatorIsAccountActivated(LinphoneAccountCreator accountCreator, Status status) { public void onAccountCreatorIsAccountActivated(LinphoneAccountCreator accountCreator, Status status) {
if (status.equals(Status.AccountNotActivated)) {
if (useEmail.isChecked() || !getResources().getBoolean(R.bool.use_phone_number_validation)) {
AssistantActivity.instance().displayAssistantConfirm(getUsername(), passwordEdit.getText().toString());
} else {
AssistantActivity.instance().displayAssistantCodeConfirm(getUsername(), phoneNumberEdit.getText().toString(), LinphoneUtils.getCountryCode(dialCode), false);
}
} else {
if (linkAccount) {
addAlias();
} else {
createAccount();
}
}
} }
@Override @Override
public void onAccountCreatorPhoneAccountRecovered(LinphoneAccountCreator accountCreator, Status status) { public void onAccountCreatorPhoneAccountRecovered(LinphoneAccountCreator accountCreator, Status status) {
} }
@Override @Override
public void onAccountCreatorIsAccountLinked(LinphoneAccountCreator accountCreator, Status status) { public void onAccountCreatorIsAccountLinked(LinphoneAccountCreator accountCreator, Status status) {
} }
} }