title: Accessibilty Service is not started
body: <p>I have an accessibility service that i use to track some app usages and let user know. Everything was working fine. Not sure suddenly my accessibility service stopped working. Its not even getting started. Permission is granted. But still the service doesn't start.</p>
  
  <p><strong>in manifest file</strong></p>
  
  <pre><code>&lt;service android:name=".Services.AutoStartReceiverService" android:enabled="true"&gt;&lt;/service&gt;
  
          &lt;service
              android:name=".Services.WindowChangeDetectingService"
              android:label="@string/accessibility_service_name"
              android:enabled="true"
              android:exported="false"
              android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.accessibilityservice.AccessibilityService" /&gt;
              &lt;/intent-filter&gt;
  
              &lt;meta-data
                  android:name="android.accessibilityservice"
                  android:resource="@xml/accessibilityservice" /&gt;
          &lt;/service&gt;
  </code></pre>
  
  <p><strong>Accessibility Service Code:</strong></p>
  
  <pre><code>public class WindowChangeDetectingService extends AccessibilityService {
  
      private static final String TAG = "APPCHANGESERV";
      private SharedPreferences sharedpreferences;
  
      @Override
      protected void onServiceConnected() {
          super.onServiceConnected();
  
          //Configure these here for compatibility with API 13 and below.
          AccessibilityServiceInfo config = new AccessibilityServiceInfo();
          config.eventTypes = AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
          config.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
  
          if (Build.VERSION.SDK_INT &gt;= 16)
              //Just in case this helps
              config.flags = AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS;
  
          setServiceInfo(config);
      }
  
  
      @Override
      public void onAccessibilityEvent(AccessibilityEvent event) {
          if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
              if (event.getPackageName() != null &amp;&amp; event.getClassName() != null) {
                  ComponentName componentName = new ComponentName(
                          event.getPackageName().toString(),
                          event.getClassName().toString()
                  );
  
                  ActivityInfo activityInfo = tryGetActivity(componentName);
                  boolean isActivity = activityInfo != null;
                  ApplicationInfo applicationInfo = null;
                  ApplicationInfo savedApplicationInfo = null;
                  sharedpreferences = getSharedPreferences("virtual_virus", Context.MODE_PRIVATE);
                  if (isActivity) {
                      try {
                          applicationInfo = (getPackageManager().getApplicationInfo(componentName.getPackageName(), 0));
                          savedApplicationInfo = (getPackageManager().getApplicationInfo(sharedpreferences.getString("packageName", ""), 0));
                      } catch (PackageManager.NameNotFoundException e) {
                          e.printStackTrace();
                      }
  
                      if ((activityInfo.flags &amp; ApplicationInfo.FLAG_SYSTEM) != 0) {
                          Log.i(TAG, "system");
                      } else {
  
                          SharedPreferences.Editor editor = sharedpreferences.edit();
  
                          // For Closing
                          Utlis.clearAllNotification(getApplicationContext());
  
                          if (savedApplicationInfo != null) {
                              AppInfo.updateAppInfo(sharedpreferences.getString("packageName", ""), new Date(), false, savedApplicationInfo.category);
                          }
  
  
                          // For Opening
                          if (activityInfo != null) {
  
                              if (applicationInfo.category == ApplicationInfo.CATEGORY_VIDEO || applicationInfo.category == ApplicationInfo.CATEGORY_SOCIAL || applicationInfo.category == ApplicationInfo.CATEGORY_GAME) {
                                  AppInfo.updateAppInfo(componentName.getPackageName(), new Date(), true, applicationInfo.category);
  
                                  AppLimit appLimit = AppLimit.getAppLimit(componentName.getPackageName());
                                  if (appLimit.getLimit() &gt; 0) {
                                      AppInfo obj = AppInfo.getAppInfoByDateAndPackage(componentName.getPackageName(), new Date());
                                      Log.v(TAG, "obj.getAppUsage(): " + obj.getAppUsage());
                                      if ((appLimit.getLimit() * 60 * 1000) - obj.getAppUsage() &gt; 0) {
                                          Utlis.scheduleNotification(getApplicationContext(), Utlis.getNotification(getApplicationContext(), componentName.getPackageName()), (int) Math.abs((appLimit.getLimit() * 60 * 1000) - obj.getAppUsage()));
                                      }
                                  }
  
  //                                else {
  //                                    Utlis.scheduleNotification(getApplicationContext(), Utlis.getNotification(getApplicationContext(), componentName.getPackageName()), 1000);
  //                                }
                              }
                          }
  
                          editor.putString("packageName", componentName.getPackageName());
                          editor.commit();
  
                          Log.i(TAG, componentName.getPackageName() + "  " + ApplicationInfo.FLAG_IS_GAME);
                      }
  
                  }
              }
          }
      }
  
      private ActivityInfo tryGetActivity(ComponentName componentName) {
          try {
              return getPackageManager().getActivityInfo(componentName, 0);
          } catch (PackageManager.NameNotFoundException e) {
              return null;
          }
      }
  
      @Override
      public void onInterrupt() {
  
      }
  }
  </code></pre>
  
  <p><strong>in string file:</strong></p>
  
  <pre><code>&lt;string name="accessibility_service_name"&gt;@string/app_name&lt;/string&gt;
      &lt;string name="accessibility_service_description"&gt;ভার্চুয়াল অ্যান্টিভাইরাস er je karone ei permission ti dorkar&lt;/string&gt;
  </code></pre>
  
  <p><strong>accessibilty service xml file:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;!-- These options MUST be specified here in order for the events to be received on first
   start in Android 4.1.1 --&gt;
  &lt;accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:accessibilityEventTypes="typeWindowStateChanged"
      android:accessibilityFeedbackType="feedbackGeneric"
      android:accessibilityFlags="flagIncludeNotImportantViews"
      android:description="@string/accessibility_service_description"
      tools:ignore="UnusedAttribute" /&gt;
  </code></pre>
  
  <p><strong>i am getting the accessibilty permission in my main activity like this:</strong></p>
  
  <pre><code>accessPermissionButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
                  startActivityForResult(intent, 0);
              }
          });
  </code></pre>
  
  <p>And noticed it works perfectly on simulator. </p>