OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 package org.adblockplus.sbrowser.contentblocker.engine; | 18 package org.adblockplus.sbrowser.contentblocker.engine; |
19 | 19 |
20 import java.util.Locale; | 20 import java.util.Locale; |
21 import android.annotation.SuppressLint; | 21 import android.annotation.SuppressLint; |
22 import android.content.Context; | 22 import android.content.Context; |
| 23 import android.content.pm.PackageManager; |
23 import android.os.Build; | 24 import android.os.Build; |
24 | 25 |
25 @SuppressLint("DefaultLocale") | 26 @SuppressLint("DefaultLocale") |
26 public class AppInfo | 27 public class AppInfo |
27 { | 28 { |
28 public final String addonName; | 29 public final String addonName; |
29 public final String addonVersion; | 30 public final String addonVersion; |
30 public final String application; | 31 public final String application; |
31 public final String applicationVersion; | 32 public final String applicationVersion; |
32 public final String platform; | 33 public final String platform; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 77 } |
77 | 78 |
78 public static AppInfo create(final Context context) | 79 public static AppInfo create(final Context context) |
79 { | 80 { |
80 return new Builder().autoFill(context).build(); | 81 return new Builder().autoFill(context).build(); |
81 } | 82 } |
82 | 83 |
83 public static class Builder | 84 public static class Builder |
84 { | 85 { |
85 private static final String SBROWSER_PACKAGE_NAME = "com.sec.android.app.sbr
owser"; | 86 private static final String SBROWSER_PACKAGE_NAME = "com.sec.android.app.sbr
owser"; |
| 87 private static final String SBROWSER_BETA_PACKAGE_NAME = "com.sec.android.ap
p.sbrowser.beta"; |
| 88 private static final String SBROWSER_APP_NAME = "sbrowser"; |
| 89 private static final String YANDEX_PACKAGE_NAME = "com.yandex.browser"; |
| 90 private static final String YANDEX_ALPHA_PACKAGE_NAME = "com.yandex.browser.
alpha"; |
| 91 private static final String YANDEX_BETA_PACKAGE_NAME = "com.yandex.browser.b
eta"; |
| 92 private static final String YANDEX_APP_NAME = "yandex"; |
86 | 93 |
87 private String addonName = "adblockplussbrowser"; | 94 private String addonName = "adblockplussbrowser"; |
88 private String addonVersion = "0"; | 95 private String addonVersion = "0"; |
89 private String application = "sbrowser"; | 96 private String application = ""; |
90 private String applicationVersion = "0"; | 97 private String applicationVersion = "0"; |
91 private String platform = "android"; | 98 private String platform = "android"; |
92 private String platformVersion = Integer.toString(Build.VERSION.SDK_INT); | 99 private String platformVersion = Integer.toString(Build.VERSION.SDK_INT); |
93 private String locale = "en-US"; | 100 private String locale = "en-US"; |
94 | 101 |
95 public Builder autoFill(Context context) | 102 public Builder autoFill(Context context) |
96 { | 103 { |
97 try | 104 try |
98 { | 105 { |
99 this.addonVersion = context.getPackageManager().getPackageInfo(context.g
etPackageName(), 0).versionName | 106 this.addonVersion = context.getPackageManager().getPackageInfo(context.g
etPackageName(), 0).versionName |
100 .toLowerCase(); | 107 .toLowerCase(); |
101 } | 108 } |
102 catch (Throwable t) | 109 catch (Throwable t) |
103 { | 110 { |
104 // ignored | 111 // ignored |
105 } | 112 } |
106 | 113 |
107 try | 114 try |
108 { | 115 { |
109 this.applicationVersion = context.getPackageManager().getPackageInfo(SBR
OWSER_PACKAGE_NAME, | 116 this.applicationVersion = context.getPackageManager().getPackageInfo(SBR
OWSER_PACKAGE_NAME, |
110 0).versionName.toLowerCase(); | 117 0).versionName.toLowerCase(); |
111 } | 118 } |
112 catch (Throwable t) | 119 catch (Throwable t) |
113 { | 120 { |
114 // ignored | 121 // ignored |
115 } | 122 } |
116 | 123 |
117 this.locale = Locale.getDefault().toString().replace('_', '-'); | 124 this.locale = Locale.getDefault().toString().replace('_', '-'); |
118 | 125 |
| 126 this.application = checkForCompatibleInstalledBrowser(context.getPackageMa
nager()); |
| 127 |
119 return this; | 128 return this; |
120 } | 129 } |
121 | 130 |
122 public AppInfo build() | 131 public AppInfo build() |
123 { | 132 { |
124 return new AppInfo(this.addonName, this.addonVersion, this.application, | 133 return new AppInfo(this.addonName, this.addonVersion, this.application, |
125 this.applicationVersion, this.platform, this.platformVersion, this.loc
ale); | 134 this.applicationVersion, this.platform, this.platformVersion, this.loc
ale); |
126 } | 135 } |
| 136 |
| 137 private String checkForCompatibleInstalledBrowser(final PackageManager packa
geManager) |
| 138 { |
| 139 StringBuilder installedCompatibleBrowser = new StringBuilder(); |
| 140 |
| 141 if (isPackageInstalled(packageManager, SBROWSER_PACKAGE_NAME) |
| 142 || isPackageInstalled(packageManager, SBROWSER_BETA_PACKAGE_NAME)) |
| 143 { |
| 144 installedCompatibleBrowser.append(SBROWSER_APP_NAME); |
| 145 } |
| 146 |
| 147 if (isPackageInstalled(packageManager, YANDEX_PACKAGE_NAME) |
| 148 || isPackageInstalled(packageManager, YANDEX_ALPHA_PACKAGE_NAME) |
| 149 || isPackageInstalled(packageManager, YANDEX_BETA_PACKAGE_NAME)) |
| 150 { |
| 151 installedCompatibleBrowser.append(YANDEX_APP_NAME); |
| 152 } |
| 153 |
| 154 return installedCompatibleBrowser.toString(); |
| 155 } |
| 156 |
| 157 private boolean isPackageInstalled(final PackageManager packageManager, fina
l String packageName) |
| 158 { |
| 159 try |
| 160 { |
| 161 packageManager.getPackageInfo(packageName, 0); |
| 162 return true; |
| 163 } |
| 164 catch (PackageManager.NameNotFoundException e) |
| 165 { |
| 166 return false; |
| 167 } |
| 168 } |
127 } | 169 } |
128 } | 170 } |
OLD | NEW |