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

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

Issue 29603697: Issue 5931 - Create tests for util package (Closed)
Patch Set: Created Nov. 10, 2017, 2:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.sbrowser.contentblocker.engine;
19
20 import java.util.Locale;
21 import android.annotation.SuppressLint;
22 import android.content.Context;
23 import android.os.Build;
24
25 @SuppressLint("DefaultLocale")
26 public class AppInfo
27 {
28 public final String addonName;
29 public final String addonVersion;
30 public final String application;
31 public final String applicationVersion;
32 public final String platform;
33 public final String platformVersion;
34 public final String locale;
35
36 private AppInfo(
37 final String addonName,
38 final String addonVersion,
39 final String application,
40 final String applicationVersion,
41 final String platform,
42 final String platformVersion,
43 final String locale)
44 {
45 this.addonName = addonName;
46 this.addonVersion = addonVersion;
47 this.application = application;
48 this.applicationVersion = applicationVersion;
49 this.platform = platform;
50 this.platformVersion = platformVersion;
51 this.locale = locale;
52 }
53
54 @Override
55 public String toString()
56 {
57 final StringBuilder sb = new StringBuilder();
58
59 sb.append("{addonName=");
60 sb.append(this.addonName);
61 sb.append(", addonVersion=");
62 sb.append(this.addonVersion);
63 sb.append(", application=");
64 sb.append(this.application);
65 sb.append(", applicationVersion=");
66 sb.append(this.applicationVersion);
67 sb.append(", platform=");
68 sb.append(this.platform);
69 sb.append(", platformVersion=");
70 sb.append(this.platformVersion);
71 sb.append(", locale=");
72 sb.append(this.locale);
73 sb.append('}');
74
75 return sb.toString();
76 }
77
78 public static AppInfo create(final Context context)
79 {
80 return new Builder().autoFill(context).build();
81 }
82
83 public static class Builder
84 {
85 private static final String SBROWSER_PACKAGE_NAME = "com.sec.android.app.sbr owser";
86
87 private String addonName = "adblockplussbrowser";
88 private String addonVersion = "0";
89 private String application = "sbrowser";
90 private String applicationVersion = "0";
91 private String platform = "android";
92 private String platformVersion = Integer.toString(Build.VERSION.SDK_INT);
93 private String locale = "en-US";
94
95 public Builder autoFill(Context context)
96 {
97 try
98 {
99 this.addonVersion = context.getPackageManager().getPackageInfo(context.g etPackageName(), 0).versionName
100 .toLowerCase();
101 }
102 catch (Throwable t)
103 {
104 // ignored
105 }
106
107 try
108 {
109 this.applicationVersion = context.getPackageManager().getPackageInfo(SBR OWSER_PACKAGE_NAME,
110 0).versionName.toLowerCase();
111 }
112 catch (Throwable t)
113 {
114 // ignored
115 }
116
117 this.locale = Locale.getDefault().toString().replace('_', '-');
118
119 return this;
120 }
121
122 public AppInfo build()
123 {
124 return new AppInfo(this.addonName, this.addonVersion, this.application,
125 this.applicationVersion, this.platform, this.platformVersion, this.loc ale);
126 }
127 }
128 }
OLDNEW

Powered by Google App Engine
This is Rietveld