Xash3D background service (prevend unload)

This commit is contained in:
mittorn 2017-03-24 22:03:00 +00:00
parent 6d9056c74c
commit 5368a7f56b
8 changed files with 203 additions and 58 deletions

View file

@ -66,13 +66,16 @@
<activity android:name="in.celest.xash3d.XashActivity" <activity android:name="in.celest.xash3d.XashActivity"
android:screenOrientation="sensorLandscape" android:screenOrientation="sensorLandscape"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize"
android:label="@string/app_name"> android:label="@string/app_name"
android:launchMode="singleTask">
<intent-filter> <intent-filter>
<action android:name="in.celest.xash3d.START" /> <action android:name="in.celest.xash3d.START" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="in.celest.xash3d.FPicker"></activity> <activity android:name="in.celest.xash3d.FPicker"></activity>
<service android:name="in.celest.xash3d.XashService" android:stopWithTask="false" />
<receiver android:name="in.celest.xash3d.XashService$exitButtonListener" />
<receiver android:name="in.celest.xash3d.InstallReceiver"> <receiver android:name="in.celest.xash3d.InstallReceiver">
<intent-filter android:priority="100"> <intent-filter android:priority="100">
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />

View file

@ -1,4 +1,4 @@
ANDROID_JAR=../android-13.jar ANDROID_JAR=../android-14_.jar
AAPT=./../aapt AAPT=./../aapt
DX=./../dx DX=./../dx
APKBUILDER=./../apkbuilder APKBUILDER=./../apkbuilder

@ -1 +1 @@
Subproject commit 472f483e21b042a3fa04f2e559acf7c71c0c0325 Subproject commit 8dcecbaac9204a87200f2ce7e95c2b8f23a7a616

View file

@ -1,43 +1,34 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_width="fill_parent" android:layout_height="65sp"
android:layout_height="fill_parent" android:orientation="horizontal" >
android:padding="5dp">
<ImageView android:id="@+id/status_icon" <ImageView
android:layout_width="wrap_content" android:id="@+id/status_image"
android:layout_height="fill_parent" android:layout_width="wrap_content"
android:layout_alignParentLeft="true" android:layout_height="wrap_content"
android:layout_marginRight="10dp"/> android:src="@drawable/ic_launcher"
android:layout_weight="00"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/status_text"
<RelativeLayout android:layout_width="fill_parent" android:layout_width="wrap_content"
android:layout_height="fill_parent" android:layout_height="wrap_content"
android:layout_toRightOf="@id/status_icon"> android:layout_alignParentTop="true"
android:layout_marginLeft="10dip"
android:singleLine="true"
android:layout_weight="90"
<TextView android:id="@+id/status_text" android:text="Xash3D"
android:layout_width="fill_parent" android:layout_gravity="center_vertical" />
android:layout_height="wrap_content" <Button
android:layout_alignParentTop="true" /> android:id="@+id/status_exit_button"
android:layout_width="wrap_content"
<ProgressBar android:id="@+id/status_progress" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:text="Exit"
android:layout_height="wrap_content" android:layout_weight="0"
android:layout_below="@id/status_text" android:layout_alignParentLeft="true"
android:indeterminate="false" android:layout_gravity="center_vertical" />
android:indeterminateOnly="false" </LinearLayout>
style="?android:attr/progressBarStyleHorizontal" />
</RelativeLayout>
</RelativeLayout>

View file

