[XPOSED] [KK] [FIX] KitKat BUGS fixer

Search This thread

jamespat93

Senior Member
Dec 30, 2013
217
26
The fix is working great! Is there any way the same can be done for heavy applications so games dont restart?
 

darren1

Senior Member
Oct 31, 2010
387
124
============== FIXES ==============
1. https://android-review.googlesource.com/#/c/81970/
Head: All service returning START_STICKY do not restart after it is being killed.
Symptom: if you will start heavy application (game, video encode/decode viewing or bad application which occupy lot of resources), android can kill background service, for example Skype or WhatsApp, but will never restart services when resources become free. Need to start application again or even full phone restart.
Affected version: 4.4, 4.4.1, and 4.4.2.
[/CODE][/hide]

Will this fix NotificationListenerService not restarting after being killed? The bug is explained here.

https://code.google.com/p/android/issues/detail?id=62811
 

darren1

Senior Member
Oct 31, 2010
387
124
I have been running your module for around 36 hours on my Nexus 10 and so far the NotificationListenerService hasn't dropped. Have never had it drop on my Nexus 4 or Nexus 7, its because of the lower ram. Hopefully fixed, thanks.
 

darren1

Senior Member
Oct 31, 2010
387
124
Could you look at altering the level that stock KitKat starts giving Insufficient Storage errors? Seems there is a 500mb floor limit which is supposedly kept aside for the system to run. Had this problem with a 8GB Nexus 4 running 4.4.2. Won't let me install any more apps sideloading or via Google Play.
 

Dovidhalevi

Senior Member
Jun 26, 2012
2,728
1,172
I am running a 4.4.4 Omni. Should not need this module.

However, recent versions of Titanium have been kicking out background processes while doing schedule backup jobs. The processes do not return, even after a reboot, unless I manually restart their parent apps.

What is to be done? ROM has an app permissions settings but the appropriate one is not shown.
 

Dovidhalevi

Senior Member
Jun 26, 2012
2,728
1,172
Should not have been needed on my 4.4.4 Omni-based ROM but se la vie. Worked OK. Only Tasker failed to persist/restart.

Better solution than KeepRunning app since this brings up the UI of processes it relaunches and ... it can be knocked out as well so not work at all.

Tasker may in fact be unique in that while is launches on startup just fine, it seems to require exercising it UI to relaunch.
 

Kzyw

Senior Member
Sep 28, 2014
461
79
Thanks thanks thanks!!
This mod is amazing :)k
 
Last edited:

PamelaGirl

