forked from mattermost/mattermost-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pavelborzikov
committed
Feb 12, 2019
1 parent
b9f55dc
commit ae910f9
Showing
9 changed files
with
139 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
android/app/src/main/java/com/mattermost/rnbeta/UserAgentModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.mattermost.rnbeta; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.PackageInfo; | ||
import android.util.Log; | ||
import android.os.Build; | ||
import android.webkit.WebSettings; | ||
import android.webkit.WebView; | ||
|
||
import com.facebook.react.bridge.Arguments; | ||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.WritableArray; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class UserAgentModule extends ReactContextBaseJavaModule { | ||
|
||
private final ReactApplicationContext reactContext; | ||
|
||
public UserAgentModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
this.reactContext = reactContext; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "RNUserAgent"; | ||
} | ||
|
||
protected String getUserAgent() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
return System.getProperty("http.agent"); | ||
} | ||
|
||
return ""; | ||
} | ||
|
||
protected String getWebViewUserAgent() { | ||
if (Build.VERSION.SDK_INT >= 17) { | ||
return WebSettings.getDefaultUserAgent(this.reactContext); | ||
} | ||
|
||
// try { | ||
// Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class); | ||
// constructor.setAccessible(true); | ||
// try { | ||
// WebSettings settings = constructor.newInstance(this.reactContext, null); | ||
// return settings.getUserAgentString(); | ||
// } finally { | ||
// constructor.setAccessible(false); | ||
// } | ||
// } catch (Exception e) { | ||
// return new WebView(this.reactContext).getSettings().getUserAgentString(); | ||
// } | ||
|
||
return new WebView(this.reactContext).getSettings().getUserAgentString(); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getConstants() { | ||
HashMap<String, Object> constants = new HashMap<String, Object>(); | ||
|
||
PackageManager packageManager = this.reactContext.getPackageManager(); | ||
String packageName = this.reactContext.getPackageName(); | ||
String shortPackageName = packageName.substring(packageName.lastIndexOf(".") + 1); | ||
String applicationName = ""; | ||
String applicationVersion = ""; | ||
Integer buildNumber = 0; | ||
String userAgent = this.getUserAgent(); | ||
|
||
try { | ||
PackageInfo info = packageManager.getPackageInfo(packageName, 0); | ||
applicationName = this.reactContext.getApplicationInfo().loadLabel(this.reactContext.getPackageManager()).toString(); | ||
applicationVersion = info.versionName; | ||
buildNumber = info.versionCode; | ||
userAgent = shortPackageName + '/' + applicationVersion + '.' + buildNumber.toString() + ' ' + userAgent; | ||
|
||
} catch(PackageManager.NameNotFoundException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
constants.put("systemName", "Android"); | ||
constants.put("systemVersion", Build.VERSION.RELEASE); | ||
constants.put("packageName", packageName); | ||
constants.put("shortPackageName", shortPackageName); | ||
constants.put("applicationName", applicationName); | ||
constants.put("applicationVersion", applicationVersion); | ||
constants.put("applicationBuildNumber", buildNumber); | ||
constants.put("userAgent", userAgent); | ||
constants.put("webViewUserAgent", this.getWebViewUserAgent()); | ||
|
||
return constants; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
android/app/src/main/java/com/mattermost/rnbeta/UserAgentPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.mattermost.rnbeta; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
|
||
public class UserAgentPackage implements ReactPackage { | ||
@Override | ||
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) { | ||
return Arrays.<NativeModule>asList(new UserAgentModule(reactContext)); | ||
} | ||
|
||
@Override | ||
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters