Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/AppInfo.java

Issue 29640558: Issue 6187 - Adjust query string parameters for Yandex (Closed)
Patch Set: Renamed method to isPackageInstalled Created Dec. 18, 2017, 9:29 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/AppInfo.java
===================================================================
--- a/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/AppInfo.java
+++ b/adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/AppInfo.java
@@ -15,16 +15,17 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.adblockplus.sbrowser.contentblocker.engine;
import java.util.Locale;
import android.annotation.SuppressLint;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.os.Build;
@SuppressLint("DefaultLocale")
public class AppInfo
{
public final String addonName;
public final String addonVersion;
public final String application;
@@ -78,20 +79,26 @@ public class AppInfo
public static AppInfo create(final Context context)
{
return new Builder().autoFill(context).build();
}
public static class Builder
{
private static final String SBROWSER_PACKAGE_NAME = "com.sec.android.app.sbrowser";
+ private static final String SBROWSER_BETA_PACKAGE_NAME = "com.sec.android.app.sbrowser.beta";
+ private static final String SBROWSER_APP_NAME = "sbrowser";
+ private static final String YANDEX_PACKAGE_NAME = "com.yandex.browser";
+ private static final String YANDEX_ALPHA_PACKAGE_NAME = "com.yandex.browser.alpha";
+ private static final String YANDEX_BETA_PACKAGE_NAME = "com.yandex.browser.beta";
+ private static final String YANDEX_APP_NAME = "yandex";
private String addonName = "adblockplussbrowser";
private String addonVersion = "0";
- private String application = "sbrowser";
+ private String application = "";
private String applicationVersion = "0";
private String platform = "android";
private String platformVersion = Integer.toString(Build.VERSION.SDK_INT);
private String locale = "en-US";
public Builder autoFill(Context context)
{
try
@@ -111,18 +118,53 @@ public class AppInfo
}
catch (Throwable t)
{
// ignored
}
this.locale = Locale.getDefault().toString().replace('_', '-');
+ this.application = checkForCompatibleInstalledBrowser(context.getPackageManager());
+
return this;
}
public AppInfo build()
{
return new AppInfo(this.addonName, this.addonVersion, this.application,
this.applicationVersion, this.platform, this.platformVersion, this.locale);
}
+
+ private String checkForCompatibleInstalledBrowser(final PackageManager packageManager)
+ {
+ StringBuilder installedCompatibleBrowser = new StringBuilder();
+
+ if (isPackageInstalled(packageManager, SBROWSER_PACKAGE_NAME)
+ || isPackageInstalled(packageManager, SBROWSER_BETA_PACKAGE_NAME))
+ {
+ installedCompatibleBrowser.append(SBROWSER_APP_NAME);
+ }
+
+ if (isPackageInstalled(packageManager, YANDEX_PACKAGE_NAME)
+ || isPackageInstalled(packageManager, YANDEX_ALPHA_PACKAGE_NAME)
+ || isPackageInstalled(packageManager, YANDEX_BETA_PACKAGE_NAME))
+ {
+ installedCompatibleBrowser.append(YANDEX_APP_NAME);
+ }
+
+ return installedCompatibleBrowser.toString();
+ }
+
+ private boolean isPackageInstalled(final PackageManager packageManager, final String packageName)
+ {
+ try
+ {
+ packageManager.getPackageInfo(packageName, 0);
+ return true;
+ }
+ catch (PackageManager.NameNotFoundException e)
+ {
+ return false;
+ }
+ }
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld