mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 15:58:43 +00:00
Merge "example vendor app" am: e49b3684a1 am: aebd7e6bb7
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2308365 Change-Id: I80e4d182c39814c31783b2746e1c42d014e6923e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -17,7 +17,7 @@ aidl_interface {
|
||||
stability: "vintf",
|
||||
backend: {
|
||||
java: {
|
||||
sdk_version: "module_current",
|
||||
sdk_version: "system_current",
|
||||
},
|
||||
},
|
||||
versions: [
|
||||
|
||||
34
vibrator/aidl/default/example_vendor_java_client/Android.bp
Normal file
34
vibrator/aidl/default/example_vendor_java_client/Android.bp
Normal file
@@ -0,0 +1,34 @@
|
||||
package {
|
||||
// See: http://go/android-license-faq
|
||||
// A large-scale-change added 'default_applicable_licenses' to import
|
||||
// all of the 'license_kinds' from "hardware_interfaces_license"
|
||||
// to get the below license kinds:
|
||||
// SPDX-license-identifier-Apache-2.0
|
||||
default_applicable_licenses: ["hardware_interfaces_license"],
|
||||
}
|
||||
|
||||
cc_library {
|
||||
name: "libexample_vib_getter",
|
||||
srcs: ["getter.cpp"],
|
||||
vendor: true,
|
||||
shared_libs: [
|
||||
"liblog",
|
||||
"libbinder_ndk",
|
||||
],
|
||||
header_libs: ["jni_headers"],
|
||||
stl: "c++_shared",
|
||||
visibility: [":__subpackages__"],
|
||||
}
|
||||
|
||||
android_app {
|
||||
name: "ExampleVibratorJavaVendorClient",
|
||||
privileged: true,
|
||||
vendor: true,
|
||||
static_libs: ["android.hardware.vibrator-V1-java"],
|
||||
jni_libs: ["libexample_vib_getter"],
|
||||
jarjar_rules: "jarjar.txt",
|
||||
stl: "c++_shared",
|
||||
srcs: ["example/vib/MyActivity.java"],
|
||||
sdk_version: "system_current",
|
||||
visibility: [":__subpackages__"],
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="example.vib">
|
||||
<application>
|
||||
<activity android:name=".MyActivity"/>
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package example.vib;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.hardware.vibrator.IVibrator;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
|
||||
public class MyActivity extends Activity {
|
||||
private static native IBinder gimme(String name);
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle b) {
|
||||
super.onCreate(b);
|
||||
System.loadLibrary("example_vib_getter");
|
||||
|
||||
// There is no API to get ahold of a Stable AIDL service from a vendor app
|
||||
// in Java. This is because this is not the recommended way to get ahold
|
||||
// of functionality in Android. The Android API Council recommendation is to
|
||||
// implement uses-library APIs in the system/system_ext partition which add
|
||||
// new APIs. AIDL as an API in Java is not recommended or supported way to
|
||||
// communicate by apps - the recommendation is to use Java APIs. However,
|
||||
// there also exists a large number of vendor apps which are coupled with
|
||||
// hardware-specific code, and are therefore on the vendor partition. A
|
||||
// large number of these use HIDL, and this is how they can continue to
|
||||
// use that structure with AIDL.
|
||||
IVibrator v =
|
||||
IVibrator.Stub.asInterface(gimme("android.hardware.vibrator.IVibrator/default"));
|
||||
|
||||
try {
|
||||
v.on(100 /*ms*/, null /*cb*/);
|
||||
} catch (RemoteException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
48
vibrator/aidl/default/example_vendor_java_client/getter.cpp
Normal file
48
vibrator/aidl/default/example_vendor_java_client/getter.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <android/binder_auto_utils.h>
|
||||
#include <android/binder_ibinder_jni.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <jni.h>
|
||||
#include <log/log.h>
|
||||
|
||||
extern "C" JNIEXPORT jobject JNICALL
|
||||
Java_example_vib_MyActivity_gimme__Ljava_lang_String_2(JNIEnv* env, jclass /**/, jstring str) {
|
||||
ALOGI("%s", __func__);
|
||||
|
||||
// Best practice is probably libnativehelper ScopedUtfChars or
|
||||
// libbase ScopeGuard (for platform code), but this is with minimal
|
||||
// dependencies.
|
||||
const char* name = env->GetStringUTFChars(str, nullptr);
|
||||
|
||||
ALOGI("example vib gimme %s", name);
|
||||
|
||||
jobject jbinder = nullptr;
|
||||
|
||||
// Java does not have vendor variants. It's only safe to pass a service when
|
||||
// 'vendor: true' if it is @VintfStability.
|
||||
if (AServiceManager_isDeclared(name)) {
|
||||
ndk::SpAIBinder binder = ndk::SpAIBinder(AServiceManager_waitForService(name));
|
||||
jbinder = AIBinder_toJavaBinder(env, binder.get());
|
||||
} else {
|
||||
ALOGI("not declared");
|
||||
}
|
||||
|
||||
env->ReleaseStringUTFChars(str, name);
|
||||
|
||||
return jbinder;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
rule android.hardware.** example.vib.ah.@1
|
||||
|
||||
Reference in New Issue
Block a user