@ -155,15 +155,6 @@ public class XashActivity extends Activity {
setFolderAsk( false ); // don't ask on next run setFolderAsk( false ); // don't ask on next run
Log.v(TAG, "Got new basedir from FPicker: " + newBaseDir ); Log.v(TAG, "Got new basedir from FPicker: " + newBaseDir );
} }
else if( requestCode == OPEN_DOCUMENT_TREE_RESULT )
{
Uri uri = resultData.getData();
if( uri != null )
{
getContentResolver().takePersistableUriPermission(uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION );
}
}
} }
} }
@ -235,34 +226,41 @@ public class XashActivity extends Activity {
@Override @Override
protected void onResume() { protected void onResume() {
Log.v(TAG, "onResume()"); Log.v(TAG, "onResume()");
if( mEngineReady )
nativeOnResume();
super.onResume(); super.onResume();
} }
@Override @Override
protected void onStop() { protected void onStop() {
Log.v(TAG, "onStop()"); Log.v(TAG, "onStop()");
/*
if( mEngineReady ) if( mEngineReady )
{ {
nativeSetPause(0);
// let engine properly exit, instead of killing it's thread // let engine properly exit, instead of killing it's thread
nativeOnStop(); nativeOnStop();
// wait for engine // wait for engine
mSurface.engineThreadWait(); mSurface.engineThreadWait();
} }
*/
super.onStop(); super.onStop();
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
Log.v(TAG, "onStop()"); Log.v(TAG, "onDestroy()");
if( mEngineReady ) if( mEngineReady )
{ {
nativeUnPause();
// let engine a chance to properly exit // let engine a chance to properly exit
nativeOnDestroy(); nativeOnDestroy();
//mSurface.engineThreadWait();
// wait until Xash will exit // wait until Xash will exit
mSurface.engineThreadJoin(); mSurface.engineThreadJoin();
} }
@ -274,6 +272,9 @@ public class XashActivity extends Activity {
@Override @Override
public void onWindowFocusChanged(boolean hasFocus) public void onWindowFocusChanged(boolean hasFocus)
{ {
if( mEngineReady )
nativeOnFocusChange();
super.onWindowFocusChanged(hasFocus); super.onWindowFocusChanged(hasFocus);
if( mImmersiveMode != null ) if( mImmersiveMode != null )
@ -418,6 +419,8 @@ public class XashActivity extends Activity {
mVibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE); mVibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
mHasVibrator = ( mVibrator != null ) && ( mVibrator.hasVibrator() ); mHasVibrator = ( mVibrator != null ) && ( mVibrator.hasVibrator() );
startService(new Intent(getBaseContext(), XashService.class));
mEngineReady = true; mEngineReady = true;
} }
@ -469,8 +472,10 @@ public class XashActivity extends Activity {
public static native void nativeString( String text ); public static native void nativeString( String text );
public static native void nativeSetPause(int pause); public static native void nativeSetPause(int pause);
public static native void nativeOnDestroy(); public static native void nativeOnDestroy();
public static native void nativeOnStop(); public static native void nativeOnResume();
public static native void nativeOnFocusChange();
public static native void nativeOnPause(); public static native void nativeOnPause();
public static native void nativeUnPause();
public static native void nativeHat(int id, byte hat, byte keycode, boolean down); public static native void nativeHat(int id, byte hat, byte keycode, boolean down);
public static native void nativeAxis(int id, byte axis, short value); public static native void nativeAxis(int id, byte axis, short value);
public static native void nativeJoyButton(int id, byte button, boolean down); public static native void nativeJoyButton(int id, byte button, boolean down);
@ -765,6 +770,7 @@ public class XashActivity extends Activity {
} }
/** /**
Simple nativeInit() runnable Simple nativeInit() runnable
*/ */

View file

@ -0,0 +1,99 @@
package in.celest.xash3d;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.opengles.GL10;
import javax.microedition.khronos.egl.*;
import android.app.*;
import android.content.*;
import android.view.*;
import android.os.*;
import android.util.*;
import android.graphics.*;
import android.text.method.*;
import android.text.*;
import android.media.*;
import android.hardware.*;
import android.content.*;
import android.widget.*;
import android.content.pm.*;
import android.net.Uri;
import android.provider.*;
import android.database.*;
import android.view.inputmethod.*;
import java.lang.*;
import java.util.List;
import java.security.MessageDigest;
import in.celest.xash3d.hl.R;
import in.celest.xash3d.hl.BuildConfig;
import in.celest.xash3d.XashConfig;
import in.celest.xash3d.JoystickHandler;
import in.celest.xash3d.CertCheck;
public class XashService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
public static class exitButtonListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
XashActivity.nativeUnPause();
XashActivity.nativeOnDestroy();
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("XashService", "Service Started");
Intent intent_ = new Intent(this, XashActivity.class);
intent_.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
final PendingIntent pendingIntent = PendingIntent.getActivity(
getApplicationContext(), 0, intent_, 0);
Notification notification = new Notification(R.drawable.ic_launcher,
"Xash3D", System.currentTimeMillis());
notification.contentView = new RemoteViews(getApplicationContext()
.getPackageName(), R.layout.notify);
notification.contentIntent = pendingIntent;
notification.flags = notification.flags
| Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE;
notification.contentView.setTextViewText(R.id.status_text, "Xash3D");
Intent exitIntent = new Intent(this, exitButtonListener.class);
PendingIntent pendingExitIntent = PendingIntent.getBroadcast(this, 0,
exitIntent, 0);
notification.contentView.setOnClickPendingIntent(R.id.status_exit_button, pendingExitIntent);
startForeground(100, notification);
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("XashService", "Service Destroyed");
}
@Override
public void onCreate()
{
}
@Override
public void onTaskRemoved(Intent rootIntent) {
Log.e("XashService", "OnTaskRemoved");
XashActivity.nativeUnPause();
XashActivity.nativeOnDestroy();
stopSelf();
}
};

View file

@ -77,13 +77,16 @@
android:screenOrientation="sensorLandscape" android:screenOrientation="sensorLandscape"
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize"
android:windowSoftInputMode="adjustResize" android:windowSoftInputMode="adjustResize"
android:label="@string/app_name"> android:label="@string/app_name"
android:launchMode="singleTask">
<intent-filter> <intent-filter>
<action android:name="in.celest.xash3d.START" /> <action android:name="in.celest.xash3d.START" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<receiver android:name="in.celest.xash3d.InstallReceiver"> <service android:name="in.celest.xash3d.XashService" android:stopWithTask="false"/>
<receiver android:name="in.celest.xash3d.XashService$exitButtonListener" />
<receiver android:name="in.celest.xash3d.InstallReceiver">
<intent-filter android:priority="100"> <intent-filter android:priority="100">
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.PACKAGE_ADDED" /> <action android:name="android.intent.action.PACKAGE_ADDED" />

43
unused/notify.xml Normal file
View file

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<ImageView android:id="@+id/status_icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_marginRight="10dp"/>
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="@id/status_icon">
<TextView android:id="@+id/status_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ProgressBar android:id="@+id/status_progress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/status_text"
android:indeterminate="false"
android:indeterminateOnly="false"
style="?android:attr/progressBarStyleHorizontal" />
</RelativeLayout>
</RelativeLayout>