summaryrefslogtreecommitdiff
path: root/packages/services
diff options
context:
space:
mode:
authorAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-02-10 13:50:28 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-02-10 13:50:28 +0000
commit8efe77c9983b859c10e695fa7730dfbdb738b7b2 (patch)
treea02f3773f1c6854345a5f8d908cbdc062e05dbac /packages/services
parent3ff7d5e955deec38cbc204680a8e9024210f049a (diff)
parentc19a2ed00d3778e7a9997e2ccf5005041fab6280 (diff)
Merge "Mitigate race conditions in PacService" am: d7942eef48 am: 6cd7b812ca am: c19a2ed00d
Change-Id: Ibd7b037d692ef478c36a05d1ba2ab4231fc1dc44
Diffstat (limited to 'packages/services')
-rw-r--r--packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java8
-rw-r--r--packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java38
2 files changed, 14 insertions, 32 deletions
diff --git a/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java b/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java
index c67fe9ffa916..1e8109cb393c 100644
--- a/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/PacNative.java
@@ -23,6 +23,8 @@ import android.util.Log;
public class PacNative {
private static final String TAG = "PacProxy";
+ private static final PacNative sInstance = new PacNative();
+
private String mCurrentPac;
private boolean mIsActive;
@@ -39,8 +41,12 @@ public class PacNative {
System.loadLibrary("jni_pacprocessor");
}
- PacNative() {
+ private PacNative() {
+
+ }
+ public static PacNative getInstance() {
+ return sInstance;
}
public synchronized boolean startPacSupport() {
diff --git a/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java b/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java
index 74391eb676d1..b006d6e1fa7b 100644
--- a/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java
+++ b/packages/services/PacProcessor/src/com/android/pacprocessor/PacService.java
@@ -31,43 +31,27 @@ import java.net.URL;
public class PacService extends Service {
private static final String TAG = "PacService";
- private PacNative mPacNative;
- private ProxyServiceStub mStub;
+ private PacNative mPacNative = PacNative.getInstance();
+ private ProxyServiceStub mStub = new ProxyServiceStub();
@Override
public void onCreate() {
super.onCreate();
- if (mPacNative == null) {
- mPacNative = new PacNative();
- mStub = new ProxyServiceStub(mPacNative);
- }
+ mPacNative.startPacSupport();
}
@Override
public void onDestroy() {
+ mPacNative.stopPacSupport();
super.onDestroy();
- if (mPacNative != null) {
- mPacNative.stopPacSupport();
- mPacNative = null;
- mStub = null;
- }
}
@Override
public IBinder onBind(Intent intent) {
- if (mPacNative == null) {
- mPacNative = new PacNative();
- mStub = new ProxyServiceStub(mPacNative);
- }
return mStub;
}
- private static class ProxyServiceStub extends IProxyService.Stub {
- private final PacNative mPacNative;
-
- public ProxyServiceStub(PacNative pacNative) {
- mPacNative = pacNative;
- }
+ private class ProxyServiceStub extends IProxyService.Stub {
@Override
public String resolvePacFile(String host, String url) throws RemoteException {
@@ -102,20 +86,12 @@ public class PacService extends Service {
@Override
public void startPacSystem() throws RemoteException {
- if (Binder.getCallingUid() != Process.SYSTEM_UID) {
- Log.e(TAG, "Only system user is allowed to call startPacSystem");
- throw new SecurityException();
- }
- mPacNative.startPacSupport();
+ //TODO: remove
}
@Override
public void stopPacSystem() throws RemoteException {
- if (Binder.getCallingUid() != Process.SYSTEM_UID) {
- Log.e(TAG, "Only system user is allowed to call stopPacSystem");
- throw new SecurityException();
- }
- mPacNative.stopPacSupport();
+ //TODO: remove
}
}
}