Skip to content

Commit

Permalink
ACardEmulator: fixed linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmorgner committed Nov 29, 2024
1 parent cd52697 commit 3c2e54b
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 80 deletions.
8 changes: 6 additions & 2 deletions ACardEmulator/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:theme="@style/AppTheme" >
<activity
android:name="com.vsmartcard.acardemulator.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
>
Expand All @@ -33,6 +34,7 @@

<activity
android:name="com.vsmartcard.acardemulator.SettingsActivity"
android:exported="false"
android:label="@string/action_settings" >

<intent-filter>
Expand All @@ -56,12 +58,14 @@
</service>

<service android:name=".SmartcardProviderService" />
<receiver android:name="com.samsung.android.sdk.accessory.RegisterUponInstallReceiver" >
<receiver android:name="com.samsung.android.sdk.accessory.RegisterUponInstallReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.samsung.accessory.action.REGISTER_AGENT" />
</intent-filter>
</receiver>
<receiver android:name="com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver" >
<receiver android:name="com.samsung.android.sdk.accessory.ServiceConnectionIndicationBroadcastReceiver"
android:exported="true">
<intent-filter>
<action android:name="com.samsung.accessory.action.SERVICE_CONNECTION_REQUESTED" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import android.os.Bundle;
import android.preference.PreferenceActivity;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;

import android.view.MenuInflater;
import android.view.View;
Expand Down Expand Up @@ -38,10 +37,7 @@ public ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}

public void setSupportActionBar(@Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}

