Skip to content

Commit

Permalink
Initial upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mittorn committed Sep 29, 2018
0 parents commit 8cdc4a4
Show file tree
Hide file tree
Showing 37 changed files with 1,119 additions and 0 deletions.
53 changes: 53 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mittorn.OverlayTest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="9" />

<application android:label="virgl-overlay" >
<activity android:name="settings.activity" android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<service android:name="process.p1" android:exported="true" android:process=":p1"/>
<service android:name="process.p2" android:process=":p2" android:exported="true"/>
<service android:name="process.p3" android:process=":p3" android:exported="true"/>
<service android:name="process.p4" android:process=":p4" android:exported="true"/>
<service android:name="process.p5" android:process=":p5" android:exported="true"/>
<service android:name="process.p6" android:process=":p6" android:exported="true"/>
<service android:name="process.p7" android:process=":p7" android:exported="true"/>
<service android:name="process.p8" android:process=":p8" android:exported="true"/>
<service android:name="process.p9" android:process=":p9" android:exported="true"/>
<service android:name="process.p10" android:process=":p10" android:exported="true"/>
<service android:name="process.p11" android:process=":p11" android:exported="true"/>
<service android:name="process.p12" android:process=":p12" android:exported="true"/>
<service android:name="process.p13" android:process=":p13" android:exported="true"/>
<service android:name="process.p14" android:process=":p14" android:exported="true"/>
<service android:name="process.p15" android:process=":p15" android:exported="true"/>
<service android:name="process.p16" android:process=":p16" android:exported="true"/>
<service android:name="process.p17" android:process=":p17" android:exported="true"/>
<service android:name="process.p18" android:process=":p18" android:exported="true"/>
<service android:name="process.p19" android:process=":p19" android:exported="true"/>
<service android:name="process.p20" android:process=":p20" android:exported="true"/>
<service android:name="process.p21" android:process=":p21" android:exported="true"/>
<service android:name="process.p22" android:process=":p22" android:exported="true"/>
<service android:name="process.p23" android:process=":p23" android:exported="true"/>
<service android:name="process.p24" android:process=":p24" android:exported="true"/>
<service android:name="process.p25" android:process=":p25" android:exported="true"/>
<service android:name="process.p26" android:process=":p26" android:exported="true"/>
<service android:name="process.p27" android:process=":p27" android:exported="true"/>
<service android:name="process.p28" android:process=":p28" android:exported="true"/>
<service android:name="process.p29" android:process=":p29" android:exported="true"/>
<service android:name="process.p30" android:process=":p30" android:exported="true"/>
<service android:name="process.p31" android:process=":p31" android:exported="true"/>
<service android:name="process.p32" android:process=":p32" android:exported="true"/>
</application>

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

</manifest>
1 change: 1 addition & 0 deletions gen-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
i=2;while [ $i -le 32 ]; do echo '<service' android:name=\"process.p$i\" android:process=\":p$i\" 'android:exported="true"/>';i=$(($i+1));done
196 changes: 196 additions & 0 deletions src/common/overlay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package common;
import android.content.*;
import android.graphics.*;
import android.view.*;
import android.app.*;
import android.util.Log;
import android.os.Handler;

public class overlay {
private static final String T = "virgl-java";
private static native void nativeRun(int fd);
private static native int nativeAccept(int fd);
private static native int nativeOpen();
private static native int nativeInit(String settings)
private static native void nativeUnlink();
private static Handler handler;
private static Context ctx;
private static WindowManager wm;

private static void start_next(int svc_id)
{
java.util.List<ActivityManager.RunningServiceInfo> services =
((ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE)).
getRunningServices(Integer.MAX_VALUE);
for(int i = 1; i < 32; i++)
{
boolean free = true;

if( i == svc_id )
continue;
for(ActivityManager.RunningServiceInfo s :services)
{

if(s.service.getClassName().equals("process.p"+i))
{
free = false;
break;
}
}
if(free)
{
Log.d(T,"starting instance "+i);
ctx.startService( new Intent().setClassName(ctx, "process.p"+i));
return;
}
}
}

private static void run_mt()
{

new Thread(){
@Override
public void run()
{
int sock = nativeOpen();
int fd;
while((fd = nativeAccept(sock)) >= 0)
{
final int fd1 = fd;
Thread t = new Thread(){
@Override
public void run()
{
nativeRun(fd1);
}
};
t.start();
}
}
}.start();
}
private static void run_mp(final int svc_id)
{
new Thread()
{
public void run()
{
int fd = nativeOpen();
fd = nativeAccept(fd);
nativeUnlink();
start_next(svc_id);
nativeRun(fd);
ctx.stopService( new Intent().setClassName(ctx, "process.p"+svc_id));
}
}.start();
}

public static void start(Context ctx1, int svc_id)
{
ctx = ctx1;
wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
byte[] settings = new byte[65];
System.loadLibrary("vtest");
int thread_mode = nativeInit(ctx.getFilesDir().getPath()+"/settings");
handler = new Handler();
if( thread_mode == 1 )
run_mt();
else
run_mp(svc_id);
}

private static SurfaceView create(final int x, final int y, final int width, final int height) {
//resize(x,y,width, height);
final Thread t = Thread.currentThread();
final SurfaceView surf[] = new SurfaceView[1];
try
{
Log.d(T, "post");

handler.postDelayed(new Runnable(){
public void run()
{
surf[0] = new SurfaceView(ctx);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.OPAQUE);
params.gravity = Gravity.LEFT | Gravity.TOP;
params.x = x;
params.y = y;
params.width = width;
params.height = height;
if( (width == 0) || (height == 0) )
{
params.width = params.height = 32;
}
wm.addView(surf[0], params);
Log.d(T, "notify");
synchronized(t)
{
t.notify();
}
}
},100);
synchronized(t)
{
t.wait();
t.sleep(1000);
}
Log.d(T, "resume");
}
catch(Exception e)
{
e.printStackTrace();

Log.d(T, "int");
//return null;
}
return surf[0];
}

