Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java

Issue 21554002: Enable Android support for Chromoting PINless (paired) authentication (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting.jni; 5 package org.chromium.chromoting.jni;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.app.AlertDialog; 8 import android.app.AlertDialog;
9 import android.app.ProgressDialog; 9 import android.app.ProgressDialog;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.DialogInterface; 11 import android.content.DialogInterface;
12 import android.content.SharedPreferences;
12 import android.graphics.Bitmap; 13 import android.graphics.Bitmap;
13 import android.os.Looper; 14 import android.os.Looper;
14 import android.text.InputType; 15 import android.text.InputType;
15 import android.util.Log; 16 import android.util.Log;
16 import android.view.KeyEvent; 17 import android.view.KeyEvent;
18 import android.view.View;
17 import android.view.inputmethod.EditorInfo; 19 import android.view.inputmethod.EditorInfo;
18 import android.widget.EditText; 20 import android.widget.CheckBox;
19 import android.widget.TextView; 21 import android.widget.TextView;
20 import android.widget.Toast; 22 import android.widget.Toast;
21 23
22 import org.chromium.chromoting.R; 24 import org.chromium.chromoting.R;
23 25
24 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
25 import java.nio.ByteOrder; 27 import java.nio.ByteOrder;
26 28
27 /** 29 /**
28 * Initializes the Chromium remoting library, and provides JNI calls into it. 30 * Initializes the Chromium remoting library, and provides JNI calls into it.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 String hostJid, String hostId, String hostPubkey, Runnable successCa llback) { 87 String hostJid, String hostId, String hostPubkey, Runnable successCa llback) {
86 synchronized(JniInterface.class) { 88 synchronized(JniInterface.class) {
87 if (!sLoaded) return; 89 if (!sLoaded) return;
88 90
89 if (sConnected) { 91 if (sConnected) {
90 disconnectFromHost(); 92 disconnectFromHost();
91 } 93 }
92 } 94 }
93 95
94 sSuccessCallback = successCallback; 96 sSuccessCallback = successCallback;
95 connectNative(username, authToken, hostJid, hostId, hostPubkey); 97 SharedPreferences prefs = sContext.getPreferences(Activity.MODE_PRIVATE) ;
98 connectNative(username, authToken, hostJid, hostId, hostPubkey,
99 prefs.getString(hostId+"_id", ""), prefs.getString(hostId+"_secr et", ""));
garykac 2013/08/06 20:50:32 spaces around operators
solb 2013/08/07 04:30:46 "I don't know how those [failed to get] there..."
96 sConnected = true; 100 sConnected = true;
97 } 101 }
98 102
99 /** Severs the connection and cleans up. */ 103 /** Severs the connection and cleans up. */
100 public static void disconnectFromHost() { 104 public static void disconnectFromHost() {
101 synchronized(JniInterface.class) { 105 synchronized(JniInterface.class) {
102 if (!sLoaded || !sConnected) return; 106 if (!sLoaded || !sConnected) return;
103 107
104 if (sProgressIndicator != null) { 108 if (sProgressIndicator != null) {
105 sProgressIndicator.dismiss(); 109 sProgressIndicator.dismiss();
106 sProgressIndicator = null; 110 sProgressIndicator = null;
107 } 111 }
108 } 112 }
109 113
110 disconnectNative(); 114 disconnectNative();
111 sSuccessCallback = null; 115 sSuccessCallback = null;
112 sConnected = false; 116 sConnected = false;
113 } 117 }
114 118
115 /** Performs the native portion of the connection. */ 119 /** Performs the native portion of the connection. */
116 private static native void connectNative( 120 private static native void connectNative(String username, String authToken, String hostJid,
117 String username, String authToken, String hostJid, String hostId, St ring hostPubkey); 121 String hostId, String hostPubkey, String pairId, String pairSecret);
118 122
119 /** Performs the native portion of the cleanup. */ 123 /** Performs the native portion of the cleanup. */
120 private static native void disconnectNative(); 124 private static native void disconnectNative();
121 125
122 /* 126 /*
123 * Entry points *from* the native code. 127 * Entry points *from* the native code.
124 */ 128 */
125 /** Callback to signal whenever we need to redraw. */ 129 /** Callback to signal whenever we need to redraw. */
126 private static Runnable sRedrawCallback = null; 130 private static Runnable sRedrawCallback = null;
127 131
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 185 }
182 } 186 }
183 187
184 /** Prompts the user to enter a PIN. */ 188 /** Prompts the user to enter a PIN. */
185 private static void displayAuthenticationPrompt() { 189 private static void displayAuthenticationPrompt() {
186 AlertDialog.Builder pinPrompt = new AlertDialog.Builder(sContext); 190 AlertDialog.Builder pinPrompt = new AlertDialog.Builder(sContext);
187 pinPrompt.setTitle(sContext.getString(R.string.pin_entry_title)); 191 pinPrompt.setTitle(sContext.getString(R.string.pin_entry_title));
188 pinPrompt.setMessage(sContext.getString(R.string.pin_entry_message)); 192 pinPrompt.setMessage(sContext.getString(R.string.pin_entry_message));
189 pinPrompt.setIcon(android.R.drawable.ic_lock_lock); 193 pinPrompt.setIcon(android.R.drawable.ic_lock_lock);
190 194
191 final EditText pinEntry = new EditText(sContext); 195 final View pinEntry = sContext.getLayoutInflater().inflate(R.layout.pin_ dialog, null);
192 pinEntry.setInputType(
193 InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PA SSWORD);
194 pinEntry.setImeOptions(EditorInfo.IME_ACTION_DONE);
195 pinPrompt.setView(pinEntry); 196 pinPrompt.setView(pinEntry);
196 197
197 pinPrompt.setPositiveButton( 198 pinPrompt.setPositiveButton(
198 R.string.pin_entry_connect, new DialogInterface.OnClickListener( ) { 199 R.string.pin_entry_connect, new DialogInterface.OnClickListener( ) {
199 @Override 200 @Override
200 public void onClick(DialogInterface dialog, int which) { 201 public void onClick(DialogInterface dialog, int which) {
201 Log.i("jniiface", "User provided a PIN code"); 202 Log.i("jniiface", "User provided a PIN code");
202 authenticationResponse(String.valueOf(pinEntry.getText() )); 203 authenticationResponse(String.valueOf(((TextView)pinEntr y.findViewById(
204 R.id.pin_dialog_text)).getText()), ((CheckBox)pi nEntry.findViewById(
205 R.id.pin_dialog_check)).isChecked());
garykac 2013/08/06 20:50:32 Those parameters jumble together into a mess. Som
solb 2013/08/07 04:30:46 After playing with this line, I settled upon the s
203 } 206 }
204 }); 207 });
205 208
206 pinPrompt.setNegativeButton( 209 pinPrompt.setNegativeButton(
207 R.string.pin_entry_cancel, new DialogInterface.OnClickListener() { 210 R.string.pin_entry_cancel, new DialogInterface.OnClickListener() {
208 @Override 211 @Override
209 public void onClick(DialogInterface dialog, int which) { 212 public void onClick(DialogInterface dialog, int which) {
210 Log.i("jniiface", "User canceled pin entry prompt"); 213 Log.i("jniiface", "User canceled pin entry prompt");
211 Toast.makeText(sContext, 214 Toast.makeText(sContext,
212 sContext.getString(R.string.msg_pin_canceled), 215 sContext.getString(R.string.msg_pin_canceled),
213 Toast.LENGTH_LONG).show(); 216 Toast.LENGTH_LONG).show();
214 disconnectFromHost(); 217 disconnectFromHost();
215 } 218 }
216 }); 219 });
217 220
218 final AlertDialog pinDialog = pinPrompt.create(); 221 final AlertDialog pinDialog = pinPrompt.create();
219 222
220 pinEntry.setOnEditorActionListener( 223 ((TextView)pinEntry.findViewById(R.id.pin_dialog_text)).setOnEditorActio nListener(
221 new TextView.OnEditorActionListener() { 224 new TextView.OnEditorActionListener() {
222 @Override 225 @Override
223 public boolean onEditorAction(TextView v, int actionId, KeyE vent event) { 226 public boolean onEditorAction(TextView v, int actionId, KeyE vent event) {
224 // The user pressed enter on the keypad (equivalent to t he connect button). 227 // The user pressed enter on the keypad (equivalent to t he connect button).
225 pinDialog.getButton(AlertDialog.BUTTON_POSITIVE).perform Click(); 228 pinDialog.getButton(AlertDialog.BUTTON_POSITIVE).perform Click();
226 pinDialog.dismiss(); 229 pinDialog.dismiss();
227 return true; 230 return true;
228 } 231 }
229 }); 232 });
230 233
231 pinDialog.setOnCancelListener( 234 pinDialog.setOnCancelListener(
232 new DialogInterface.OnCancelListener() { 235 new DialogInterface.OnCancelListener() {
233 @Override 236 @Override
234 public void onCancel(DialogInterface dialog) { 237 public void onCancel(DialogInterface dialog) {
235 // The user backed out of the dialog (equivalent to the cancel button). 238 // The user backed out of the dialog (equivalent to the cancel button).
236 pinDialog.getButton(AlertDialog.BUTTON_NEGATIVE).perform Click(); 239 pinDialog.getButton(AlertDialog.BUTTON_NEGATIVE).perform Click();
237 } 240 }
238 }); 241 });
239 242
240 pinDialog.show(); 243 pinDialog.show();
241 } 244 }
242 245
246 /** Saves newly-received pairing credentials to permanent storage. */
247 private static void commitPairingCredentials(String host, byte[] id, byte[] secret) {
248 synchronized (sContext) {
249 sContext.getPreferences(Activity.MODE_PRIVATE).edit().
250 putString(host+"_id", new String(id)).
garykac 2013/08/06 20:50:32 spaces around operators
solb 2013/08/07 04:30:46 Sorry!
251 putString(host+"_secret", new String(secret)).
252 apply();
253 }
254 }
255
243 /** 256 /**
244 * Sets the redraw callback to the provided functor. Provide a value of null whenever the 257 * Sets the redraw callback to the provided functor. Provide a value of null whenever the
245 * window is no longer visible so that we don't continue to draw onto it. 258 * window is no longer visible so that we don't continue to draw onto it.
246 */ 259 */
247 public static void provideRedrawCallback(Runnable redrawCallback) { 260 public static void provideRedrawCallback(Runnable redrawCallback) {
248 sRedrawCallback = redrawCallback; 261 sRedrawCallback = redrawCallback;
249 } 262 }
250 263
251 /** Forces the native graphics thread to redraw to the canvas. */ 264 /** Forces the native graphics thread to redraw to the canvas. */
252 public static boolean redrawGraphics() { 265 public static boolean redrawGraphics() {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 /** Presses and releases the specified (nonnegative) key. */ 310 /** Presses and releases the specified (nonnegative) key. */
298 public static void keyboardAction(int keyCode, boolean keyDown) { 311 public static void keyboardAction(int keyCode, boolean keyDown) {
299 if (!sConnected) { 312 if (!sConnected) {
300 return; 313 return;
301 } 314 }
302 315
303 keyboardActionNative(keyCode, keyDown); 316 keyboardActionNative(keyCode, keyDown);
304 } 317 }
305 318
306 /** Performs the native response to the user's PIN. */ 319 /** Performs the native response to the user's PIN. */
307 private static native void authenticationResponse(String pin); 320 private static native void authenticationResponse(String pin, boolean create Pair);
308 321
309 /** Schedules a redraw on the native graphics thread. */ 322 /** Schedules a redraw on the native graphics thread. */
310 private static native void scheduleRedrawNative(); 323 private static native void scheduleRedrawNative();
311 324
312 /** Passes mouse information to the native handling code. */ 325 /** Passes mouse information to the native handling code. */
313 private static native void mouseActionNative(int x, int y, int whichButton, boolean buttonDown); 326 private static native void mouseActionNative(int x, int y, int whichButton, boolean buttonDown);
314 327
315 /** Passes key press information to the native handling code. */ 328 /** Passes key press information to the native handling code. */
316 private static native void keyboardActionNative(int keyCode, boolean keyDown ); 329 private static native void keyboardActionNative(int keyCode, boolean keyDown );
317 } 330 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698