diff options
| author | 2020-08-31 16:45:54 +0000 | |
|---|---|---|
| committer | 2020-08-31 16:45:54 +0000 | |
| commit | bd7b6b12a4d3011bd95cc50306bdf02045d5a27d (patch) | |
| tree | c8fae8c383ff346b107c3f8c7ae97814d5db12ed | |
| parent | 3683a64f0b33fb51e20309b5a48aa63829e97289 (diff) | |
| parent | e8da2d3a48ac87760fbf89a7dc2c6fe3c28546c1 (diff) | |
Merge changes from topic "KeyCharacterMapRefactor"
* changes:
Move KeyCharacterMap from RefBase to shared_ptr.
Move KeyLayoutMap from RefBase to shared_ptr.
| -rw-r--r-- | core/jni/android_view_KeyCharacterMap.cpp | 54 | ||||
| -rw-r--r-- | core/jni/android_view_KeyCharacterMap.h | 2 | ||||
| -rw-r--r-- | services/core/jni/com_android_server_input_InputManagerService.cpp | 15 | ||||
| -rw-r--r-- | tools/validatekeymaps/Main.cpp | 16 |
4 files changed, 43 insertions, 44 deletions
diff --git a/core/jni/android_view_KeyCharacterMap.cpp b/core/jni/android_view_KeyCharacterMap.cpp index 586b26ef328f..cbce38e12d25 100644 --- a/core/jni/android_view_KeyCharacterMap.cpp +++ b/core/jni/android_view_KeyCharacterMap.cpp @@ -1,18 +1,18 @@ /* * Copyright 2006, 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 + * 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 + * 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 + * 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_runtime/AndroidRuntime.h> @@ -47,9 +47,8 @@ static struct { class NativeKeyCharacterMap { public: - NativeKeyCharacterMap(int32_t deviceId, const sp<KeyCharacterMap>& map) : - mDeviceId(deviceId), mMap(map) { - } + NativeKeyCharacterMap(int32_t deviceId, std::shared_ptr<KeyCharacterMap> map) + : mDeviceId(deviceId), mMap(std::move(map)) {} ~NativeKeyCharacterMap() { } @@ -58,26 +57,22 @@ public: return mDeviceId; } - inline const sp<KeyCharacterMap>& getMap() const { - return mMap; - } + inline const std::shared_ptr<KeyCharacterMap> getMap() const { return mMap; } private: int32_t mDeviceId; - sp<KeyCharacterMap> mMap; + std::shared_ptr<KeyCharacterMap> mMap; }; - jobject android_view_KeyCharacterMap_create(JNIEnv* env, int32_t deviceId, - const sp<KeyCharacterMap>& kcm) { - NativeKeyCharacterMap* map = new NativeKeyCharacterMap(deviceId, - kcm.get() ? kcm : KeyCharacterMap::empty()); - if (!map) { - return NULL; + const std::shared_ptr<KeyCharacterMap> kcm) { + NativeKeyCharacterMap* nativeMap = new NativeKeyCharacterMap(deviceId, kcm); + if (!nativeMap) { + return nullptr; } return env->NewObject(gKeyCharacterMapClassInfo.clazz, gKeyCharacterMapClassInfo.ctor, - reinterpret_cast<jlong>(map)); + reinterpret_cast<jlong>(nativeMap)); } static jlong nativeReadFromParcel(JNIEnv *env, jobject clazz, jobject parcelObj) { @@ -91,7 +86,7 @@ static jlong nativeReadFromParcel(JNIEnv *env, jobject clazz, jobject parcelObj) return 0; } - sp<KeyCharacterMap> kcm = KeyCharacterMap::readFromParcel(parcel); + std::shared_ptr<KeyCharacterMap> kcm = KeyCharacterMap::readFromParcel(parcel); if (!kcm.get()) { return 0; } @@ -102,6 +97,9 @@ static jlong nativeReadFromParcel(JNIEnv *env, jobject clazz, jobject parcelObj) static void nativeWriteToParcel(JNIEnv* env, jobject clazz, jlong ptr, jobject parcelObj) { NativeKeyCharacterMap* map = reinterpret_cast<NativeKeyCharacterMap*>(ptr); + if (!map->getMap()) { + return; + } Parcel* parcel = parcelForJavaObject(env, parcelObj); if (parcel) { parcel->writeInt32(map->getDeviceId()); @@ -150,9 +148,8 @@ static jchar nativeGetMatch(JNIEnv *env, jobject clazz, jlong ptr, jint keyCode, return 0; } - char16_t result = map->getMap()->getMatch( - keyCode, reinterpret_cast<char16_t*>(chars), size_t(numChars), - metaState); + char16_t result = map->getMap()->getMatch(keyCode, reinterpret_cast<char16_t*>(chars), + size_t(numChars), metaState); env->ReleasePrimitiveArrayCritical(charsArray, chars, JNI_ABORT); return result; @@ -180,8 +177,7 @@ static jobjectArray nativeGetEvents(JNIEnv *env, jobject clazz, jlong ptr, Vector<KeyEvent> events; jobjectArray result = NULL; - if (map->getMap()->getEvents(map->getDeviceId(), - reinterpret_cast<char16_t*>(chars), + if (map->getMap()->getEvents(map->getDeviceId(), reinterpret_cast<char16_t*>(chars), size_t(numChars), events)) { result = env->NewObjectArray(jsize(events.size()), gKeyEventClassInfo.clazz, NULL); if (result) { diff --git a/core/jni/android_view_KeyCharacterMap.h b/core/jni/android_view_KeyCharacterMap.h index e8465c2a33e3..be0335380f87 100644 --- a/core/jni/android_view_KeyCharacterMap.h +++ b/core/jni/android_view_KeyCharacterMap.h @@ -25,7 +25,7 @@ namespace android { /* Creates a KeyCharacterMap object from the given information. */ extern jobject android_view_KeyCharacterMap_create(JNIEnv* env, int32_t deviceId, - const sp<KeyCharacterMap>& map); + const std::shared_ptr<KeyCharacterMap> kcm); } // namespace android diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index 9751c46f93c9..5dd6cd7b42e9 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -233,7 +233,8 @@ public: virtual void getReaderConfiguration(InputReaderConfiguration* outConfig); virtual std::shared_ptr<PointerControllerInterface> obtainPointerController(int32_t deviceId); virtual void notifyInputDevicesChanged(const std::vector<InputDeviceInfo>& inputDevices); - virtual sp<KeyCharacterMap> getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier); + virtual std::shared_ptr<KeyCharacterMap> getKeyboardLayoutOverlay( + const InputDeviceIdentifier& identifier); virtual std::string getDeviceAlias(const InputDeviceIdentifier& identifier); virtual TouchAffineTransformation getTouchAffineTransformation(JNIEnv *env, jfloatArray matrixArr); @@ -622,12 +623,12 @@ void NativeInputManager::notifyInputDevicesChanged(const std::vector<InputDevice checkAndClearExceptionFromCallback(env, "notifyInputDevicesChanged"); } -sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay( +std::shared_ptr<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay( const InputDeviceIdentifier& identifier) { ATRACE_CALL(); JNIEnv* env = jniEnv(); - sp<KeyCharacterMap> result; + std::shared_ptr<KeyCharacterMap> result; ScopedLocalRef<jstring> descriptor(env, env->NewStringUTF(identifier.descriptor.c_str())); ScopedLocalRef<jobject> identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz, gInputDeviceIdentifierInfo.constructor, descriptor.get(), @@ -642,8 +643,12 @@ sp<KeyCharacterMap> NativeInputManager::getKeyboardLayoutOverlay( ScopedUtfChars filenameChars(env, filenameObj.get()); ScopedUtfChars contentsChars(env, contentsObj.get()); - KeyCharacterMap::loadContents(filenameChars.c_str(), - contentsChars.c_str(), KeyCharacterMap::FORMAT_OVERLAY, &result); + base::Result<std::shared_ptr<KeyCharacterMap>> ret = + KeyCharacterMap::loadContents(filenameChars.c_str(), contentsChars.c_str(), + KeyCharacterMap::FORMAT_OVERLAY); + if (ret) { + result = *ret; + } } checkAndClearExceptionFromCallback(env, "getKeyboardLayoutOverlay"); return result; diff --git a/tools/validatekeymaps/Main.cpp b/tools/validatekeymaps/Main.cpp index 5ac9dfd2a557..0aca13e95a52 100644 --- a/tools/validatekeymaps/Main.cpp +++ b/tools/validatekeymaps/Main.cpp @@ -96,21 +96,19 @@ static bool validateFile(const char* filename) { return false; case FILETYPE_KEYLAYOUT: { - sp<KeyLayoutMap> map; - status_t status = KeyLayoutMap::load(filename, &map); - if (status) { - error("Error %d parsing key layout file.\n\n", status); + base::Result<std::shared_ptr<KeyLayoutMap>> ret = KeyLayoutMap::load(filename); + if (!ret) { + error("Error %s parsing key layout file.\n\n", ret.error().message().c_str()); return false; } break; } case FILETYPE_KEYCHARACTERMAP: { - sp<KeyCharacterMap> map; - status_t status = KeyCharacterMap::load(filename, - KeyCharacterMap::FORMAT_ANY, &map); - if (status) { - error("Error %d parsing key character map file.\n\n", status); + base::Result<std::shared_ptr<KeyCharacterMap>> ret = KeyCharacterMap::load(filename, + KeyCharacterMap::FORMAT_ANY); + if (!ret) { + error("Error %s parsing key character map file.\n\n", ret.error().message().c_str()); return false; } break; |