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

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

Issue 4705284891082752: Proxy configurators (Closed)
Patch Set: Update 1 Created Aug. 19, 2014, 10:43 a.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.content.Context;
21 import android.net.ConnectivityManager;
22
23 public class LinkProperties
24 {
25 private final Object linkProperties;
26
27 public LinkProperties(final Object linkProperties)
28 {
29 this.linkProperties = linkProperties;
30 }
31
32 public boolean isValid()
33 {
34 return this.linkProperties != null;
35 }
36
37 public static LinkProperties getActiveLinkProperties(final ConnectivityManager manager) throws CompatibilityException
38 {
39 try
40 {
41 return new LinkProperties(
42 manager.getClass()
43 .getMethod("getActiveLinkProperties")
44 .invoke(manager));
45 }
46 catch (final Throwable t)
47 {
48 throw new CompatibilityException(t);
49 }
50 }
51
52 public static LinkProperties getLinkProperties(final ConnectivityManager manag er, final int networkType) throws CompatibilityException
53 {
54 try
55 {
56 return new LinkProperties(
57 manager.getClass()
58 .getMethod("getLinkProperties", int.class)
59 .invoke(manager, networkType));
60 }
61 catch (final Throwable t)
62 {
63 throw new CompatibilityException(t);
64 }
65 }
66
67 public static LinkProperties fromContext(final Context context)
68 {
69 try
70 {
71 return getActiveLinkProperties(((ConnectivityManager) context.getSystemSer vice(Context.CONNECTIVITY_SERVICE)));
72 }
73 catch (final CompatibilityException e)
74 {
75 return null;
76 }
77 }
78
79 public Object getLinkProperties()
80 {
81 return this.linkProperties;
82 }
83
84 public String getInterfaceName() throws CompatibilityException
85 {
86 try
87 {
88 return (String) Class.forName("android.net.LinkProperties")
89 .getMethod("getInterfaceName")
90 .invoke(this.linkProperties);
91 }
92 catch (final Throwable t)
93 {
94 throw new CompatibilityException(t);
95 }
96 }
97
98 public void setHttpProxy(final ProxyProperties proxyProperties) throws Compati bilityException
99 {
100 try
101 {
102 Class.forName("android.net.LinkProperties")
103 .getMethod("setHttpProxy", Class.forName("android.net.ProxyProperties" ))
104 .invoke(this.linkProperties, proxyProperties != null ? proxyProperties .toAndroidNetProxyProperties() : null);
105 }
106 catch (final CompatibilityException e)
107 {
108 throw e;
109 }
110 catch (final Throwable t)
111 {
112 throw new CompatibilityException(t);
113 }
114 }
115
116 public ProxyProperties getHttpProxy() throws CompatibilityException
117 {
118 try
119 {
120 return ProxyProperties.fromObject(
121 Class.forName("android.net.LinkProperties")
122 .getMethod("getHttpProxy")
123 .invoke(this.linkProperties));
124 }
125 catch (final CompatibilityException e)
126 {
127 throw e;
128 }
129 catch (final Throwable t)
130 {
131 throw new CompatibilityException(t);
132 }
133 }
134
135 @Override
136 public String toString()
137 {
138 return this.isValid() ? this.linkProperties.toString() : null;
139 }
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld