BugFix: Fix potential NPEs with getService()
Should fix "java.lang.NullPointerException: Attempt to invoke interface method 'int cyanogenmod.hardware.ICMHardwareService.getSupportedFeatures()' on a null object reference" and others Change-Id: Ic5a02fc953376aa746844fd6c2f93b5f48246516
This commit is contained in:
parent
6850732052
commit
40a46bd09e
@ -166,7 +166,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public int getSupportedFeatures() {
|
public int getSupportedFeatures() {
|
||||||
try {
|
try {
|
||||||
return getService().getSupportedFeatures();
|
if (checkService()) {
|
||||||
|
return sService.getSupportedFeatures();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -198,7 +200,9 @@ public final class CMHardwareManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return getService().get(feature);
|
if (checkService()) {
|
||||||
|
return sService.get(feature);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -220,7 +224,9 @@ public final class CMHardwareManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return getService().set(feature, enable);
|
if (checkService()) {
|
||||||
|
return sService.set(feature, enable);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -257,7 +263,9 @@ public final class CMHardwareManager {
|
|||||||
|
|
||||||
private int[] getVibratorIntensityArray() {
|
private int[] getVibratorIntensityArray() {
|
||||||
try {
|
try {
|
||||||
return getService().getVibratorIntensity();
|
if (checkService()) {
|
||||||
|
return sService.getVibratorIntensity();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -308,7 +316,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public boolean setVibratorIntensity(int intensity) {
|
public boolean setVibratorIntensity(int intensity) {
|
||||||
try {
|
try {
|
||||||
return getService().setVibratorIntensity(intensity);
|
if (checkService()) {
|
||||||
|
return sService.setVibratorIntensity(intensity);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -341,7 +351,9 @@ public final class CMHardwareManager {
|
|||||||
|
|
||||||
private int[] getDisplayColorCalibrationArray() {
|
private int[] getDisplayColorCalibrationArray() {
|
||||||
try {
|
try {
|
||||||
return getService().getDisplayColorCalibration();
|
if (checkService()) {
|
||||||
|
return sService.getDisplayColorCalibration();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -390,7 +402,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public boolean setDisplayColorCalibration(int[] rgb) {
|
public boolean setDisplayColorCalibration(int[] rgb) {
|
||||||
try {
|
try {
|
||||||
return getService().setDisplayColorCalibration(rgb);
|
if (checkService()) {
|
||||||
|
return sService.setDisplayColorCalibration(rgb);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -419,7 +433,9 @@ public final class CMHardwareManager {
|
|||||||
|
|
||||||
private int[] getDisplayGammaCalibrationArray(int idx) {
|
private int[] getDisplayGammaCalibrationArray(int idx) {
|
||||||
try {
|
try {
|
||||||
return getService().getDisplayGammaCalibration(idx);
|
if (checkService()) {
|
||||||
|
return sService.getDisplayGammaCalibration(idx);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -431,7 +447,9 @@ public final class CMHardwareManager {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public int getNumGammaControls() {
|
public int getNumGammaControls() {
|
||||||
try {
|
try {
|
||||||
return getService().getNumGammaControls();
|
if (checkService()) {
|
||||||
|
return sService.getNumGammaControls();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -480,7 +498,9 @@ public final class CMHardwareManager {
|
|||||||
@Deprecated
|
@Deprecated
|
||||||
public boolean setDisplayGammaCalibration(int idx, int[] rgb) {
|
public boolean setDisplayGammaCalibration(int idx, int[] rgb) {
|
||||||
try {
|
try {
|
||||||
return getService().setDisplayGammaCalibration(idx, rgb);
|
if (checkService()) {
|
||||||
|
return sService.setDisplayGammaCalibration(idx, rgb);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -491,7 +511,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public String getLtoSource() {
|
public String getLtoSource() {
|
||||||
try {
|
try {
|
||||||
return getService().getLtoSource();
|
if (checkService()) {
|
||||||
|
return sService.getLtoSource();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -502,7 +524,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public String getLtoDestination() {
|
public String getLtoDestination() {
|
||||||
try {
|
try {
|
||||||
return getService().getLtoDestination();
|
if (checkService()) {
|
||||||
|
return sService.getLtoDestination();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -513,7 +537,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public long getLtoDownloadInterval() {
|
public long getLtoDownloadInterval() {
|
||||||
try {
|
try {
|
||||||
return getService().getLtoDownloadInterval();
|
if (checkService()) {
|
||||||
|
return sService.getLtoDownloadInterval();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -524,7 +550,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public String getSerialNumber() {
|
public String getSerialNumber() {
|
||||||
try {
|
try {
|
||||||
return getService().getSerialNumber();
|
if (checkService()) {
|
||||||
|
return sService.getSerialNumber();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -536,7 +564,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public boolean requireAdaptiveBacklightForSunlightEnhancement() {
|
public boolean requireAdaptiveBacklightForSunlightEnhancement() {
|
||||||
try {
|
try {
|
||||||
return getService().requireAdaptiveBacklightForSunlightEnhancement();
|
if (checkService()) {
|
||||||
|
return sService.requireAdaptiveBacklightForSunlightEnhancement();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -547,7 +577,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public DisplayMode[] getDisplayModes() {
|
public DisplayMode[] getDisplayModes() {
|
||||||
try {
|
try {
|
||||||
return getService().getDisplayModes();
|
if (checkService()) {
|
||||||
|
return sService.getDisplayModes();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -558,7 +590,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public DisplayMode getCurrentDisplayMode() {
|
public DisplayMode getCurrentDisplayMode() {
|
||||||
try {
|
try {
|
||||||
return getService().getCurrentDisplayMode();
|
if (checkService()) {
|
||||||
|
return sService.getCurrentDisplayMode();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -569,7 +603,9 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public DisplayMode getDefaultDisplayMode() {
|
public DisplayMode getDefaultDisplayMode() {
|
||||||
try {
|
try {
|
||||||
return getService().getDefaultDisplayMode();
|
if (checkService()) {
|
||||||
|
return sService.getDefaultDisplayMode();
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -580,9 +616,22 @@ public final class CMHardwareManager {
|
|||||||
*/
|
*/
|
||||||
public boolean setDisplayMode(DisplayMode mode, boolean makeDefault) {
|
public boolean setDisplayMode(DisplayMode mode, boolean makeDefault) {
|
||||||
try {
|
try {
|
||||||
return getService().setDisplayMode(mode, makeDefault);
|
if (checkService()) {
|
||||||
|
return sService.setDisplayMode(mode, makeDefault);
|
||||||
|
}
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if service is valid
|
||||||
|
*/
|
||||||
|
private boolean checkService() {
|
||||||
|
if (sService == null) {
|
||||||
|
Log.w(TAG, "not connected to CMHardwareManagerService");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user