Fixed Huawei build
This commit is contained in:
parent
6b3dfbe0a3
commit
30097c2249
6 changed files with 130 additions and 63 deletions
5
OsmAnd/.gitignore
vendored
5
OsmAnd/.gitignore
vendored
|
@ -13,6 +13,11 @@ libs/it.unibo.alice.tuprolog-tuprolog-3.2.1.jar
|
||||||
libs/commons-codec-commons-codec-1.11.jar
|
libs/commons-codec-commons-codec-1.11.jar
|
||||||
libs/OsmAndCore_android-0.1-SNAPSHOT.jar
|
libs/OsmAndCore_android-0.1-SNAPSHOT.jar
|
||||||
|
|
||||||
|
libs/huawei-*.jar
|
||||||
|
huaweidrmlib/
|
||||||
|
HwDRM_SDK_*
|
||||||
|
drm_strings.xml
|
||||||
|
|
||||||
valgrind/
|
valgrind/
|
||||||
bin/
|
bin/
|
||||||
dist/
|
dist/
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.huawei.android.sdk.drm"
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
android:versionCode="2"
|
|
||||||
android:versionName="2.0.0" >
|
|
||||||
|
|
||||||
<uses-sdk
|
<application>
|
||||||
android:minSdkVersion="14"
|
<activity android:name="com.huawei.android.sdk.drm.DrmDialogActivity"
|
||||||
android:targetSdkVersion="21" />
|
android:configChanges="screenSize|orientation|keyboardHidden"
|
||||||
|
android:exported="false"
|
||||||
|
android:theme="@android:style/Theme.Translucent">
|
||||||
|
<meta-data
|
||||||
|
android:name="hwc-theme"
|
||||||
|
android:value="androidhwext:style/Theme.Emui.Translucent" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<application
|
<provider
|
||||||
android:allowBackup="true"
|
android:name="android.support.v4.content.FileProvider"
|
||||||
android:icon="@drawable/ic_launcher"
|
android:authorities="net.osmand.plus.huawei.fileprovider"
|
||||||
android:theme="@style/AppTheme" >
|
tools:replace="android:authorities" />
|
||||||
<activity
|
<service
|
||||||
android:name="com.huawei.android.sdk.drm.DrmDialogActivity"
|
android:name="net.osmand.plus.NavigationService"
|
||||||
android:configChanges="screenSize|orientation|keyboardHidden"
|
android:process="net.osmand.plus.huawei"
|
||||||
android:exported="false"
|
tools:replace="android:process" />
|
||||||
android:theme="@android:style/Theme.Translucent" >
|
</application>
|
||||||
<meta-data
|
|
||||||
android:name="hwc-theme"
|
|
||||||
android:value="androidhwext:style/Theme.Emui.Translucent" />
|
|
||||||
</activity>
|
|
||||||
</application>
|
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
|
@ -17,9 +17,6 @@ apply plugin: 'com.android.application'
|
||||||
// </unzip>
|
// </unzip>
|
||||||
// Less important
|
// Less important
|
||||||
|
|
||||||
|
|
||||||
def huawei = (System.getenv("APP_FEATURES") && System.getenv("APP_FEATURES").contains("+huawei"))
|
|
||||||
|
|
||||||
task printc {
|
task printc {
|
||||||
configurations.each { if(it.isCanBeResolved()) println it.name }
|
configurations.each { if(it.isCanBeResolved()) println it.name }
|
||||||
}
|
}
|
||||||
|
@ -114,6 +111,9 @@ android {
|
||||||
freecustom {
|
freecustom {
|
||||||
manifest.srcFile "AndroidManifest-freecustom.xml"
|
manifest.srcFile "AndroidManifest-freecustom.xml"
|
||||||
}
|
}
|
||||||
|
huawei {
|
||||||
|
manifest.srcFile "AndroidManifest-huawei.xml"
|
||||||
|
}
|
||||||
|
|
||||||
legacy {
|
legacy {
|
||||||
jniLibs.srcDirs = ["libc++"]
|
jniLibs.srcDirs = ["libc++"]
|
||||||
|
@ -177,6 +177,10 @@ android {
|
||||||
resConfig "en"
|
resConfig "en"
|
||||||
//resConfigs "xxhdpi", "nodpi"
|
//resConfigs "xxhdpi", "nodpi"
|
||||||
}
|
}
|
||||||
|
huawei {
|
||||||
|
dimension "version"
|
||||||
|
applicationId "net.osmand.plus.huawei"
|
||||||
|
}
|
||||||
|
|
||||||
// CoreVersion
|
// CoreVersion
|
||||||
legacy {
|
legacy {
|
||||||
|
@ -253,12 +257,39 @@ task downloadWorldMiniBasemap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task downloadHuaweiDrm {
|
task downloadHuaweiDrmZip {
|
||||||
doLast {
|
doLast {
|
||||||
if (huawei) {
|
ant.get(src: 'https://obs.cn-north-2.myhwclouds.com/hms-ds-wf/sdk/HwDRM_SDK_2.5.2.300_ADT.zip', dest: 'HwDRM_SDK_2.5.2.300_ADT.zip', skipexisting: 'true')
|
||||||
ant.get(src: 'https://obs.cn-north-2.myhwclouds.com/hms-ds-wf/sdk/HwDRM_SDK_2.5.2.300_ADT.zip', dest: 'HwDRM_SDK_2.5.2.300_ADT.zip', skipexisting: 'true')
|
ant.unzip(src: 'HwDRM_SDK_2.5.2.300_ADT.zip', dest: 'huaweidrmlib/')
|
||||||
ant.unzip(src: 'HwDRM_SDK_2.5.2.300_ADT.zip', dest: 'libs/')
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task copyHuaweiDrmLibs(type: Copy) {
|
||||||
|
dependsOn downloadHuaweiDrmZip
|
||||||
|
from "huaweidrmlib/HwDRM_SDK_2.5.2.300_ADT/libs"
|
||||||
|
into "libs"
|
||||||
|
}
|
||||||
|
|
||||||
|
task copyHuaweiDrmValues(type: Copy) {
|
||||||
|
dependsOn downloadHuaweiDrmZip
|
||||||
|
from "huaweidrmlib/HwDRM_SDK_2.5.2.300_ADT/res"
|
||||||
|
into "res"
|
||||||
|
}
|
||||||
|
|
||||||
|
task downloadPrebuiltHuaweiDrm {
|
||||||
|
dependsOn copyHuaweiDrmLibs, copyHuaweiDrmValues
|
||||||
|
}
|
||||||
|
|
||||||
|
task cleanHuaweiDrmLibs(type: Delete) {
|
||||||
|
delete "huaweidrmlib"
|
||||||
|
delete fileTree("libs").matching {
|
||||||
|
include "**/huawei-*.jar"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task cleanHuaweiDrmValues(type: Delete) {
|
||||||
|
delete fileTree("res").matching {
|
||||||
|
include "**/drm_strings.xml"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,8 +358,7 @@ task collectExternalResources {
|
||||||
updateNoTranslate,
|
updateNoTranslate,
|
||||||
validateTranslate,
|
validateTranslate,
|
||||||
copyWidgetIcons,
|
copyWidgetIcons,
|
||||||
downloadWorldMiniBasemap,
|
downloadWorldMiniBasemap
|
||||||
downloadHuaweiDrm
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy core build
|
// Legacy core build
|
||||||
|
@ -375,9 +405,16 @@ task cleanupDuplicatesInCore() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
android.applicationVariants.all { variant ->
|
android.applicationVariants.all { variant ->
|
||||||
variant.javaCompiler.dependsOn(collectExternalResources, buildOsmAndCore, cleanupDuplicatesInCore)
|
variant.javaCompiler.dependsOn(collectExternalResources, buildOsmAndCore, cleanupDuplicatesInCore)
|
||||||
}
|
|
||||||
|
// Use Drm strings only for huawei flavor
|
||||||
|
if ("huawei" == variant.productFlavors[0].name) {
|
||||||
|
variant.javaCompiler.dependsOn downloadPrebuiltHuaweiDrm
|
||||||
|
} else {
|
||||||
|
variant.javaCompiler.dependsOn(cleanHuaweiDrmLibs, cleanHuaweiDrmValues)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task appStart(type: Exec) {
|
task appStart(type: Exec) {
|
||||||
|
@ -435,7 +472,5 @@ dependencies {
|
||||||
exclude group: 'com.android.support'
|
exclude group: 'com.android.support'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (huawei) {
|
huaweiImplementation files('libs/huawei-android-drm_v2.5.2.300.jar')
|
||||||
implementation files('libs/huawei-android-drm_v2.5.2.300.jar')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,39 +1,66 @@
|
||||||
package net.osmand.plus;
|
package net.osmand.plus;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
//import com.huawei.android.sdk.drm.Drm;
|
import java.lang.ref.WeakReference;
|
||||||
//import com.huawei.android.sdk.drm.DrmCheckCallback;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class HuaweiDrmHelper {
|
public class HuaweiDrmHelper {
|
||||||
private Activity activity;
|
private static final String TAG = HuaweiDrmHelper.class.getSimpleName();
|
||||||
//private DrmCheckCallback callback;
|
|
||||||
|
|
||||||
//Copyright protection id
|
//Copyright protection id
|
||||||
private static final String DRM_ID = "101048021";
|
private static final String DRM_ID = "101048021";
|
||||||
//Copyright protection public key
|
//Copyright protection public key
|
||||||
private static final String DRM_PUBLIC_KEY = "e0a6c798fddfd0927bd509dfeafcef4b61c4408d7ea0ca9dfb4b7766b964f801";
|
private static final String DRM_PUBLIC_KEY = "e0a6c798fddfd0927bd509dfeafcef4b61c4408d7ea0ca9dfb4b7766b964f801";
|
||||||
|
|
||||||
public HuaweiDrmHelper(final Activity activity) {
|
|
||||||
this.activity = activity;
|
|
||||||
/*
|
|
||||||
callback = new DrmCheckCallback() {
|
|
||||||
@Override
|
|
||||||
public void onCheckSuccess() { }
|
|
||||||
|
|
||||||
@Override
|
public static void check(Activity activity) {
|
||||||
public void onCheckFailed() {
|
boolean succeed = false;
|
||||||
activity.finish();
|
try {
|
||||||
}
|
final WeakReference<Activity> activityRef = new WeakReference<>(activity);
|
||||||
};
|
Class<?> drmCheckCallbackClass = Class.forName("com.huawei.android.sdk.drm.DrmCheckCallback");
|
||||||
*/
|
Object callback = java.lang.reflect.Proxy.newProxyInstance(
|
||||||
|
drmCheckCallbackClass.getClassLoader(),
|
||||||
|
new java.lang.Class[]{drmCheckCallbackClass},
|
||||||
|
new java.lang.reflect.InvocationHandler() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) {
|
||||||
|
Activity a = activityRef.get();
|
||||||
|
if (a != null && !a.isFinishing()) {
|
||||||
|
String method_name = method.getName();
|
||||||
|
if (method_name.equals("onCheckSuccess")) {
|
||||||
|
// skip now
|
||||||
|
} else if (method_name.equals("onCheckFailed")) {
|
||||||
|
closeApplication(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Class<?> drmClass = Class.forName("com.huawei.android.sdk.drm.Drm");
|
||||||
|
Class[] partypes = new Class[]{Activity.class, String.class, String.class, String.class, drmCheckCallbackClass};
|
||||||
|
Method check = drmClass.getMethod("check", partypes);
|
||||||
|
check.invoke(null, activity, activity.getPackageName(), DRM_ID, DRM_PUBLIC_KEY, callback);
|
||||||
|
succeed = true;
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
Log.e(TAG, "check: ", e);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
Log.e(TAG, "check: ", e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
Log.e(TAG, "check: ", e);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
Log.e(TAG, "check: ", e);
|
||||||
|
}
|
||||||
|
if (!succeed) {
|
||||||
|
closeApplication(activity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void check() {
|
private static void closeApplication(Activity activity) {
|
||||||
//Drm.check(getActivity(), getActivity().getPackageName(), DRM_ID, DRM_PUBLIC_KEY, callback);
|
((OsmandApplication) activity.getApplication()).closeApplicationAnywayImpl(activity, true);
|
||||||
}
|
|
||||||
|
|
||||||
public Activity getActivity() {
|
|
||||||
return this.activity;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class Version {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHuawei(OsmandApplication ctx) {
|
public static boolean isHuawei(OsmandApplication ctx) {
|
||||||
return ctx.getString(R.string.versionFeatures).contains("+huawei");
|
return ctx.getPackageName().endsWith(".huawei");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMarketEnabled(OsmandApplication ctx) {
|
public static boolean isMarketEnabled(OsmandApplication ctx) {
|
||||||
|
|
|
@ -253,7 +253,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
if (Version.isHuawei(getMyApplication())) {
|
if (Version.isHuawei(getMyApplication())) {
|
||||||
new HuaweiDrmHelper(this).check();
|
HuaweiDrmHelper.check(this);
|
||||||
}
|
}
|
||||||
// Full screen is not used here
|
// Full screen is not used here
|
||||||
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
|
|
Loading…
Reference in a new issue