Throw RuntimeExceptions when PolicyService calls fail
* Rather than returning false, which can cause unexpected results, e.g. locking out an account until reboot * Partial fix for the referenced bug (there might be other causes) Bug: 5221119 Change-Id: I5b47093a3411deb6995624887197297323db0d2d
This commit is contained in:
parent
9bcdd58a09
commit
c28fdfeaad
|
@ -16,15 +16,15 @@
|
|||
|
||||
package com.android.emailcommon.service;
|
||||
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.Policy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.Policy;
|
||||
|
||||
public class PolicyServiceProxy extends ServiceProxy implements IPolicyService {
|
||||
private static final boolean DEBUG_PROXY = false; // DO NOT CHECK THIS IN SET TO TRUE
|
||||
private static final String TAG = "PolicyServiceProxy";
|
||||
|
@ -60,8 +60,7 @@ public class PolicyServiceProxy extends ServiceProxy implements IPolicyService {
|
|||
Log.v(TAG, "clearUnsupportedPolicies: " + ((mReturn == null) ? "null" : mReturn));
|
||||
}
|
||||
if (mReturn == null) {
|
||||
// Can this happen?
|
||||
return null;
|
||||
throw new ServiceUnavailableException("clearUnsupportedPolicies");
|
||||
} else {
|
||||
return (Policy)mReturn;
|
||||
}
|
||||
|
@ -79,8 +78,7 @@ public class PolicyServiceProxy extends ServiceProxy implements IPolicyService {
|
|||
Log.v(TAG, "isActive: " + ((mReturn == null) ? "null" : mReturn));
|
||||
}
|
||||
if (mReturn == null) {
|
||||
// Can this happen?
|
||||
return false;
|
||||
throw new ServiceUnavailableException("isActive");
|
||||
} else {
|
||||
return (Boolean)mReturn;
|
||||
}
|
||||
|
@ -98,8 +96,7 @@ public class PolicyServiceProxy extends ServiceProxy implements IPolicyService {
|
|||
Log.v(TAG, "isActiveAdmin: " + ((mReturn == null) ? "null" : mReturn));
|
||||
}
|
||||
if (mReturn == null) {
|
||||
// Can this happen?
|
||||
return false;
|
||||
throw new ServiceUnavailableException("isActiveAdmin");
|
||||
} else {
|
||||
return (Boolean)mReturn;
|
||||
}
|
||||
|
@ -117,8 +114,7 @@ public class PolicyServiceProxy extends ServiceProxy implements IPolicyService {
|
|||
Log.v(TAG, "isSupported: " + ((mReturn == null) ? "null" : mReturn));
|
||||
}
|
||||
if (mReturn == null) {
|
||||
// Can this happen?
|
||||
return false;
|
||||
throw new ServiceUnavailableException("isSupported");
|
||||
} else {
|
||||
return (Boolean)mReturn;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (C) 2011 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.emailcommon.service;
|
||||
|
||||
/**
|
||||
* An Exception thrown when a service proxy requires a result and there's a remote exception; this
|
||||
* prevents the caller from receiving an invalid result.
|
||||
*/
|
||||
public class ServiceUnavailableException extends RuntimeException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ServiceUnavailableException(String string) {
|
||||
super(string);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue