├── src ├── gen-process.sh ├── process │ ├── p1.java │ ├── p2.java │ ├── p3.java │ ├── p4.java │ ├── p5.java │ ├── p6.java │ ├── p7.java │ ├── p8.java │ ├── p9.java │ ├── p10.java │ ├── p11.java │ ├── p12.java │ ├── p13.java │ ├── p14.java │ ├── p15.java │ ├── p16.java │ ├── p17.java │ ├── p18.java │ ├── p19.java │ ├── p20.java │ ├── p21.java │ ├── p22.java │ ├── p23.java │ ├── p24.java │ ├── p25.java │ ├── p26.java │ ├── p27.java │ ├── p28.java │ ├── p29.java │ ├── p30.java │ ├── p31.java │ └── p32.java ├── common │ └── overlay.java └── settings │ └── activity.java ├── gen-manifest.sh └── AndroidManifest.xml /src/gen-process.sh: -------------------------------------------------------------------------------- 1 | i=2;while [ $i -le 32 ]; do sed -e s/1/$i/ process/p1.java > process/p$i.java;i=$(($i+1));done 2 | -------------------------------------------------------------------------------- /gen-manifest.sh: -------------------------------------------------------------------------------- 1 | i=2;while [ $i -le 32 ]; do echo '';i=$(($i+1));done -------------------------------------------------------------------------------- /src/process/p1.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p1 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,1); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p2.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p2 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,2); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p3.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p3 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,3); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p4.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p4 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,4); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p5.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p5 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,5); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p6.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p6 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,6); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p7.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p7 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,7); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p8.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p8 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,8); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p9.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p9 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,9); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p10.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p10 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,10); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p11.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p11 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,11); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p12.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p12 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,12); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p13.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p13 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,13); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p14.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p14 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,14); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p15.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p15 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,15); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p16.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p16 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,16); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p17.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p17 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,17); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p18.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p18 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,18); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p19.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p19 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,19); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p20.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p20 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,20); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p21.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p21 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,21); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p22.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p22 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,22); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p23.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p23 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,23); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p24.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p24 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,24); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p25.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p25 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,25); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p26.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p26 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,26); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p27.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p27 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,27); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p28.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p28 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,28); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p29.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p29 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,29); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p30.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p30 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,30); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p31.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p31 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,31); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/process/p32.java: -------------------------------------------------------------------------------- 1 | package process; 2 | 3 | public class p32 extends android.app.Service 4 | { 5 | @Override 6 | public android.os.IBinder onBind(android.content.Intent intent) { 7 | return null; 8 | } 9 | @Override 10 | public void onCreate() { 11 | super.onCreate(); 12 | common.overlay.start(this,32); 13 | } 14 | @Override 15 | public void onDestroy() { 16 | super.onDestroy(); 17 | System.exit(0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/common/overlay.java: -------------------------------------------------------------------------------- 1 | package common; 2 | import android.content.*; 3 | import android.graphics.*; 4 | import android.view.*; 5 | import android.app.*; 6 | import android.util.Log; 7 | import android.os.Handler; 8 | 9 | public class overlay { 10 | private static final String T = "virgl-java"; 11 | private static native void nativeRun(int fd); 12 | private static native int nativeAccept(int fd); 13 | private static native int nativeOpen(); 14 | private static native int nativeInit(String settings) 15 | private static native void nativeUnlink(); 16 | private static Handler handler; 17 | private static Context ctx; 18 | private static WindowManager wm; 19 | 20 | private static void start_next(int svc_id) 21 | { 22 | java.util.List services = 23 | ((ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE)). 24 | getRunningServices(Integer.MAX_VALUE); 25 | for(int i = 1; i < 32; i++) 26 | { 27 | boolean free = true; 28 | 29 | if( i == svc_id ) 30 | continue; 31 | for(ActivityManager.RunningServiceInfo s :services) 32 | { 33 | 34 | if(s.service.getClassName().equals("process.p"+i)) 35 | { 36 | free = false; 37 | break; 38 | } 39 | } 40 | if(free) 41 | { 42 | Log.d(T,"starting instance "+i); 43 | ctx.startService( new Intent().setClassName(ctx, "process.p"+i)); 44 | return; 45 | } 46 | } 47 | } 48 | 49 | private static void run_mt() 50 | { 51 | 52 | new Thread(){ 53 | @Override 54 | public void run() 55 | { 56 | int sock = nativeOpen(); 57 | if( sock < 0 ) 58 | { 59 | Log.d(T, "Failed to open socket!"); 60 | ctx.stopService( new Intent().setClassName(ctx, "process.p1")); 61 | return; 62 | } 63 | int fd; 64 | while((fd = nativeAccept(sock)) >= 0) 65 | { 66 | final int fd1 = fd; 67 | Thread t = new Thread(){ 68 | @Override 69 | public void run() 70 | { 71 | nativeRun(fd1); 72 | } 73 | }; 74 | t.start(); 75 | } 76 | } 77 | }.start(); 78 | } 79 | private static void run_mp(final int svc_id) 80 | { 81 | new Thread() 82 | { 83 | public void run() 84 | { 85 | int fd = nativeOpen(); 86 | if( fd < 0 ) 87 | { 88 | Log.d(T, "Failed to open socket!"); 89 | ctx.stopService( new Intent().setClassName(ctx, "process.p"+svc_id)); 90 | return; 91 | } 92 | fd = nativeAccept(fd); 93 | nativeUnlink(); 94 | start_next(svc_id); 95 | nativeRun(fd); 96 | ctx.stopService( new Intent().setClassName(ctx, "process.p"+svc_id)); 97 | } 98 | }.start(); 99 | } 100 | 101 | public static void start(Context ctx1, int svc_id) 102 | { 103 | ctx = ctx1; 104 | wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE); 105 | byte[] settings = new byte[65]; 106 | System.loadLibrary("vtest"); 107 | int thread_mode = nativeInit(ctx.getFilesDir().getPath()+"/settings"); 108 | handler = new Handler(); 109 | if( thread_mode == 1 ) 110 | run_mt(); 111 | else 112 | run_mp(svc_id); 113 | } 114 | 115 | private static SurfaceView create(final int x, final int y, final int width, final int height) { 116 | //resize(x,y,width, height); 117 | final Thread t = Thread.currentThread(); 118 | final SurfaceView surf[] = new SurfaceView[1]; 119 | try 120 | { 121 | Log.d(T, "post"); 122 | 123 | handler.postDelayed(new Runnable(){ 124 | public void run() 125 | { 126 | surf[0] = new SurfaceView(ctx); 127 | 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); 128 | params.gravity = Gravity.LEFT | Gravity.TOP; 129 | params.x = x; 130 | params.y = y; 131 | params.width = width; 132 | params.height = height; 133 | if( (width == 0) || (height == 0) ) 134 | { 135 | params.width = params.height = 32; 136 | } 137 | wm.addView(surf[0], params); 138 | Log.d(T, "notify"); 139 | synchronized(t) 140 | { 141 | t.notify(); 142 | } 143 | } 144 | },100); 145 | synchronized(t) 146 | { 147 | t.wait(); 148 | t.sleep(1000); 149 | } 150 | Log.d(T, "resume"); 151 | } 152 | catch(Exception e) 153 | { 154 | e.printStackTrace(); 155 | 156 | Log.d(T, "int"); 157 | //return null; 158 | } 159 | return surf[0]; 160 | } 161 | 162 | private static void set_rect(final SurfaceView surface, final int x, final int y, final int width, final int height, final int visible) 163 | { 164 | 165 | Log.d(T,"resize " + x + " " + y + " " + width ); 166 | handler.post(new Runnable() 167 | { 168 | public void run() 169 | { 170 | try 171 | { 172 | WindowManager.LayoutParams params = (WindowManager.LayoutParams)surface.getLayoutParams(); 173 | 174 | if( params == null ) 175 | return; 176 | if( visible != 0 ) 177 | { 178 | params.x = x; 179 | params.y = y; 180 | params.width = width; 181 | params.height = height; 182 | } 183 | else 184 | { 185 | params.x = params.y = -33; 186 | params.width = params.height = 32; 187 | } 188 | wm.updateViewLayout(surface, params); 189 | } 190 | catch(Exception e) 191 | {} 192 | } 193 | }); 194 | } 195 | 196 | public static void destroy(final SurfaceView surface) { 197 | handler.post(new Runnable(){ 198 | public void run() 199 | { 200 | wm.removeView(surface); 201 | } 202 | }); 203 | } 204 | public static Surface get_surface(SurfaceView surf) 205 | { 206 | return surf.getHolder().getSurface(); 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /src/settings/activity.java: -------------------------------------------------------------------------------- 1 | package settings; 2 | 3 | import android.app.*; 4 | import android.os.*; 5 | import android.view.*; 6 | import android.widget.*; 7 | import android.widget.RelativeLayout.*; 8 | import android.content.*; 9 | import android.text.*; 10 | import android.text.style.*; 11 | import android.graphics.*; 12 | import java.awt.font.*; 13 | import android.widget.GridLayout.*; 14 | import java.io.*; 15 | import android.util.*; 16 | import java.nio.*; 17 | 18 | public class activity extends Activity 19 | { 20 | public static final int sdk = Integer.valueOf(Build.VERSION.SDK); 21 | public static final String T = "virgl-activity"; 22 | ;public static final int FL_RING = (1<<0); 23 | //#define FL_GLX (1<<1) 24 | public static final int FL_GLES = (1<<2); 25 | //#define FL_OVERLAY (1<<3) 26 | public static final int FL_MULTITHREAD = (1<<4); 27 | 28 | public SpannableString style_button_string(String str) 29 | { 30 | if(sdk < 21) 31 | str = str.toUpperCase(); 32 | 33 | SpannableString span_string = new SpannableString(str.toUpperCase()); 34 | 35 | if(sdk < 21) 36 | span_string.setSpan(new StyleSpan(Typeface.BOLD), 0, str.length(), 0); 37 | 38 | span_string.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, str.length(), 0); 39 | 40 | return span_string; 41 | } 42 | 43 | private EditText add_edit(LinearLayout layout, String title) 44 | { 45 | LinearLayout.LayoutParams edit_params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 46 | edit_params.setMargins(10,20,10,20);//размеры строки для ввода аргументов 47 | 48 | TextView title_view = new TextView(this); 49 | title_view.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 50 | title_view.setText(title); 51 | title_view.setTextAppearance(this, android.R.attr.textAppearanceLarge); 52 | 53 | EditText edit = new EditText(this); 54 | edit.setLayoutParams(edit_params); 55 | edit.setSingleLine(true); 56 | if(sdk < 21) 57 | { 58 | edit.setBackgroundColor(0xFF353535); 59 | edit.setTextColor(0xFFFFFFFF); 60 | edit.setPadding(5,5,5,5); 61 | } 62 | 63 | layout.addView(title_view); 64 | layout.addView(edit); 65 | return edit; 66 | } 67 | private Button add_button(LinearLayout panel,String title, View.OnClickListener listener) 68 | { 69 | Button startButton = new Button(this); 70 | 71 | // Set launch button title here 72 | startButton.setText(style_button_string(title)); 73 | //startButton.setTextAlignment() 74 | LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); 75 | //buttonParams.addRule(Layout.ALIGN_PARENT_BOTTOM); 76 | buttonParams.weight = 1; 77 | startButton.setGravity(Gravity.BOTTOM); 78 | startButton.setLayoutParams(buttonParams); 79 | if(sdk < 21) 80 | { 81 | startButton.getBackground().setAlpha(96); 82 | startButton.getBackground().invalidateSelf(); 83 | startButton.setTextColor(0xFFFFFFFF); 84 | startButton.setTextAppearance(this, android.R.attr.textAppearanceLarge); 85 | startButton.setTextSize(20); 86 | } 87 | startButton.setOnClickListener(listener); 88 | 89 | // Add other options here 90 | 91 | panel.addView(startButton); 92 | return startButton; 93 | } 94 | private CheckBox add_checkbox(LinearLayout layout, String title) 95 | { 96 | CheckBox cb = new CheckBox(this); 97 | cb.setText(title); 98 | layout.addView(cb); 99 | return cb; 100 | } 101 | 102 | @Override 103 | protected void onCreate(Bundle savedInstanceState) { 104 | super.onCreate(savedInstanceState); 105 | this.requestWindowFeature(Window.FEATURE_NO_TITLE); 106 | 107 | // set theme 108 | if ( sdk >= 21 ) 109 | super.setTheme( 0x01030224 ); 110 | else 111 | super.setTheme( 0x01030005 ); 112 | 113 | // Build layout 114 | RelativeLayout launcher = new RelativeLayout(this); 115 | // launcher.setOrientation(LinearLayout.VERTICAL); 116 | // launcher.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); 117 | 118 | launcher.setBackgroundColor(0xFF252525); 119 | TextView launcherTitle = new TextView(this); 120 | LayoutParams titleparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 121 | titleparams.addRule(RelativeLayout.ALIGN_PARENT_TOP); 122 | titleparams.setMargins(5,15,5,1);//размеры верхнего layout 123 | //titleparams.weight = 1; 124 | launcherTitle.setLayoutParams(titleparams); 125 | launcherTitle.setText("virgl renderer"); 126 | launcherTitle.setTextColor(0xFF4db017); 127 | launcherTitle.setTextAppearance(this, android.R.attr.textAppearanceMedium); 128 | launcherTitle.setTextSize(25); 129 | launcherTitle.setBackgroundColor(0xFF555555); 130 | launcherTitle.setCompoundDrawablePadding(10); 131 | try 132 | { 133 | launcherTitle.setCompoundDrawablesWithIntrinsicBounds(getApplicationContext().getPackageManager().getApplicationIcon(getPackageName()),null,null,null); 134 | launcherTitle.setPadding(9,9,6,0); 135 | } 136 | catch(Exception e) 137 | { 138 | launcherTitle.setPadding(60,6,6,6); 139 | } 140 | launcher.addView(launcherTitle); 141 | LinearLayout launcherBody = new LinearLayout(this); 142 | launcherBody.setOrientation(LinearLayout.VERTICAL); 143 | ScrollView.LayoutParams bp = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 144 | bp.setMargins(10,15,10,10);//размеры верхнего layout 145 | 146 | launcherBody.setLayoutParams(bp); 147 | launcherBody.setPadding(10,0,10,30); 148 | launcherBody.setBackgroundColor(0xFF454545); 149 | LinearLayout launcherBorder = new LinearLayout(this); 150 | RelativeLayout.LayoutParams params_ = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.MATCH_PARENT); 151 | 152 | LinearLayout panel = new LinearLayout(this); 153 | panel.setId(1000); 154 | launcherTitle.setId(1001); 155 | params_.addRule(RelativeLayout.BELOW, launcherTitle.getId()); 156 | params_.setMargins(5,15,5,1);//размеры верхнего layout 157 | 158 | params_.addRule(RelativeLayout.ABOVE, panel.getId()); 159 | launcherBorder.setLayoutParams(params_); 160 | launcherBorder.setBackgroundColor(0xFF555555); 161 | launcherBorder.setOrientation(LinearLayout.VERTICAL); 162 | 163 | ScrollView launcherBorder2 = new ScrollView(this); 164 | LinearLayout.LayoutParams sp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 165 | sp.setMargins(5,15,5,10);//размеры верхнего layout 166 | 167 | launcherBorder2.setLayoutParams(sp); 168 | //launcherBorder2.setOrientation(LinearLayout.VERTICAL); 169 | launcherBorder2.setBackgroundColor(0xFF353535); 170 | launcherBorder2.addView(launcherBody); 171 | launcherBorder2.setPadding(10,0,10,10); 172 | launcherBorder.addView(launcherBorder2); 173 | launcherBorder.setPadding(10,0,10,20); 174 | launcher.addView(launcherBorder); 175 | 176 | final EditText socket_path = add_edit(launcherBody, "Socket path (/tmp/.virgl_test)"); 177 | final EditText ring_path = add_edit(launcherBody, "Ring buffer path (/dev/shm)"); 178 | final CheckBox use_ring = add_checkbox(launcherBody, "Use ring buffer instead of socket"); 179 | final CheckBox use_gles = add_checkbox(launcherBody, "Use GL ES 3.x instead of OpenGL"); 180 | final CheckBox use_threads = add_checkbox(launcherBody, "Use multi-thread egl access"); 181 | int flags = 0; 182 | try 183 | { 184 | //char[] buffer = new char[64]; 185 | CharBuffer buffer = CharBuffer.allocate(128); 186 | FileReader settings_reader = new FileReader(getFilesDir().getPath()+"/settings"); 187 | //int len = settings_reader.read(buffer); 188 | //buffer.notifyAll() 189 | //buffer. 190 | BufferedReader reader = new BufferedReader(settings_reader); 191 | //reader.readLine() 192 | //CharBuffer buf = CharBuffer.allocate(settings_reader.read(buffer)); 193 | //buffer.read(buf); 194 | //StringReader reader = new StringReader(settings_reader); 195 | String[] parts = reader.readLine().split(" "); 196 | //Log.d(T,"read:"+Integer.valueOf(parts[0]) + ", " + parts[1] + ", " + parts[2]); 197 | flags = Integer.valueOf(parts[0]); 198 | socket_path.setText(parts[1]); 199 | ring_path.setText(parts[2]); 200 | reader.close(); 201 | settings_reader.close(); 202 | } 203 | catch(Exception e){} 204 | use_ring.setChecked((flags & FL_RING) != 0); 205 | use_gles.setChecked((flags & FL_GLES) != 0); 206 | use_threads.setChecked((flags & FL_MULTITHREAD) != 0); 207 | panel.setOrientation(LinearLayout.HORIZONTAL); 208 | add_button(panel,"Clean services", new View.OnClickListener(){@Override public void onClick(View v){ 209 | for(int i = 1; i < 32; i++) 210 | { 211 | try{ 212 | stopService( new Intent().setClassName(activity.this, "process.p"+i)); 213 | } 214 | catch(Exception e){} 215 | } 216 | }}); 217 | add_button(panel,"Start service", new View.OnClickListener(){@Override public void onClick(View v){ 218 | try{ 219 | int flags = 0; 220 | if(use_ring.isChecked()) 221 | flags |= FL_RING; 222 | if(use_gles.isChecked()) 223 | flags |= FL_GLES; 224 | if(use_threads.isChecked()) 225 | flags |= FL_MULTITHREAD; 226 | 227 | FileWriter writer = new FileWriter(getFilesDir().getPath()+"/settings"); 228 | writer.write(String.valueOf(flags)); 229 | writer.write(' '); 230 | writer.write(socket_path.getText().toString()); 231 | writer.write(' '); 232 | writer.write(ring_path.getText().toString()); 233 | writer.close(); 234 | startService( new Intent().setClassName(activity.this, "process.p1")); 235 | } 236 | catch(Exception e) 237 | {} 238 | }}); 239 | //panel.setWeightSum(2); 240 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 241 | //params.weight = 1; 242 | //params.alignWithParent = true; 243 | params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 244 | 245 | panel.setLayoutParams(params);// 246 | //panel.setGravity(Gravity.BOTTOM); 247 | //RelativeLayout.ALIGN_PARENT_BOTTOM; 248 | 249 | launcher.addView(panel); 250 | //launcher.setWeightSum(5000000); 251 | setContentView(launcher); 252 | //mPref = getSharedPreferences("mod", 0); 253 | //socket_path.setText(mPref.getString("argv","-dev 3 -log")); 254 | 255 | // Uncomment this if you have pak file 256 | // ExtractAssets.extractPAK(this, false); 257 | } 258 | 259 | 260 | } 261 | --------------------------------------------------------------------------------