mirror of
https://gitlab.com/oeffi/oeffi.git
synced 2025-07-07 06:08:51 +00:00
Installer: Introduce enum class for the installerPackageName.
This commit is contained in:
parent
cfabfa2ea8
commit
af44f7b436
3 changed files with 83 additions and 9 deletions
|
@ -32,8 +32,6 @@ import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -54,6 +52,7 @@ import de.schildbach.oeffi.util.DialogBuilder;
|
||||||
import de.schildbach.oeffi.util.DividerItemDecoration;
|
import de.schildbach.oeffi.util.DividerItemDecoration;
|
||||||
import de.schildbach.oeffi.util.Downloader;
|
import de.schildbach.oeffi.util.Downloader;
|
||||||
import de.schildbach.oeffi.util.ErrorReporter;
|
import de.schildbach.oeffi.util.ErrorReporter;
|
||||||
|
import de.schildbach.oeffi.util.Installer;
|
||||||
import de.schildbach.oeffi.util.NavigationMenuAdapter;
|
import de.schildbach.oeffi.util.NavigationMenuAdapter;
|
||||||
import de.schildbach.oeffi.util.UiThreadExecutor;
|
import de.schildbach.oeffi.util.UiThreadExecutor;
|
||||||
import de.schildbach.pte.NetworkId;
|
import de.schildbach.pte.NetworkId;
|
||||||
|
@ -80,6 +79,7 @@ import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.PopupMenu;
|
import android.widget.PopupMenu;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.drawerlayout.widget.DrawerLayout;
|
import androidx.drawerlayout.widget.DrawerLayout;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
@ -393,8 +393,9 @@ public abstract class OeffiMainActivity extends OeffiActivity {
|
||||||
remoteFileName.append('-').append(flavor);
|
remoteFileName.append('-').append(flavor);
|
||||||
remoteFileName.append(".txt");
|
remoteFileName.append(".txt");
|
||||||
remoteUrl.addPathSegment(remoteFileName.toString());
|
remoteUrl.addPathSegment(remoteFileName.toString());
|
||||||
remoteUrl.addEncodedQueryParameter("installer",
|
final String installerPackageName = Installer.installerPackageName(this);
|
||||||
Strings.nullToEmpty(getPackageManager().getInstallerPackageName(getPackageName())));
|
if (installerPackageName != null)
|
||||||
|
remoteUrl.addEncodedQueryParameter("installer", installerPackageName);
|
||||||
remoteUrl.addQueryParameter("sdk", Integer.toString(Build.VERSION.SDK_INT));
|
remoteUrl.addQueryParameter("sdk", Integer.toString(Build.VERSION.SDK_INT));
|
||||||
remoteUrl.addQueryParameter("task", taskName());
|
remoteUrl.addQueryParameter("task", taskName());
|
||||||
final File localFile = new File(getFilesDir(), "messages.txt");
|
final File localFile = new File(getFilesDir(), "messages.txt");
|
||||||
|
@ -529,13 +530,11 @@ public abstract class OeffiMainActivity extends OeffiActivity {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (name.equals("installer")) {
|
} else if (name.equals("installer")) {
|
||||||
final String installer = Strings
|
final String installer = Strings.nullToEmpty(Installer.installerPackageName(this));
|
||||||
.nullToEmpty(getPackageManager().getInstallerPackageName(getPackageName()));
|
|
||||||
if (!value.equalsIgnoreCase(installer))
|
if (!value.equalsIgnoreCase(installer))
|
||||||
return false;
|
return false;
|
||||||
} else if (name.equals("not-installer")) {
|
} else if (name.equals("not-installer")) {
|
||||||
final String installer = Strings
|
final String installer = Strings.nullToEmpty(Installer.installerPackageName(this));
|
||||||
.nullToEmpty(getPackageManager().getInstallerPackageName(getPackageName()));
|
|
||||||
if (value.equalsIgnoreCase(installer))
|
if (value.equalsIgnoreCase(installer))
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -113,7 +113,12 @@ public class ErrorReporter implements Thread.UncaughtExceptionHandler {
|
||||||
report.append("Date: " + new Date() + "\n");
|
report.append("Date: " + new Date() + "\n");
|
||||||
report.append("Version: " + pi.versionName + " (" + pi.versionCode + ")\n");
|
report.append("Version: " + pi.versionName + " (" + pi.versionCode + ")\n");
|
||||||
report.append("Package: " + pi.packageName + "\n");
|
report.append("Package: " + pi.packageName + "\n");
|
||||||
report.append("Installer: " + pm.getInstallerPackageName(pi.packageName) + "\n");
|
final String installerPackageName = Installer.installerPackageName(context);
|
||||||
|
final Installer installer = Installer.from(installerPackageName);
|
||||||
|
if (installer != null)
|
||||||
|
report.append("Installer: " + installer.displayName + " (" + installerPackageName + ")\n");
|
||||||
|
else
|
||||||
|
report.append("Installer: unknown\n");
|
||||||
} catch (final NameNotFoundException x) {
|
} catch (final NameNotFoundException x) {
|
||||||
x.printStackTrace();
|
x.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
70
oeffi/src/de/schildbach/oeffi/util/Installer.java
Normal file
70
oeffi/src/de/schildbach/oeffi/util/Installer.java
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* Copyright the original author or authors.
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.schildbach.oeffi.util;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import okhttp3.HttpUrl;
|
||||||
|
|
||||||
|
public enum Installer {
|
||||||
|
F_DROID("F-Droid"), GOOGLE_PLAY("Google Play"), AMAZON_APPSTORE("Amazon Appstore");
|
||||||
|
|
||||||
|
public final String displayName;
|
||||||
|
|
||||||
|
private Installer(final String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String installerPackageName(final Context context) {
|
||||||
|
final PackageManager pm = context.getPackageManager();
|
||||||
|
return pm.getInstallerPackageName(context.getPackageName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Installer from(final String installerPackageName) {
|
||||||
|
if ("org.fdroid.fdroid".equals(installerPackageName)
|
||||||
|
|| "org.fdroid.fdroid.privileged".equals(installerPackageName))
|
||||||
|
return F_DROID;
|
||||||
|
if ("com.android.vending".equals(installerPackageName))
|
||||||
|
return GOOGLE_PLAY;
|
||||||
|
if ("com.amazon.venezia".equals(installerPackageName))
|
||||||
|
return AMAZON_APPSTORE;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Installer from(final Context context) {
|
||||||
|
return from(installerPackageName(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
public HttpUrl appStorePageFor(final Application application) {
|
||||||
|
final HttpUrl.Builder url;
|
||||||
|
if (this == F_DROID) {
|
||||||
|
url = HttpUrl.parse("https://f-droid.org/de/packages/").newBuilder();
|
||||||
|
url.addPathSegment(application.getPackageName());
|
||||||
|
} else if (this == GOOGLE_PLAY) {
|
||||||
|
url = HttpUrl.parse("https://play.google.com/store/apps/details").newBuilder();
|
||||||
|
url.addQueryParameter("id", application.getPackageName());
|
||||||
|
} else if (this == AMAZON_APPSTORE) {
|
||||||
|
url = HttpUrl.parse("https://www.amazon.com/gp/mas/dl/android").newBuilder();
|
||||||
|
url.addQueryParameter("p", application.getPackageName());
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException(this.toString());
|
||||||
|
}
|
||||||
|
return url.build();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue