From: Markus Pfeiffer Date: Tue, 21 Nov 2023 14:37:21 +0000 (+0100) Subject: android: Remove unnecessary API checks X-Git-Tag: android-2.5.0^2~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3e895b4d8b9128e509ec2d41bf9b0504ea9b410;p=thirdparty%2Fstrongswan.git android: Remove unnecessary API checks The minSdkVersion is 21, remove unnecessary checks and code that target older API versions. --- diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java index 165f479dc7..03102502db 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/CharonVpnService.java @@ -101,11 +101,12 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe private volatile boolean mTerminate; private volatile boolean mIsDisconnecting; private volatile boolean mShowNotification; - private BuilderAdapter mBuilderAdapter = new BuilderAdapter(); + private final BuilderAdapter mBuilderAdapter = new BuilderAdapter(); private Handler mHandler; private VpnStateService mService; private final Object mServiceLock = new Object(); - private final ServiceConnection mServiceConnection = new ServiceConnection() { + private final ServiceConnection mServiceConnection = new ServiceConnection() + { @Override public void onServiceDisconnected(ComponentName name) { /* since the service is local this is theoretically only called when the process is terminated */ @@ -346,7 +347,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe { synchronized (this) { - if (mNextProfile != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + if (mNextProfile != null) { mBuilderAdapter.setProfile(mNextProfile); mBuilderAdapter.establishBlocking(); @@ -437,10 +438,10 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe name = profile.getName(); } NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL) - .setSmallIcon(R.drawable.ic_notification) - .setCategory(NotificationCompat.CATEGORY_SERVICE) - .setVisibility(publicVersion ? NotificationCompat.VISIBILITY_PUBLIC - : NotificationCompat.VISIBILITY_PRIVATE); + .setSmallIcon(R.drawable.ic_notification) + .setCategory(NotificationCompat.CATEGORY_SERVICE) + .setVisibility(publicVersion ? NotificationCompat.VISIBILITY_PUBLIC + : NotificationCompat.VISIBILITY_PRIVATE); int s = R.string.state_disabled; if (error != ErrorState.NO_ERROR) { @@ -527,10 +528,11 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe } @Override - public void stateChanged() { + public void stateChanged() + { if (mShowNotification) { - NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(VPN_STATE_NOTIFICATION_ID, buildNotification(false)); } } @@ -813,7 +815,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe private VpnService.Builder mBuilder; private BuilderCache mCache; private BuilderCache mEstablishedCache; - private PacketDropper mDropper = new PacketDropper(); + private final PacketDropper mDropper = new PacketDropper(); public synchronized void setProfile(VpnProfile profile) { @@ -1071,7 +1073,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe } } } - catch (ClosedByInterruptException|InterruptedException e) + catch (ClosedByInterruptException | InterruptedException e) { /* regular interruption */ } @@ -1277,7 +1279,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe } } } - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + else { /* allow traffic that would otherwise be blocked to bypass the VPN */ builder.allowFamily(OsConstants.AF_INET); } @@ -1317,7 +1319,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe } } } - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + else { builder.allowFamily(OsConstants.AF_INET6); } @@ -1327,8 +1329,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe builder.addRoute("::", 0); } /* apply selected applications */ - if (mSelectedApps.size() > 0 && - Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + if (mSelectedApps.size() > 0) { switch (mAppHandling) { @@ -1372,11 +1373,7 @@ public class CharonVpnService extends VpnService implements Runnable, VpnStateSe { return false; } - else if (addr instanceof Inet6Address) - { - return true; - } - return false; + return addr instanceof Inet6Address; } } diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/StrongSwanApplication.java b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/StrongSwanApplication.java index 92a112a6dc..ac9866155e 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/logic/StrongSwanApplication.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/logic/StrongSwanApplication.java @@ -16,20 +16,18 @@ package org.strongswan.android.logic; -import java.security.Security; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -import org.strongswan.android.security.LocalCertificateKeyStoreProvider; -import org.strongswan.android.ui.MainActivity; - import android.app.Application; import android.content.Context; -import android.os.Build; import android.os.Handler; import android.os.Looper; +import org.strongswan.android.security.LocalCertificateKeyStoreProvider; + +import java.security.Security; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + import androidx.core.os.HandlerCompat; public class StrongSwanApplication extends Application @@ -38,7 +36,8 @@ public class StrongSwanApplication extends Application private final ExecutorService mExecutorService = Executors.newFixedThreadPool(4); private final Handler mMainHandler = HandlerCompat.createAsync(Looper.getMainLooper()); - static { + static + { Security.addProvider(new LocalCertificateKeyStoreProvider()); } @@ -51,6 +50,7 @@ public class StrongSwanApplication extends Application /** * Returns the current application context + * * @return context */ public static Context getContext() @@ -60,6 +60,7 @@ public class StrongSwanApplication extends Application /** * Returns a thread pool to run tasks in separate threads + * * @return thread pool */ public Executor getExecutor() @@ -69,6 +70,7 @@ public class StrongSwanApplication extends Application /** * Returns a handler to execute stuff by the main thread. + * * @return handler */ public Handler getHandler() @@ -82,21 +84,6 @@ public class StrongSwanApplication extends Application */ static { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) - { - System.loadLibrary("strongswan"); - - if (MainActivity.USE_BYOD) - { - System.loadLibrary("tpmtss"); - System.loadLibrary("tncif"); - System.loadLibrary("tnccs"); - System.loadLibrary("imcv"); - } - - System.loadLibrary("charon"); - System.loadLibrary("ipsec"); - } System.loadLibrary("androidbridge"); } } diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/MainActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/MainActivity.java index f2d8939ecd..a48a0a886b 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/MainActivity.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/MainActivity.java @@ -21,7 +21,6 @@ package org.strongswan.android.ui; import android.app.Dialog; import android.content.DialogInterface; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.text.format.Formatter; import android.view.Menu; @@ -82,16 +81,6 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec return true; } - @Override - public boolean onPrepareOptionsMenu(Menu menu) - { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) - { - menu.removeItem(R.id.menu_import_profile); - } - return true; - } - @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -195,26 +184,26 @@ public class MainActivity extends AppCompatActivity implements OnVpnProfileSelec size = Formatter.formatFileSize(getActivity(), s); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()) - .setTitle(R.string.clear_crl_cache_title) - .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() + .setTitle(R.string.clear_crl_cache_title) + .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int which) { - @Override - public void onClick(DialogInterface dialog, int which) - { - dismiss(); - } - }) - .setPositiveButton(R.string.clear, new DialogInterface.OnClickListener() + dismiss(); + } + }) + .setPositiveButton(R.string.clear, new DialogInterface.OnClickListener() + { + @Override + public void onClick(DialogInterface dialog, int whichButton) { - @Override - public void onClick(DialogInterface dialog, int whichButton) + for (String file : list) { - for (String file : list) - { - getActivity().deleteFile(file); - } + getActivity().deleteFile(file); } - }); + } + }); builder.setMessage(getActivity().getResources().getQuantityString(R.plurals.clear_crl_cache_msg, list.size(), list.size(), size)); return builder.create(); } diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificateImportActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificateImportActivity.java index def0b88a5d..4e1e39e2dd 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificateImportActivity.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificateImportActivity.java @@ -78,7 +78,7 @@ public class TrustedCertificateImportActivity extends AppCompatActivity { importCertificate(intent.getData()); } - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) + else { Intent openIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); openIntent.setType("*/*"); @@ -89,7 +89,6 @@ public class TrustedCertificateImportActivity extends AppCompatActivity catch (ActivityNotFoundException e) { /* some devices are unable to browse for files */ finish(); - return; } } } diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificatesActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificatesActivity.java index c941a49e97..c32ec5d827 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificatesActivity.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/TrustedCertificatesActivity.java @@ -17,7 +17,6 @@ package org.strongswan.android.ui; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; @@ -73,10 +72,10 @@ public class TrustedCertificatesActivity extends AppCompatActivity implements Tr mAdapter = new TrustedCertificatesPagerAdapter(this); - mPager = (ViewPager2)findViewById(R.id.viewpager); + mPager = findViewById(R.id.viewpager); mPager.setAdapter(mAdapter); - TabLayout tabs = (TabLayout)findViewById(R.id.tabs); + TabLayout tabs = findViewById(R.id.tabs); new TabLayoutMediator(tabs, mPager, (tab, position) -> { tab.setText(mAdapter.getTitle(position)); }).attach(); @@ -91,16 +90,6 @@ public class TrustedCertificatesActivity extends AppCompatActivity implements Tr return true; } - @Override - public boolean onPrepareOptionsMenu(Menu menu) - { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) - { - menu.removeItem(R.id.menu_import_certificate); - } - return true; - } - @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -164,7 +153,7 @@ public class TrustedCertificatesActivity extends AppCompatActivity implements Tr public static class TrustedCertificatesPagerAdapter extends FragmentStateAdapter { - private TrustedCertificatesTab mTabs[]; + private final TrustedCertificatesTab[] mTabs; public TrustedCertificatesPagerAdapter(@NonNull FragmentActivity fragmentActivity) { diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java index dc3bc1cc7d..85d178e52f 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileDetailActivity.java @@ -22,7 +22,6 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.security.KeyChain; @@ -44,7 +43,6 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; @@ -195,64 +193,64 @@ public class VpnProfileDetailActivity extends AppCompatActivity setContentView(R.layout.profile_detail_view); - mName = (MultiAutoCompleteTextView)findViewById(R.id.name); - mNameWrap = (TextInputLayoutHelper)findViewById(R.id.name_wrap); - mGateway = (EditText)findViewById(R.id.gateway); - mGatewayWrap = (TextInputLayoutHelper) findViewById(R.id.gateway_wrap); - mSelectVpnType = (Spinner)findViewById(R.id.vpn_type); - mTncNotice = (RelativeLayout)findViewById(R.id.tnc_notice); + mName = findViewById(R.id.name); + mNameWrap = findViewById(R.id.name_wrap); + mGateway = findViewById(R.id.gateway); + mGatewayWrap = findViewById(R.id.gateway_wrap); + mSelectVpnType = findViewById(R.id.vpn_type); + mTncNotice = findViewById(R.id.tnc_notice); - mUsernamePassword = (ViewGroup)findViewById(R.id.username_password_group); - mUsername = (EditText)findViewById(R.id.username); - mUsernameWrap = (TextInputLayoutHelper) findViewById(R.id.username_wrap); - mPassword = (EditText)findViewById(R.id.password); + mUsernamePassword = findViewById(R.id.username_password_group); + mUsername = findViewById(R.id.username); + mUsernameWrap = findViewById(R.id.username_wrap); + mPassword = findViewById(R.id.password); - mUserCertificate = (ViewGroup)findViewById(R.id.user_certificate_group); - mSelectUserCert = (RelativeLayout)findViewById(R.id.select_user_certificate); + mUserCertificate = findViewById(R.id.user_certificate_group); + mSelectUserCert = findViewById(R.id.select_user_certificate); - mCheckAuto = (CheckBox)findViewById(R.id.ca_auto); - mSelectCert = (RelativeLayout)findViewById(R.id.select_certificate); + mCheckAuto = findViewById(R.id.ca_auto); + mSelectCert = findViewById(R.id.select_certificate); - mShowAdvanced = (CheckBox)findViewById(R.id.show_advanced); - mAdvancedSettings = (ViewGroup)findViewById(R.id.advanced_settings); + mShowAdvanced = findViewById(R.id.show_advanced); + mAdvancedSettings = findViewById(R.id.advanced_settings); - mRemoteId = (MultiAutoCompleteTextView)findViewById(R.id.remote_id); - mRemoteIdWrap = (TextInputLayoutHelper) findViewById(R.id.remote_id_wrap); + mRemoteId = findViewById(R.id.remote_id); + mRemoteIdWrap = findViewById(R.id.remote_id_wrap); mLocalId = findViewById(R.id.local_id); mLocalIdWrap = findViewById(R.id.local_id_wrap); mDnsServers = findViewById(R.id.dns_servers); mDnsServersWrap = findViewById(R.id.dns_servers_wrap); - mMTU = (EditText)findViewById(R.id.mtu); - mMTUWrap = (TextInputLayoutHelper) findViewById(R.id.mtu_wrap); - mPort = (EditText)findViewById(R.id.port); - mPortWrap = (TextInputLayoutHelper) findViewById(R.id.port_wrap); - mNATKeepalive = (EditText)findViewById(R.id.nat_keepalive); - mNATKeepaliveWrap = (TextInputLayoutHelper) findViewById(R.id.nat_keepalive_wrap); + mMTU = findViewById(R.id.mtu); + mMTUWrap = findViewById(R.id.mtu_wrap); + mPort = findViewById(R.id.port); + mPortWrap = findViewById(R.id.port_wrap); + mNATKeepalive = findViewById(R.id.nat_keepalive); + mNATKeepaliveWrap = findViewById(R.id.nat_keepalive_wrap); mCertReq = findViewById(R.id.cert_req); mUseCrl = findViewById(R.id.use_crl); mUseOcsp = findViewById(R.id.use_ocsp); - mStrictRevocation= findViewById(R.id.strict_revocation); - mRsaPss= findViewById(R.id.rsa_pss); - mIPv6Transport= findViewById(R.id.ipv6_transport); - mIncludedSubnets = (EditText)findViewById(R.id.included_subnets); - mIncludedSubnetsWrap = (TextInputLayoutHelper)findViewById(R.id.included_subnets_wrap); - mExcludedSubnets = (EditText)findViewById(R.id.excluded_subnets); - mExcludedSubnetsWrap = (TextInputLayoutHelper)findViewById(R.id.excluded_subnets_wrap); - mBlockIPv4 = (CheckBox)findViewById(R.id.split_tunneling_v4); - mBlockIPv6 = (CheckBox)findViewById(R.id.split_tunneling_v6); - - mSelectSelectedAppsHandling = (Spinner)findViewById(R.id.apps_handling); - mSelectApps = (RelativeLayout)findViewById(R.id.select_applications); - - mIkeProposal = (EditText)findViewById(R.id.ike_proposal); - mIkeProposalWrap = (TextInputLayoutHelper)findViewById(R.id.ike_proposal_wrap); - mEspProposal = (EditText)findViewById(R.id.esp_proposal); - mEspProposalWrap = (TextInputLayoutHelper)findViewById(R.id.esp_proposal_wrap); + mStrictRevocation = findViewById(R.id.strict_revocation); + mRsaPss = findViewById(R.id.rsa_pss); + mIPv6Transport = findViewById(R.id.ipv6_transport); + mIncludedSubnets = findViewById(R.id.included_subnets); + mIncludedSubnetsWrap = findViewById(R.id.included_subnets_wrap); + mExcludedSubnets = findViewById(R.id.excluded_subnets); + mExcludedSubnetsWrap = findViewById(R.id.excluded_subnets_wrap); + mBlockIPv4 = findViewById(R.id.split_tunneling_v4); + mBlockIPv6 = findViewById(R.id.split_tunneling_v6); + + mSelectSelectedAppsHandling = findViewById(R.id.apps_handling); + mSelectApps = findViewById(R.id.select_applications); + + mIkeProposal = findViewById(R.id.ike_proposal); + mIkeProposalWrap = findViewById(R.id.ike_proposal_wrap); + mEspProposal = findViewById(R.id.esp_proposal); + mEspProposalWrap = findViewById(R.id.esp_proposal_wrap); /* make the link clickable */ ((TextView)findViewById(R.id.proposal_intro)).setMovementMethod(LinkMovementMethod.getInstance()); - mProfileIdLabel = (TextView)findViewById(R.id.profile_id_label); - mProfileId = (TextView)findViewById(R.id.profile_id); + mProfileIdLabel = findViewById(R.id.profile_id_label); + mProfileId = findViewById(R.id.profile_id); final SpaceTokenizer spaceTokenizer = new SpaceTokenizer(); mName.setTokenizer(spaceTokenizer); @@ -262,14 +260,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity mName.setAdapter(gatewayAdapter); mRemoteId.setAdapter(gatewayAdapter); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) + mGateway.addTextChangedListener(new TextWatcher() { - findViewById(R.id.apps).setVisibility(View.GONE); - mSelectSelectedAppsHandling.setVisibility(View.GONE); - mSelectApps.setVisibility(View.GONE); - } - - mGateway.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @@ -294,7 +286,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity } }); - mSelectVpnType.setOnItemSelectedListener(new OnItemSelectedListener() { + mSelectVpnType.setOnItemSelectedListener(new OnItemSelectedListener() + { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { @@ -312,7 +305,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity ((TextView)mTncNotice.findViewById(android.R.id.text1)).setText(R.string.tnc_notice_title); ((TextView)mTncNotice.findViewById(android.R.id.text2)).setText(R.string.tnc_notice_subtitle); - mTncNotice.setOnClickListener(new OnClickListener() { + mTncNotice.setOnClickListener(new OnClickListener() + { @Override public void onClick(View v) { @@ -321,14 +315,15 @@ public class VpnProfileDetailActivity extends AppCompatActivity }); mSelectUserCert.setOnClickListener(new SelectUserCertOnClickListener()); - ((Button)findViewById(R.id.install_user_certificate)).setOnClickListener(v -> { + findViewById(R.id.install_user_certificate).setOnClickListener(v -> { Intent intent = KeyChain.createInstallIntent(); mInstallPKCS12.launch(intent); }); mSelectUserIdAdapter = new CertificateIdentitiesAdapter(this); mLocalId.setAdapter(mSelectUserIdAdapter); - mCheckAuto.setOnCheckedChangeListener(new OnCheckedChangeListener() { + mCheckAuto.setOnCheckedChangeListener(new OnCheckedChangeListener() + { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -336,7 +331,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity } }); - mSelectCert.setOnClickListener(new OnClickListener() { + mSelectCert.setOnClickListener(new OnClickListener() + { @Override public void onClick(View v) { @@ -346,7 +342,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity } }); - mShowAdvanced.setOnCheckedChangeListener(new OnCheckedChangeListener() { + mShowAdvanced.setOnCheckedChangeListener(new OnCheckedChangeListener() + { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -354,7 +351,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity } }); - mSelectSelectedAppsHandling.setOnItemSelectedListener(new OnItemSelectedListener() { + mSelectSelectedAppsHandling.setOnItemSelectedListener(new OnItemSelectedListener() + { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { @@ -370,7 +368,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity } }); - mSelectApps.setOnClickListener(new OnClickListener() { + mSelectApps.setOnClickListener(new OnClickListener() + { @Override public void onClick(View v) { @@ -489,7 +488,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity AlertDialog.Builder adb = new AlertDialog.Builder(VpnProfileDetailActivity.this); adb.setTitle(R.string.alert_text_nocertfound_title); adb.setMessage(R.string.alert_text_nocertfound); - adb.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + adb.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() + { @Override public void onClick(DialogInterface dialog, int id) { @@ -624,6 +624,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity /** * Verify the user input and display error messages. + * * @return true if the input is valid */ private boolean verifyInput() @@ -969,7 +970,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity { final X509Certificate[] chain = KeyChain.getCertificateChain(VpnProfileDetailActivity.this, alias); /* alias() is not called from our main thread */ - runOnUiThread(new Runnable() { + runOnUiThread(new Runnable() + { @Override public void run() { @@ -992,7 +994,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity /** * Callback interface for the user certificate loader. */ - private interface UserCertificateLoaderCallback { + private interface UserCertificateLoaderCallback + { void onComplete(X509Certificate result); } @@ -1050,7 +1053,8 @@ public class VpnProfileDetailActivity extends AppCompatActivity return new AlertDialog.Builder(getActivity()) .setTitle(R.string.tnc_notice_title) .setMessage(HtmlCompat.fromHtml(getString(R.string.tnc_notice_details), HtmlCompat.FROM_HTML_MODE_LEGACY)) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() + { @Override public void onClick(DialogInterface dialog, int id) { @@ -1111,7 +1115,7 @@ public class VpnProfileDetailActivity extends AppCompatActivity if (text instanceof Spanned) { SpannableString sp = new SpannableString(text + " "); - TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0); + TextUtils.copySpansFrom((Spanned)text, 0, text.length(), Object.class, sp, 0); return sp; } else diff --git a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileImportActivity.java b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileImportActivity.java index d7a069d0b8..c58365d9cd 100644 --- a/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileImportActivity.java +++ b/src/frontends/android/app/src/main/java/org/strongswan/android/ui/VpnProfileImportActivity.java @@ -21,7 +21,6 @@ import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.net.Uri; -import android.os.Build; import android.os.Bundle; import android.security.KeyChain; import android.security.KeyChainAliasCallback; @@ -135,12 +134,12 @@ public class VpnProfileImportActivity extends AppCompatActivity } ); - private LoaderManager.LoaderCallbacks mProfileLoaderCallbacks = new LoaderManager.LoaderCallbacks() + private final LoaderManager.LoaderCallbacks mProfileLoaderCallbacks = new LoaderManager.LoaderCallbacks() { @Override public Loader onCreateLoader(int id, Bundle args) { - return new ProfileLoader(VpnProfileImportActivity.this, (Uri)args.getParcelable(PROFILE_URI)); + return new ProfileLoader(VpnProfileImportActivity.this, args.getParcelable(PROFILE_URI)); } @Override @@ -156,7 +155,7 @@ public class VpnProfileImportActivity extends AppCompatActivity } }; - private LoaderManager.LoaderCallbacks mUserCertificateLoaderCallbacks = new LoaderManager.LoaderCallbacks() + private final LoaderManager.LoaderCallbacks mUserCertificateLoaderCallbacks = new LoaderManager.LoaderCallbacks() { @Override public Loader onCreateLoader(int id, Bundle args) @@ -191,23 +190,23 @@ public class VpnProfileImportActivity extends AppCompatActivity setContentView(R.layout.profile_import_view); mProgressBar = findViewById(R.id.progress_bar); - mExistsWarning = (TextView)findViewById(R.id.exists_warning); - mBasicDataGroup = (ViewGroup)findViewById(R.id.basic_data_group); - mName = (TextView)findViewById(R.id.name); - mGateway = (TextView)findViewById(R.id.gateway); - mSelectVpnType = (TextView)findViewById(R.id.vpn_type); + mExistsWarning = findViewById(R.id.exists_warning); + mBasicDataGroup = findViewById(R.id.basic_data_group); + mName = findViewById(R.id.name); + mGateway = findViewById(R.id.gateway); + mSelectVpnType = findViewById(R.id.vpn_type); - mUsernamePassword = (ViewGroup)findViewById(R.id.username_password_group); - mUsername = (EditText)findViewById(R.id.username); - mUsernameWrap = (TextInputLayoutHelper) findViewById(R.id.username_wrap); - mPassword = (EditText)findViewById(R.id.password); + mUsernamePassword = findViewById(R.id.username_password_group); + mUsername = findViewById(R.id.username); + mUsernameWrap = findViewById(R.id.username_wrap); + mPassword = findViewById(R.id.password); - mUserCertificate = (ViewGroup)findViewById(R.id.user_certificate_group); - mSelectUserCert = (RelativeLayout)findViewById(R.id.select_user_certificate); - mImportUserCert = (Button)findViewById(R.id.import_user_certificate); + mUserCertificate = findViewById(R.id.user_certificate_group); + mSelectUserCert = findViewById(R.id.select_user_certificate); + mImportUserCert = findViewById(R.id.import_user_certificate); - mRemoteCertificate = (ViewGroup)findViewById(R.id.remote_certificate_group); - mRemoteCert = (RelativeLayout)findViewById(R.id.remote_certificate); + mRemoteCertificate = findViewById(R.id.remote_certificate_group); + mRemoteCert = findViewById(R.id.remote_certificate); mExistsWarning.setVisibility(View.GONE); mBasicDataGroup.setVisibility(View.GONE); @@ -216,7 +215,8 @@ public class VpnProfileImportActivity extends AppCompatActivity mRemoteCertificate.setVisibility(View.GONE); mSelectUserCert.setOnClickListener(new SelectUserCertOnClickListener()); - mImportUserCert.setOnClickListener(new View.OnClickListener() { + mImportUserCert.setOnClickListener(new View.OnClickListener() + { @Override public void onClick(View v) { @@ -233,7 +233,7 @@ public class VpnProfileImportActivity extends AppCompatActivity { loadProfile(getIntent().getData()); } - else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) + else { Intent openIntent = new Intent(Intent.ACTION_OPEN_DOCUMENT); openIntent.setType("*/*"); @@ -535,9 +535,9 @@ public class VpnProfileImportActivity extends AppCompatActivity if (split != null) { String included = getSubnets(split, "subnets"); - profile.setIncludedSubnets(included != null ? included : null); + profile.setIncludedSubnets(included); String excluded = getSubnets(split, "excluded"); - profile.setExcludedSubnets(excluded != null ? excluded : null); + profile.setExcludedSubnets(excluded); int st = 0; st |= split.optBoolean("block-ipv4") ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV4 : 0; st |= split.optBoolean("block-ipv6") ? VpnProfile.SPLIT_TUNNELING_BLOCK_IPV6 : 0; @@ -710,6 +710,7 @@ public class VpnProfileImportActivity extends AppCompatActivity /** * Verify the user input and display error messages. + * * @return true if the input is valid */ private boolean verifyInput() @@ -899,14 +900,15 @@ public class VpnProfileImportActivity extends AppCompatActivity public void alias(final String alias) { /* alias() is not called from our main thread */ - runOnUiThread(new Runnable() { + runOnUiThread(new Runnable() + { @Override public void run() { mUserCertLoading = alias; updateUserCertView(); if (alias != null) - { /* otherwise the dialog was canceled, the request denied */ + { /* otherwise the dialog was canceled, the request denied */ LoaderManager.getInstance(VpnProfileImportActivity.this).restartLoader(USER_CERT_LOADER, null, mUserCertificateLoaderCallbacks); } }