chrometophone (3)

なんとなく時間が取れたと思ったら別方面に現実トウヒしてたりなんかして微妙ですが、なんとか掘削に着手できた定時前だったりして。
とりあえず不思議なのが svn checkout して作成される root が chrometophome-read-only というディレクトリなんですが、その下にあるのが

$ ls
android      appengine      extension      third_party
$

という形になってます。いずれもディレクトリ。で、android の配下が

$ ls
AndroidManifest.xml  default.properties   src
c2dm                 rex
$

というカンジ。src 配下は Activity なソレ達が格納されているみたいなんですが、c2dm 配下にもソースが投入されております。

$ ls android/c2dm/com/google/android/c2dm/
C2DMBaseReceiver.java    C2DMBroadcastReceiver.java    C2DMessaging.java
$

どーゆーソレでこいつらが build されるのかが謎だったりしてます。

それは良いとして

上記のナニと Manifest とを見つつ、って事で Manifest の下らへんに BroadcastReceiver な記述がある。

        <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver"
                  android:permission="com.google.android.c2dm.permission.SEND">
            <!-- Receive the actual message -->
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.google.android.apps.chrometophone" />
            </intent-filter>
            <!-- Receive the registration id -->
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
                <category android:name="com.google.android.apps.chrometophone" />
            </intent-filter>
        </receiver>

上記二点の BroadcastIntent は C2DMBroadcastReceiver が受けれ、との指令。onReceive の定義が以下となっている模様。

    public final void onReceive(Context context, Intent intent) {
        // To keep things in one place.
        C2DMBaseReceiver.runIntentInService(context, intent);
        setResult(Activity.RESULT_OK, null /* data */, null /* extra */);        
    }

ええと、static なメソドを呼び出しております。上記の手続きで諸々の準備をした挙句に

        context.startService(intent);

という事をしております。ここから onHandleIntent メソドに飛ぶんかな。振り分けとしては以下。

            Context context = getApplicationContext();
            if (intent.getAction().equals(REGISTRATION_CALLBACK_INTENT)) {
                handleRegistration(context, intent);
            } else if (intent.getAction().equals(C2DM_INTENT)) {
                onMessage(context, intent);
            } else if (intent.getAction().equals(C2DM_RETRY)) {
                C2DMessaging.register(context, senderId);
            }

上記によれば BroadcastIntent 経由でのソレは

  • actual message (C2DM_INTENT)
    • onMessage に dispatch
  • registration ID (REGISTRATION_CALLBACK_INTENT)
    • handleRegistration に dispatch

してるんですが、最後の C2DM_RETRY というのは一体何でしょ。

    private static final String C2DM_RETRY = "com.google.android.c2dm.intent.RETRY";

うーん。と思ったら AlarmManager なるもの経由で何かをしてますな。これは Broadcast なソレではなくて自分で自分に投げてる、という理解で良いのかな。

毎回

中途半端ですが、この基底クラスをきちんと確認する必要はありそげ。ってか、tomcat が分かればサーバ側を python ででっち上げるんだけどなぁ (弱