22
33import android .accessibilityservice .AccessibilityService ;
44import android .content .Intent ;
5- import android .content .res .Configuration ;
65import android .view .accessibility .AccessibilityEvent ;
76
7+ import java .lang .ref .WeakReference ;
8+
89public class TouchHelperService extends AccessibilityService {
910
1011 public final static int ACTION_REFRESH_KEYWORDS = 1 ;
@@ -13,15 +14,17 @@ public class TouchHelperService extends AccessibilityService {
1314 public final static int ACTION_ACTIVITY_CUSTOMIZATION = 4 ;
1415 public final static int ACTION_STOP_SERVICE = 5 ;
1516 public final static int ACTION_START_SKIPAD = 6 ;
17+ public final static int ACTION_STOP_SKIPAD = 7 ;
1618
17- public static TouchHelperServiceImpl serviceImpl = null ;
19+ private static WeakReference <TouchHelperService > sServiceRef ;
20+ private TouchHelperServiceImpl serviceImpl ;
1821
19- final private String TAG = getClass ().getName ();
22+ private final String TAG = getClass ().getName ();
2023
2124 @ Override
2225 protected void onServiceConnected () {
2326 super .onServiceConnected ();
24-
27+ sServiceRef = new WeakReference <>( this );
2528 if (serviceImpl == null ) {
2629 serviceImpl = new TouchHelperServiceImpl (this );
2730 }
@@ -50,6 +53,21 @@ public boolean onUnbind(Intent intent) {
5053 serviceImpl .onUnbind (intent );
5154 serviceImpl = null ;
5255 }
56+ sServiceRef = null ;
5357 return super .onUnbind (intent );
5458 }
59+
60+ public static boolean dispatchAction (int action ) {
61+ final TouchHelperService service = sServiceRef != null ? sServiceRef .get () : null ;
62+ if (service == null || service .serviceImpl == null ) {
63+ return false ;
64+ }
65+ service .serviceImpl .receiverHandler .sendEmptyMessage (action );
66+ return true ;
67+ }
68+
69+ public static boolean isServiceRunning () {
70+ final TouchHelperService service = sServiceRef != null ? sServiceRef .get () : null ;
71+ return service != null && service .serviceImpl != null ;
72+ }
5573}
0 commit comments