1 package com.joshuawise.dumload;
3 import java.io.InputStream;
5 import com.jcraft.jsch.*;
6 import java.lang.Boolean;
8 import android.app.Activity;
9 import android.app.Service;
10 import android.content.Intent;
11 import android.app.PendingIntent;
12 import android.content.Context;
13 import android.net.Uri;
14 import android.os.Bundle;
15 import android.os.IBinder;
16 import android.widget.TextView;
17 import android.widget.Toast;
18 import android.util.Log;
19 import android.app.NotificationManager;
20 import android.app.Notification;
21 import android.os.Handler;
22 import android.os.Messenger;
23 import android.os.Looper;
24 import android.os.Message;
25 import android.os.SystemClock;
27 public class Uploader extends Service implements Runnable, UserInfo, UIKeyboardInteractive {
29 private String homedir;
31 private static final int HELPME_ID = 1;
33 public Object _theObject;
35 private Object /* pick one type, and fixate on it */ dance(final String type, final String text) /* for inside the thread */
37 final Uploader thisupl = this;
38 final Message msg = Message.obtain();
41 Thread t = new Thread() {
44 int bogon = (int)SystemClock.elapsedRealtime();
46 NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
47 Notification notification = new Notification(R.drawable.icon, "Dumload prompt", System.currentTimeMillis());
49 Handler h = new Handler() {
50 public void handleMessage(Message M) {
52 Looper.myLooper().quit();
55 Messenger m = new Messenger(h);
57 Intent intent = new Intent(thisupl, NotifSlave.class);
59 intent.setAction("com.joshuawise.dumload.NotifSlave");
60 intent.putExtra("com.joshuawise.dumload.returnmessenger", m);
61 intent.putExtra("com.joshuawise.dumload.reqtype", type);
62 intent.putExtra("com.joshuawise.dumload.prompt", text);
63 intent.setData((Uri.parse("suckit://"+SystemClock.elapsedRealtime())));
65 PendingIntent contentIntent = PendingIntent.getActivity(thisupl, 0, intent, 0);
66 notification.defaults |= Notification.DEFAULT_VIBRATE;
67 notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
68 notification.setLatestEventInfo(getApplicationContext(), "I've been had!", "Dumload needs your input.", contentIntent);
70 Log.e("Dumload.Uploader[thread]", "Notifying...");
72 mNotificationManager.notify(bogon, notification);
74 Log.e("Dumload.Uploader[thread]", "About to go to 'sleep'...");
76 Log.e("Dumload.Uploader[thread]", "And we're alive!");
78 Log.e("Dumload.Uploader[thread]", "result was: "+(Integer.toString(msg.arg1)));
80 mNotificationManager.cancel(bogon);
87 } catch (Exception e) {
91 if (type.equals("yesno"))
92 return new Boolean(msg.arg1 == 1);
93 else if (type.equals("message"))
95 else if (type.equals("password")) {
98 Bundle b = msg.getData();
99 return b.getString("response");
105 String _password = null;
106 public String getPassword()
110 public boolean promptPassword(String message)
112 _password = (String)dance("password", message);
113 return (_password != null);
116 String _passphrase = null;
117 public String getPassphrase()
121 public boolean promptPassphrase(String message)
123 _passphrase = (String)dance("password", message);
124 return (_passphrase != null);
127 public boolean promptYesNo(String str)
129 return ((Boolean)dance("yesno", str)).booleanValue();
132 public void showMessage(String str)
134 dance("message", str);
137 public String[] promptKeyboardInteractive(String dest, String name, String instr, String[] prompt, boolean[] echo)
140 String [] responses = new String[prompt.length];
142 Log.e("Dumload.Uploader", "dest: "+dest);
143 Log.e("Dumload.Uploader", "name: "+name);
144 Log.e("Dumload.Uploader", "instr: "+instr);
145 for (i = 0; i < prompt.length; i++)
147 responses[i] = (String) dance("password", "[" + dest + "]\n" + prompt[i]);
157 Log.e("Dumload.Uploader[thread]", "This brought to you from the new thread.");
160 JSch jsch = new JSch();
161 jsch.setKnownHosts(homedir + "/known_hosts");
162 Session s = jsch.getSession("joshua", "nyus.joshuawise.com", 22);
166 Channel channel = s.openChannel("exec");
167 ((ChannelExec)channel).setCommand("echo foo > /tmp/lol");
170 dance("message", "done");
172 channel.disconnect();
174 } catch (JSchException e) {
175 Log.e("Dumload.uploader[thread]", "JSchException: "+(e.toString()));
179 Log.e("Dumload.uploader[thread]", "And now I'm back to life!");
182 private void say(String s) {
183 Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
187 public void onStart(Intent i, int startId)
190 homedir = getApplicationContext().getFilesDir().getAbsolutePath();
193 super.onStart(i, startId);
195 Log.e("Dumload.Uploader", "Started.");
196 Log.e("Dumload.Uploader", "My path is "+homedir);
199 InputStream is = getContentResolver().openInputStream(uri);
200 shits = is.available();
201 } catch (Exception e) {
204 say("Your shit was "+(Integer.toString(shits))+" bytes long");
206 me = new Thread(this, "Uploader thread");
211 public IBinder onBind(Intent i) {
212 Log.e("Dumload.Uploader", "bound");