Skip to content

Commit

Permalink
remove "singleTask" launch mode on Android 11+ (#1673)
Browse files Browse the repository at this point in the history
* remove "singleTask" launch mode on Android 12+

* remove commented and unneccesary code

* fix formatting and change from Android 12 to Android 11
  • Loading branch information
jlf0dev committed Dec 6, 2021
1 parent ea1ee2c commit 05bcc10
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 25 deletions.
5 changes: 5 additions & 0 deletions src/Android/Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@
<AndroidResource Include="Resources\values-night\styles.xml" />
<AndroidResource Include="Resources\values\styles.xml" />
<AndroidResource Include="Resources\values\colors.xml" />
<AndroidResource Include="Resources\values\manifest.xml" />
<AndroidResource Include="Resources\values-v30\manifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\splash_screen.xml" />
Expand Down Expand Up @@ -271,5 +273,8 @@
<SubType>Designer</SubType>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\values-v30\" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
33 changes: 13 additions & 20 deletions src/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,10 @@

namespace Bit.Droid
{
[Activity(
Label = "Bitwarden",
Icon = "@mipmap/ic_launcher",
Theme = "@style/LaunchTheme",
MainLauncher = true,
LaunchMode = LaunchMode.SingleTask,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation |
ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden |
ConfigChanges.Navigation | ConfigChanges.UiMode)]
[IntentFilter(
new[] { Intent.ActionSend },
Categories = new[] { Intent.CategoryDefault },
DataMimeTypes = new[]
{
@"application/*",
@"image/*",
@"video/*",
@"text/*"
})]
// Activity and IntentFilter declarations have been moved to Properties/AndroidManifest.xml
// They have been hardcoded so we can use the default LaunchMode on Android 11+
// LaunchMode defined in values/manifest.xml for Android 10- and values-v30/manifest.xml for Android 11+
// See https://github.com/bitwarden/mobile/pull/1673 for details
[Register("com.x8bit.bitwarden.MainActivity")]
public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
Expand Down Expand Up @@ -159,7 +144,15 @@ protected override void OnNewIntent(Intent intent)
base.OnNewIntent(intent);
try
{
if (intent.GetBooleanExtra("generatorTile", false))
if (intent?.GetStringExtra("uri") is string uri)
{
_messagingService.Send("popAllAndGoToAutofillCiphers");
if (_appOptions != null)
{
_appOptions.Uri = uri;
}
}
else if (intent.GetBooleanExtra("generatorTile", false))
{
_messagingService.Send("popAllAndGoToTabGenerator");
if (_appOptions != null)
Expand Down
28 changes: 25 additions & 3 deletions src/Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,35 @@

<!-- Support for LG "Dual Window" mode (for Android < 7.0 users) -->
<meta-data android:name="com.lge.support.SPLIT_WINDOW" android:value="true" />
<!-- Declare MainActivity manually so we can set LaunchMode using API dependant resource -->
<activity
android:name="com.x8bit.bitwarden.MainActivity"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|uiMode"
android:exported="true"
android:icon="@mipmap/ic_launcher"
android:label="Bitwarden"
android:launchMode="@integer/launchModeAPIlevel"
android:theme="@style/LaunchTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/*" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
<data android:mimeType="text/*" />
</intent-filter>
</activity>
</application>

<!-- Package visibility (for Android 11+) -->
<queries>
<intent>
<action android:name="*"/>
</intent>
<intent>
<action android:name="*"/>
</intent>
</queries>

</manifest>
4 changes: 4 additions & 0 deletions src/Android/Resources/values-v30/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<integer name="launchModeAPIlevel">0</integer>
</resources>
4 changes: 4 additions & 0 deletions src/Android/Resources/values/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<integer name="launchModeAPIlevel">2</integer>
</resources>
9 changes: 7 additions & 2 deletions src/App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public App(AppOptions appOptions)
}
else if (message.Command == "popAllAndGoToTabGenerator" ||
message.Command == "popAllAndGoToTabMyVault" ||
message.Command == "popAllAndGoToTabSend")
message.Command == "popAllAndGoToTabSend" ||
message.Command == "popAllAndGoToAutofillCiphers")
{
Device.BeginInvokeOnMainThread(async () =>
{
Expand All @@ -123,7 +124,11 @@ public App(AppOptions appOptions)
{
await tabsPage.Navigation.PopModalAsync(false);
}
if (message.Command == "popAllAndGoToTabMyVault")
if (message.Command == "popAllAndGoToAutofillCiphers")
{
Current.MainPage = new NavigationPage(new AutofillCiphersPage(Options));
}
else if (message.Command == "popAllAndGoToTabMyVault")
{
Options.MyVaultTile = false;
tabsPage.ResetToVaultPage();
Expand Down

0 comments on commit 05bcc10

Please sign in to comment.