diff options
author | Jason Monk <jmonk@google.com> | 2013-08-14 15:50:59 -0400 |
---|---|---|
committer | Jason Monk <jmonk@google.com> | 2013-08-20 15:27:51 -0400 |
commit | 433ba46fcc3205b8bbda6eb2256088bbab81fd49 (patch) | |
tree | 11a1013aff627c24ded7eea4e4a154160348a7b1 | |
parent | 58514937628dfcf3b2949e4cbc45d5526ecb8019 (diff) | |
download | frameworks_base-433ba46fcc3205b8bbda6eb2256088bbab81fd49.zip frameworks_base-433ba46fcc3205b8bbda6eb2256088bbab81fd49.tar.gz frameworks_base-433ba46fcc3205b8bbda6eb2256088bbab81fd49.tar.bz2 |
Fix ProxyHandler to only run when needed
Changes ProxyHandler service to only be active when needed for PAC services.
Bug: 10260877
Change-Id: If42e53e805488fd08381baa96409ba3027661c70
3 files changed, 17 insertions, 7 deletions
diff --git a/packages/services/Proxy/AndroidManifest.xml b/packages/services/Proxy/AndroidManifest.xml index 02475c0..09b8327 100644 --- a/packages/services/Proxy/AndroidManifest.xml +++ b/packages/services/Proxy/AndroidManifest.xml @@ -6,7 +6,6 @@ <uses-permission android:name="android.permission.INTERNET" /> <application - android:persistent="true" android:label="@string/app_label" android:process="com.android.proxyhandler"> diff --git a/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java b/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java index 0aea5ee..18ed645 100644 --- a/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java +++ b/packages/services/Proxy/src/com/android/proxyhandler/ProxyService.java @@ -24,24 +24,28 @@ public class ProxyService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { if (intent != null) { - handleCommand(intent); + if (handleCommand(intent)) { + return START_REDELIVER_INTENT; + } } - return START_STICKY; + return START_NOT_STICKY; } - private void handleCommand(Intent intent) { + private boolean handleCommand(Intent intent) { Bundle bundle = intent.getExtras(); ProxyProperties proxy = null; if ((bundle != null) && bundle.containsKey(Proxy.EXTRA_PROXY_INFO)) { proxy = bundle.getParcelable(Proxy.EXTRA_PROXY_INFO); if ((proxy != null) && !TextUtils.isEmpty(proxy.getPacFileUrl())) { startProxy(proxy); + return true; } else { stopSelf(); } } else { stopSelf(); } + return false; } diff --git a/packages/services/Proxy/src/com/android/proxyhandler/ProxyServiceReceiver.java b/packages/services/Proxy/src/com/android/proxyhandler/ProxyServiceReceiver.java index f5c2ca5..4638def 100644 --- a/packages/services/Proxy/src/com/android/proxyhandler/ProxyServiceReceiver.java +++ b/packages/services/Proxy/src/com/android/proxyhandler/ProxyServiceReceiver.java @@ -4,7 +4,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.Proxy; +import android.net.ProxyProperties; import android.os.Bundle; +import android.text.TextUtils; public class ProxyServiceReceiver extends BroadcastReceiver { @@ -12,11 +14,16 @@ public class ProxyServiceReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Intent service = new Intent(context, ProxyService.class); Bundle bundle = intent.getExtras(); + ProxyProperties proxy = null; if (bundle != null) { - service.putExtra(Proxy.EXTRA_PROXY_INFO, - bundle.getParcelable(Proxy.EXTRA_PROXY_INFO)); + proxy = bundle.getParcelable(Proxy.EXTRA_PROXY_INFO); + service.putExtra(Proxy.EXTRA_PROXY_INFO, proxy); + } + if ((proxy != null) && (!TextUtils.isEmpty(proxy.getPacFileUrl()))) { + context.startService(service); + } else { + context.stopService(service); } - context.startService(service); } } |