Skip to content

Commit

Permalink
Merge pull request #141 from se1exin/issue/126
Browse files Browse the repository at this point in the history
Issue/126 - Android Autofill
  • Loading branch information
perry-mitchell authored Apr 21, 2019
2 parents 75fdbdf + b0ccb65 commit 788c4b4
Show file tree
Hide file tree
Showing 27 changed files with 1,510 additions and 149 deletions.
39 changes: 24 additions & 15 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@ android {
}
}
buildTypes {
debug {
// Fix for RN Debug on Android 8 - https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted/50834600#50834600
manifestPlaceholders = [usesCleartextTraffic:"true"]
}
release {
manifestPlaceholders = [usesCleartextTraffic:"false"]
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
Expand All @@ -140,24 +145,28 @@ android {
jni.srcDirs = [/*'src/main/jniLibs', 'src/main/jniLibs/'*/]
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile project(':react-native-keychain')
compile project(':react-native-secure-storage')
compile project(':react-native-touch-id')
compile project(':react-native-randombytes')
compile project(':@yfuks/react-native-action-sheet')
compile project(':react-native-vector-icons')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.madgag.spongycastle:prov:1.56.0.0"
testCompile "junit:junit:4.12"
androidTestCompile "junit:junit:4.12"
androidTestCompile "com.android.support.test:runner:0.4.1"
androidTestCompile "com.android.support.test:rules:0.4.1"
androidTestCompile "com.android.support:support-annotations:23.0.1"
implementation project(':react-native-keychain')
implementation project(':react-native-secure-storage')
implementation project(':react-native-touch-id')
implementation project(':react-native-randombytes')
implementation project(':@yfuks/react-native-action-sheet')
implementation project(':react-native-vector-icons')
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:23.0.1"
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "com.madgag.spongycastle:prov:1.56.0.0"
testImplementation "junit:junit:4.12"
androidTestImplementation "junit:junit:4.12"
androidTestImplementation "com.android.support.test:runner:0.4.1"
androidTestImplementation "com.android.support.test:rules:0.4.1"
androidTestImplementation "com.android.support:support-annotations:23.0.1"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
Expand Down
21 changes: 20 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.USE_FINGERPRINT" />

<application
android:usesCleartextTraffic="${usesCleartextTraffic}"
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
Expand All @@ -21,7 +22,25 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
<activity
android:name=".autofill.AutoFillActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
/>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

<service
android:name=".autofill.BCAutoFillService"
android:label="Buttercup Autofill Service"
android:permission="android.permission.BIND_AUTOFILL_SERVICE">
<intent-filter>
<action android:name="android.service.autofill.AutofillService" />
</intent-filter>
<meta-data
android:name="android.autofill"
android:resource="@xml/autofill_service_configuration" />
</service>

</application>

</manifest>
10 changes: 3 additions & 7 deletions android/app/src/main/java/com/buttercup/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Application;

import com.buttercup.autofill.AutoFillPackage;
import com.facebook.react.ReactApplication;
import com.oblador.keychain.KeychainPackage;
import li.yunqi.rnsecurestorage.RNSecureStoragePackage;
Expand All @@ -13,15 +14,9 @@
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.NativeModule;

import java.util.Arrays;
import java.util.List;
import java.util.Collections;
import java.util.ArrayList;

public class MainApplication extends Application implements ReactApplication {

Expand All @@ -41,7 +36,8 @@ protected List<ReactPackage> getPackages() {
new RandomBytesPackage(),
new ActionSheetPackage(),
new VectorIconsPackage(),
new CryptoPackage()
new CryptoPackage(),
new AutoFillPackage()
);
}
};
Expand Down
111 changes: 111 additions & 0 deletions android/app/src/main/java/com/buttercup/autofill/AutoFillActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.buttercup.autofill;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.actionsheet.ActionSheetPackage;
import com.bitgo.randombytes.RandomBytesPackage;
import com.buttercup.BuildConfig;
import com.buttercup.CryptoPackage;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.oblador.keychain.KeychainPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.rnfingerprint.FingerprintAuthPackage;

import org.spongycastle.jce.provider.BouncyCastleProvider;

import java.security.Security;
import java.util.Arrays;
import java.util.List;

import li.yunqi.rnsecurestorage.RNSecureStoragePackage;

public class AutoFillActivity extends ReactActivity {
private static final String TAG = "AutoFillActivity";
private ReactNativeHost mReactNativeHost;

static {
Security.insertProviderAt(new BouncyCastleProvider(), 1);
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SoLoader.init(this, false);
}

@Override
public void onDestroy() {
super.onDestroy();
mReactNativeHost = null;
}

private ReactNativeHost getAutoFillReactNativeHost() {
if (mReactNativeHost == null) {
mReactNativeHost = new ReactNativeHost(getApplication()) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
Log.d(TAG, "getPackages");
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new KeychainPackage(),
new RNSecureStoragePackage(),
new FingerprintAuthPackage(),
new RandomBytesPackage(),
new ActionSheetPackage(),
new VectorIconsPackage(),
new CryptoPackage(),
new AutoFillPackage()
);
}
};
}

return mReactNativeHost;
}

/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "Buttercup";
}

@Override
protected ReactActivityDelegate createReactActivityDelegate() {
// We need to override the Bridge Delegate so we can inject PROPs into the react app
Log.d(TAG, "createReactActivityDelegate");
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected Bundle getLaunchOptions() {
Log.d(TAG, "getLaunchOptions");
Intent intent = getIntent();
String[] serviceIdentifiers = intent.getStringArrayExtra("serviceIdentifiers");

Bundle bundle = new Bundle();
bundle.putBoolean("isContextAutoFill", true);
bundle.putStringArray("serviceIdentifiers", serviceIdentifiers);
return bundle;
}

@Override
protected ReactNativeHost getReactNativeHost() {
Log.d(TAG, "getReactNativeHost");
return getAutoFillReactNativeHost();
}
};
}
}
Loading

0 comments on commit 788c4b4

Please sign in to comment.