[go: nahoru, domu]

17640caaf912a7eefacc3e2108c5afd70f7b072a4noda/*
27640caaf912a7eefacc3e2108c5afd70f7b072a4noda * Copyright (C) 2010 The Android Open Source Project
37640caaf912a7eefacc3e2108c5afd70f7b072a4noda *
47640caaf912a7eefacc3e2108c5afd70f7b072a4noda * Licensed under the Apache License, Version 2.0 (the "License");
57640caaf912a7eefacc3e2108c5afd70f7b072a4noda * you may not use this file except in compliance with the License.
67640caaf912a7eefacc3e2108c5afd70f7b072a4noda * You may obtain a copy of the License at
77640caaf912a7eefacc3e2108c5afd70f7b072a4noda *
87640caaf912a7eefacc3e2108c5afd70f7b072a4noda *      http://www.apache.org/licenses/LICENSE-2.0
97640caaf912a7eefacc3e2108c5afd70f7b072a4noda *
107640caaf912a7eefacc3e2108c5afd70f7b072a4noda * Unless required by applicable law or agreed to in writing, software
117640caaf912a7eefacc3e2108c5afd70f7b072a4noda * distributed under the License is distributed on an "AS IS" BASIS,
127640caaf912a7eefacc3e2108c5afd70f7b072a4noda * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137640caaf912a7eefacc3e2108c5afd70f7b072a4noda * See the License for the specific language governing permissions and
147640caaf912a7eefacc3e2108c5afd70f7b072a4noda * limitations under the License.
157640caaf912a7eefacc3e2108c5afd70f7b072a4noda */
167640caaf912a7eefacc3e2108c5afd70f7b072a4noda
177640caaf912a7eefacc3e2108c5afd70f7b072a4nodapackage com.android.smspush.unitTests;
187640caaf912a7eefacc3e2108c5afd70f7b072a4noda
197640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.app.Activity;
207640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.content.ComponentName;
217640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.content.Context;
227640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.content.Intent;
237640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.content.ServiceConnection;
247640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.os.Bundle;
257640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.os.IBinder;
267640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.os.RemoteException;
277640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.util.Log;
287640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.view.View;
297640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.widget.Button;
307640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.widget.CheckBox;
317640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.widget.EditText;
327640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport android.widget.RadioButton;
337640caaf912a7eefacc3e2108c5afd70f7b072a4noda
347640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport com.android.internal.telephony.IWapPushManager;
357640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport com.android.internal.telephony.WapPushManagerParams;
367640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport com.android.internal.telephony.WapPushOverSms;
377640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport com.android.internal.util.HexDump;
387640caaf912a7eefacc3e2108c5afd70f7b072a4nodaimport com.android.smspush.WapPushManager;
397640caaf912a7eefacc3e2108c5afd70f7b072a4noda
407640caaf912a7eefacc3e2108c5afd70f7b072a4noda/**
417640caaf912a7eefacc3e2108c5afd70f7b072a4noda * WapPushManager test application
427640caaf912a7eefacc3e2108c5afd70f7b072a4noda */
437640caaf912a7eefacc3e2108c5afd70f7b072a4nodapublic class ClientTest extends Activity {
447640caaf912a7eefacc3e2108c5afd70f7b072a4noda    private static final String LOG_TAG = "WAP PUSH";
457640caaf912a7eefacc3e2108c5afd70f7b072a4noda
467640caaf912a7eefacc3e2108c5afd70f7b072a4noda    /** Called when the activity is first created. */
477640caaf912a7eefacc3e2108c5afd70f7b072a4noda    @Override
487640caaf912a7eefacc3e2108c5afd70f7b072a4noda    public void onCreate(Bundle savedInstanceState) {
497640caaf912a7eefacc3e2108c5afd70f7b072a4noda        super.onCreate(savedInstanceState);
507640caaf912a7eefacc3e2108c5afd70f7b072a4noda        setContentView(R.layout.main);
517640caaf912a7eefacc3e2108c5afd70f7b072a4noda
527640caaf912a7eefacc3e2108c5afd70f7b072a4noda        Button addpbtn = (Button) findViewById(R.id.addpkg);
537640caaf912a7eefacc3e2108c5afd70f7b072a4noda        Button procbtn = (Button) findViewById(R.id.procmsg);
547640caaf912a7eefacc3e2108c5afd70f7b072a4noda        Button delbtn = (Button) findViewById(R.id.delpkg);
557640caaf912a7eefacc3e2108c5afd70f7b072a4noda
567640caaf912a7eefacc3e2108c5afd70f7b072a4noda        Log.v(LOG_TAG, "activity created!!");
577640caaf912a7eefacc3e2108c5afd70f7b072a4noda
587640caaf912a7eefacc3e2108c5afd70f7b072a4noda        addpbtn.setOnClickListener(new View.OnClickListener() {
597640caaf912a7eefacc3e2108c5afd70f7b072a4noda                public void onClick(View v) {
607640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText app_id = (EditText) findViewById(R.id.app_id);
617640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText cont = (EditText) findViewById(R.id.cont);
627640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText pkg = (EditText) findViewById(R.id.pkg);
637640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText cls = (EditText) findViewById(R.id.cls);
647640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    RadioButton act = (RadioButton) findViewById(R.id.act);
657640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    CheckBox sig = (CheckBox) findViewById(R.id.sig);
667640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    CheckBox ftr = (CheckBox) findViewById(R.id.ftr);
677640caaf912a7eefacc3e2108c5afd70f7b072a4noda
687640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    try {
697640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        if (!mWapPushMan.addPackage(
707640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                app_id.getText().toString(),
717640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                cont.getText().toString(),
727640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                pkg.getText().toString(),
737640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                cls.getText().toString(),
747640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                act.isChecked() ? WapPushManagerParams.APP_TYPE_ACTIVITY :
757640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                WapPushManagerParams.APP_TYPE_SERVICE,
767640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                sig.isChecked(), ftr.isChecked())) {
777640caaf912a7eefacc3e2108c5afd70f7b072a4noda
787640caaf912a7eefacc3e2108c5afd70f7b072a4noda                            Log.w(LOG_TAG, "remote add pkg failed...");
797640caaf912a7eefacc3e2108c5afd70f7b072a4noda                            mWapPushMan.updatePackage(
807640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                    app_id.getText().toString(),
817640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                    cont.getText().toString(),
827640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                    pkg.getText().toString(),
837640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                    cls.getText().toString(),
847640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                    act.isChecked() ? WapPushManagerParams.APP_TYPE_ACTIVITY :
857640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                    WapPushManagerParams.APP_TYPE_SERVICE,
867640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                    sig.isChecked(), ftr.isChecked());
877640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        }
887640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    } catch (RemoteException e) {
897640caaf912a7eefacc3e2108c5afd70f7b072a4noda                            Log.w(LOG_TAG, "remote func failed...");
907640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    }
917640caaf912a7eefacc3e2108c5afd70f7b072a4noda                }
927640caaf912a7eefacc3e2108c5afd70f7b072a4noda            });
937640caaf912a7eefacc3e2108c5afd70f7b072a4noda
947640caaf912a7eefacc3e2108c5afd70f7b072a4noda        delbtn.setOnClickListener(new View.OnClickListener() {
957640caaf912a7eefacc3e2108c5afd70f7b072a4noda                public void onClick(View v) {
967640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText app_id = (EditText) findViewById(R.id.app_id);
977640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText cont = (EditText) findViewById(R.id.cont);
987640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText pkg = (EditText) findViewById(R.id.pkg);
997640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText cls = (EditText) findViewById(R.id.cls);
1007640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    // CheckBox delall = (CheckBox) findViewById(R.id.delall);
1017640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    // Log.d(LOG_TAG, "button clicked");
1027640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1037640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    try {
1047640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        mWapPushMan.deletePackage(
1057640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                app_id.getText().toString(),
1067640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                cont.getText().toString(),
1077640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                pkg.getText().toString(),
1087640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                cls.getText().toString());
1097640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        // delall.isChecked());
1107640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    } catch (RemoteException e) {
1117640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        Log.w(LOG_TAG, "remote func failed...");
1127640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    }
1137640caaf912a7eefacc3e2108c5afd70f7b072a4noda                }
1147640caaf912a7eefacc3e2108c5afd70f7b072a4noda            });
1157640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1167640caaf912a7eefacc3e2108c5afd70f7b072a4noda        procbtn.setOnClickListener(new View.OnClickListener() {
1177640caaf912a7eefacc3e2108c5afd70f7b072a4noda                public void onClick(View v) {
1187640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText pdu = (EditText) findViewById(R.id.pdu);
1197640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText app_id = (EditText) findViewById(R.id.app_id);
1207640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    EditText cont = (EditText) findViewById(R.id.cont);
1217640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1227640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    // WapPushOverSms wap = new WapPushOverSms();
1237640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    // wap.dispatchWapPdu(strToHex(pdu.getText().toString()));
1247640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    try {
1257640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        Intent intent = new Intent();
1267640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        intent.putExtra("transactionId", 0);
1277640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        intent.putExtra("pduType", 6);
1287640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        intent.putExtra("header",
1297640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                HexDump.hexStringToByteArray(pdu.getText().toString()));
1307640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        intent.putExtra("data",
1317640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                HexDump.hexStringToByteArray(pdu.getText().toString()));
1327640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1337640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        mWapPushMan.processMessage(
1347640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                app_id.getText().toString(),
1357640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                cont.getText().toString(),
1367640caaf912a7eefacc3e2108c5afd70f7b072a4noda                                intent);
1377640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        //HexDump.hexStringToByteArray(pdu.getText().toString()), 0, 6, 5, 5);
1387640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    } catch (RemoteException e) {
1397640caaf912a7eefacc3e2108c5afd70f7b072a4noda                        Log.w(LOG_TAG, "remote func failed...");
1407640caaf912a7eefacc3e2108c5afd70f7b072a4noda                    }
1417640caaf912a7eefacc3e2108c5afd70f7b072a4noda                }
1427640caaf912a7eefacc3e2108c5afd70f7b072a4noda            });
1437640caaf912a7eefacc3e2108c5afd70f7b072a4noda    }
1447640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1457640caaf912a7eefacc3e2108c5afd70f7b072a4noda    private IWapPushManager mWapPushMan;
1467640caaf912a7eefacc3e2108c5afd70f7b072a4noda    private ServiceConnection conn = new ServiceConnection() {
1477640caaf912a7eefacc3e2108c5afd70f7b072a4noda        public void onServiceDisconnected(ComponentName name) {
1487640caaf912a7eefacc3e2108c5afd70f7b072a4noda            mWapPushMan = null;
1497640caaf912a7eefacc3e2108c5afd70f7b072a4noda            Log.v(LOG_TAG, "service disconnected.");
1507640caaf912a7eefacc3e2108c5afd70f7b072a4noda        }
1517640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1527640caaf912a7eefacc3e2108c5afd70f7b072a4noda        public void onServiceConnected(ComponentName name, IBinder service) {
1537640caaf912a7eefacc3e2108c5afd70f7b072a4noda            mWapPushMan = IWapPushManager.Stub.asInterface(service);
1547640caaf912a7eefacc3e2108c5afd70f7b072a4noda            Log.v(LOG_TAG, "service connected.");
1557640caaf912a7eefacc3e2108c5afd70f7b072a4noda        }
1567640caaf912a7eefacc3e2108c5afd70f7b072a4noda        };
1577640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1587640caaf912a7eefacc3e2108c5afd70f7b072a4noda    @Override
1597640caaf912a7eefacc3e2108c5afd70f7b072a4noda    public void onStart() {
1607640caaf912a7eefacc3e2108c5afd70f7b072a4noda        super.onStart();
1617640caaf912a7eefacc3e2108c5afd70f7b072a4noda        Log.v(LOG_TAG, "onStart bind WAPPushManager service "
1627640caaf912a7eefacc3e2108c5afd70f7b072a4noda                + IWapPushManager.class.getName());
1637640caaf912a7eefacc3e2108c5afd70f7b072a4noda        this.bindService(new Intent(IWapPushManager.class.getName()), conn,
1647640caaf912a7eefacc3e2108c5afd70f7b072a4noda                Context.BIND_AUTO_CREATE);
1657640caaf912a7eefacc3e2108c5afd70f7b072a4noda        Log.v(LOG_TAG, "bind service done.");
1667640caaf912a7eefacc3e2108c5afd70f7b072a4noda    }
1677640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1687640caaf912a7eefacc3e2108c5afd70f7b072a4noda    @Override
1697640caaf912a7eefacc3e2108c5afd70f7b072a4noda    public void onDestroy() {
1707640caaf912a7eefacc3e2108c5afd70f7b072a4noda        super.onDestroy();
1717640caaf912a7eefacc3e2108c5afd70f7b072a4noda        this.unbindService(conn);
1727640caaf912a7eefacc3e2108c5afd70f7b072a4noda    }
1737640caaf912a7eefacc3e2108c5afd70f7b072a4noda
1747640caaf912a7eefacc3e2108c5afd70f7b072a4noda}
175