Fix indexing error of mobile related controllers

There were several errors in indexing mobile related sliceable
controllers, which led them not able to display on Panel and as inline
controls in search result.

It's because indexing mechanism is running in a worker thread and trying
to construct each controller instance, but the failed controllers'
constructors need to initilize something in the main thread.

- Give the main looper to the classes which only can be initialized in
  the main thread to fix the indexing.
- Guard null pointer exception in SlicesIndexer after fixing the
  indexing.
- Use onStart/onStop in AirplaneModePreferenceController to start/stop
  listener.

Fixes: 149720345
Test: robotest
Change-Id: Ibe5a8d6cc713eeddf26eceaabc05e6d1faa45507
diff --git a/src/com/android/settings/AirplaneModeEnabler.java b/src/com/android/settings/AirplaneModeEnabler.java
index a843a04..6028c18 100644
--- a/src/com/android/settings/AirplaneModeEnabler.java
+++ b/src/com/android/settings/AirplaneModeEnabler.java
@@ -19,6 +19,7 @@
 import android.app.settings.SettingsEnums;
 import android.content.Context;
 import android.content.Intent;
+import android.os.Looper;
 import android.os.UserHandle;
 import android.provider.Settings;
 import android.telephony.PhoneStateListener;
@@ -62,8 +63,6 @@
     @VisibleForTesting
     PhoneStateListener mPhoneStateListener;
 
-    private GlobalSettingsChangeListener mAirplaneModeObserver;
-
     public AirplaneModeEnabler(Context context, OnAirplaneModeChangedListener listener) {
         super(context, Settings.Global.AIRPLANE_MODE_ON);
 
@@ -73,7 +72,7 @@
 
         mTelephonyManager = context.getSystemService(TelephonyManager.class);
 
-        mPhoneStateListener = new PhoneStateListener() {
+        mPhoneStateListener = new PhoneStateListener(Looper.getMainLooper()) {
             @Override
             public void onRadioPowerStateChanged(int state) {
                 if (DEBUG) {
@@ -87,6 +86,7 @@
     /**
      * Implementation of GlobalSettingsChangeListener.onChanged
      */
+    @Override
     public void onChanged(String field) {
         if (DEBUG) {
             Log.d(LOG_TAG, "Airplane mode configuration update");
@@ -94,12 +94,18 @@
         onAirplaneModeChanged();
     }
 
-    public void resume() {
+    /**
+     * Start listening to the phone state change
+     */
+    public void start() {
         mTelephonyManager.listen(mPhoneStateListener,
                 PhoneStateListener.LISTEN_RADIO_POWER_STATE_CHANGED);
     }
 
-    public void pause() {
+    /**
+     * Stop listening to the phone state change
+     */
+    public void stop() {
         mTelephonyManager.listen(mPhoneStateListener,
                 PhoneStateListener.LISTEN_NONE);
     }