Post Reply

[HOWTO]Implement Swipe to Remove Notification

OP hansip87

6th February 2012, 07:31 AM   |  #1  
hansip87's Avatar
OP Senior Member
Flag Jakarta
Thanks Meter: 1,840
 
2,553 posts
Join Date:Joined: Jan 2011
Donate to Me
More
Hi there, I want to share this tutorial for implementing Swipe-to-Remove Notification feature found in CyanogenMod to stock ROM (Gingerbread or earlier ROM). Sure it will be available on ICS but for those who like to add one to their custom ROM here's how Currently i don't know to whom should i give credit to, if anybody knows please post below and i'll add the link for the original modder. Thanks to:
1. like-p for help showing me what files to be edited
2. LeoMar75 for some info on how to control Stub switch case

This mod is based on Sony Ericsson Xperia Ray, so take care when adding to another device, some code might be different though so no direct copy paste, please learn some of the line first.

PS: For Froyo mod, please follow Jason-EX here

Requirement:
1. decompiled Framework.jar with Baksmali manager
2. decompiled SystemUI.apk with APK Multi Tool
3. Some Basic understanding about editing xml file and smali code.
4. WinMerge or other comparison tool (to better editing and comparing with my sample file)
5. Backup the framework.jar and SystemUI.apk first!

Files to be edited:

in SystemUI.apk
  1. res/anim/
  2. res/layout/status_bar_latest_event.xml
  3. res/values/public.xml
  4. smali/com/android/systemui/statusbar/LatestItemContainer$1.smali
  5. smali/com/android/systemui/statusbar/LatestItemContainer.smali
  6. smali/com/android/systemui/statusbar/StatusBarService$7.smali (or depends on your numbering, could be $8 or larger)
  7. smali/com/android/systemui/statusbar/StatusBarService.smali

in framework.jar:
  1. smali/com/android/internal/statusbar/IStatusBarService$Stub$Proxy.smali
  2. smali/com/android/internal/statusbar/IStatusBarService$Stub.smali
  3. smali/com/android/internal/statusbar/IStatusBarService.smali

UPDATE: This is the additional guide for other device when editing StatusBarService.smali. See here:
1. HTC based
2. Samsung based

Alright, let's mod one by one

1. Editing SystemUI.apk
1.1 Editing res/anim
We are registering anim object here, so swipe animation can be done.
  1. Create folder anim (if not exists yet) inside /res folder
  2. Create 2 file named slide_out_left_basic.xml and slide_out_right_basic.xml inside res/anim folder
  3. for slide_out_left_basic.xml, edit the file and fill with this
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <translate android:duration="@android:integer/config_mediumAnimTime" android:fromXDelta="0.0" android:toXDelta="-100.0%p"
      xmlns:android="http://schemas.android.com/apk/res/android" />
  4. for slide_out_right_basic.xml, edit the file and fill with this
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <translate android:duration="@android:integer/config_mediumAnimTime" android:fromXDelta="0.0" android:toXDelta="100.0%p"
      xmlns:android="http://schemas.android.com/apk/res/android" />
  5. Save both

Update: Mirko ddd (&shoman94 have pointed that out before but i have no idea where to change, sorry mate) have given me the tip to improve the gesture. read his post here Thanks mate, both of you!

1.2 Editing res/layout/status_bar_latest_event.xml
We are replacing LinearLayout object used in StatusBar with LatestItemContainer here, so notification can be removed. We handle the Styling first by editing this .xml first. Here are the steps:
  1. Change the code from Original code to this (change the bold one)
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <com.android.systemui.statusbar.LatestItemContainer android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="65.0sp"
      xmlns:android="http://schemas.android.com/apk/res/android">
        <com.android.systemui.statusbar.LatestItemView android:id="@id/content" android:background="@android:drawable/status_bar_item_background" android:paddingRight="6.0sp" android:focusable="true" android:clickable="true" android:layout_width="fill_parent" android:layout_height="64.0sp" android:shadowColor="#ff000000" android:shadowDx="0.0" android:shadowDy="1.0" android:shadowRadius="2.0" />
        <View android:background="@drawable/divider_horizontal_light_opaque" android:layout_width="fill_parent" android:layout_height="wrap_content" />
    </com.android.systemui.statusbar.LatestItemContainer>
  2. Save

1.3 Editing res/values/public.xml
This one is for registering anim file that we made on step 1.1 to be available publicly and to be recognized in .smali program. Here are the steps:
  1. Recompile your apk after putting anim file into /res folder
  2. Decompile again the resulting apk
  3. Inside /res/values/public.xml, you'll found something like this:
    Code:
    <resources>
         .
         .
         .
         
        <public type="anim" name="slide_out_left_basic" id="0x7f0c0000" />
        <public type="anim" name="slide_out_right_basic" id="0x7f0c0001" />
         
    </resources>
  4. Remember the ID for both anim lines. This will be applied again on the step 1.4

