AndroidDeviceNames icon indicating copy to clipboard operation
AndroidDeviceNames copied to clipboard

Exception thrown for missing manufacturer when retrieving getDeviceName()

Open RDLemos opened this issue 5 years ago • 4 comments

Hello, I am using the library to retrieve the device market name, which works, but i always see this exception below for the missing manufacturer?

org.json.JSONException: No value for manufacturer at org.json.JSONObject.get(JSONObject.java:389) at org.json.JSONObject.getString(JSONObject.java:550) at com.jaredrummler.android.device.DeviceName$DeviceInfo.(DeviceName.java:374) at com.jaredrummler.android.device.DeviceName$DeviceInfo.(DeviceName.java:347) at com.jaredrummler.android.device.DeviceName.getDeviceInfo(DeviceName.java:186) at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:138) at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:111) at com.atos.ucc.g3pten.core.services.G3PTenService.setDeviceInformation(G3PTenService.kt:307) at com.atos.ucc.g3pten.core.services.G3PTenService.setup(G3PTenService.kt:143) at com.atos.ucc.g3pten.core.services.G3PTenService.onCreate(G3PTenService.kt:100) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3522) at android.app.ActivityThread.-wrap6(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1740) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6688) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

It is a very simple code:

I have initialized the lib: DeviceName.init(this)

Then call:

    private fun setupDeviceInformation() {
        try {
            g3ptDeviceModelInformation =
                "${Build.MODEL} (${Build.MANUFACTURER}) (${DeviceName.getDeviceName()})"
            G3PTenLog.d(TAG, "[SVC] DeviceName: $g3ptDeviceModelInformation")
        } catch (e: Exception) {
            G3PTenLog.e(TAG, "[SVC] Error retrieving device name: $e")
            e.printStackTrace()
        }
    }

RDLemos avatar Jul 11 '20 06:07 RDLemos

I have the same trouble. After I called:

/**
     * Will return a model of device(For example: Nexus 5)
     * @return String
     */
    public static String getDeviceModel() {
        if (Build.MODEL.equals(DeviceName.getDeviceName())) {
            return Build.MODEL;
        }
        return DeviceName.getDeviceName() + " (" + Build.MODEL + ")";
    }

Got error:

org.json.JSONException: No value for manufacturer
at org.json.JSONObject.get(JSONObject.java:400)
at org.json.JSONObject.getString(JSONObject.java:561)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:374)
at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:347)
at com.jaredrummler.android.device.DeviceName.getDeviceInfo(DeviceName.java:186)
at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:138)
at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:111)

andrewgrow avatar Jul 20 '20 10:07 andrewgrow

Device: Xiaomi Redmi Note 8 Pro

W/System.err: org.json.JSONException: No value for manufacturer
W/System.err:     at org.json.JSONObject.get(JSONObject.java:399)
W/System.err:     at org.json.JSONObject.getString(JSONObject.java:560)
W/System.err:     at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:374)
W/System.err:     at com.jaredrummler.android.device.DeviceName$DeviceInfo.<init>(DeviceName.java:347)
W/System.err:     at com.jaredrummler.android.device.DeviceName.getDeviceInfo(DeviceName.java:186)
W/System.err:     at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:138)
W/System.err:     at com.jaredrummler.android.device.DeviceName.getDeviceName(DeviceName.java:111)
W/System.err:     ...
W/System.err:     at android.net.ConnectivityManager$NetworkCallback.onAvailable(ConnectivityManager.java:3
W/System.err:     at android.net.ConnectivityManager$CallbackHandler.handleMessage(ConnectivityManager.java
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
W/System.err:     at android.os.Looper.loop(Looper.java:224)
W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:67)

Same for me Samsung galaxy Note 9

Climax777 avatar Jul 28 '20 10:07 Climax777

I am using AndroidDeviceNames library in the banking app and found a problem: In the DeviceName class the getDeviceInfo() function uses the following code:

try {
  return new DeviceInfo(new JSONObject(savedJson));
}
catch (Exception e) {
  e.printStackTrace();
}

In this section of code, printStackTrace() outputs all exceptions to the console, even in the release build of the app. This behavior reduces the security of the application. In addition, stack trace in the console always catches the eye and irritates.

If the library can perform its functions successfully without annoying stack trace in the console, then you don't need to output extra information to the console. If you need to get this information when developing the library, then it is better to run printStackTrace() in the library version only for the developers of the library itself. To do this, you can use Timber library or your custom logger.

Please fix the specified problem.

ilexbor avatar Jul 28 '20 10:07 ilexbor

Faced this too.

C5FR7Q avatar Sep 24 '20 03:09 C5FR7Q