Android(4.0以降)にはグローバルプロキシ設定が隠れているようだ。

最近、Galaxy Note(GT-N7000)にCyanogenMod 10を導入していろいろソースを見たりいじったりしてるわけですが、
たまたまなんだか気になるものを発見したのでメモ。


あれ?プロキシ設定あるよ?

まあ、なにもしなくてもWifi設定からできるけど、あれって「ブラウザでしか使えまへん」って思いっきり書いてあるし。
こっちはどうなんでしょう?
(そのうちtcpdumpとって見てみます)

以下、自分のEvernoteにメモってたことそのままコピペw
------------------------
ICSくらいからAsIsでメニュー自体は実装されているようだ。
ただ、動きが保証できていないのか、非表示にされてる。


    158         // Enable Proxy selector settings if allowed.
    160         DevicePolicyManager mDPM = (DevicePolicyManager)
    161                 activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
    162         // proxy UI disabled until we have better app support
    163         getPreferenceScreen().removePreference(mGlobalProxy);
    164         mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);


163, 164行目をコメントアウトすると、メニュー自体は見れるようになる。



そして、ConnectivityManagerがわにGlobalProxyをセットするルートもあるようだ。


    257         ProxyProperties p = new ProxyProperties(hostname, port, exclList);
    258         // FIXME: The best solution would be to make a better UI that would
    259         // disable editing of the text boxes if the user chooses to use the
    260         // default settings. i.e. checking a box to always use the default
    261         // carrier. http:/b/issue?id=756480
    262         // FIXME: If the user types in a proxy that matches the default, should
    263         // we keep that setting? Can be fixed with a new UI.
    264         ConnectivityManager cm =
    265                 (ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    266 
    267         cm.setGlobalProxy(p);


もっと根っこをみていくと、単純なDBセットのようだ。

   2806             ContentResolver res = mContext.getContentResolver();
   2807             Settings.Secure.putString(res, Settings.Secure.GLOBAL_HTTP_PROXY_HOST, host);
   2808             Settings.Secure.putInt(res, Settings.Secure.GLOBAL_HTTP_PROXY_PORT, port);
   2810                     exclList);

------------------------


ということは・・・・
ルートハックさえしてしまえば
ってやって、書き換えれちゃうわけですね。


ただ、下記のようなソースコメントがあるくらいなので、どのくらいまともに動くのかは…使ってみないとわからんですね。
   162         // proxy UI disabled until we have better app support




:追伸:

一応検証したので。

プロキシ設定のUIから、DBに設定値が行く事は確認した。

adb shell 'echo "select * from secure;" | sqlite3 /data/data/com.android.providers.settings/databases/settings.db'
129|global_http_proxy_host|hoge-hoge.org
130|global_http_proxy_port|8080
131|global_http_proxy_exclusion_list|abc.com

ただ、tcpdumpを取ってみると、反映はされていない。3G/Wifi環境ともに

どれも直接接続しに行ってる。すくなくとも4.1.2では。
全然グローバルじゃねえ!!!

っていう結果でした。