Changeset 4292
- Timestamp:
- Nov 1, 2012 6:14:15 AM (12 years ago)
- Location:
- pjproject/branches/projects/android/pjsip-apps/src/apjloader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/android/pjsip-apps/src/apjloader/AndroidManifest.xml
r4289 r4292 7 7 android:minSdkVersion="15" 8 8 android:targetSdkVersion="15" /> 9 9 10 10 <uses-permission android:name="android.permission.INTERNET" /> 11 11 <uses-permission android:name="android.permission.RECORD_AUDIO" /> … … 16 16 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 17 17 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 18 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />19 <uses-permission android:name="android.permission.READ_CONTACTS" />20 <uses-permission android:name="android.permission.WRITE_CONTACTS" />21 <uses-permission android:name="android.permission.CALL_PHONE" />22 18 <uses-permission android:name="android.permission.WAKE_LOCK" /> 23 <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />24 19 <uses-permission android:name="android.permission.VIBRATE" /> 25 <uses-permission android:name="android.permission.BLUETOOTH" />26 20 <uses-permission android:name="android.permission.READ_LOGS" /> 27 21 <uses-permission android:name="android.permission.USE_SIP" /> 28 22 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 29 23 <uses-permission android:name="android.permission.CAMERA" /> 30 <uses-permission android:name="android.permission.BROADCAST_STICKY" /> 31 <uses-permission android:name="android.permission.READ_PROFILE" /> 32 33 <uses-feature android:name="android.hardware.sip.voip" android:required="true" /> 34 <uses-feature android:name="android.hardware.microphone" android:required="true" /> 35 24 25 <uses-feature 26 android:name="android.hardware.microphone" 27 android:required="true" /> 28 36 29 <application 37 30 android:icon="@drawable/ic_launcher" … … 39 32 android:theme="@android:style/Theme.DeviceDefault.NoActionBar" > 40 33 <activity 41 android:screenOrientation="portrait"42 android:configChanges="keyboardHidden|orientation|screenLayout"43 34 android:name=".MainActivity" 35 android:windowSoftInputMode="stateHidden" 44 36 android:label="@string/title_activity_main" > 45 37 <intent-filter> -
pjproject/branches/projects/android/pjsip-apps/src/apjloader/src/org/pjsip/apjloader/MainActivity.java
r4289 r4292 2 2 3 3 package org.pjsip.apjloader; 4 5 import java.lang.ref.WeakReference; 4 6 5 7 import android.app.Activity; … … 10 12 import android.os.Message; 11 13 import android.text.method.ScrollingMovementMethod; 14 import android.util.Log; 12 15 import android.view.KeyEvent; 13 16 import android.view.View; … … 22 25 public static final String TAG = "apjloader"; 23 26 public static final String NEWLINE = "\r\n"; 24 public static final Boolean AUTOKILL_ON_FINISHED = true; 27 public static final Boolean AUTOKILL_ON_FINISH = false; 28 public static final int MAX_LOG_CHARS = 20000; // set to zero to disable limit 25 29 public enum MSG_TYPE { 26 30 STR_INFO, … … 42 46 43 47 class LoaderThread extends Thread { 44 private Handlerui_handler;48 private WeakReference<Handler> ui_handler; 45 49 46 50 public LoaderThread(Handler ui_handler_) { 47 ui_handler = ui_handler_; 51 set_ui_handler(ui_handler_); 52 } 53 54 public void set_ui_handler(Handler ui_handler_) { 55 ui_handler = new WeakReference<Handler>(ui_handler_); 48 56 } 49 57 … … 56 64 "--clock-rate=8000", 57 65 "--auto-answer=200", 58 }; 59 60 LOG.INFO(ui_handler, "Starting module.." + CONST.NEWLINE); 66 }; 67 68 Handler ui = ui_handler.get(); 69 LOG.INFO(ui, "Starting module.." + CONST.NEWLINE); 61 70 int rc = apjloader.main(argv.length, argv); 62 LOG.INFO(ui_handler, "Module finished with return code: " + 71 72 ui = ui_handler.get(); 73 LOG.INFO(ui, "Module finished with return code: " + 63 74 Integer.toString(rc) + CONST.NEWLINE); 64 75 65 76 apjloader.destroy_stdio_pipe(); 66 77 67 if (CONST.AUTOKILL_ON_FINISHED) { 68 Message msg = Message.obtain(ui_handler, CONST.MSG_TYPE.QUIT.ordinal()); 69 ui_handler.sendMessageDelayed(msg, 2000); 78 if (CONST.AUTOKILL_ON_FINISH) { 79 ui = ui_handler.get(); 80 Message msg = Message.obtain(ui, CONST.MSG_TYPE.QUIT.ordinal()); 81 ui.sendMessageDelayed(msg, 2000); 70 82 } 71 83 } … … 73 85 74 86 class OutputThread extends Thread { 75 private Handlerui_handler;87 private WeakReference<Handler> ui_handler; 76 88 77 89 public OutputThread(Handler ui_handler_) { 78 ui_handler = ui_handler_; 90 set_ui_handler(ui_handler_); 91 } 92 93 public void set_ui_handler(Handler ui_handler_) { 94 ui_handler = new WeakReference<Handler>(ui_handler_); 79 95 } 80 96 … … 87 103 byte ch[] = new byte[1]; 88 104 int rc = apjloader.read_from_stdout(ch); 105 Handler ui = ui_handler.get(); 89 106 90 107 if (rc == 0) { 91 108 if (ch[0]=='\r' || ch[0]== '\n') { 92 109 if (sb.length() > 0) { 93 LOG.INFO(ui _handler, sb.toString()+CONST.NEWLINE);110 LOG.INFO(ui, sb.toString()+CONST.NEWLINE); 94 111 sb.delete(0, sb.length()); 95 112 } … … 98 115 } 99 116 } else { 100 LOG.INFO(ui _handler, "Stdout pipe stopped, rc="+Integer.toString(rc)+CONST.NEWLINE);117 LOG.INFO(ui, "Stdout pipe stopped, rc="+Integer.toString(rc)+CONST.NEWLINE); 101 118 break; 102 119 } … … 109 126 private TextView log_view; 110 127 private ScrollView log_scroll_view; 111 EditText input_cmd; 112 113 /** Called when the activity is first created. */ 114 @Override 115 public void onCreate(Bundle savedInstanceState) { 116 super.onCreate(savedInstanceState); 117 setContentView(R.layout.activity_main); 118 119 init_view(); 120 121 print_log("Loading module.." + CONST.NEWLINE); 122 int rc = init_lib(); 123 if (rc != 0) 128 private EditText input_cmd; 129 private MyHandler ui_handler = new MyHandler(this); 130 private static OutputThread ot; 131 private static LoaderThread lt; 132 133 private static class MyHandler extends Handler { 134 private final WeakReference<MainActivity> mTarget; 135 136 public MyHandler(MainActivity target) { 137 mTarget = new WeakReference<MainActivity>(target); 138 } 139 140 @Override 141 public void handleMessage(Message m) { 142 MainActivity target = mTarget.get(); 143 if (target == null) 144 return; 145 146 if (m.what == CONST.MSG_TYPE.STR_INFO.ordinal() || 147 m.what == CONST.MSG_TYPE.STR_ERROR.ordinal()) 148 { 149 target.print_log((String)m.obj); 150 } else if (m.what == CONST.MSG_TYPE.QUIT.ordinal()) { 151 target.finish(); 152 System.gc(); 153 android.os.Process.killProcess(android.os.Process.myPid()); 154 } 155 } 156 } 157 158 @Override 159 protected void onCreate(Bundle savedInstanceState) { 160 Log.d(CONST.TAG, "=== Activity::onCreate() ==="); 161 super.onCreate(savedInstanceState); 162 163 init_view(); 164 165 int rc = init_lib(); 166 if (rc != 0) { 124 167 print_log("Failed loading module: " + Integer.toString(rc) + CONST.NEWLINE); 125 } 126 168 return; 169 } 170 171 ot.set_ui_handler(ui_handler); 172 lt.set_ui_handler(ui_handler); 173 } 174 175 @Override 176 protected void onStart() { 177 Log.d(CONST.TAG, "=== Activity::onStart() ==="); 178 super.onStart(); 179 } 180 181 @Override 182 protected void onRestart() { 183 Log.d(CONST.TAG, "=== Activity::onRestart() ==="); 184 super.onRestart(); 185 } 186 187 @Override 188 protected void onResume() { 189 Log.d(CONST.TAG, "=== Activity::onResume() ==="); 190 super.onResume(); 191 } 192 193 @Override 194 protected void onPause() { 195 Log.d(CONST.TAG, "=== Activity::onPause() ==="); 196 super.onPause(); 197 } 198 199 @Override 200 protected void onStop() { 201 Log.d(CONST.TAG, "=== Activity::onStop() ==="); 202 super.onStop(); 203 } 204 205 @Override 206 protected void onDestroy() { 207 Log.d(CONST.TAG, "=== Activity::onDestroy() ==="); 208 super.onDestroy(); 209 } 210 211 @Override 212 protected void onSaveInstanceState(Bundle outState) { 213 super.onSaveInstanceState(outState); 214 outState.putString("INPUT_CMD", input_cmd.getText().toString()); 215 outState.putString("LOG_VIEW", log_view.getText().toString()); 216 } 217 218 @Override 219 protected void onRestoreInstanceState(Bundle savedInstanceState) { 220 super.onRestoreInstanceState(savedInstanceState); 221 input_cmd.setText(savedInstanceState.getString("INPUT_CMD")); 222 log_view.setText(savedInstanceState.getString("LOG_VIEW")); 223 log_view.post(new Runnable() { 224 public void run() { 225 log_scroll_view.fullScroll(View.FOCUS_DOWN); 226 } 227 }); 228 } 229 230 127 231 private View.OnClickListener on_send_cmd_click = new View.OnClickListener() { 128 232 public void onClick(View v) { … … 161 265 private void print_log(String st) { 162 266 log_view.append(st); 163 //Log.i(CONST.TAG, st); 164 267 Log.d(CONST.TAG, st); 268 269 // Limit log view text length 270 if (CONST.MAX_LOG_CHARS > 0 && log_view.length() > CONST.MAX_LOG_CHARS) { 271 int to_del = log_view.length() - CONST.MAX_LOG_CHARS + 100; 272 if (to_del > log_view.length()) 273 to_del = log_view.length(); 274 log_view.getEditableText().delete(0, to_del); 275 } 276 277 // Scroll to bottom 165 278 log_view.post(new Runnable() { 166 279 public void run() { … … 170 283 } 171 284 172 private Handler ui_handler = new Handler() {173 @Override174 public void handleMessage(Message m) {175 if (m.what == CONST.MSG_TYPE.STR_INFO.ordinal() ||176 m.what == CONST.MSG_TYPE.STR_ERROR.ordinal())177 {178 print_log((String)m.obj);179 } else if (m.what == CONST.MSG_TYPE.QUIT.ordinal()) {180 finish();181 System.gc();182 android.os.Process.killProcess(android.os.Process.myPid());183 }184 }185 };186 187 285 private void hide_soft_keyboard() { 188 286 InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); … … 191 289 192 290 private void init_view() { 193 Button send_cmd_button = (Button)findViewById(R.id.send_cmd_button); 291 setContentView(R.layout.activity_main); 292 293 Button send_cmd_button = (Button)findViewById(R.id.send_cmd_button); 194 294 send_cmd_button.setOnClickListener(on_send_cmd_click); 195 295 … … 199 299 input_cmd = (EditText)findViewById(R.id.input_cmd); 200 300 input_cmd.setOnKeyListener(on_input_cmd_key); 201 301 202 302 log_view = (TextView)findViewById(R.id.output); 203 303 log_view.setMovementMethod(new ScrollingMovementMethod()); 204 log_view.setText("");205 304 206 305 log_scroll_view = (ScrollView)findViewById(R.id.output_scroller); 207 306 } 208 307 209 private int init_stdio_pipes() {210 int rc = apjloader.init_stdio_pipe();211 if (rc != 0)212 return rc;213 214 return 0;215 }216 217 308 private int init_lib() { 309 if (ot != null || lt != null) 310 return 0; 311 312 print_log("Loading module.." + CONST.NEWLINE); 313 218 314 try { 219 315 System.loadLibrary(CONST.LIB_FILENAME); … … 232 328 } 233 329 234 int rc = init_stdio_pipes();330 int rc = apjloader.init_stdio_pipe(); 235 331 print_log("Stdio pipes inited: " + Integer.toString(rc) + CONST.NEWLINE); 236 332 237 OutputThreadot = new OutputThread(ui_handler);333 ot = new OutputThread(ui_handler); 238 334 ot.start(); 239 335 240 LoaderThreadlt = new LoaderThread(ui_handler);336 lt = new LoaderThread(ui_handler); 241 337 lt.start(); 242 338
Note: See TracChangeset
for help on using the changeset viewer.