Skip to content

Commit c6fc626

Browse files
committed
Added detection and handling of errors around creating shortcuts and intents when master password is enabled.
1 parent 19fc905 commit c6fc626

File tree

7 files changed

+43
-17
lines changed

7 files changed

+43
-17
lines changed

eclipse_projects/bVNC/res/values-ru/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@
317317
<string name="master_password_error_failed_to_disable">Не удалось отключить Мастер-пароль. Проверьте свободное место на Вашем устройстве и повторите попытку.</string>
318318
<string name="master_password_error_password_necessary">Мастер-пароль требуется для того, чтобы продолжить.</string>
319319
<string name="master_password_error_password_not_set">Установка Мастер-пароля была отменена.</string>
320+
<string name="master_password_error_intents_not_supported">Connection intents are not yet supported when Master Password is enabled.</string>
321+
<string name="master_password_error_shortcuts_not_supported">Короткие сокращения пока не поддерживаются, когда мастер-пароль включена.</string>
320322
<string name="master_password_error_wrong_password">Невозможно проверить подлинность с этим Мастер-пароль.</string>
321323
<string name="master_password_hint_once">Введите Пароль</string>
322324
<string name="master_password_hint_twice">Повторите Пароль</string>

eclipse_projects/bVNC/res/values/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ If you are looking for a quick performance boost, try setting the Color mode to
318318
<string name="master_password_error_failed_to_disable">Could not disable master password. Check free space on your device and try again.</string>
319319
<string name="master_password_error_password_necessary">Master Password is required in order to continue.</string>
320320
<string name="master_password_error_password_not_set">Setting Master Password was cancelled.</string>
321+
<string name="master_password_error_intents_not_supported">Connection intents are not yet supported when Master Password is enabled.</string>
322+
<string name="master_password_error_shortcuts_not_supported">Short-cuts are not yet supported when Master Password is enabled.</string>
321323
<string name="master_password_error_wrong_password">Could not authenticate with provided Master Password.</string>
322324
<string name="master_password_hint_once">Enter Password</string>
323325
<string name="master_password_hint_twice">Repeat Password</string>

eclipse_projects/bVNC/src/com/iiordanov/bVNC/ConnectionListActivity.java

+14-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
package com.iiordanov.bVNC;
2222

2323
import android.app.ListActivity;
24+
import android.content.Context;
2425
import android.content.Intent;
26+
import android.content.SharedPreferences;
2527
import android.content.Intent.ShortcutIconResource;
2628
import android.database.Cursor;
2729
import android.net.Uri;
@@ -42,10 +44,11 @@ public class ConnectionListActivity extends ListActivity {
4244
protected void onCreate(Bundle savedInstanceState){
4345
super.onCreate(savedInstanceState);
4446

45-
try {
46-
database = new Database(this);
47-
} catch (Exception e) {
48-
Utils.showFatalErrorMessage(this, "ERROR, could not open database, could it be its encryped?");
47+
database = new Database(this);
48+
49+
if (isMasterPasswordEnabled()) {
50+
Utils.showFatalErrorMessage(this, getResources().getString(R.string.master_password_error_shortcuts_not_supported));
51+
return;
4952
}
5053

5154
// Query for all people contacts using the Contacts.People convenience class.
@@ -119,8 +122,14 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
119122
*/
120123
@Override
121124
protected void onDestroy() {
122-
database.close();
125+
if (database != null) {
126+
database.close();
127+
}
123128
super.onDestroy();
124129
}
125130

131+
private boolean isMasterPasswordEnabled() {
132+
SharedPreferences sp = getSharedPreferences(Constants.generalSettingsTag, Context.MODE_PRIVATE);
133+
return sp.getBoolean(Constants.masterPasswordEnabledTag, false);
134+
}
126135
}

eclipse_projects/bVNC/src/com/iiordanov/bVNC/Constants.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ public class Constants {
173173
public static final int numIterations = 10000;
174174
public static final int keyLength = 256;
175175
public static final int saltLength = 256;
176-
177-
176+
177+
public static final String generalSettingsTag = "generalSettings";
178+
public static final String masterPasswordEnabledTag = "masterPasswordEnabled";
179+
178180
/**
179181
* Returns a string matching a session selection index
180182
* @param index - index to convert

eclipse_projects/bVNC/src/com/iiordanov/bVNC/Database.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ public SQLiteDatabase getReadableDatabase() {
8282
return getReadableDatabase(Database.password);
8383
}
8484

85+
public static String getPassword() {
86+
return password;
87+
}
88+
8589
public static void setPassword (String newPassword) {
8690
Database.password = newPassword;
8791
}
@@ -343,8 +347,4 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
343347
oldVersion = DBV_2_1_4;
344348
}
345349
}
346-
347-
public static String getPassword() {
348-
return password;
349-
}
350350
}

eclipse_projects/bVNC/src/com/iiordanov/bVNC/MainConfiguration.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ public void onClick(DialogInterface dialog, int i)
341341
return true;
342342
}
343343

344-
private boolean isMasterPasswordEnabled () {
345-
SharedPreferences sp = getSharedPreferences("generalSettings", Context.MODE_PRIVATE);
346-
return sp.getBoolean("masterPasswordEnabled", false);
344+
private boolean isMasterPasswordEnabled() {
345+
SharedPreferences sp = getSharedPreferences(Constants.generalSettingsTag, Context.MODE_PRIVATE);
346+
return sp.getBoolean(Constants.masterPasswordEnabledTag, false);
347347
}
348348

349-
private void toggleMasterPasswordState () {
349+
private void toggleMasterPasswordState() {
350350
SharedPreferences sp = getSharedPreferences("generalSettings", Context.MODE_PRIVATE);
351351
boolean state = sp.getBoolean("masterPasswordEnabled", false);
352352
Editor editor = sp.edit();

eclipse_projects/bVNC/src/com/iiordanov/bVNC/RemoteCanvasActivity.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import android.content.Context;
3737
import android.content.DialogInterface;
3838
import android.content.Intent;
39+
import android.content.SharedPreferences;
3940
import android.content.res.Configuration;
4041
import android.database.Cursor;
4142
import android.graphics.Rect;
@@ -138,7 +139,7 @@ public void onCreate(Bundle icicle) {
138139
super.onCreate(icicle);
139140
Utils.showMenu(this);
140141
initialize();
141-
if (connection.isReadyForConnection())
142+
if (connection != null && connection.isReadyForConnection())
142143
continueConnecting();
143144
}
144145

@@ -161,8 +162,13 @@ void initialize () {
161162

162163
Uri data = i.getData();
163164
if ((data != null) && (data.getScheme().equals("vnc")) || !Utils.isNullOrEmptry(i.getType())) {
165+
if (isMasterPasswordEnabled()) {
166+
Utils.showFatalErrorMessage(this, getResources().getString(R.string.master_password_error_intents_not_supported));
167+
return;
168+
}
169+
164170
connection = ConnectionBean.createLoadFromUri(data, this);
165-
171+
166172
String host = data.getHost();
167173
if (!host.startsWith(Constants.CONNECTION)) {
168174
connection.parseFromUri(data);
@@ -1328,4 +1334,9 @@ protected void onSaveInstanceState(Bundle outState) {
13281334
outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
13291335
super.onSaveInstanceState(outState);
13301336
}
1337+
1338+
private boolean isMasterPasswordEnabled() {
1339+
SharedPreferences sp = getSharedPreferences(Constants.generalSettingsTag, Context.MODE_PRIVATE);
1340+
return sp.getBoolean(Constants.masterPasswordEnabledTag, false);
1341+
}
13311342
}

0 commit comments

Comments
 (0)