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
This commit is contained in:
Jason Chiu
2020-04-09 14:29:58 +08:00
parent 4edb83b260
commit 1766b3c01d
9 changed files with 38 additions and 25 deletions

View File

@@ -19,6 +19,7 @@ package com.android.settings;
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 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
@VisibleForTesting
PhoneStateListener mPhoneStateListener;
private GlobalSettingsChangeListener mAirplaneModeObserver;
public AirplaneModeEnabler(Context context, OnAirplaneModeChangedListener listener) {
super(context, Settings.Global.AIRPLANE_MODE_ON);
@@ -73,7 +72,7 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
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 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
/**
* Implementation of GlobalSettingsChangeListener.onChanged
*/
@Override
public void onChanged(String field) {
if (DEBUG) {
Log.d(LOG_TAG, "Airplane mode configuration update");
@@ -94,12 +94,18 @@ public class AirplaneModeEnabler extends GlobalSettingsChangeListener {
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);
}