Skip to content

Commit

Permalink
allow to open AutoOpenEntries manually if they are not "Enabled" (but…
Browse files Browse the repository at this point in the history
… "Visible"). Don't suggest to configure fingerprint unlock for child databases.
  • Loading branch information
Philipp Crocoll committed Nov 19, 2018
1 parent 183c171 commit ef8b9b0
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/keepass2android/AutoOpenEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public override string GetTitle(string key)
if (key == strVisible)
return Application.Context.GetString(Resource.String.Visible_title);
if (key == strEnabled)
return Application.Context.GetString(Resource.String.Enabled_title);
return Application.Context.GetString(Resource.String.child_db_Enabled_title);
if (key == strUiKeyFile)
return Application.Context.GetString(Resource.String.keyfile_heading);
if (key == strUiDatabaseFile)
Expand Down
1 change: 0 additions & 1 deletion src/keepass2android/ConfigureChildDatabasesActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ public void Update()
private void OnOpen(AutoExecItem item)
{
KeeAutoExecExt.AutoOpenEntry(this, item, true);

}

private void OnEnableCopy(AutoExecItem item)
Expand Down
2 changes: 1 addition & 1 deletion src/keepass2android/GroupBaseActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ private void UpdateFingerprintInfo()

bool disabledForDatabase = _prefs.GetBoolean(fingerprintinfohidden_prefskey + App.Kp2a.CurrentDb.CurrentFingerprintPrefKey, false);
bool disabledForAll = _prefs.GetBoolean(fingerprintinfohidden_prefskey, false);
if (!disabledForAll && !disabledForDatabase)
if (!disabledForAll && !disabledForDatabase && !App.Kp2a.IsChildDatabase(App.Kp2a.CurrentDb))
{

FingerprintModule fpModule = new FingerprintModule(this);
Expand Down
3 changes: 3 additions & 0 deletions src/keepass2android/KeeAutoExec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ public static bool AutoOpenEntry(Activity activity, AutoExecItem item, bool bMan

PasswordActivity.Launch(activity,ioc,ck,new ActivityLaunchModeSimple(), !
bRestoreFocus);

App.Kp2a.RegisterChildDatabase(ioc);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="2dip" />
<solid android:color="#bbb" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="2dip" />
<solid android:color="#ccc"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="2dip" />
<solid android:color="#ccc" />
</shape>
</item>
</selector>
2 changes: 1 addition & 1 deletion src/keepass2android/Resources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@
<string name="EnableCopyForThisDevice_Info">This will create and enable a copy of the child database settings. These copied settings can then be adjusted specifically for this device.</string>

<string name="Visible_title">Visible</string>
<string name="Enabled_title">Enabled</string>
<string name="child_db_Enabled_title">Open automatically</string>
<string name="database_file_heading">Database file</string>
<string name="if_device_text">Enable for %1$s</string>

Expand Down
46 changes: 39 additions & 7 deletions src/keepass2android/SelectCurrentDbActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Java.Net;
using keepass2android.Io;
using keepass2android.Utils;
using KeePassLib;
using KeePassLib.Keys;
using KeePassLib.Serialization;
using Object = Java.Lang.Object;
Expand All @@ -37,6 +38,7 @@ public class OpenDatabaseAdapter : BaseAdapter

private readonly SelectCurrentDbActivity _context;
internal List<Database> _displayedDatabases;
internal List<AutoExecItem> _autoExecItems;

public OpenDatabaseAdapter(SelectCurrentDbActivity context)
{
Expand Down Expand Up @@ -75,7 +77,7 @@ public override View GetView(int position, View convertView, ViewGroup parent)
btn = new Button(_context);
btn.LayoutParameters = new GridView.LayoutParams((int) convertDpToPixel(140, _context),
(int) convertDpToPixel(150, _context));
btn.SetBackgroundResource(Resource.Drawable.storagetype_button_bg);

btn.SetPadding((int) convertDpToPixel(4, _context),
(int) convertDpToPixel(20, _context),
(int) convertDpToPixel(4, _context),
Expand All @@ -89,11 +91,12 @@ public override View GetView(int position, View convertView, ViewGroup parent)
int pos;
int.TryParse(((Button) sender).Tag.ToString(), out pos);
if (pos < _displayedDatabases.Count)
_context.OnItemSelected(_displayedDatabases[pos]);
_context.OnDatabaseSelected(_displayedDatabases[pos]);
else if (pos < _displayedDatabases.Count + _autoExecItems.Count)
_context.OnAutoExecItemSelected(_autoExecItems[pos - _displayedDatabases.Count]);
else
{
_context.OnOpenOther();
}
};
}
else
Expand All @@ -111,9 +114,18 @@ public override View GetView(int position, View convertView, ViewGroup parent)
drawable = App.Kp2a.GetResourceDrawable("ic_storage_" + Util.GetProtocolId(db.Ioc));
displayName = db.KpDatabase.Name;
displayName += "\n" + App.Kp2a.GetFileStorage(db.Ioc).GetDisplayName(db.Ioc);
btn.SetBackgroundResource(Resource.Drawable.storagetype_button_bg);
}
else if (position < _displayedDatabases.Count + _autoExecItems.Count)
{
var item = _autoExecItems[position - _displayedDatabases.Count];
drawable = App.Kp2a.GetResourceDrawable("ic_nav_changedb");
displayName = item.Entry.Strings.ReadSafe(PwDefs.TitleField);
btn.SetBackgroundResource(Resource.Drawable.storagetype_button_bg_dark);
}
else
{
btn.SetBackgroundResource(Resource.Drawable.storagetype_button_bg);
displayName = _context.GetString(Resource.String.start_open_file);
drawable = App.Kp2a.GetResourceDrawable("ic_nav_changedb");
}
Expand All @@ -129,21 +141,41 @@ public override View GetView(int position, View convertView, ViewGroup parent)

public override int Count
{
get { return _displayedDatabases.Count+1; }
get { return _displayedDatabases.Count+_autoExecItems.Count+1; }
}

public void Update()
{
string thisDevice = KeeAutoExecExt.ThisDeviceId;
_displayedDatabases = App.Kp2a.OpenDatabases.ToList();
_autoExecItems = App.Kp2a.OpenDatabases
.SelectMany(db => KeeAutoExecExt.GetAutoExecItems(db.KpDatabase))
.Where(item =>
item.Visible
&&
KeeAutoExecExt.IsDeviceEnabled(item, thisDevice, out _)
&&
!_displayedDatabases.Any(displayedDb =>
{
IOConnectionInfo itemIoc;
return KeeAutoExecExt.TryGetDatabaseIoc(item, out itemIoc) &&
displayedDb.Ioc.IsSameFileAs(itemIoc);
}))
.ToList();
}
}

