|
|
|
|
@ -2,45 +2,39 @@ package com.gsoft.mitv; |
|
|
|
|
|
|
|
|
|
import android.app.Service; |
|
|
|
|
import android.content.Intent; |
|
|
|
|
import android.os.Binder; |
|
|
|
|
import android.os.IBinder; |
|
|
|
|
|
|
|
|
|
import com.anymediacloud.iptv.standard.ForceTV; |
|
|
|
|
import com.forcetech.Port; |
|
|
|
|
|
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.InputStream; |
|
|
|
|
import java.lang.ref.WeakReference; |
|
|
|
|
|
|
|
|
|
public class MainActivity extends Service { |
|
|
|
|
|
|
|
|
|
private static WeakReference<MainActivity> ref; |
|
|
|
|
private final IBinder binder = new LocalBinder(); |
|
|
|
|
private ForceTV forceTV; |
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
System.loadLibrary("mitv"); |
|
|
|
|
public class LocalBinder extends Binder { |
|
|
|
|
MainActivity getService() { |
|
|
|
|
// Return this instance of LocalService so clients can call public methods
|
|
|
|
|
return MainActivity.this; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private native void loadLibrary(int i); |
|
|
|
|
|
|
|
|
|
public static void start() { |
|
|
|
|
ref.get().loadLibrary(1); |
|
|
|
|
static { |
|
|
|
|
System.loadLibrary("mitv"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onCreate() { |
|
|
|
|
super.onCreate(); |
|
|
|
|
ref = new WeakReference<>(this); |
|
|
|
|
try { |
|
|
|
|
loadAsset(); |
|
|
|
|
} catch (Throwable ignored) { |
|
|
|
|
} |
|
|
|
|
loadLibrary(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public IBinder onBind(Intent intent) { |
|
|
|
|
forceTV = new ForceTV(); |
|
|
|
|
forceTV.start(Port.MTV); |
|
|
|
|
return null; |
|
|
|
|
return binder; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@ -49,20 +43,5 @@ public class MainActivity extends Service { |
|
|
|
|
return super.onUnbind(intent); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void loadAsset() throws Throwable { |
|
|
|
|
InputStream is = getAssets().open("libmitv.so"); |
|
|
|
|
FileOutputStream fos = new FileOutputStream(getCacheDir() + "/libmitv.so"); |
|
|
|
|
byte[] bytes = new byte[1024]; |
|
|
|
|
while (true) { |
|
|
|
|
int read = is.read(bytes); |
|
|
|
|
if (read != -1) { |
|
|
|
|
fos.write(bytes, 0, read); |
|
|
|
|
} else { |
|
|
|
|
is.close(); |
|
|
|
|
fos.flush(); |
|
|
|
|
fos.close(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
private native void loadLibrary(int type); |
|
|
|
|
} |
|
|
|
|
|