Update linphone + override CodecDownloader to app

This commit is contained in:
Erwan Croze 2016-06-21 13:38:49 +02:00
parent 43585944e9
commit 3f6e93a37d
4 changed files with 135 additions and 10 deletions

View file

@ -56,6 +56,7 @@ import org.linphone.core.LinphoneCore.RegistrationState;
import org.linphone.core.LinphoneCore.RemoteProvisioningState;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreFactoryImpl;
import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneEvent;
import org.linphone.core.LinphoneFriend;
@ -73,13 +74,17 @@ import org.linphone.mediastream.Version;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration;
import org.linphone.mediastream.video.capture.hwconf.AndroidCameraConfiguration.AndroidCamera;
import org.linphone.mediastream.video.capture.hwconf.Hacks;
import org.linphone.tools.CodecDownloader;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager.NameNotFoundException;
@ -101,6 +106,7 @@ import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.Vibrator;
import android.preference.CheckBoxPreference;
import android.provider.MediaStore;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
@ -135,6 +141,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
private Resources mR;
private LinphonePreferences mPrefs;
private LinphoneCore mLc;
private CodecDownloader mCodecDownloader;
private String lastLcStatusMessage;
private String basePath;
private static boolean sExited;
@ -182,6 +189,7 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
mConnectivityManager = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE);
mR = c.getResources();
mPendingChatFileMessage = new ArrayList<LinphoneChatMessage>();
initCodecDownloader();
}
private static final int LINPHONE_VOLUME_STREAM = STREAM_VOICE_CALL;
@ -212,6 +220,123 @@ public class LinphoneManager implements LinphoneCoreListener, LinphoneChatMessag
mLc.enableSpeaker(speakerOn);
}
private void initCodecDownloader() {
mCodecDownloader = new CodecDownloader() {
Context ctxt = mServiceContext;
ProgressDialog progress;
CheckBoxPreference box;
@Override
public void listenerDownloadStarting() {
if (mServiceContext == null) return;
mHandler.post(new Runnable() {
@Override
public void run() {
progress = new ProgressDialog(ctxt);
progress.setCanceledOnTouchOutside(false);
progress.setCancelable(false);
progress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
}
});
}
@Override
public void listenerUpdateMsg(final int now, final int max) {
if (progress == null) return;
mHandler.post(new Runnable() {
@Override
public void run() {
progress.setMessage("Downloading OpenH264");
progress.setMax(max);
progress.setProgress(now);
progress.show();
}
});
}
@Override
public void listenerDownloadEnding() {
if (progress == null) return;
mHandler.post(new Runnable() {
@Override
public void run() {
progress.dismiss();
LinphoneCoreFactoryImpl.loadOptionalLibraryWithPath(ctxt.getFilesDir()+"/" + CodecDownloader.getNameLib());
LinphoneManager.getLc().reloadMsPlugins(null);
AlertDialog.Builder builder = new AlertDialog.Builder(ctxt);
builder.setMessage(CodecDownloader.getLicenseMessage() + " downloaded");
builder.setCancelable(false);
builder.setNeutralButton("Ok", null);
builder.show();
if (box != null) box.setSummary(CodecDownloader.getLicenseMessage());
}
});
}
@Override
public void listenerDownloadFailed(final String error) {
if (progress == null) return;
mHandler.post(new Runnable() {
@Override
public void run() {
if (progress != null) progress.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(ctxt);
builder.setMessage(error);
builder.show();
}
});
}
@Override
public void startDownload(Context context, Object obj) {
box = (CheckBoxPreference)obj;
ctxt = context;
this.setFileDirection(ctxt.getFilesDir().toString());
askPopUp();
}
public void askPopUp() {
AlertDialog.Builder builder = new AlertDialog.Builder(ctxt);
builder.setCancelable(false);
AlertDialog.Builder show = builder.setMessage("Do you want to download "
+ CodecDownloader.getLicenseMessage()).setPositiveButton("Yes", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE)
mCodecDownloader.downloadCodec();
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_NEGATIVE){
// Disable H264
PayloadType h264 = null;
for (PayloadType pt : mLc.getVideoCodecs()) {
if (pt.getMime().equals("H264")) h264 = pt;
}
if (h264 == null) return;
if (LinphonePreferences.instance().isFirstLaunch()) {
try {
mLc.enablePayloadType(h264, false);
} catch (LinphoneCoreException e) {
e.printStackTrace();
}
}
}
}
}).show();
}
};
}
public CodecDownloader getCodecDownloader(){
return mCodecDownloader;
}
public void routeAudioToSpeaker() {
routeAudioToSpeakerHelper(true);
}

View file

@ -557,7 +557,7 @@ public class SettingsFragment extends PreferencesListFragment {
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
for (final PayloadType pt : lc.getVideoCodecs()) {
CheckBoxPreference codec = new CheckBoxPreference(getActivity());
final CheckBoxPreference codec = new CheckBoxPreference(getActivity());
codec.setTitle(pt.getMime());
if (!pt.getMime().equals("VP8")) {
@ -572,6 +572,8 @@ public class SettingsFragment extends PreferencesListFragment {
}
}
}
if (pt.getMime().equals("H264") && CodecDownloader.codecExist(ctxt))
codec.setSummary(CodecDownloader.getLicenseMessage());
codec.setChecked(lc.isPayloadTypeEnabled(pt));
codec.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@ -579,11 +581,9 @@ public class SettingsFragment extends PreferencesListFragment {
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean enable = (Boolean) newValue;
try {
if (Version.getCpuAbis().contains("armeabi-v7a") && !Version.getCpuAbis().contains("x86") && pt.getMime().equals("H264")) {
if (enable && !CodecDownloader.codecExist(ctxt)) {
CodecDownloader download = new CodecDownloader(ctxt);
download.askPopUp("Do you want to download h264 codec?","No","Yes");
}
if (enable && Version.getCpuAbis().contains("armeabi-v7a") && !Version.getCpuAbis().contains("x86")
&& pt.getMime().equals("H264") && !CodecDownloader.codecExist(ctxt)) {
LinphoneManager.getInstance().getCodecDownloader().startDownload(ctxt, codec);
}
LinphoneManager.getLcIfManagerNotDestroyedOrNull().enablePayloadType(pt, enable);
} catch (LinphoneCoreException e) {

View file

@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.R;
import org.linphone.mediastream.Version;
@ -42,9 +43,8 @@ public class WelcomeFragment extends Fragment implements OnClickListener {
View view = inflater.inflate(R.layout.assistant_welcome, container, false);
if (LinphonePreferences.instance().isFirstLaunch() && Version.getCpuAbis().contains("armeabi-v7a")
&& !Version.getCpuAbis().contains("x86") && !CodecDownloader.codecExist(getContext())) {
CodecDownloader download = new CodecDownloader(getContext());
download.askPopUp("Do you want to download h264 codec?","No","Yes");
&& !Version.getCpuAbis().contains("x86") && !CodecDownloader.codecExist(getContext())) {
LinphoneManager.getInstance().getCodecDownloader().startDownload(getContext(), null);
}
createAccount = (Button) view.findViewById(R.id.create_account);

@ -1 +1 @@
Subproject commit 76074d2bc028b09fa1853486c75d2dd2c4c3bbaa
Subproject commit 031a83953bfa302e3035b5b8d99491578ad0e258