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 */ 16 package com.android.proxyhandler; 17 18 import android.app.Service; 19 import android.content.Intent; 20 import android.os.IBinder; 21 import android.os.RemoteException; 22 23 import com.android.net.IProxyCallback; 24 import com.android.net.IProxyPortListener; 25 26 /** 27 * @hide 28 */ 29 public 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"; 36 // STOPSHIP This being a static port means it can be hijacked by other apps. 37 public static final int PORT = 8182; 38 public static final String EXCL_LIST = ""; 39 40 @Override onCreate()41 public void onCreate() { 42 super.onCreate(); 43 if (server == null) { 44 server = new ProxyServer(); 45 server.startServer(); 46 } 47 } 48 49 @Override onDestroy()50 public void onDestroy() { 51 if (server != null) { 52 server.stopServer(); 53 server = null; 54 } 55 } 56 57 @Override onBind(Intent intent)58 public IBinder onBind(Intent intent) { 59 return new IProxyCallback.Stub() { 60 @Override 61 public void getProxyPort(IBinder callback) throws RemoteException { 62 if (server != null) { 63 IProxyPortListener portListener = IProxyPortListener.Stub.asInterface(callback); 64 if (portListener != null) { 65 server.setCallback(portListener); 66 } 67 } 68 } 69 }; 70 } 71 }