| OLD | NEW | 
| (Empty) |  | 
 |    1 /* | 
 |    2  * This file is part of Adblock Plus <http://adblockplus.org/>, | 
 |    3  * Copyright (C) 2006-2014 Eyeo GmbH | 
 |    4  * | 
 |    5  * Adblock Plus is free software: you can redistribute it and/or modify | 
 |    6  * it under the terms of the GNU General Public License version 3 as | 
 |    7  * published by the Free Software Foundation. | 
 |    8  * | 
 |    9  * Adblock Plus is distributed in the hope that it will be useful, | 
 |   10  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 |   11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 |   12  * GNU General Public License for more details. | 
 |   13  * | 
 |   14  * You should have received a copy of the GNU General Public License | 
 |   15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
 |   16  */ | 
 |   17  | 
 |   18 package org.adblockplus.android.compat; | 
 |   19  | 
 |   20 import android.app.Activity; | 
 |   21 import android.content.Context; | 
 |   22  | 
 |   23 /** | 
 |   24  * Wrapper for CyanogenMod GlobalProxyManager API. | 
 |   25  */ | 
 |   26 public class CmGlobalProxyManager | 
 |   27 { | 
 |   28   private final Object proxyManager; | 
 |   29  | 
 |   30   public final static String GLOBAL_PROXY_STATE_CHANGE_ACTION = "cyanogenmod.int
     ent.action.GLOBAL_PROXY_STATE_CHANGE"; | 
 |   31  | 
 |   32   public CmGlobalProxyManager(final Context context) throws CompatibilityExcepti
     on | 
 |   33   { | 
 |   34     try | 
 |   35     { | 
 |   36       this.proxyManager = Class.forName("org.cyanogenmod.support.proxy.GlobalPro
     xyManager") | 
 |   37           .getConstructor(Context.class) | 
 |   38           .newInstance(context); | 
 |   39     } | 
 |   40     catch (final Exception e) | 
 |   41     { | 
 |   42       throw new CompatibilityException("Could not create GlobalProxyManager inst
     ance", e); | 
 |   43     } | 
 |   44   } | 
 |   45  | 
 |   46   public boolean isPackageCurrentManager() throws CompatibilityException | 
 |   47   { | 
 |   48     try | 
 |   49     { | 
 |   50       return ((Boolean) this.proxyManager.getClass().getMethod("isPackageCurrent
     Manager") | 
 |   51           .invoke(this.proxyManager)).booleanValue(); | 
 |   52     } | 
 |   53     catch (final Exception e) | 
 |   54     { | 
 |   55       throw new CompatibilityException(e); | 
 |   56     } | 
 |   57   } | 
 |   58  | 
 |   59   public void requestGlobalProxy(final Activity activity) throws CompatibilityEx
     ception | 
 |   60   { | 
 |   61     try | 
 |   62     { | 
 |   63       this.proxyManager.getClass().getMethod("requestGlobalProxy", Activity.clas
     s) | 
 |   64           .invoke(this.proxyManager, activity); | 
 |   65     } | 
 |   66     catch (final Exception e) | 
 |   67     { | 
 |   68       throw new CompatibilityException(e); | 
 |   69     } | 
 |   70   } | 
 |   71  | 
 |   72   /** | 
 |   73    * <p> | 
 |   74    * Set a network-independent global http proxy. This is not normally what you 
     want for typical HTTP proxies - they are general network dependent. | 
 |   75    * However if you're doing something unusual like general internal filtering t
     his may be useful. On a private network where the proxy is not | 
 |   76    * accessible, you may break HTTP using this. | 
 |   77    * </p> | 
 |   78    * <p> | 
 |   79    * This method requires the call to hold the permission {@code cyanogenmod.per
     mission.GLOBAL_PROXY_MANAGEMENT}. | 
 |   80    * </p> | 
 |   81    * | 
 |   82    * @param proxyProperties | 
 |   83    *          The a {@link CmProxyProperites} object defining the new global HTT
     P proxy. A {@code null} value will clear the global HTTP proxy. | 
 |   84    */ | 
 |   85   public void setGlobalProxy(final ProxyProperties p) throws CompatibilityExcept
     ion | 
 |   86   { | 
 |   87     try | 
 |   88     { | 
 |   89       this.proxyManager.getClass().getMethod("setGlobalProxy", Class.forName("or
     g.cyanogenmod.support.proxy.CmProxyProperties")) | 
 |   90           .invoke(this.proxyManager, p.toCmProxyProperties()); | 
 |   91     } | 
 |   92     catch (final CompatibilityException ce) | 
 |   93     { | 
 |   94       throw ce; | 
 |   95     } | 
 |   96     catch (final Exception e) | 
 |   97     { | 
 |   98       throw new CompatibilityException(e); | 
 |   99     } | 
 |  100   } | 
 |  101  | 
 |  102   /** | 
 |  103    * <p> | 
 |  104    * Retrieve any network-independent global HTTP proxy. | 
 |  105    * </p> | 
 |  106    * <p> | 
 |  107    * This method requires the call to hold the permission {@link cyanogenmod.per
     mission.GLOBAL_PROXY_MANAGEMENT}. | 
 |  108    * </p> | 
 |  109    * | 
 |  110    * @return {@link ProxyProperties} for the current global HTTP proxy or {@code
      null} if no global HTTP proxy is set. | 
 |  111    * @throws CompatibilityException | 
 |  112    */ | 
 |  113   public ProxyProperties getGlobalProxy() throws CompatibilityException | 
 |  114   { | 
 |  115     try | 
 |  116     { | 
 |  117       return ProxyProperties.fromObject(this.proxyManager.getClass().getMethod("
     getGlobalProxy") | 
 |  118           .invoke(this.proxyManager)); | 
 |  119     } | 
 |  120     catch (final CompatibilityException ce) | 
 |  121     { | 
 |  122       throw ce; | 
 |  123     } | 
 |  124     catch (final Exception e) | 
 |  125     { | 
 |  126       throw new CompatibilityException(e); | 
 |  127     } | 
 |  128   } | 
 |  129 } | 
| OLD | NEW |