Skip to content

Commit

Permalink
CHG: [droid] Split backend (service) and frontend (app)
Browse files Browse the repository at this point in the history
  • Loading branch information
koying committed Jan 26, 2018
1 parent 42c0394 commit e8818ab
Show file tree
Hide file tree
Showing 30 changed files with 778 additions and 342 deletions.
2 changes: 1 addition & 1 deletion project/cmake/scripts/android/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ set(package_files strings.xml
src/content/XBMCYTDLContentProvider.java
src/XBMCSettingsContentObserver.java
src/XBMCMainView.java
src/KeepAliveService.java
src/Service.java
)
foreach(file IN LISTS package_files)
configure_file(${CORE_SOURCE_DIR}/tools/android/packaging/xbmc/${file}.in
Expand Down
1 change: 1 addition & 0 deletions project/cmake/treedata/android/subdirs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ xbmc/windowing/egl windowing/egl
xbmc/platform/posix posix
xbmc/platform/android android
xbmc/platform/android/activity android_activity
xbmc/platform/android/service android_service
xbmc/platform/android/bionic_supplement android_bionicsupplement
2 changes: 1 addition & 1 deletion tools/android/packaging/xbmc/AndroidManifest.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE" />
<service
android:name=".KeepAliveService"
android:name=".Service"
android:enabled="true"
android:exported="true"/>
</application>
Expand Down
71 changes: 71 additions & 0 deletions tools/android/packaging/xbmc/src/Service.java.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package @APP_PACKAGE@;

import android.app.Notification;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.IBinder;

public class Service extends android.app.Service
{
native boolean _launchApplication();

static private Boolean m_isStarted = false;
public static Boolean isStarted()
{
return m_isStarted;
}

public Service()
{
}

@Override
public void onCreate()
{
System.loadLibrary("@APP_NAME_LC@");
super.onCreate();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
if (!m_isStarted)
m_isStarted =_launchApplication();
if (m_isStarted)
{
Intent i = new Intent("@APP_PACKAGE@.SERVICE_STARTED");
sendBroadcast(i);
}

Bitmap icon = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_recommendation_80dp);

Notification.Builder builder = new Notification.Builder(this)
.setContentTitle(getString(R.string.app_name))
.setContentText("@APP_NAME@ is running...")
.setSmallIcon(R.drawable.notif_icon)
.setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
;

Notification notification = builder.build();
startForeground(1, notification);
return START_STICKY;
}

@Override
public void onDestroy()
{
Intent i = new Intent("@APP_PACKAGE@.SERVICE_STOPPED");
sendBroadcast(i);

super.onDestroy();
}

@Override
public IBinder onBind(Intent intent)
{
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not implemented");
}
}
76 changes: 67 additions & 9 deletions tools/android/packaging/xbmc/src/Splash.java.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,22 @@ package @APP_PACKAGE@;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.System;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Properties;
import java.util.Enumeration;
import java.util.ArrayList;

import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -63,6 +58,8 @@ public class Splash extends Activity
private static final int StorageChecked = 8;
private static final int DownloadingObb = 90;
private static final int DownloadObbDone = 91;
private static final int StartingService = 97;
private static final int WaitingService = 98;
private static final int StartingXBMC = 99;

private static final String TAG = "@APP_NAME@";
Expand All @@ -85,6 +82,8 @@ public class Splash extends Activity

private BroadcastReceiver mExternalStorageReceiver = null;
private boolean mExternalStorageChecked = false;
private BroadcastReceiver mServiceReceiver = null;
private boolean mServiceChecked = false;
private boolean mCachingDone = false;
private boolean mInstallLibs = false;

Expand Down Expand Up @@ -123,7 +122,7 @@ public class Splash extends Activity
break;
case CachingDone:
mSplash.mCachingDone = true;
sendEmptyMessage(StartingXBMC);
sendEmptyMessage(StartingService);
break;
case WaitingStorageChecked:
mSplash.mTextView.setText("Waiting for external storage...");
Expand All @@ -134,7 +133,7 @@ public class Splash extends Activity
mExternalStorageChecked = true;
mSplash.stopWatchingExternalStorage();
if (mSplash.mCachingDone)
sendEmptyMessage(StartingXBMC);
sendEmptyMessage(StartingService);
else
{
SetupEnvironment();
Expand All @@ -147,16 +146,32 @@ public class Splash extends Activity
mState = CachingDone;
mCachingDone = true;

sendEmptyMessage(StartingXBMC);
sendEmptyMessage(StartingService);
}
else
{
new FillCache(mSplash).execute();
}
}

break;
case StartingService:
if (mServiceChecked)
sendEmptyMessage(StartingXBMC);
else
{
mSplash.mTextView.setText("Starting Service...");
mSplash.mProgress.setVisibility(View.INVISIBLE);
mSplash.startService();
sendEmptyMessage(WaitingService);
}
break;
case WaitingService:
mSplash.mTextView.setText("Waiting for Service...");
mSplash.mProgress.setVisibility(View.INVISIBLE);
break;
case StartingXBMC:
stopWatchingService();
mSplash.mTextView.setText("Starting @APP_NAME@...");
mSplash.mProgress.setVisibility(View.INVISIBLE);
mSplash.startXBMC();
Expand Down Expand Up @@ -739,13 +754,53 @@ public class Splash extends Activity
unregisterReceiver(mExternalStorageReceiver);
}

void updateServiceState()
{
mServiceChecked = Service.isStarted();
if (!mServiceChecked)
mStateMachine.sendEmptyMessage(StartingService);
else
mStateMachine.sendEmptyMessage(StartingXBMC);
}

void startWatchingService()
{
mServiceReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
updateServiceState();
}
};
IntentFilter filter = new IntentFilter();
filter.addAction("@APP_PACKAGE@.SERVICE_STARTED");
registerReceiver(mServiceReceiver, filter);
}

void stopWatchingService()
{
if (mServiceReceiver != null)
unregisterReceiver(mServiceReceiver);
}

protected void startService()
{
if (!Service.isStarted())
{
startWatchingService();
startService(new Intent(this, Service.class));
}
}

protected void startXBMC()
{
// Run @APP_NAME@
Intent intent = getIntent();
intent.setClass(this, @APP_PACKAGE@.Main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
startActivity(intent);

finish();
}

Expand Down Expand Up @@ -845,6 +900,9 @@ public class Splash extends Activity
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
mExternalStorageChecked = true;

if (Service.isStarted())
mServiceChecked = true;

if (mState != InError && mExternalStorageChecked)
{
mState = ChecksDone;
Expand All @@ -859,7 +917,7 @@ public class Splash extends Activity
}
}

if ((mState != DownloadingObb && mState != InError) && mCachingDone && mExternalStorageChecked)
if ((mState != DownloadingObb && mState != InError) && mCachingDone && mExternalStorageChecked && mServiceChecked)
{
startXBMC();
return;
Expand Down
2 changes: 1 addition & 1 deletion tools/depends/target/libandroidjni/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DEPS= ../../Makefile.include Makefile

# lib name, version
LIBNAME=libandroidjni
VERSION=29aae460c8144d939d5f0bf16af97f9ede6b12fb
VERSION=3fadaf0daa4b7b99337a6c41bce54e7db783b5d7
SOURCE=archive
ARCHIVE=$(VERSION).tar.gz
GIT_BASE_URL=https://github.com/koying
Expand Down
Loading

0 comments on commit e8818ab

Please sign in to comment.