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:
components:
- tools
- build-tools-28.0.2
- build-tools-28.0.3
- android-28
- extra-google-m2repository
- extra-android-m2repository

View file

@ -15,58 +15,55 @@
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:supportsRtl="true">
<activity android:name=".PasswordStore" android:label="@string/app_name"
<activity
android:name=".PasswordStore"
android:label="@string/app_name"
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"
<activity
android:name=".git.GitActivity"
android:parentActivityName=".PasswordStore">
<meta-data android:name="android.PARENT_ACTIVITY1"
android:value="com.zeapo.pwdstore.PasswordStore" />
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<activity android:name=".UserPreference"
<activity
android:name=".UserPreference"
android:parentActivityName=".PasswordStore">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value="com.zeapo.pwdstore.PasswordStore" />
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<activity android:name=".SshKeyGen"
<activity
android:name=".SshKeyGen"
android:parentActivityName=".PasswordStore">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value="com.zeapo.pwdstore.PasswordStore" />
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<service android:name=".autofill.AutofillService"
<service
android:name=".autofill.AutofillService"
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" />
<meta-data android:name="android.accessibilityservice" android:resource="@xml/autofill_config" />
</service>
<activity android:name=".autofill.AutofillActivity"
<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" />
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<activity android:name=".autofill.AutofillPreferenceActivity"
<activity
android:name=".autofill.AutofillPreferenceActivity"
android:parentActivityName=".PasswordStore">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value="com.zeapo.pwdstore.PasswordStore" />
<meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.zeapo.pwdstore.PasswordStore" />
</activity>
<activity

View file

@ -37,6 +37,7 @@ import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.lang.ref.WeakReference;
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);
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};
ArrayAdapter<Integer> adapter = new ArrayAdapter<>(getActivity(),
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);
CheckBox checkbox = (CheckBox) v.findViewById(R.id.show_passphrase);
CheckBox checkbox = v.findViewById(R.id.show_passphrase);
checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
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();
if (isChecked) {
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);
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");
try {
textView.setText(FileUtils.readFileToString(file));
@ -124,7 +125,7 @@ public class SshKeyGen extends AppCompatActivity {
b.setOnClickListener(new View.OnClickListener() {
@Override
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);
ClipData clip = ClipData.newPlainText("public key", textView.getText().toString());
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 WeakReference<SshKeyGen> weakReference;
private KeyGenerateTask(final SshKeyGen activity) {
weakReference = new WeakReference<>(activity);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd = ProgressDialog.show(SshKeyGen.this, "", "Generating keys");
pd = ProgressDialog.show(weakReference.get(), "", "Generating keys");
}
protected Exception doInBackground(String... strings) {
@ -170,7 +176,7 @@ public class SshKeyGen extends AppCompatActivity {
try {
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);
if (passphrase.length() > 0) {
kp.writePrivateKey(out, passphrase.getBytes());
@ -178,7 +184,7 @@ public class SshKeyGen extends AppCompatActivity {
kp.writePrivateKey(out);
}
file = new File(getFilesDir() + "/.ssh_key.pub");
file = new File(weakReference.get().getFilesDir() + "/.ssh_key.pub");
out = new FileOutputStream(file, false);
kp.writePublicKey(out, comment);
return null;
@ -194,18 +200,18 @@ public class SshKeyGen extends AppCompatActivity {
super.onPostExecute(e);
pd.dismiss();
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();
df.show(getFragmentManager(), "public_key");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
df.show(weakReference.get().getFragmentManager(), "public_key");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(weakReference.get());
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("use_generated_key", true);
editor.apply();
} else {
new AlertDialog.Builder(SshKeyGen.this)
new AlertDialog.Builder(weakReference.get())
.setTitle("Error while trying to generate the ssh-key")
.setMessage(getResources().getString(R.string.ssh_key_error_dialog_text) + e.getMessage())
.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
.setMessage(weakReference.get().getResources().getString(R.string.ssh_key_error_dialog_text) + e.getMessage())
.setPositiveButton(weakReference.get().getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// pass
@ -223,7 +229,7 @@ public class SshKeyGen extends AppCompatActivity {
String length = Integer.toString((Integer) ((Spinner) findViewById(R.id.length)).getSelectedItem());
String passphrase = ((EditText) findViewById(R.id.passphrase)).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);
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)
}
}