Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13598f19 authored by Xin Li's avatar Xin Li
Browse files

DO NOT MERGE - Merge PPRL.190205.001 into master

Bug: 124234733
Change-Id: I4276a04a6718e24347c094928ef5e6ced930d01a
parents d24fd2d4 eb592d88
Loading
Loading
Loading
Loading
+36 −0
Original line number Original line Diff line number Diff line
@@ -194,6 +194,40 @@ static jboolean disconnectHearingAidNative(JNIEnv* env, jobject object,
  return JNI_TRUE;
  return JNI_TRUE;
}
}


static jboolean addToWhiteListNative(JNIEnv* env, jobject object,
                                     jbyteArray address) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sHearingAidInterface) return JNI_FALSE;

  jbyte* addr = env->GetByteArrayElements(address, nullptr);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
    return JNI_FALSE;
  }

  RawAddress* tmpraw = (RawAddress*)addr;
  sHearingAidInterface->AddToWhiteList(*tmpraw);
  env->ReleaseByteArrayElements(address, addr, 0);
  return JNI_TRUE;
}

static jboolean removeFromWhiteListNative(JNIEnv* env, jobject object,
                                          jbyteArray address) {
  std::shared_lock<std::shared_timed_mutex> lock(interface_mutex);
  if (!sHearingAidInterface) return JNI_FALSE;

  jbyte* addr = env->GetByteArrayElements(address, nullptr);
  if (!addr) {
    jniThrowIOException(env, EINVAL);
    return JNI_FALSE;
  }

  RawAddress* tmpraw = (RawAddress*)addr;
  sHearingAidInterface->RemoveFromWhiteList(*tmpraw);
  env->ReleaseByteArrayElements(address, addr, 0);
  return JNI_TRUE;
}

