Merge "Mitigate race conditions in PacService" am: d7942eef48 am: 6cd7b812ca
Change-Id: I2250d3b541c7b1696fe31441df0b01890bc1c41a
This commit is contained in:
@@ -23,6 +23,8 @@ import android.util.Log;
|
|||||||
public class PacNative {
|
public class PacNative {
|
||||||
private static final String TAG = "PacProxy";
|
private static final String TAG = "PacProxy";
|
||||||
|
|
||||||
|
private static final PacNative sInstance = new PacNative();
|
||||||
|
|
||||||
private String mCurrentPac;
|
private String mCurrentPac;
|
||||||
|
|
||||||
private boolean mIsActive;
|
private boolean mIsActive;
|
||||||
@@ -39,10 +41,14 @@ public class PacNative {
|
|||||||
System.loadLibrary("jni_pacprocessor");
|
System.loadLibrary("jni_pacprocessor");
|
||||||
}
|
}
|
||||||
|
|
||||||
PacNative() {
|
private PacNative() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static PacNative getInstance() {
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized boolean startPacSupport() {
|
public synchronized boolean startPacSupport() {
|
||||||
if (createV8ParserNativeLocked()) {
|
if (createV8ParserNativeLocked()) {
|
||||||
Log.e(TAG, "Unable to Create v8 Proxy Parser.");
|
Log.e(TAG, "Unable to Create v8 Proxy Parser.");
|
||||||
|
|||||||
@@ -31,43 +31,27 @@ import java.net.URL;
|
|||||||
public class PacService extends Service {
|
public class PacService extends Service {
|
||||||
private static final String TAG = "PacService";
|
private static final String TAG = "PacService";
|
||||||
|
|
||||||
private PacNative mPacNative;
|
private PacNative mPacNative = PacNative.getInstance();
|
||||||
private ProxyServiceStub mStub;
|
private ProxyServiceStub mStub = new ProxyServiceStub();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
if (mPacNative == null) {
|
mPacNative.startPacSupport();
|
||||||
mPacNative = new PacNative();
|
|
||||||
mStub = new ProxyServiceStub(mPacNative);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
mPacNative.stopPacSupport();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (mPacNative != null) {
|
|
||||||
mPacNative.stopPacSupport();
|
|
||||||
mPacNative = null;
|
|
||||||
mStub = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IBinder onBind(Intent intent) {
|
public IBinder onBind(Intent intent) {
|
||||||
if (mPacNative == null) {
|
|
||||||
mPacNative = new PacNative();
|
|
||||||
mStub = new ProxyServiceStub(mPacNative);
|
|
||||||
}
|
|
||||||
return mStub;
|
return mStub;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ProxyServiceStub extends IProxyService.Stub {
|
private class ProxyServiceStub extends IProxyService.Stub {
|
||||||
private final PacNative mPacNative;
|
|
||||||
|
|
||||||
public ProxyServiceStub(PacNative pacNative) {
|
|
||||||
mPacNative = pacNative;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resolvePacFile(String host, String url) throws RemoteException {
|
public String resolvePacFile(String host, String url) throws RemoteException {
|
||||||
@@ -102,20 +86,12 @@ public class PacService extends Service {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startPacSystem() throws RemoteException {
|
public void startPacSystem() throws RemoteException {
|
||||||
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
|
//TODO: remove
|
||||||
Log.e(TAG, "Only system user is allowed to call startPacSystem");
|
|
||||||
throw new SecurityException();
|
|
||||||
}
|
|
||||||
mPacNative.startPacSupport();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopPacSystem() throws RemoteException {
|
public void stopPacSystem() throws RemoteException {
|
||||||
if (Binder.getCallingUid() != Process.SYSTEM_UID) {
|
//TODO: remove
|
||||||
Log.e(TAG, "Only system user is allowed to call stopPacSystem");
|
|
||||||
throw new SecurityException();
|
|
||||||
}
|
|
||||||
mPacNative.stopPacSupport();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user