Fixed Huawei build

This commit is contained in:
max-klaus 2019-09-11 19:04:12 +03:00
parent 1505b77fea
commit 98162d6b8f
6 changed files with 130 additions and 63 deletions

5
OsmAnd/.gitignore vendored
View file

@ -13,6 +13,11 @@ libs/it.unibo.alice.tuprolog-tuprolog-3.2.1.jar
libs/commons-codec-commons-codec-1.11.jar
libs/OsmAndCore_android-0.1-SNAPSHOT.jar
libs/huawei-*.jar
huaweidrmlib/
HwDRM_SDK_*
drm_strings.xml
valgrind/
bin/
dist/

View file

@ -1,25 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.huawei.android.sdk.drm"
android:versionCode="2"
android:versionName="2.0.0" >
xmlns:tools="http://schemas.android.com/tools">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="21" />
<application>
<activity android:name="com.huawei.android.sdk.drm.DrmDialogActivity"
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
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:theme="@style/AppTheme" >
<activity
android:name="com.huawei.android.sdk.drm.DrmDialogActivity"
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:name="android.support.v4.content.FileProvider"
android:authorities="net.osmand.plus.huawei.fileprovider"
tools:replace="android:authorities" />
<service
android:name="net.osmand.plus.NavigationService"
android:process="net.osmand.plus.huawei"
tools:replace="android:process" />
</application>
</manifest>

View file

@ -17,9 +17,6 @@ apply plugin: 'com.android.application'
// </unzip>
// Less important
def huawei = (System.getenv("APP_FEATURES") && System.getenv("APP_FEATURES").contains("+huawei"))
task printc {
configurations.each { if(it.isCanBeResolved()) println it.name }
}
@ -114,6 +111,9 @@ android {
freecustom {
manifest.srcFile "AndroidManifest-freecustom.xml"
}
huawei {
manifest.srcFile "AndroidManifest-huawei.xml"
}
legacy {
jniLibs.srcDirs = ["libc++"]
@ -177,6 +177,10 @@ android {
resConfig "en"
//resConfigs "xxhdpi", "nodpi"
}
huawei {
dimension "version"
applicationId "net.osmand.plus.huawei"
}
// CoreVersion
legacy {
@ -253,12 +257,39 @@ task downloadWorldMiniBasemap {
}
}
task downloadHuaweiDrm {
task downloadHuaweiDrmZip {
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.unzip(src: 'HwDRM_SDK_2.5.2.300_ADT.zip', dest: 'libs/')
}
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/')
}
}
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,
validateTranslate,
copyWidgetIcons,
downloadWorldMiniBasemap,
downloadHuaweiDrm
downloadWorldMiniBasemap
}
// Legacy core build
@ -375,9 +405,16 @@ task cleanupDuplicatesInCore() {
}
}
afterEvaluate {
android.applicationVariants.all { variant ->
variant.javaCompiler.dependsOn(collectExternalResources, buildOsmAndCore, cleanupDuplicatesInCore)
}
android.applicationVariants.all { variant ->
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) {
@ -434,7 +471,5 @@ dependencies {
exclude group: 'com.android.support'
}
if (huawei) {
implementation files('libs/huawei-android-drm_v2.5.2.300.jar')
}
huaweiImplementation files('libs/huawei-android-drm_v2.5.2.300.jar')
}

View file

@ -1,39 +1,66 @@
package net.osmand.plus;
import android.app.Activity;
import android.util.Log;
//import com.huawei.android.sdk.drm.Drm;
//import com.huawei.android.sdk.drm.DrmCheckCallback;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class HuaweiDrmHelper {
private Activity activity;
//private DrmCheckCallback callback;
private static final String TAG = HuaweiDrmHelper.class.getSimpleName();
//Copyright protection id
private static final String DRM_ID = "101048021";
//Copyright protection public key
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 void onCheckFailed() {
activity.finish();
}
};
*/
public static void check(Activity activity) {
boolean succeed = false;
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() {
//Drm.check(getActivity(), getActivity().getPackageName(), DRM_ID, DRM_PUBLIC_KEY, callback);
}
public Activity getActivity() {
return this.activity;
private static void closeApplication(Activity activity) {
((OsmandApplication) activity.getApplication()).closeApplicationAnywayImpl(activity, true);
}
}

View file

@ -26,7 +26,7 @@ public class Version {
}
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) {

View file

@ -247,7 +247,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
super.onCreate(savedInstanceState);
if (Version.isHuawei(getMyApplication())) {
new HuaweiDrmHelper(this).check();
HuaweiDrmHelper.check(this);
}
// Full screen is not used here
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);