Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/org/adblockplus/android/compat/CmGlobalProxyManager.java

Issue 4705284891082752: Proxy configurators (Closed)
Patch Set: Created Aug. 11, 2014, 12:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(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 * @author rjeschke
Felix Dahlke 2014/08/19 09:06:00 We don't really do author tags so far. IMO there's
René Jeschke 2014/08/19 10:41:33 Right, auto-comments in Eclipse. Will remove those
27 */
28 public class CmGlobalProxyManager
29 {
30 private final Object proxyManager;
31
32 public final static String GLOBAL_PROXY_STATE_CHANGE_ACTION = "cyanogenmod.int ent.action.GLOBAL_PROXY_STATE_CHANGE";
33
34 public CmGlobalProxyManager(final Context context) throws CompatibilityExcepti on
35 {
36 try
37 {
38 this.proxyManager = Class.forName("org.cyanogenmod.support.proxy.GlobalPro xyManager")
39 .getConstructor(Context.class)
40 .newInstance(context);
41 }
42 catch (final Exception e)
43 {
44 throw new CompatibilityException("Could not create GlobalProxyManager inst ance", e);
45 }
46 }
47
48 public boolean isPackageCurrentManager() throws CompatibilityException
49 {
50 try
51 {
52 return ((Boolean) this.proxyManager.getClass().getMethod("isPackageCurrent Manager")
53 .invoke(this.proxyManager)).booleanValue();
54 }
55 catch (final Exception e)
56 {
57 throw new CompatibilityException(e);
58 }
59 }
60
61 public void requestGlobalProxy(final Activity activity) throws CompatibilityEx ception
62 {
63 try
64 {
65 this.proxyManager.getClass().getMethod("requestGlobalProxy", Activity.clas s)
66 .invoke(this.proxyManager, activity);
67 }
68 catch (final Exception e)
69 {
70 throw new CompatibilityException(e);
71 }
72 }
73
74 /**
75 * <p>
76 * Set a network-independent global http proxy. This is not normally what you want for typical HTTP proxies - they are general network dependent.
77 * 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
78 * accessible, you may break HTTP using this.
79 * </p>
80 * <p>
81 * This method requires the call to hold the permission {@code cyanogenmod.per mission.GLOBAL_PROXY_MANAGEMENT}.
82 * </p>
83 *
84 * @param proxyProperties
85 * The a {@link CmProxyProperites} object defining the new global HTT P proxy. A {@code null} value will clear the global HTTP proxy.
86 */
87 public void setGlobalProxy(final ProxyProperties p) throws CompatibilityExcept ion
88 {
89 try
90 {
91 this.proxyManager.getClass().getMethod("setGlobalProxy", Class.forName("or g.cyanogenmod.support.proxy.CmProxyProperties"))
92 .invoke(this.proxyManager, p.toCmProxyProperties());
93 }
94 catch (final CompatibilityException ce)
95 {
96 throw ce;
97 }
98 catch (final Exception e)
99 {
100 throw new CompatibilityException(e);
101 }
102 }
103
104 /**
105 * <p>
106 * Retrieve any network-independent global HTTP proxy.
107 * </p>
108 * <p>
109 * This method requires the call to hold the permission {@link cyanogenmod.per mission.GLOBAL_PROXY_MANAGEMENT}.
110 * </p>
111 *
112 * @return {@link ProxyProperties} for the current global HTTP proxy or {@code null} if no global HTTP proxy is set.
113 * @throws CompatibilityException
114 */
115 public ProxyProperties getGlobalProxy() throws CompatibilityException
116 {
117 try
118 {
119 return ProxyProperties.fromObject(this.proxyManager.getClass().getMethod(" getGlobalProxy")
120 .invoke(this.proxyManager));
121 }
122 catch (final CompatibilityException ce)
123 {
124 throw ce;
125 }
126 catch (Exception e)
127 {
128 throw new CompatibilityException(e);
129 }
130 }
131 }
OLDNEW

Powered by Google App Engine
This is Rietveld