1.4 Adding smali/com/android/systemui/statusbar/LatestItemContainer$1.smali and smali/com/android/systemui/statusbar/LatestItemContainer.smali
This is the class of LatestItemContainer that will be used to handle the notification list instead of LatestItemView. Here are the steps:
  • Please download from the attachment
  • insert the files inside to mentioned folder above
  • Inside LatestItemContainer$1.smali, there's an id that references the anim from step1.2. please edit it if you have different id for anim left or anim from previous step.
    Code:
        .line 53
        :cond_0
        const/high16 v1, 0x7f0c
    and
    Code:
        .line 51
        const v1, 0x7f0c0001

1.5 Add smali/com/android/systemui/statusbar/StatusBarService$7.smali (or depends on your existing framework numbering, could be $8 or larger)
This is additional function for StatusBarService to handle onClearNotification function. Here are the steps:
  1. Extract the StatusBarService$7.smali from attachment
  2. If StatusBarService$7.smali does not exist before, just place it inside, if not, skip this step.
  3. If StatusBarService$7.smali exists, Please rename the file to StatusBarService$8.smali (or whatever higher number that is unused) and rename all the line inside the file from
    Code:
    StatusBarService$7
    to
    Code:
    StatusBarService$8

1.6 Edit smali/com/android/systemui/statusbar/StatusBarService.smali
UPDATE: This is the additional guide for other device when editing StatusBarService.smali. See here:
1. Generic java readout
2. HTC based
3. Samsung based

