Additional fixes (#449)

* Convert ToCloneOrNot to Kotlin

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>

* Cleanup and fix memory leak in SshKeyGen

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>

* Fix manifest issues

- Indent with 4 spaces
- Fix typo'd meta-data values

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>

* travis: Install build tools 28.0.3

Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
This commit is contained in:
Harsh Shandilya 2018-11-22 16:20:40 +05:30 committed by حسين
parent e72038f6f1
commit 0d55f71ff5
5 changed files with 103 additions and 105 deletions

View file

@ -6,7 +6,7 @@ jdk:
android: android:
components: components:
- tools - tools
- build-tools-28.0.2 - build-tools-28.0.3
- android-28 - android-28
- extra-google-m2repository - extra-google-m2repository
- extra-android-m2repository - extra-android-m2repository

View file

@ -10,77 +10,74 @@
tools:ignore="ProtectedPermissions"/> tools:ignore="ProtectedPermissions"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application android:allowBackup="true" <application android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:supportsRtl="true"> android:supportsRtl="true">
<activity android:name=".PasswordStore" android:label="@string/app_name" <activity
android:configChanges="orientation|screenSize"> android:name=".PasswordStore"
<intent-filter> android:label="@string/app_name"
<action android:name="android.intent.action.MAIN" /> android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".git.GitActivity"
android:parentActivityName=".PasswordStore">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<category android:name="android.intent.category.LAUNCHER" /> <activity
</intent-filter> android:name=".UserPreference"
</activity> android:parentActivityName=".PasswordStore">
<activity android:name=".git.GitActivity" <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
android:parentActivityName=".PasswordStore"> </activity>
<meta-data android:name="android.PARENT_ACTIVITY1"
android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<activity android:name=".UserPreference" <activity
android:parentActivityName=".PasswordStore"> android:name=".SshKeyGen"
android:parentActivityName=".PasswordStore">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<meta-data android:name="android.support.PARENT_ACTIVITY" <service
android:value="com.zeapo.pwdstore.PasswordStore" /> android:name=".autofill.AutofillService"
</activity> android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action android:name="android.accessibilityservice.AccessibilityService" />
</intent-filter>
<meta-data android:name="android.accessibilityservice" android:resource="@xml/autofill_config" />
</service>
<activity android:name=".SshKeyGen" <activity
android:parentActivityName=".PasswordStore"> android:name=".autofill.AutofillActivity"
android:parentActivityName=".PasswordStore"
android:documentLaunchMode="intoExisting"
android:excludeFromRecents="true"
tools:ignore="UnusedAttribute">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<meta-data android:name="android.support.PARENT_ACTIVITY" <activity
android:value="com.zeapo.pwdstore.PasswordStore" /> android:name=".autofill.AutofillPreferenceActivity"
</activity> android:parentActivityName=".PasswordStore">
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<service android:name=".autofill.AutofillService" <activity
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"> android:name="com.nononsenseapps.filepicker.FilePickerActivity"
<intent-filter> android:label="@string/app_name"
<action android:name="android.accessibilityservice.AccessibilityService" /> android:theme="@style/FilePickerTheme">
</intent-filter> <intent-filter>
<meta-data android:name="android.accessibilityservice" <action android:name="android.intent.action.GET_CONTENT" />
android:resource="@xml/autofill_config" /> <category android:name="android.intent.category.DEFAULT" />
</service> </intent-filter>
</activity>
<activity android:name=".autofill.AutofillActivity"
android:parentActivityName=".PasswordStore"
android:documentLaunchMode="intoExisting"
android:excludeFromRecents="true"
tools:ignore="UnusedAttribute">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<activity android:name=".autofill.AutofillPreferenceActivity"
android:parentActivityName=".PasswordStore">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<activity
android:name="com.nononsenseapps.filepicker.FilePickerActivity"
android:label="@string/app_name"
android:theme="@style/FilePickerTheme">
<intent-filter>
<action android:name="android.intent.action.GET_CONTENT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".crypto.PgpActivity" <activity android:name=".crypto.PgpActivity"
android:parentActivityName=".PasswordStore"/> android:parentActivityName=".PasswordStore"/>
<activity android:name=".SelectFolderActivity" /> <activity android:name=".SelectFolderActivity" />
</application> </application>
</manifest> </manifest>

View file

@ -37,6 +37,7 @@ import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.lang.ref.WeakReference;
public class SshKeyGen extends AppCompatActivity { public class SshKeyGen extends AppCompatActivity {
@ -51,7 +52,7 @@ public class SshKeyGen extends AppCompatActivity {
final View v = inflater.inflate(R.layout.fragment_ssh_keygen, container, false); final View v = inflater.inflate(R.layout.fragment_ssh_keygen, container, false);
Typeface monoTypeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/sourcecodepro.ttf"); Typeface monoTypeface = Typeface.createFromAsset(getActivity().getAssets(), "fonts/sourcecodepro.ttf");
Spinner spinner = (Spinner) v.findViewById(R.id.length); Spinner spinner = v.findViewById(R.id.length);
Integer[] lengths = new Integer[]{2048, 4096}; Integer[] lengths = new Integer[]{2048, 4096};
ArrayAdapter<Integer> adapter = new ArrayAdapter<>(getActivity(), ArrayAdapter<Integer> adapter = new ArrayAdapter<>(getActivity(),
android.R.layout.simple_spinner_dropdown_item, lengths); android.R.layout.simple_spinner_dropdown_item, lengths);
@ -59,11 +60,11 @@ public class SshKeyGen extends AppCompatActivity {
((EditText) v.findViewById(R.id.passphrase)).setTypeface(monoTypeface); ((EditText) v.findViewById(R.id.passphrase)).setTypeface(monoTypeface);
CheckBox checkbox = (CheckBox) v.findViewById(R.id.show_passphrase); CheckBox checkbox = v.findViewById(R.id.show_passphrase);
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
EditText editText = (EditText) v.findViewById(R.id.passphrase); EditText editText = v.findViewById(R.id.passphrase);
int selection = editText.getSelectionEnd(); int selection = editText.getSelectionEnd();
if (isChecked) { if (isChecked) {
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
@ -90,7 +91,7 @@ public class SshKeyGen extends AppCompatActivity {
@SuppressLint("InflateParams") final View v = inflater.inflate(R.layout.fragment_show_ssh_key, null); @SuppressLint("InflateParams") final View v = inflater.inflate(R.layout.fragment_show_ssh_key, null);
builder.setView(v); builder.setView(v);
TextView textView = (TextView) v.findViewById(R.id.public_key); TextView textView = v.findViewById(R.id.public_key);
File file = new File(getActivity().getFilesDir() + "/.ssh_key.pub"); File file = new File(getActivity().getFilesDir() + "/.ssh_key.pub");
try { try {
textView.setText(FileUtils.readFileToString(file)); textView.setText(FileUtils.readFileToString(file));
@ -124,7 +125,7 @@ public class SshKeyGen extends AppCompatActivity {
b.setOnClickListener(new View.OnClickListener() { b.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
TextView textView = (TextView) getDialog().findViewById(R.id.public_key); TextView textView = getDialog().findViewById(R.id.public_key);
ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("public key", textView.getText().toString()); ClipData clip = ClipData.newPlainText("public key", textView.getText().toString());
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
@ -152,13 +153,18 @@ public class SshKeyGen extends AppCompatActivity {
} }
} }
private class generateTask extends AsyncTask<String, Void, Exception> { private static class KeyGenerateTask extends AsyncTask<String, Void, Exception> {
private ProgressDialog pd; private ProgressDialog pd;
private WeakReference<SshKeyGen> weakReference;
private KeyGenerateTask(final SshKeyGen activity) {
weakReference = new WeakReference<>(activity);
}
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
super.onPreExecute(); super.onPreExecute();
pd = ProgressDialog.show(SshKeyGen.this, "", "Generating keys"); pd = ProgressDialog.show(weakReference.get(), "", "Generating keys");
} }
protected Exception doInBackground(String... strings) { protected Exception doInBackground(String... strings) {
@ -170,7 +176,7 @@ public class SshKeyGen extends AppCompatActivity {
try { try {
KeyPair kp = KeyPair.genKeyPair(jsch, KeyPair.RSA, length); KeyPair kp = KeyPair.genKeyPair(jsch, KeyPair.RSA, length);
File file = new File(getFilesDir() + "/.ssh_key"); File file = new File(weakReference.get().getFilesDir() + "/.ssh_key");
FileOutputStream out = new FileOutputStream(file, false); FileOutputStream out = new FileOutputStream(file, false);
if (passphrase.length() > 0) { if (passphrase.length() > 0) {
kp.writePrivateKey(out, passphrase.getBytes()); kp.writePrivateKey(out, passphrase.getBytes());
@ -178,7 +184,7 @@ public class SshKeyGen extends AppCompatActivity {
kp.writePrivateKey(out); kp.writePrivateKey(out);
} }
file = new File(getFilesDir() + "/.ssh_key.pub"); file = new File(weakReference.get().getFilesDir() + "/.ssh_key.pub");
out = new FileOutputStream(file, false); out = new FileOutputStream(file, false);
kp.writePublicKey(out, comment); kp.writePublicKey(out, comment);
return null; return null;
@ -194,18 +200,18 @@ public class SshKeyGen extends AppCompatActivity {
super.onPostExecute(e); super.onPostExecute(e);
pd.dismiss(); pd.dismiss();
if (e == null) { if (e == null) {
Toast.makeText(SshKeyGen.this, "SSH-key generated", Toast.LENGTH_LONG).show(); Toast.makeText(weakReference.get(), "SSH-key generated", Toast.LENGTH_LONG).show();
DialogFragment df = new ShowSshKeyFragment(); DialogFragment df = new ShowSshKeyFragment();
df.show(getFragmentManager(), "public_key"); df.show(weakReference.get().getFragmentManager(), "public_key");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(weakReference.get());
SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("use_generated_key", true); editor.putBoolean("use_generated_key", true);
editor.apply(); editor.apply();
} else { } else {
new AlertDialog.Builder(SshKeyGen.this) new AlertDialog.Builder(weakReference.get())
.setTitle("Error while trying to generate the ssh-key") .setTitle("Error while trying to generate the ssh-key")
.setMessage(getResources().getString(R.string.ssh_key_error_dialog_text) + e.getMessage()) .setMessage(weakReference.get().getResources().getString(R.string.ssh_key_error_dialog_text) + e.getMessage())
.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { .setPositiveButton(weakReference.get().getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
// pass // pass
@ -223,7 +229,7 @@ public class SshKeyGen extends AppCompatActivity {
String length = Integer.toString((Integer) ((Spinner) findViewById(R.id.length)).getSelectedItem()); String length = Integer.toString((Integer) ((Spinner) findViewById(R.id.length)).getSelectedItem());
String passphrase = ((EditText) findViewById(R.id.passphrase)).getText().toString(); String passphrase = ((EditText) findViewById(R.id.passphrase)).getText().toString();
String comment = ((EditText) findViewById(R.id.comment)).getText().toString(); String comment = ((EditText) findViewById(R.id.comment)).getText().toString();
new generateTask().execute(length, passphrase, comment); new KeyGenerateTask(this).execute(length, passphrase, comment);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); imm.hideSoftInputFromWindow(view.getWindowToken(), 0);

View file

@ -1,23 +0,0 @@
package com.zeapo.pwdstore;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class ToCloneOrNot extends Fragment {
public ToCloneOrNot() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_to_clone_or_not, container, false);
}
}

View file

@ -0,0 +1,18 @@
package com.zeapo.pwdstore
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
class ToCloneOrNot : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_to_clone_or_not, container, false)
}
}