static void setVolumeNative(JNIEnv* env, jclass clazz, jint volume) {
static void setVolumeNative(JNIEnv* env, jclass clazz, jint volume) {
  if (!sHearingAidInterface) {
  if (!sHearingAidInterface) {
    LOG(ERROR) << __func__
    LOG(ERROR) << __func__
@@ -209,6 +243,8 @@ static JNINativeMethod sMethods[] = {
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"cleanupNative", "()V", (void*)cleanupNative},
    {"connectHearingAidNative", "([B)Z", (void*)connectHearingAidNative},
    {"connectHearingAidNative", "([B)Z", (void*)connectHearingAidNative},
    {"disconnectHearingAidNative", "([B)Z", (void*)disconnectHearingAidNative},
    {"disconnectHearingAidNative", "([B)Z", (void*)disconnectHearingAidNative},
    {"addToWhiteListNative", "([B)Z", (void*)addToWhiteListNative},
    {"removeFromWhiteListNative", "([B)Z", (void*)removeFromWhiteListNative},
    {"setVolumeNative", "(I)V", (void*)setVolumeNative},
    {"setVolumeNative", "(I)V", (void*)setVolumeNative},
};
};


+1 −1
Original line number Original line Diff line number Diff line
@@ -45,7 +45,7 @@
    <string name="notification_sent" msgid="9218710861333027778">"Bluetooth: <xliff:g id="FILE">%1$s</xliff:g> enviat"</string>
    <string name="notification_sent" msgid="9218710861333027778">"Bluetooth: <xliff:g id="FILE">%1$s</xliff:g> enviat"</string>
    <string name="notification_sent_complete" msgid="302943281067557969">"100% complet"</string>
    <string name="notification_sent_complete" msgid="302943281067557969">"100% complet"</string>
    <string name="notification_sent_fail" msgid="6696082233774569445">"Bluetooth: <xliff:g id="FILE">%1$s</xliff:g> no enviat"</string>
    <string name="notification_sent_fail" msgid="6696082233774569445">"Bluetooth: <xliff:g id="FILE">%1$s</xliff:g> no enviat"</string>
    <string name="download_title" msgid="3353228219772092586">"Transferència del fitxer"</string>
    <string name="download_title" msgid="3353228219772092586">"Transferència de fitxers"</string>
    <string name="download_line1" msgid="4926604799202134144">"De: \"<xliff:g id="SENDER">%1$s</xliff:g>\""</string>
    <string name="download_line1" msgid="4926604799202134144">"De: \"<xliff:g id="SENDER">%1$s</xliff:g>\""</string>
    <string name="download_line2" msgid="5876973543019417712">"Fitxer: <xliff:g id="FILE">%1$s</xliff:g>"</string>
    <string name="download_line2" msgid="5876973543019417712">"Fitxer: <xliff:g id="FILE">%1$s</xliff:g>"</string>
    <string name="download_line3" msgid="4384821622908676061">"Mida del fitxer: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
    <string name="download_line3" msgid="4384821622908676061">"Mida del fitxer: <xliff:g id="SIZE">%1$s</xliff:g>"</string>
+1 −1
Original line number Original line Diff line number Diff line
@@ -125,7 +125,7 @@
    <string name="bluetooth_a2dp_sink_queue_name" msgid="6864149958708669766">"आता प्ले करत आहे"</string>
    <string name="bluetooth_a2dp_sink_queue_name" msgid="6864149958708669766">"आता प्ले करत आहे"</string>
    <string name="bluetooth_map_settings_save" msgid="7635491847388074606">"सेव्ह करा"</string>
    <string name="bluetooth_map_settings_save" msgid="7635491847388074606">"सेव्ह करा"</string>
    <string name="bluetooth_map_settings_cancel" msgid="9205350798049865699">"रद्द करा"</string>
    <string name="bluetooth_map_settings_cancel" msgid="9205350798049865699">"रद्द करा"</string>
    <string name="bluetooth_map_settings_intro" msgid="6482369468223987562">"तुम्ही ब्लूटूथद्वारे सामायिक करू इच्छित असलेली खाती निवडा. कनेक्ट करताना अद्याप तुम्ही खात्यांमधील कोणताही अॅक्सेस स्वीकारण्याची आवश्यकता आहे."</string>
    <string name="bluetooth_map_settings_intro" msgid="6482369468223987562">"तुम्ही ब्लूटूथद्वारे शेअर करू इच्छित असलेली खाती निवडा. कनेक्ट करताना अद्याप तुम्ही खात्यांमधील कोणताही अॅक्सेस स्वीकारण्याची आवश्यकता आहे."</string>
    <string name="bluetooth_map_settings_count" msgid="4557473074937024833">"स्लॉट शिल्लक:"</string>
    <string name="bluetooth_map_settings_count" msgid="4557473074937024833">"स्लॉट शिल्लक:"</string>
    <string name="bluetooth_map_settings_app_icon" msgid="7105805610929114707">"अॅप्लिकेशन आयकन"</string>
    <string name="bluetooth_map_settings_app_icon" msgid="7105805610929114707">"अॅप्लिकेशन आयकन"</string>
    <string name="bluetooth_map_settings_title" msgid="7420332483392851321">"ब्लूटूथ मेसेज सामायिकरण सेटिंग्ज"</string>
    <string name="bluetooth_map_settings_title" msgid="7420332483392851321">"ब्लूटूथ मेसेज सामायिकरण सेटिंग्ज"</string>
+24 −0
Original line number Original line Diff line number Diff line
@@ -104,6 +104,28 @@ public class HearingAidNativeInterface {
        return disconnectHearingAidNative(getByteAddress(device));
        return disconnectHearingAidNative(getByteAddress(device));
    }
    }


    /**
     * Add a hearing aid device to white list.
     *
     * @param device the remote device
     * @return true on success, otherwise false.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public boolean addToWhiteList(BluetoothDevice device) {
        return addToWhiteListNative(getByteAddress(device));
    }

    /**
     * Remove a hearing aid device from white list.
     *
     * @param device the remote device
     * @return true on success, otherwise false.
     */
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public boolean removeFromWhiteList(BluetoothDevice device) {
        return removeFromWhiteListNative(getByteAddress(device));
    }

    /**
    /**
     * Sets the HearingAid volume
     * Sets the HearingAid volume
     * @param volume
     * @param volume
@@ -168,5 +190,7 @@ public class HearingAidNativeInterface {
    private native void cleanupNative();
    private native void cleanupNative();
    private native boolean connectHearingAidNative(byte[] address);
    private native boolean connectHearingAidNative(byte[] address);
    private native boolean disconnectHearingAidNative(byte[] address);
    private native boolean disconnectHearingAidNative(byte[] address);
    private native boolean addToWhiteListNative(byte[] address);
    private native boolean removeFromWhiteListNative(byte[] address);
    private native void setVolumeNative(int volume);
    private native void setVolumeNative(int volume);
}
}
+22 −13
Original line number Original line Diff line number Diff line
@@ -58,6 +58,10 @@ public class HearingAidService extends ProfileService {
    // Upper limit of all HearingAid devices: Bonded or Connected
    // Upper limit of all HearingAid devices: Bonded or Connected
    private static final int MAX_HEARING_AID_STATE_MACHINES = 10;
    private static final int MAX_HEARING_AID_STATE_MACHINES = 10;
    private static HearingAidService sHearingAidService;
    private static HearingAidService sHearingAidService;
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    static int sConnectTimeoutForEachSideMs = 8000;
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    static int sCheckWhitelistTimeoutMs = 16000;


    private AdapterService mAdapterService;
    private AdapterService mAdapterService;
    private HandlerThread mStateMachinesThread;
    private HandlerThread mStateMachinesThread;
@@ -247,14 +251,6 @@ public class HearingAidService extends ProfileService {
            }
            }
        }
        }


        synchronized (mStateMachines) {
            HearingAidStateMachine smConnect = getOrCreateStateMachine(device);
            if (smConnect == null) {
                Log.e(TAG, "Cannot connect to " + device + " : no state machine");
            }
            smConnect.sendMessage(HearingAidStateMachine.CONNECT);
        }

        for (BluetoothDevice storedDevice : mDeviceHiSyncIdMap.keySet()) {
        for (BluetoothDevice storedDevice : mDeviceHiSyncIdMap.keySet()) {
            if (device.equals(storedDevice)) {
            if (device.equals(storedDevice)) {
                continue;
                continue;
@@ -267,14 +263,27 @@ public class HearingAidService extends ProfileService {
                        Log.e(TAG, "Ignored connect request for " + device + " : no state machine");
                        Log.e(TAG, "Ignored connect request for " + device + " : no state machine");
                        continue;
                        continue;
                    }
                    }
                    sm.sendMessage(HearingAidStateMachine.CONNECT);
                    sm.sendMessage(HearingAidStateMachine.CONNECT,
                            sConnectTimeoutForEachSideMs);
                    sm.sendMessageDelayed(HearingAidStateMachine.CHECK_WHITELIST_CONNECTION,
                            sCheckWhitelistTimeoutMs);
                }
                }
                if (hiSyncId == BluetoothHearingAid.HI_SYNC_ID_INVALID
                        && !device.equals(storedDevice)) {
                break;
                break;
            }
            }
        }
        }

        synchronized (mStateMachines) {
            HearingAidStateMachine smConnect = getOrCreateStateMachine(device);
            if (smConnect == null) {
                Log.e(TAG, "Cannot connect to " + device + " : no state machine");
            } else {
                smConnect.sendMessage(HearingAidStateMachine.CONNECT,
                        sConnectTimeoutForEachSideMs * 2);
                smConnect.sendMessageDelayed(HearingAidStateMachine.CHECK_WHITELIST_CONNECTION,
                        sCheckWhitelistTimeoutMs);
            }
            }
        }

        return true;
        return true;
    }
    }


Loading