diff options
Diffstat (limited to 'main/src/ui/java/de/blinkt/openvpn/activities')
4 files changed, 105 insertions, 146 deletions
diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt b/main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt index fa786dcb..b85eaa26 100644 --- a/main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt +++ b/main/src/ui/java/de/blinkt/openvpn/activities/ConfigConverter.kt @@ -811,8 +811,10 @@ class ConfigConverter : BaseActivity(), FileSelectCallback, View.OnClickListener // We got a file:/// URL and have no permission to read it. Technically an error of the calling app since // it makes an assumption about other apps being able to read the url but well ... - if (data != null && "file" == data.scheme) + if (data != null && "file" == data.scheme) { + log("An external app instructed OpenVPN for Android to open a file:// URI. This kind of URI have been deprecated since Android 7 and no longer work on modern Android versions at all.") doRequestSDCardPermission(PERMISSION_REQUEST_READ_URL) + } } diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java b/main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java index e1cb8862..82455895 100644 --- a/main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java +++ b/main/src/ui/java/de/blinkt/openvpn/activities/CreateShortcuts.java @@ -51,9 +51,6 @@ import java.util.Vector; public class CreateShortcuts extends ListActivity implements OnItemClickListener { - private static final int START_VPN_PROFILE= 70; - - private ProfileManager mPM; private VpnProfile mSelectedProfile; @@ -128,7 +125,8 @@ public class CreateShortcuts extends ListActivity implements OnItemClickListener Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClass(this, LaunchVPN.class); - shortcutIntent.putExtra(LaunchVPN.EXTRA_KEY,profile.getUUID().toString()); + shortcutIntent.putExtra(LaunchVPN.EXTRA_KEY, profile.getUUID().toString()); + shortcutIntent.putExtra(LaunchVPN.EXTRA_START_REASON, "shortcut"); // Then, set up the container intent (the response to the caller) diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/MainActivity.java b/main/src/ui/java/de/blinkt/openvpn/activities/MainActivity.java deleted file mode 100644 index a6d5ecc4..00000000 --- a/main/src/ui/java/de/blinkt/openvpn/activities/MainActivity.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (c) 2012-2016 Arne Schwabe - * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt - */ - -package de.blinkt.openvpn.activities; - -import android.content.Intent; -import android.net.Uri; -import android.view.Menu; -import android.view.MenuItem; -import android.widget.Toast; - -import androidx.appcompat.app.ActionBar; -import androidx.viewpager.widget.ViewPager; - -import com.google.android.material.tabs.TabLayout; - -import de.blinkt.openvpn.R; -import de.blinkt.openvpn.fragments.AboutFragment; -import de.blinkt.openvpn.fragments.FaqFragment; -import de.blinkt.openvpn.fragments.GeneralSettings; -import de.blinkt.openvpn.fragments.GraphFragment; -import de.blinkt.openvpn.fragments.ImportRemoteConfig; -import de.blinkt.openvpn.fragments.LogFragment; -import de.blinkt.openvpn.fragments.SendDumpFragment; -import de.blinkt.openvpn.fragments.VPNProfileList; -import de.blinkt.openvpn.views.ScreenSlidePagerAdapter; - - -public class MainActivity extends BaseActivity { - - private static final String FEATURE_TELEVISION = "android.hardware.type.television"; - private static final String FEATURE_LEANBACK = "android.software.leanback"; - private TabLayout mTabs; - private ViewPager mPager; - private ScreenSlidePagerAdapter mPagerAdapter; - - protected void onCreate(android.os.Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.main_activity); - - - // Instantiate a ViewPager and a PagerAdapter. - mPager = findViewById(R.id.pager); - mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager(), this); - - /* Toolbar and slider should have the same elevation */ - disableToolbarElevation(); - - - mPagerAdapter.addTab(R.string.vpn_list_title, VPNProfileList.class); - mPagerAdapter.addTab(R.string.graph, GraphFragment.class); - - mPagerAdapter.addTab(R.string.generalsettings, GeneralSettings.class); - mPagerAdapter.addTab(R.string.faq, FaqFragment.class); - - if (SendDumpFragment.getLastestDump(this) != null) { - mPagerAdapter.addTab(R.string.crashdump, SendDumpFragment.class); - } - - - if (isAndroidTV()) - mPagerAdapter.addTab(R.string.openvpn_log, LogFragment.class); - - mPagerAdapter.addTab(R.string.about, AboutFragment.class); - mPager.setAdapter(mPagerAdapter); - } - - - private void disableToolbarElevation() { - ActionBar toolbar = getSupportActionBar(); - toolbar.setElevation(0); - } - - @Override - protected void onResume() { - super.onResume(); - Intent intent = getIntent(); - if (intent != null) { - String action = intent.getAction(); - if (Intent.ACTION_VIEW.equals(action)) - { - Uri uri = intent.getData(); - if (uri != null) - checkUriForProfileImport(uri); - } - String page = intent.getStringExtra("PAGE"); - if ("graph".equals(page)) { - mPager.setCurrentItem(1); - } - setIntent(null); - } - } - - private void checkUriForProfileImport(Uri uri) { - if ("openvpn".equals(uri.getScheme()) && "import-profile".equals(uri.getHost())) - { - String realUrl = uri.getEncodedPath() + "?" + uri.getEncodedQuery(); - if (!realUrl.startsWith("/https://")) - { - Toast.makeText(this, "Cannot use openvpn://import-profile/ URL that does not use https://", Toast.LENGTH_LONG).show(); - return; - } - realUrl = realUrl.substring(1); - startOpenVPNUrlImport(realUrl); - } - } - - private void startOpenVPNUrlImport(String url) { - ImportRemoteConfig asImportFrag = ImportRemoteConfig.newInstance(url); - asImportFrag.show(getSupportFragmentManager(), "dialog"); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.main_menu, menu); - return super.onCreateOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.show_log) { - Intent showLog = new Intent(this, LogWindow.class); - startActivity(showLog); - } - return super.onOptionsItemSelected(item); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - System.out.println(data); - - - } - - -} diff --git a/main/src/ui/java/de/blinkt/openvpn/activities/MainActivity.kt b/main/src/ui/java/de/blinkt/openvpn/activities/MainActivity.kt new file mode 100644 index 00000000..68117b52 --- /dev/null +++ b/main/src/ui/java/de/blinkt/openvpn/activities/MainActivity.kt @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2012-2016 Arne Schwabe + * Distributed under the GNU GPL v2 with additional terms. For full terms see the file doc/LICENSE.txt + */ +package de.blinkt.openvpn.activities + +import android.content.Intent +import android.net.Uri +import android.os.Bundle +import android.view.Menu +import android.view.MenuItem +import android.widget.Toast +import androidx.viewpager.widget.ViewPager +import com.google.android.material.tabs.TabLayout +import de.blinkt.openvpn.R +import de.blinkt.openvpn.fragments.* +import de.blinkt.openvpn.fragments.ImportRemoteConfig.Companion.newInstance +import de.blinkt.openvpn.views.ScreenSlidePagerAdapter + +class MainActivity : BaseActivity() { + private lateinit var mPager: ViewPager + private lateinit var mPagerAdapter: ScreenSlidePagerAdapter + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.main_activity) + + + // Instantiate a ViewPager and a PagerAdapter. + mPager = findViewById(R.id.pager) + mPagerAdapter = ScreenSlidePagerAdapter(supportFragmentManager, this) + + /* Toolbar and slider should have the same elevation */disableToolbarElevation() + mPagerAdapter.addTab(R.string.vpn_list_title, VPNProfileList::class.java) + mPagerAdapter.addTab(R.string.graph, GraphFragment::class.java) + mPagerAdapter.addTab(R.string.generalsettings, GeneralSettings::class.java) + mPagerAdapter.addTab(R.string.faq, FaqFragment::class.java) + if (SendDumpFragment.getLastestDump(this) != null) { + mPagerAdapter.addTab(R.string.crashdump, SendDumpFragment::class.java) + } + if (isAndroidTV) + mPagerAdapter.addTab(R.string.openvpn_log, LogFragment::class.java) + mPagerAdapter.addTab(R.string.about, AboutFragment::class.java) + mPager.setAdapter(mPagerAdapter) + } + + private fun disableToolbarElevation() { + supportActionBar?.elevation = 0f + } + + override fun onResume() { + super.onResume() + val intent = intent + if (intent != null) { + val action = intent.action + if (Intent.ACTION_VIEW == action) { + val uri = intent.data + uri?.let { checkUriForProfileImport(it) } + } + val page = intent.getStringExtra("PAGE") + if ("graph" == page) { + mPager.currentItem = 1 + } + setIntent(null) + } + } + + private fun checkUriForProfileImport(uri: Uri) { + if ("openvpn" == uri.scheme && "import-profile" == uri.host) { + var realUrl = uri.encodedPath + "?" + uri.encodedQuery + if (!realUrl.startsWith("/https://")) { + Toast.makeText( + this, + "Cannot use openvpn://import-profile/ URL that does not use https://", + Toast.LENGTH_LONG + ).show() + return + } + realUrl = realUrl.substring(1) + startOpenVPNUrlImport(realUrl) + } + } + + private fun startOpenVPNUrlImport(url: String) { + val asImportFrag = newInstance(url) + asImportFrag.show(supportFragmentManager, "dialog") + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.main_menu, menu) + return super.onCreateOptionsMenu(menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == R.id.show_log) { + val showLog = Intent(this, LogWindow::class.java) + startActivity(showLog) + } + return super.onOptionsItemSelected(item) + } +}
\ No newline at end of file |