Left: | ||
Right: |
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_APP_NAME = "sbrowser"; | |
88 private static final String YANDEX_PACKAGE_NAME = "com.yandex.browser"; | |
89 private static final String YANDEX_APP_NAME = "yandex"; | |
86 | 90 |
87 private String addonName = "adblockplussbrowser"; | 91 private String addonName = "adblockplussbrowser"; |
88 private String addonVersion = "0"; | 92 private String addonVersion = "0"; |
89 private String application = "sbrowser"; | 93 private String application = ""; |
90 private String applicationVersion = "0"; | 94 private String applicationVersion = "0"; |
91 private String platform = "android"; | 95 private String platform = "android"; |
92 private String platformVersion = Integer.toString(Build.VERSION.SDK_INT); | 96 private String platformVersion = Integer.toString(Build.VERSION.SDK_INT); |
93 private String locale = "en-US"; | 97 private String locale = "en-US"; |
94 | 98 |
95 public Builder autoFill(Context context) | 99 public Builder autoFill(Context context) |
96 { | 100 { |
97 try | 101 try |
98 { | 102 { |
99 this.addonVersion = context.getPackageManager().getPackageInfo(context.g etPackageName(), 0).versionName | 103 this.addonVersion = context.getPackageManager().getPackageInfo(context.g etPackageName(), 0).versionName |
100 .toLowerCase(); | 104 .toLowerCase(); |
101 } | 105 } |
102 catch (Throwable t) | 106 catch (Throwable t) |
103 { | 107 { |
104 // ignored | 108 // ignored |
105 } | 109 } |
106 | 110 |
107 try | 111 try |
108 { | 112 { |
109 this.applicationVersion = context.getPackageManager().getPackageInfo(SBR OWSER_PACKAGE_NAME, | 113 this.applicationVersion = context.getPackageManager().getPackageInfo(SBR OWSER_PACKAGE_NAME, |
110 0).versionName.toLowerCase(); | 114 0).versionName.toLowerCase(); |
111 } | 115 } |
112 catch (Throwable t) | 116 catch (Throwable t) |
113 { | 117 { |
114 // ignored | 118 // ignored |
115 } | 119 } |
116 | 120 |
117 this.locale = Locale.getDefault().toString().replace('_', '-'); | 121 this.locale = Locale.getDefault().toString().replace('_', '-'); |
118 | 122 |
123 this.application = checkForCompatibleInstalledBrowser(context.getPackageMa nager()); | |
124 | |
119 return this; | 125 return this; |
120 } | 126 } |
121 | 127 |
122 public AppInfo build() | 128 public AppInfo build() |
123 { | 129 { |
124 return new AppInfo(this.addonName, this.addonVersion, this.application, | 130 return new AppInfo(this.addonName, this.addonVersion, this.application, |
125 this.applicationVersion, this.platform, this.platformVersion, this.loc ale); | 131 this.applicationVersion, this.platform, this.platformVersion, this.loc ale); |
126 } | 132 } |
133 | |
134 private String checkForCompatibleInstalledBrowser(final PackageManager packa geManager) | |
diegocarloslima
2017/12/15 16:13:43
I think that we should also consider all the alpha
jens
2017/12/18 08:41:34
Thats actually a good idea :)
| |
135 { | |
136 StringBuilder installedCompatibleBrowser = new StringBuilder(); | |
137 try | |
138 { | |
139 packageManager.getPackageInfo(SBROWSER_PACKAGE_NAME, 0); | |
140 installedCompatibleBrowser.append(SBROWSER_APP_NAME); | |
141 } | |
142 catch (PackageManager.NameNotFoundException e) | |
143 { | |
144 // nothing | |
145 } | |
146 try | |
147 { | |
148 packageManager.getPackageInfo(YANDEX_PACKAGE_NAME, 0); | |
149 installedCompatibleBrowser.append(YANDEX_APP_NAME); | |
150 } | |
151 catch (PackageManager.NameNotFoundException e) | |
152 { | |
153 // nothing | |
154 } | |
155 return installedCompatibleBrowser.toString(); | |
156 } | |
127 } | 157 } |
128 } | 158 } |
OLD | NEW |