This is the file that generate NotificationView. Please take care of the changes here more carefully because there might be some differences between vendors in this file. Here are the steps:
  1. Open StatusBarService.smali and find this function
    Code:
    .method makeNotificationView(Lcom/android/internal/statusbar/StatusBarNotification;Landroid/view/ViewGroup;)[Landroid/view/View;
  2. Find this code in the makeNotificationView function body:
    Code:
        invoke-virtual {v0, v1, v2, v3}, Landroid/view/LayoutInflater;->inflate(ILandroid/view/ViewGroup;Z)Landroid/view/View;
    
        move-result-object v18
    
        const v4, 0x7f0b0014
    
        move-object/from16 v0, v18
    
        move v1, v4
    
        invoke-virtual {v0, v1}, Landroid/view/View;->findViewById(I)Landroid/view/View;
    
        move-result-object v10
  3. Insert the bold code below between the existing code:
    Code:
        invoke-virtual {v0, v1, v2, v3}, Landroid/view/LayoutInflater;->inflate(ILandroid/view/ViewGroup;Z)Landroid/view/View;
    
        move-result-object v18
    
        check-cast v18, Lcom/android/systemui/statusbar/LatestItemContainer;
    
        .line 516
        .local v18, row:Lcom/android/systemui/statusbar/LatestItemContainer;
        move-object/from16 v0, v16
    
        iget v0, v0, Landroid/app/Notification;->flags:I
    
        move v4, v0
    
        and-int/lit8 v4, v4, 0x2
    
        if-nez v4, :cond_swno
    
        move-object/from16 v0, v16
    
        iget v0, v0, Landroid/app/Notification;->flags:I
    
        move v4, v0
    
        and-int/lit8 v4, v4, 0x20
    
        if-nez v4, :cond_swno
    
        new-instance v4, Lcom/android/systemui/statusbar/StatusBarService$7;
    
        move-object v0, v4
    
        move-object/from16 v1, p0
    
        move-object/from16 v2, p1
    
        invoke-direct {v0, v1, v2}, Lcom/android/systemui/statusbar/StatusBarService$7;-><init>(Lcom/android/systemui/statusbar/StatusBarService;Lcom/android/internal/statusbar/StatusBarNotification;)V
    
        move-object/from16 v0, v18
    
        move-object v1, v4
    
        invoke-virtual {v0, v1}, Lcom/android/systemui/statusbar/LatestItemContainer;->setOnSwipeCallback(Ljava/lang/Runnable;)V
    
        .line 735
        :cond_swno
        
        const v4, 0x7f0b0014
    
        move-object/from16 v0, v18
    
        move v1, v4
    
        invoke-virtual {v0, v1}, Lcom/android/systemui/statusbar/LatestItemContainer;->findViewById(I)Landroid/view/View;
    
        move-result-object v10
    Once again, change
    Code:
    StatusBarService$7
    to
    Code:
    StatusBarService$8
    line if you happened to have StatusBarService$8.smali as the result of renaming on the previous step.

    IMPORTANT LOGIC TO BE UNDERSTOOD: This step tells the function to:
    1. cast the already made View Object to LatestItemContainer instead of using LatestView class.
    2. Filter if the Notification is removable or not
    3. the LatestItemContainer object (v18) is assigned with onSwipeCallback(new StatusBarService$7)
  4. Change the following (still on the same function body):
    Code:
        move v1, v4
    
        invoke-virtual {v0, v1}, Landroid/view/View;->setDrawingCacheEnabled(Z)V
    
        .line 542
        const/4 v4, 0x3
    to
    Code:
        move v1, v4
    
        invoke-virtual {v0, v1}, Lcom/android/systemui/statusbar/LatestItemContainer;->setDrawingCacheEnabled(Z)V
    
        .line 542
        const/4 v4, 0x3

Please note:
  • StatusBarService.smali might be different between vendor, so please adapt with your .smali to implement the above coding.


2. Editing framework.jar
2.1 editing smali/com/android/internal/statusbar/IStatusBarService$Stub.smali
Here are the steps:
  1. Add this code on variable declaration part inside the file
    Code:
    .field static final TRANSACTION_onClearAllNotifications:I = 0xb
    
    .field static final TRANSACTION_onNotificationClear:I = 0xc
    
    .field static final TRANSACTION_onNotificationClick:I = 0x9
    
    .field static final TRANSACTION_onNotificationError:I = 0xa
  2. If the 0xc is already used on another static value, you must change it so it remains unique.
  3. Find this code:
    Code:
    .method public onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
        .registers 14
        .parameter "code"
        .parameter "data"
        .parameter "reply"
        .parameter "flags"
        .annotation system Ldalvik/annotation/Throws;
            value = {
                Landroid/os/RemoteException;
            }
        .end annotation
    
        .prologue
        .line 39
        sparse-switch p1, :sswitch_data_124
    change to
    Code:
    .method public onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
        .registers 14
        .parameter "code"
        .parameter "data"
        .parameter "reply"
        .parameter "flags"
        .annotation system Ldalvik/annotation/Throws;
            value = {
                Landroid/os/RemoteException;
            }
        .end annotation
    
        .prologue
        .line 39
        sparse-switch p1, :sswitch_data_13e
  4. Insert/replace this code (it is at the end of the file):
    Code:
        .line 176
        const/4 v0, 0x1
    
        goto/16 :goto_7
    
        .line 39
        :sswitch_data_124
        .sparse-switch
            0x1 -> :sswitch_f
            0x2 -> :sswitch_1c
            0x3 -> :sswitch_29
            0x4 -> :sswitch_42
            0x5 -> :sswitch_5f
            0x6 -> :sswitch_7b
            0x7 -> :sswitch_8d
            0x8 -> :sswitch_c7
            0x9 -> :sswitch_d5
            0xa -> :sswitch_ef
            0xb -> :sswitch_116
            0x5f4e5446 -> :sswitch_8
        .end sparse-switch
    to
    Code:
    
        .line 176
        const/4 v0, 0x1
    
        goto/16 :goto_7
    
        .end local v1           #_arg0:Ljava/lang/String;
        .end local v2           #_arg1:Ljava/lang/String;
        .end local v3           #_arg2:I
        :sswitch_124
        const-string v0, "com.android.internal.statusbar.IStatusBarService"
    
        invoke-virtual {p2, v0}, Landroid/os/Parcel;->enforceInterface(Ljava/lang/String;)V
    
        .line 177
        invoke-virtual {p2}, Landroid/os/Parcel;->readString()Ljava/lang/String;
    
        move-result-object v1
    
        .line 178
        .restart local v1       #_arg0:Ljava/lang/String;
        invoke-virtual {p2}, Landroid/os/Parcel;->readString()Ljava/lang/String;
    
        move-result-object v2
    
        .line 179
        .restart local v2       #_arg1:Ljava/lang/String;
        invoke-virtual {p2}, Landroid/os/Parcel;->readInt()I
    
        move-result v3
    
        .line 180
        .restart local v3       #_arg2:I
        invoke-virtual {p0, v1, v2, v3}, Lcom/android/internal/statusbar/IStatusBarService$Stub;->onNotificationClear(Ljava/lang/String;Ljava/lang/String;I)V
    
        .line 181
        invoke-virtual {p3}, Landroid/os/Parcel;->writeNoException()V
    
        .line 182
        const/4 v0, 0x1
    
        goto/16 :goto_7
    
        .line 39
        :sswitch_data_13e
        .sparse-switch
            0x1 -> :sswitch_f
            0x2 -> :sswitch_1c
            0x3 -> :sswitch_29
            0x4 -> :sswitch_42
            0x5 -> :sswitch_5f
            0x6 -> :sswitch_7b
            0x7 -> :sswitch_8d
            0x8 -> :sswitch_c7
            0x9 -> :sswitch_d5
            0xa -> :sswitch_ef
            0xb -> :sswitch_116
            0xc -> :sswitch_124
            0x5f4e5446 -> :sswitch_8
        .end sparse-switch
  5. it's important to note this
    Code:
    0xc -> :sswitch_124
    If you rename the static at the previous steps, please change the 0xc accordingly.

2.2 Editing smali/com/android/internal/statusbar/IStatusBarService$Stub$Proxy.smali
Here are the steps:
  1. Insert these function code to the file:
    Code:
    .method public onNotificationClear(Ljava/lang/String;Ljava/lang/String;I)V
        .registers 9
        .parameter "pkg"
        .parameter "tag"
        .parameter "id"
        .annotation system Ldalvik/annotation/Throws;
            value = {
                Landroid/os/RemoteException;
            }
        .end annotation
    
        .prologue
        .line 359
        invoke-static {}, Landroid/os/Parcel;->obtain()Landroid/os/Parcel;
    
        move-result-object v0
    
        .line 360
        .local v0, _data:Landroid/os/Parcel;
        invoke-static {}, Landroid/os/Parcel;->obtain()Landroid/os/Parcel;
    
        move-result-object v1
    
        .line 362
        .local v1, _reply:Landroid/os/Parcel;
        :try_start_8
        const-string v2, "com.android.internal.statusbar.IStatusBarService"
    
        invoke-virtual {v0, v2}, Landroid/os/Parcel;->writeInterfaceToken(Ljava/lang/String;)V
    
        .line 363
        invoke-virtual {v0, p1}, Landroid/os/Parcel;->writeString(Ljava/lang/String;)V
    
        .line 364
        invoke-virtual {v0, p2}, Landroid/os/Parcel;->writeString(Ljava/lang/String;)V
    
        .line 365
        invoke-virtual {v0, p3}, Landroid/os/Parcel;->writeInt(I)V
    
        .line 366
        iget-object v2, p0, Lcom/android/internal/statusbar/IStatusBarService$Stub$Proxy;->mRemote:Landroid/os/IBinder;
    
        const/16 v3, 0xa
    
        const/4 v4, 0x0
    
        invoke-interface {v2, v3, v0, v1, v4}, Landroid/os/IBinder;->transact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
    
        .line 367
        invoke-virtual {v1}, Landroid/os/Parcel;->readException()V
        :try_end_21
        .catchall {:try_start_8 .. :try_end_21} :catchall_28
    
        .line 370
        invoke-virtual {v1}, Landroid/os/Parcel;->recycle()V
    
        .line 371
        invoke-virtual {v0}, Landroid/os/Parcel;->recycle()V
    
        .line 373
        return-void
    
        .line 370
        :catchall_28
        move-exception v2
    
        invoke-virtual {v1}, Landroid/os/Parcel;->recycle()V
    
        .line 371
        invoke-virtual {v0}, Landroid/os/Parcel;->recycle()V
    
        throw v2
    .end method
  2. Please inspect the code for this part:
    Code:
       
    const/16 v3, 0xa
    
    const/4 v4, 0x0
    
        invoke-interface {v2, v3, v0, v1, v4}, Landroid/os/IBinder;->transact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z
    The bold one must match on one of the switch case value at the end of IStatusBarService$Stub.smali,
    in my phone actually the valid one is the TRANSACTION_onNotificationError (0xa) so if your NotificationError is not 0xa but 0xb for example, please change the bold one to 0xb
  3. Save

2.3 editing smali/com/android/internal/statusbar/IStatusBarService.smali
Insert this function code to the file. Here are the steps:
  1. Insert these function code to the file:
    Code:
    .method public abstract onNotificationClear(Ljava/lang/String;Ljava/lang/String;I)V
        .annotation system Ldalvik/annotation/Throws;
            value = {
                Landroid/os/RemoteException;
            }
        .end annotation
    .end method
  2. Save

There you have it AFAIK, the files that you need to take care more than others are:
1. smali/com/android/systemui/statusbar/StatusBarService.smali
2. res/values/public.xml


The rest can be applied from the attachment below directly. Ok that's all, after you are done, compile both SystemUI.apk and Framework.jar.

How to Compile the right way?
1. SystemUI.apk ->
  • Compile with APK Multi Tool, press y and y twice with all the requested input,
  • delete modified file from keep folder, and after that continue compiling.
  • Copy from original APK the META-INF and AndroidManifest.xml to the unsignedSystemUI.apk
  • rename unsignedSystemUI.apk to signedSystemUI.apk
  • select Zipalign from APK Multi Tool to optimize apk.
  • Rename to SystemUI.apk (move the original one just in case)
2. framework.jar ->
  • Smali inside Baksmali Manager
  • Replace classes.dex inside framework.jar with the generated one.

and apply on your phone.

Hope this helps you (programmer ofc, not end user ) to implement on your device.

G'day!
Attached Files
File Type: zip SystemUI-file.zip - [Click for QR Code] (23.4 KB, 2423 views)
File Type: zip framework-file.zip - [Click for QR Code] (3.5 KB, 1920 views)
Last edited by hansip87; 22nd February 2013 at 03:40 PM.
The Following 150 Users Say Thank You to hansip87 For This Useful Post: [ View ]
6th February 2012, 11:30 AM   |  #2  
Dunc001's Avatar
Recognized Developer
Flag Hiding out south of the border...
Thanks Meter: 1,334
 
2,611 posts
Join Date:Joined: Apr 2010
More
Mate, thank you so much for this - I have been trying to figure it out for our ROM for weeks LOL I'm going to give it a try this evening and I'll let you know if I get it! Thanks again
6th February 2012, 12:41 PM   |  #3  
hansip87's Avatar
OP Senior Member
Flag Jakarta
Thanks Meter: 1,840
 
2,553 posts
Join Date:Joined: Jan 2011
Donate to Me
More
Quote:
Originally Posted by Dunc001

Mate, thank you so much for this - I have been trying to figure it out for our ROM for weeks LOL I'm going to give it a try this evening and I'll let you know if I get it! Thanks again

Ok let me know mate
The Following User Says Thank You to hansip87 For This Useful Post: [ View ]
8th February 2012, 02:16 AM   |  #4  
musashihatred's Avatar
Senior Member
Flag Somewhere in Neverland
Thanks Meter: 1,133
 
2,034 posts
Join Date:Joined: Dec 2011
More
ill try it on my SGY
8th February 2012, 03:53 AM   |  #5  
tommytomatoe's Avatar
Recognized Developer
Flag Knoxville USA
Thanks Meter: 6,821
 
6,256 posts
Join Date:Joined: Dec 2010
Donate to Me
More
Looks fun! great post
8th February 2012, 04:48 AM   |  #6  
hansip87's Avatar
OP Senior Member
Flag Jakarta
Thanks Meter: 1,840
 
2,553 posts
Join Date:Joined: Jan 2011
Donate to Me
More
Quote:
Originally Posted by tommytomatoe

Looks fun! great post

Updated step, to give you some warning about StatusBarService$7 naming convention
The Following User Says Thank You to hansip87 For This Useful Post: [ View ]
8th February 2012, 05:12 AM   |  #7  
mcmb03's Avatar
Senior Member
Flag Milwaukee, WI
Thanks Meter: 113
 
745 posts
Join Date:Joined: Feb 2011
Donate to Me
More
definitely gonna give this a try!!
8th February 2012, 05:59 AM   |  #8  
Senior Member
Thanks Meter: 237
 
232 posts
Join Date:Joined: Oct 2011
great akaka.try it soon.
did u know how to port ICS layout to stock rom? can u write a tut?
this will be great!!
Last edited by nvt992; 8th February 2012 at 09:00 AM.
8th February 2012, 08:18 AM   |  #9  
hansip87's Avatar
OP Senior Member
Flag Jakarta
Thanks Meter: 1,840
 
2,553 posts
Join Date:Joined: Jan 2011
Donate to Me
More
Quote:
Originally Posted by nvt992

great akaka.try it soon.
did u know how to port have ICS layout to stock rom? can u write a tut?
this will be great!!

What layout? Do you mean ICS launcher layout or..?
The Following User Says Thank You to hansip87 For This Useful Post: [ View ]
8th February 2012, 08:57 AM   |  #10  
Senior Member
Thanks Meter: 237
 
232 posts
Join Date:Joined: Oct 2011
no.see my attach
Attached Thumbnails
Click image for larger version

Name:	2.jpg
Views:	5457
Size:	96.5 KB
ID:	892599  

Post Reply Subscribe to Thread

Tags
notification, remove, statusbar, swipe
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Top Threads in Android Software and Hacking General [Developers Only] by ThreadRank