[Android Q&A, Help & Troubleshooting] AmmarGitham:
Hi. Wanted some help for this Mod I've been working on from the past 3 days. Coming from the stock Touchwiz of my phone to the recently released CM10, I missed the feature of the Task Manager button which used to be there along with the recent apps.

So I tried to mod the SystemUI.apk of CM10 to include a similar functionality. I tried different approaches to do this. First I tried to compare the smali files from the Galaxy S II SystemUI.apk and make corresponding changes. But that didnt work. So I tried another approach.

What I did was exploited the Button xml attribute * android:onClick="methodname"* where the method with the name 'methodname' is called when the button is clicked.

So I modified the necessary layouts namely,"layout/status_bar_no_recent_apps.xml", "layout-land/status_bar_recent_panel.xml", "layout-port/status_bar_recent_panel.xml"

What I did was added the following code to those layout files :

<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="center"
android:onClick="openTaskManager"
android:text="Task Manager" />

As you can see on clicking the button, "openTaskManager" should be called.

Next I did was created the method openTaskManager in SystemUIService.smali which is located in SystemUI.apk\smali\com\android\systemui\

I added the following code at the end of the file :

.method public openTaskManager(Landroid/view/View;)V
.locals 5
.parameter "view"

.prologue
.line 99
:try_start_0

.line 100
new-instance v1, Landroid/content/Intent;

invoke-direct {v1}, Landroid/content/Intent;-><init>()V

.line 102
.local v1, intent:Landroid/content/Intent;
const-string v2, "android.intent.action.MAIN"

invoke-virtual {v1, v2}, Landroid/content/Intent;->setAction(Ljava/lang/String;)Landroid/content/Intent;

.line 105
const/high16 v2, 0x1000

invoke-virtual {v1, v2}, Landroid/content/Intent;->setFlags(I)Landroid/content/Intent;

.line 107
const-string v2, "com.sec.android.app.controlpanel"

const-string v3, "com.sec.android.app.controlpanel.activity.JobManagerActivity"

invoke-virtual {v1, v2, v3}, Landroid/content/Intent;->setClassName(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;

invoke-virtual {p0, v1}, Lcom/android/systemui/SystemUIService;->startActivity(Landroid/content/Intent;)V

.line 109
#iget-object v1, p0, Lcom/android/systemui/SystemUIService;->mRecentsPanel:Lcom/android/systemui/recent/RecentsPanelView;

#invoke-virtual {v1}, Lcom/android/systemui/recent/RecentsPanelView;->dismiss()V

#invoke-virtual {p0}, Lcom/android/systemui/SystemUIService;->onBackPressed()V

#const/4 v1, 0x0

#invoke-virtual {p0, v1, v1}, Lcom/android/systemui/recent/RecentsPanelView;->show(ZZ)V

:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

.line 112
.end local v1 #intent:Landroid/content/Intent;
:goto_0
return-void

.line 115
:catch_0
move-exception v0

.line 117
.local v0, e:Ljava/lang/Exception;
invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

goto :goto_0
.end method

Note that line numbers may depend on your smali file.

The method starts the activity of the Task Manager. The package name depends on which app you want to call. I'm using the TouchWiz Task Manager which can be found here.

All this took me almost 3 days to get working. Ok, so after doing the modifications and saving, I recompile the apk. Replaced the xml files and classes.dex from new apk to the old apk. Placed the SystemUI.apk in the system/app/ folder with permissions rw-r-r. Reboot the phone.

The mod WORKS but with a minor problem. The following screenshots shows the problem.

If you see the images properly. The Button is properly place(though it may need changes later), on clicking the button the Task Manager DOES OPEN. But the thing is it opens in the background with the recent apps still showing. Now that's where I need help.

After a lot of analyzing, I can think of 2 approaches to solve this problem.

1. Make TaskManager to start in foreground.

2. Somehow call the RecentPanelView's dismiss() method after starting the Task Manager. I tired this but couldn't make it work.

The RecentPanelView.smali is in SystemUI.apk\smali\com\android\systemui\recent\

So that's that. Would really appreciate it if anybody could help me out. As you can see it's almost done. I would really like to finish it perfectly.

If you have any doubts let me know.

My decompiled SystemUI.apk folder can be downloaded from here.

Thanks. :)