KillerService: ensure all the services are killed
This commit is contained in:
parent
9d545a7196
commit
7ddb4a8dd2
|
@ -9,6 +9,7 @@ import net.typeblog.shelter.services.ILoadIconCallback;
|
|||
import net.typeblog.shelter.util.ApplicationInfoWrapper;
|
||||
|
||||
interface IShelterService {
|
||||
void ping();
|
||||
void stopShelterService(boolean kill);
|
||||
void getApps(IGetAppsCallback callback);
|
||||
void loadIcon(in ApplicationInfoWrapper info, ILoadIconCallback callback);
|
||||
|
|
|
@ -40,6 +40,12 @@ public class KillerService extends Service {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
killEverything();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTaskRemoved(Intent rootIntent) {
|
||||
super.onTaskRemoved(rootIntent);
|
||||
|
|
|
@ -35,6 +35,11 @@ public class ShelterService extends Service {
|
|||
private PackageManager mPackageManager = null;
|
||||
private ComponentName mAdminComponent = null;
|
||||
private IShelterService.Stub mBinder = new IShelterService.Stub() {
|
||||
@Override
|
||||
public void ping() {
|
||||
// Do nothing, just let the other side know we are alive
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopShelterService(boolean kill) {
|
||||
// dirty: just wait for some time and kill this service itself
|
||||
|
|
|
@ -189,6 +189,35 @@ public class MainActivity extends AppCompatActivity {
|
|||
return isRemote ? mServiceMain : mServiceWork;
|
||||
}
|
||||
|
||||
boolean servicesAlive() {
|
||||
try {
|
||||
mServiceMain.ping();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
mServiceWork.ping();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (mServiceMain != null && mServiceWork != null && !servicesAlive()) {
|
||||
// Restart the activity if the services are no longer alive
|
||||
// This might be caused by KillerService being destroyed and
|
||||
// bringing all the other services with it
|
||||
Intent intent = getIntent();
|
||||
finish();
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
|
Loading…
Reference in a new issue