diff --git a/core/jni/android_view_KeyCharacterMap.cpp b/core/jni/android_view_KeyCharacterMap.cpp index 586b26ef328fe..cbce38e12d256 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 @@ -47,9 +47,8 @@ static struct { class NativeKeyCharacterMap { public: - NativeKeyCharacterMap(int32_t deviceId, const sp& map) : - mDeviceId(deviceId), mMap(map) { - } + NativeKeyCharacterMap(int32_t deviceId, std::shared_ptr map) + : mDeviceId(deviceId), mMap(std::move(map)) {} ~NativeKeyCharacterMap() { } @@ -58,26 +57,22 @@ public: return mDeviceId; } - inline const sp& getMap() const { - return mMap; - } + inline const std::shared_ptr getMap() const { return mMap; } private: int32_t mDeviceId; - sp mMap; + std::shared_ptr mMap; }; - jobject android_view_KeyCharacterMap_create(JNIEnv* env, int32_t deviceId, - const sp& kcm) { - NativeKeyCharacterMap* map = new NativeKeyCharacterMap(deviceId, - kcm.get() ? kcm : KeyCharacterMap::empty()); - if (!map) { - return NULL; + const std::shared_ptr kcm) { + NativeKeyCharacterMap* nativeMap = new NativeKeyCharacterMap(deviceId, kcm); + if (!nativeMap) { + return nullptr; } return env->NewObject(gKeyCharacterMapClassInfo.clazz, gKeyCharacterMapClassInfo.ctor, - reinterpret_cast(map)); + reinterpret_cast(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 kcm = KeyCharacterMap::readFromParcel(parcel); + std::shared_ptr 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(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(chars), size_t(numChars), - metaState); + char16_t result = map->getMap()->getMatch(keyCode, reinterpret_cast(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 events; jobjectArray result = NULL; - if (map->getMap()->getEvents(map->getDeviceId(), - reinterpret_cast(chars), + if (map->getMap()->getEvents(map->getDeviceId(), reinterpret_cast(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 e8465c2a33e31..be0335380f872 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& map); + const std::shared_ptr 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 9751c46f93c93..5dd6cd7b42e95 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 obtainPointerController(int32_t deviceId); virtual void notifyInputDevicesChanged(const std::vector& inputDevices); - virtual sp getKeyboardLayoutOverlay(const InputDeviceIdentifier& identifier); + virtual std::shared_ptr 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 NativeInputManager::getKeyboardLayoutOverlay( +std::shared_ptr NativeInputManager::getKeyboardLayoutOverlay( const InputDeviceIdentifier& identifier) { ATRACE_CALL(); JNIEnv* env = jniEnv(); - sp result; + std::shared_ptr result; ScopedLocalRef descriptor(env, env->NewStringUTF(identifier.descriptor.c_str())); ScopedLocalRef identifierObj(env, env->NewObject(gInputDeviceIdentifierInfo.clazz, gInputDeviceIdentifierInfo.constructor, descriptor.get(), @@ -642,8 +643,12 @@ sp 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> 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 756347179874b..0aca13e95a522 100644 --- a/tools/validatekeymaps/Main.cpp +++ b/tools/validatekeymaps/Main.cpp @@ -105,11 +105,10 @@ static bool validateFile(const char* filename) { } case FILETYPE_KEYCHARACTERMAP: { - sp 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> 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;