Jason Monk | da205a7 | 2013-08-21 15:57:30 -0400 | [diff] [blame] | 1 | /** |
| 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 Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 16 | package com.android.proxyhandler; |
| 17 | |
| 18 | import android.app.Service; |
| 19 | import android.content.Intent; |
| 20 | import android.net.Proxy; |
| 21 | import android.net.ProxyProperties; |
| 22 | import android.os.Bundle; |
| 23 | import android.os.IBinder; |
Jason Monk | 6f8a68f | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 24 | import android.os.RemoteException; |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 25 | import android.text.TextUtils; |
| 26 | |
Jason Monk | 6f8a68f | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 27 | import com.android.net.IProxyCallback; |
| 28 | import com.android.net.IProxyPortListener; |
| 29 | |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 30 | /** |
| 31 | * @hide |
| 32 | */ |
| 33 | public class ProxyService extends Service { |
| 34 | |
| 35 | private static ProxyServer server = null; |
| 36 | |
| 37 | /** Keep these values up-to-date with PacManager.java */ |
| 38 | public static final String KEY_PROXY = "keyProxy"; |
| 39 | public static final String HOST = "localhost"; |
Jason Monk | da205a7 | 2013-08-21 15:57:30 -0400 | [diff] [blame] | 40 | // STOPSHIP This being a static port means it can be hijacked by other apps. |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 41 | public static final int PORT = 8182; |
| 42 | public static final String EXCL_LIST = ""; |
| 43 | |
| 44 | @Override |
Jason Monk | da205a7 | 2013-08-21 15:57:30 -0400 | [diff] [blame] | 45 | public void onCreate() { |
| 46 | super.onCreate(); |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 47 | if (server == null) { |
| 48 | server = new ProxyServer(); |
| 49 | server.startServer(); |
| 50 | } |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public void onDestroy() { |
| 55 | if (server != null) { |
| 56 | server.stopServer(); |
| 57 | server = null; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public IBinder onBind(Intent intent) { |
Jason Monk | 6f8a68f | 2013-08-23 19:21:25 -0400 | [diff] [blame] | 63 | return new IProxyCallback.Stub() { |
| 64 | @Override |
| 65 | public void getProxyPort(IBinder callback) throws RemoteException { |
| 66 | if (server != null) { |
| 67 | IProxyPortListener portListener = IProxyPortListener.Stub.asInterface(callback); |
| 68 | if (portListener != null) { |
| 69 | server.setCallback(portListener); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | }; |
Jason Monk | 602b232 | 2013-07-03 17:04:33 -0400 | [diff] [blame] | 74 | } |
| 75 | } |