private static void set_rect(final SurfaceView surface, final int x, final int y, final int width, final int height, final int visible)
{

Log.d(T,"resize " + x + " " + y + " " + width );
handler.post(new Runnable()
{
public void run()
{
try
{
WindowManager.LayoutParams params = (WindowManager.LayoutParams)surface.getLayoutParams();

if( params == null )
return;
if( visible != 0 )
{
params.x = x;
params.y = y;
params.width = width;
params.height = height;
}
else
{
params.x = params.y = -33;
params.width = params.height = 32;
}
wm.updateViewLayout(surface, params);
}
catch(Exception e)
{}
}
});
}

public static void destroy(final SurfaceView surface) {
handler.post(new Runnable(){
public void run()
{
wm.removeView(surface);
}
});
}
public static Surface get_surface(SurfaceView surf)
{
return surf.getHolder().getSurface();
}
}
1 change: 1 addition & 0 deletions src/gen-process.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
i=2;while [ $i -le 32 ]; do sed -e s/1/$i/ process/p1.java > process/p$i.java;i=$(($i+1));done
19 changes: 19 additions & 0 deletions src/process/p1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package process;

public class p1 extends android.app.Service
{
@Override
public android.os.IBinder onBind(android.content.Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
common.overlay.start(this,1);
}
@Override
public void onDestroy() {
super.onDestroy();
System.exit(0);
}
}
19 changes: 19 additions & 0 deletions src/process/p10.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package process;

public class p10 extends android.app.Service
{
@Override
public android.os.IBinder onBind(android.content.Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
common.overlay.start(this,10);
}
@Override
public void onDestroy() {
super.onDestroy();
System.exit(0);
}
}
19 changes: 19 additions & 0 deletions src/process/p11.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package process;

public class p11 extends android.app.Service
{
@Override
public android.os.IBinder onBind(android.content.Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
common.overlay.start(this,11);
}
@Override
public void onDestroy() {
super.onDestroy();
System.exit(0);
}
}
19 changes: 19 additions & 0 deletions src/process/p12.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package process;

public class p12 extends android.app.Service
{
@Override
public android.os.IBinder onBind(android.content.Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
common.overlay.start(this,12);
}
@Override
public void onDestroy() {
super.onDestroy();
System.exit(0);
}
}
19 changes: 19 additions & 0 deletions src/process/p13.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package process;

public class p13 extends android.app.Service
{
@Override
public android.os.IBinder onBind(android.content.Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
common.overlay.start(this,13);
}
@Override
public void onDestroy() {
super.onDestroy();
System.exit(0);
}
}
19 changes: 19 additions & 0 deletions src/process/p14.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package process;

public class p14 extends android.app.Service
{
@Override
public android.os.IBinder onBind(android.content.Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
common.overlay.start(this,14);
}
@Override
public void onDestroy() {
super.onDestroy();
System.exit(0);
}
}
19 changes: 19 additions & 0 deletions src/process/p15.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package process;

public class p15 extends android.app.Service
{
@Override
public android.os.IBinder onBind(android.content.Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
common.overlay.start(this,15);
}
@Override
public void onDestroy() {
super.onDestroy();
System.exit(0);
}
}
Loading

0 comments on commit 8cdc4a4

Please sign in to comment.