1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.smspush.unitTests; 18 19 import android.app.Activity; 20 import android.content.ComponentName; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.ServiceConnection; 24 import android.os.Bundle; 25 import android.os.IBinder; 26 import android.os.RemoteException; 27 import android.util.Log; 28 import android.view.View; 29 import android.widget.Button; 30 import android.widget.CheckBox; 31 import android.widget.EditText; 32 import android.widget.RadioButton; 33 34 import com.android.internal.telephony.IWapPushManager; 35 import com.android.internal.telephony.WapPushManagerParams; 36 import com.android.internal.telephony.WapPushOverSms; 37 import com.android.internal.util.HexDump; 38 import com.android.smspush.WapPushManager; 39 40 /** 41 * WapPushManager test application 42 */ 43 public class ClientTest extends Activity { 44 private static final String LOG_TAG = "WAP PUSH"; 45 46 /** Called when the activity is first created. */ 47 @Override onCreate(Bundle savedInstanceState)48 public void onCreate(Bundle savedInstanceState) { 49 super.onCreate(savedInstanceState); 50 setContentView(R.layout.main); 51 52 Button addpbtn = findViewById(R.id.addpkg); 53 Button procbtn = findViewById(R.id.procmsg); 54 Button delbtn = findViewById(R.id.delpkg); 55 56 Log.v(LOG_TAG, "activity created!!"); 57 58 addpbtn.setOnClickListener(new View.OnClickListener() { 59 public void onClick(View v) { 60 EditText app_id = findViewById(R.id.app_id); 61 EditText cont = findViewById(R.id.cont); 62 EditText pkg = findViewById(R.id.pkg); 63 EditText cls = findViewById(R.id.cls); 64 RadioButton act = findViewById(R.id.act); 65 CheckBox sig = findViewById(R.id.sig); 66 CheckBox ftr = findViewById(R.id.ftr); 67 68 try { 69 if (!mWapPushMan.addPackage( 70 app_id.getText().toString(), 71 cont.getText().toString(), 72 pkg.getText().toString(), 73 cls.getText().toString(), 74 act.isChecked() ? WapPushManagerParams.APP_TYPE_ACTIVITY : 75 WapPushManagerParams.APP_TYPE_SERVICE, 76 sig.isChecked(), ftr.isChecked())) { 77 78 Log.w(LOG_TAG, "remote add pkg failed..."); 79 mWapPushMan.updatePackage( 80 app_id.getText().toString(), 81 cont.getText().toString(), 82 pkg.getText().toString(), 83 cls.getText().toString(), 84 act.isChecked() ? WapPushManagerParams.APP_TYPE_ACTIVITY : 85 WapPushManagerParams.APP_TYPE_SERVICE, 86 sig.isChecked(), ftr.isChecked()); 87 } 88 } catch (RemoteException e) { 89 Log.w(LOG_TAG, "remote func failed..."); 90 } 91 } 92 }); 93 94 delbtn.setOnClickListener(new View.OnClickListener() { 95 public void onClick(View v) { 96 EditText app_id = findViewById(R.id.app_id); 97 EditText cont = findViewById(R.id.cont); 98 EditText pkg = findViewById(R.id.pkg); 99 EditText cls = findViewById(R.id.cls); 100 // CheckBox delall = findViewById(R.id.delall); 101 // Log.d(LOG_TAG, "button clicked"); 102 103 try { 104 mWapPushMan.deletePackage( 105 app_id.getText().toString(), 106 cont.getText().toString(), 107 pkg.getText().toString(), 108 cls.getText().toString()); 109 // delall.isChecked()); 110 } catch (RemoteException e) { 111 Log.w(LOG_TAG, "remote func failed..."); 112 } 113 } 114 }); 115 116 procbtn.setOnClickListener(new View.OnClickListener() { 117 public void onClick(View v) { 118 EditText pdu = findViewById(R.id.pdu); 119 EditText app_id = findViewById(R.id.app_id); 120 EditText cont = findViewById(R.id.cont); 121 122 // WapPushOverSms wap = new WapPushOverSms(); 123 // wap.dispatchWapPdu(strToHex(pdu.getText().toString())); 124 try { 125 Intent intent = new Intent(); 126 intent.putExtra("transactionId", 0); 127 intent.putExtra("pduType", 6); 128 intent.putExtra("header", 129 HexDump.hexStringToByteArray(pdu.getText().toString())); 130 intent.putExtra("data", 131 HexDump.hexStringToByteArray(pdu.getText().toString())); 132 133 mWapPushMan.processMessage( 134 app_id.getText().toString(), 135 cont.getText().toString(), 136 intent); 137 //HexDump.hexStringToByteArray(pdu.getText().toString()), 0, 6, 5, 5); 138 } catch (RemoteException e) { 139 Log.w(LOG_TAG, "remote func failed..."); 140 } 141 } 142 }); 143 } 144 145 private IWapPushManager mWapPushMan; 146 private ServiceConnection conn = new ServiceConnection() { 147 public void onServiceDisconnected(ComponentName name) { 148 mWapPushMan = null; 149 Log.v(LOG_TAG, "service disconnected."); 150 } 151 152 public void onServiceConnected(ComponentName name, IBinder service) { 153 mWapPushMan = IWapPushManager.Stub.asInterface(service); 154 Log.v(LOG_TAG, "service connected."); 155 } 156 }; 157 158 @Override onStart()159 public void onStart() { 160 super.onStart(); 161 Log.v(LOG_TAG, "onStart bind WAPPushManager service " 162 + IWapPushManager.class.getName()); 163 this.bindService(new Intent(IWapPushManager.class.getName()), conn, 164 Context.BIND_AUTO_CREATE); 165 Log.v(LOG_TAG, "bind service done."); 166 } 167 168 @Override onDestroy()169 public void onDestroy() { 170 super.onDestroy(); 171 this.unbindService(conn); 172 } 173 174 } 175