more fdroid build cleanup of google services

This commit is contained in:
Kyle Spearrin 2019-06-13 10:06:08 -04:00
parent a6ea2de691
commit 2fe67137c5
2 changed files with 88 additions and 10 deletions

View file

@ -2,6 +2,8 @@
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Android.App; using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime; using Android.Runtime;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Services; using Bit.App.Services;
@ -13,7 +15,9 @@ using Bit.Droid.Services;
using Bit.Droid.Utilities; using Bit.Droid.Utilities;
using Plugin.CurrentActivity; using Plugin.CurrentActivity;
using Plugin.Fingerprint; using Plugin.Fingerprint;
using Plugin.Fingerprint.Abstractions; #if !FDROID
using Android.Gms.Security;
#endif
namespace Bit.Droid namespace Bit.Droid
{ {
@ -23,7 +27,11 @@ namespace Bit.Droid
[Application(Debuggable = false)] [Application(Debuggable = false)]
#endif #endif
[Register("com.x8bit.bitwarden.MainApplication")] [Register("com.x8bit.bitwarden.MainApplication")]
#if FDROID
public class MainApplication : Application public class MainApplication : Application
#else
public class MainApplication : Application, ProviderInstaller.IProviderInstallListener
#endif
{ {
public MainApplication(IntPtr handle, JniHandleOwnership transer) public MainApplication(IntPtr handle, JniHandleOwnership transer)
: base(handle, transer) : base(handle, transer)
@ -38,6 +46,12 @@ namespace Bit.Droid
Task.Delay(2000).Wait(); Task.Delay(2000).Wait();
} }
} }
#if !FDROID
if(Build.VERSION.SdkInt <= BuildVersionCodes.Kitkat)
{
ProviderInstaller.InstallIfNeededAsync(ApplicationContext, this);
}
#endif
} }
public override void OnCreate() public override void OnCreate()
@ -47,6 +61,14 @@ namespace Bit.Droid
CrossCurrentActivity.Current.Init(this); CrossCurrentActivity.Current.Init(this);
} }
public void OnProviderInstallFailed(int errorCode, Intent recoveryIntent)
{
}
public void OnProviderInstalled()
{
}
private void RegisterLocalServices() private void RegisterLocalServices()
{ {
ServiceContainer.Register<ILogService>("logService", new AndroidLogService()); ServiceContainer.Register<ILogService>("logService", new AndroidLogService());
@ -73,7 +95,7 @@ namespace Bit.Droid
CrossFingerprint.SetDialogFragmentType<CustomFingerprintDialogFragment>(); CrossFingerprint.SetDialogFragmentType<CustomFingerprintDialogFragment>();
var preferencesStorage = new PreferencesStorageService(null); var preferencesStorage = new PreferencesStorageService(null);
var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var liteDbStorage = new LiteDbStorageService(Path.Combine(documentsPath, "bitwarden.db")); var liteDbStorage = new LiteDbStorageService(Path.Combine(documentsPath, "bitwarden.db"));
liteDbStorage.InitAsync(); liteDbStorage.InitAsync();
var localizeService = new LocalizeService(); var localizeService = new LocalizeService();

View file

@ -3,7 +3,9 @@
$androidPath = $($rootPath + "\src\Android\Android.csproj"); $androidPath = $($rootPath + "\src\Android\Android.csproj");
$appPath = $($rootPath + "\src\App\App.csproj"); $appPath = $($rootPath + "\src\App\App.csproj");
echo "########################################"
echo "##### Increment Version" echo "##### Increment Version"
echo "########################################"
$androidManifest = $($rootPath + "\src\Android\Properties\AndroidManifest.xml"); $androidManifest = $($rootPath + "\src\Android\Properties\AndroidManifest.xml");
@ -15,35 +17,73 @@ $node.SetAttribute("android:versionCode", $env:APPVEYOR_BUILD_NUMBER);
$xml.Save($androidManifest); $xml.Save($androidManifest);
echo "########################################"
echo "##### Decrypt Keystore" echo "##### Decrypt Keystore"
echo "########################################"
$encKeystorePath = $($rootPath + "\src\Android\8bit.keystore.enc"); $encKeystorePath = $($rootPath + "\src\Android\8bit.keystore.enc");
$secureFilePath = $($rootPath + "\secure-file\tools\secure-file.exe"); $secureFilePath = $($rootPath + "\secure-file\tools\secure-file.exe");
Invoke-Expression "& `"$secureFilePath`" -decrypt $($encKeystorePath) -secret $($env:keystore_dec_secret)" Invoke-Expression "& `"$secureFilePath`" -decrypt $($encKeystorePath) -secret $($env:keystore_dec_secret)"
echo "########################################"
echo "##### Sign Release Configuration" echo "##### Sign Release Configuration"
echo "########################################"
msbuild "$($androidPath)" "/t:SignAndroidPackage" "/p:Configuration=Release" "/p:AndroidKeyStore=true" "/p:AndroidSigningKeyAlias=bitwarden" "/p:AndroidSigningKeyPass=$($env:keystore_password)" "/p:AndroidSigningKeyStore=8bit.keystore" "/p:AndroidSigningStorePass=$($env:keystore_password)" "/v:quiet" msbuild "$($androidPath)" "/t:SignAndroidPackage" "/p:Configuration=Release" "/p:AndroidKeyStore=true" `
"/p:AndroidSigningKeyAlias=bitwarden" "/p:AndroidSigningKeyPass=$($env:keystore_password)" `
"/p:AndroidSigningKeyStore=8bit.keystore" "/p:AndroidSigningStorePass=$($env:keystore_password)" "/v:quiet"
echo "########################################"
echo "##### Copy Release apk to project root" echo "##### Copy Release apk to project root"
echo "########################################"
$signedApkPath = $($rootPath + "\src\Android\bin\Release\com.x8bit.bitwarden-Signed.apk"); $signedApkPath = $($rootPath + "\src\Android\bin\Release\com.x8bit.bitwarden-Signed.apk");
$signedApkDestPath = $($rootPath + "\com.x8bit.bitwarden.apk"); $signedApkDestPath = $($rootPath + "\com.x8bit.bitwarden.apk");
Copy-Item $signedApkPath $signedApkDestPath Copy-Item $signedApkPath $signedApkDestPath
echo "########################################"
echo "##### Clean Android and App" echo "##### Clean Android and App"
echo "########################################"
msbuild "$($androidPath)" "/t:Clean" "/p:Configuration=FDroid" msbuild "$($androidPath)" "/t:Clean" "/p:Configuration=FDroid"
msbuild "$($appPath)" "/t:Clean" "/p:Configuration=FDroid" msbuild "$($appPath)" "/t:Clean" "/p:Configuration=FDroid"
echo "########################################"
echo "##### Backup project files" echo "##### Backup project files"
echo "########################################"
Copy-Item $androidManifest $($androidManifest + ".original");
Copy-Item $androidPath $($androidPath + ".original"); Copy-Item $androidPath $($androidPath + ".original");
Copy-Item $appPath $($appPath + ".original"); Copy-Item $appPath $($appPath + ".original");
echo "########################################"
echo "##### Cleanup Android Manifest"
echo "########################################"
$xml=New-Object XML;
$xml.Load($androidManifest);
$nsAndroid=New-Object System.Xml.XmlNamespaceManager($xml.NameTable);
$nsAndroid.AddNamespace("android", "http://schemas.android.com/apk/res/android");
$firebaseReceiver1=$xml.SelectSingleNode(`
"/manifest/application/receiver[@android:name='com.google.firebase.iid.FirebaseInstanceIdInternalReceiver']", `
$nsAndroid);
$firebaseReceiver1.ParentNode.RemoveChild($firebaseReceiver1);
$firebaseReceiver2=$xml.SelectSingleNode(`
"/manifest/application/receiver[@android:name='com.google.firebase.iid.FirebaseInstanceIdReceiver']", `
$nsAndroid);
$firebaseReceiver2.ParentNode.RemoveChild($firebaseReceiver2);
$xml.Save($androidManifest);
echo "########################################"
echo "##### Uninstall from Android.csproj" echo "##### Uninstall from Android.csproj"
echo "########################################"
$xml=New-Object XML; $xml=New-Object XML;
$xml.Load($androidPath); $xml.Load($androidPath);
@ -51,12 +91,19 @@ $xml.Load($androidPath);
$ns=New-Object System.Xml.XmlNamespaceManager($xml.NameTable); $ns=New-Object System.Xml.XmlNamespaceManager($xml.NameTable);
$ns.AddNamespace("ns", $xml.DocumentElement.NamespaceURI); $ns.AddNamespace("ns", $xml.DocumentElement.NamespaceURI);
$firebaseNode=$xml.SelectSingleNode("/ns:Project/ns:ItemGroup/ns:PackageReference[@Include='Xamarin.Firebase.Messaging']", $ns); $firebaseNode=$xml.SelectSingleNode(`
"/ns:Project/ns:ItemGroup/ns:PackageReference[@Include='Xamarin.Firebase.Messaging']", $ns);
$firebaseNode.ParentNode.RemoveChild($firebaseNode); $firebaseNode.ParentNode.RemoveChild($firebaseNode);
$safetyNetNode=$xml.SelectSingleNode(`
"/ns:Project/ns:ItemGroup/ns:PackageReference[@Include='Xamarin.GooglePlayServices.SafetyNet']", $ns);
$safetyNetNode.ParentNode.RemoveChild($safetyNetNode);
$xml.Save($androidPath); $xml.Save($androidPath);
echo "########################################"
echo "##### Uninstall from App.csproj" echo "##### Uninstall from App.csproj"
echo "########################################"
$xml=New-Object XML; $xml=New-Object XML;
$xml.Load($appPath); $xml.Load($appPath);
@ -66,22 +113,31 @@ $hockeyNode.ParentNode.RemoveChild($hockeyNode);
$xml.Save($appPath); $xml.Save($appPath);
echo "########################################"
echo "##### Restore NuGet" echo "##### Restore NuGet"
echo "########################################"
$nugetPath = $($rootPath + "\nuget.exe");
Invoke-Expression "& nuget restore" Invoke-Expression "& nuget restore"
echo "########################################"
echo "##### Build and Sign FDroid Configuration" echo "##### Build and Sign FDroid Configuration"
echo "########################################"
msbuild "$($androidPath)" "/logger:C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" "/p:Configuration=FDroid" msbuild "$($androidPath)" "/logger:C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" `
msbuild "$($androidPath)" "/t:SignAndroidPackage" "/p:Configuration=FDroid" "/p:AndroidKeyStore=true" "/p:AndroidSigningKeyAlias=bitwarden" "/p:AndroidSigningKeyPass=$($env:keystore_password)" "/p:AndroidSigningKeyStore=8bit.keystore" "/p:AndroidSigningStorePass=$($env:keystore_password)" "/v:quiet" "/p:Configuration=FDroid"
msbuild "$($androidPath)" "/t:SignAndroidPackage" "/p:Configuration=FDroid" "/p:AndroidKeyStore=true" `
"/p:AndroidSigningKeyAlias=bitwarden" "/p:AndroidSigningKeyPass=$($env:keystore_password)" `
"/p:AndroidSigningKeyStore=8bit.keystore" "/p:AndroidSigningStorePass=$($env:keystore_password)" "/v:quiet"
echo "########################################"
echo "##### Copy FDroid apk to project root" echo "##### Copy FDroid apk to project root"
echo "########################################"
$signedApkPath = $($rootPath + "\src\Android\bin\FDroid\com.x8bit.bitwarden-Signed.apk"); $signedApkPath = $($rootPath + "\src\Android\bin\FDroid\com.x8bit.bitwarden-Signed.apk");
$signedApkDestPath = $($rootPath + "\com.x8bit.bitwarden-fdroid.apk"); $signedApkDestPath = $($rootPath + "\com.x8bit.bitwarden-fdroid.apk");
Copy-Item $signedApkPath $signedApkDestPath Copy-Item $signedApkPath $signedApkDestPath
echo "########################################"
echo "##### Done" echo "##### Done"
echo "########################################"