OmniGears: add missing disabled entry for app select preference

Change-Id: Ia576140447c0403ba69c307a0ee7430672d30570
diff --git a/src/org/omnirom/omnigears/preference/AppSelectListPreference.java b/src/org/omnirom/omnigears/preference/AppSelectListPreference.java
index b57a795..7fdd73e 100644
--- a/src/org/omnirom/omnigears/preference/AppSelectListPreference.java
+++ b/src/org/omnirom/omnigears/preference/AppSelectListPreference.java
@@ -107,6 +107,10 @@
         private final Handler mHandler = new Handler() {
             @Override
             public void handleMessage(Message msg) {
+                PackageItem disabledItem = new PackageItem(getContext().getResources().getString(R.string.disabled_entry),
+                        R.drawable.ic_disabled, DISABLED_ENTRY);
+                mInstalledPackages.add(0, disabledItem);
+
                 notifyDataSetChanged();
                 updatePreferenceViews();
             }
@@ -274,14 +278,19 @@
         mAppIconResourceId = R.drawable.ic_disabled;
 
         if (name != null) {
-            mAppIconDrawable = null;
-            ComponentName componentName = ComponentName.unflattenFromString(name);
-            PackageItem item = mAdapter.resolveApplication(componentName);
-            if (item != null) {
-                mTitle = item.mTitle;
-                mAppIconDrawable = resolveAppIcon(item);
+            if (name.equals(DISABLED_ENTRY)) {
+                mTitle = getContext().getResources().getString(R.string.disabled_entry);
+                mAppIconResourceId = R.drawable.ic_disabled;
             } else {
-                mTitle = getContext().getResources().getString(R.string.resolve_failed_summary);
+                mAppIconDrawable = null;
+                ComponentName componentName = ComponentName.unflattenFromString(name);
+                PackageItem item = mAdapter.resolveApplication(componentName);
+                if (item != null) {
+                    mTitle = item.mTitle;
+                    mAppIconDrawable = resolveAppIcon(item);
+                } else {
+                    mTitle = getContext().getResources().getString(R.string.resolve_failed_summary);
+                }
             }
         } else {
             mTitle = getContext().getResources().getString(R.string.disabled_entry);
diff --git a/src/org/omnirom/omnigears/service/EventService.java b/src/org/omnirom/omnigears/service/EventService.java
index 0acaa70..2756e15 100644
--- a/src/org/omnirom/omnigears/service/EventService.java
+++ b/src/org/omnirom/omnigears/service/EventService.java
@@ -39,9 +39,12 @@
 import android.os.UserHandle;
 import android.os.ServiceManager;
 import android.os.SystemClock;
+import android.text.TextUtils;
 import android.util.Log;
 import android.view.KeyEvent;
 
+import org.omnirom.omnigears.preference.AppSelectListPreference;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -77,7 +80,7 @@
                         mA2DPConnected = true;
                         if (DEBUG) Log.d(TAG, "BluetoothProfile.STATE_CONNECTED = true" );
                         String app = getPrefs(context).getString(EventServiceSettings.EVENT_A2DP_CONNECT, null);
-                        if (app != null) {
+                        if (!TextUtils.isEmpty(app) && !app.equals(AppSelectListPreference.DISABLED_ENTRY)) {
                             if (DEBUG) Log.d(TAG, "AudioManager.ACTION_HEADSET_PLUG app = " + app);
                             try {
                                 context.startActivityAsUser(createIntent(app), UserHandle.CURRENT);
@@ -104,7 +107,7 @@
                         mWiredHeadsetConnected = true;
                         if (DEBUG) Log.d(TAG, "AudioManager.ACTION_HEADSET_PLUG = true" );
                         String app = getPrefs(context).getString(EventServiceSettings.EVENT_WIRED_HEADSET_CONNECT, null);
-                        if (app != null) {
+                        if (!TextUtils.isEmpty(app) && !app.equals(AppSelectListPreference.DISABLED_ENTRY)) {
                             if (DEBUG) Log.d(TAG, "AudioManager.ACTION_HEADSET_PLUG app = " + app);
                             try {
                                 context.startActivityAsUser(createIntent(app), UserHandle.CURRENT);