@NonNull
@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
Expand Down Expand Up @@ -80,7 +76,7 @@ protected void onTitleChanged(CharSequence title, int color) {
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ public void onCreate() {
EmulatorSingleton.createEmulator(this);
}

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

@Override
public byte[] processCommandApdu(byte[] capdu, Bundle extras) {
return EmulatorSingleton.process(this, capdu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
Expand All @@ -47,13 +48,15 @@
import androidx.appcompat.widget.Toolbar;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import java.util.Objects;

public class MainActivity extends AppCompatActivity {

private TextView textViewVPCDStatus;
private BroadcastReceiver bReceiver = new BroadcastReceiver() {
private final BroadcastReceiver bReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(EmulatorSingleton.TAG)) {
if (Objects.requireNonNull(intent.getAction()).equals(EmulatorSingleton.TAG)) {
String capdu = intent.getStringExtra(EmulatorSingleton.EXTRA_CAPDU);
String rapdu = intent.getStringExtra(EmulatorSingleton.EXTRA_RAPDU);
String error = intent.getStringExtra(EmulatorSingleton.EXTRA_ERROR);
Expand All @@ -76,7 +79,7 @@ public void onReceive(Context context, Intent intent) {
private AlertDialog dialog;
final String PREFS = "ACardEmulatorPrefs";
final String PREF_LASTVERSION = "last version";
private static String SAVED_STATUS = "textViewVPCDStatus";
private static final String SAVED_STATUS = "textViewVPCDStatus";

private void showStartupMessage() {
if (dialog == null)
Expand All @@ -94,25 +97,25 @@ public void onClick(DialogInterface dialog, int id) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
FloatingActionButton fab = findViewById(R.id.fab);
assert fab != null;
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
String emulator = SP.getString("emulator", "");
if (emulator != getString(R.string.vicc)) {
if (!emulator.equals(getString(R.string.vicc))) {
Snackbar.make(view, "Scheduled re-installation of all applets...", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
EmulatorSingleton.destroyEmulator();
}
}
});

textViewVPCDStatus = (TextView) findViewById(R.id.textViewLog);
textViewVPCDStatus = findViewById(R.id.textViewLog);
SharedPreferences settings = getSharedPreferences(PREFS, 0);
if (settings.getInt(PREF_LASTVERSION, 0) != BuildConfig.VERSION_CODE) {
showStartupMessage();
Expand Down Expand Up @@ -161,7 +164,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
textViewVPCDStatus.setText(savedInstanceState.getCharSequence(SAVED_STATUS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
package com.vsmartcard.acardemulator;


import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
Expand All @@ -43,6 +41,8 @@
import com.google.zxing.integration.android.IntentResult;
import com.vsmartcard.acardemulator.emulators.VICCEmulator;

import java.util.Objects;

import ACardEmulator.BuildConfig;
import ACardEmulator.R;

Expand Down Expand Up @@ -127,7 +127,7 @@ public boolean onPreferenceChange(Preference preference, Object value) {
: null);
} else if (preference instanceof SwitchPreference) {
SwitchPreference switchPreference = (SwitchPreference) preference;
if (stringValue == "true") {
if (stringValue.equals("true")) {
CharSequence aid = switchPreference.getSwitchTextOn();
preference.setSummary("Selectable with AID " + aid);
} else {
Expand Down Expand Up @@ -174,7 +174,6 @@ private static void bindPreferenceSummaryToValue(Preference preference) {
* This fragment shows data and sync preferences only. It is used when the
* activity is showing a two-pane settings UI.
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static class VICCPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -208,16 +207,13 @@ public boolean onPreferenceClick(Preference preference) {
Preference internal_nfc = findPreference("internal_nfc");
internal_nfc.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (android.os.Build.VERSION.SDK_INT >= 16) {
startActivity(new Intent(android.provider.Settings.ACTION_NFC_SETTINGS));
} else {
startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
}
startActivity(new Intent(android.provider.Settings.ACTION_NFC_SETTINGS));
return true;
}
});

final Preference gear_nfc = findPreference("gear_nfc");
//noinspection ConstantValue
if (BuildConfig.FLAVOR.equals("fdroid")) {
gear_nfc.setSummary("Samsung Gear integration is disabled in F-Droid");
} else {
Expand Down Expand Up @@ -248,12 +244,10 @@ public boolean onOptionsItemSelected(MenuItem item) {

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
switch(requestCode) {
case IntentIntegrator.REQUEST_CODE:
if (resultCode != RESULT_CANCELED) {
handleScannedURI(Uri.parse(scanResult.getContents()));
}
break;
if (requestCode == IntentIntegrator.REQUEST_CODE) {
if (resultCode != RESULT_CANCELED) {
handleScannedURI(Uri.parse(scanResult.getContents()));
}
}
}

Expand All @@ -273,7 +267,7 @@ private void handleScannedURI(Uri uri) {
getFragmentManager().beginTransaction().replace(android.R.id.content,
new VICCPreferenceFragment()).commit();
} catch (Exception e) {
Snackbar.make(this.getCurrentFocus(), "Could not import configuration", Snackbar.LENGTH_LONG)
Snackbar.make(Objects.requireNonNull(this.getCurrentFocus()), "Could not import configuration", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

public interface Emulator {

public void deactivate();
void deactivate();

public void destroy();
void destroy();

public byte[] process(byte[] commandAPDU);
byte[] process(byte[] commandAPDU);

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.XmlResourceParser;
import android.preference.PreferenceManager;
import android.util.Log;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.vsmartcard.acardemulator.Util;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import ACardEmulator.R;

public class EmulatorSingleton {
Expand Down Expand Up @@ -100,32 +92,6 @@ public static byte[] process(Context context, byte[] capdu) {
return rapdu;
}

public static String[] getRegisteredAids(Context context) {
List<String> aidList = new ArrayList<>();
XmlResourceParser aidXmlParser = context.getResources().getXml(R.xml.aid_list);

try {
while (aidXmlParser.getEventType() != XmlPullParser.END_DOCUMENT) {
if (aidXmlParser.getEventType() == XmlPullParser.START_TAG) {
if (aidXmlParser.getName().equals("aid-filter")) {
int aid = aidXmlParser.getAttributeResourceValue(0, -1);
if (aid != -1) {
aidList.add(context.getResources().getString(aid));
}
}
}

aidXmlParser.next();
}

aidXmlParser.close();
} catch (XmlPullParserException | IOException e) {
Log.e(TAG.substring(0, 23), "Couldn't parse aid xml list.");
}

return aidList.toArray(new String[0]);
}

public static void deactivate() {
emulator.deactivate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ public class VICCEmulator implements Emulator {
public VICCEmulator(String hostname, int port) {
if (socket == null) {
try {
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
vpcdConnect(hostname, port);
sendPowerOn();
} catch (IOException e) {
Expand Down Expand Up @@ -113,7 +111,7 @@ private void sendToVPCD(byte[] data) throws IOException {
}

private void vpcdConnect(String hostname, int port) throws IOException {
Log.d("", "Connecting to " + hostname + ":" + Integer.toString(port));
Log.d("", "Connecting to " + hostname + ":" + port);
socket = new Socket(InetAddress.getByName(hostname), port);
outputStream = socket.getOutputStream();
inputStream = socket.getInputStream();
Expand Down

0 comments on commit 3c2e54b

Please sign in to comment.