Catch exception when checking WifiDisplay availability

Change-Id: Ic2f17905babf43e92a825b8b5b4f8aac7d8ff001
Fixes: 68013053
Test: robotests
This commit is contained in:
Fan Zhang
2017-10-19 16:49:21 -07:00
parent c543d5ba26
commit e0fdec2750
2 changed files with 24 additions and 9 deletions

View File

@@ -36,6 +36,7 @@ import android.net.wifi.p2p.WifiP2pManager.Channel;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.ServiceManager;
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.ListPreference;
@@ -212,8 +213,13 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment {
}
public static boolean isAvailable(Context context) {
return context.getSystemService(Context.DISPLAY_SERVICE) != null
&& context.getSystemService(Context.WIFI_P2P_SERVICE) != null;
try {
return context.getSystemService(Context.DISPLAY_SERVICE) != null
&& context.getSystemService(Context.WIFI_P2P_SERVICE) != null;
} catch (Exception e) {
// Service is not registered, so this is definitely not available.
return false;
}
}
private void scheduleUpdate(int changes) {