Senior Member
Jul 10, 2011
865
101
Hello All,
I am having issues with 4.4.2 where if I am in an app it simply returns me to the home screen. I hoped this would work but it caused my device to randomly reboot which isnt good :(
 

PamelaGirl

Senior Member
Jul 10, 2011
865
101
I switched my mobile network from LTE to 3G and so far my device appears to be more stable.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 16
    ============== FIXES ==============
    1. https://android-review.googlesource.com/#/c/81970/
    Head: All service returning START_STICKY do not restart after it is being killed.
    Symptom: if you will start heavy application (game, video encode/decode viewing or bad application which occupy lot of resources), android can kill background service, for example Skype or WhatsApp, but will never restart services when resources become free. Need to start application again or even full phone restart.
    Affected version: 4.4, 4.4.1, and 4.4.2.

    2. https://android-review.googlesource.com/#/c/98918/
    Head: If all activities of a given stack were finishing, no activity was marked as front-of-task.
    Symptom: if recents has several apps running, clicking BACK button fast to close current activity will bring to front another activity.
    Affected version: 4.4.*

    Mod does not have any settings activity. Just enabled it in Xposed menu.

    INSTRUCTIONS:
    if you get boot-loop
    1. after phone start go to Xposed and immediately uncheck module.
    2. issue command adb logcat > logcat.txt
    3. phone will reboot again soon
    4. upload logcat somewhere and post link here.
    5. After next restart mod will be disabled.
    6. Wait when I will publish correction.

    Can be downloaded through Xposed Installer or here: http://repo.xposed.info/module/kz.virtex.android.issue63793fix

    Source code:
    Code:
    package kz.virtex.android.issue63793fix;
    
    import android.content.pm.ApplicationInfo;
    import android.os.SystemClock;
    import android.util.EventLog;
    import android.util.Slog;
    
    import com.android.server.am.EventLogTags;
    
    import de.robv.android.xposed.IXposedHookZygoteInit;
    import de.robv.android.xposed.XC_MethodReplacement;
    import de.robv.android.xposed.XposedHelpers;
    
    public class XMain implements IXposedHookZygoteInit
    {
    	@Override
    	public void initZygote(StartupParam startupParam) throws Throwable
    	{
    		final Class<?> ActiveServices = XposedHelpers.findClass("com.android.server.am.ActiveServices", null);
    
    		XposedHelpers.findAndHookMethod(ActiveServices, "killServicesLocked", "com.android.server.am.ProcessRecord", "boolean", new XC_MethodReplacement()
    		{
    			@Override
    			protected Object replaceHookedMethod(MethodHookParam param) throws Throwable
    			{
    				Boolean DEBUG_SERVICE = (Boolean) XposedHelpers.getStaticBooleanField(ActiveServices, "DEBUG_SERVICE");
    				String TAG = (String) XposedHelpers.getStaticObjectField(ActiveServices, "TAG");
    
    				Object app = param.args[0];
    				boolean allowRestart = (Boolean) param.args[1];
    				Object services = XposedHelpers.getObjectField(app, "services");
    				int size = (Integer) XposedHelpers.callMethod(services, "size");
    
    				// First clear app state from services.
    				for (int i = size - 1; i >= 0; i--) {
    					Object sr = XposedHelpers.callMethod(services, "valueAt", i);
    					Object stats = XposedHelpers.getObjectField(sr, "stats");
    					synchronized (XposedHelpers.callMethod(stats, "getBatteryStats")) {
    						XposedHelpers.callMethod(stats, "stopLaunchedLocked");
    					}
    					Object sr_app = XposedHelpers.getObjectField(sr, "app");
    					Boolean persistent = XposedHelpers.getBooleanField(sr_app, "persistent");
    					Boolean stopIfKilled = XposedHelpers.getBooleanField(sr, "stopIfKilled");
    
    					if (sr_app != null && !persistent && stopIfKilled) {
    						Object sr_app_services = XposedHelpers.getObjectField(sr_app, "services");
    						XposedHelpers.callMethod(sr_app_services, "remove", sr);
    					}
    					XposedHelpers.setObjectField(sr, "app", null);
    					XposedHelpers.setObjectField(sr, "isolatedProc", null);
    					XposedHelpers.setObjectField(sr, "executeNesting", 0);
    					XposedHelpers.callMethod(sr, "forceClearTracker");
    
    					Object mDestroyingServices = XposedHelpers.getObjectField(param.thisObject, "mDestroyingServices");
    					Boolean check = (Boolean) XposedHelpers.callMethod(mDestroyingServices, "remove", sr);
    					if (check) {
    						if (DEBUG_SERVICE)
    							Slog.v(TAG, "killServices remove destroying " + sr);
    					}
    
    					Object bindings = XposedHelpers.getObjectField(sr, "bindings");
    					final int numClients = (Integer) XposedHelpers.callMethod(bindings, "size");
    					for (int bindingi = numClients - 1; bindingi >= 0; bindingi--) {
    						Object IntentBindRecord = XposedHelpers.callMethod(bindings, "valueAt", bindingi);
    						if (DEBUG_SERVICE)
    							Slog.v(TAG, "Killing binding " + IntentBindRecord + ": shouldUnbind=" + XposedHelpers.getObjectField(IntentBindRecord, "hasBound"));
    
    						XposedHelpers.setObjectField(IntentBindRecord, "binder", null);
    						XposedHelpers.setObjectField(IntentBindRecord, "requested", false);
    						XposedHelpers.setObjectField(IntentBindRecord, "received", false);
    						XposedHelpers.setObjectField(IntentBindRecord, "hasBound", false);
    					}
    				}
    
    				// Clean up any connections this application has to other
    				// services.
    				Object connections = XposedHelpers.getObjectField(app, "connections");
    				size = (Integer) XposedHelpers.callMethod(connections, "size");
    				for (int i = size - 1; i >= 0; i--) {
    					Object ConnectionRecord = XposedHelpers.callMethod(connections, "valueAt", i);
    
    					XposedHelpers.callMethod(param.thisObject, "removeConnectionLocked", ConnectionRecord, app, null);
    				}
    				XposedHelpers.callMethod(connections, "clear");
    
    				Object smap = XposedHelpers.callMethod(param.thisObject, "getServiceMap", XposedHelpers.getObjectField(app, "userId"));
    
    				// Now do remaining service cleanup.
    				services = XposedHelpers.getObjectField(app, "services");
    				size = (Integer) XposedHelpers.callMethod(services, "size");
    				for (int i = size - 1; i >= 0; i--) {
    					Object sr = XposedHelpers.callMethod(services, "valueAt", i);
    					Object mServicesByName = XposedHelpers.getObjectField(smap, "mServicesByName");
    					if (XposedHelpers.callMethod(mServicesByName, "get", XposedHelpers.getObjectField(sr, "name")) != sr) {
    						Object cur = XposedHelpers.callMethod(mServicesByName, "get", XposedHelpers.getObjectField(sr, "name"));
    						Slog.wtf(TAG, "Service " + sr + " in process " + app + " not same as in map: " + cur);
    						Object app_services = XposedHelpers.getObjectField(app, "services");
    						XposedHelpers.callMethod(app_services, "removeAt", i);
    						continue;
    					}
    					// Any services running in the application may need to be
    					// placed back in the pending list.
    					Object serviceInfo = XposedHelpers.getObjectField(sr, "serviceInfo");
    					Object applicationInfo = XposedHelpers.getObjectField(serviceInfo, "applicationInfo");
    					if (allowRestart && XposedHelpers.getIntField(sr, "crashCount") >= 2 && (XposedHelpers.getIntField(applicationInfo, "flags") & ApplicationInfo.FLAG_PERSISTENT) == 0) {
    						Slog.w(TAG, "Service crashed " + XposedHelpers.getIntField(sr, "crashCount") + " times, stopping: " + sr);
    						EventLog.writeEvent(EventLogTags.AM_SERVICE_CRASHED_TOO_MUCH, XposedHelpers.getObjectField(sr, "userId"), XposedHelpers.getObjectField(sr, "crashCount"), XposedHelpers.getObjectField(sr, "shortName"), XposedHelpers.getObjectField(app, "pid"));
    						XposedHelpers.callMethod(param.thisObject, "bringDownServiceLocked", sr);
    					} else if (!allowRestart) {
    						XposedHelpers.callMethod(param.thisObject, "bringDownServiceLocked", sr);
    					} else {
    						boolean canceled = (Boolean) XposedHelpers.callMethod(param.thisObject, "scheduleServiceRestartLocked", sr, true);
    						// Should the service remain running? Note that in the
    						// extreme case of so many attempts to deliver a command
    						// that it failed we also will stop it here.
    						if (XposedHelpers.getBooleanField(sr, "startRequested") && (XposedHelpers.getBooleanField(sr, "stopIfKilled") || canceled)) {
    							Object pendingStarts = XposedHelpers.getObjectField(sr, "pendingStarts");
    							if ((Integer) XposedHelpers.callMethod(pendingStarts, "size") == 0) {
    								XposedHelpers.setBooleanField(sr, "startRequested", false);
    								if (XposedHelpers.getObjectField(sr, "tracker") != null) {
    									Object tracker = XposedHelpers.getObjectField(sr, "tracker");
    									Object mAm = XposedHelpers.getObjectField(param.thisObject, "mAm");
    									Object mProcessStats = XposedHelpers.getObjectField(mAm, "mProcessStats");
    									XposedHelpers.callMethod(tracker, "setStarted", false, XposedHelpers.callMethod(mProcessStats, "getMemFactorLocked"), SystemClock.uptimeMillis());
    								}
    								if (!XposedHelpers.getBooleanField(sr, "hasAutoCreateConnections")) {
    									// Whoops, no reason to restart!
    									XposedHelpers.callMethod(param.thisObject, "bringDownServiceLocked", sr);
    								}
    							}
    						}
    					}
    				}
    
    				if (!allowRestart) {
    					Object app_services = XposedHelpers.getObjectField(app, "services");
    					XposedHelpers.callMethod(app_services, "clear");
    
    					// Make sure there are no more restarting services for this
    					// process.
    					Object mRestartingServices = XposedHelpers.getObjectField(param.thisObject, "mRestartingServices");
    
    					for (int i = (Integer) XposedHelpers.callMethod(mRestartingServices, "size") - 1; i >= 0; i--) {
    						Object r = XposedHelpers.callMethod(mRestartingServices, "get", i);
    						String processName = (String) XposedHelpers.getObjectField(r, "processName");
    						Object serviceInfo = XposedHelpers.getObjectField(r, "serviceInfo");
    						Object applicationInfo = XposedHelpers.getObjectField(serviceInfo, "applicationInfo");
    						Object info = XposedHelpers.getObjectField(app, "info");
    						if (processName.equals((String) XposedHelpers.getObjectField(app, "processName")) && XposedHelpers.getIntField(applicationInfo, "uid") == XposedHelpers.getIntField(info, "uid")) {
    							XposedHelpers.callMethod(mRestartingServices, "remove", i);
    							XposedHelpers.callMethod(param.thisObject, "clearRestartingIfNeededLocked", r);
    						}
    					}
    					Object mPendingServices = XposedHelpers.getObjectField(param.thisObject, "mPendingServices");
    					for (int i = (Integer) XposedHelpers.callMethod(mPendingServices, "size") - 1; i >= 0; i--) {
    						Object r = XposedHelpers.callMethod(mPendingServices, "get", i);
    
    						String processName = (String) XposedHelpers.getObjectField(r, "processName");
    						Object serviceInfo = XposedHelpers.getObjectField(r, "serviceInfo");
    						Object applicationInfo = XposedHelpers.getObjectField(serviceInfo, "applicationInfo");
    						Object info = XposedHelpers.getObjectField(app, "info");
    						if (processName.equals((String) XposedHelpers.getObjectField(app, "processName")) && XposedHelpers.getIntField(applicationInfo, "uid") == XposedHelpers.getIntField(info, "uid")) {
    							XposedHelpers.callMethod(mPendingServices, "remove", i);
    						}
    					}
    				}
    				// Make sure we have no more records on the stopping list.
    				Object mDestroyingServices = XposedHelpers.getObjectField(param.thisObject, "mDestroyingServices");
    				int i = (Integer) XposedHelpers.callMethod(mDestroyingServices, "size");
    				while (i > 0) {
    					i--;
    					Object sr = XposedHelpers.callMethod(mDestroyingServices, "get", i);
    					if (XposedHelpers.getObjectField(sr, "app") == app) {
    						XposedHelpers.callMethod(sr, "forceClearTracker");
    						XposedHelpers.callMethod(mDestroyingServices, "remove", i);
    						if (DEBUG_SERVICE)
    							Slog.v(TAG, "killServices remove destroying " + sr);
    					}
    				}
    				Object executingServices = XposedHelpers.getObjectField(app, "executingServices");
    				XposedHelpers.callMethod(executingServices, "clear");
    
    				return null;
    			}
    		});
    	}
    }
    2
    Awesome work!
    Could you create a module for this fix also? https://android-review.googlesource.com/#/c/98918 ;)

    what if we will combine all bugs fixes in one mod?
    1
    1
    Is HTC Sense 5.5 with Android 4.4.2 also affected?

    yes
    1
    Ooh, cool, gotcha!
    Thanks!

    on HTC 4.4.2 this bug already fixed so can't check by myself

    please try with Google Music.

    if you will get boot-loop - see OP