private void OnAutoExecItemSelected(AutoExecItem autoExecItem)
{
KeeAutoExecExt.AutoOpenEntry(this, autoExecItem, true);
}

private void OnOpenOther()
{
StartFileSelect(true, true);
}

private void OnItemSelected(Database selectedDatabase)
private void OnDatabaseSelected(Database selectedDatabase)
{
App.Kp2a.CurrentDb = selectedDatabase;
LaunchingOther = true;
Expand Down Expand Up @@ -177,7 +209,7 @@ protected override void OnCreate(Bundle savedInstanceState)

_adapter = new OpenDatabaseAdapter(this);
var gridView = FindViewById<GridView>(Resource.Id.gridview);
gridView.ItemClick += (sender, args) => OnItemSelected(_adapter._displayedDatabases[args.Position]);

gridView.Adapter = _adapter;

if (!string.IsNullOrEmpty(Intent.GetStringExtra(Util.KeyFilename)))
Expand Down
14 changes: 13 additions & 1 deletion src/keepass2android/app/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,16 @@ public void SetQuickUnlockEnabled(bool enabled)

private readonly List<IOConnectionInfo> _openAttempts = new List<IOConnectionInfo>(); //stores which files have been attempted to open. Used to avoid that we repeatedly try to load files which failed to load.
private readonly List<Database> _openDatabases = new List<Database>();
private Database _currentDatabase;
private readonly List<IOConnectionInfo> _childDatabases = new List<IOConnectionInfo>(); //list of databases which were opened as child databases
private Database _currentDatabase;

public IEnumerable<Database> OpenDatabases
{
get { return _openDatabases; }
}

public readonly HashSet<PwGroup> dirty = new HashSet<PwGroup>(new PwGroupEqualityFromIdComparer());

public HashSet<PwGroup> DirtyGroups { get { return dirty; } }

public bool AttemptedToOpenBefore(IOConnectionInfo ioc)
Expand Down Expand Up @@ -1087,6 +1089,16 @@ public Database TryFindDatabaseForElement(IStructureItem element)
}
return null;
}

public void RegisterChildDatabase(IOConnectionInfo ioc)
{
_childDatabases.Add(ioc);
}

public bool IsChildDatabase(Database db)
{
return _childDatabases.Any(ioc => ioc.IsSameFileAs(db.Ioc));
}
}


Expand Down
1 change: 1 addition & 0 deletions src/keepass2android/fileselect/FileSelectActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ protected override void OnCreate(Bundle savedInstanceState)
{
//ShowFilenameDialog(false, true, true, Android.OS.Environment.ExternalStorageDirectory + GetString(Resource.String.default_file_path), "", Intents.RequestCodeFileBrowseForCreate)
Intent i = new Intent(this, typeof (CreateDatabaseActivity));
i.PutExtra("MakeCurrent", Intent.GetBooleanExtra("MakeCurrent", true));
i.SetFlags(ActivityFlags.ForwardResult);
StartActivity(i);
Expand Down
5 changes: 5 additions & 0 deletions src/keepass2android/keepass2android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,11 @@
<ItemGroup>
<AndroidResource Include="Resources\layout\config_child_db.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\storagetype_button_bg_dark.xml">
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
Expand Down

0 comments on commit ef8b9b0

Please sign in to comment.