blob: 970fdc727ded393432e6ff1f550349d3a71b020b [file] [log] [blame]
Jason Monkda205a72013-08-21 15:57:30 -04001/**
2 * Copyright (c) 2013, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jason Monk602b2322013-07-03 17:04:33 -040016package com.android.proxyhandler;
17
18import android.app.Service;
19import android.content.Intent;
Jason Monk602b2322013-07-03 17:04:33 -040020import android.os.IBinder;
Jason Monk6f8a68f2013-08-23 19:21:25 -040021import android.os.RemoteException;
Jason Monk602b2322013-07-03 17:04:33 -040022
Jason Monk6f8a68f2013-08-23 19:21:25 -040023import com.android.net.IProxyCallback;
24import com.android.net.IProxyPortListener;
25
Jason Monk602b2322013-07-03 17:04:33 -040026/**
27 * @hide
28 */
29public class ProxyService extends Service {
30
31 private static ProxyServer server = null;
32
33 /** Keep these values up-to-date with PacManager.java */
34 public static final String KEY_PROXY = "keyProxy";
35 public static final String HOST = "localhost";
Jason Monk602b2322013-07-03 17:04:33 -040036 public static final String EXCL_LIST = "";
37
38 @Override
Jason Monkda205a72013-08-21 15:57:30 -040039 public void onCreate() {
40 super.onCreate();
Jason Monk602b2322013-07-03 17:04:33 -040041 if (server == null) {
42 server = new ProxyServer();
43 server.startServer();
44 }
Jason Monk602b2322013-07-03 17:04:33 -040045 }
46
47 @Override
48 public void onDestroy() {
49 if (server != null) {
50 server.stopServer();
51 server = null;
52 }
53 }
54
55 @Override
56 public IBinder onBind(Intent intent) {
Jason Monk6f8a68f2013-08-23 19:21:25 -040057 return new IProxyCallback.Stub() {
58 @Override
59 public void getProxyPort(IBinder callback) throws RemoteException {
60 if (server != null) {
61 IProxyPortListener portListener = IProxyPortListener.Stub.asInterface(callback);
62 if (portListener != null) {
63 server.setCallback(portListener);
64 }
65 }
66 }
67 };
Jason Monk602b2322013-07-03 17:04:33 -040068 }
69}